PluginProbe
Bulk Delete / 1.6
Bulk Delete v1.6
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 1.6, at bulk-delete.php

831 lines 35.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: 1.6
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
31 /* Copyright 2009 Sudar Muthu (email : sudar@sudarmuthu.com)
32
33 This program is free software; you can redistribute it and/or modify
34 it under the terms of the GNU General Public License, version 2, as
35 published by the Free Software Foundation.
36
37 This program is distributed in the hope that it will be useful,
38 but WITHOUT ANY WARRANTY; without even the implied warranty of
39 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 GNU General Public License for more details.
41
42 You should have received a copy of the GNU General Public License
43 along with this program; if not, write to the Free Software
44 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
45 */
46
47 /**
48 * Request Handler
49 */
50
51 if (!function_exists('smbd_request_handler')) {
52 function smbd_request_handler() {
53 global $wpdb;
54
55 if (isset($_POST['smbd_action'])) {
56
57 $wp_query = new WP_Query;
58 check_admin_referer( 'bulk-delete-posts');
59
60 switch($_POST['smbd_action']) {
61
62 case "bulk-delete-cats":
63 // delete by cats
64 $selected_cats = $_POST['smbd_cats'];
65 if ($_POST['smbd_cats_restrict'] == "true") {
66
67 add_option('cats_op', $_POST['smbd_cats_op']);
68 add_option('cats_days', $_POST['smbd_cats_days']);
69
70 add_filter ('posts_where', 'cats_by_days');
71 }
72
73 $private = $_POST['smbd_cats_private'];
74
75 if ($private == 'true') {
76 $options = array('category__in'=>$selected_cats,'post_status'=>'private', 'post_type'=>'post');
77 } else {
78 $options = array('category__in'=>$selected_cats,'post_status'=>'publish', 'post_type'=>'post');
79 }
80
81 $limit_to = absint($_POST['smbd_cats_limits_to']);
82
83 if ($limit_to > 0) {
84 $options['showposts'] = $limit_to;
85 } else {
86 $options['nopaging'] = 'true';
87 }
88
89 $force_delete = $_POST['smbd_cats_force_delete'];
90
91 if ($force_delete == 'true') {
92 $force_delete = true;
93 } else {
94 $force_delete = false;
95 }
96
97 $posts = $wp_query->query($options);
98 foreach ($posts as $post) {
99 wp_delete_post($post->ID, $force_delete);
100 }
101
102 break;
103
104 case "bulk-delete-tags":
105 // delete by tags
106 $selected_tags = $_POST['smbd_tags'];
107 if ($_POST['smbd_tags_restrict'] == "true") {
108
109 add_option('tags_op', $_POST['smbd_tags_op']);
110 add_option('tags_days', $_POST['smbd_tags_days']);
111
112 add_filter ('posts_where', 'tags_by_days');
113 }
114
115 $private = $_POST['smbd_tags_private'];
116
117 if ($private == 'true') {
118 $options = array('tag__in'=>$selected_tags,'post_status'=>'private', 'post_type'=>'post');
119 } else {
120 $options = array('tag__in'=>$selected_tags,'post_status'=>'publish', 'post_type'=>'post');
121 }
122
123 $limit_to = absint($_POST['smbd_tags_limits_to']);
124
125 if ($limit_to > 0) {
126 $options['showposts'] = $limit_to;
127 } else {
128 $options['nopaging'] = 'true';
129 }
130
131 $force_delete = $_POST['smbd_tags_force_delete'];
132
133 if ($force_delete == 'true') {
134 $force_delete = true;
135 } else {
136 $force_delete = false;
137 }
138
139 $posts = $wp_query->query($options);
140
141 foreach ($posts as $post) {
142 wp_delete_post($post->ID, $force_delete);
143 }
144
145 break;
146
147 case "bulk-delete-taxs":
148 // delete by taxs
149 $selected_taxs = $_POST['smbd_taxs'];
150
151 foreach ($selected_taxs as $selected_tax) {
152 $postids = get_tax_post($selected_tax);
153
154 if ($_POST['smbd_taxs_restrict'] == "true") {
155
156 add_option('taxs_op', $_POST['smbd_taxs_op']);
157 add_option('taxs_days', $_POST['smbd_taxs_days']);
158
159 add_filter ('posts_where', 'taxs_by_days');
160 }
161
162 $private = $_POST['smbd_taxs_private'];
163
164 if ($private == 'true') {
165 $options = array('post__in'=>$postids,'post_status'=>'private', 'post_type'=>'post');
166 } else {
167 $options = array('post__in'=>$postids,'post_status'=>'publish', 'post_type'=>'post');
168 }
169
170 $limit_to = absint($_POST['smbd_taxs_limits_to']);
171
172 if ($limit_to > 0) {
173 $options['showposts'] = $limit_to;
174 } else {
175 $options['nopaging'] = 'true';
176 }
177
178 $force_delete = $_POST['smbd_taxs_force_delete'];
179
180 if ($force_delete == 'true') {
181 $force_delete = true;
182 } else {
183 $force_delete = false;
184 }
185
186 $posts = $wp_query->query($options);
187 foreach ($posts as $post) {
188 wp_delete_post($post->ID, $force_delete);
189 }
190 }
191
192 break;
193
194 case "bulk-delete-special":
195 $options = array();
196
197 $limit_to = absint($_POST['smbd_special_limit_to']);
198
199 if ($limit_to > 0) {
200 $options['showposts'] = $limit_to;
201 } else {
202 $options['nopaging'] = 'true';
203 }
204
205 $force_delete = $_POST['smbd_special_force_delete'];
206 if ($force_delete == 'true') {
207 $force_delete = true;
208 } else {
209 $force_delete = false;
210 }
211
212 // Drafts
213 if ("drafs" == $_POST['smbd_drafs']) {
214 $options['post_status'] = 'draft';
215 $drafts = $wp_query->query($options);
216
217 foreach ($drafts as $draft) {
218 wp_delete_post($draft->ID, $force_delete);
219 }
220 }
221
222 // Revisions
223 if ("revisions" == $_POST['smbd_revisions']) {
224 $revisions = $wpdb->get_results($wpdb->prepare("select ID from $wpdb->posts where post_type = 'revision'"));
225
226 foreach ($revisions as $revision) {
227 wp_delete_post($revision->ID, $force_delete);
228 }
229 }
230
231 // Pending Posts
232 if ("pending" == $_POST['smbd_pending']) {
233 $pendings = $wpdb->get_results($wpdb->prepare("select ID from $wpdb->posts where post_status = 'pending'"));
234
235 foreach ($pendings as $pending) {
236 wp_delete_post($pending->ID, $force_delete);
237 }
238 }
239
240 // Future Posts
241 if ("future" == $_POST['smbd_future']) {
242 $futures = $wpdb->get_results($wpdb->prepare("select ID from $wpdb->posts where post_status = 'future'"));
243
244 foreach ($futures as $future) {
245 wp_delete_post($future->ID, $force_delete);
246 }
247 }
248
249 // Private Posts
250 if ("private" == $_POST['smbd_private']) {
251 $privates = $wpdb->get_results($wpdb->prepare("select ID from $wpdb->posts where post_status = 'private'"));
252
253 foreach ($privates as $private) {
254 wp_delete_post($private->ID, $force_delete);
255 }
256 }
257
258 // Pages
259 if ("pages" == $_POST['smbd_pages']) {
260 $options['post_type'] = 'page';
261 $pages = $wp_query->query($options);
262
263 foreach ($pages as $page) {
264 wp_delete_post($page->ID, $force_delete);
265 }
266 }
267 break;
268 }
269
270 // hook the admin notices action
271 add_action( 'admin_notices', 'smbd_deleted_notice', 9 );
272 }
273 }
274 }
275
276 /**
277 * Show deleted notice messages
278 */
279 function smbd_deleted_notice() {
280 echo "<div class = 'updated'><p>" . __("All the selected posts have been sucessfully deleted.", 'bulk-delete') . "</p></div>";
281 }
282
283 /**
284 * Show the Admin page
285 */
286 if (!function_exists('smbd_displayOptions')) {
287 function smbd_displayOptions() {
288 global $wpdb;
289 ?>
290 <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>
291 <div class="wrap">
292 <?php screen_icon(); ?>
293 <h2>Bulk Delete</h2>
294
295 <h3><?php _e("Select the posts which you want to delete", 'bulk-delete'); ?></h3>
296
297 <form name="smbd_form" id = "smbd_misc_form"
298 action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post"
299 onsubmit="return bd_validateForm(this);">
300
301 <?php
302 $wp_query = new WP_Query;
303 $drafts = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_status = 'draft'"));
304 $revisions = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_type = 'revision'"));
305 $pending = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_status = 'pending'"));
306 $future = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_status = 'future'"));
307 $private = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_status = 'private'"));
308 $pages = $wpdb->get_var($wpdb->prepare("select count(*) from $wpdb->posts where post_type = 'page'"));
309 ?>
310 <fieldset class="options">
311 <table class="optiontable">
312 <tr>
313 <td scope="row" >
314 <input name="smbd_drafs" id ="smbd_drafs" value = "drafs" type = "checkbox" />
315 <label for="smbd_drafs"><?php echo _e("All Drafts", 'bulk-delete'); ?> (<?php echo $drafts . " "; _e("Drafts", 'bulk-delete'); ?>)</label>
316 </td>
317 </tr>
318 <tr>
319 <td>
320 <input name="smbd_revisions" id ="smbd_revisions" value = "revisions" type = "checkbox" />
321 <label for="smbd_revisions"><?php echo _e("All Revisions", 'bulk-delete'); ?> (<?php echo $revisions . " "; _e("Revisions", 'bulk-delete'); ?>)</label>
322 </td>
323 </tr>
324 <tr>
325 <td>
326 <input name="smbd_pending" id ="smbd_pending" value = "pending" type = "checkbox" />
327 <label for="smbd_pending"><?php echo _e("All Pending posts", 'bulk-delete'); ?> (<?php echo $pending . " "; _e("Posts", 'bulk-delete'); ?>)</label>
328 </td>
329 </tr>
330 <tr>
331 <td>
332 <input name="smbd_future" id ="smbd_future" value = "future" type = "checkbox" />
333 <label for="smbd_future"><?php echo _e("All scheduled posts", 'bulk-delete'); ?> (<?php echo $future . " "; _e("Posts", 'bulk-delete'); ?>)</label>
334 </td>
335 </tr>
336 <tr>
337 <td>
338 <input name="smbd_private" id ="smbd_private" value = "private" type = "checkbox" />
339 <label for="smbd_private"><?php echo _e("All private posts", 'bulk-delete'); ?> (<?php echo $private . " "; _e("Posts", 'bulk-delete'); ?>)</label>
340 </td>
341 </tr>
342 <tr>
343 <td>
344 <input name="smbd_pages" value = "pages" type = "checkbox" />
345 <label for="smbd_pages"><?php echo _e("All Pages", 'bulk-delete'); ?> (<?php echo $pages . " "; _e("Pages", 'bulk-delete'); ?>)</label>
346 </td>
347 </tr>
348
349 <tr>
350 <td scope="row">
351 <input name="smbd_special_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
352 <input name="smbd_special_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
353 </td>
354 </tr>
355
356 <tr>
357 <td scope="row">
358 <input name="smbd_special_limit" id="smbd_special_limit" value = "true" type = "checkbox" onclick="toggle_limit_restrict('special');" />
359 <?php _e("Only delete first ", 'bulk-delete');?>
360 <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');?>
361 <?php _e("Use this option if there are more than 1000 posts and the script timesout.", 'bulk-delete') ?>
362 </td>
363 </tr>
364
365 </table>
366 </fieldset>
367 <p class="submit">
368 <input type="submit" name="submit" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
369 </p>
370
371 <?php wp_nonce_field('bulk-delete-posts'); ?>
372
373 <input type="hidden" name="smbd_action" value="bulk-delete-special" />
374 </form>
375
376 <h3><?php _e("By Category", 'bulk-delete'); ?></h3>
377 <h4><?php _e("Select the categories whose post you want to delete", 'bulk-delete'); ?></h4>
378
379 <form name="smbd_form" id = "smbd_cat_form"
380 action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post"
381 onsubmit="return bd_validateForm(this);">
382
383 <fieldset class="options">
384 <table class="optiontable">
385 <?php
386 $categories = get_categories(array('hide_empty' => false));
387 foreach ($categories as $category) {
388 ?>
389 <tr>
390 <td scope="row" >
391 <input name="smbd_cats[]" value = "<?php echo $category->cat_ID; ?>" type = "checkbox" />
392 </td>
393 <td>
394 <label for="smbd_cats"><?php echo $category->cat_name; ?> (<?php echo $category->count . " "; _e("Posts", 'bulk-delete'); ?>)</label>
395 </td>
396 </tr>
397 <?php
398 }
399 ?>
400 <tr>
401 <td scope="row" >
402 <input name="smbd_cats_all" id ="smbd_cats_all" value = "-1" type = "checkbox" onclick="bd_checkAll(document.getElementById('smbd_cat_form'));" />
403 </td>
404 <td>
405 <label for="smbd_cats_all"><?php _e("All Categories", 'bulk-delete') ?></label>
406 </td>
407 </tr>
408 <tr>
409 <td colspan="2"></td>
410 </tr>
411
412 <tr>
413 <td scope="row">
414 <input name="smbd_cats_restrict" id="smbd_cats_restrict" value = "true" type = "checkbox" onclick="toggle_date_restrict('cats');" />
415 </td>
416 <td>
417 <?php _e("Only restrict to posts which are ", 'bulk-delete');?>
418 <select name="smbd_cats_op" id="smbd_cats_op" disabled>
419 <option value ="<"><?php _e("older than", 'bulk-delete');?></option>
420 <option value =">"><?php _e("posted within last", 'bulk-delete');?></option>
421 </select>
422 <input type ="textbox" name="smbd_cats_days" id="smbd_cats_days" disabled value ="0" maxlength="4" size="4" /><?php _e("days", 'bulk-delete');?>
423 </td>
424 </tr>
425
426 <tr>
427 <td scope="row" colspan="2">
428 <input name="smbd_cats_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
429 <input name="smbd_cats_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
430 </td>
431 </tr>
432
433 <tr>
434 <td scope="row" colspan="2">
435 <input name="smbd_cats_private" value = "false" type = "radio" checked="checked" /> <?php _e('Public posts', 'bulk-delete'); ?>
436 <input name="smbd_cats_private" value = "true" type = "radio" /> <?php _e('Private Posts', 'bulk-delete'); ?>
437 </td>
438 </tr>
439
440 <tr>
441 <td scope="row">
442 <input name="smbd_cats_limit" id="smbd_cats_limit" value = "true" type = "checkbox" onclick="toggle_limit_restrict('cats');" />
443 </td>
444 <td>
445 <?php _e("Only delete first ", 'bulk-delete');?>
446 <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');?>
447 <?php _e("Use this option if there are more than 1000 posts and the script timesout.", 'bulk-delete') ?>
448 </td>
449 </tr>
450
451 </table>
452 </fieldset>
453 <p class="submit">
454 <input type="submit" name="submit" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
455 </p>
456
457 <?php wp_nonce_field('bulk-delete-posts'); ?>
458
459 <input type="hidden" name="smbd_action" value="bulk-delete-cats" />
460 </form>
461 <?php
462 $tags = get_tags();
463 if (count($tags) > 0) {
464 ?>
465 <h3><?php _e("By Tags", 'bulk-delete'); ?></h3>
466 <h4><?php _e("Select the tags whose post you want to delete", 'bulk-delete') ?></h4>
467
468 <form name="smbd_form" id = "smbd_tag_form"
469 action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post"
470 onsubmit="return bd_validateForm(this);">
471
472 <fieldset class="options">
473 <table class="optiontable">
474 <?php
475 foreach ($tags as $tag) {
476 ?>
477 <tr>
478 <td scope="row" >
479 <input name="smbd_tags[]" value = "<?php echo $tag->term_id; ?>" type = "checkbox" />
480 </td>
481 <td>
482 <label for="smbd_tags"><?php echo $tag->name; ?> (<?php echo $tag->count . " "; _e("Posts", 'bulk-delete'); ?>)</label>
483 </td>
484 </tr>
485 <?php
486 }
487 ?>
488 <tr>
489 <td scope="row" >
490 <input name="smbd_tags_all" id ="smbd_tags_all" value = "-1" type = "checkbox" onclick="bd_checkAll(document.getElementById('smbd_tag_form'));" />
491 </td>
492 <td>
493 <label for="smbd_tags_all"><?php _e("All Tags", 'bulk-delete') ?></label>
494 </td>
495 </tr>
496
497 <tr>
498 <td colspan="2"></td>
499 </tr>
500
501 <tr>
502 <td scope="row">
503 <input name="smbd_tags_restrict" id ="smbd_tags_restrict" value = "true" type = "checkbox" onclick="toggle_date_restrict('tags');" />
504 </td>
505 <td>
506 <?php _e("Only restrict to posts which are ", 'bulk-delete');?>
507 <select name="smbd_tags_op" id="smbd_tags_op" disabled>
508 <option value ="<"><?php _e("older than", 'bulk-delete');?></option>
509 <option value =">"><?php _e("posted within last", 'bulk-delete');?></option>
510 </select>
511 <input type ="textbox" name="smbd_tags_days" id ="smbd_tags_days" value ="0" maxlength="4" size="4" disabled /><?php _e("days", 'bulk-delete');?>
512 </td>
513 </tr>
514
515 <tr>
516 <td scope="row" colspan="2">
517 <input name="smbd_tags_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
518 <input name="smbd_tags_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
519 </td>
520 </tr>
521
522 <tr>
523 <td scope="row" colspan="2">
524 <input name="smbd_tags_private" value = "false" type = "radio" checked="checked" /> <?php _e('Public posts', 'bulk-delete'); ?>
525 <input name="smbd_tags_private" value = "true" type = "radio" /> <?php _e('Private Posts', 'bulk-delete'); ?>
526 </td>
527 </tr>
528
529 <tr>
530 <td scope="row">
531 <input name="smbd_tags_limit" id="smbd_tags_limit" value = "true" type = "checkbox" onclick="toggle_limit_restrict('tags');" />
532 </td>
533 <td>
534 <?php _e("Only delete first ", 'bulk-delete');?>
535 <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');?>
536 <?php _e("Use this option if there are more than 1000 posts and the script timesout.", 'bulk-delete') ?>
537 </td>
538 </tr>
539
540 </table>
541 </fieldset>
542 <p class="submit">
543 <input type="submit" name="submit" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
544 </p>
545
546 <?php wp_nonce_field('bulk-delete-posts'); ?>
547
548 <input type="hidden" name="smbd_action" value="bulk-delete-tags" />
549 </form>
550 <?php
551 }
552 ?>
553
554 <?php
555 $customTaxs = get_taxonomies();
556 if (count($customTaxs) > 0) {
557 ?>
558 <h3><?php _e("By Taxonomies", 'bulk-delete'); ?></h3>
559 <h4><?php _e("Select the taxonomies whose post you want to delete", 'bulk-delete') ?></h4>
560
561 <form name="smbd_form" id = "smbd_tax_form"
562 action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post"
563 onsubmit="return bd_validateForm(this);">
564
565 <fieldset class="options">
566 <table class="optiontable">
567 <?php
568 foreach ($customTaxs as $taxs) {
569
570 $posts = get_tax_post($taxs);
571 ?>
572 <tr>
573 <td scope="row" >
574 <input name="smbd_taxs[]" value = "<?php echo $taxs; ?>" type = "checkbox" />
575 </td>
576 <td>
577 <label for="smbd_taxs"><?php echo $taxs; ?> (<?php echo count($posts) . " "; _e("Posts", 'bulk-delete'); ?>)</label>
578 </td>
579 </tr>
580 <?php
581 }
582 ?>
583 <tr>
584 <td scope="row" >
585 <input name="smbd_taxs_all" id ="smbd_taxs_all" value = "-1" type = "checkbox" onclick="bd_checkAll(document.getElementById('smbd_tax_form'));" />
586 </td>
587 <td>
588 <label for="smbd_taxs_all"><?php _e("All Taxonomies", 'bulk-delete') ?></label>
589 </td>
590 </tr>
591
592 <tr>
593 <td colspan="2"></td>
594 </tr>
595
596 <tr>
597 <td scope="row">
598 <input name="smbd_taxs_restrict" id ="smbd_taxs_restrict" value = "true" type = "checkbox" onclick="toggle_date_restrict('taxs');" />
599 </td>
600 <td>
601 <?php _e("Only restrict to posts which are ", 'bulk-delete');?>
602 <select name="smbd_taxs_op" id="smbd_taxs_op" disabled>
603 <option value ="<"><?php _e("older than", 'bulk-delete');?></option>
604 <option value =">"><?php _e("posted within last", 'bulk-delete');?></option>
605 </select>
606 <input type ="textbox" name="smbd_taxs_days" id ="smbd_taxs_days" value ="0" maxlength="4" size="4" disabled /><?php _e("days", 'bulk-delete');?>
607 </td>
608 </tr>
609
610 <tr>
611 <td scope="row" colspan="2">
612 <input name="smbd_taxs_force_delete" value = "false" type = "radio" checked="checked" /> <?php _e('Move to Trash', 'bulk-delete'); ?>
613 <input name="smbd_taxs_force_delete" value = "true" type = "radio" /> <?php _e('Delete permanently', 'bulk-delete'); ?>
614 </td>
615 </tr>
616
617 <tr>
618 <td scope="row" colspan="2">
619 <input name="smbd_taxs_private" value = "false" type = "radio" checked="checked" /> <?php _e('Public posts', 'bulk-delete'); ?>
620 <input name="smbd_taxs_private" value = "true" type = "radio" /> <?php _e('Private Posts', 'bulk-delete'); ?>
621 </td>
622 </tr>
623
624 <tr>
625 <td scope="row">
626 <input name="smbd_taxs_limit" id="smbd_taxs_limit" value = "true" type = "checkbox" onclick="toggle_limit_restrict('taxs');" />
627 </td>
628 <td>
629 <?php _e("Only delete first ", 'bulk-delete');?>
630 <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');?>
631 <?php _e("Use this option if there are more than 1000 posts and the script timesout.", 'bulk-delete') ?>
632 </td>
633 </tr>
634
635 </table>
636 </fieldset>
637 <p class="submit">
638 <input type="submit" name="submit" value="<?php _e("Bulk Delete ", 'bulk-delete') ?>&raquo;">
639 </p>
640
641 <?php wp_nonce_field('bulk-delete-posts'); ?>
642
643 <input type="hidden" name="smbd_action" value="bulk-delete-taxs" />
644 </form>
645 <?php
646 }
647 ?>
648 <h3><?php _e('Support', 'bulk-delete'); ?></h3>
649 <p><?php _e('If you have any questions/comments/feedback about the Plugin then post a comment in the <a target="_blank" href = "http://sudarmuthu.com/wordpress/bulk-delete">Plugins homepage</a>.','bulk-delete'); ?></p>
650 <p><?php _e('If you like the Plugin, then consider doing one of the following.', 'bulk-delete'); ?></p>
651 <ul style="list-style:disc inside">
652 <li><?php _e('Write a blog post about the Plugin.', 'bulk-delete'); ?></li>
653 <li><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://sudarmuthu.com/wordpress/bulk-delete" data-text="Bulk Delete WordPress Plugin" data-count="none" data-via="sudarmuthu">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script><?php _e(' about it.', 'bulk-delete'); ?></li>
654 <li><?php _e('Give a <a href = "http://wordpress.org/extend/plugins/bulk-delete/" target="_blank">good rating</a>.', 'bulk-delete'); ?></li>
655 <li><?php _e('Say <a href = "http://sudarmuthu.com/if-you-wanna-thank-me" target="_blank">thank you</a>.', 'bulk-delete'); ?></li>
656 </ul>
657
658 <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>
659 </div>
660 <?php
661
662 // Display credits in Footer
663 add_action( 'in_admin_footer', 'smbd_admin_footer' );
664 }
665 }
666
667 /**
668 * Print JavaScript
669 */
670 function smbd_print_scripts() {
671 ?>
672 <script type="text/javascript">
673
674 /**
675 * Check All Checkboxes
676 */
677 function bd_checkAll(form) {
678 for (i = 0, n = form.elements.length; i < n; i++) {
679 if(form.elements[i].type == "checkbox" && !(form.elements[i].getAttribute('onclick',2))) {
680 if(form.elements[i].checked == true)
681 form.elements[i].checked = false;
682 else
683 form.elements[i].checked = true;
684 }
685 }
686 }
687
688 function toggle_date_restrict(el) {
689 if (jQuery("#smbd_" + el + "_restrict").is(":checked")) {
690 jQuery("#smbd_" + el + "_op").removeAttr('disabled');
691 jQuery("#smbd_" + el + "_days").removeAttr('disabled');
692 } else {
693 jQuery("#smbd_" + el + "_op").attr('disabled', 'true');
694 jQuery("#smbd_" + el + "_days").attr('disabled', 'true');
695 }
696 }
697
698 function toggle_limit_restrict(el) {
699 if (jQuery("#smbd_" + el + "_limit").is(":checked")) {
700 jQuery("#smbd_" + el + "_limit_to").removeAttr('disabled');
701 } else {
702 jQuery("#smbd_" + el + "_limit_to").attr('disabled', 'true');
703 }
704 }
705 /**
706 * Validate Form
707 */
708 function bd_validateForm(form) {
709 var valid = false;
710 for (i = 0, n = form.elements.length; i < n; i++) {
711 if(form.elements[i].type == "checkbox" && !(form.elements[i].getAttribute('onclick',2))) {
712 if(form.elements[i].checked == true) {
713 valid = true;
714 break;
715 }
716 }
717 }
718
719 if (valid) {
720 return confirm("<?php _e('Are you sure you want to delete all the selected posts', 'bulk-delete'); ?>");
721 } else {
722 alert ("<?php _e('Please select at least one', 'bulk-delete'); ?>");
723 return false;
724 }
725 }
726 </script>
727 <?php
728 }
729
730 /**
731 * function to filter posts by days
732 * @param <type> $where
733 * @return <type>
734 */
735 function cats_by_days ($where = '') {
736 $cats_op = get_option('cats_op');
737 $cats_days = get_option('cats_days');
738 remove_filter('posts_where', 'cats_by_days');
739
740 $where .= " AND post_date $cats_op '" . date('y-m-d', strtotime("-$cats_days days")) . "'";
741 return $where;
742 }
743
744 /**
745 * function to filter posts by days
746 * @param <type> $where
747 * @return <type>
748 */
749 function tags_by_days ($where = '') {
750 $tags_op = get_option('tags_op');
751 $tags_days = get_option('tags_days');
752
753 remove_filter('posts_where', 'tags_by_days');
754 $where .= " AND post_date $tags_op '" . date('y-m-d', strtotime("-$tags_days days")) . "'";
755 return $where;
756 }
757
758 /**
759 * function to filter custom taxonomy posts by days
760 * @param <type> $where
761 * @return <type>
762 */
763 function taxs_by_days ($where = '') {
764 $taxs_op = get_option('taxs_op');
765 $taxs_days = get_option('taxs_days');
766
767 remove_filter('posts_where', 'taxs_by_days');
768 $where .= " AND post_date $taxs_op '" . date('y-m-d', strtotime("-$taxs_days days")) . "'";
769 return $where;
770 }
771
772 /**
773 * Return the posts for a taxonomy
774 *
775 * @param <type> $tax
776 * @return <type>
777 */
778 function get_tax_post($tax) {
779 global $wpdb;
780
781 $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')");
782 $post_ids_result = $wpdb->get_results($query);
783
784 $postids = array();
785 foreach ($post_ids_result as $post_id_result) {
786 $postids[] = $post_id_result->object_id;
787 }
788
789 return $postids;
790 }
791 /**
792 * Add navigation menu
793 */
794 if(!function_exists('smbd_add_menu')) {
795 function smbd_add_menu() {
796 //Add a submenu to Manage
797 $page = add_options_page("Bulk Delete", "Bulk Delete", 8, basename(__FILE__), "smbd_displayOptions");
798 add_action('admin_print_scripts-' . $page, 'smbd_print_scripts');
799 }
800 }
801
802 /**
803 * Adds the settings link in the Plugin page. Based on http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/
804 * @staticvar <type> $this_plugin
805 * @param <type> $links
806 * @param <type> $file
807 */
808 function smbd_filter_plugin_actions($links, $file) {
809 static $this_plugin;
810 if( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
811
812 if( $file == $this_plugin ) {
813 $settings_link = '<a href="options-general.php?page=bulk-delete.php">' . _('Manage') . '</a>';
814 array_unshift( $links, $settings_link ); // before other links
815 }
816 return $links;
817 }
818
819 /**
820 * Adds Footer links. Based on http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/
821 */
822 function smbd_admin_footer() {
823 $plugin_data = get_plugin_data( __FILE__ );
824 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']);
825 }
826
827 add_filter( 'plugin_action_links', 'smbd_filter_plugin_actions', 10, 2 );
828 add_action('admin_menu', 'smbd_add_menu');
829 add_action('init', 'smbd_request_handler');
830 ?>
831