edited_terms
云策文档标注
概述
edited_terms 是一个 WordPress 动作钩子,在数据库中更新一个术语后立即触发,但早于其术语-分类法关系的更新。它允许开发者在术语更新后执行自定义代码。
关键要点
- 触发时机:在术语更新到数据库后、术语-分类法关系更新前执行。
- 参数:$term_id(术语ID)、$taxonomy(分类法slug)、$args(传递给 wp_update_term() 的参数数组)。
- 用途:用于挂钩代码,以在术语更新后执行操作,例如日志记录或数据同步。
- 版本历史:从 WordPress 2.9.0 引入,6.1.0 版本添加了 $args 参数。
代码示例
add_action( 'edited_terms', 'my_custom_function', 10, 3 );
function my_custom_function( $term_id, $taxonomy, $args ) {
// 自定义代码,例如记录术语更新
error_log( "Term updated: ID $term_id, Taxonomy $taxonomy" );
}注意事项
- 此钩子在术语更新后触发,但术语-分类法关系尚未更新,需注意操作顺序。
- $args 参数包含来自 wp_update_term() 的更新参数,如 alias_of、description、parent 和 slug。
- 相关函数包括 wp_update_term() 和 wp_insert_term(),用于术语的更新和插入操作。
原文内容
Fires immediately after a term is updated in the database, but before its term-taxonomy relationship is updated.
Parameters
$term_idint-
Term ID.
$taxonomystring-
Taxonomy slug.
$argsarray-
Arguments passed to wp_update_term() .
More Arguments from wp_update_term( … $args )
Array of arguments for updating a term.
alias_ofstringSlug of the term to make this term an alias of.
Accepts a term slug.descriptionstringThe term description.parentintThe id of the parent term. Default 0.slugstringThe term slug to use.
Source
do_action( 'edited_terms', $term_id, $taxonomy, $args );