0

I'm trying to add ( using wp_editor ) an HTML Term Description without a pluign. Whenever I try and spit out the data I get escaped HTML back:

&lt;strong&gt;test&lt;/strong&gt; Should be <strong>test</strong>

I tried html_entity_decode() but has unexpected consequences...

<div class="\&quot;big">Test</div> Should be <div class="big blue">Test</div>

I've tried removing wp_kses filters like other answers have suggested but it doesn't seem to have any kind of affect.

remove_filter( 'pre_term_description', 'wp_filter_kses', 20 );
remove_filter( 'term_description', 'wp_kses_data', 20 );

Here's where I'm actually displaying the editor:

/**
 * Adds additional fields to terms
 * @param Object $term
 * @return void
 */
function extra_category_fields( $term ) {
  ?>

    <style type="text/css">
        tr.form-field.term-description-wrap {display:none!important;}
    </style>

    <tr class="form-field">
        <th scope="row" valign="top"><label for="meta-content"><?php _e( 'Description' ); ?></label></th>
        <td>
            <div id="catContent">
                <style type="text/css">.form-field input {width: auto!important;}</style>
                <?php wp_editor( $term->description, 'term_desc', array(
                        'textarea_name' =>  '_term_desc',
                        'textarea_rows' =>  15,
                    ) ); 
                ?>
            </div>
            <span class="description"><?php _e( 'The description is not prominent by default.' ); ?></span>
        </td> 
    </tr>

  <?php
}
add_action( 'tax_class_edit_form_fields', 'extra_category_fields' );

Here's what I'm actually updating the data:

/** 
 * Save Term Meta
 * @param int $term_id
 * @return void
 */
function save_extra_category_fileds( $term_id ) {
    global $wpdb;

    if( isset( $_POST['_term_desc'] ) && ! empty( $_POST['_term_desc'] ) ) {
        $wpdb->update( $wpdb->term_taxonomy, array( 'description' => $_POST['_term_desc'] ), array( 'term_id' => $term_id ) );
    } else {
        $wpdb->update( $wpdb->term_taxonomy, array( 'description' => '' ), array( 'term_id' => $term_id ) );
    }
}
add_action( 'edited_tax_class', 'save_extra_category_fileds' );

Does it have to do with how I'm displaying it or how I'm saving it? How can I store / save HTML in Term Descriptions?

0

1 Answer 1

2

The only way I can see for getting this to work is running the output through html_entity_decode() and stripslashes() and saving it with esc_attr():

Saving the term:

$wpdb->update( $wpdb->term_taxonomy, array( 'description' => esc_attr( $_POST['_term_desc'] ) ), array( 'term_id' => $term_id ) );

Showing the term on the front end:

echo apply_filters( 'the_content', html_entity_decode( stripslashes( $term->description ) ) );

Showing the content in the editor:

<?php wp_editor( html_entity_decode( stripslashes( $term->description ) ), 'term_desc', array(
        'textarea_name' =>  '_term_desc',
        'textarea_rows' =>  15,
    ) ); 
?>

Your Answer

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

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