I have a plugin that adds the following action which among other things sends out a registration mail when a new user is added:
add_action('um_post_registration_approved_hook', 'um_post_registration_approved_hook', 10, 2);
I would like to remove this action, so I can add it again with some additional checks in the called function. I have tried the following, but can't get it to work:
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);
}
Any ideas?
EDIT
Turns out I had the priority wrong, thanks! I am now able to remove the action and register a new one instead. However, I'm now having some problems with that. This is what I've unregistered:
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();
}
I have then registered the following instead:
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') );
}
Which is simply another version of the original approve()-function, with the mail notification removed. BUT this doesn't work, since the original approve() is defined inside the UM_user class and the function relies on this. The original file is here, with the approve()-function defined from line 941: http://pastebin.com/FknrcxzM
Does my problem make sense? And can I hook into the class instead of the function? - Don't really know the correct approach here..
this
have nowhere to go. If I understand the code here, that isn't the$ultimatemember
object? If you changethis
to the correct object name then that might be sufficient in this case.class UM_User { function __construct() { $this->id = 0;
, so it might be referring to the UM_User object?