How to add wordpress wysing editor to post category's description textarea

First need to remove html tag remove filter from description value
by bellow filter description will accepts html content also
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );

for add wysing editor to category description just copy and past below class

class Visual_Term_Description_Editor {
public $taxonomies;
public function __construct( $taxonomies ) {
/* Setup the class variables */
$this->taxonomies = (array) $taxonomies;
/* Only users with the "publish_posts" capability can use this feature */
if ( current_user_can( 'publish_posts' ) ) {
/* Remove the filters which disallow HTML in term descriptions */
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );
/* Add filters to disallow unsafe HTML tags */
if ( ! current_user_can( 'unfiltered_html ' ) ) {
add_filter( 'pre_term_description', 'wp_kses_post' );
add_filter( 'term_description', 'wp_kses_post' );
}
}
/* Evaluate shortcodes */
add_filter( 'term_description', 'do_shortcode' );
/* Convert smilies */
add_filter( 'term_description', 'convert_smilies' );
/* Loop through the taxonomies, adding actions */
foreach ( $this->taxonomies as $taxonomy ) {
add_action( $taxonomy . '_edit_form_fields', array( $this, 'render_field_edit' ), 1, 2 );
add_action( $taxonomy . '_add_form_fields', array( $this, 'render_field_add' ), 1, 1 );
}
}
public function render_field_edit( $tag, $taxonomy ) {
$settings = array(
'textarea_name' => 'description',
'textarea_rows' => 10,
);
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="description"><?php _ex( 'Description', 'Taxonomy Description' ); ?></label></th>
<td><?php wp_editor( htmlspecialchars_decode( $tag->description ), 'html-description', $settings ); ?>
<span class="description"><?php _e( 'The description is not prominent by default, however some themes may show it.' ); ?></span></td>
<script type="text/javascript">
// Remove the non-html field
jQuery( 'textarea#description' ).closest( '.form-field' ).remove();
</script>
</tr>
<?php
}
public function render_field_add( $taxonomy ) {
$settings = array(
'textarea_name' => 'description',
'textarea_rows' => 7,
);
?>
<div>
<label for="tag-description"><?php _ex( 'Description', 'Taxonomy Description' ); ?></label>
<?php wp_editor( '', 'html-tag-description', $settings ); ?>
<p class="description"><?php _e( 'The description is not prominent by default, however some themes may show it.' ); ?></p>
<script type="text/javascript">
// Remove the non-html field
jQuery( 'textarea#tag-description' ).closest( '.form-field' ).remove();
jQuery(function() {
// Trigger save
jQuery( '#addtag' ).on( 'mousedown', '#submit', function() {
tinyMCE.triggerSave();
});
});
</script>
</div>
<?php
}
}
function visual_term_description_editor() {
$taxonomies = get_taxonomies( '', 'names' );
$GLOBALS['visual-term-description-editor'] = new Visual_Term_Description_Editor( $taxonomies );
}
add_action( 'wp_loaded', 'visual_term_description_editor', 999 );
function fix_visual_term_description_editor_style() {
echo '<style>.quicktags-toolbar input { width: auto; }</style>';
}
add_action( 'admin_head-edit-tags.php', 'fix_visual_term_description_editor_style' );

Comments

Popular posts from this blog

How to add a custom sorting or order by option on category archive or product archive page in woocommerce wordpress

How to create a custom wp_list_table and bulk action in wordpress

How to add image option in nav menu in wordpress