【问题标题】:Remove main editor from wordpress edit page screen从 wordpress 编辑页面屏幕中删除主编辑器
【发布时间】:2011-02-02 10:40:45
【问题描述】:

有人知道从页面编辑屏幕中删除主编辑器的方法吗?不仅仅是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 字段工作正常。

有什么想法吗?

【问题讨论】:

    标签: php jquery wordpress wordpress-theming


    【解决方案1】:

    内置的 WP 对此提供支持,因此您不必直接使用全局变量,并确保在它们改变功能处理方式时向前兼容。 WP Core 代码的逻辑与@user622018 答案几乎完全相同

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

    【讨论】:

    • 注意:要选择性地执行此操作,对于特定页面,您需要稍后挂钩。全局 $post 对象在 admin_init 不可用。我使用admin_head 为主页禁用了编辑器。
    【解决方案2】:

    您正在寻找的是全局 $_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");
    

    【讨论】:

    • 为什么是if (!isset($_wp_post_type_features[$post_type]) 行?它没有做任何事情,下一行正在检查,并且只有当关联数组包含所需的键时才会取消设置。
    • 我同意,不需要,只需要这个: if ( isset($_wp_post_type_features[$post_type][$feature]) ) unset($_wp_post_type_features[$post_type][$feature]);
    【解决方案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 编辑器,因为您的元框与它发生冲突吗? :)

      【讨论】:

      • 不,这也会禁用我其他元框上的 TinyMCE。我想要那些:)
      【解决方案5】:

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

      define('DISALLOW_FILE_EDIT', true);
      

      【讨论】:

      • 此常量阻止使用主题/插件编辑器,但对页面编辑器屏幕没有影响。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多