WP_Post_Type::set_props( array|string $args )
- Since
- 4.6.0
- Source
wp-includes/class-wp-post-type.php:490
Description
See the register_post_type() function for accepted arguments for $args.
Compatibility
- WordPress
- since 4.6.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
$argsarray|string- Array or string of arguments for registering a post type.
Performance profile
How much work a call to WP_Post_Type::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
- 98–163
- 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 210.
Third-party callbacks on 'register_post_type_args', 'register_{$post_type}_post_type_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_Post_Type::set_props() - serializeserialisation
maybe_unserialize()one call below WP_Post_Type::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 · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Post_Type::set_props() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($args) | 98–110 | wp_parse_args(), apply_filters(), apply_filters(), array_merge(), get_post_type_capabilities(), get_post_type_labels() |
!empty($args) && !is_admin() | 105–160 | wp_parse_args(), apply_filters(), apply_filters(), array_merge(), get_post_type_capabilities(), is_admin(), get_option(), get_post_type_labels() |
!empty($args) && $args | 108–113 | wp_parse_args(), apply_filters(), apply_filters(), array_merge(), get_post_type_capabilities(), sanitize_title_with_dashes(), get_post_type_labels() |
!empty($args) && $args && !is_admin() | 115–163 | wp_parse_args(), apply_filters(), apply_filters(), array_merge(), get_post_type_capabilities(), sanitize_title_with_dashes(), is_admin(), get_option(), get_post_type_labels() |
!empty($args) && is_admin() | 121–156 | wp_parse_args(), apply_filters(), apply_filters(), array_merge(), get_post_type_capabilities(), is_admin(), get_post_type_labels() |
!empty($args) && $args && is_admin() | 131–159 | wp_parse_args(), apply_filters(), apply_filters(), array_merge(), get_post_type_capabilities(), sanitize_title_with_dashes(), is_admin(), get_post_type_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 210 | 98–163 | 32 | |
| 8.5 | 210 | 98–163 | 32 | |
| 8.4 | 210 | 98–163 | 32 | |
| 8.3 | 210 | 98–163 | 32 | |
| 8.2 | 210 | 98–163 | 32 | |
| 8.1 | 210 | 98–163 | 32 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 211 | 98–164 | 32 |
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_Post_Type::set_props() runs, in this order:
- apply_filters( register_post_type_args )filterline 502 (+12 into the body)
Filters the arguments for registering a post type.
- apply_filters( register_{$post_type}_post_type_args )filterline 523 (+33 into the body)
Filters the arguments for registering a specific post type.
Uses · 7
- wp_parse_args()Merges user defined arguments into defaults array.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_post_type_capabilities()Builds an object with all post type capabilities out of a post type object
- sanitize_title_with_dashes()Sanitizes a title, replacing whitespace and a few other characters with dashes.
- is_admin()Determines whether the current request is for an administrative interface page.
- get_option()Retrieves an option value based on an option name.
- get_post_type_labels()Builds an object with all post type labels out of a post type object.
Used by · 1
- WP_Post_Type::__construct()Constructor.
Source code
public function set_props( $args ) { $args = wp_parse_args( $args ); /** * Filters the arguments for registering a post type. * * @since 4.4.0 * * @param array $args Array of arguments for registering a post type. * See the register_post_type() function for accepted arguments. * @param string $post_type Post type key. */ $args = apply_filters( 'register_post_type_args', $args, $this->name ); $post_type = $this->name; /** * Filters the arguments for registering a specific post type. * * The dynamic portion of the filter name, `$post_type`, refers to the post type key. * * Possible hook names include: * * - `register_post_post_type_args` * - `register_page_post_type_args` * * @since 6.0.0 * @since 6.4.0 Added `late_route_registration`, `autosave_rest_controller_class` and `revisions_rest_controller_class` arguments. * * @param array $args Array of arguments for registering a post type. * See the register_post_type() function for accepted arguments. * @param string $post_type Post type key. */ $args = apply_filters( "register_{$post_type}_post_type_args", $args, $this->name ); $has_edit_link = ! empty( $args['_edit_link'] ); // Args prefixed with an underscore are reserved for internal use. $defaults = array( 'labels' => array(), 'description' => '', 'public' => false, 'hierarchical' => false, 'exclude_from_search' => null, 'publicly_queryable' => null, 'embeddable' => null, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_in_admin_bar' => null, 'menu_position' => null, 'menu_icon' => null, 'capability_type' => 'post', 'capabilities' => array(), 'map_meta_cap' => null, 'supports' => array(), 'register_meta_box_cb' => null, 'taxonomies' => array(), 'has_archive' => false, 'rewrite' => true, 'query_var' => true, 'can_export' => true, 'delete_with_user' => null, 'show_in_rest' => false, 'rest_base' => false, 'rest_namespace' => false, 'rest_controller_class' => false, 'autosave_rest_controller_class' => false, 'revisions_rest_controller_class' => false, 'late_route_registration' => false, 'template' => array(), 'template_lock' => false, '_builtin' => false, '_edit_link' => 'post.php?post=%d', ); $args = array_merge( $defaults, $args ); $args['name'] = $this->name;Changelog
Introduced in 4.6.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-post-type.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.