WP_Ability_Categories_Registry::register( string $slug, array $args ): WP_Ability_Category|null
- Since
- 6.9.0
- Source
wp-includes/abilities-api/class-wp-ability-categories-registry.php:57
Description
Do not use this method 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. Must contain only lowercase alphanumeric characters and dashes.
$argsarray
Return value
WP_Ability_Category|null- The registered ability category instance on success, null on failure.
Performance profile
How much work a call to WP_Ability_Categories_Registry::register() 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
- 17–25
- Plugin surface
- 1 hook
- Called by
- 0
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 59.
Third-party callbacks on 'wp_register_ability_category_args' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly
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 · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Ability_Categories_Registry::register() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!->is_registered() && !$slug | 17 | ->is_registered(), __(), _doing_it_wrong() |
->is_registered() | 22 | ->is_registered(), __(), esc_html(), sprintf(), _doing_it_wrong() |
!->is_registered() && $slug | 25 | ->is_registered(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 59 | 17–25 | 2 | |
| 8.5 | 59 | 17–25 | 2 | |
| 8.4 | 59 | 17–25 | 2 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 62 | 20–28 | 2 | |
| 8.2 | 62 | 20–28 | 2 | |
| 8.1 | 62 | 20–28 | 2 | |
| 7.4 | 62 | 20–28 | 2 |
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 · 1
One hook fires while WP_Ability_Categories_Registry::register() runs, in this order:
- apply_filters( wp_register_ability_category_args )filterline 91 (+34 into the body)
Filters the ability category arguments before they are validated and used to instantiate the ability category.
Uses · 6
- _doing_it_wrong()Marks something as being incorrectly called.
- __()Retrieves the translation of $text.
- esc_html()Escaping for HTML blocks.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_Ability_Categories_Registry::is_registered()Checks if an ability category is registered.
- WP_Ability_Category::__construct()Constructor.
Source code
public function register( string $slug, array $args ): ?WP_Ability_Category { if ( $this->is_registered( $slug ) ) { _doing_it_wrong( __METHOD__, /* translators: %s: Ability category slug. */ sprintf( __( 'Ability category "%s" is already registered.' ), esc_html( $slug ) ), '6.9.0' ); return null; } if ( ! preg_match( '/^[a-z0-9]+(?:-[a-z0-9]+)*$/', $slug ) ) { _doing_it_wrong( __METHOD__, __( 'Ability category slug must contain only lowercase alphanumeric characters and dashes.' ), '6.9.0' ); return null; } /** * Filters the ability category arguments before they are validated and used to instantiate the ability category. * * @since 6.9.0 * * @param array<string, mixed> $args { * The arguments used to instantiate the ability category. * * @type string $label The human-readable label for the ability category. * @type string $description A description of the ability category. * @type array<string, mixed> $meta Optional. Additional metadata for the ability category. * } * @param string $slug The slug of the ability category. */ $args = apply_filters( 'wp_register_ability_category_args', $args, $slug ); try { // WP_Ability_Category::prepare_properties() will throw an exception if the properties are invalid. $category = new WP_Ability_Category( $slug, $args ); } catch ( InvalidArgumentException $e ) { _doing_it_wrong( __METHOD__, $e->getMessage(), '6.9.0' ); return null; } $this->registered_categories[ $slug ] = $category; return $category; }Changelog
Introduced in 6.9.0. Unchanged from 6.9.7 through 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-categories-registry.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.