dqr91899 2019-04-16 20:40
浏览 42
已采纳

使用第二个WordPress内容编辑器(wysiwyg)插入图像时,不会呈现图像[caption]元数据

I have deployed some code into functions.php that gives me a second CLASSIC WYSIWYG / text editor (not dealing with Gutenberg right now) so that I can populate content for each post from both editors. Whenever I am editing a post, I see two wizzy's (the second editor is displayed in the admin area using a meta_box).

Having a second editor allows me to insert other code (like ads and other things) in between where each editor outputs to the page.

All works great except that when I insert images into the second editor, the caption data is escaped rather than rendered as the friendly caption text.

Below is the code for the second editor in functions.php.

     function custom_editor2_meta_box() {    
               add_meta_box ( 
                  'custom-editor2', 
                  __('Second Content Area', 'custom-editor2') , 
                  'custom_editor2',
                  'post'
               );

     }

     //Displaying the meta box
     function custom_editor2($post) {          
              echo "<h3>Second content area that appears after the inline advertisement.</h3>";
              $content = get_post_meta($post->ID, 'custom_editor2', true);

              //This function adds the WYSIWYG Editor 
              wp_editor ( 
                $content , 
                'custom_editor2', 
                array ( "media_buttons" => true ) 
              );

     }

     //This function saves the data you put in the meta box
     function custom_editor2_save_postdata($post_id) {


        if( isset( $_POST['custom_editor_nonce'] ) && isset( $_POST['second'] ) ) {

            //Not save if the user hasn't submitted changes
            if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
            return;
            } 

            // Verifying whether input is coming from the proper form
            if ( ! wp_verify_nonce ( $_POST['custom_editor_nonce'] ) ) {
            return;
            } 

            // Making sure the user has permission
            if( 'post' == $_POST['second'] ) {
                   if( ! current_user_can( 'edit_post', $post_id ) ) {
                        return;
                   }
            } 
        } 

        if (!empty($_POST['custom_editor2'])) {

            $data = $_POST['custom_editor2'];
            if (strlen($data) > 0) { update_post_meta($post_id, 'custom_editor2', $data); }

        }

     }

    add_action('save_post', 'custom_editor2_save_postdata'); 
    add_action('admin_init', 'custom_editor2_meta_box');

What I expect to see is the image rendered and then the friendly text below it. Instead I see the [caption] syntax itself before and after the properly rendered image, as if the syntax was completely ignored by WordPress:

[caption id="attachment_165" align="alignnone" width="900"]

(Image is rendered properly because this is where the image tag is located within the caption syntax)

Friendly caption text is here[/caption]

  • 写回答

1条回答 默认 最新

  • dss89001 2019-04-16 22:56
    关注

    It looks like you want the caption shortcode to be processed in the WYSIWYG editor? This is not the intended function inside the WYSIWYG, which is meant to show the raw shortcode. If it's not displaying correctly on the frontend (template) try wrapping your call to print the content of the editor in do_shortcode.

    You could possibly try outputting your content into the editor using do_shortcode but that would only work once. I.e. once the shortcode is converted to HTML you'll have HTML floating around in your editor.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机数字电压表电路组成及框图
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line