dimanche 15 mai 2016

Wordpress Ultimate Member Plugin – Set User Status to Awaiting Admin Approval

The Wordpress Ultimate Member (UM) plugin allows us to set newly registered users to ‘Pending’ through wp-admin.

The Pending function does 2 things:

  • Sets the user status to ‘awaiting admin approval’
  • Sends the user an email

See here:

function pending(){ 
global $ultimatemember; 
$this->set_status('awaiting_admin_review'); 
$ultimatemember->mail->send( um_user('user_email'), 'pending_email' );  

But, there is no way to set existing users to ‘Pending’ admin approval if users edit an existing account.

I’m not strong at PHP, but I figured out a hook into the ‘um_user_edit_profile’ action, so that if existing users edit their profile the status is changed to ‘pending’.

See here:

// Set profile to under pending after edits
add_action('um_user_edit_profile', 'um_post_edit_pending_hook', 10, 2); 
function um_post_edit_pending_hook($user_id, $args){ 
if ( is_super_admin() ) {
    return false;
    } else { 
        global $ultimatemember; 
        $ultimatemember->user->pending(); 
    }
}

Unfortunately, I have just discovered that the ‘um_user_edit_profile’ action is also used at registration, so my hook triggers at registration too which results in two emails being sent.

I’ve tried to overcome this by:

Adding and if statement so the action is only triggered for logged in users:

// Set profile to under review after edits
add_action('um_user_edit_profile', 'um_post_edit_pending_hook', 10, 2); 
function um_post_edit_pending_hook($user_id, $args){ 
if ( is_super_admin() ) {
    return false;
    } else {
if ( is_user_logged_in() ) {
        global $ultimatemember; 
        $ultimatemember->user->pending();
    }
}

By trying to set the status to ‘awaiting admin approval’ without including the email:

// Set profile to under review after edits
add_action('um_user_edit_profile', 'um_post_edit_pending_hook', 10, 2); 
function um_post_edit_pending_hook($user_id, $args){ 
if ( is_super_admin() ) {
    return false;
    } else { 
        global $ultimatemember; 
        $ultimatemember->set_status('awaiting_admin_review');
    }
}

// Set profile to under review after edits
add_action('um_user_edit_profile', 'um_post_edit_pending_hook', 10, 2); 
function um_post_edit_pending_hook($user_id, $args){ 
if ( is_super_admin() ) {
    return false;
    } else { 
        global $ultimatemember; 
        $this->set_status('awaiting_admin_review');
    }
}

I’ve also tried too many other variations to include and all of them break the site.

So, I’m asking the community for some support/ pointers on how to use the pending function without the email being sent or how to set the status to 'awaiting admin review' using my hook.

I’ve been using the UM github repository to help me research the UM code:



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire