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 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3