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:

Read More
  • 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:

Related posts

2 comments

  1. After quite a bit of further research I managed to identify the um_submit_form_profile action which is triggered when users edit their profile, but not used at registration, so the duplicate email issue at registration is solved.

    Here is my original hook into the new action. This sets the user status to pending admin review when users edit their profile.

    // Set profile to under pending after edits
    add_action('um_submit_form_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(); 
        }
    }
    

    Thanks to Champ Campo, one of the plugin authors, I got an even better fix that just changes the account status to awaiting admin review and does nothing else.

    // Set profile to under review after edits
    add_action('um_user_edit_profile', 'um_post_edit_pending_hook');
    function um_post_edit_pending_hook( $args ){
        $user_id =  $args['user_id'];
        if ( is_super_admin() ) {
            return;
        }
            update_user_meta( $user_id, 'account_status', 'awaiting_admin_review');
    
    }
    
  2. I couldn’t make this work in UM 2+. However, for anyone still struggling with this, I did find a way to do it, by tacking on the user meta change to the end of an email notification snippet which I found. I also adjusted the email to include the ‘description’ field from the profile, so admin can see immediately if it has been changed to include anything undesirable.

    /*function to notify admin of profile changes*/
    add_action( 'um_after_user_updated', 'my_after_user_updated', 10, 3 );
    function my_after_user_updated( $user_id, $args, $userinfo ) {
        um_fetch_user($user_id);
        $groupMember = um_user('display_name');
        $groupMmbr_name = um_user('user_login');
        $groupMmbr_hidden = um_user('hide_in_members');
        $groupMmbr_status = um_user('account_status');
        $groupMmbr_desc = um_user('description');
        $loggedIn_user = wp_get_current_user();
        $loggedIn_userEml =  $loggedIn_user->user_email;
        $headers = array('Content-Type: text/html; charset=UTF-8', 'Cc:your-cc-address@yourwebsite.com', 'Bcc:', 
        'From:Your Website <website@yourwebsite.com>', 'Reply-To:No-reply Email<noreply@yourwebsitesite.com>');
        wp_mail( 'your-admin-email-address@yourwebsite.com', 'The member profile '.$groupMember.' has been updated.', 
        'The <b>'.$groupMember.'</b> profile was updated by the user with this email address: '.$loggedIn_userEml.'. <a href="https://yourwebsite.com/member/'.$groupMmbr_name.'/?profiletab=main&um_action=edit"><br>
        <b>Click here</b></a> to visit this profile online.<br><br><i style="color:#767676; font-size:11px; text-align:center;"><b>NOTE:</b> you must be logged in first to see this profile.</i>
        <br><br>The new profile description is:<br><br>'.$groupMmbr_desc.'<br><br>',$headers);
        update_user_meta( $user_id, 'account_status', 'awaiting_admin_review');
    }
    

Comments are closed.