public function delete($nonce = "", $id = 0, $validate = 1) { global $wpdb; # When using delete_all no need to check every time nonce. nd add id $is_valid = 1; if ($validate) { $is_valid = $this->validate($nonce, self::NONCE_DELETE); } if ($is_valid) { $artist_id = $id ? $id : $this->id; // Check if artist assigned to event $wpdb->get_row("SELECT event_id FROM " . WORDTOUR_EVENTS . " WHERE event_artist_id={$artist_id} LIMIT 1", "ARRAY_A"); if (!$wpdb->num_rows) { $wpdb->query($wpdb->prepare("DELETE FROM " . WORDTOUR_ARTISTS . " WHERE artist_id={$artist_id}")); if ($wpdb->result) { $attachments = new WT_Attachment(); $attachments->delete("attachment_target_id={$artist_id}&attachment_target=artist"); $this->db_result("success", $wpdb); } else { $this->db_result("error", $wpdb, array("msg" => "Error delete artist, please try again<br>" . $wpdb->last_error)); } return $wpdb->result; } else { $this->db_result("error", $wpdb, array("msg" => "Can't Delete artist because it's attached to event.")); } } return false; }
public function delete($nonce = "", $id = 0, $validate = 1) { global $wpdb; # When using delete_all no need to check every time nonce. nd add id $is_valid = 1; if ($validate) { $is_valid = $this->validate($nonce, self::NONCE_DELETE); } if ($is_valid) { $venue_id = $id ? $id : $this->id; $wpdb->get_row("SELECT event_id FROM " . WORDTOUR_EVENTS . " WHERE event_venue_id={$venue_id}", "ARRAY_A"); if (!$wpdb->num_rows) { $wpdb->query($wpdb->prepare("DELETE FROM " . WORDTOUR_VENUES . " WHERE venue_id = {$venue_id}")); if ($wpdb->result) { $attachments = new WT_Attachment(); $attachments->delete("attachment_target_id={$venue_id}&attachment_target=venue"); $wpdb->query("DELETE FROM " . WORDTOUR_SOCIAL . " WHERE social_parent_id = {$venue_id} AND social_parent_type = 'venue'"); $this->db_result("success", $wpdb); } else { $this->db_result("error", $wpdb, array("msg" => "Error delete venue, please try again<br>" . $wpdb->last_error)); } return $wpdb->result; } else { $this->db_result("error", $wpdb, array("msg" => "Error delete venue, already assigned to event<br>")); } } return false; }
public function update_attachments($attachments = array(), $id = 0, $target_type = "", $type = "") { $id = $id ? $id : $this->id; if ($id && !empty($target_type)) { foreach ($attachments as $attachment) { $attachment->attachment_target = $target_type; $attachment->attachment_type = $type; $attachment->attachment_target_id = $id; } $attachment = new WT_Attachment(); $attachment->delete("attachment_target_type={$target_type}&attachment_target_id={$target_id}&attachment_type={$type}"); return $attachment->insert($attachments); } return array(); }
public function delete($nonce = "", $id = 0, $validate = 1) { global $wpdb; $is_valid = 1; if ($validate) { $is_valid = $this->validate($nonce, self::NONCE_DELETE); } # if ($is_valid) { $tour_id = $id ? $id : $this->id; $wpdb->query($wpdb->prepare("DELETE FROM " . WORDTOUR_TOUR . " WHERE tour_id={$tour_id}")); if ($wpdb->result) { $attachments = new WT_Attachment(); $attachments->delete("attachment_target_id={$tour_id}&attachment_target=tour"); $this->db_result("success", $wpdb); } else { $this->db_result("error", $wpdb, array("msg" => "Error delete comment, please try again<br>" . $wpdb->last_error)); } return $wpdb->result; } return false; }