wp_has_ability()
Checks whether an ability is registered in the Abilities API.
Use it to check availability before using an ability.
No Hooks.
Returns
bool.
true- the ability is registered.false- the ability is not registered or the registry is unavailable.
Usage
wp_has_ability( $name ): bool;
- $name(string) (required)
- Namespaced ability name, for example
my-plugin/my-ability.
Examples
#1 Accessibility check for advanced export
if ( wp_has_ability( 'premium-plugin/advanced-export' ) ) {
echo 'Advanced export';
} else {
echo 'Regular export';
}Notes
| See: WP_Abilities_Registry::is_registered() |
| See: wp_get_ability() |
Changelog
| Since 6.9.0 | Introduced. |
wp_has_ability() wp has ability code WP 7.1
function wp_has_ability( string $name ): bool {
$registry = WP_Abilities_Registry::get_instance();
if ( null === $registry ) {
return false;
}
return $registry->is_registered( $name );
}