0

I have been working around with adding stuff in user profile edit area. I am done with that but there is one thing I am unable to sort out.

What I am planning to do is to redirect a user to a custom page (custom member page) after they successfully edited their profile (wp-admin/profile.php) . In case of error they stay there. Help is appreciate :) Thanks

2
  • I am also looking for the same and in addition to that I want to have two more things 1. I want to redirect users to the same profile page with a message saying "profile updated" when they change their email id 2. Redirect users to the login page after changing their password because changing password logs them out. Could you guys help me out? Commented Oct 23, 2020 at 7:37
  • @AkbarBasha this isn't a discussion forum, don't post replies as answers/solutions, if you have a new question ask it as a new question
    – Tom J Nowell
    Commented Oct 23, 2020 at 10:56

4 Answers 4

2

This is the function that you need:

add_action( 'profile_update', 'custom_profile_redirect', 12 );
function custom_profile_redirect() {
    if(is_admin()):
        wp_redirect( trailingslashit( home_url() ) );
        exit;
    endif;
}

Just change the target of wp_redirect to whatever URL you want your users to go to. You can even add conditional logic to it if you only want this to happen for certain users, like the function below:

add_action( 'profile_update', 'custom_profile_redirect', 12 );
function custom_profile_redirect() {
    if ( is_admin() && current_user_can( 'subscriber' ) ) {
        wp_redirect( trailingslashit( home_url() ) );
        exit;
    }
}

Hope this helps! You can learn more about it from this tutorial I wrote.

1
  • Hi Thomas, I know how to add a textbox profile field but how can I add a textarea on profile.php ? Should I create a new question for you ?
    – EnexoOnoma
    Commented Jun 28, 2011 at 14:09
1

Just adding to the answers by Thomas Griffin and user114196 (not got the reputation to comment). The hook profile_update is also called when the lost password functionality is used, before the email is sent, so the redirect breaks this in a very annoying to debug way. This can be fixed by checking if user_activation_key has changed (the link used for password reset), and not redirecting if so.

add_action('profile_update', 'wbb_profile_update', 10, 3);
function wbb_profile_update($user_id, $oldUserData, $newUserData) {
    // This is also called on lost password, BEFORE the email is sent - hence breaking it. If that's the case, don't redirect.
    $doRedirect = $oldUserData->data->user_activation_key === $newUserData['user_activation_key'];
    if ($doRedirect && get_option('wbb-redirect-users-to-on-login', '')){
        wp_redirect(get_option('wbb-redirect-users-to-on-login', ''));
        die();
    }
}
0
add_action('personal_options_update', 'redirect_me');
function redirect_me(){
  wp_redirect(home_url('/'));
  exit;
}
3
  • Hey, thx,, yes it is redirecting but it isn't saving or updating the changes .
    – Ayaz Malik
    Commented Jan 14, 2011 at 1:55
  • I don't see any other hook there, so I guess the only way is to edit the .php file... Commented Jan 14, 2011 at 2:30
  • oh hmm k . thx :)
    – Ayaz Malik
    Commented Jan 14, 2011 at 3:11
0

this is old but i'll add to this as i was looking for a similar solution and this was the closest result.

personal_options_update fires before updating the profile

profile_update fires after the updating the profile

add_action('profile_update', 'redirect_me');
function redirect_me(){
  wp_redirect(home_url('/'));
  exit;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.