Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_make_cat_compat() WordPress Function

The make_cat_compat() WordPress function makes it easy to run a category-specific template on your website. This function will first check if a category-specific template exists for the current category, and if so, will use that template. If no category-specific template exists, it will use the default template.

_make_cat_compat( array|object|WP_Term $category ) #

Updates category structure to old pre-2.3 from new taxonomy structure.


Description

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.


Top ↑

Parameters

$category

(array|object|WP_Term)(Required)Category row object or array.


Top ↑

Source

File: wp-includes/category.php

function _make_cat_compat( &$category ) {
	if ( is_object( $category ) && ! is_wp_error( $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;
	} elseif ( 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'];
	}
}


Top ↑

Changelog

Changelog
VersionDescription
4.4.0The $category parameter now also accepts a WP_Term object.
2.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.