wp_get_ability()
Gets a registered ability object from the Abilities API.
The WP_Ability{} object contains the ability's settings, metadata, and execution methods.
If the ability is not registered, WordPress triggers an _doing_it_wrong() warning. Use wp_has_ability() to check whether it exists.
No Hooks.
Returns
WP_Ability|null.
WP_Ability- the registered ability object.null- if the ability is not registered or the registry is unavailable.
Usage
wp_get_ability( $name ): ?WP_Ability;
- $name(string) (required)
- Namespaced ability name, for example
my-plugin/my-ability.
Examples
#1 Getting information about the availability
if ( wp_has_ability( 'my-plugin/export-data' ) ) {
$ability = wp_get_ability( 'my-plugin/export-data' );
echo esc_html(
$ability->get_label() . ': ' . $ability->get_description()
);
}Notes
Changelog
| Since 6.9.0 | Introduced. |
wp_get_ability() wp get ability code WP 7.0.4
function wp_get_ability( string $name ): ?WP_Ability {
$registry = WP_Abilities_Registry::get_instance();
if ( null === $registry ) {
return null;
}
return $registry->get_registered( $name );
}