wp_has_ability()
Checks if an ability is registered.
Use this for conditional logic and feature detection before attempting to retrieve or use an ability.
Example:
// Displays different UI based on available abilities.
if ( wp_has_ability( 'premium-plugin/advanced-export' ) ) {
echo 'Export with Premium Features';
} else {
echo 'Basic Export';
}
Хуков нет.
Возвращает
true|false. true if the ability is registered, false otherwise.
Использование
wp_has_ability( $name ): bool;
- $name(строка) (обязательный)
- The name of the ability to check, including namespace prefix (e.g., 'my-plugin/my-ability').
Заметки
- Смотрите: WP_Abilities_Registry::is_registered()
- Смотрите: wp_get_ability()
Список изменений
| С версии 6.9.0 | Введена. |
Код wp_has_ability() wp has ability WP 6.9
function wp_has_ability( string $name ): bool {
$registry = WP_Abilities_Registry::get_instance();
if ( null === $registry ) {
return false;
}
return $registry->is_registered( $name );
}