I am trying to login a user from custom user registration form. My Code for Custom user Register is
function register_user($data) {
$userdata = array(
'user_login' => $data['email'],
'user_email' => $data['email'],
'user_pass' => $data['pssword'],
'user_nicename' => $data['fname'],
'display_name' => $data['fname'],
);
$usermetedata = array(
'son_name' => $data['son_name'],
'shape' => $data['shape'],
'siret' => $data['siret'],
'company_email' => $data['company_email'],
'company_activity' => $data['activity'],
'staff' => $data['staff'],
'position_held' => $data['position_held'],
'company_phone' => $data['company_phone'],
'company_mobile' => $data['company_mobile'],
'company_address' => $data['company_address'],
'company_postal' => $data['company_postal'],
'company_ville' => $data['company_ville'],
'url' => $data['url'],
'personal_region' => $data['personal_region'],
'personal_address' => $data['personal_address'],
'personal_ville' => $data['personal_ville'],
'personal_postal' => $data['personal_postal'],
'personal_phone' => $data['personal_phone'],
'personal_mobile' => $data['personal_mobile'],
'dob' => $data['dob'],
'invite_email' => $data['invite_email']
);
$userid = wp_insert_user($userdata);
foreach ($usermetedata as $key => $val):
add_user_meta($userid, $key, $val);
endforeach;
gdlr_new_user_registered($userid);
// echo 'Registration complete. Goto <a href="' . get_site_url() . '/wp-admin">login page</a>.';
if ($userid) {
user_activation($userid, $data);
}
}
And My code for Login currently register user is
function gdlr_new_user_registered( $user_id ) {
$user = get_user_by( 'id', $user_id );
wp_set_auth_cookie( $user_id, false, is_ssl() );
$redirect_to = site_url().'le-reseau-social/teepy-tableau-de-bord/';
do_action( 'wp_login', $user->user_login );
return $redirect_to;
}
add_filter('login_redirect', 'gdlr_new_user_registered', 10, 3);
But I am not able to login please suggest me or let me know if i am doing some mistake.
Thanks