Redirect After Adding a New User in WordPress
by c.bavota | Posted in Tutorials | 10 comments
Since the release of WordPress 3.3, I noticed something that was overlooked when adding a new user in the wp-admin. Before, adding a new user would redirect to a list view after the user was created that only included the new user. Now it redirects back to the full user list, though it’s actually trying to display just that one new user. The problem is that they seemed to have removed the functionality of the usersearch parameter from the URL string. It has been replaced with the usual s that is used in the front end WordPress search. I wrote a little fix that can be added to your functions.php file in order to bring back the old behaviour:
add_action("admin_init", "redirect_user_add");
function redirect_user_add() {
if(!empty($_GET['usersearch'])) {
$username = $_GET['usersearch'];
$user = get_userdatabylogin($username);
wp_redirect(admin_url("/users.php?s=".$username."&update=add#user-".$user->ID));
}
}
With this in place, you’ll now be redirected to the user list page with only the new user’s account listed. You can even modify it slightly so that it opens up the user’s profile edit page instead.
add_action("admin_init", "redirect_user_add");
function redirect_user_add() {
if(!empty($_GET['usersearch'])) {
$username = $_GET['usersearch'];
$user = get_userdatabylogin($username);
wp_redirect( admin_url("/user-edit.php?user_id=".$user->ID) );
}
}
This is useful if you have added customized user fields that need to be set immediately after adding a new user.



I like the e-mail notification
That was fast and I’m first to comment
Thanks for a redirect, will check it later today and let my comment!
Thanks for the fix, I liked the old behavior so much better and will try to bring it back in my blogs backend with this.
great ! it turn my blog to be helpful , and email notification is great
Cheers for the nifty fix, Bavota San!
Thanks,i’ve extended my word press site to capture information about health complaints.
Thanks! Great Blog! Thanks for all the useful bits and pieces!!
Nice fix, thanks Bavota San! I couldn’t live without wp, and generally it just keeps getting better and better, but they do still occasionally surprise us with some small annoyances. Thanks again!
add_action("admin_init", "dmt_redirect_after_user_add"); function dmt_redirect_after_user_add() { if(!empty($_GET['id']) && !empty($_GET['update']) && ($_GET['update'] == 'add')) { $userid = $_GET['id']; $user = get_userdata( $userid ); wp_redirect( admin_url("/user-edit.php?user_id=".$user->ID) ); } }Tried the code but it din seem to work
this is the new fix i tried instead
Seems like they changed things for 3.4. Thanks for the update.