最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom field - wp_editor in add_meta_boxes does not show gallery

programmeradmin1浏览0评论

I have added a meta box in the page edit section:

add_meta_box('custom_section_box', 'Sections', array($this, 'section_box'), 'page','normal','high');

Within the box, there is a wp_editor call:

$tinymce_options = array('plugins' => "table,lists,link,textcolor,hr", 'toolbar1'=>"fontsizeselect,forecolor,backcolor,bold,italic,underline,strikethrough,alignleft,aligncenter,alignright,alignjustify",'toolbar2'=>"blockquote,hr,table,bullist,numlist,undo,redo,link,unlink");
$editor_config= array('teeny'=>true, 'textarea_rows'=>10, 'editor_class'=>'csec_text', 'textarea_name'=>'csec_body', 'wpautop'=>false, 'tinymce'=>$tinymce_options);
wp_editor(html_entity_decode(stripslashes($vals['content'])), 'csec_body', $editor_config); 

Everything is working fine, but when I add a gallery through the media button, it displays the gallery shortcode only (like [gallery link="file" ids="759,760,761"]). There is no usual display of the gallery as in the normal page editor with edit/delete buttons.

I had tried to add the do_shortcode to pass the value in wp_editor, but that displays the full html instead. Also other shortcodes are rendered as html.

Can you please help?

I have added a meta box in the page edit section:

add_meta_box('custom_section_box', 'Sections', array($this, 'section_box'), 'page','normal','high');

Within the box, there is a wp_editor call:

$tinymce_options = array('plugins' => "table,lists,link,textcolor,hr", 'toolbar1'=>"fontsizeselect,forecolor,backcolor,bold,italic,underline,strikethrough,alignleft,aligncenter,alignright,alignjustify",'toolbar2'=>"blockquote,hr,table,bullist,numlist,undo,redo,link,unlink");
$editor_config= array('teeny'=>true, 'textarea_rows'=>10, 'editor_class'=>'csec_text', 'textarea_name'=>'csec_body', 'wpautop'=>false, 'tinymce'=>$tinymce_options);
wp_editor(html_entity_decode(stripslashes($vals['content'])), 'csec_body', $editor_config); 

Everything is working fine, but when I add a gallery through the media button, it displays the gallery shortcode only (like [gallery link="file" ids="759,760,761"]). There is no usual display of the gallery as in the normal page editor with edit/delete buttons.

I had tried to add the do_shortcode to pass the value in wp_editor, but that displays the full html instead. Also other shortcodes are rendered as html.

Can you please help?

Share Improve this question edited May 1, 2019 at 13:41 sariDon asked May 1, 2019 at 12:55 sariDonsariDon 2651 gold badge2 silver badges18 bronze badges 5
  • Include your w_editor settings $editor_config too – anton Commented May 1, 2019 at 13:36
  • Yes. I did that. $editor_config= array('teeny'=>true, 'textarea_rows'=>10, 'editor_class'=>'csec_text', 'textarea_name'=>'csec_body', 'wpautop'=>false, 'tinymce'=>$tinymce_options); – sariDon Commented May 1, 2019 at 13:38
  • All is working fine except the gallery display.Image edit is also not working too. – sariDon Commented May 1, 2019 at 13:39
  • Try to simply call wp_editor without 3 argument - '$editor_config'. At least we will know if the problem related to settings. – anton Commented May 1, 2019 at 13:44
  • Thanks Anton. It works with the settings removed! I think we need to add something in the settings. – sariDon Commented May 1, 2019 at 13:47
Add a comment  | 

2 Answers 2

Reset to default 1

Make sure tinymce option has a valid value.
Remove it or set it to true if you don't pass any parameters to tinymce

$editor_config = array(
    'teeny'=>true,
    'textarea_rows'=>10, 
    'editor_class'=>'csec_text', 
    'textarea_name'=>'csec_body', 
    'wpautop'=>false, 
    'tinymce'=>$tinymce_options //THIS OPTION SHOULD BE VALID
);

Edit:

Made a small research. Add wpview in plugins argument of tinymce options.

$tinymce_options = array(
    'plugins' => "wpview,lists,link,textcolor,hr",
    //all other options
}


Also, there is no tinymce table plugin.
List of available plugins:

'charmap',
'colorpicker',
'hr',
'lists',
'media',
'paste',
'tabfocus',
'textcolor',
'fullscreen',
'wordpress',
'wpautoresize',
'wpeditimage',
'wpemoji',
'wpgallery',
'wplink',
'wpdialogs',
'wptextpattern',
'wpview',

This piece works perfectly:

$tinymce_options = array(
'plugins' => "paste,lists,link,textcolor,hr,media,wordpress,wpeditimage,wpgallery,wpdialogs,wplink,wpview",
'wordpress_adv_hidden'=> false,
'toolbar1'=>"formatselect,fontsizeselect,forecolor,backcolor,bold,italic,underline,strikethrough,alignleft,aligncenter,alignright,alignjustify,wp_adv",
'toolbar2'=>"blockquote,hr,table,bullist,numlist,outdent,indent,undo,redo,link,unlink,wp_fullscreen,wp_help"
);

Note I have added few wordpress related plugins in the tinymce options.

发布评论

评论列表(0)

  1. 暂无评论