wp_has_ability()WP 6.9.0

Checks whether an ability is registered in the Abilities API.

Use it to check availability before using an ability.

No Hooks.

Returns

true|false.

  • 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

Changelog

Since 6.9.0 Introduced.

wp_has_ability() code WP 7.0.4

function wp_has_ability( string $name ): bool {
	$registry = WP_Abilities_Registry::get_instance();
	if ( null === $registry ) {
		return false;
	}

	return $registry->is_registered( $name );
}