$selected_cats,'post_status'=>'private', 'post_type'=>'post'); } else { $options = array('category__in'=>$selected_cats,'post_status'=>'publish', 'post_type'=>'post'); } $limit_to = absint($_POST['smbd_cats_limits_to']); if ($limit_to > 0) { $options['showposts'] = $limit_to; } else { $options['nopaging'] = 'true'; } $force_delete = $_POST['smbd_cats_force_delete']; if ($force_delete == 'true') { $force_delete = true; } else { $force_delete = false; } $posts = $wp_query->query($options); foreach ($posts as $post) { wp_delete_post($post->ID, $force_delete); } break; case "bulk-delete-tags": // delete by tags $selected_tags = $_POST['smbd_tags']; if ($_POST['smbd_tags_restrict'] == "true") { add_filter ('posts_where', 'smbd_tags_by_days'); } $private = $_POST['smbd_tags_private']; if ($private == 'true') { $options = array('tag__in'=>$selected_tags,'post_status'=>'private', 'post_type'=>'post'); } else { $options = array('tag__in'=>$selected_tags,'post_status'=>'publish', 'post_type'=>'post'); } $limit_to = absint($_POST['smbd_tags_limits_to']); if ($limit_to > 0) { $options['showposts'] = $limit_to; } else { $options['nopaging'] = 'true'; } $force_delete = $_POST['smbd_tags_force_delete']; if ($force_delete == 'true') { $force_delete = true; } else { $force_delete = false; } $posts = $wp_query->query($options); foreach ($posts as $post) { wp_delete_post($post->ID, $force_delete); } break; case "bulk-delete-taxs": // delete by taxs $selected_taxs = $_POST['smbd_taxs']; foreach ($selected_taxs as $selected_tax) { $postids = smbd_get_tax_post($selected_tax); if ($_POST['smbd_taxs_restrict'] == "true") { add_filter ('posts_where', 'smbd_taxs_by_days'); } $private = $_POST['smbd_taxs_private']; if ($private == 'true') { $options = array('post__in'=>$postids,'post_status'=>'private', 'post_type'=>'post'); } else { $options = array('post__in'=>$postids,'post_status'=>'publish', 'post_type'=>'post'); } $limit_to = absint($_POST['smbd_taxs_limits_to']); if ($limit_to > 0) { $options['showposts'] = $limit_to; } else { $options['nopaging'] = 'true'; } $force_delete = $_POST['smbd_taxs_force_delete']; if ($force_delete == 'true') { $force_delete = true; } else { $force_delete = false; } $posts = $wp_query->query($options); foreach ($posts as $post) { wp_delete_post($post->ID, $force_delete); } } break; case "bulk-delete-special": $options = array(); $limit_to = absint($_POST['smbd_special_limit_to']); if ($limit_to > 0) { $options['showposts'] = $limit_to; } else { $options['nopaging'] = 'true'; } $force_delete = $_POST['smbd_special_force_delete']; if ($force_delete == 'true') { $force_delete = true; } else { $force_delete = false; } // Drafts if ("drafs" == $_POST['smbd_drafs']) { $options['post_status'] = 'draft'; $drafts = $wp_query->query($options); foreach ($drafts as $draft) { wp_delete_post($draft->ID, $force_delete); } } // Revisions if ("revisions" == $_POST['smbd_revisions']) { $revisions = $wpdb->get_results($wpdb->prepare("select ID from $wpdb->posts where post_type = 'revision'")); foreach ($revisions as $revision) { wp_delete_post($revision->ID, $force_delete); } } // Pending Posts if ("pending" == $_POST['smbd_pending']) { $pendings = $wpdb->get_results($wpdb->prepare("select ID from $wpdb->posts where post_status = 'pending'")); foreach ($pendings as $pending) { wp_delete_post($pending->ID, $force_delete); } } // Future Posts if ("future" == $_POST['smbd_future']) { $futures = $wpdb->get_results($wpdb->prepare("select ID from $wpdb->posts where post_status = 'future'")); foreach ($futures as $future) { wp_delete_post($future->ID, $force_delete); } } // Private Posts if ("private" == $_POST['smbd_private']) { $privates = $wpdb->get_results($wpdb->prepare("select ID from $wpdb->posts where post_status = 'private'")); foreach ($privates as $private) { wp_delete_post($private->ID, $force_delete); } } // Pages if ("pages" == $_POST['smbd_pages']) { $options['post_type'] = 'page'; $pages = $wp_query->query($options); foreach ($pages as $page) { wp_delete_post($page->ID, $force_delete); } } // Specific Pages if ("specificpages" == $_POST['smdb_specific_pages']) { $urls = preg_split( '/\r\n|\r|\n/', $_POST['smdb_specific_pages_urls'] ); foreach ($urls as $url) { $checkedurl = $url; if (substr($checkedurl ,0,1) == '/') { $checkedurl = get_site_url() . $checkedurl ; } $postid = url_to_postid( $checkedurl ); wp_delete_post($postid, $force_delete); } } break; } // hook the admin notices action add_action( 'admin_notices', 'smbd_deleted_notice', 9 ); } } } /** * Show deleted notice messages */ if (!function_exists('smbd_deleted_notice')) { function smbd_deleted_notice() { echo "

