Forum Replies Created
-
AuthorPosts
-
April 14, 2022 at 6:14 PM in reply to: ✅How to set auto login after a successfull registration page ? #35635
Andrea Guerriero
ParticipantHi Joie
Just a custom function to check user rolefunction awr_user_has_role ($user_id, $role) { if (is_numeric( $user_id)) $user = get_user_by( 'id', $user_id ); else $user = wp_get_current_user(); if (empty($user)) return false; return in_array($role, (array) $user->roles); }April 8, 2022 at 4:20 PM in reply to: ✅How to set auto login after a successfull registration page ? #35538Andrea Guerriero
ParticipantHere again just to post the final code to whom may be interested
Obviously I had to check the doc to get it working because user_register pass a number while rwmb_profile_after_save_user pass an objectfunction auto_login_new_user( $user ) { $id = $user->user_id; wp_set_current_user($id); wp_set_auth_cookie($id); if(awr_user_has_role($id, 'subscriber')){ wp_redirect("/proponi-un-luogo/"); } exit(); } add_action( 'rwmb_profile_after_save_user', 'auto_login_new_user' );April 8, 2022 at 2:05 PM in reply to: ✅How to set auto login after a successfull registration page ? #35535Andrea Guerriero
ParticipantGrazie mille! 🙂
Long you’re an angel… and I’m quite ashamed of my laziness… I should definitely pay more attention to the documentation. There’s already everything in it. Indeed is probably the best api documentation I ever used: clear, accurate, complete, in depth, useful. I love your great work every day more.April 7, 2022 at 8:23 PM in reply to: ✅How to set auto login after a successfull registration page ? #35522Andrea Guerriero
ParticipantHi Long
Similar problem here
I followed your link and the autologin works well
But the extra fields I added in the registration form (custom and regular) are not saved anymore
Well, somehow it saves only the user_url
Before adding the autologin function data were all saved as aspected
It seems I'm using the wrong WP hook and the autolign fires before META plugin complete it's work
Any clues?Here's my code:
add_filter( 'rwmb_meta_boxes', 'agri_new' ); function agri_new( $meta_boxes ) { $prefix = ''; $meta_boxes[] = [ 'title' => __( 'Submitter', 'agri' ), 'id' => 'user-extra', 'type' => 'user', 'fields' => [ [ 'name' => __( 'Nome', 'agri' ), 'id' => $prefix . 'first_name', 'type' => 'text', 'required' => true, ], [ 'name' => __( 'Cognome', 'agri' ), 'id' => $prefix . 'last_name', 'type' => 'text', 'required' => true, ], [ 'name' => __( 'Telefono', 'agri' ), 'id' => $prefix . 'user_phone', 'type' => 'text', 'required' => true, ], [ 'name' => __( 'Sito web', 'agri' ), 'id' => $prefix . 'user_url', 'type' => 'url', ], ], ]; return $meta_boxes; }Here's the custom function:
function auto_login_new_user( $user_id ) { wp_set_current_user($user_id); wp_set_auth_cookie($user_id); if(awr_user_has_role(get_current_user_id(), 'subscriber')){ wp_redirect("/proponi-un-luogo/"); } exit(); } add_action( 'user_register', 'auto_login_new_user' );Andrea Guerriero
ParticipantThanks Nguyen
Actually is the first time for me. We buy the AIO versions because we develope a lot on WordPress and it seems the perfect solution for most of our recurring scenarios. There are so many options and docs to browse that problably I got confused. By the way thanks, I manage it with the MB Builder just like you suggest -
AuthorPosts