函数文档

wp_unregister_ability_category()

💡 云策文档标注

概述

wp_unregister_ability_category() 函数用于从全局注册表中移除一个已注册的能力类别,以禁用不再需要的类别。它可以在能力类别注册后的任何时间调用。

关键要点

  • 函数作用:注销一个能力类别,使其从全局注册表中移除。
  • 参数:$slug(字符串,必需),指定要注销的能力类别的标识符。
  • 返回值:成功时返回被注销的 WP_Ability_Category 实例,失败时返回 null。
  • 相关函数:与 wp_register_ability_category() 和 WP_Ability_Categories_Registry::unregister() 配合使用。

代码示例

if ( wp_has_ability_category( 'deprecated-category' ) ) {
    wp_unregister_ability_category( 'deprecated-category' );
}

注意事项

  • 在调用前,建议使用 wp_has_ability_category() 检查能力类别是否存在,以避免错误。
  • 此函数在 WordPress 6.9.0 版本中引入。

📄 原文内容

Unregisters an ability category.

Description

Removes a previously registered ability category from the global registry. Use this to disable ability categories that are no longer needed.

Can be called at any time after the ability category has been registered.

Example:

if ( wp_has_ability_category( 'deprecated-category' ) ) {
    wp_unregister_ability_category( 'deprecated-category' );
}

See also

Parameters

$slugstringrequired
The slug of the ability category to unregister.

Return

WP_Ability_Category|null The unregistered ability category instance on success, null on failure.

Source

function wp_unregister_ability_category( string $slug ): ?WP_Ability_Category {
	$registry = WP_Ability_Categories_Registry::get_instance();
	if ( null === $registry ) {
		return null;
	}

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

Changelog

Version Description
6.9.0 Introduced.