_make_cat_compat

Update category structure to old pre 2.3 from new taxonomy structure.

Description

_make_cat_compat( (array|object|WP_Term) &$category ); 

This function was added for the taxonomy support to update the new category structure with the old category one. This will maintain compatibility with plugins and themes which depend on the old key or property names.

The parameter should only be passed a variable and not create the array or object inline to the parameter. The reason for this is that parameter is passed by reference and PHP will fail unless it has the variable.

There is no return value, because everything is updated on the variable you pass to it. This is one of the features with using pass by reference in PHP.

Parameters (1)

0. $category (array|object|WP_Term) => &$category
Category Row object or array

Usage

  1. if ( !function_exists( '_make_cat_compat' ) ) { 
  2. require_once ABSPATH . WPINC . '/category.php'; 
  3.  
  4. // Category Row object or array 
  5. $category = &$category; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _make_cat_compat($category); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/category.php  
  1. function _make_cat_compat( &$category ) { 
  2. if ( is_object( $category ) && ! is_wp_error( $category ) ) { 
  3. $category->cat_ID = $category->term_id; 
  4. $category->category_count = $category->count; 
  5. $category->category_description = $category->description; 
  6. $category->cat_name = $category->name; 
  7. $category->category_nicename = $category->slug; 
  8. $category->category_parent = $category->parent; 
  9. } elseif ( is_array( $category ) && isset( $category['term_id'] ) ) { 
  10. $category['cat_ID'] = &$category['term_id']; 
  11. $category['category_count'] = &$category['count']; 
  12. $category['category_description'] = &$category['description']; 
  13. $category['cat_name'] = &$category['name']; 
  14. $category['category_nicename'] = &$category['slug']; 
  15. $category['category_parent'] = &$category['parent'];