Bulk Delete - Version 0.2

Version Description

Download this release

Release Info

Developer sudar
Plugin Icon 128x128 Bulk Delete
Version 0.2
Comparing to
See all releases

Version 0.2

Files changed (2) hide show
  1. trunk/bulk-delete.php +342 -0
  2. trunk/readme.txt +27 -0
trunk/bulk-delete.php ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Version: 0.2
8
+ License: GPL
9
+ Author: Sudar
10
+ Author URI: http://sudarmuthu.com/
11
+
12
+ === RELEASE NOTES ===
13
+ 2009-02-02 - v0.1 - first version
14
+ 2009-02-03 - v0.2 - Second release - Fixed issues with pagging
15
+
16
+ */
17
+
18
+
19
+ /**
20
+ * Request Handler
21
+ */
22
+
23
+ if (!function_exists('smbd_request_handler')) {
24
+ function smbd_request_handler() {
25
+ global $wpdb;
26
+ if (isset($_POST['smbd_action'])) {
27
+
28
+ $wp_query = new WP_Query;
29
+ check_admin_referer( 'bulk-delete-posts');
30
+
31
+ switch($_POST['smbd_action']) {
32
+
33
+ case "bulk-delete-cats":
34
+ // delete by cats
35
+ $selected_cats = $_POST['smbd_cats'];
36
+ $posts = $wp_query->query(array('category__in'=>$selected_cats, 'post_type'=>'post', 'nopaging'=>'true'));
37
+
38
+ foreach ($posts as $post) {
39
+ wp_delete_post($post->ID);
40
+ }
41
+
42
+ break;
43
+
44
+ case "bulk-delete-tags":
45
+ // delete by tags
46
+ $selected_tags = $_POST['smbd_tags'];
47
+ $posts = $wp_query->query(array('tag__in'=>$selected_tags, 'post_type'=>'post', 'nopaging'=>'true'));
48
+
49
+ foreach ($posts as $post) {
50
+ wp_delete_post($post->ID);
51
+ }
52
+
53
+ break;
54
+
55
+ case "bulk-delete-special":
56
+ // Drafts
57
+ if ("drafs" == $_POST['smbd_drafs']) {
58
+ $drafts = $wp_query->query(array('post_status'=>'draft', 'nopaging'=>'true'));
59
+
60
+ foreach ($drafts as $draft) {
61
+ wp_delete_post($draft->ID);
62
+ }
63
+ }
64
+
65
+ // Revisions
66
+ if ("revisions" == $_POST['smbd_revisions']) {
67
+ $revisions = $wpdb->get_results($wpdb->prepare("select * from $wpdb->posts where post_type = 'revision'"));
68
+
69
+ foreach ($revisions as $revision) {
70
+ wp_delete_post($revision->ID);
71
+ }
72
+ }
73
+
74
+ // Pages
75
+ if ("pages" == $_POST['smbd_pages']) {
76
+ $pages = $wp_query->query(array('post_type'=>'page', 'nopaging'=>'true'));
77
+
78
+ foreach ($pages as $page) {
79
+ wp_delete_post($page->ID);
80
+ }
81
+ }
82
+ break;
83
+ }
84
+
85
+ // hook the admin notices action
86
+ add_action( 'admin_notices', 'smbd_deleted_notice', 9 );
87
+ }
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Show deleted notice messages
93
+ */
94
+ function smbd_deleted_notice() {
95
+ echo "<div class = 'updated'><p>" . __("All the selected posts have been sucessfully deleted.") ."</p></div>";
96
+ }
97
+
98
+ /**
99
+ * Show the Admin page
100
+ */
101
+ if (!function_exists('smbd_displayOptions')) {
102
+ function smbd_displayOptions() {
103
+ global $wpdb;
104
+ ?>
105
+ <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."); ?></strong></p></div>
106
+ <div class="wrap">
107
+ <h2>Bulk Delete</h2>
108
+
109
+ <h3><?php _e("Select the posts which you want to delete"); ?></h3>
110
+
111
+ <form name="smbd_form" id = "smbd_misc_form"
112
+ action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post"
113
+ onsubmit="return bd_validateForm(this);">
114
+
115
+ <?php
116
+ $wp_query = new WP_Query;
117
+ $drafts = $wp_query->query(array('post_status'=>'draft'));
118
+ $revisions = $wpdb->get_results($wpdb->prepare("select * from $wpdb->posts where post_type = 'revision'"));
119
+ $pages = $wp_query->query(array('post_type'=>'page'));
120
+ ?>
121
+ <fieldset class="options">
122
+ <table class="optiontable">
123
+ <tr>
124
+ <td scope="row" >
125
+ <input name="smbd_drafs" id ="smbd_drafs" value = "drafs" type = "checkbox" />
126
+ </td>
127
+ <td>
128
+ <label for="smbd_drafs"><?php echo _e("All Drafts"); ?> (<?php echo count($drafts) . " "; _e("Drafts"); ?>)</label>
129
+ </td>
130
+ <td>
131
+ <input name="smbd_revisions" id ="smbd_revisions" value = "revisions" type = "checkbox" />
132
+ </td>
133
+ <td>
134
+ <label for="smbd_revisions"><?php echo _e("All Revisions"); ?> (<?php echo count($revisions) . " "; _e("Revisons"); ?>)</label>
135
+ </td>
136
+ <td>
137
+ <input name="smbd_pages" value = "pages" type = "checkbox" />
138
+ </td>
139
+ <td>
140
+ <label for="smbd_pages"><?php echo _e("All Pages"); ?> (<?php echo count($pages) . " "; _e("Pages"); ?>)</label>
141
+ </td>
142
+ </tr>
143
+
144
+ </table>
145
+ </fieldset>
146
+ <p class="submit">
147
+ <input type="submit" name="submit" value="<?php _e("Bulk Delete ") ?>&raquo;">
148
+ </p>
149
+
150
+ <?php wp_nonce_field('bulk-delete-posts'); ?>
151
+
152
+ <input type="hidden" name="smbd_action" value="bulk-delete-special" />
153
+ </form>
154
+
155
+ <h3><?php _e("By Category"); ?></h3>
156
+ <h4><?php _e("Select the categories whose post you want to delete") ?></h4>
157
+
158
+ <form name="smbd_form" id = "smbd_cat_form"
159
+ action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post"
160
+ onsubmit="return bd_validateForm(this);">
161
+
162
+ <fieldset class="options">
163
+ <table class="optiontable">
164
+ <?php
165
+ $categories = get_categories(array('hide_empty' => false));
166
+ foreach ($categories as $category) {
167
+ ?>
168
+ <tr>
169
+ <td scope="row" >
170
+ <input name="smbd_cats[]" value = "<?php echo $category->cat_ID; ?>" type = "checkbox" />
171
+ </td>
172
+ <td>
173
+ <label for="smbd_cats"><?php echo $category->cat_name; ?> (<?php echo $category->count . " "; _e("Posts"); ?>)</label>
174
+ </td>
175
+ </tr>
176
+ <?php
177
+ }
178
+ ?>
179
+ <tr>
180
+ <td scope="row" >
181
+ <input name="smbd_cats_all" id ="smbd_cats_all" value = "-1" type = "checkbox" onclick="bd_checkAll(document.getElementById('smbd_cat_form'));" />
182
+ </td>
183
+ <td>
184
+ <label for="smbd_cats_all"><?php _e("All Categories") ?></label>
185
+ </td>
186
+ </tr>
187
+
188
+ </table>
189
+ </fieldset>
190
+ <p class="submit">
191
+ <input type="submit" name="submit" value="<?php _e("Bulk Delete ") ?>&raquo;">
192
+ </p>
193
+
194
+ <?php wp_nonce_field('bulk-delete-posts'); ?>
195
+
196
+ <input type="hidden" name="smbd_action" value="bulk-delete-cats" />
197
+ </form>
198
+ <?php
199
+ $tags = get_tags();
200
+ if (count($tags) > 0) {
201
+ ?>
202
+ <h3><?php _e("By Tags"); ?></h3>
203
+ <h4><?php _e("Select the tags whose post you want to delete") ?></h4>
204
+
205
+ <form name="smbd_form" id = "smbd_tag_form"
206
+ action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=bulk-delete.php" method="post"
207
+ onsubmit="return bd_validateForm(this);">
208
+
209
+ <fieldset class="options">
210
+ <table class="optiontable">
211
+ <?php
212
+ foreach ($tags as $tag) {
213
+ ?>
214
+ <tr>
215
+ <td scope="row" >
216
+ <input name="smbd_tags[]" value = "<?php echo $tag->term_id; ?>" type = "checkbox" />
217
+ </td>
218
+ <td>
219
+ <label for="smbd_tags"><?php echo $tag->name; ?> (<?php echo $tag->count . " "; _e("Posts"); ?>)</label>
220
+ </td>
221
+ </tr>
222
+ <?php
223
+ }
224
+ ?>
225
+ <tr>
226
+ <td scope="row" >
227
+ <input name="smbd_tags_all" id ="smbd_tags_all" value = "-1" type = "checkbox" onclick="bd_checkAll(document.getElementById('smbd_tag_form'));" />
228
+ </td>
229
+ <td>
230
+ <label for="smbd_tags_all"><?php _e("All Tags") ?></label>
231
+ </td>
232
+ </tr>
233
+
234
+ </table>
235
+ </fieldset>
236
+ <p class="submit">
237
+ <input type="submit" name="submit" value="<?php _e("Bulk Delete ") ?>&raquo;">
238
+ </p>
239
+
240
+ <?php wp_nonce_field('bulk-delete-posts'); ?>
241
+
242
+ <input type="hidden" name="smbd_action" value="bulk-delete-tags" />
243
+ </form>
244
+ <?php
245
+ }
246
+ ?>
247
+ <p><em><?php _e("If you are looking to move posts in bulk, instead of deleting then try out my "); ?> <a href = "http://sudarmuthu.com/wordpress/bulk-move"><?php _e("Bulk Move Plugin");?></a>.</em></p>
248
+ </div>
249
+ <?php
250
+
251
+ // Display credits in Footer
252
+ add_action( 'in_admin_footer', 'smbd_admin_footer' );
253
+ }
254
+ }
255
+
256
+ /**
257
+ * Print JavaScript
258
+ */
259
+ function smbd_print_scripts() {
260
+ ?>
261
+ <script type="text/javascript">
262
+
263
+ /**
264
+ * Check All Checkboxes
265
+ */
266
+ function bd_checkAll(form) {
267
+ for (i = 0, n = form.elements.length; i < n; i++) {
268
+ if(form.elements[i].type == "checkbox" && !(form.elements[i].getAttribute('onclick',2))) {
269
+ if(form.elements[i].checked == true)
270
+ form.elements[i].checked = false;
271
+ else
272
+ form.elements[i].checked = true;
273
+ }
274
+ }
275
+ }
276
+
277
+ /**
278
+ * Validate Form
279
+ */
280
+ function bd_validateForm(form) {
281
+ var valid = false;
282
+ for (i = 0, n = form.elements.length; i < n; i++) {
283
+ if(form.elements[i].type == "checkbox" && !(form.elements[i].getAttribute('onclick',2))) {
284
+ if(form.elements[i].checked == true) {
285
+ valid = true;
286
+ break;
287
+ }
288
+ }
289
+ }
290
+
291
+ if (valid) {
292
+ return confirm("<?php _e('Are you sure you want to delete all the selected posts'); ?>");
293
+ } else {
294
+ alert ("<?php _e('Please select atleast one'); ?>");
295
+ return false;
296
+ }
297
+ }
298
+ </script>
299
+ <?php
300
+ }
301
+
302
+ /**
303
+ * Add navigation menu
304
+ */
305
+ if(!function_exists('smbd_add_menu')) {
306
+ function smbd_add_menu() {
307
+ //Add a submenu to Manage
308
+ add_options_page("Bulk Delete", "Bulk Delete", 8, basename(__FILE__), "smbd_displayOptions");
309
+ }
310
+ }
311
+
312
+ /**
313
+ * Adds the settings link in the Plugin page. Based on http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/
314
+ * @staticvar <type> $this_plugin
315
+ * @param <type> $links
316
+ * @param <type> $file
317
+ */
318
+ function smbd_filter_plugin_actions($links, $file) {
319
+ static $this_plugin;
320
+ if( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
321
+
322
+ if( $file == $this_plugin ) {
323
+ $settings_link = '<a href="options-general.php?page=bulk-delete.php">' . _('Manage') . '</a>';
324
+ array_unshift( $links, $settings_link ); // before other links
325
+ }
326
+ return $links;
327
+ }
328
+
329
+ /**
330
+ * Adds Footer links. Based on http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/
331
+ */
332
+ function smbd_admin_footer() {
333
+ $plugin_data = get_plugin_data( __FILE__ );
334
+ printf('%1$s ' . __("plugin") .' | ' . __("Version") . ' %2$s | '. __('by') . ' %3$s<br />', $plugin_data['Title'], $plugin_data['Version'], $plugin_data['Author']);
335
+ }
336
+
337
+ add_filter( 'plugin_action_links', 'smbd_filter_plugin_actions', 10, 2 );
338
+
339
+ add_action('admin_menu', 'smbd_add_menu');
340
+ add_action('init', 'smbd_request_handler');
341
+ add_action('admin_head', 'smbd_print_scripts');
342
+ ?>
trunk/readme.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Bulk Delete ===
2
+ Contributors: sudar
3
+ Tags: post, comment, delete, bulk, draft, revision, page
4
+ Requires at least: 2.5
5
+ Tested up to: 2.7.1
6
+ Stable tag: 0.2
7
+
8
+ Bulk delete posts from selected categories or tags
9
+
10
+ == Description ==
11
+
12
+ Bulk Delete is a WordPress Plugin which can be used to delete posts in bulk from selected categories or tags. This Plugin can also delete all drafts, post revisions or pages.
13
+
14
+ More details about the Plugin can be found at the [Plugins Home page][1].
15
+
16
+ If you looking for just moving posts, instead of deleting, then use [Bulk Move Plugin][2] instead.
17
+
18
+ [1]: http://sudarmuthu.com/wordpress/bulk-delete
19
+ [2]: http://sudarmuthu.com/wordpress/bulk-move
20
+
21
+ == Installation ==
22
+
23
+ Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page.
24
+
25
+ ==Readme Generator==
26
+
27
+ This Readme file was generated using <a href = 'http://sudarmuthu.com/projects/wp-readme/'>wp-readme</a>, which generates readme files for WordPress Plugins.