2012-12-30 56 views
4

我想補充的前端模態對話框(ThickBox的)內的wp_editor但只得到沒有按鈕的空編輯器上(WordPress的3.5和插件開發)添加wp_editor ThickBox時內

的wp_editor是通過阿賈克斯呼籲...

這似乎是一些重要的JavaScripts失蹤的網頁。

是否有可能以某種方式預先編輯我的WP腳本?

下面是一個示例的插件以暴露問題(增加了一個修改鏈接到每個內容):

<?php 
/* 
Plugin Name: ThickboxEditor 
*/ 

$thickboxeditor = new ThickboxEditor(); 

class ThickboxEditor{ 

    function __construct() 
    { 

     add_action('wp_print_styles', array(&$this, 'wp_print_styles')); 
     add_action('init', array(&$this, 'init')); 
     add_filter('the_content', array(&$this, 'the_content')); 
     add_action('wp_ajax_thickboxeditor', array(&$this, 'editor')); 
     add_action('wp_ajax_nopriv_thickboxeditor', array(&$this, 'editor')); 

    } 

    function the_content($content){ 

     $content .= '<a href="' . admin_url('admin-ajax.php') . '?action=thickboxeditor" class="thickbox" title="Add new note">EDIT THICKBOXEDITOR</a>'; 

     return $content; 

    } 

    function editor(){ 

     wp_editor($this->postcontent, 'postcontent', array(
      'media_buttons' => false, 
      'teeny' => false, 
      'textarea_rows' => '7', 
      'tinymce' => array('plugins' => 'inlinepopups, fullscreen, wordpress, wplink, wpdialogs') 
     )); 

     die(0); 

    } 

} 
?> 

UPDATE

由於@danielauener一種解決方案是初始化mceAddControl。因此,這裏是相同的插件的工作示例:

<?php 
/* 
Plugin Name: ThickboxEditor 
*/ 

$thickboxeditor = new ThickboxEditor(); 

class ThickboxEditor{ 

    function __construct() 
    { 

     add_action('wp_print_styles', array(&$this, 'wp_print_styles')); 
     add_action('init', array(&$this, 'init')); 
     add_filter('the_content', array(&$this, 'the_content')); 
     add_action('wp_ajax_thickboxeditor', array(&$this, 'editor')); 
     add_action('wp_ajax_nopriv_thickboxeditor', array(&$this, 'editor')); 
     add_action('wp_footer', array(&$this, 'wp_footer')); 

    } 

    function wp_footer(){ 

     echo '<!--'; 
     wp_editor('', 'invisible_editor_for_initialization'); 
     echo '-->'; 

    } 

    function the_content($content){ 

     $content .= '<a href="' . admin_url('admin-ajax.php') . '?action=thickboxeditor" class="thickbox" title="Add new note">EDIT THICKBOXEDITOR</a>'; 

     return $content; 

    } 

    function editor(){ 

     wp_editor('', 'postcontent', array(
      'media_buttons' => false, 
      'teeny' => false, 
      'textarea_rows' => '7', 
      'tinymce' => array('plugins' => 'inlinepopups, fullscreen, wordpress, wplink, wpdialogs') 
     )); 

     ?> 

     <script language="javascript"> 
      jQuery(document).ready(function(){ 
       tinymce.execCommand('mceAddControl',true,'postcontent'); 
      }); 
     </script> 

     <?php 

     die(0); 

    } 

} 
?> 

這將是非常好的跳過醜陋wp_editor初始化:-)

回答

1

滑稽,那ThickBox時不提供任何回調。但正如我在twitter上所提到的,我會嘗試撥打$.ajaxSuccess來解決醜陋的js-inject問題。只需添加以下到您的JavaScript文件之一:

(function($) { 
    // gets called for every successful ajax call 
    $(document).ajaxSuccess(function(evt, request, settings) { 

     // make sure this call was from your thickbox 
     if ($('#your-thickbox-selector').length > 0) { 
      tinymce.execCommand('mceAddControl',true,'postcontent'); 
     } 
    }); 
})(jQuery); 

UPDATE:ajaxSuccess方法,已被分配給一個元素,改變了代碼

+0

但仍的ajaxSuccess應該被分配到元素? –

+0

沒錯,更新了答案 –