WP_Ability_Categories_Registry::get_instance(): WP_Ability_Categories_Registry|null
- Since
- 6.9.0
- Source
wp-includes/abilities-api/class-wp-ability-categories-registry.php:203
Description
The instance will be created if it does not exist yet.
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.
Return value
WP_Ability_Categories_Registry|null- The main registry instance, or null when
initaction has not fired.
Performance profile
How much work a call to WP_Ability_Categories_Registry::get_instance() 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
- 10–20
- Plugin surface
- 1 hook
- Called by
- 6
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 33.
Third-party callbacks on 'wp_abilities_api_categories_init' run inside this call, and their cost is not bounded by anything here.
6 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action()called directly
Further down the call graph this can also reach query, option, cache, serialize 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::get_instance() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
did_action() | 10 | did_action() |
!did_action() | 17 | did_action(), __(), sprintf(), _doing_it_wrong() |
did_action() | 20 | did_action(), do_action() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 33 instructions, 10–20 executed per call, 2 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 · 1
One hook fires while WP_Ability_Categories_Registry::get_instance() runs, in this order:
- do_action( wp_abilities_api_categories_init )actionline 229 (+26 into the body)
Fires when preparing ability categories registry.
Uses · 5
- did_action()Retrieves the number of times an action has been fired during the current request.
- _doing_it_wrong()Marks something as being incorrectly called.
- __()Retrieves the translation of $text.
- do_action()Calls the callback functions that have been added to an action hook.
- WP_Ability_Categories_Registry::__construct()
Used by · 6
- WP_Abilities_Registry::get_instance()Utility method to retrieve the main instance of the registry class.
- wp_get_ability_categories()Retrieves all registered ability categories.
- wp_get_ability_category()Retrieves a registered ability category.
- wp_has_ability_category()Checks if an ability category is registered.
- wp_register_ability_category()Registers a new ability category.
- wp_unregister_ability_category()Unregisters an ability category.
Source code
public static function get_instance(): ?self { if ( ! did_action( 'init' ) ) { _doing_it_wrong( __METHOD__, sprintf( // translators: %s: init action. __( 'Ability API should not be initialized before the %s action has fired.' ), '<code>init</code>' ), '6.9.0' ); return null; } if ( null === self::$instance ) { self::$instance = new self(); /** * Fires when preparing ability categories registry. * * Ability categories should be registered on this action to ensure they're available when needed. * * @since 6.9.0 * * @param WP_Ability_Categories_Registry $instance Ability categories registry object. */ do_action( 'wp_abilities_api_categories_init', self::$instance ); } return self::$instance; }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.