Advertisement
Guest User

Untitled

a guest
Nov 17th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. case 'create_customers':
  2. $result = array();
  3. mysql_connect("localhost","root","nopasswod");
  4. $conn=mysql_select_db("testapi");
  5. if($conn){
  6.  
  7. }else{
  8. echo "Tidak Konek";
  9. }
  10.  
  11. $response = array();
  12.  
  13. // $encript = md5($password);
  14. $hash = wp_hash_password( $password );
  15.  
  16. if (empty($_POST['email']) OR empty($_POST['password']) OR empty($_POST['username'])) {
  17. // successfully inserted into database
  18. $response["message"] = "parameter email, password,username.". mysql_error();
  19.  
  20. // echoing JSON response
  21. echo json_encode($response);
  22.  
  23. } elseif (!empty($_POST['email']) AND !empty($_POST['password']) AND !empty($_POST['username'])) {
  24.  
  25. $username = $_POST['username'];
  26. $now = date('Y-m-d H:i:s');
  27. $post_title = 'wp_capabilities';
  28. $role ='a:1:{s:8:"customer";b:1;}';
  29.  
  30. $email = $_POST['email'];
  31. $password = $_POST['password'];
  32. // failed to insert row
  33.  
  34. $result = mysql_query("INSERT INTO wp_users (user_login,user_pass,user_nicename,user_email,user_registered,display_name ) VALUES( '$username','$hash','$username','$email','$now','$username' )") or die(mysql_error());
  35. $last_id = mysql_insert_id();
  36. $response["api_status"] = 1;
  37. $response["message"] = "Account has been successfully made.";
  38. $response['id'] = $last_id;
  39. // $response['password'] = $hash;
  40. $result.= mysql_query("INSERT INTO wp_usermeta (user_id,meta_key,meta_value) VALUES ('$last_id','$post_title','$role')");
  41. echo json_encode($response);
  42. }else{
  43. $response["api_status"] = 0;
  44. $response["test"] = $message;
  45. $response["message"] = "Oops! An error occurred. ". mysql_error();
  46.  
  47. // echoing JSON response
  48. echo json_encode($response);
  49. }
  50.  
  51. break;
  52.  
  53. customUrl function () {
  54.    $ Uri = $ _ SERVER ['REQUEST_URI'];
  55.    if (strpos ($ uri, 'fire-Hymart')) {
  56.      locate_template ('api.php', true);
  57.    }
  58. }
  59.  
  60. add_action ('init', 'customUrl');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement