我有一个插件,它添加了以下操作,其中包括在添加新用户时发送注册邮件:
add_action(\'um_post_registration_approved_hook\', \'um_post_registration_approved_hook\', 10, 2);
我想删除此操作,以便通过在调用的函数中进行一些额外检查来再次添加它。我尝试了以下方法,但未能成功:
add_action( \'um_post_registration_approved_hook\', \'remove_my_action\', 11 );
function remove_my_action(){
remove_action(\'um_post_registration_approved_hook\', \'um_post_registration_approved_hook\', 10, 2);
}
有什么想法吗?
EDIT
原来我的优先级错了,谢谢!我现在可以删除该操作并注册一个新操作。然而,我现在对此有一些问题。这是我取消注册的内容:
add_action(\'um_post_registration_approved_hook\', \'um_post_registration_approved_hook\', 10, 2);
function um_post_registration_approved_hook($user_id, $args){
global $ultimatemember;
$ultimatemember->user->approve();
}
然后,我注册了以下内容:
add_action( \'um_post_registration_approved_hook\', \'remove_my_action\', 9 );
function remove_my_action(){
remove_action(\'um_post_registration_approved_hook\', \'um_post_registration_approved_hook\', 10, 2);
add_action(\'um_post_registration_approved_hook\', \'um_post_registration_approved_hook_new\', 10, 2);
}
function um_post_registration_approved_hook_new($user_id, $args){
newApprove();
}
// Make the action call another version of this function - check for user meta - paupress_pp_user_type
function newApprove(){
global $ultimatemember;
$user_id = um_user(\'ID\');
delete_option( "um_cache_userdata_{$user_id}" );
if ( um_user(\'account_status\') == \'awaiting_admin_review\' ) {
$this->password_reset_hash();
$ultimatemember->mail->send( um_user(\'user_email\'), \'approved_email\' );
} else {
// check for paupress_pp_user_type before sending
$this->password_reset_hash();
// DONT SEND THIS MAIL
//$ultimatemember->mail->send( um_user(\'user_email\'), \'welcome_email\');
}
$this->set_status(\'approved\');
$this->delete_meta(\'account_secret_hash\');
$this->delete_meta(\'_um_cool_but_hard_to_guess_plain_pw\');
do_action(\'um_after_user_is_approved\', um_user(\'ID\') );
}
它只是原始approve()函数的另一个版本,删除了邮件通知。但这不起作用,因为最初的approve()是在UM\\u用户类中定义的,函数依赖于此。原始文件位于此处,第941行定义了approve()函数:
http://pastebin.com/FknrcxzM我的问题有意义吗?我可以钩住类而不是函数吗?-我真的不知道这里的正确方法。。
最合适的回答,由SO网友:Andy Macaulay-Brook 整理而成
您需要:
remove_action(\'um_post_registration_approved_hook\', \'um_post_registration_approved_hook\', 10, 2);
。。。在原始文件之后运行
add_action
, 但在动作触发函数之前
um_post_registration_approved_hook
要做到这一点,最简单的方法(但我还没有测试过)可能是在同一个钩子上为您的删除赋予更早的优先级:
add_action( \'um_post_registration_approved_hook\', \'remove_my_action\', 9 );
function remove_my_action(){
remove_action(\'um_post_registration_approved_hook\', \'um_post_registration_approved_hook\', 10, 2);
}
这是你一直在尝试的,但优先顺序是错误的。
11
追求
10
.