In your cats, making them back compat.

git-svn-id: https://develop.svn.wordpress.org/trunk@5818 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2007-07-25 03:04:46 +00:00
parent 706c581757
commit e83be1d2ca
1 changed files with 38 additions and 3 deletions

View File

@ -18,13 +18,22 @@ function &get_categories($args = '') {
$taxonomy = 'category';
if ( 'link' == $args['type'] )
$taxonomy = 'link_category';
return get_terms($taxonomy, $args);
$categories = get_terms($taxonomy, $args);
foreach ( $categories as $category )
_make_cat_compat($category);
return $categories;
}
// Retrieves category data given a category ID or category object.
// Handles category caching.
function &get_category(&$category, $output = OBJECT) {
return get_term($category, 'category', $output);
$category = get_term($category, 'category', $output);
_make_cat_compat($category);
return $category;
}
function get_category_by_path($category_path, $full_match = true, $output = OBJECT) {
@ -64,7 +73,11 @@ function get_category_by_path($category_path, $full_match = true, $output = OBJE
}
function get_category_by_slug( $slug ) {
return get_term_by('slug', $slug, 'category');
$category = get_term_by('slug', $slug, 'category');
if ( $category )
_make_cat_compat($category);
return $category;
}
// Get the ID of a category from its name
@ -139,4 +152,26 @@ function clean_category_cache($id) {
clean_term_cache($id, 'category');
}
//
// Private helpers
//
function _make_cat_compat( &$category) {
if ( is_object($category) ) {
$category->cat_ID = &$category->term_id;
$category->category_count = &$category->count;
$category->category_description = &$category->description;
$category->cat_name = &$category->name;
$category->category_nicename = &$category->slug;
$category->category_parent = &$category->parent;
} else if ( is_array($category) && isset($category['term_id']) ) {
$category['cat_ID'] = &$category['term_id'];
$category['category_count'] = &$category['count'];
$category['category_description'] = &$category['description'];
$category['cat_name'] = &$category['name'];
$category['category_nicename'] = &$category['slug'];
$category['category_parent'] = &$category['parent'];
}
}
?>