钩子文档

registered_taxonomy

💡 云策文档标注

概述

registered_taxonomy 是一个 WordPress 钩子,在自定义分类法注册后触发。它提供分类法键、对象类型名称和注册参数,允许开发者在分类法注册后执行自定义操作。

关键要点

  • registered_taxonomy 是一个动作钩子,在分类法注册后立即触发。
  • 钩子传递三个参数:$taxonomy(分类法键)、$object_type(对象类型或数组)和 $args(注册参数数组)。
  • 可用于在特定分类法注册后执行自定义逻辑,如初始化相关功能或验证设置。

代码示例

/**
 * Example of registered_taxonomy usage
 * @param string $taxonomy Taxonomy key.
 * @param array|string $object_type Name of the object type for the taxonomy object.
 * @param array|string $args Optional args used in taxonomy registration.
 */
function wporg_registered_taxonomy_example( $taxonomy, $object_type, $args ) {
	if ( 'customtax' == $taxonomy ) {
		// Do something after customtax is registered as custom taxonomy
	}
}
add_action( 'registered_taxonomy', 'wporg_registered_taxonomy_example', 10, 3 );

📄 原文内容

Fires after a taxonomy is registered.

Parameters

$taxonomystring
Taxonomy slug.
$object_typearray|string
Object type or array of object types.
$argsarray
Array of taxonomy registration arguments.

More Information

registered_taxonomy is a hook triggered after a custom taxonomy has been registered. This hook provides the taxonomy key, the name of the object type for the taxonomy object, and arguments used to register the taxonomy as parameters.

Source

do_action( 'registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object );

Changelog

Version Description
3.3.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    /**
     * Example of registered_taxonomy usage
     * @param string $taxonomy Taxonomy key.
     * @param array|string $object_type Name of the object type for the taxonomy object.
     * @param array|string $args Optional args used in taxonomy registration.
     */
    function wporg_registered_taxonomy_example( $taxonomy, $object_type, $args ) {
    	if ( 'customtax' == $taxonomy ) {
    		// Do something after customtax is registered as custom taxonomy
    	}
    }
    add_action( 'registered_taxonomy', 'wporg_registered_taxonomy_example', 10, 3 );