8

I've used this script below inside functions.php since WP 3.5

It converts the standard category description editor to a rich text editor. Unfortunately, after upgrading sites to WP 3.9, the description editor is back to a standard text area.

Any ideas what I need to change for 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');
1
  • You're missing cb_editor_init function in the code sample
    – NoBugs
    May 17, 2014 at 6:01

2 Answers 2

1

I was having the same issue and the problem was actually coming from the way the js was dynamically generating tinyMCE.

Prior to v.4, it was:

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

With 4, you need to use:

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

Have a look at wherever your function 'wp_tiny_mce' is - might be in there.

1

Here is the sample complete code to do this. See reference link also.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.