" . __("All the selected posts have been successfully deleted.", 'bulk-delete') . "

"; } } /** * Show the Admin page */ if (!function_exists('smbd_displayOptions')) { function smbd_displayOptions() { global $wpdb; ?>

Bulk Delete


/wp-admin/options-general.php?page=bulk-delete.php" method="post" onsubmit="return bd_validateForm(this);"> get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_status = 'draft'")); $revisions = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_type = 'revision'")); $pending = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_status = 'pending'")); $future = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_status = 'future'")); $private = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_status = 'private'")); $pages = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_type = 'page'")); ?>

»">


/wp-admin/options-general.php?page=bulk-delete.php" method="post" onsubmit="return bd_validateForm(this);">
false)); foreach ($categories as $category) { ?>

»">

0) { ?>

/wp-admin/options-general.php?page=bulk-delete.php" method="post" onsubmit="return bd_validateForm(this);">

»">

0) { ?>

/wp-admin/options-general.php?page=bulk-delete.php" method="post" onsubmit="return bd_validateForm(this);">

»">


.

.

$where * @return */ if (!function_exists('smbd_cats_by_days ')) { function smbd_cats_by_days ($where = '') { $cats_op = $_POST['smbd_cats_op']; $cats_days = $_POST['smbd_cats_days']; remove_filter('posts_where', 'smbd_cats_by_days'); $where .= " AND post_date $cats_op '" . date('y-m-d', strtotime("-$cats_days days")) . "'"; return $where; } } /** * function to filter posts by days * @param $where * @return */ if (!function_exists('smbd_tags_by_days ')) { function smbd_tags_by_days ($where = '') { $tags_op = $_POST['smbd_tags_op']; $tags_days = $_POST['smbd_tags_days']; remove_filter('posts_where', 'smbd_tags_by_days'); $where .= " AND post_date $tags_op '" . date('y-m-d', strtotime("-$tags_days days")) . "'"; return $where; } } /** * function to filter custom taxonomy posts by days * @param $where * @return */ if (!function_exists('smbd_taxs_by_days ')) { function smbd_taxs_by_days ($where = '') { $taxs_op = $_POST['smbd_taxs_op']; $taxs_days = $_POST['smbd_taxs_days']; remove_filter('posts_where', 'smbd_taxs_by_days'); $where .= " AND post_date $taxs_op '" . date('y-m-d', strtotime("-$taxs_days days")) . "'"; return $where; } } /** * Return the posts for a taxonomy * * @param $tax * @return */ if (!function_exists('smbd_get_tax_post')) { function smbd_get_tax_post($tax) { global $wpdb; $query = $wpdb->prepare("select object_id from {$wpdb->prefix}term_relationships where term_taxonomy_id in (select term_taxonomy_id from {$wpdb->prefix}term_taxonomy where taxonomy = '$tax')"); $post_ids_result = $wpdb->get_results($query); $postids = array(); foreach ($post_ids_result as $post_id_result) { $postids[] = $post_id_result->object_id; } return $postids; } } /** * Add navigation menu */ if(!function_exists('smbd_add_menu')) { function smbd_add_menu() { //Add a submenu to Manage $page = add_options_page("Bulk Delete", "Bulk Delete", 'manage_options', basename(__FILE__), "smbd_displayOptions"); } } /** * Adds the settings link in the Plugin page. Based on http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/ * @staticvar $this_plugin * @param $links * @param $file */ if (!function_exists('smbd_filter_plugin_actions')) { function smbd_filter_plugin_actions($links, $file) { static $this_plugin; if( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__); if( $file == $this_plugin ) { $settings_link = '' . _('Manage') . ''; array_unshift( $links, $settings_link ); // before other links } return $links; } } /** * Adds Footer links. Based on http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/ */ if (!function_exists('smbd_admin_footer')) { function smbd_admin_footer() { $plugin_data = get_plugin_data( __FILE__ ); printf('%1$s ' . __("plugin", 'bulk-delete') .' | ' . __("Version", 'bulk-delete') . ' %2$s | '. __('by', 'bulk-delete') . ' %3$s
', $plugin_data['Title'], $plugin_data['Version'], $plugin_data['Author']); ?>