为什么管理员不工作?

I edited a bit of code the other day from the Wordpress Ultimate Members plug-in to change the user profile to pending if the profile is edited by the user.

However, I noted that the code also sets the admin account to pending too. I don’t want this, so I have been trying to use an if/ else statement to query if the user is admin before the script runs.

I know this is straight forward for experts in PHP, but I have tried lots of variations and admin is still being set to pending approval.

Here’s the original code that is setting admin to pending:

// 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){ 
        global $ultimatemember; 
        $ultimatemember->user->pending(); 
}

Here s the code that I am trying to bypass admin with which won’t work. I won’t add all the variations I have tried.

add_action('um_user_edit_profile', 'um_post_edit_pending_hook', 10, 2); 
function um_post_edit_pending_hook($user_id, $args){ 
if ( is_admin() ) {
    return false;
    } else { 
        global $ultimatemember; 
        $ultimatemember->user->pending(); 
    }
}

Any assistance would gratefully be appreciated.

This Conditional Tag checks if the Dashboard or the administration panel is attempting to be displayed. It should not be used as a means to verify whether the current user has permission to view the Dashboard or the administration panel (try current_user_can() instead):

https://codex.wordpress.org/Function_Reference/current_user_can

Source:

https://codex.wordpress.org/Function_Reference/is_admin

@user45250 has explained this very well. I have added this answer to provide some example code.

Here is the code from my earlier comment.

add_action('um_user_edit_profile', 'um_post_edit_pending_hook', 10, 2); 
function um_post_edit_pending_hook($user_id, $args){ 
    if ( current_user_can('administrator') ) {
        return false;
    } else { 
        global $ultimatemember; 
        $ultimatemember->user->pending(); 
    }
}

P.S. here is a related question, gmazzap's answer has more detail.