wppaste
WordPress

WP_Post_Type::set_props( array|string $args )

Since
4.6.0
Source
wp-includes/class-wp-post-type.php:490
Sets post type properties.

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

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
98–163

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 210.

Plugin surface
2 hooks

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.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()called directly
  • cacheobject cachewp_cache_get()one call below WP_Post_Type::set_props()
  • serializeserialisationmaybe_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.

WhenInstructionsCalls it makes
!empty($args)98–110wp_parse_args(), apply_filters(), apply_filters(), array_merge(), get_post_type_capabilities(), get_post_type_labels()
!empty($args) && !is_admin()105–160wp_parse_args(), apply_filters(), apply_filters(), array_merge(), get_post_type_capabilities(), is_admin(), get_option(), get_post_type_labels()
!empty($args) && $args108–113wp_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–163wp_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–156wp_parse_args(), apply_filters(), apply_filters(), array_merge(), get_post_type_capabilities(), is_admin(), get_post_type_labels()
!empty($args) && $args && is_admin()131–159wp_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

PHPCompiledExecutedBranchesNotes
8.6-dev21098–16332
8.521098–16332
8.421098–16332
8.321098–16332
8.221098–16332
8.121098–163321 fewer instruction than PHP 7.4
7.421198–16432

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:

  1. apply_filters( register_post_type_args )filterline 502 (+12 into the body)

    Filters the arguments for registering a post type.

  2. 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

Used by · 1

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.