【问题标题】:How to customize default wordpress editor?如何自定义默认的 wordpress 编辑器?
【发布时间】:2012-01-11 07:47:02
【问题描述】:

很高兴听到索尼 (wordpress3.3) 拥有新的编辑器 API wp_editor(),它使我们能够轻松地在自定义字段中使用编辑器的多个实例。

但我需要自定义默认编辑器(用于主要内容),但不知道如何使用此功能。 我需要为名为 baner 的新自定义帖子类型自定义编辑器,为此我需要用更少的按钮更改编辑器的大小。我知道我可以通过简单地使用自定义字段来做到这一点,但出于某种原因,我想使用内容来描述横幅。

在此先感谢您。

【问题讨论】:

    标签: wordpress editor customization


    【解决方案1】:

    我正在寻找将自定义元框放置在默认编辑器上方的解决方案,我找到了解决我的老问题(如何使用 wp_editor 自定义默认编辑器)的解决方案!

    解决方案是先取消设置默认编辑器。然后创建另一个元框来放置内容,然后使用 wp_editor 创建新的新实例,是不是很简单?

    add_action( 'add_meta_boxes', 'page_meta_boxes' );
    public function page_meta_boxes()
    {
    
        global $_wp_post_type_features;
                //ive defined my other metaboxes first with higher priority
        add_meta_box(
            $id     =   'page_heading_meta_box',
            $title  =   __('Heading'),
            $callback   = array(&$this,'render_page_heading_metabox'),
            $post_type  =   'page',
            $context    =   'normal',
            $priority   =   'core'
            );
        add_meta_box(
            $id     =   'page_description_meta_box',
            $title  =   __('Description'),
            $callback   = array(&$this,'render_page_description_metabox'),
            $post_type  =   'page',
            $context    =   'normal',
            $priority   =   'core'
            );
        //check for the required post type page or post or <custom post type(here article)  
        if (isset($_wp_post_type_features['article']['editor']) && $_wp_post_type_features['post']['editor']) {
            unset($_wp_post_type_features['article']['editor']);
            add_meta_box(
                'wsp_content',
                __('Content'),
                array(&$this,'content_editor_meta_box'),
                'article', 'normal', 'core'
            );
        }
        if (isset($_wp_post_type_features['page']['editor']) && $_wp_post_type_features['page']['editor']) {
            unset($_wp_post_type_features['page']['editor']);
            add_meta_box(
                'wsp_content',
                __('Content'),
                array(&$this,'content_editor_meta_box'),
                'page', 'normal', 'low'
            );
        }
        }
    

    通过这种方式,我们注册了一个名为 content 的新元框。现在是时候放置编辑器了

            function content_editor_meta_box($post)
        {
            $settings = array(
                #media_buttons
                #(boolean) (optional) Whether to display media insert/upload buttons
                #Default: true
                'media_buttons' => true,
    
                #textarea_name
                #(string) (optional) The name assigned to the generated textarea and passed parameter when the form is submitted. (may include [] to pass data as array)
                #Default: $editor_id
                'textarea_name'=>'content',
    
                #textarea_rows
                #(integer) (optional) The number of rows to display for the textarea
                #Default: get_option('default_post_edit_rows', 10)
    
                #tabindex
                #(integer) (optional) The tabindex value used for the form field
                #Default: None
                'tabindex' => '4'
    
                #editor_css
                #(string) (optional) Additional CSS styling applied for both visual and HTML editors buttons, needs to #include <style> tags, can use "scoped"
                #Default: None
    
                #editor_class
                #(string) (optional) Any extra CSS Classes to append to the Editor textarea
                #Default:
    
                #teeny
                #(boolean) (optional) Whether to output the minimal editor configuration used in PressThis
                #Default: false
    
                #dfw
                #(boolean) (optional) Whether to replace the default fullscreen editor with DFW (needs specific DOM elements #and css)
                #Default: false
    
                #tinymce
                #(array) (optional) Load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
                #Default: true
    
                #quicktags
                #(array) (optional) Load Quicktags, can be used to pass settings directly to Quicktags using an array()
                #Default: true
            );
            wp_editor($post->post_content,'content');
    
        }
    

    现在您可以完全自定义您的编辑器了!这就是它现在的样子。希望它对你也有用!

    【讨论】:

      【解决方案2】:

      您可以使用过滤器自定义编辑器 (TinyMCE),如 here 所示。附代码sn-p:

      function myformatTinyMCE($in)
      {
       $in['plugins']='inlinepopups,tabfocus,paste,media,fullscreen,wordpress,wpeditimage,wpgallery,wplink,wpdialogs,wpfullscreen';
       $in['wpautop']=true;
       $in['apply_source_formatting']=false;
       $in['theme_advanced_buttons1']='formatselect,forecolor,|,bold,italic,underline,|,bullist,numlist,blockquote,|,justifyleft,justifycenter,justifyright,justifyfull,|,link,unlink,|,wp_fullscreen,wp_adv';
       $in['theme_advanced_buttons2']='pastetext,pasteword,removeformat,|,charmap,|,outdent,indent,|,undo,redo';
       $in['theme_advanced_buttons3']='';
       $in['theme_advanced_buttons4']='';
       return $in;
      }
      add_filter('tiny_mce_before_init', 'myformatTinyMCE' );
      

      此代码应放在主题的functions.php 文件中。您可能想print_r( $in ) 查看所有传递的键(我在这里省略了一些键,因为我不相信我上面链接到的页面是最新的)。你可以浏览最新的源码here。您将在函数public static function editor_settings($editor_id, $set)中找到您要查找的过滤器

      此外,您可能还需要确保这只发生在您的 baner post_type 上,因为这会影响已创建的编辑器的所有实例。

      【讨论】:

      • 我试过这个,但我没有找到任何选项,比如更改编辑器大小(即 textarea_rows),使其变小等。
      • 您在最初的问题中链接到 wp_editor 参考——您可以通过 $settings 参数修改这些选项,键为 textarea_rowsteeny
      【解决方案3】:

      你可以试试这个Editor,你可以添加额外的字段,使用和安装也很简单

      【讨论】:

      • 有点重,有额外的桌子,我不喜欢那样,无论如何谢谢你的建议。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-16
      • 2011-06-20
      • 1970-01-01
      • 2021-03-05
      • 1970-01-01
      相关资源
      最近更新 更多