Guest User

Untitled

a guest
Dec 6th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. $password = wp_generate_password();
  2. $userdata = array(
  3. 'user_login' => $email,
  4. 'user_email' => $email,
  5. 'user_pass' => $password,
  6. 'display_name' => $firstname . ' ' . $name,
  7. 'first_name' => $firstname,
  8. 'last_name' => $name,
  9. 'role' => 'subscriber',
  10. 'user_registered' => (new DateTime())->format('Y-m-d H:i:s')
  11. );
  12. $user_id = wp_insert_user( $userdata ) ;
  13.  
  14. // Autologin after registration
  15. wp_set_current_user($user_id);
  16. if (wp_validate_auth_cookie()==FALSE)
  17. {
  18. wp_set_auth_cookie($user_id, true, false);
  19. }
  20.  
  21. $response = null;
  22. $current_user = wp_get_current_user();
  23. var_dump( $current_user );
  24.  
  25. object(WP_User)#3217 (7) {
  26. ["data"]=>
  27. object(stdClass)#3218 (0) {
  28. }
  29. ["ID"]=>
  30. int(0)
  31. ["caps"]=>
  32. array(0) {
  33. }
  34. ["cap_key"]=>
  35. NULL
  36. ["roles"]=>
  37. array(0) {
  38. }
  39. ["allcaps"]=>
  40. array(0) {
  41. }
  42. ["filter"]=>
  43. NULL
  44.  
  45. /**
  46. * login_force_update_cookie - Specific action for force overriding the logged_in_cookie
  47. * when being in the AJAX registration context
  48. *
  49. * @param {type} $logged_in_cookie description
  50. * @return {type} description
  51. */
  52. public function login_force_update_cookie( $logged_in_cookie ) {
  53. if ( strstr( $_SERVER['REQUEST_URI'], 'toto/user/register' ) ) {
  54. $_COOKIE[LOGGED_IN_COOKIE] = $logged_in_cookie;
  55. }
  56. }
  57.  
  58. wp_set_current_user($user_id);
  59. if ( wp_validate_auth_cookie( '', 'logged_in' ) != $user_id )
  60. {
  61. wp_set_auth_cookie( $user_id );
  62. }
  63.  
  64. // Storing the regitration event for the user
  65. $this->saveLoginEvent( $user_id );
  66. $data = array(
  67. 'user_id' => $user_id,
  68. 'nonce' => wp_create_nonce( 'wp_rest' ),
  69. 'message' => 'user_created'
  70. );
  71. $response = rest_ensure_response( $data );
Add Comment
Please, Sign In to add comment