function gwolle_gb_del_entries($status) { global $wpdb; // First get all the id's, so we can remove the logs later if ($status == 'spam') { $where = "\n\t\t\tisspam = %d"; $values[] = 1; } else { if ($status == 'trash') { $where = "\n\t\t\tistrash = %d"; $values[] = 1; } else { return false; // not the right $status } } $sql = "\n\t\t\tSELECT\n\t\t\t\t`id`\n\t\t\tFROM\n\t\t\t\t{$wpdb->gwolle_gb_entries}\n\t\t\tWHERE\n\t\t\t\t" . $where . "\n\t\t\tLIMIT 999999999999999\n\t\t\tOFFSET 0\n\t\t;"; $sql = $wpdb->prepare($sql, $values); $datalist = $wpdb->get_results($sql, ARRAY_A); if (is_array($datalist) && !empty($datalist)) { $sql = "\n\t\t\tDELETE\n\t\t\tFROM\n\t\t\t\t{$wpdb->gwolle_gb_entries}\n\t\t\tWHERE\n\t\t\t\t" . $where . "\n\t\t\t;"; $result = $wpdb->query($wpdb->prepare($sql, $values)); if ($result > 0) { // Also remove the log entries foreach ($datalist as $id) { gwolle_gb_del_log_entries($id['id']); } return $result; } } return false; }
public function delete() { global $wpdb; if ($this->get_isspam() == 0 && $this->get_istrash() == 0) { // Do not delete the good stuff. return false; } $id = $this->get_id(); $sql = "\n\t\t\tDELETE\n\t\t\tFROM\n\t\t\t\t{$wpdb->gwolle_gb_entries}\n\t\t\tWHERE\n\t\t\t\tid = %d\n\t\t\tLIMIT 1"; $values = array($id); $result = $wpdb->query($wpdb->prepare($sql, $values)); if ($result == 1) { // Also remove the log entries gwolle_gb_del_log_entries($id); return true; } return false; }