WP_Taxonomy::set_props( string|string[] $object_type, array|string $args )
- Since
- 4.7.0
- Source
wp-includes/class-wp-taxonomy.php:303
Description
See the register_taxonomy() function for accepted arguments for $args.
Compatibility
- WordPress
- since 4.7.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
$object_typestring|string[]- Name or array of names of the object types for the taxonomy.
$argsarray|string- Array or query string of arguments for registering a taxonomy.
Performance profile
How much work a call to WP_Taxonomy::set_props() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 132–176
- Plugin surface
- 2 hooks
- Called by
- 1
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 244.
Third-party callbacks on 'register_taxonomy_args', 'register_{$taxonomy}_taxonomy_args' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()called directly - cacheobject cache
wp_cache_get()one call below WP_Taxonomy::set_props() - serializeserialisation
maybe_unserialize()one call below WP_Taxonomy::set_props()
Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
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 WP_Taxonomy::set_props() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($args) | 132–161 | wp_parse_args(), apply_filters(), apply_filters(), array_merge(), array_merge(), array_unique(), get_taxonomy_labels() |
!empty($args) | 143–176 | wp_parse_args(), apply_filters(), apply_filters(), array_merge(), array_merge(), array_unique(), wp_parse_args(), get_taxonomy_labels() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 244 instructions, 132–176 executed per call, 26 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.
Hooks and filters fired · 2
2 hooks fire while WP_Taxonomy::set_props() runs, in this order:
- apply_filters( register_taxonomy_args )filterline 316 (+13 into the body)
Filters the arguments for registering a taxonomy.
- apply_filters( register_{$taxonomy}_taxonomy_args )filterline 337 (+34 into the body)
Filters the arguments for registering a specific taxonomy.
Uses · 6
- wp_parse_args()Merges user defined arguments into defaults array.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- is_admin()Determines whether the current request is for an administrative interface page.
- sanitize_title_with_dashes()Sanitizes a title, replacing whitespace and a few other characters with dashes.
- get_option()Retrieves an option value based on an option name.
- get_taxonomy_labels()Builds an object with all taxonomy labels out of a taxonomy object.
Used by · 1
- WP_Taxonomy::__construct()Constructor.
Source code
public function set_props( $object_type, $args ) { $args = wp_parse_args( $args ); /** * Filters the arguments for registering a taxonomy. * * @since 4.4.0 * * @param array $args Array of arguments for registering a taxonomy. * See the register_taxonomy() function for accepted arguments. * @param string $taxonomy Taxonomy key. * @param string[] $object_type Array of names of object types for the taxonomy. */ $args = apply_filters( 'register_taxonomy_args', $args, $this->name, (array) $object_type ); $taxonomy = $this->name; /** * Filters the arguments for registering a specific taxonomy. * * The dynamic portion of the filter name, `$taxonomy`, refers to the taxonomy key. * * Possible hook names include: * * - `register_category_taxonomy_args` * - `register_post_tag_taxonomy_args` * * @since 6.0.0 * * @param array $args Array of arguments for registering a taxonomy. * See the register_taxonomy() function for accepted arguments. * @param string $taxonomy Taxonomy key. * @param string[] $object_type Array of names of object types for the taxonomy. */ $args = apply_filters( "register_{$taxonomy}_taxonomy_args", $args, $this->name, (array) $object_type ); $defaults = array( 'labels' => array(), 'description' => '', 'public' => true, 'publicly_queryable' => null, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'show_in_quick_edit' => null, 'show_admin_column' => false, 'meta_box_cb' => null, 'meta_box_sanitize_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $this->name, 'update_count_callback' => '', 'show_in_rest' => false, 'rest_base' => false, 'rest_namespace' => false, 'rest_controller_class' => false, 'default_term' => null, 'sort' => null, 'args' => null, '_builtin' => false, ); $args = array_merge( $defaults, $args ); // If not set, default to the setting for 'public'. if ( null === $args['publicly_queryable'] ) { $args['publicly_queryable'] = $args['public']; } if ( false !== $args['query_var'] && ( is_admin() || false !== $args['publicly_queryable'] ) ) { if ( true === $args['query_var'] ) { $args['query_var'] = $this->name; } else { $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] ); } } else { // Force 'query_var' to false for non-public taxonomies. $args['query_var'] = false;Changelog
Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-taxonomy.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.