Advertisement
Guest User

Untitled

a guest
Feb 6th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1.  
  2.  
  3. add_action( 'rest_api_init', function() {
  4.  
  5. register_rest_route( 'del_ads/v1', '/del_ads/post', array(
  6. 'methods' => 'POST',
  7. 'callback' => 'del_ads',
  8. 'args' => array(
  9. 'login' => array(
  10. 'type' => 'string',
  11. 'required' => true
  12. ),
  13. 'pass' => array(
  14. 'type' => 'string',
  15. 'required' => true
  16. ),
  17. 'ID_advertising' => array(
  18. 'type' => 'string',
  19. 'required' => true
  20. )
  21. )
  22. ));
  23.  
  24. });
  25.  
  26.  
  27. function del_ads( $req ) {
  28. global $wpdb;
  29.  
  30. $user_data = $req->get_param('login');
  31. $pass = $req->get_param('pass');
  32. $id_advertising = $req->get_param('ID_advertising');
  33. $user = get_user_by( 'login', $user_data);
  34. if (!$user) {
  35. $user = get_user_by( 'email', $user_data);
  36. }
  37.  
  38. if ($user) {
  39. $hash = $user->data->user_pass;
  40. $is_true_pass = wp_check_password($pass, $hash);
  41. $user_id = $user->data->ID;
  42.  
  43. if ($is_true_pass) {
  44.  
  45. $sql = "SELECT `ID_user` FROM `wp_pa_advertising` WHERE `ID_advertising` = $id_advertising";
  46. $id = $wpdb->get_var($sql);
  47.  
  48. if ($id == $user_id) {
  49. $id_advertising = (int) $id_advertising;
  50. $delete_adds = "DELETE FROM `wp_pa_unproc_iframes` WHERE `id_pa_advertising` = $id_advertising";
  51. $wpdb->query($delete_adds);
  52. }
  53.  
  54. $delete_adds = "DELETE FROM `wp_pa_advertising` WHERE `ID_advertising` = $id_advertising AND `ID_user` = $user_id";
  55. $wpdb->query($delete_adds);
  56.  
  57. return true;
  58. } else {
  59. return 'Password is not correct!';
  60. }
  61. } else {
  62. return 'User not found!';
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement