wppaste
WordPress

WP_Ability_Category::__construct( string $slug, array $args )

Since
6.9.0
Source
wp-includes/abilities-api/class-wp-ability-category.php:76
Constructor.

Description

Do not use this constructor directly. Instead, use the wp_register_ability_category() function.

Compatibility

WordPress
since 6.9.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 3 of the 5 tracked releases, added in 6.9.0, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$slugstring
The unique slug for the ability category.
$argsarray

Performance profile

How much work a call to WP_Ability_Category::__construct() 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
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

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

Instructions
11–14

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

Plugin surface
None

Nothing here hands control to plugin code.

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 callbacksdo_action()one call below WP_Ability_Category::__construct()

Further down the call graph this can also reach option, cache, serialize, 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_Ability_Category::__construct() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
empty($slug)11__()
!empty($slug)13–14->prepare_properties()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev5511–144
8.55511–144
8.45511–1443 fewer instructions than PHP 8.3
8.35811–144
8.25811–144
8.15811–144
7.45811–144

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 · 5

Used by · 1

Source code

	public function __construct( string $slug, array $args ) {		if ( empty( $slug ) ) {			throw new InvalidArgumentException(				__( 'The ability category slug cannot be empty.' )			);		} 		$this->slug = $slug; 		$properties = $this->prepare_properties( $args ); 		foreach ( $properties as $property_name => $property_value ) {			if ( ! property_exists( $this, $property_name ) ) {				_doing_it_wrong(					__METHOD__,					sprintf(						/* translators: %s: Property name. */						__( 'Property "%1$s" is not a valid property for ability category "%2$s". Please check the %3$s class for allowed properties.' ),						'<code>' . esc_html( $property_name ) . '</code>',						'<code>' . esc_html( $this->slug ) . '</code>',						'<code>' . __CLASS__ . '</code>'					),					'6.9.0'				);				continue;			} 			$this->$property_name = $property_value;		}	}

Changelog

Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.

  1. 6.9.7
  2. 7.0.4
  3. 7.1.0

Signature, return type and hooks compared across 3 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/abilities-api/class-wp-ability-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.