PluginProbe
Bulk Delete / 2.1
Bulk Delete v2.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 2.1, at bulk-delete.php

951 lines 39.5 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 or tags. Use it with caution.
7 Donate Link: http://sudarmuthu.com/if-you-wanna-thank-me
8 Version: 2.1
9 License: GPL
10 Author: Sudar
11 Author URI: http://sudarmuthu.com/
12 Text Domain: bulk-delete
13
14 === RELEASE NOTES ===
15 2009-02-02 - v0.1 - first version
16 2009-02-03 - v0.2 - Second release - Fixed issues with pagging
17 2009-04-05 - v0.3 - Third release - Prevented drafts from deleted when only posts are selected
18 2009-07-05 - v0.4 - Fourth release - Added option to delete by date.
19 2009-07-21 - v0.5 - Fifth release - Added option to delete all pending posts.
20 2009-07-22 - v0.6 - Sixth release - Added option to delete all scheduled posts.
21 2010-02-21 - v0.7 - Added an option to delete posts directly or send them to trash and support for translation.
22 2010-03-17 - v0.8 - Added support for private posts.
23 2010-06-19 - v1.0 - Proper handling of limits.
24 2011-01-22 - v1.1 - Added support to delete posts by custom taxonomies
25 2011-02-06 - v1.2 - Added some optimization to handle huge number of posts in underpowered servers
26 2011-05-11 - v1.3 - Added German translations
27 2011-08-25 - v1.4 - Added Turkish translations
28 2011-11-13 - v1.5 - Added Spanish translations
29 2011-11-28 - v1.6 - Added Italian translations
30 2012-01-12 - v1.7 - Added Bulgarian translations
31 2012-01-31 - v1.8 - Added roles and capabilities for menu
32 2012-03-16 - v1.9 - Added support for deleting by permalink. Credit Martin Capodici
33 - Fixed issues with translations
34 - Added Rusian translations
35 2012-04-01 - v2.0 (10 hours) - Fixed a major issue in how dates were handled.
36 - Major UI revamp
37 - Added debug information and support urls
38 2012-04-07 - v2.1 (1 hour) - Fixed CSS issues in IE.
39 - Added Lithuanian translations
40
41 */
42
43 /* Copyright 2009 Sudar Muthu (email : sudar@sudarmuthu.com)
44
45 This program is free software; you can redistribute it and/or modify
46 it under the terms of the GNU General Public License, version 2, as
47 published by the Free Software Foundation.
48
49 This program is distributed in the hope that it will be useful,
50 but WITHOUT ANY WARRANTY; without even the implied warranty of
51 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52 GNU General Public License for more details.
53
54 You should have received a copy of the GNU General Public License
55 along with this program; if not, write to the Free Software
56 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
57 */
58
59 /**
60 * Request Handler
61 */
62
63 if (!function_exists('smbd_request_handler')) {
64 function smbd_request_handler() {
65 global $wpdb;
66
67 // Load localization domain
68 load_plugin_textdomain( 'bulk-delete', false, dirname(plugin_basename(__FILE__)) . '/languages' );
69
70 if (isset($_POST['smbd_action'])) {
71
72 $wp_query = new WP_Query;
73 check_admin_referer( 'bulk-delete-posts');
74
75 switch($_POST['smbd_action']) {
76
77 case "bulk-delete-cats":
78 // delete by cats
79 $selected_cats = $_POST['smbd_cats'];
80 if ($_POST['smbd_cats_restrict'] == "true") {
81
82 add_filter ('posts_where', 'smbd_cats_by_days');
83 }
84
85 $private = $_POST['smbd_cats_private'];
86
87 if ($private == 'true') {
88 $options = array('category__in'=>$selected_cats,'post_status'=>'private', 'post_type'=>'post');
89 } else {
90 $options = array('category__in'=>$selected_cats,'post_status'=>'publish', 'post_type'=>'post');
91 }
92
93 $limit_to = absint($_POST['smbd_cats_limits_to']);
94
95 if ($limit_to > 0) {
96 $options['showposts'] = $limit_to;
97 } else {
98 $options['nopaging'] = 'true';
99 }
100
101 $force_delete = $_POST['smbd_cats_force_delete'];
102
103 if ($force_delete == 'true') {
104 $force_delete = true;
105 } else {
106 $force_delete = false;
107 }
108
109 $posts = $wp_query->query($options);
110 foreach ($posts as $post) {
111 wp_delete_post($post->ID, $force_delete);
112 }
113
114 break;
115
116 case "bulk-delete-tags":
117 // delete by tags
118 $selected_tags = $_POST['smbd_tags'];
119 if ($_POST['smbd_tags_restrict'] == "true") {
120 add_filter ('posts_where', 'smbd_tags_by_days');
121 }
122
123 $private = $_POST['smbd_tags_private'];
124
125 if ($private == 'true') {
126 $options = array('tag__in'=>$selected_tags,'post_status'=>'private', 'post_type'=>'post');
127 } else {
128 $options = array('tag__in'=>$selected_tags,'post_status'=>'publish', 'post_type'=>'post');
129 }
130
131 $limit_to = absint($_POST['smbd_tags_limits_to']);
132
133 if ($limit_to > 0) {
134 $options['showposts'] = $limit_to;
135 } else {
136 $options['nopaging'] = 'true';
137 }
138
139 $force_delete = $_POST['smbd_tags_force_delete'];
140
141 if ($force_delete == 'true') {
142 $force_delete = true;
143 } else {
144 $force_delete = false;
145 }
146
147 $posts = $wp_query->query($options);
148
149 foreach ($posts as $post) {
150 wp_delete_post($post->ID, $force_delete);
151 }
152
153 break;
154
155 case "bulk-delete-taxs":
156 // delete by taxs
157 $selected_taxs = $_POST['smbd_taxs'];
158
159 foreach ($selected_taxs as $selected_tax) {
160 $postids = smbd_get_tax_post($selected_tax);
161
162 if ($_POST['smbd_taxs_restrict'] == "true") {
163 add_filter ('posts_where', 'smbd_taxs_by_days');
164 }
165
166 $private = $_POST['smbd_taxs_private'];
167
168 if ($private == 'true') {
169 $options = array('post__in'=>$postids,'post_status'=>'private', 'post_type'=>'post');
170 } else {
171 $options = array('post__in'=>$postids,'post_status'=>'publish', 'post_type'=>'post');
172 }
173
174 $limit_to = absint($_POST['smbd_taxs_limits_to']);
175
176 if ($limit_to > 0) {
177 $options['showposts'] = $limit_to;
178 } else {
179 $options['nopaging'] = 'true';
180 }
181
182 $force_delete = $_POST['smbd_taxs_force_delete'];
183
184 if ($force_delete == 'true') {
185 $force_delete = true;
186 } else {
187 $force_delete = false;
188 }
189
190 $posts = $wp_query->query($options);
191 foreach ($posts as $post) {
192 wp_delete_post($post->ID, $force_delete);
193 }
194 }
195
196 break;
197
198 case "bulk-delete-special":
199 $options = array();
200
201 $limit_to = absint($_POST['smbd_special_limit_to']);
202
203 if ($limit_to > 0) {
204 $options['showposts'] = $limit_to;
205 } else {
206 $options['nopaging'] = 'true';
207 }
208
209 $force_delete = $_POST['smbd_special_force_delete'];
210 if ($force_delete == 'true') {
211 $force_delete = true;
212 } else {
213 $force_delete = false;
214 }
215
216 // Drafts
217 if ("drafs" == $_POST['smbd_drafs']) {
218 $options['post_status'] = 'draft';
219 $drafts = $wp_query->query($options);
220
221 foreach ($drafts as $draft) {
222 wp_delete_post($draft->ID, $force_delete);
223 }
224 }
225
226 // Revisions
227 if ("revisions" == $_POST['smbd_revisions']) {
228 $revisions = $wpdb->get_results($wpdb->prepare("select ID from $wpdb->posts where post_type = 'revision'"));
229
230 foreach ($revisions as $revision) {
231 wp_delete_post($revision->ID, $force_delete);
232 }
233 }
234
235 // Pending Posts
236 if ("pending" == $_POST['smbd_pending']) {
237 $pendings = $wpdb->get_results($wpdb->prepare("select ID from $wpdb->posts where post_status = 'pending'"));
238
239 foreach ($pendings as $pending) {
240 wp_delete_post($pending->ID, $force_delete);
241 }
242 }
243
244 // Future Posts
245 if ("future" == $_POST['smbd_future']) {
246 $futures = $wpdb->get_results($wpdb->prepare("select ID from $wpdb->posts where post_status = 'future'"));
247
248 foreach ($futures as $future) {
249 wp_delete_post($future->ID, $force_delete);
250 }
251 }
252
253 // Private Posts
254 if ("private" == $_POST['smbd_private']) {
255 $privates = $wpdb->get_results($wpdb->prepare("select ID from $wpdb->posts where post_status = 'private'"));
256
257 foreach ($privates as $private) {
258 wp_delete_post($private->ID, $force_delete);
259 }
260 }
261
262 // Pages
263 if ("pages" == $_POST['smbd_pages']) {
264 $options['post_type'] = 'page';
265 $pages = $wp_query->query($options);
266
267 foreach ($pages as $page) {
268 wp_delete_post($page->ID, $force_delete);
269 }
270 }
271
272 // Specific Pages
273 if ("specificpages" == $_POST['smdb_specific_pages']) {
274 $urls = preg_split( '/\r\n|\r|\n/', $_POST['smdb_specific_pages_urls'] );
275 foreach ($urls as $url) {
276 $checkedurl = $url;
277 if (substr($checkedurl ,0,1) == '/') {
278 $checkedurl = get_site_url() . $checkedurl ;
279 }
280 $postid = url_to_postid( $checkedurl );
281 wp_delete_post($postid, $force_delete);
282 }
283 }
284
285 break;
286 }
287
288 // hook the admin notices action
289 add_action( 'admin_notices', 'smbd_deleted_notice', 9 );
290 }
291 }
292 }
293
294 /**
295 * Show deleted notice messages
296 */
297 if (!function_exists('smbd_deleted_notice')) {
298 function smbd_deleted_notice() {
299 echo "<div class = 'updated'><p>" . __("All the selected posts have been successfully deleted.", 'bulk-delete') . "</p></div>";
300 }
301 }
302
303 /**
304 * Show the Admin page
305 */
306 if (!function_exists('smbd_displayOptions')) {
307 function smbd_displayOptions() {
308 global $wpdb;
309 ?>
310 <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>
311
312 <div class="wrap">
313 <?php screen_icon(); ?>
314 <h2>Bulk Delete</h2>
315
316 <div id = "poststuff" style = "float:left; width:75%">
317 <div class = "postbox">
318 <div class = "handlediv">
319 <br>
320 </div>
321 <h3 class = "hndle"><span><?php _e("By Type", 'bulk-delete'); ?></span></h3>
322 <div class = "inside">
323 <h4><?php _e("Select the posts which you want to delete", 'bulk-delete'); ?></h4>
324
325 <form name="smbd_form" id = "smbd_misc_form"
326 action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post"
327 onsubmit="return bd_validateForm(this);">
328
329 <?php
330 $wp_query = new WP_Query;
331 $drafts = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_status = 'draft'"));
332 $revisions = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_type = 'revision'"));
333 $pending = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_status = 'pending'"));
334 $future = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_status = 'future'"));
335 $private = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_status = 'private'"));
336 $pages = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_type = 'page'"));
337 ?>
338 <fieldset class="options">
339 <table class="optiontable">
340 <tr>
341 <td scope="row" >
342 <input name="smbd_drafs" id ="smbd_drafs" value = "drafs" type = "checkbox" />
343 <label for="smbd_drafs"><?php _e("All Drafts", 'bulk-delete'); ?> (<?php echo $drafts . " "; _e("Drafts", 'bulk-delete'); ?>)</label>
344 </td>
345 </tr>
346
347 <tr>
348 <td>
349 <input name="smbd_revisions" id ="smbd_revisions" value = "revisions" type = "checkbox" />
350 <label for="smbd_revisions"><?php _e("All Revisions", 'bulk-delete'); ?> (<?php echo $revisions . " "; _e("Revisions", 'bulk-delete'); ?>)</label>
351 </td>
352 </tr>
353
354 <tr>
355 <td>
356 <input name="smbd_pending" id ="smbd_pending" value = "pending" type = "checkbox" />
357 <label for="smbd_pending"><?php _e("All Pending posts", 'bulk-delete'); ?> (<?php echo $pending . " "; _e("Posts", 'bulk-delete'); ?>)</label>
358 </td>
359 </tr>
360
361 <tr>
362 <td>
363 <input name="smbd_future" id ="smbd_future" value = "future" type = "checkbox" />
364 <label for="smbd_future"><?php _e("All scheduled posts", 'bulk-delete'); ?> (<?php echo $future . " "; _e("Posts", 'bulk-delete'); ?>)</label>
365 </td>
366 </tr>
367
368 <tr>
369 <td>
370 <input name="smbd_private" id ="smbd_private" value = "private" type = "checkbox" />
371 <label for="smbd_private"><?php _e("All private posts", 'bulk-delete'); ?> (<?php echo $private . " "; _e("Posts", 'bulk-delete'); ?>)</label>
372 </td>
373 </tr>
374
375 <tr>
376 <td>
377 <input name="smbd_pages" value = "pages" type = "checkbox" />
378 <label for="smbd_pages"><?php _e("All Pages", 'bulk-delete'); ?> (<?php echo $pages . " "; _e("Pages", 'bulk-delete'); ?>)</label>
379 </td>
380 </tr>
381
382 <tr>
383 <td scope="row">
384 <input name="smdb_specific_pages" id="smdb_specific_pages" value = "specificpages" type = "checkbox" />
385 <label for="smdb_specific_pages"><?php _e("Delete these specific pages (Enter one post url (not post ids) per line)", 'bulk-delete'); ?></label>
386 <br/>
387 <textarea style="width: 450px; height: 80px;" id="smdb_specific_pages_urls" name="smdb_specific_pages_urls" rows="5" columns="80" ></textarea>
388 </td>
389 </tr>
390
391 <tr>
392 <td>
393 <h4><?php _e("Choose your filtering options", 'bulk-delete'); ?></h4>
394 </td>
395 </tr>
396
397 <tr>
398 <td scope="row">
399 <input name="smbd_special_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
400 <input name="smbd_special_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
401 </td>
402 </tr>
403
404 <tr>
405 <td scope="row">
406 <input name="smbd_special_limit" id="smbd_special_limit" value = "true" type = "checkbox" onclick="toggle_limit_restrict('special');" />
407 <?php _e("Only delete first ", 'bulk-delete');?>
408 <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');?>
409 <?php _e("Use this option if there are more than 1000 posts and the script timesout.", 'bulk-delete') ?>
410 </td>
411 </tr>
412
413 </table>
414 </fieldset>
415
416 <p class="submit">
417 <input type="submit" name="submit" class="button-primary" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
418 </p>
419
420 <?php wp_nonce_field('bulk-delete-posts'); ?>
421
422 <input type="hidden" name="smbd_action" value="bulk-delete-special" />
423 </form>
424 </div>
425 </div>
426
427 <div class = "postbox">
428 <div class = "handlediv">
429 <br>
430 </div>
431 <h3 class = "hndle"><span><?php _e("By Category", 'bulk-delete'); ?></span></h3>
432 <div class = "inside">
433 <h4><?php _e("Select the categories whose post you want to delete", 'bulk-delete'); ?></h4>
434
435 <form name="smbd_form" id = "smbd_cat_form"
436 action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post" onsubmit="return bd_validateForm(this);">
437
438 <fieldset class="options">
439 <table class="optiontable">
440 <?php
441 $categories = get_categories(array('hide_empty' => false));
442 foreach ($categories as $category) {
443 ?>
444 <tr>
445 <td scope="row" >
446 <input name="smbd_cats[]" value = "<?php echo $category->cat_ID; ?>" type = "checkbox" />
447 </td>
448 <td>
449 <label for="smbd_cats"><?php echo $category->cat_name; ?> (<?php echo $category->count . " "; _e("Posts", 'bulk-delete'); ?>)</label>
450 </td>
451 </tr>
452 <?php
453 }
454 ?>
455 <tr>
456 <td scope="row" >
457 <input name="smbd_cats_all" id ="smbd_cats_all" value = "-1" type = "checkbox" onclick="bd_checkAll(document.getElementById('smbd_cat_form'));" />
458 </td>
459 <td>
460 <label for="smbd_cats_all"><?php _e("All Categories", 'bulk-delete') ?></label>
461 </td>
462 </tr>
463
464 <tr>
465 <td colspan="2">
466 <h4><?php _e("Choose your filtering options", 'bulk-delete'); ?></h4>
467 </td>
468 </tr>
469
470 <tr>
471 <td scope="row">
472 <input name="smbd_cats_restrict" id="smbd_cats_restrict" value = "true" type = "checkbox" onclick="toggle_date_restrict('cats');" />
473 </td>
474 <td>
475 <?php _e("Only restrict to posts which are ", 'bulk-delete');?>
476 <select name="smbd_cats_op" id="smbd_cats_op" disabled>
477 <option value ="<"><?php _e("older than", 'bulk-delete');?></option>
478 <option value =">"><?php _e("posted within last", 'bulk-delete');?></option>
479 </select>
480 <input type ="textbox" name="smbd_cats_days" id="smbd_cats_days" disabled value ="0" maxlength="4" size="4" /><?php _e("days", 'bulk-delete');?>
481 </td>
482 </tr>
483
484 <tr>
485 <td scope="row" colspan="2">
486 <input name="smbd_cats_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
487 <input name="smbd_cats_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
488 </td>
489 </tr>
490
491 <tr>
492 <td scope="row" colspan="2">
493 <input name="smbd_cats_private" value = "false" type = "radio" checked="checked" /> <?php _e('Public posts', 'bulk-delete'); ?>
494 <input name="smbd_cats_private" value = "true" type = "radio" /> <?php _e('Private Posts', 'bulk-delete'); ?>
495 </td>
496 </tr>
497
498 <tr>
499 <td scope="row">
500 <input name="smbd_cats_limit" id="smbd_cats_limit" value = "true" type = "checkbox" onclick="toggle_limit_restrict('cats');" />
501 </td>
502 <td>
503 <?php _e("Only delete first ", 'bulk-delete');?>
504 <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');?>
505 <?php _e("Use this option if there are more than 1000 posts and the script timesout.", 'bulk-delete') ?>
506 </td>
507 </tr>
508
509 </table>
510 </fieldset>
511 <p class="submit">
512 <input type="submit" name="submit" class="button-primary" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
513 </p>
514
515 <?php wp_nonce_field('bulk-delete-posts'); ?>
516
517 <input type="hidden" name="smbd_action" value="bulk-delete-cats" />
518 </form>
519 </div>
520 </div>
521 <?php
522 $tags = get_tags();
523 if (count($tags) > 0) {
524 ?>
525 <div class = "postbox">
526 <div class = "handlediv">
527 <br>
528 </div>
529
530 <h3 class = "hndle"><span><?php _e("By Tags", 'bulk-delete'); ?></span></h3>
531
532 <div class = "inside">
533 <h4><?php _e("Select the tags whose post you want to delete", 'bulk-delete') ?></h4>
534
535 <form name="smbd_form" id = "smbd_tag_form"
536 action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post"
537 onsubmit="return bd_validateForm(this);">
538
539 <fieldset class="options">
540 <table class="optiontable">
541 <?php
542 foreach ($tags as $tag) {
543 ?>
544 <tr>
545 <td scope="row" >
546 <input name="smbd_tags[]" value = "<?php echo $tag->term_id; ?>" type = "checkbox" />
547 </td>
548 <td>
549 <label for="smbd_tags"><?php echo $tag->name; ?> (<?php echo $tag->count . " "; _e("Posts", 'bulk-delete'); ?>)</label>
550 </td>
551 </tr>
552 <?php
553 }
554 ?>
555 <tr>
556 <td scope="row" >
557 <input name="smbd_tags_all" id ="smbd_tags_all" value = "-1" type = "checkbox" onclick="bd_checkAll(document.getElementById('smbd_tag_form'));" />
558 </td>
559 <td>
560 <label for="smbd_tags_all"><?php _e("All Tags", 'bulk-delete') ?></label>
561 </td>
562 </tr>
563
564 <tr>
565 <td colspan="2">
566 <h4><?php _e("Choose your filtering options", 'bulk-delete'); ?></h4>
567 </td>
568 </tr>
569
570 <tr>
571 <td scope="row">
572 <input name="smbd_tags_restrict" id ="smbd_tags_restrict" value = "true" type = "checkbox" onclick="toggle_date_restrict('tags');" />
573 </td>
574 <td>
575 <?php _e("Only restrict to posts which are ", 'bulk-delete');?>
576 <select name="smbd_tags_op" id="smbd_tags_op" disabled>
577 <option value ="<"><?php _e("older than", 'bulk-delete');?></option>
578 <option value =">"><?php _e("posted within last", 'bulk-delete');?></option>
579 </select>
580 <input type ="textbox" name="smbd_tags_days" id ="smbd_tags_days" value ="0" maxlength="4" size="4" disabled /><?php _e("days", 'bulk-delete');?>
581 </td>
582 </tr>
583
584 <tr>
585 <td scope="row" colspan="2">
586 <input name="smbd_tags_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
587 <input name="smbd_tags_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
588 </td>
589 </tr>
590
591 <tr>
592 <td scope="row" colspan="2">
593 <input name="smbd_tags_private" value = "false" type = "radio" checked="checked" /> <?php _e('Public posts', 'bulk-delete'); ?>
594 <input name="smbd_tags_private" value = "true" type = "radio" /> <?php _e('Private Posts', 'bulk-delete'); ?>
595 </td>
596 </tr>
597
598 <tr>
599 <td scope="row">
600 <input name="smbd_tags_limit" id="smbd_tags_limit" value = "true" type = "checkbox" onclick="toggle_limit_restrict('tags');" />
601 </td>
602 <td>
603 <?php _e("Only delete first ", 'bulk-delete');?>
604 <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');?>
605 <?php _e("Use this option if there are more than 1000 posts and the script timesout.", 'bulk-delete') ?>
606 </td>
607 </tr>
608
609 </table>
610 </fieldset>
611 <p class="submit">
612 <input type="submit" name="submit" class="button-primary" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
613 </p>
614
615 <?php wp_nonce_field('bulk-delete-posts'); ?>
616
617 <input type="hidden" name="smbd_action" value="bulk-delete-tags" />
618 </form>
619 </div>
620 </div>
621 <?php
622 }
623 ?>
624
625 <?php
626 $customTaxs = get_taxonomies();
627 if (count($customTaxs) > 0) {
628 ?>
629 <div class = "postbox">
630 <div class = "handlediv">
631 <br>
632 </div>
633 <h3 class = "hndle"><span><?php _e("By Taxonomies", 'bulk-delete'); ?></span></h3>
634 <div class = "inside">
635 <h4><?php _e("Select the taxonomies whose post you want to delete", 'bulk-delete') ?></h4>
636
637 <form name="smbd_form" id = "smbd_tax_form"
638 action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post"
639 onsubmit="return bd_validateForm(this);">
640
641 <fieldset class="options">
642 <table class="optiontable">
643 <?php
644 foreach ($customTaxs as $taxs) {
645
646 $posts = smbd_get_tax_post($taxs);
647 ?>
648 <tr>
649 <td scope="row" >
650 <input name="smbd_taxs[]" value = "<?php echo $taxs; ?>" type = "checkbox" />
651 </td>
652 <td>
653 <label for="smbd_taxs"><?php echo $taxs; ?> (<?php echo count($posts) . " "; _e("Posts", 'bulk-delete'); ?>)</label>
654 </td>
655 </tr>
656 <?php
657 }
658 ?>
659 <tr>
660 <td scope="row" >
661 <input name="smbd_taxs_all" id ="smbd_taxs_all" value = "-1" type = "checkbox" onclick="bd_checkAll(document.getElementById('smbd_tax_form'));" />
662 </td>
663 <td>
664 <label for="smbd_taxs_all"><?php _e("All Taxonomies", 'bulk-delete') ?></label>
665 </td>
666 </tr>
667
668 <tr>
669 <td colspan="2">
670 <h4><?php _e("Choose your filtering options", 'bulk-delete'); ?></h4>
671 </td>
672 </tr>
673
674 <tr>
675 <td scope="row">
676 <input name="smbd_taxs_restrict" id ="smbd_taxs_restrict" value = "true" type = "checkbox" onclick="toggle_date_restrict('taxs');" />
677 </td>
678 <td>
679 <?php _e("Only restrict to posts which are ", 'bulk-delete');?>
680 <select name="smbd_taxs_op" id="smbd_taxs_op" disabled>
681 <option value ="<"><?php _e("older than", 'bulk-delete');?></option>
682 <option value =">"><?php _e("posted within last", 'bulk-delete');?></option>
683 </select>
684 <input type ="textbox" name="smbd_taxs_days" id ="smbd_taxs_days" value ="0" maxlength="4" size="4" disabled /><?php _e("days", 'bulk-delete');?>
685 </td>
686 </tr>
687
688 <tr>
689 <td scope="row" colspan="2">
690 <input name="smbd_taxs_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
691 <input name="smbd_taxs_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
692 </td>
693 </tr>
694
695 <tr>
696 <td scope="row" colspan="2">
697 <input name="smbd_taxs_private" value = "false" type = "radio" checked="checked" /> <?php _e('Public posts', 'bulk-delete'); ?>
698 <input name="smbd_taxs_private" value = "true" type = "radio" /> <?php _e('Private Posts', 'bulk-delete'); ?>
699 </td>
700 </tr>
701
702 <tr>
703 <td scope="row">
704 <input name="smbd_taxs_limit" id="smbd_taxs_limit" value = "true" type = "checkbox" onclick="toggle_limit_restrict('taxs');" />
705 </td>
706 <td>
707 <?php _e("Only delete first ", 'bulk-delete');?>
708 <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');?>
709 <?php _e("Use this option if there are more than 1000 posts and the script timesout.", 'bulk-delete') ?>
710 </td>
711 </tr>
712
713 </table>
714 </fieldset>
715 <p class="submit">
716 <input type="submit" class="button-primary" name="submit" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
717 </p>
718
719 <?php wp_nonce_field('bulk-delete-posts'); ?>
720
721 <input type="hidden" name="smbd_action" value="bulk-delete-taxs" />
722 </form>
723 </div>
724 </div>
725 <?php
726 }
727 ?>
728 <div class = "postbox">
729 <div class = "handlediv">
730 <br>
731 </div>
732 <h3 class = "hndle"><span><?php _e('Debug Information', 'bulk-delete'); ?></span></h3>
733 <div class = "inside">
734 <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>.
735 <?php _e('You also need need the following debug information.', 'bulk-delete'); ?></p>
736 <table cellspacing="10">
737 <tr>
738 <th align = "right"><?php _e('Available memory size ', 'bulk-delete');?></th>
739 <td><?php echo ini_get( 'memory_limit' ); ?></td>
740 </tr>
741 <tr>
742 <th align = "right"><?php _e('Script time out ', 'bulk-delete');?></th>
743 <td><?php echo ini_get( 'max_execution_time' ); ?></td>
744 </tr>
745 <tr>
746 <th align = "right"><?php _e('Script input time ', 'bulk-delete'); ?></th>
747 <td><?php echo ini_get( 'max_input_time' ); ?></td>
748 </tr>
749 </table>
750 </div>
751 </div>
752
753 <p><em><?php _e("If you are looking to move posts in bulk, instead of deleting then try out my ", 'bulk-delete'); ?> <a href = "http://sudarmuthu.com/wordpress/bulk-move"><?php _e("Bulk Move Plugin", 'bulk-delete');?></a>.</em></p>
754 </div>
755
756 <iframe frameBorder="0" height = "950" src = "http://sudarmuthu.com/projects/wordpress/bulk-delete/sidebar.php?color=<?php echo get_user_option('admin_color'); ?>"></iframe>
757
758 </div>
759 <?php
760
761 // Display credits in Footer
762 add_action( 'in_admin_footer', 'smbd_admin_footer' );
763 }
764 }
765
766 /**
767 * function to filter posts by days
768 * @param <type> $where
769 * @return <type>
770 */
771 if (!function_exists('smbd_cats_by_days ')) {
772 function smbd_cats_by_days ($where = '') {
773 $cats_op = $_POST['smbd_cats_op'];
774 $cats_days = $_POST['smbd_cats_days'];
775
776 remove_filter('posts_where', 'smbd_cats_by_days');
777
778 $where .= " AND post_date $cats_op '" . date('y-m-d', strtotime("-$cats_days days")) . "'";
779 return $where;
780 }
781 }
782
783 /**
784 * function to filter posts by days
785 * @param <type> $where
786 * @return <type>
787 */
788 if (!function_exists('smbd_tags_by_days ')) {
789 function smbd_tags_by_days ($where = '') {
790 $tags_op = $_POST['smbd_tags_op'];
791 $tags_days = $_POST['smbd_tags_days'];
792
793 remove_filter('posts_where', 'smbd_tags_by_days');
794
795 $where .= " AND post_date $tags_op '" . date('y-m-d', strtotime("-$tags_days days")) . "'";
796 return $where;
797 }
798 }
799
800 /**
801 * function to filter custom taxonomy posts by days
802 * @param <type> $where
803 * @return <type>
804 */
805 if (!function_exists('smbd_taxs_by_days ')) {
806 function smbd_taxs_by_days ($where = '') {
807 $taxs_op = $_POST['smbd_taxs_op'];
808 $taxs_days = $_POST['smbd_taxs_days'];
809
810 remove_filter('posts_where', 'smbd_taxs_by_days');
811
812 $where .= " AND post_date $taxs_op '" . date('y-m-d', strtotime("-$taxs_days days")) . "'";
813 return $where;
814 }
815 }
816
817 /**
818 * Return the posts for a taxonomy
819 *
820 * @param <type> $tax
821 * @return <type>
822 */
823 if (!function_exists('smbd_get_tax_post')) {
824 function smbd_get_tax_post($tax) {
825 global $wpdb;
826
827 $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')");
828 $post_ids_result = $wpdb->get_results($query);
829
830 $postids = array();
831 foreach ($post_ids_result as $post_id_result) {
832 $postids[] = $post_id_result->object_id;
833 }
834
835 return $postids;
836 }
837 }
838
839 /**
840 * Add navigation menu
841 */
842 if(!function_exists('smbd_add_menu')) {
843 function smbd_add_menu() {
844 //Add a submenu to Manage
845 $page = add_options_page("Bulk Delete", "Bulk Delete", 'manage_options', basename(__FILE__), "smbd_displayOptions");
846 }
847 }
848
849 /**
850 * Adds the settings link in the Plugin page. Based on http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/
851 * @staticvar <type> $this_plugin
852 * @param <type> $links
853 * @param <type> $file
854 */
855 if (!function_exists('smbd_filter_plugin_actions')) {
856 function smbd_filter_plugin_actions($links, $file) {
857 static $this_plugin;
858 if( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
859
860 if( $file == $this_plugin ) {
861 $settings_link = '<a href="options-general.php?page=bulk-delete.php">' . _('Manage') . '</a>';
862 array_unshift( $links, $settings_link ); // before other links
863 }
864 return $links;
865 }
866 }
867
868 /**
869 * Adds Footer links. Based on http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/
870 */
871 if (!function_exists('smbd_admin_footer')) {
872 function smbd_admin_footer() {
873 $plugin_data = get_plugin_data( __FILE__ );
874 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']);
875 ?>
876 <script type="text/javascript">
877
878 /**
879 * Toggle closing of different sections
880 *
881 */
882 jQuery(document).ready( function() {
883 jQuery('.postbox h3').click( function() {
884 jQuery(jQuery(this).parent().get(0)).toggleClass('closed');
885 });
886 });
887
888 /**
889 * Check All Checkboxes
890 */
891 function bd_checkAll(form) {
892 for (i = 0, n = form.elements.length; i < n; i++) {
893 if(form.elements[i].type == "checkbox" && !(form.elements[i].getAttribute('onclick',2))) {
894 if(form.elements[i].checked == true)
895 form.elements[i].checked = false;
896 else
897 form.elements[i].checked = true;
898 }
899 }
900 }
901
902 function toggle_date_restrict(el) {
903 if (jQuery("#smbd_" + el + "_restrict").is(":checked")) {
904 jQuery("#smbd_" + el + "_op").removeAttr('disabled');
905 jQuery("#smbd_" + el + "_days").removeAttr('disabled');
906 } else {
907 jQuery("#smbd_" + el + "_op").attr('disabled', 'true');
908 jQuery("#smbd_" + el + "_days").attr('disabled', 'true');
909 }
910 }
911
912 function toggle_limit_restrict(el) {
913 if (jQuery("#smbd_" + el + "_limit").is(":checked")) {
914 jQuery("#smbd_" + el + "_limit_to").removeAttr('disabled');
915 } else {
916 jQuery("#smbd_" + el + "_limit_to").attr('disabled', 'true');
917 }
918 }
919
920 /**
921 * Validate Form
922 */
923 function bd_validateForm(form) {
924 var valid = false;
925 for (i = 0, n = form.elements.length; i < n; i++) {
926 if(form.elements[i].type == "checkbox" && !(form.elements[i].getAttribute('onclick',2))) {
927 if(form.elements[i].checked == true) {
928 valid = true;
929 break;
930 }
931 }
932 }
933
934 if (valid) {
935 return confirm("<?php _e('Are you sure you want to delete all the selected posts', 'bulk-delete'); ?>");
936 } else {
937 alert ("<?php _e('Please select at least one', 'bulk-delete'); ?>");
938 return false;
939 }
940 }
941 </script>
942
943 <?php
944 }
945 }
946
947 add_filter( 'plugin_action_links', 'smbd_filter_plugin_actions', 10, 2 );
948 add_action('admin_menu', 'smbd_add_menu');
949 add_action('admin_init', 'smbd_request_handler');
950 ?>
951