WP_Abilities_Registry::get_instance(): WP_Abilities_Registry|null
- Since
- 6.9.0
- Source
wp-includes/abilities-api/class-wp-abilities-registry.php:282
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_Abilities_Registry|null- The main registry instance, or null when
initaction has not fired.
Performance profile
How much work a call to WP_Abilities_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–22
- Plugin surface
- 1 hook
- Called by
- 5
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 35.
Third-party callbacks on 'wp_abilities_api_init' run inside this call, and their cost is not bounded by anything here.
5 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_Abilities_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() | 22 | did_action(), ::WP_Ability_Categories_Registry(), 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: 35 instructions, 10–22 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_Abilities_Registry::get_instance() runs, in this order:
- do_action( wp_abilities_api_init )actionline 313 (+31 into the body)
Fires when preparing abilities registry.
Uses · 6
- 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_Abilities_Registry::__construct()
- WP_Ability_Categories_Registry::get_instance()Utility method to retrieve the main instance of the registry class.
Used by · 5
- wp_get_abilities()Retrieves registered abilities, optionally filtered by the given arguments.
- wp_get_ability()Retrieves a registered ability.
- wp_has_ability()Checks if an ability is registered.
- wp_register_ability()Registers a new ability using the Abilities API. It requires three steps:
- wp_unregister_ability()Unregisters an ability from the Abilities API.
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(); // Ensure ability category registry is initialized first to allow categories to be registered // before abilities that depend on them. WP_Ability_Categories_Registry::get_instance(); /** * Fires when preparing abilities registry. * * Abilities should be created and register their hooks on this action rather * than another action to ensure they're only loaded when needed. * * @since 6.9.0 * * @param WP_Abilities_Registry $instance Abilities registry object. */ do_action( 'wp_abilities_api_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-abilities-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.