• Resolved Bigint

    (@bigint)


    Hi Callum,

    You may remember a while ago I asked how to set users to pending when they edited an existing account so admin could review the edits. I also wanted to send admin an email to notify admin when a user edits an existing account.

    I’m not very good at PHP at all, but in the end I figured out a code fix on my own using the plug-in code for direction – included below.

    However, we have noticed an issue. New new users are receiving duplicate registration pending emails.

    It is definitely the code I added that is causing this issue; I have removed it and only one pending email is sent.

    I cannot understand this because I thought all my code does is set a ‘user status’ to pending when the ‘um_user_edit_profile’ function is triggered.

    Can you possibly please let me know why this is triggering a duplicate email? And, if you have a little time could you please show me how to make my code set users to pending after editing their existing profile without sending a duplicate email at registration?

    Many thanks,

    Dan.

    // 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->user->pending();
        }
    }
    
    // Email admin after edits
    add_action( 'um_user_edit_profile','notify_admin_on_update');
    function notify_admin_on_update(){
        global $current_user;
        get_currentuserinfo();
    
        if (!current_user_can( 'administrator' )){// avoid sending emails when admin is updating user profiles
            $to = 'admin@enterprise-team.co.uk';
            $subject = 'user updated profile';
            $message = "the user : " .$current_user->business_name . " has updated his profile with:\n";
            foreach($_POST as $key => $value){
                $message .= $key . ": ". $value ."\n";
            }
            wp_mail( $to, $subject, $message);
        }
    }

    https://wordpress.org/plugins/ultimate-member/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Bigint

    (@bigint)

    Hi,

    So, I figured out that the pending function does not only set the status of users to pending, but it sends an email too. So, I presume my hook is being called at registration.

    What I want to do is just set the status of users to pending without sending the email. I looked into the pending function in greater detail and noticed that the following line actually looks to set users to pending $this->set_status('awaiting_admin_review');.

    Therefore, I have tried to use that line alone in a hook into the ‘um_user_edit_profile’ action (shown below) – but it doesn’t work.

    I think I’m nearly there. Can anyone please point out why the hook is breaking the site?

    // 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(){
    if ( is_super_admin() ) {
        return false;
    	} else {
    	global $ultimatemember;
    	$ultimatemember->set_status('awaiting_admin_review');
        }
    }
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi,

    If you want to change the user status, you can try the following code:

    // 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 = um_get_requested_user();
       update_user_meta( $user_id, 'account_status', 'awaiting_admin_review');
    }

    Regards,

    Thread Starter Bigint

    (@bigint)

    Hi Champ Camba,

    Thank you, very much, for taking the time to read my post and reply.

    Over the weekend I thought about hooking into the ‘um_submit_form_profile’ action, but I haven’t tried that yet.

    However, your approach looks much more appropriate. I’m going to try it now.

    Thanks again, your support is much appreciated.

    Thread Starter Bigint

    (@bigint)

    Hi Champ Camba,

    Unfortunately, the code does’nt work.

    When I added my original code that uses the pending function it also set admin to awaiting admin review which locked me out unless I added (if is super admin) first. I did not want that to happen so I added (if is super admin) to your code – below.

    // 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 = um_get_requested_user();
        if ( is_super_admin() ) {
            return false;
            } else {
            update_user_meta( $user_id, 'account_status', 'awaiting_admin_review');
        }
    }

    When that did not work I just ran your code. The code doesn’t break the site, but the user account status does not change when users make edits.

    Any more ideas please and thanks for your time.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi,

    You can try the following:

    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');
    
    }

    Regards,

    Thread Starter Bigint

    (@bigint)

    Hi Champ Camba,

    In the end I found an action to hook into called (um_submit_form_profile) that seemed to get triggered when a user updated their profile, but not at registration.

    However, your code works and is much more appropriate/ better. Therefore, of course, I am using your code.

    Thank you, very much indeed. I really appreciate your time. Have a fantastic day!

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Thanks for letting us know. I am closing this thread now.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Duplicate Registration Pending Emails Sent’ is closed to new replies.