3

wp_editor を使用して、正常に機能するフロントエンド エディターを作成しました。

テストの結果、コンテンツに挿入されたショートコードが取り除かれていることがわかりました。この問題を調べたところ、それらを削除しているのは「ob_」(出力バッファリング) であることがわかりました。この出力バッファリングを削除すると、ショートコードは正常に表示されますが、エディター用に作成した機能が壊れます。

以下で使用しているコードを保持し、すべてのショートコードが表示されるように修正するにはどうすればよいですか? どんな助け/アイデアも大歓迎です、S.

if(!is_feed() && current_user_can( 'manage_network' ) ) :

function ps_add_post_editor($content) {
global $post;
$settings = array(
    'wpautop' => true,
    'media_buttons' => false
);
    $content .= '<div id="content-edit-area" style="display:none;"><form action="" id="page-content-editor-panel" method="post"><span id="ajax_my_post_edit_nonce" class="hidden">' . wp_create_nonce( 'ajax_my_post_edit_nonce' ) . '</span>' . ps_get_wp_editor($post->post_content, 'textarea-' . $post->ID , $settings) . '<input type="submit" id="feesavebtn" value="Save" /></form><a href="#" id="cancelbtn">Cancel</a></div><br><br><div id="loadingmessage"><img src="'.get_template_directory_uri().'/images/loading.gif" /> saving...</div>

    <style type="text/css">
        #textarea-'.$post->ID.'_ifr, #textarea-'.$post->ID.' { min-height:700px !important; }
    </style>

    <script type="text/javascript">
    jQuery(\'#page-content-editor-panel\').submit(function(){       
    var pageid = '.$post->ID.'; 
    var content;
    var editor = tinyMCE.get(\'textarea-'.$post->ID.'\');
    if (editor) {
        content = editor.getContent();
    } else {
        content = jQuery(\'#textarea-'.$post->ID.'\').val();
    }       
    jQuery(\'#content-edit-area\').hide();  
    jQuery(\'#loadingmessage\').show(); 
    jQuery.post(
       ajaxurl, 
       {
          \'action\':\'add_foobar\',
          \'nonce\':jQuery(\'#ajax_my_post_edit_nonce\').text(),
          \'post_id\':pageid,
          \'post_data\':content
       }, 
       function(response){            
          window.location.reload(true); 
       }
    ); 
    return false;        
    });
    </script>';

return $content;
}

function ps_get_wp_editor($content,$textarea,$settings) {
ob_start();
wp_editor($content, $textarea, $settings);
$edior_html_code = ob_get_contents();
ob_end_clean();
return $edior_html_code;
} 
add_filter('the_content', 'ps_add_post_editor');

add_action('wp_ajax_add_foobar', 'prefix_ajax_add_foobar');
add_action('wp_ajax_nopriv_add_foobar', 'prefix_ajax_add_foobar');

function prefix_ajax_add_foobar() {
if( wp_verify_nonce( $_REQUEST['nonce'], 'ajax_my_post_edit_nonce' ) )           {      
    $myfee_post = array();
    $myfee_post['ID'] = $_POST['post_id'];
    $myfee_post['post_content'] = $_POST['post_data'];
    wp_update_post( $myfee_post );      
    die("This page has now been updated."); 
} else {        
    die("Unable to process your request at this time.");
}
}

endif;
4

1 に答える 1

1

認めざるを得ませんが、あなたの目標が何であるかは完全にはわかりませんが、それだけの価値があるため、これは私にとってはうまくいくようです:

remove_filter('the_content', 'do_shortcode', 11);

function ps_get_wp_editor($content,$textarea,$settings = array()) {
   ob_start();
   wp_editor($content, $textarea, $settings);
   $editor_html_code = ob_get_contents();
   ob_end_clean();
   return $editor_html_code;
}

function ps_add_post_editor($content) {
    global $post;

    $post_content = $post->post_content;
    $content = ps_get_wp_editor($post_content, 'ps-editor-' . $post->ID );
    return $content;
}
add_filter('the_content', 'ps_add_post_editor');

function ps_eat_pants() {
    return "eat pants has happened";
}
add_shortcode('eat_pants', 'ps_eat_pants');

問題は、ショートコードを編集できるようにしたい場合は、バックエンドのエディターにあったように、「do_shortcode」フィルターを「the_content」から削除して、前面に表示されたときに実行されないようにする必要があることです。終わり。

認めざるを得ませんが、あなたが投稿したコードが実際にどのように機能したかはわかりません。入力ミスか文脈から外れていると思います。=)

つまり、実際に関数に必要なすべてのパラメーターを与えている時点はありませんでした...

もっと詳しく説明していただけると助かりますが、参考になれば幸いです。

[編集: ああ、その「eat_pants」は単なるテスト ショートコードです...]

于 2013-08-29T13:25:12.557 に答える