wp_unregister_ability()WP 6.9.0

Removes a previously registered ability from the global Abilities API registry.

It can be called at any time after registration, for example to disable another plugin's ability. If the ability is not registered, WordPress triggers an _doing_it_wrong() warning. Check first with wp_has_ability().

No Hooks.

Returns

WP_Ability|null.

  • WP_Ability - the removed ability.
  • null - if the ability is not registered or the registry is unavailable.

Usage

wp_unregister_ability( $name ): ?WP_Ability;
$name(string) (required)
Namespaced ability name, for example my-plugin/my-ability.

Examples

#1 Disabling another plugin’s ability

Removes the ability after other plugins have had a chance to register it.

add_action( 'wp_abilities_api_init', 'my_plugin_unregister_ability', 100 );

function my_plugin_unregister_ability(): void {
	if ( wp_has_ability( 'other-plugin/some-ability' ) ) {
		wp_unregister_ability( 'other-plugin/some-ability' );
	}
}

Notes

Changelog

Since 6.9.0 Introduced.

wp_unregister_ability() code WP 7.0.4

function wp_unregister_ability( string $name ): ?WP_Ability {
	$registry = WP_Abilities_Registry::get_instance();
	if ( null === $registry ) {
		return null;
	}

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