PluginProbe
Bulk Delete / 3.1
Bulk Delete v3.1
6.12 trunk 0.2 0.3 0.4 0.6 0.7 0.8 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.2.1 2.2.2 3.0 3.1 All 64 releases
bulk-delete / bulk-delete.php

bulk-delete.php in Bulk Delete 3.1, at bulk-delete.php

1,311 lines 55.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Bulk Delete
4 Plugin Script: bulk-delete.php
5 Plugin URI: http://sudarmuthu.com/wordpress/bulk-delete
6 Description: Bulk delete posts from selected categories, tags, custom taxonomies or by post type like drafts, scheduled posts, revisions etc.
7 Donate Link: http://sudarmuthu.com/if-you-wanna-thank-me
8 Version: 3.1
9 License: GPL
10 Author: Sudar
11 Author URI: http://sudarmuthu.com/
12 Text Domain: bulk-delete
13 Domain Path: languages/
14
15 === RELEASE NOTES ===
16 2009-02-02 - v0.1 - first version
17 2009-02-03 - v0.2 - Second release - Fixed issues with pagging
18 2009-04-05 - v0.3 - Third release - Prevented drafts from deleted when only posts are selected
19 2009-07-05 - v0.4 - Fourth release - Added option to delete by date.
20 2009-07-21 - v0.5 - Fifth release - Added option to delete all pending posts.
21 2009-07-22 - v0.6 - Sixth release - Added option to delete all scheduled posts.
22 2010-02-21 - v0.7 - Added an option to delete posts directly or send them to trash and support for translation.
23 2010-03-17 - v0.8 - Added support for private posts.
24 2010-06-19 - v1.0 - Proper handling of limits.
25 2011-01-22 - v1.1 - Added support to delete posts by custom taxonomies
26 2011-02-06 - v1.2 - Added some optimization to handle huge number of posts in underpowered servers
27 2011-05-11 - v1.3 - Added German translations
28 2011-08-25 - v1.4 - Added Turkish translations
29 2011-11-13 - v1.5 - Added Spanish translations
30 2011-11-28 - v1.6 - Added Italian translations
31 2012-01-12 - v1.7 - Added Bulgarian translations
32 2012-01-31 - v1.8 - Added roles and capabilities for menu
33 2012-03-16 - v1.9 - Added support for deleting by permalink. Credit Martin Capodici
34 - Fixed issues with translations
35 - Added Rusian translations
36 2012-04-01 - v2.0 (10 hours) - Fixed a major issue in how dates were handled.
37 - Major UI revamp
38 - Added debug information and support urls
39 2012-04-07 - v2.1 (1 hour) - Fixed CSS issues in IE.
40 - Added Lithuanian translations
41 2012-07-11 - v2.2 - (Dev time: 0.5 hour)
42 - Added Hindi translations
43 - Added checks to see if elements are present in the array before accessing them.
44 2012-10-28 - v2.2.1 - (Dev time: 0.5 hour)
45 - Added Serbian translations
46 2012-12-20 - v2.2.2 - (Dev time: 0.5 hour)
47 - Removed unused wpdb->prepare() function calls
48 2013-04-27 - v3.0 - (Dev time: 10 hours)
49 - Added support for pro addons
50 - Added GUI to see cron jobs
51 2013-04-28 - v3.1 - (Dev time: 5 hours)
52 - Added separate delete by sections for pages, drafts and urls
53 - Added the option to delete by date for drafts, revisions, future posts etc
54 - Added the option to delete by date for pages
55 */
56
57 /* Copyright 2009 Sudar Muthu (email : sudar@sudarmuthu.com)
58
59 This program is free software; you can redistribute it and/or modify
60 it under the terms of the GNU General Public License, version 2, as
61 published by the Free Software Foundation.
62
63 This program is distributed in the hope that it will be useful,
64 but WITHOUT ANY WARRANTY; without even the implied warranty of
65 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66 GNU General Public License for more details.
67
68 You should have received a copy of the GNU General Public License
69 along with this program; if not, write to the Free Software
70 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
71 */
72
73 /**
74 * Bulk Delete Main class
75 */
76 class Bulk_Delete {
77
78 const VERSION = '3.1';
79 const JS_HANDLE = 'bulk-delete';
80 const JS_VARIABLE = 'BULK_DELETE';
81
82 /**
83 * Default constructor
84 */
85 public function __construct() {
86 // Load localization domain
87 $this->translations = dirname(plugin_basename(__FILE__)) . '/languages/' ;
88 load_plugin_textdomain( 'bulk-delete', false, $this->translations);
89
90 // Register hooks
91 add_action('admin_menu', array(&$this, 'add_menu'));
92 add_action('admin_init', array(&$this, 'request_handler'));
93
94 // Add more links in the plugin listing page
95 add_filter('plugin_action_links', array(&$this, 'filter_plugin_actions'), 10, 2 );
96 add_filter( 'plugin_row_meta', array( &$this, 'add_plugin_links' ), 10, 2 );
97 }
98
99 /**
100 * Add navigation menu
101 */
102 function add_menu() {
103 //Add a submenu to Manage
104 $this->admin_page = add_options_page(__("Bulk Delete", 'bulk-delete'), __("Bulk Delete", 'bulk-delete'), 'delete_posts', basename(__FILE__), array(&$this, 'display_setting_page'));
105 $this->cron_page = add_options_page(__("Bulk Delete Schedules", 'bulk-delete'), __("Bulk Delete Schedules", 'bulk-delete'), 'delete_posts', 'bulk-delete-cron', array(&$this, 'display_cron_page'));
106
107 add_action('admin_print_scripts-' . $this->admin_page, array(&$this, 'add_script'));
108 }
109
110 /**
111 * Enqueue JavaScript
112 */
113 function add_script() {
114 global $wp_scripts;
115
116 // uses code from http://trentrichardson.com/examples/timepicker/
117 wp_enqueue_script( 'jquery-ui-timepicker', plugins_url('/js/jquery-ui-timepicker.js', __FILE__), array('jquery-ui-slider', 'jquery-ui-datepicker'), '1.1.1', true);
118 wp_enqueue_script( self::JS_HANDLE, plugins_url('/js/bulk-delete.js', __FILE__), array('jquery-ui-timepicker'), self::VERSION, TRUE);
119
120 $ui = $wp_scripts->query('jquery-ui-core');
121
122 $url = "http://ajax.aspnetcdn.com/ajax/jquery.ui/{$ui->ver}/themes/smoothness/jquery-ui.css";
123 wp_enqueue_style('jquery-ui-smoothness', $url, false, $ui->ver);
124 wp_enqueue_style('jquery-ui-timepicker', plugins_url('/style/jquery-ui-timepicker.css', __FILE__), array(), '1.1.1');
125
126 // JavaScript messages
127 $msg = array(
128 'deletewarning' => __('Are you sure you want to delete all the selected posts', 'bulk-delete'),
129 'selectone' => __('Please select at least one option', 'bulk-delete')
130 );
131 $translation_array = array( 'msg' => $msg );
132 wp_localize_script( self::JS_HANDLE, self::JS_VARIABLE, $translation_array );
133 }
134
135 /**
136 * Adds the settings link in the Plugin page. Based on http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/
137 * @staticvar <type> $this_plugin
138 * @param <type> $links
139 * @param <type> $file
140 */
141 function filter_plugin_actions($links, $file) {
142 static $this_plugin;
143 if( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
144
145 if( $file == $this_plugin ) {
146 $settings_link = '<a href="options-general.php?page=bulk-delete.php">' . __('Manage', 'bulk-delete') . '</a>';
147 array_unshift( $links, $settings_link ); // before other links
148 }
149 return $links;
150 }
151
152 /**
153 * Adds additional links in the Plugin listing. Based on http://zourbuth.com/archives/751/creating-additional-wordpress-plugin-links-row-meta/
154 */
155 function add_plugin_links($links, $file) {
156 $plugin = plugin_basename(__FILE__);
157
158 if ($file == $plugin) // only for this plugin
159 return array_merge( $links,
160 array( '<a href="http://sudarmuthu.com/out/bulk-delete-addons" target="_blank">' . __('Buy Addons', 'bulk-delete') . '</a>' )
161 );
162 return $links;
163 }
164
165 /**
166 * Show the Admin page
167 */
168 function display_setting_page() {
169 global $wpdb;
170 ?>
171 <div class="updated fade" style="background:#ff0;text-align:center;color: red;"><p><strong><?php _e("WARNING: Posts deleted once cannot be retrieved back. Use with caution.", 'bulk-delete'); ?></strong></p></div>
172
173 <div class="wrap">
174 <?php screen_icon(); ?>
175 <h2><?php _e('Bulk Delete', 'bulk-delete');?></h2>
176
177 <div id = "poststuff" style = "float:left; width:75%">
178
179 <div class = "postbox">
180 <div class = "handlediv"> <br> </div>
181 <h3 class = "hndle"><span><?php _e("By Type", 'bulk-delete'); ?></span></h3>
182 <div class = "inside">
183 <h4><?php _e("Select the posts which you want to delete", 'bulk-delete'); ?></h4>
184
185 <form name="smbd_form" id = "smbd_misc_form" action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post" onsubmit="return bd_validateForm(this);">
186
187 <?php
188 $wp_query = new WP_Query;
189 $drafts = $wpdb->get_var("select count(*) from $wpdb->posts where post_status = 'draft'");
190 $revisions = $wpdb->get_var("select count(*) from $wpdb->posts where post_type = 'revision'");
191 $pending = $wpdb->get_var("select count(*) from $wpdb->posts where post_status = 'pending'");
192 $future = $wpdb->get_var("select count(*) from $wpdb->posts where post_status = 'future'");
193 $private = $wpdb->get_var("select count(*) from $wpdb->posts where post_status = 'private'");
194 ?>
195 <fieldset class="options">
196 <table class="optiontable">
197 <tr>
198 <td scope="row" >
199 <input name="smbd_drafts" id ="smbd_drafts" value = "drafts" type = "checkbox" />
200 <label for="smbd_drafts"><?php _e("All Drafts", 'bulk-delete'); ?> (<?php echo $drafts . " "; _e("Drafts", 'bulk-delete'); ?>)</label>
201 </td>
202 </tr>
203
204 <tr>
205 <td>
206 <input name="smbd_revisions" id ="smbd_revisions" value = "revisions" type = "checkbox" />
207 <label for="smbd_revisions"><?php _e("All Revisions", 'bulk-delete'); ?> (<?php echo $revisions . " "; _e("Revisions", 'bulk-delete'); ?>)</label>
208 </td>
209 </tr>
210
211 <tr>
212 <td>
213 <input name="smbd_pending" id ="smbd_pending" value = "pending" type = "checkbox" />
214 <label for="smbd_pending"><?php _e("All Pending posts", 'bulk-delete'); ?> (<?php echo $pending . " "; _e("Posts", 'bulk-delete'); ?>)</label>
215 </td>
216 </tr>
217
218 <tr>
219 <td>
220 <input name="smbd_future" id ="smbd_future" value = "future" type = "checkbox" />
221 <label for="smbd_future"><?php _e("All scheduled posts", 'bulk-delete'); ?> (<?php echo $future . " "; _e("Posts", 'bulk-delete'); ?>)</label>
222 </td>
223 </tr>
224
225 <tr>
226 <td>
227 <input name="smbd_private" id ="smbd_private" value = "private" type = "checkbox" />
228 <label for="smbd_private"><?php _e("All private posts", 'bulk-delete'); ?> (<?php echo $private . " "; _e("Posts", 'bulk-delete'); ?>)</label>
229 </td>
230 </tr>
231
232 <tr>
233 <td>
234 <h4><?php _e("Choose your filtering options", 'bulk-delete'); ?></h4>
235 </td>
236 </tr>
237
238 <tr>
239 <td scope="row">
240 <input name="smbd_special_restrict" id="smbd_special_restrict" value = "true" type = "checkbox" onclick="toggle_date_restrict('special');" />
241 <?php _e("Only restrict to posts which are ", 'bulk-delete');?>
242 <select name="smbd_special_op" id="smbd_special_op" disabled>
243 <option value ="<"><?php _e("older than", 'bulk-delete');?></option>
244 <option value =">"><?php _e("posted within last", 'bulk-delete');?></option>
245 </select>
246 <input type ="textbox" name="smbd_special_days" id="smbd_special_days" disabled value ="0" maxlength="4" size="4" /><?php _e("days", 'bulk-delete');?>
247 </td>
248 </tr>
249
250 <tr>
251 <td scope="row">
252 <input name="smbd_special_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
253 <input name="smbd_special_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
254 </td>
255 </tr>
256
257 <tr>
258 <td scope="row">
259 <input name="smbd_special_limit" id="smbd_special_limit" value = "true" type = "checkbox" onclick="toggle_limit_restrict('special');" />
260 <?php _e("Only delete first ", 'bulk-delete');?>
261 <input type ="textbox" name="smbd_special_limit_to" id="smbd_special_limit_to" disabled value ="0" maxlength="4" size="4" /><?php _e("posts.", 'bulk-delete');?>
262 <?php _e("Use this option if there are more than 1000 posts and the script timesout.", 'bulk-delete') ?>
263 </td>
264 </tr>
265
266 </table>
267 </fieldset>
268
269 <p class="submit">
270 <input type="submit" name="submit" class="button-primary" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
271 </p>
272
273 <?php wp_nonce_field('bulk-delete-posts'); ?>
274
275 <input type="hidden" name="smbd_action" value="bulk-delete-special" />
276 </form>
277 </div>
278 </div>
279
280
281 <div class = "postbox">
282 <div class = "handlediv"> <br> </div>
283 <h3 class = "hndle"><span><?php _e("By Pages", 'bulk-delete'); ?></span></h3>
284 <div class = "inside">
285 <h4><?php _e("Select the pages which you want to delete", 'bulk-delete'); ?></h4>
286
287 <form name="smbd_form" id = "smbd_page_form" action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post"
288 onsubmit="return bd_validateForm(this);">
289
290 <?php
291 $wp_query = new WP_Query;
292 $pages = $wpdb->get_var("select count(*) from $wpdb->posts where post_type = 'page' AND post_status = 'publish' ");
293 ?>
294 <fieldset class="options">
295 <table class="optiontable">
296 <tr>
297 <td>
298 <input name="smbd_pages" value = "pages" type = "checkbox" />
299 <label for="smbd_pages"><?php _e("All Pages", 'bulk-delete'); ?> (<?php echo $pages . " "; _e("Pages", 'bulk-delete'); ?>)</label>
300 </td>
301 </tr>
302
303 <tr>
304 <td>
305 <h4><?php _e("Choose your filtering options", 'bulk-delete'); ?></h4>
306 </td>
307 </tr>
308
309 <tr>
310 <td scope="row">
311 <input name="smbd_page_restrict" id="smbd_page_restrict" value = "true" type = "checkbox" onclick="toggle_date_restrict('page');" />
312 <?php _e("Only restrict to pages which are ", 'bulk-delete');?>
313 <select name="smbd_page_op" id="smbd_page_op" disabled>
314 <option value ="<"><?php _e("older than", 'bulk-delete');?></option>
315 <option value =">"><?php _e("posted within last", 'bulk-delete');?></option>
316 </select>
317 <input type ="textbox" name="smbd_page_days" id="smbd_page_days" disabled value ="0" maxlength="4" size="4" /><?php _e("days", 'bulk-delete');?>
318 </td>
319 </tr>
320
321 <tr>
322 <td scope="row">
323 <input name="smbd_page_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
324 <input name="smbd_page_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
325 </td>
326 </tr>
327
328 <tr>
329 <td scope="row">
330 <input name="smbd_page_limit" id="smbd_page_limit" value = "true" type = "checkbox" onclick="toggle_limit_restrict('page');" />
331 <?php _e("Only delete first ", 'bulk-delete');?>
332 <input type ="textbox" name="smbd_page_limit_to" id="smbd_page_limit_to" disabled value ="0" maxlength="4" size="4" /><?php _e("posts.", 'bulk-delete');?>
333 <?php _e("Use this option if there are more than 1000 posts and the script timesout.", 'bulk-delete') ?>
334 </td>
335 </tr>
336
337 </table>
338 </fieldset>
339
340 <p class="submit">
341 <input type="submit" name="submit" class="button-primary" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
342 </p>
343
344 <?php wp_nonce_field('bulk-delete-posts'); ?>
345
346 <input type="hidden" name="smbd_action" value="bulk-delete-page" />
347 </form>
348 </div>
349 </div>
350
351
352 <div class = "postbox">
353 <div class = "handlediv"> <br> </div>
354 <h3 class = "hndle"><span><?php _e("By Urls", 'bulk-delete'); ?></span></h3>
355 <div class = "inside">
356 <h4><?php _e("Delete these specific pages", 'bulk-delete'); ?></h4>
357
358 <form name="smbd_form" id = "smbd_specific_form" action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post" >
359
360 <fieldset class="options">
361 <table class="optiontable">
362 <tr>
363 <td scope="row">
364 <label for="smdb_specific_pages"><?php _e("Enter one post url (not post ids) per line", 'bulk-delete'); ?></label>
365 <br/>
366 <textarea style="width: 450px; height: 80px;" id="smdb_specific_pages_urls" name="smdb_specific_pages_urls" rows="5" columns="80" ></textarea>
367 </td>
368 </tr>
369
370 <tr>
371 <td>
372 <h4><?php _e("Choose your filtering options", 'bulk-delete'); ?></h4>
373 </td>
374 </tr>
375
376 <tr>
377 <td scope="row">
378 <input name="smbd_specific_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
379 <input name="smbd_specific_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
380 </td>
381 </tr>
382
383 </table>
384 </fieldset>
385
386 <p class="submit">
387 <input type="submit" name="submit" class="button-primary" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
388 </p>
389
390 <?php wp_nonce_field('bulk-delete-posts'); ?>
391
392 <input type="hidden" name="smbd_action" value="bulk-delete-specific" >
393 </form>
394 </div>
395 </div>
396
397
398 <div class = "postbox">
399 <div class = "handlediv">
400 <br>
401 </div>
402 <h3 class = "hndle"><span><?php _e("By Category", 'bulk-delete'); ?></span></h3>
403 <div class = "inside">
404 <h4><?php _e("Select the categories whose post you want to delete", 'bulk-delete'); ?></h4>
405
406 <form name="smbd_form" id = "smbd_cat_form"
407 action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post" onsubmit="return bd_validateForm(this);">
408
409 <fieldset class="options">
410 <table class="optiontable">
411 <?php
412 $categories = get_categories(array('hide_empty' => false));
413 foreach ($categories as $category) {
414 ?>
415 <tr>
416 <td scope="row" >
417 <input name="smbd_cats[]" value = "<?php echo $category->cat_ID; ?>" type = "checkbox" />
418 </td>
419 <td>
420 <label for="smbd_cats"><?php echo $category->cat_name; ?> (<?php echo $category->count . " "; _e("Posts", 'bulk-delete'); ?>)</label>
421 </td>
422 </tr>
423 <?php
424 }
425 ?>
426 <tr>
427 <td scope="row" >
428 <input name="smbd_cats_all" id ="smbd_cats_all" value = "-1" type = "checkbox" onclick="bd_checkAll(document.getElementById('smbd_cat_form'));" />
429 </td>
430 <td>
431 <label for="smbd_cats_all"><?php _e("All Categories", 'bulk-delete') ?></label>
432 </td>
433 </tr>
434
435 <tr>
436 <td colspan="2">
437 <h4><?php _e("Choose your filtering options", 'bulk-delete'); ?></h4>
438 </td>
439 </tr>
440
441 <tr>
442 <td scope="row">
443 <input name="smbd_cats_restrict" id="smbd_cats_restrict" value = "true" type = "checkbox" onclick="toggle_date_restrict('cats');" />
444 </td>
445 <td>
446 <?php _e("Only restrict to posts which are ", 'bulk-delete');?>
447 <select name="smbd_cats_op" id="smbd_cats_op" disabled>
448 <option value ="<"><?php _e("older than", 'bulk-delete');?></option>
449 <option value =">"><?php _e("posted within last", 'bulk-delete');?></option>
450 </select>
451 <input type ="textbox" name="smbd_cats_days" id="smbd_cats_days" disabled value ="0" maxlength="4" size="4" /><?php _e("days", 'bulk-delete');?>
452 </td>
453 </tr>
454
455 <tr>
456 <td scope="row" colspan="2">
457 <input name="smbd_cats_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
458 <input name="smbd_cats_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
459 </td>
460 </tr>
461
462 <tr>
463 <td scope="row" colspan="2">
464 <input name="smbd_cats_private" value = "false" type = "radio" checked="checked" /> <?php _e('Public posts', 'bulk-delete'); ?>
465 <input name="smbd_cats_private" value = "true" type = "radio" /> <?php _e('Private Posts', 'bulk-delete'); ?>
466 </td>
467 </tr>
468
469 <tr>
470 <td scope="row">
471 <input name="smbd_cats_limit" id="smbd_cats_limit" value = "true" type = "checkbox" onclick="toggle_limit_restrict('cats');" />
472 </td>
473 <td>
474 <?php _e("Only delete first ", 'bulk-delete');?>
475 <input type ="textbox" name="smbd_cats_limit_to" id="smbd_cats_limit_to" disabled value ="0" maxlength="4" size="4" /><?php _e("posts.", 'bulk-delete');?>
476 <?php _e("Use this option if there are more than 1000 posts and the script timesout.", 'bulk-delete') ?>
477 </td>
478 </tr>
479
480 <tr>
481 <td scope="row" colspan="2">
482 <input name="smbd_cats_cron" value = "false" type = "radio" checked="checked" /> <?php _e('Delete now', 'bulk-delete'); ?>
483 <input name="smbd_cats_cron" value = "true" type = "radio" id = "smbd_cats_cron" disabled > <?php _e('Schedule', 'bulk-delete'); ?>
484 <input name="smbd_cats_cron_start" id = "smbd_cats_cron_start" value = "now" type = "text" disabled><?php _e('repeat ', 'bulk-delete');?>
485 <select name = "smbd_cats_cron_freq" id = "smbd_cats_cron_freq" disabled>
486 <option value = "-1"><?php _e("Don't repeat", 'bulk-delete'); ?></option>
487 <?php
488 $schedules = wp_get_schedules();
489 foreach($schedules as $key => $value) {
490 ?>
491 <option value = "<?php echo $key; ?>"><?php echo $value['display']; ?></option>
492 <?php
493 }
494 ?>
495 </select>
496 <span class = "bd-cats-pro" style = "color:red"><?php _e('Only available in Pro Addon', 'bulk-delete'); ?> <a href = "http://sudarmuthu.com/out/bulk-delete-category-addon">Buy now</a></span>
497 </td>
498 </tr>
499 <tr>
500 <td scope="row" colspan="2">
501 <?php _e("Enter time in Y-m-d H:i:s format or enter now to use current time", 'bulk-delete');?>
502 </td>
503 </tr>
504
505 </table>
506 </fieldset>
507 <p class="submit">
508 <input type="submit" name="submit" class="button-primary" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
509 </p>
510
511 <?php wp_nonce_field('bulk-delete-posts'); ?>
512
513 <input type="hidden" name="smbd_action" value="bulk-delete-cats" />
514 </form>
515 </div>
516 </div>
517 <?php
518 $tags = get_tags();
519 if (count($tags) > 0) {
520 ?>
521 <div class = "postbox">
522 <div class = "handlediv">
523 <br>
524 </div>
525
526 <h3 class = "hndle"><span><?php _e("By Tags", 'bulk-delete'); ?></span></h3>
527
528 <div class = "inside">
529 <h4><?php _e("Select the tags whose post you want to delete", 'bulk-delete') ?></h4>
530
531 <form name="smbd_form" id = "smbd_tag_form"
532 action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post"
533 onsubmit="return bd_validateForm(this);">
534
535 <fieldset class="options">
536 <table class="optiontable">
537 <?php
538 foreach ($tags as $tag) {
539 ?>
540 <tr>
541 <td scope="row" >
542 <input name="smbd_tags[]" value = "<?php echo $tag->term_id; ?>" type = "checkbox" />
543 </td>
544 <td>
545 <label for="smbd_tags"><?php echo $tag->name; ?> (<?php echo $tag->count . " "; _e("Posts", 'bulk-delete'); ?>)</label>
546 </td>
547 </tr>
548 <?php
549 }
550 ?>
551 <tr>
552 <td scope="row" >
553 <input name="smbd_tags_all" id ="smbd_tags_all" value = "-1" type = "checkbox" onclick="bd_checkAll(document.getElementById('smbd_tag_form'));" />
554 </td>
555 <td>
556 <label for="smbd_tags_all"><?php _e("All Tags", 'bulk-delete') ?></label>
557 </td>
558 </tr>
559
560 <tr>
561 <td colspan="2">
562 <h4><?php _e("Choose your filtering options", 'bulk-delete'); ?></h4>
563 </td>
564 </tr>
565
566 <tr>
567 <td scope="row">
568 <input name="smbd_tags_restrict" id ="smbd_tags_restrict" value = "true" type = "checkbox" onclick="toggle_date_restrict('tags');" />
569 </td>
570 <td>
571 <?php _e("Only restrict to posts which are ", 'bulk-delete');?>
572 <select name="smbd_tags_op" id="smbd_tags_op" disabled>
573 <option value ="<"><?php _e("older than", 'bulk-delete');?></option>
574 <option value =">"><?php _e("posted within last", 'bulk-delete');?></option>
575 </select>
576 <input type ="textbox" name="smbd_tags_days" id ="smbd_tags_days" value ="0" maxlength="4" size="4" disabled /><?php _e("days", 'bulk-delete');?>
577 </td>
578 </tr>
579
580 <tr>
581 <td scope="row" colspan="2">
582 <input name="smbd_tags_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
583 <input name="smbd_tags_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
584 </td>
585 </tr>
586
587 <tr>
588 <td scope="row" colspan="2">
589 <input name="smbd_tags_private" value = "false" type = "radio" checked="checked" /> <?php _e('Public posts', 'bulk-delete'); ?>
590 <input name="smbd_tags_private" value = "true" type = "radio" /> <?php _e('Private Posts', 'bulk-delete'); ?>
591 </td>
592 </tr>
593
594 <tr>
595 <td scope="row">
596 <input name="smbd_tags_limit" id="smbd_tags_limit" value = "true" type = "checkbox" onclick="toggle_limit_restrict('tags');" />
597 </td>
598 <td>
599 <?php _e("Only delete first ", 'bulk-delete');?>
600 <input type ="textbox" name="smbd_tags_limit_to" id="smbd_tags_limit_to" disabled value ="0" maxlength="4" size="4" /><?php _e("posts.", 'bulk-delete');?>
601 <?php _e("Use this option if there are more than 1000 posts and the script timesout.", 'bulk-delete') ?>
602 </td>
603 </tr>
604
605 </table>
606 </fieldset>
607 <p class="submit">
608 <input type="submit" name="submit" class="button-primary" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
609 </p>
610
611 <?php wp_nonce_field('bulk-delete-posts'); ?>
612
613 <input type="hidden" name="smbd_action" value="bulk-delete-tags" />
614 </form>
615 </div>
616 </div>
617 <?php
618 }
619 ?>
620
621 <?php
622 $customTaxs = get_taxonomies();
623 if (count($customTaxs) > 0) {
624 ?>
625 <div class = "postbox">
626 <div class = "handlediv">
627 <br>
628 </div>
629 <h3 class = "hndle"><span><?php _e("By Taxonomies", 'bulk-delete'); ?></span></h3>
630 <div class = "inside">
631 <h4><?php _e("Select the taxonomies whose post you want to delete", 'bulk-delete') ?></h4>
632
633 <form name="smbd_form" id = "smbd_tax_form"
634 action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post"
635 onsubmit="return bd_validateForm(this);">
636
637 <fieldset class="options">
638 <table class="optiontable">
639 <?php
640 foreach ($customTaxs as $taxs) {
641
642 $posts = smbd_get_tax_post($taxs);
643 ?>
644 <tr>
645 <td scope="row" >
646 <input name="smbd_taxs[]" value = "<?php echo $taxs; ?>" type = "checkbox" />
647 </td>
648 <td>
649 <label for="smbd_taxs"><?php echo $taxs; ?> (<?php echo count($posts) . " "; _e("Posts", 'bulk-delete'); ?>)</label>
650 </td>
651 </tr>
652 <?php
653 }
654 ?>
655 <tr>
656 <td scope="row" >
657 <input name="smbd_taxs_all" id ="smbd_taxs_all" value = "-1" type = "checkbox" onclick="bd_checkAll(document.getElementById('smbd_tax_form'));" />
658 </td>
659 <td>
660 <label for="smbd_taxs_all"><?php _e("All Taxonomies", 'bulk-delete') ?></label>
661 </td>
662 </tr>
663
664 <tr>
665 <td colspan="2">
666 <h4><?php _e("Choose your filtering options", 'bulk-delete'); ?></h4>
667 </td>
668 </tr>
669
670 <tr>
671 <td scope="row">
672 <input name="smbd_taxs_restrict" id ="smbd_taxs_restrict" value = "true" type = "checkbox" onclick="toggle_date_restrict('taxs');" />
673 </td>
674 <td>
675 <?php _e("Only restrict to posts which are ", 'bulk-delete');?>
676 <select name="smbd_taxs_op" id="smbd_taxs_op" disabled>
677 <option value ="<"><?php _e("older than", 'bulk-delete');?></option>
678 <option value =">"><?php _e("posted within last", 'bulk-delete');?></option>
679 </select>
680 <input type ="textbox" name="smbd_taxs_days" id ="smbd_taxs_days" value ="0" maxlength="4" size="4" disabled /><?php _e("days", 'bulk-delete');?>
681 </td>
682 </tr>
683
684 <tr>
685 <td scope="row" colspan="2">
686 <input name="smbd_taxs_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
687 <input name="smbd_taxs_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
688 </td>
689 </tr>
690
691 <tr>
692 <td scope="row" colspan="2">
693 <input name="smbd_taxs_private" value = "false" type = "radio" checked="checked" /> <?php _e('Public posts', 'bulk-delete'); ?>
694 <input name="smbd_taxs_private" value = "true" type = "radio" /> <?php _e('Private Posts', 'bulk-delete'); ?>
695 </td>
696 </tr>
697
698 <tr>
699 <td scope="row">
700 <input name="smbd_taxs_limit" id="smbd_taxs_limit" value = "true" type = "checkbox" onclick="toggle_limit_restrict('taxs');" />
701 </td>
702 <td>
703 <?php _e("Only delete first ", 'bulk-delete');?>
704 <input type ="textbox" name="smbd_taxs_limit_to" id="smbd_taxs_limit_to" disabled value ="0" maxlength="4" size="4" /><?php _e("posts.", 'bulk-delete');?>
705 <?php _e("Use this option if there are more than 1000 posts and the script timesout.", 'bulk-delete') ?>
706 </td>
707 </tr>
708
709 </table>
710 </fieldset>
711 <p class="submit">
712 <input type="submit" class="button-primary" name="submit" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
713 </p>
714
715 <?php wp_nonce_field('bulk-delete-posts'); ?>
716
717 <input type="hidden" name="smbd_action" value="bulk-delete-taxs" />
718 </form>
719 </div>
720 </div>
721 <?php
722 }
723 ?>
724 <div class = "postbox">
725 <div class = "handlediv">
726 <br>
727 </div>
728 <h3 class = "hndle"><span><?php _e('Debug Information', 'bulk-delete'); ?></span></h3>
729 <div class = "inside">
730 <p><?php _e('If you are seeing a blank page after clicking the Bulk Delete button, then ', 'bulk-delete'); ?><a href = "http://sudarmuthu.com/wordpress/bulk-delete#faq-white-screen"><?php _e('check out this FAQ', 'bulk-delete');?></a>.
731 <?php _e('You also need need the following debug information.', 'bulk-delete'); ?></p>
732 <table cellspacing="10">
733 <tr>
734 <th align = "right"><?php _e('Available memory size ', 'bulk-delete');?></th>
735 <td><?php echo ini_get( 'memory_limit' ); ?></td>
736 </tr>
737 <tr>
738 <th align = "right"><?php _e('Script time out ', 'bulk-delete');?></th>
739 <td><?php echo ini_get( 'max_execution_time' ); ?></td>
740 </tr>
741 <tr>
742 <th align = "right"><?php _e('Script input time ', 'bulk-delete'); ?></th>
743 <td><?php echo ini_get( 'max_input_time' ); ?></td>
744 </tr>
745 </table>
746 </div>
747 </div>
748 </div>
749
750 <iframe frameBorder="0" height = "950" src = "http://sudarmuthu.com/projects/wordpress/bulk-delete/sidebar.php?color=<?php echo get_user_option('admin_color'); ?>"></iframe>
751
752 </div>
753 <?php
754
755 // Display credits in Footer
756 add_action( 'in_admin_footer', array(&$this, 'admin_footer' ));
757 }
758
759 /**
760 * Adds Footer links. Based on http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/
761 */
762 function admin_footer() {
763 $plugin_data = get_plugin_data( __FILE__ );
764 printf('%1$s ' . __("plugin", 'bulk-delete') .' | ' . __("Version", 'bulk-delete') . ' %2$s | '. __('by', 'bulk-delete') . ' %3$s<br />', $plugin_data['Title'], $plugin_data['Version'], $plugin_data['Author']);
765 }
766
767 /**
768 * Display the schedule page
769 */
770 function display_cron_page() {
771
772 if(!class_exists('WP_List_Table')){
773 require_once( ABSPATH . WPINC . '/class-wp-list-table.php' );
774 }
775 if (!class_exists('Cron_List_Table')) {
776 require_once dirname(__FILE__) . '/include/class-cron-list-table.php';
777 }
778
779 //Prepare Table of elements
780 $cron_list_table = new Cron_List_Table();
781 $cron_list_table->prepare_items($this->get_cron_schedules());
782
783 ?>
784 <div class="wrap">
785 <?php screen_icon(); ?>
786 <h2><?php _e('Bulk Delete Schedules', 'bulk-delete');?></h2>
787 <?php
788 //Table of elements
789 $cron_list_table->display();
790 ?>
791 </div>
792 <?php
793 }
794
795 /**
796 * Request Handler
797 */
798 function request_handler() {
799 global $wpdb;
800
801 if (isset($_GET['smbd_action'])) {
802
803 switch($_GET['smbd_action']) {
804
805 case 'delete-cron':
806 //TODO: Check for nonce and referer
807 $cron_id = absint($_GET['cron_id']);
808 $cron_items = $this->get_cron_schedules();
809 wp_unschedule_event($cron_items[$cron_id]['timestamp'], $cron_items[$cron_id]['type'], $cron_items[$cron_id]['args']);
810
811 break;
812 }
813 }
814
815 if (isset($_POST['smbd_action'])) {
816
817 $wp_query = new WP_Query;
818 check_admin_referer( 'bulk-delete-posts');
819
820 switch($_POST['smbd_action']) {
821
822 case "bulk-delete-cats":
823 // delete by cats
824
825 $delete_options = array();
826 $delete_options['selected_cats'] = array_get($_POST, 'smbd_cats');
827 $delete_options['restrict'] = array_get($_POST, 'smbd_cats_restrict', FALSE);
828 $delete_options['private'] = array_get($_POST, 'smbd_cats_private');
829 $delete_options['limit_to'] = absint(array_get($_POST, 'smbd_cats_limits_to', 0));
830 $delete_options['force_delete'] = array_get($_POST, 'smbd_cats_force_delete', 'false');
831
832 $delete_options['cats_op'] = array_get($_POST, 'smbd_cats_op');
833 $delete_options['cats_days'] = array_get($_POST, 'smbd_cats_days');
834
835 if (array_get($_POST, 'smbd_cats_cron', 'false') == 'true') {
836 $freq = $_POST['smbd_cats_cron_freq'];
837 $time = strtotime($_POST['smbd_cats_cron_start']) - ( get_option('gmt_offset') * 60 * 60 );
838
839 if ($freq == -1) {
840 wp_schedule_single_event($time, 'do-bulk-delete-cats', array($delete_options));
841 } else {
842 wp_schedule_event($time, $freq , 'do-bulk-delete-cats', array($delete_options));
843 }
844 } else {
845 self::delete_cats($delete_options);
846 }
847
848 break;
849
850 case "bulk-delete-tags":
851 // delete by tags
852 $selected_tags = array_get($_POST, 'smbd_tags');
853 if (array_get($_POST, 'smbd_tags_restrict', 'false') == "true") {
854 add_filter ('posts_where', 'smbd_tags_by_days');
855 }
856
857 $private = array_get($_POST, 'smbd_tags_private', 'false');
858
859 if ($private == 'true') {
860 $options = array('tag__in'=>$selected_tags,'post_status'=>'private', 'post_type'=>'post');
861 } else {
862 $options = array('tag__in'=>$selected_tags,'post_status'=>'publish', 'post_type'=>'post');
863 }
864
865 $limit_to = absint(array_get($_POST, 'smbd_tags_limits_to', 0));
866
867 if ($limit_to > 0) {
868 $options['showposts'] = $limit_to;
869 } else {
870 $options['nopaging'] = 'true';
871 }
872
873 $force_delete = array_get($_POST, 'smbd_tags_force_delete');
874
875 if ($force_delete == 'true') {
876 $force_delete = true;
877 } else {
878 $force_delete = false;
879 }
880
881 $posts = $wp_query->query($options);
882
883 foreach ($posts as $post) {
884 wp_delete_post($post->ID, $force_delete);
885 }
886
887 break;
888
889 case "bulk-delete-taxs":
890 // delete by taxs
891 $selected_taxs = array_get($_POST, 'smbd_taxs');
892
893 foreach ($selected_taxs as $selected_tax) {
894 $postids = smbd_get_tax_post($selected_tax);
895
896 if (array_get($_POST, 'smbd_taxs_restrict', 'false') == "true") {
897 add_filter ('posts_where', 'smbd_taxs_by_days');
898 }
899
900 $private = array_get($_POST, 'smbd_taxs_private');
901
902 if ($private == 'true') {
903 $options = array('post__in'=>$postids,'post_status'=>'private', 'post_type'=>'post');
904 } else {
905 $options = array('post__in'=>$postids,'post_status'=>'publish', 'post_type'=>'post');
906 }
907
908 $limit_to = absint(array_get($_POST, 'smbd_taxs_limits_to', 0));
909
910 if ($limit_to > 0) {
911 $options['showposts'] = $limit_to;
912 } else {
913 $options['nopaging'] = 'true';
914 }
915
916 $force_delete = array_get($_POST, 'smbd_taxs_force_delete');
917
918 if ($force_delete == 'true') {
919 $force_delete = true;
920 } else {
921 $force_delete = false;
922 }
923
924 $posts = $wp_query->query($options);
925 foreach ($posts as $post) {
926 wp_delete_post($post->ID, $force_delete);
927 }
928 }
929
930 break;
931
932 case "bulk-delete-special":
933 // Delete special types like drafts, reviesion etc
934
935 $delete_options = array();
936 $delete_options['restrict'] = array_get($_POST, 'smbd_special_restrict', FALSE);
937 $delete_options['limit_to'] = absint(array_get($_POST, 'smbd_special_limits_to', 0));
938 $delete_options['force_delete'] = array_get($_POST, 'smbd_special_force_delete', 'false');
939
940 $delete_options['special_op'] = array_get($_POST, 'smbd_special_op');
941 $delete_options['special_days'] = array_get($_POST, 'smbd_special_days');
942
943 $delete_options['drafts'] = array_get($_POST, 'smbd_drafts');
944 $delete_options['revisions'] = array_get($_POST, 'smbd_revisions');
945 $delete_options['pending'] = array_get($_POST, 'smbd_pending');
946 $delete_options['future'] = array_get($_POST, 'smbd_future');
947 $delete_options['private'] = array_get($_POST, 'smbd_private');
948
949 if (array_get($_POST, 'smbd_special_cron', 'false') == 'true') {
950 $freq = $_POST['smbd_special_cron_freq'];
951 $time = strtotime($_POST['smbd_special_cron_start']) - ( get_option('gmt_offset') * 60 * 60 );
952
953 if ($freq == -1) {
954 wp_schedule_single_event($time, 'do-bulk-delete-special', array($delete_options));
955 } else {
956 wp_schedule_event($time, $freq , 'do-bulk-delete-special', array($delete_options));
957 }
958 } else {
959 self::delete_special($delete_options);
960 }
961
962 break;
963
964 case "bulk-delete-page":
965 // Delete pages
966
967 $delete_options = array();
968 $delete_options['restrict'] = array_get($_POST, 'smbd_page_restrict', FALSE);
969 $delete_options['limit_to'] = absint(array_get($_POST, 'smbd_page_limits_to', 0));
970 $delete_options['force_delete'] = array_get($_POST, 'smbd_page_force_delete', 'false');
971
972 $delete_options['page_op'] = array_get($_POST, 'smbd_page_op');
973 $delete_options['page_days'] = array_get($_POST, 'smbd_page_days');
974
975 $delete_options['pages'] = array_get($_POST, 'smbd_pages');
976
977 if (array_get($_POST, 'smbd_page_cron', 'false') == 'true') {
978 $freq = $_POST['smbd_page_cron_freq'];
979 $time = strtotime($_POST['smbd_page_cron_start']) - ( get_option('gmt_offset') * 60 * 60 );
980
981 if ($freq == -1) {
982 wp_schedule_single_event($time, 'do-bulk-delete-page', array($delete_options));
983 } else {
984 wp_schedule_event($time, $freq , 'do-bulk-delete-page', array($delete_options));
985 }
986 } else {
987 self::delete_pages($delete_options);
988 }
989
990 break;
991
992 case "bulk-delete-specific":
993 // Delete pages
994
995 $force_delete = array_get($_POST, 'smbd_specific_force_delete');
996 if ($force_delete == 'true') {
997 $force_delete = true;
998 } else {
999 $force_delete = false;
1000 }
1001
1002 $urls = preg_split( '/\r\n|\r|\n/', array_get($_POST, 'smdb_specific_pages_urls') );
1003 foreach ($urls as $url) {
1004 $checkedurl = $url;
1005 if (substr($checkedurl ,0,1) == '/') {
1006 $checkedurl = get_site_url() . $checkedurl ;
1007 }
1008 $postid = url_to_postid( $checkedurl );
1009 wp_delete_post($postid, $force_delete);
1010 }
1011 break;
1012 }
1013
1014 // hook the admin notices action
1015 add_action( 'admin_notices', array(&$this, 'deleted_notice'), 9 );
1016 }
1017 }
1018
1019 /**
1020 * Show deleted notice messages
1021 */
1022 function deleted_notice() {
1023 echo "<div class = 'updated'><p>" . __("All the selected posts have been successfully deleted.", 'bulk-delete') . "</p></div>";
1024 }
1025
1026 /**
1027 * Delete posts by category
1028 */
1029 static function delete_cats($delete_options) {
1030
1031 $selected_cats = $delete_options['selected_cats'];
1032
1033 $private = $delete_options['private'];
1034
1035 if ($private == 'true') {
1036 $options = array('category__in'=>$selected_cats,'post_status'=>'private', 'post_type'=>'post');
1037 } else {
1038 $options = array('category__in'=>$selected_cats,'post_status'=>'publish', 'post_type'=>'post');
1039 }
1040
1041 $limit_to = $delete_options['limit_to'];
1042
1043 if ($limit_to > 0) {
1044 $options['showposts'] = $limit_to;
1045 } else {
1046 $options['nopaging'] = 'true';
1047 }
1048
1049 $force_delete = $delete_options['force_delete'];
1050
1051 if ($force_delete == 'true') {
1052 $force_delete = true;
1053 } else {
1054 $force_delete = false;
1055 }
1056
1057 if ($delete_options['restrict'] == "true") {
1058 $options['cats_op'] = $delete_options['cats_op'];
1059 $options['cats_days'] = $delete_options['cats_days'];
1060
1061 if (!class_exists('Bulk_Delete_By_Days')) {
1062 require_once dirname(__FILE__) . '/include/class-bulk-delete-by-days.php';
1063 }
1064 $bulk_Delete_By_Days = new Bulk_Delete_By_Days;
1065 }
1066
1067 $wp_query = new WP_Query();
1068 $posts = $wp_query->query($options);
1069
1070 foreach ($posts as $post) {
1071 wp_delete_post($post->ID, $force_delete);
1072 }
1073 }
1074
1075 /**
1076 * Delete special type of posts - drafts, revisions etc.
1077 */
1078 static function delete_special($delete_options) {
1079 global $wp_query;
1080
1081 $options = array();
1082
1083 $limit_to = $delete_options['limit_to'];
1084
1085 if ($limit_to > 0) {
1086 $options['showposts'] = $limit_to;
1087 } else {
1088 $options['nopaging'] = 'true';
1089 }
1090
1091 $force_delete = $delete_options['force_delete'];
1092
1093 if ($force_delete == 'true') {
1094 $force_delete = true;
1095 } else {
1096 $force_delete = false;
1097 }
1098
1099 if ($delete_options['restrict'] == "true") {
1100 $options['op'] = $delete_options['special_op'];
1101 $options['days'] = $delete_options['special_days'];
1102
1103 if (!class_exists('Bulk_Delete_By_Days')) {
1104 require_once dirname(__FILE__) . '/include/class-bulk-delete-by-days.php';
1105 }
1106 $bulk_Delete_By_Days = new Bulk_Delete_By_Days;
1107 }
1108
1109 // Drafts
1110 if ("drafts" == $delete_options['drafts']) {
1111 $options['post_status'] = 'draft';
1112 $drafts = $wp_query->query($options);
1113
1114 foreach ($drafts as $draft) {
1115 wp_delete_post($draft->ID, $force_delete);
1116 }
1117 }
1118
1119 // Revisions
1120 if ("revisions" == $delete_options['revisions']) {
1121 $revisions = $wpdb->get_results("select ID from $wpdb->posts where post_type = 'revision'");
1122
1123 foreach ($revisions as $revision) {
1124 wp_delete_post($revision->ID, $force_delete);
1125 }
1126 }
1127
1128 // Pending Posts
1129 if ("pending" == $delete_options['pending']) {
1130 $pendings = $wpdb->get_results("select ID from $wpdb->posts where post_status = 'pending'");
1131
1132 foreach ($pendings as $pending) {
1133 wp_delete_post($pending->ID, $force_delete);
1134 }
1135 }
1136
1137 // Future Posts
1138 if ("future" == $delete_options['future']) {
1139 $futures = $wpdb->get_results("select ID from $wpdb->posts where post_status = 'future'");
1140
1141 foreach ($futures as $future) {
1142 wp_delete_post($future->ID, $force_delete);
1143 }
1144 }
1145
1146 // Private Posts
1147 if ("private" == $delete_options['private']) {
1148 $privates = $wpdb->get_results("select ID from $wpdb->posts where post_status = 'private'");
1149
1150 foreach ($privates as $private) {
1151 wp_delete_post($private->ID, $force_delete);
1152 }
1153 }
1154 }
1155
1156 /**
1157 * Delete pages
1158 */
1159 static function delete_pages($delete_options) {
1160 global $wp_query;
1161
1162 $options = array();
1163
1164 $limit_to = $delete_options['limit_to'];
1165
1166 if ($limit_to > 0) {
1167 $options['showposts'] = $limit_to;
1168 } else {
1169 $options['nopaging'] = 'true';
1170 }
1171
1172 $force_delete = $delete_options['force_delete'];
1173
1174 if ($force_delete == 'true') {
1175 $force_delete = true;
1176 } else {
1177 $force_delete = false;
1178 }
1179
1180 if ($delete_options['restrict'] == "true") {
1181 $options['op'] = $delete_options['page_op'];
1182 $options['days'] = $delete_options['page_days'];
1183
1184 if (!class_exists('Bulk_Delete_By_Days')) {
1185 require_once dirname(__FILE__) . '/include/class-bulk-delete-by-days.php';
1186 }
1187 $bulk_Delete_By_Days = new Bulk_Delete_By_Days;
1188 }
1189
1190 // Pages
1191 if ("pages" == $delete_options['pages']) {
1192 $options['post_type'] = 'page';
1193 $pages = $wp_query->query($options);
1194
1195 foreach ($pages as $page) {
1196 wp_delete_post($page->ID, $force_delete);
1197 }
1198 }
1199 }
1200
1201 /**
1202 * Get the list of cron schedules
1203 *
1204 * @return array - The list of cron schedules
1205 */
1206 private function get_cron_schedules() {
1207
1208 $cron_items = array();
1209 $cron = _get_cron_array();
1210 $date_format = _x( 'M j, Y @ G:i', 'Cron table date format', 'bulk-delete' );
1211 $i = 0;
1212
1213 foreach ( $cron as $timestamp => $cronhooks ) {
1214 foreach ( (array) $cronhooks as $hook => $events ) {
1215 if (substr($hook, 0, 15) == 'do-bulk-delete-') {
1216 $cron_item = array();
1217
1218 foreach ( (array) $events as $key => $event ) {
1219 $cron_item['timestamp'] = $timestamp;
1220 $cron_item['due'] = date_i18n( $date_format, $timestamp + ( get_option('gmt_offset') * 60 * 60 ) );
1221 $cron_item['schedule'] = $event['schedule'];
1222 $cron_item['type'] = $hook;
1223 $cron_item['args'] = $event['args'];
1224 $cron_item['id'] = $i;
1225 }
1226
1227 $cron_items[$i] = $cron_item;
1228 $i++;
1229 }
1230 }
1231 }
1232 return $cron_items;
1233 }
1234 }
1235
1236 // Start this plugin once all other plugins are fully loaded
1237 add_action( 'init', 'Bulk_Delete' ); function Bulk_Delete() { global $Bulk_Delete; $Bulk_Delete = new Bulk_Delete(); }
1238
1239 /**
1240 * Check whether a key is present. If present returns the value, else returns the default value
1241 *
1242 * @param <array> $array - Array whose key has to be checked
1243 * @param <string> $key - key that has to be checked
1244 * @param <string> $default - the default value that has to be used, if the key is not found (optional)
1245 *
1246 * @return <mixed> If present returns the value, else returns the default value
1247 * @author Sudar
1248 */
1249 if (!function_exists('array_get')) {
1250 function array_get($array, $key, $default = NULL) {
1251 return isset($array[$key]) ? $array[$key] : $default;
1252 }
1253 }
1254
1255 /**
1256 * function to filter posts by days
1257 * @param <type> $where
1258 * @return <type>
1259 */
1260 if (!function_exists('smbd_tags_by_days ')) {
1261 function smbd_tags_by_days ($where = '') {
1262 $tags_op = array_get($_POST, 'smbd_tags_op');
1263 $tags_days = array_get($_POST, 'smbd_tags_days');
1264
1265 remove_filter('posts_where', 'smbd_tags_by_days');
1266
1267 $where .= " AND post_date $tags_op '" . date('y-m-d', strtotime("-$tags_days days")) . "'";
1268 return $where;
1269 }
1270 }
1271
1272 /**
1273 * function to filter custom taxonomy posts by days
1274 * @param <type> $where
1275 * @return <type>
1276 */
1277 if (!function_exists('smbd_taxs_by_days ')) {
1278 function smbd_taxs_by_days ($where = '') {
1279 $taxs_op = array_get($_POST, 'smbd_taxs_op');
1280 $taxs_days = array_get($_POST, 'smbd_taxs_days');
1281
1282 remove_filter('posts_where', 'smbd_taxs_by_days');
1283
1284 $where .= " AND post_date $taxs_op '" . date('y-m-d', strtotime("-$taxs_days days")) . "'";
1285 return $where;
1286 }
1287 }
1288
1289 /**
1290 * Return the posts for a taxonomy
1291 *
1292 * @param <type> $tax
1293 * @return <type>
1294 */
1295 if (!function_exists('smbd_get_tax_post')) {
1296 function smbd_get_tax_post($tax) {
1297 global $wpdb;
1298
1299 $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 = '%s')", $tax);
1300 $post_ids_result = $wpdb->get_results($query);
1301
1302 $postids = array();
1303 foreach ($post_ids_result as $post_id_result) {
1304 $postids[] = $post_id_result->object_id;
1305 }
1306
1307 return $postids;
1308 }
1309 }
1310 ?>
1311