/** * Delete posts by custom post type. * * @static * @since 5.0 * @param array $delete_options Options for deleting posts * @return int $posts_deleted Number of posts that were deleted */ public static function delete_posts_by_post_type($delete_options) { // Backward compatibility code. Will be removed in Bulk Delete v6.0 if (array_key_exists('types_op', $delete_options)) { $delete_options['date_op'] = $delete_options['types_op']; $delete_options['days'] = $delete_options['types_days']; } $delete_options = apply_filters('bd_delete_options', $delete_options); $count = 0; $selected_types = $delete_options['selected_types']; foreach ($selected_types as $selected_type) { $type_status = BD_Util::split_post_type_status($selected_type); $type = $type_status['type']; $status = $type_status['status']; $options = array('post_status' => $status, 'post_type' => $type); $options = bd_build_query_options($delete_options, $options); $post_ids = bd_query($options); foreach ($post_ids as $post_id) { // $force delete parameter to custom post types doesn't work if ($delete_options['force_delete']) { wp_delete_post($post_id, true); } else { wp_trash_post($post_id); } } $count += count($post_ids); } return $count; }
/** * Bulk Delete pages * * @since 5.0 * @param array $delete_options * @return integer */ public static function delete_pages_by_status($delete_options) { global $wp_query; // Backward compatibility code. Will be removed in Bulk Delete v6.0 if (array_key_exists('page_op', $delete_options)) { $delete_options['date_op'] = $delete_options['page_op']; $delete_options['days'] = $delete_options['page_days']; } $delete_options = apply_filters('bd_delete_options', $delete_options); $post_status = array(); // published pages if ('published_pages' == $delete_options['publish']) { $post_status[] = 'publish'; } // Drafts if ('draft_pages' == $delete_options['drafts']) { $post_status[] = 'draft'; } // Pending pages if ('pending_pages' == $delete_options['pending']) { $post_status[] = 'pending'; } // Future pages if ('future_pages' == $delete_options['future']) { $post_status[] = 'future'; } // Private pages if ('private_pages' == $delete_options['private']) { $post_status[] = 'private'; } $options = array('post_type' => 'page', 'post_status' => $post_status); $options = bd_build_query_options($delete_options, $options); $pages = $wp_query->query($options); foreach ($pages as $page) { wp_delete_post($page->ID, $delete_options['force_delete']); } return count($pages); }