Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'rest_api_init', function() {
- register_rest_route( 'del_ads/v1', '/del_ads/post', array(
- 'methods' => 'POST',
- 'callback' => 'del_ads',
- 'args' => array(
- 'login' => array(
- 'type' => 'string',
- 'required' => true
- ),
- 'pass' => array(
- 'type' => 'string',
- 'required' => true
- ),
- 'ID_advertising' => array(
- 'type' => 'string',
- 'required' => true
- )
- )
- ));
- });
- function del_ads( $req ) {
- global $wpdb;
- $user_data = $req->get_param('login');
- $pass = $req->get_param('pass');
- $id_advertising = $req->get_param('ID_advertising');
- $user = get_user_by( 'login', $user_data);
- if (!$user) {
- $user = get_user_by( 'email', $user_data);
- }
- if ($user) {
- $hash = $user->data->user_pass;
- $is_true_pass = wp_check_password($pass, $hash);
- $user_id = $user->data->ID;
- if ($is_true_pass) {
- $sql = "SELECT `ID_user` FROM `wp_pa_advertising` WHERE `ID_advertising` = $id_advertising";
- $id = $wpdb->get_var($sql);
- if ($id == $user_id) {
- $id_advertising = (int) $id_advertising;
- $delete_adds = "DELETE FROM `wp_pa_unproc_iframes` WHERE `id_pa_advertising` = $id_advertising";
- $wpdb->query($delete_adds);
- }
- $delete_adds = "DELETE FROM `wp_pa_advertising` WHERE `ID_advertising` = $id_advertising AND `ID_user` = $user_id";
- $wpdb->query($delete_adds);
- return true;
- } else {
- return 'Password is not correct!';
- }
- } else {
- return 'User not found!';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement