function delete_posts($post_date) { global $wpdb, $table_prefix; $ids = GDPTDB::get_posts_for_delete($post_date); $results["posts"] = count($ids); $ids = join(",", $ids); $sql = sprintf("delete from %scomments where comment_post_id in (%s)", $table_prefix, $ids); wp_gdpt_log_sql("DELETE_POSTS_COMMENTS", $sql); $wpdb->query($sql); $results["comments"] = $wpdb->rows_affected; $sql = sprintf("delete %s, %s, %s from %sposts p left join %sterm_relationships t on t.object_id = p.ID left join %spostmeta m on m.post_id = p.ID where p.ID in (%s)", gdFunctionsGDPT::mysql_pre_4_1() ? sprintf("%sposts", $table_prefix) : "p", gdFunctionsGDPT::mysql_pre_4_1() ? sprintf("%sterm_relationships", $table_prefix) : "t", gdFunctionsGDPT::mysql_pre_4_1() ? sprintf("%spostmeta", $table_prefix) : "m", $table_prefix, $table_prefix, $table_prefix, $ids); wp_gdpt_log_sql("DELETE_POSTS_POSTS", $sql); $wpdb->query($sql); $sql = sprintf("delete %s, %s, %s from %sposts p left join %sterm_relationships t on t.object_id = p.ID left join %spostmeta m on m.post_id = p.ID where p.post_type = 'revision' and p.post_parent in (%s)", gdFunctionsGDPT::mysql_pre_4_1() ? sprintf("%sposts", $table_prefix) : "p", gdFunctionsGDPT::mysql_pre_4_1() ? sprintf("%sterm_relationships", $table_prefix) : "t", gdFunctionsGDPT::mysql_pre_4_1() ? sprintf("%spostmeta", $table_prefix) : "m", $table_prefix, $table_prefix, $table_prefix, $ids); wp_gdpt_log_sql("DELETE_POSTS_REST", $sql); $wpdb->query($sql); return $results; }
/** * Deletes revisions for selected post. * * @global WPDB $wpdb wordpress database object * @global string $table_prefix prefix used for database tables * @param int $post_id post id to delete revisions from * @return int number of deleted revisions */ function gd_delete_revisions($post_id) { global $wpdb, $table_prefix; $sql = sprintf("delete %s, %s, %s from %sposts p left join %sterm_relationships t on t.object_id = p.ID left join %spostmeta m on m.post_id = p.ID where p.post_type = 'revision' and p.post_parent = %s", gdFunctionsGDPT::mysql_pre_4_1() ? sprintf("%sposts", $table_prefix) : "p", gdFunctionsGDPT::mysql_pre_4_1() ? sprintf("%sterm_relationships", $table_prefix) : "t", gdFunctionsGDPT::mysql_pre_4_1() ? sprintf("%spostmeta", $table_prefix) : "m", $table_prefix, $table_prefix, $table_prefix, $post_id); $wpdb->query($sql); wp_gdpt_log_sql("DELETE_REVISIONS_FOR_POST", $sql); return $wpdb->rows_affected; }