Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $password = wp_generate_password();
- $userdata = array(
- 'user_login' => $email,
- 'user_email' => $email,
- 'user_pass' => $password,
- 'display_name' => $firstname . ' ' . $name,
- 'first_name' => $firstname,
- 'last_name' => $name,
- 'role' => 'subscriber',
- 'user_registered' => (new DateTime())->format('Y-m-d H:i:s')
- );
- $user_id = wp_insert_user( $userdata ) ;
- // Autologin after registration
- wp_set_current_user($user_id);
- if (wp_validate_auth_cookie()==FALSE)
- {
- wp_set_auth_cookie($user_id, true, false);
- }
- $response = null;
- $current_user = wp_get_current_user();
- var_dump( $current_user );
- object(WP_User)#3217 (7) {
- ["data"]=>
- object(stdClass)#3218 (0) {
- }
- ["ID"]=>
- int(0)
- ["caps"]=>
- array(0) {
- }
- ["cap_key"]=>
- NULL
- ["roles"]=>
- array(0) {
- }
- ["allcaps"]=>
- array(0) {
- }
- ["filter"]=>
- NULL
- /**
- * login_force_update_cookie - Specific action for force overriding the logged_in_cookie
- * when being in the AJAX registration context
- *
- * @param {type} $logged_in_cookie description
- * @return {type} description
- */
- public function login_force_update_cookie( $logged_in_cookie ) {
- if ( strstr( $_SERVER['REQUEST_URI'], 'toto/user/register' ) ) {
- $_COOKIE[LOGGED_IN_COOKIE] = $logged_in_cookie;
- }
- }
- wp_set_current_user($user_id);
- if ( wp_validate_auth_cookie( '', 'logged_in' ) != $user_id )
- {
- wp_set_auth_cookie( $user_id );
- }
- // Storing the regitration event for the user
- $this->saveLoginEvent( $user_id );
- $data = array(
- 'user_id' => $user_id,
- 'nonce' => wp_create_nonce( 'wp_rest' ),
- 'message' => 'user_created'
- );
- $response = rest_ensure_response( $data );
Add Comment
Please, Sign In to add comment