简体   繁体   中英

How to redirect admin after admin add user?

I have a customize admin login. I want the admin to add user and redirect to a customize page upon successful add. Is there any webhook I can use?

You can use user_register hook for this; it is called after any user is register or added to DB.

Here is the code:

add_action('user_register', 'wh_redirectAfterRegistration', 10, 1);

function wh_redirectAfterRegistration($user_id)
{
    if (empty($user_id))
        return;

    $user = wp_get_current_user();
    $curr_roles = $user->roles;
    $page_id = 70; //<-- Replace with YOUR PAGE ID

    //if logged in user is admin
    if (in_array('administrator', $curr_roles))
    {
        wp_redirect(get_permalink($page_id));
        exit();
    }
}

Code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.
Code is tested and works.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM