Guest User

Untitled

a guest
Mar 2nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. $webhook_posted_json = file_get_contents('php://input');
  2. $location_info = json_decode($webhook_posted_json, true);
  3.  
  4. $the_user_id = 0;
  5. // Check if user exist or not!
  6. if ( !function_exists( 'get_user_by' ) ) {
  7. require_once ABSPATH . WPINC . '/pluggable.php';
  8. }
  9. if ( username_exists( $location_name ) ){
  10. $the_user = get_user_by('login', $location_name);
  11. $the_user_id = $the_user->ID;
  12. }
  13. else{
  14. $the_user_id = 0;
  15. }
  16.  
  17.  
  18. if ( !function_exists( 'wp_insert_user' ) ) {
  19. require_once ABSPATH . WPINC . '/user.php';
  20. }
  21. $password = wp_generate_password();
  22. // An array, object, or WP_User object of user data arguments.
  23. $userdata = array(
  24. 'ID' => $the_user_id,
  25. 'user_pass' => $password,
  26. 'user_login' => $location_name,
  27. 'user_email' => $location_email,
  28. 'role' => 'editor'
  29. );
  30.  
  31. // NOTICE! Understand what this does before running.
  32. $result = wp_insert_user($userdata);
Add Comment
Please, Sign In to add comment