动作挂钩,用于自定义税项编辑


8

因此,我在我的模板文件functions.php中有一个函数,该函数可缓存包含自定义分类法术语的搜索表单。当我添加/删除/编辑特定分类法的术语时,我想刷新缓存(或删除一个缓存组)。

可能吗?也许使用do_action,但是要使用哪个钩子?谢谢

Answers:


11

看看wp-includes/taxonomy.php。这些动作是:

do_action( "create_term",       $term_id, $tt_id, $taxonomy );
do_action( "created_term",      $term_id, $tt_id, $taxonomy );
do_action( "edited_term",       $term_id, $tt_id, $taxonomy );
do_action( 'delete_term',       $term,    $tt_id, $taxonomy, $deleted_term );
do_action( "create_$taxonomy",  $term_id, $tt_id );
do_action( "created_$taxonomy", $term_id, $tt_id );
do_action( "edited_$taxonomy",  $term_id, $tt_id );
do_action( "delete_$taxonomy",  $term,    $tt_id, $deleted_term );

8

您正在寻找created_termedited_termdelete_term。每个回调都接受3个参数:

function wpse_created_term( $term_id, $tt_id, $taxonomy ) {
}    
function wpse_edited_term( $term_id, $tt_id, $taxonomy ) {
}    
function wpse_delete_term( $term_id, $tt_id, $taxonomy ) {
}    

add_action( 'created_term', 'wpse_created_term', 10, 3 );
add_action( 'edited_term', 'wpse_edited_term', 10, 3 );
add_action( 'delete_term', 'wpse_delete_term', 10, 3 );
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.