个性化阅读
专注于IT技术分析

从WordPress编辑页面屏幕中删除主编辑器

有人知道从页面编辑屏幕中删除主编辑器的方法吗?不仅是CSS。我在tinymce中添加了其他一些元框, 它们与主框碰撞。

我有一个可以从编辑屏幕中删除其他元框的类, 但是我不能以这种方式摆脱主编辑器。我试图将’divpostrich’和’divpost’添加到类中的数组中(但没有运气):

class removeMetas{
    public function __construct(){
        add_action('do_meta_boxes', array($this, 'removeMetaBoxes'), 10, 3);
    }

    public function removeMetaBoxes($type, $context, $post){
        /**
         * usages
         * remove_meta_box($id, $page, $context)
         * add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default')
         */
        $boxes = array( 'slugdiv', 'postexcerpt', 'passworddiv', 'categorydiv', 'tagsdiv', 'trackbacksdiv', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'postcustom');

        foreach ($boxes as $box){
            foreach (array('link', 'post', 'page') as $page){
                foreach (array('normal', 'advanced', 'side') as $context){
                    remove_meta_box($box, $type, $context);
                }
            }
        }
    }
}

$removeMetas = new removeMetas();

我也尝试过用jquery删除’divpostrich’。但无法弄清楚将js用于何处。当我使用Firebug在浏览器中删除” postdivrich”时, 我剩下的tinymce字段可以正常工作。

有任何想法吗?


#1


你要查找的是全局$ _wp_post_type_features数组。

以下是如何使用它的快速示例

function reset_editor()
{
     global $_wp_post_type_features;

     $post_type="page";
     $feature = "editor";
     if ( !isset($_wp_post_type_features[$post_type]) )
     {

     }
     elseif ( isset($_wp_post_type_features[$post_type][$feature]) )
     unset($_wp_post_type_features[$post_type][$feature]);
}

add_action("init", "reset_editor");

#2


对此提供了内置的WP支持, 因此你不必直接与全局变量打扰, 并确保前向兼容性(如果它们改变了功能的处理方式)。 WP Core代码几乎与@ user622018答案具有完全相同的逻辑。

function remove_editor() {
  remove_post_type_support('page', 'editor');
}
add_action('admin_init', 'remove_editor');

#3


将以下代码添加到你的函数中。

function remove_editor_init() {
if ( is_admin() ) {
    $post_id = 0;
    if(isset($_GET['post'])) $post_id = $_GET['post'];
    $template_file = get_post_meta($post_id, '_wp_page_template', TRUE);
    if ($template_file == 'page-home.php') {
        remove_post_type_support('page', 'editor');
    }
}
}
add_action( 'init', 'remove_editor_init' );

#4


你不能禁用TinyMCE编辑器, 而放弃HTML编辑器, 因为你的元框正在与它碰撞吗? 🙂


#5


要禁用编辑器, 你将需要编辑wp-config.php文件并将此行添加到顶部:

define('DISALLOW_FILE_EDIT', true);
赞(0)
未经允许不得转载:srcmini » 从WordPress编辑页面屏幕中删除主编辑器

评论 抢沙发

评论前必须登录!