WP 3.9 TinyMCE不再加载到类别描述编辑器上


8

自WP 3.5起,我就在functions.php中使用了以下脚本

它将标准类别描述编辑器转换为RTF编辑器。不幸的是,在将站点升级到WP 3.9之后,描述编辑器又回到了标准文本区域。

有什么想法需要更改3.9吗?

add_action('load-categories.php', 'cb_admin_init');
add_action('load-edit-tags.php', 'cb_admin_init');

function cb_admin_init()
{
    if ( user_can_richedit() && isset($_GET['action']) && 'edit' === $_GET['action'] && ( !empty($_GET['cat_ID']) || ( !empty($_GET['taxonomy']) && !empty($_GET['tag_ID']) ) ) ){
        add_filter( 'tiny_mce_before_init', 'cb_mceinit');
        add_action('admin_footer', 'wp_tiny_mce');
        add_action('admin_head', 'cb_head');
    }
}

function cb_mceinit($init)
{
    $init['mode'] = 'exact';
    $init['editor_selector'] = 'description';
    $init['elements'] = 'category_description,description';
    $init['plugins'] = 'safari,inlinepopups,spellchecker,paste,fullscreen';
    $init['theme_advanced_buttons1'] .= ',image';
    $init['theme_advanced_buttons2'] .= ',code';
    $init['onpageload'] = '';
    $init['save_callback'] = '';
    return $init;
}

function cb_head()
{
wp_enqueue_style('editor-buttons');
    ?>
<style type="text/css">#category_description_tbl,#description_tbl{border:1px solid #dfdfdf;}.wp_themeSkin .mceStatusbar{border-color:#dddddd;}</style><?php
}


add_action('init', 'cb_editor_init');

您在代码示例中缺少cb_editor_init函数
NoBugs,2014年

Answers:


1

我遇到了同样的问题,问题实际上出在js动态生成tinyMCE的方式上。

在v.4之前,它是:

tinymce.EditorManager.execCommand('mceAddControl', true, id);

对于4,您需要使用:

tinymce.EditorManager.execCommand('mceAddEditor', true, id);

看看您的函数“ wp_tiny_mce”在哪里-可能在那里。


1

这是执行此操作的示例完整代码。另请参阅参考链接

// Add term page
function pippin_taxonomy_add_new_meta_field() {
    // this will add the custom meta field to the add new term page
    ?>
    <div class="form-field">
        <label for="term_meta[custom_term_meta]"><?php _e( 'Example meta field', 'pippin' ); ?></label>
        <?php wp_editor( $content,'term_meta[custom_term_meta]') ?>
        <p class="description"><?php _e( 'Enter a value for this field','pippin' ); ?></p>
    </div>
<?php
}
add_action( 'category_add_form_fields', 'pippin_taxonomy_add_new_meta_field', 10, 2 );
add_action( 'category_add_form_fields', 'pippin_taxonomy_add_new_meta_field', 10, 2 );


add_action( 'genres_add_form_fields', 'pippin_taxonomy_add_new_meta_field', 10, 2 );

// Edit term page
function pippin_taxonomy_edit_meta_field($term) {

    // put the term ID into a variable
    $t_id = $term->term_id;

    // retrieve the existing value(s) for this meta field. This returns an array
    $term_meta = get_option( "taxonomy_$t_id" ); ?>
    <tr class="form-field">
    <th scope="row" valign="top"><label for="term_meta[custom_term_meta]"><?php _e( 'Example meta field', 'pippin' ); ?></label></th>
        <td>
            <?php $content = esc_attr( $term_meta['custom_term_meta'] ) ? esc_attr( $term_meta['custom_term_meta'] ) : '';
             wp_editor( $content,'term_meta[custom_term_meta]') ?>
            <p class="description"><?php _e( 'Enter a value for this field','pippin' ); ?></p>
        </td>
    </tr>
<?php
}
add_action( 'category_edit_form_fields', 'pippin_taxonomy_edit_meta_field', 10, 2 );



// Save extra taxonomy fields callback function.
function save_taxonomy_custom_meta( $term_id ) {
    if ( isset( $_POST['term_meta'] ) ) {
        $t_id = $term_id;
        $term_meta = get_option( "taxonomy_$t_id" );
        $cat_keys = array_keys( $_POST['term_meta'] );
        foreach ( $cat_keys as $key ) {
            if ( isset ( $_POST['term_meta'][$key] ) ) {
                $term_meta[$key] = $_POST['term_meta'][$key];
            }
        }
        // Save the option array.
        update_option( "taxonomy_$t_id", $term_meta );
    }
}  
add_action( 'edited_category', 'save_taxonomy_custom_meta', 10, 2 );  
add_action( 'create_category', 'save_taxonomy_custom_meta', 10, 2 );


add_action( 'edited_genres', 'save_taxonomy_custom_meta', 10, 2 );  
add_action( 'create_genres', 'save_taxonomy_custom_meta', 10, 2 );
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.