Skip to content

Instantly share code, notes, and snippets.

@rdworth
Created June 19, 2012 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdworth/2953991 to your computer and use it in GitHub Desktop.
Save rdworth/2953991 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Better Category Description
Plugin URI: http://www.learningjquery.com/
Description: Allows full HTML in Category Descriptions.
Author: Karl Swedberg
Author URI: http://www.learningjquery.com/
Version: 1.0
Copyright (c) 2010 Karl Swedberg (http://www.learningjquery.com)
Dual licensed under the MIT or GPL Version 2 licenses.
* For GPL2, see http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
MIT License:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
add_action('init', 'better_cat_desc');
function better_cat_desc() {
if ( ( is_admin() || defined('DOING_AJAX') ) && current_user_can('manage_categories') ) {
remove_filter('pre_term_description', 'wp_filter_kses');
}
}
// KARL'S ADDITION TO ALLOW HTML IN CATEGORY DESCRIPTIONS
function ks_term_description( $category = 0, $taxonomy = 'category') {
if ( !$term && ( is_tax() || is_tag() || is_category() ) ) {
global $wp_query;
$term = $wp_query->get_queried_object();
$taxonomy = $term->taxonomy;
$term = $term->term_id;
}
return ks_get_term_field( 'description', $term, $taxonomy );
}
function ks_get_term_field( $field, $term, $taxonomy, $context = 'display' ) {
$term = (int) $term;
$term = get_term( $term, $taxonomy );
if ( is_wp_error($term) )
return $term;
if ( !is_object($term) )
return '';
if ( !isset($term->$field) )
return '';
if ( preg_match('@</(p(re)?|div|ul|ol)@', $term->$field) ) {
$context = 'raw';
}
return sanitize_term_field($field, $term->$field, $term->term_id, $taxonomy, $context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment