Changeset 1422060
- Timestamp:
- 05/23/2016 04:30:38 AM (10 years ago)
- File:
-
- 1 edited
-
wp-bulk-post-delete/trunk/bulk_post_delete.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-bulk-post-delete/trunk/bulk_post_delete.php
r1422056 r1422060 1 1 <?php 2 /* 3 Plugin Name:WP Bulk Post Delete 4 Version: 1.0 5 Author: Numetriclabz 6 Author URI: http://www.numetriclabz.com/ 7 Description: This plugin delete posts according to your choice. 8 */ 2 /* 3 Plugin Name:WP Bulk Post Delete 4 Version: 1.0 5 Author: Numetriclabz 6 Author URI: http://www.numetriclabz.com/ 7 Description: This plugin delete posts according to your choice. 8 */ 9 10 add_action('admin_menu', 'bulk_post_delete'); 11 function bulk_post_delete(){ 12 add_menu_page( 'Detail', 'WP Post Delete', 'manage_options', 'bulk_post_delete-plugin', 'html_info' ); 13 } 9 14 10 add_action('admin_menu', 'bulk_post_delete'); 11 function bulk_post_delete(){ 12 add_menu_page( 'Detail', 'WP Post Delete', 'manage_options', 'bulk_post_delete-plugin', 'html_info' ); 13 } 14 function html_info() { 15 function html_info() { 15 16 global $wpdb, $wp_version, $post; 16 17 $theme_data = wp_get_theme(); 17 18 $theme = $theme_data->Name . ' ' . $theme_data->Version; 18 ?> 19 ?> 20 19 21 <div class="wrap"> 20 <ul id="users"> 21 <h2><?php _e('Authors'); ?></h2> 22 <form action="<?php bloginfo('url'); ?>" method="get"> 23 <?php 24 $authors = wp_dropdown_users(array('name' => 'author')); 25 $author_count = array(); 26 foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author" ) as $row ) { 27 $author_count[$row->post_author] = $row->count; 28 } 29 ?> 30 <input type="submit" name="submit" value="view" /> 31 </form> 32 </ul> 22 <h2>Wordpress Delete by Category and Author</h2> 23 </div> 33 24 34 <h2>Wordpress Delete by category</h2> 35 </div> 25 <h4><?php 26 _e('Select the categories from which you want to delete posts', 'bulk-delete'); 27 ?></h4> 36 28 37 <h4><?php 38 _e('Select the categories from which you want to delete posts', 'bulk-delete'); 39 ?></h4> 40 <p><?php 41 _e('Note: The post count below for each category is the total number of posts in that category, irrespective of post type', 'bulk-delete'); 42 ?></p> 29 <p><?php 30 _e('Note: The post count below for each category is the total number of posts in that category, irrespective of post type', 'bulk-delete'); 31 ?></p> 43 32 44 <?php 45 $categories = get_categories(array( 46 'hide_empty' => false 47 )); 48 ?><form method="post"> 49 50 51 52 53 <?php 33 <?php 34 $categories = get_categories(array( 35 'hide_empty' => false 36 )); 37 ?> 38 39 <form method="post"> 40 <?php 54 41 $counter = 1; 55 ?> 56 <?php 57 foreach ($categories as $category) { 42 ?> 43 <?php 44 45 foreach ($categories as $category) { 46 ?> 47 <input onclick="getValue(this.value)" type="checkbox" name="menu[]; 48 ?>" class="menu<?php 49 echo $counter; 50 ?>" id="menu<?php 51 echo $counter; 52 ?>" value="<?php 53 echo $category->cat_ID; 54 ?>"><?php 55 echo $category->cat_name, ' (', $category->count, ' ', __('Posts', 'bulk-delete'), ')'; 56 ?></input> 58 57 59 ?> 60 <input onclick="getValue(this.value)" type="checkbox" name="menu[]; 61 ?>" class="menu<?php 62 echo $counter; 63 ?>" id="menu<?php 64 echo $counter; 65 ?>" value="<?php 66 echo $category->cat_ID; 67 ?>"><?php 68 echo $category->cat_name, ' (', $category->count, ' ', __('Posts', 'bulk-delete'), ')'; 69 58 <?php 59 $counter++; 60 } 61 ?> 70 62 63 <div class="form-status"> 64 <h2>Post status</h2> 65 <input type="checkbox" name="publish" > Published <input type="checkbox" name="future"> Scheduled <input type="checkbox" name="pending"> Pending <input type="checkbox" name="draft"> Draft <input type="checkbox" name="private"> Private 66 </div> 67 <?php 68 if (version_compare($wp_version, '2.9', '>=')) { 69 70 ?> 71 <div class="wpdropdown"> 72 <h2>Select Author</h2> 73 <?php 74 $authors = wp_dropdown_users(array('name' => 'author'));?> 75 <p><?php 76 _e('Select the Author whose posts you want to delete', 'bulk-delete'); 77 ?></p> 78 </div> 71 79 80 <div class="form-trash"> 81 <h2>Bypass trash</h2> 82 <input type="checkbox" name="force_delete"> 83 <p class="description">Enable this option to completely delete the specified posts.</p> 84 </div> 72 85 73 ?></input> 86 <?php 87 } 88 $token1 = rand(); 89 ?> 74 90 75 <?php 76 $counter++; 77 ?> 78 <?php 91 <input type="hidden" name="wpmd_token1" value="<?php 92 echo $token1; 93 ?>" /> 94 <input type="submit" id="sub" class="sub button-primary" value="Delete the posts" onclick="func();" /> 95 <script> 96 function func() 97 { 98 var retVal = confirm("Delete? , This action cannot be undone"); 99 if( retVal == true ){ 100 document.getElementById("sub").setAttribute("name", "delete"); 101 return true; 79 102 } 80 ?> 81 <div class="form-status"> 82 <h2>Post status</h2> 83 <input type="checkbox" name="publish" > Published <input type="checkbox" name="future"> Scheduled <input type="checkbox" name="pending"> Pending <input type="checkbox" name="draft"> Draft <input type="checkbox" name="private"> Private 84 </div> 85 <?php 86 87 if (version_compare($wp_version, '2.9', '>=')) { 88 89 ?> 90 <div class="form-trash"> 91 <h2>Bypass trash</h2> 92 <input type="checkbox" name="force_delete"> 93 <p class="description">enable this option to completely delete the specified posts.</p> 94 </div> 95 <?php 96 } 97 ?> 98 99 100 101 102 <?php 103 $token1 = rand(); 104 105 ?> 106 <input type="hidden" name="wpmd_token1" value="<?php 107 echo $token1; 108 ?>" /> 109 110 <input type="submit" id="sub" class="sub button-primary" value="Delete the posts" onclick="func();" /> 111 112 113 <script> 114 function func() 115 { 116 117 var retVal = confirm("Delete? , This action cannot be undone"); 118 if( retVal == true ){ 119 120 document.getElementById("sub").setAttribute("name", "delete"); 121 return true; 122 } 123 else{ 124 e.preventdefault(); 125 return false; 126 } 127 128 } 129 </script> 130 131 132 <input type="button" name="cancel" value="Cancel" class="button" onclick="javascript:history.go(-1)" /> 133 </form> 134 135 <?php 136 137 if (isset($_POST['delete']) && ($_POST['wpmd_token1'] == get_option('wpmd_token1'))) { 138 139 $type = array(); 140 141 $type = implode(",", $_POST["menu"]); 142 143 144 145 146 $status = array(); 147 if (@$_POST ['publish'] == "on") { 148 $status [] .= "'publish'"; 149 } 150 if (@$_POST ['pending'] == "on") { 151 $status [] .= "'pending'"; 152 } 153 if (@$_POST ['draft'] == "on") { 154 $status [] .= "'draft'"; 155 } 156 if (@$_POST ['private'] == "on") { 157 $status [] .= "'private'"; 158 } 159 if (@$_POST ['future'] == "on") { 160 $status [] .= "'future'"; 161 } 162 163 $query = new WP_Query( array( 'cat' => $type , 'posts_per_page' => -1, 'post_status' => $status) ); 164 165 $jset = array(); 166 $json = json_encode( array_values( $query->get_posts())); 167 $jset = json_decode( $json, true ); 168 169 $a = array(); 170 $i =0; 171 while ( $query->have_posts() ) { 172 $query->the_post(); 173 174 $a[] = $jset[$i]['ID']; 175 176 $i++; 177 } 178 179 180 181 if ((count($type) >= "1" ) || count($status) >= "1" ) { 182 183 184 $post_ids = $a; 185 186 187 188 189 $cnt = count($post_ids); 190 191 if ($cnt) { 192 echo "<br \><div id=\"message\" class=\"updated fade\">Deleting <strong>$cnt</strong> items..."; 193 foreach ($post_ids as $id) { 194 if (($_POST['force_delete'])) { 195 wp_delete_post($id, @$_POST['force_delete'] == "on"); 196 } else { 197 wp_delete_post($id); 198 } 199 } 200 echo "Done!</div><br \>"; 201 return; 202 } 203 204 } 205 echo "<br \><div id=\"message\" class=\"updated fade\">Nothing to delete.</div><br \>"; 206 103 else{ 104 e.preventdefault(); 105 return false; 207 106 } 208 107 209 update_option('wpmd_token1', $token1); 108 } 109 </script> 110 111 112 <input type="button" name="cancel" value="Cancel" class="button" onclick="javascript:history.go(-1)" /> 113 </form> 114 115 <?php 116 if (isset($_POST['delete']) && ($_POST['wpmd_token1'] == get_option('wpmd_token1'))) { 117 $type = array(); 118 $type = implode(",", $_POST["menu"]); 210 119 211 } 120 $status = array(); 121 if (@$_POST ['publish'] == "on") { 122 $status [] .= "'publish'"; 123 } 124 if (@$_POST ['pending'] == "on") { 125 $status [] .= "'pending'"; 126 } 127 if (@$_POST ['draft'] == "on") { 128 $status [] .= "'draft'"; 129 } 130 if (@$_POST ['private'] == "on") { 131 $status [] .= "'private'"; 132 } 133 if (@$_POST ['future'] == "on") { 134 $status [] .= "'future'"; 135 } 212 136 137 if ($_POST ['author'] != "") { 138 $author = $wpdb->escape($_POST ['author']); 139 } 140 141 $query = new WP_Query( array( 'cat' => $type , 'posts_per_page' => -1, 'post_status' => $status, 'author'=> $author ) ); 142 // print_r($query); 143 $jset = array(); 144 $json = json_encode( array_values( $query->get_posts())); 145 $jset = json_decode( $json, true ); 146 147 $a = array(); 148 $i =0; 149 while ( $query->have_posts() ) { 150 $query->the_post(); 151 152 $a[] = $jset[$i]['ID']; 153 154 $i++; 155 } 156 157 158 159 if ((count($type) >= "1" ) || count($status) >= "1" ) { 160 161 162 $post_ids = $a; 163 164 165 166 167 $cnt = count($post_ids); 168 169 if ($cnt) { 170 echo "<br \><div id=\"message\" class=\"updated fade\">Deleting <strong>$cnt</strong> items..."; 171 foreach ($post_ids as $id) { 172 if (($_POST['force_delete'])) { 173 wp_delete_post($id, @$_POST['force_delete'] == "on"); 174 } else { 175 wp_delete_post($id); 176 } 177 } 178 echo "Done!</div><br \>"; 179 return; 180 } 181 182 } 183 echo "<br \><div id=\"message\" class=\"updated fade\">Nothing to Delete!</div><br \>"; 184 185 } 186 187 update_option('wpmd_token1', $token1); 188 189 } 190 213 191 ?> 214
Note: See TracChangeset
for help on using the changeset viewer.