_make_cat_compat( array|object|WP_Term $category )
- Since
- 2.3.0, 4.4.0
- Source
wp-includes/category.php:377
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.
Compatibility
- WordPress
- since 4.4.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$categoryarray|object|WP_Term- Category row object or array.
Performance profile
How much work a call to _make_cat_compat() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 6–36
- Plugin surface
- None
- Called by
- 8
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 55.
Nothing here hands control to plugin code.
8 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action()one call below _make_cat_compat()
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _make_cat_compat() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_object($category) | 6–32 | none |
is_object($category) | 10–36 | is_wp_error() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 55 instructions, 6–36 executed per call, 4 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 1
- is_wp_error()Checks whether the given variable is a WordPress Error.
Used by · 8
- WP_Query::get_queried_object()Retrieves the currently queried object.
- get_categories()Retrieves a list of category objects.
- get_category()Retrieves category data given a category ID or category object.
- get_category_by_path()Retrieves a category based on URL containing the category slug.
- get_category_by_slug()Retrieves a category object by category slug.
- get_category_to_edit()Gets category object for given ID and 'edit' filter context.
- get_the_category()Retrieves post categories.
- wp_update_category()Aliases wp_insert_category() with minimal args.
Source code
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']; }}Changelog
Introduced in 2.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$category parameter now also accepts a WP_Term object.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/category.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.