2

I have a user registration form implemented and working correctly on the front end of a website. My main issue is that I would like to redirect a user after completing the profile form.

My idea would be to show a page with some content to let the user know that their account is being reviewed. So this kind of users will have a new role called "members-in-approval" and once the admin reviews their profile and approve them, they would get the role "active member".

Everything is working fine right now but I cannot redirect them to the page I mention before after completing the profile.

I'm pretty new using WP so any help or advice would be appreciated. Thanks!

  • Is your issue resolved or not @laluk? – Balas Aug 1 '18 at 5:47
  • Not yet. Still working on it. @Balas – laluk Aug 1 '18 at 23:30
0

Please put below code on your theme funcation.php file

add_action('user_register','post_user_reg_redirect');
function post_user_reg_redirect( $user_id )
{           
            $url = 'http://example.com';          
             wp_redirect($url);
             die();     

}
0

I think that I have figured out how to accomplish this issue but I would need your help guys to make it works.

Using the following hook:

add_action( 'member_role_upgrade', 'my_member_role_upgrade', 10, 2 );
function my_member_role_upgrade( $old_role, $new_role ) {
  if ( $new_role === 'member-in-approval' ) {

      $url = 'http://example.com';          
       wp_redirect($url);
       die(); 

}
}

Any feedback would be appreciated.

  • I have tested and it works! There is one more issue...when a user completes the profile, the redirects fires but the user is not assigned to "member-in-approval" role. – laluk Aug 2 '18 at 1:54
0

You can use simple redirect after user register. If you don't use Javascript ajax for your form you can use this with your register function (example);

$new_user = wp_insert_user(array(
    'user_login'        => $user_login,
    'user_pass'         => $user_pass,
    'user_email'        => $user_email,
    'first_name'        => $user_first,
    'last_name'         => $user_last,
    'user_registered'   => date('Y-m-d H:i:s'),
    'role'              => 'subscriber'
    )
);
  if($new_user) {
     // Maybe you have some custom user metas
        update_user_meta($new_user,'customarea','custom value');

     // log the new user in
        wp_setcookie($user_login, $user_pass, true);
        wp_set_current_user($new_user_id, $user_login); 
        do_action('wp_login', $user_login);

    // send the newly created user to the home page after logging them in
        wp_redirect(home_url()); exit;
  }
0

So after a hard work (as a Wordpress newbie), I have found a possible solution to redirect users after completing their user front-end profile.

Here is how I've achieved this functionality:

add_action( 'member_role_upgrade', 'my_member_role_upgrade', 10, 3 );
function my_member_role_upgrade( $old_role, $new_role, $user_id ) {
      if ( $new_role === 'member-in-approval' ) {

      $user_id = wp_update_user( array( 'ID' => $user_id, 'role' => 'member-in-approval' ) );
      $url = 'http://example.com/profile-under-review/';
      wp_redirect($url);
      die();

      }
}

As usual, any feedback would be appreciated. Thanks!

0

Not tested but using the hook user_register you should be able to achieve it:

add_action( 'user_register', 'stack_310127_redirect', 10, 1 );
function stack_310127_redirect( $user_id ){
  wp_redirect( 'http://www.example.com/yoururl' ); 
  exit;
}
  • Thanks for your help gents!! The only issue is that the user is already registered in the database when they fill out the profile form, so I'm not sure if the hook user_register is going to work. I think a good idea would be to check when the profile form is 100% completed and then execute a redirect to an URL. Would that be possible? – laluk Aug 1 '18 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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