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

时间:2014-04-17 作者:N2Mystic

我在函数中使用了下面的脚本。自WP 3.5以来的php

它将标准类别描述编辑器转换为富文本编辑器。不幸的是,在将站点升级到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\');

2 个回复
SO网友:Pat Gilmour

我也遇到了同样的问题,而问题实际上来自js动态生成tinyMCE的方式。

在第4节之前,它是:

tinymce.EditorManager.execCommand(\'mceAddControl\', true, id);
对于4,您需要使用:

tinymce.EditorManager.execCommand(\'mceAddEditor\', true, id);
看看你的函数“wp\\u tiny\\u mce”在哪里-可能在那里。

SO网友:Hakkim

下面是完成此操作的完整代码示例。参见参考link 而且

// 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 );

结束