1 | <?php |
||
2 | /** |
||
3 | * Plugin Name: Bulk Delete |
||
4 | * Plugin Script: bulk-delete.php |
||
5 | * Plugin URI: https://bulkwp.com |
||
6 | * Description: Bulk delete users and posts from selected categories, tags, post types, custom taxonomies or by post status like drafts, scheduled posts, revisions etc. |
||
7 | * Version: 5.6.1 |
||
8 | * License: GPLv2 or later |
||
9 | * License URI: http://www.gnu.org/licenses/gpl-2.0.html |
||
10 | * Author: Sudar |
||
11 | * Author URI: https://sudarmuthu.com/ |
||
12 | * Text Domain: bulk-delete |
||
13 | * Domain Path: languages/ |
||
14 | * === RELEASE NOTES === |
||
15 | * Check readme file for full release notes. |
||
16 | */ |
||
17 | |||
18 | /** |
||
19 | * Copyright 2009 Sudar Muthu (email : [email protected]) |
||
20 | * This program is free software; you can redistribute it and/or modify |
||
21 | * it under the terms of the GNU General Public License, version 2, as |
||
22 | * published by the Free Software Foundation. |
||
23 | * |
||
24 | * This program is distributed in the hope that it will be useful, |
||
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
27 | * GNU General Public License for more details. |
||
28 | * |
||
29 | * You should have received a copy of the GNU General Public License |
||
30 | * along with this program; if not, write to the Free Software |
||
31 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
||
32 | */ |
||
33 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
||
34 | |||
35 | /** |
||
36 | * Main Bulk_Delete class. |
||
37 | * |
||
38 | * Singleton @since 5.0 |
||
39 | */ |
||
40 | final class Bulk_Delete { |
||
41 | /** |
||
42 | * @var Bulk_Delete The one true Bulk_Delete |
||
43 | * |
||
44 | * @since 5.0 |
||
45 | */ |
||
46 | private static $instance; |
||
47 | |||
48 | /** |
||
49 | * Is the plugin is loaded? |
||
50 | * |
||
51 | * @since 5.7.0 |
||
52 | * |
||
53 | * @var bool |
||
54 | */ |
||
55 | private $loaded = false; |
||
56 | |||
57 | private $controller; |
||
58 | |||
59 | // version |
||
60 | const VERSION = '5.6.1'; |
||
61 | |||
62 | // Numeric constants |
||
63 | const MENU_ORDER = '26'; |
||
64 | |||
65 | // page slugs |
||
66 | const POSTS_PAGE_SLUG = 'bulk-delete-posts'; |
||
67 | const PAGES_PAGE_SLUG = 'bulk-delete-pages'; |
||
68 | const CRON_PAGE_SLUG = 'bulk-delete-cron'; |
||
69 | const ADDON_PAGE_SLUG = 'bulk-delete-addon'; |
||
70 | |||
71 | // JS constants |
||
72 | const JS_HANDLE = 'bulk-delete'; |
||
73 | const JS_VARIABLE = 'BulkWP'; |
||
74 | |||
75 | const CSS_HANDLE = 'bulk-delete'; |
||
76 | |||
77 | // Cron hooks |
||
78 | const CRON_HOOK_CATEGORY = 'do-bulk-delete-cat'; |
||
79 | const CRON_HOOK_POST_STATUS = 'do-bulk-delete-post-status'; |
||
80 | const CRON_HOOK_TAG = 'do-bulk-delete-tag'; |
||
81 | const CRON_HOOK_TAXONOMY = 'do-bulk-delete-taxonomy'; |
||
82 | const CRON_HOOK_POST_TYPE = 'do-bulk-delete-post-type'; |
||
83 | const CRON_HOOK_CUSTOM_FIELD = 'do-bulk-delete-custom-field'; |
||
84 | const CRON_HOOK_TITLE = 'do-bulk-delete-by-title'; |
||
85 | const CRON_HOOK_DUPLICATE_TITLE = 'do-bulk-delete-by-duplicate-title'; |
||
86 | const CRON_HOOK_POST_BY_ROLE = 'do-bulk-delete-posts-by-role'; |
||
87 | |||
88 | const CRON_HOOK_PAGES_STATUS = 'do-bulk-delete-pages-by-status'; |
||
89 | |||
90 | // meta boxes for delete posts |
||
91 | const BOX_POST_STATUS = 'bd_by_post_status'; |
||
92 | const BOX_CATEGORY = 'bd_by_category'; |
||
93 | const BOX_TAG = 'bd_by_tag'; |
||
94 | const BOX_TAX = 'bd_by_tax'; |
||
95 | const BOX_POST_TYPE = 'bd_by_post_type'; |
||
96 | const BOX_URL = 'bd_by_url'; |
||
97 | const BOX_POST_REVISION = 'bd_by_post_revision'; |
||
98 | const BOX_CUSTOM_FIELD = 'bd_by_custom_field'; |
||
99 | const BOX_TITLE = 'bd_by_title'; |
||
100 | const BOX_DUPLICATE_TITLE = 'bd_by_duplicate_title'; |
||
101 | const BOX_POST_FROM_TRASH = 'bd_posts_from_trash'; |
||
102 | const BOX_POST_BY_ROLE = 'bd_post_by_user_role'; |
||
103 | |||
104 | // meta boxes for delete pages |
||
105 | const BOX_PAGE_STATUS = 'bd_by_page_status'; |
||
106 | const BOX_PAGE_FROM_TRASH = 'bd_pages_from_trash'; |
||
107 | |||
108 | // Settings constants |
||
109 | const SETTING_OPTION_GROUP = 'bd_settings'; |
||
110 | const SETTING_OPTION_NAME = 'bd_licenses'; |
||
111 | const SETTING_SECTION_ID = 'bd_license_section'; |
||
112 | |||
113 | // Transient keys |
||
114 | const LICENSE_CACHE_KEY_PREFIX = 'bd-license_'; |
||
115 | |||
116 | // path variables |
||
117 | // Ideally these should be constants, but because of PHP's limitations, these are static variables |
||
118 | public static $PLUGIN_DIR; |
||
119 | public static $PLUGIN_URL; |
||
120 | public static $PLUGIN_FILE; |
||
121 | |||
122 | // Instance variables |
||
123 | public $translations; |
||
124 | public $posts_page; |
||
125 | public $pages_page; |
||
126 | public $cron_page; |
||
127 | public $addon_page; |
||
128 | public $settings_page; |
||
129 | public $meta_page; |
||
130 | public $misc_page; |
||
131 | public $display_activate_license_form = false; |
||
132 | |||
133 | // Deprecated. |
||
134 | // Will be removed in v6.0 |
||
135 | const CRON_HOOK_USER_ROLE = 'do-bulk-delete-users-by-role'; |
||
136 | public $users_page; |
||
137 | |||
138 | /** |
||
139 | * Main Bulk_Delete Instance. |
||
140 | * |
||
141 | * Insures that only one instance of Bulk_Delete exists in memory at any one |
||
142 | * time. Also prevents needing to define globals all over the place. |
||
143 | * |
||
144 | * @since 5.0 |
||
145 | * @static |
||
146 | * @staticvar array $instance |
||
147 | * |
||
148 | * @see BULK_DELETE() |
||
149 | * |
||
150 | * @uses Bulk_Delete::setup_paths() Setup the plugin paths |
||
151 | * @uses Bulk_Delete::includes() Include the required files |
||
152 | * @uses Bulk_Delete::load_textdomain() Load text domain for translation |
||
153 | * @uses Bulk_Delete::setup_actions() Setup the hooks and actions |
||
154 | * |
||
155 | * @return Bulk_Delete The one true instance of Bulk_Delete |
||
156 | */ |
||
157 | 5 | public static function get_instance() { |
|
158 | 5 | if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Bulk_Delete ) ) { |
|
159 | 1 | self::$instance = new Bulk_Delete(); |
|
160 | |||
161 | 1 | self::$instance->setup_paths(); |
|
162 | 1 | self::$instance->includes(); |
|
163 | } |
||
164 | |||
165 | 5 | return self::$instance; |
|
166 | } |
||
167 | |||
168 | /** |
||
169 | * Load the plugin if it is not loaded. |
||
170 | * |
||
171 | * This function will be invoked in the `plugins_loaded` hook. |
||
172 | */ |
||
173 | 1 | public function load() { |
|
174 | 1 | if ( $this->loaded ) { |
|
175 | return; |
||
176 | } |
||
177 | |||
178 | 1 | add_action( 'init', array( $this, 'on_init' ) ); |
|
179 | |||
180 | 1 | $this->setup_actions(); |
|
181 | |||
182 | 1 | $this->loaded = true; |
|
183 | |||
184 | /** |
||
185 | * Bulk Delete plugin loaded. |
||
186 | * |
||
187 | * @since 5.7.0 |
||
188 | */ |
||
189 | 1 | do_action( 'bd_loaded' ); |
|
190 | 1 | } |
|
191 | |||
192 | /** |
||
193 | * Throw error on object clone. |
||
194 | * |
||
195 | * The whole idea of the singleton design pattern is that there is a single |
||
196 | * object therefore, we don't want the object to be cloned. |
||
197 | * |
||
198 | * @since 5.0 |
||
199 | * @access protected |
||
200 | * |
||
201 | * @return void |
||
202 | */ |
||
203 | 1 | public function __clone() { |
|
204 | // Cloning instances of the class is forbidden |
||
205 | 1 | _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bulk-delete' ), '5.0' ); |
|
206 | 1 | } |
|
207 | |||
208 | /** |
||
209 | * Disable unserializing of the class. |
||
210 | * |
||
211 | * @since 5.0 |
||
212 | * @access protected |
||
213 | * |
||
214 | * @return void |
||
215 | */ |
||
216 | 1 | public function __wakeup() { |
|
217 | // Unserializing instances of the class is forbidden |
||
218 | 1 | _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bulk-delete' ), '5.0' ); |
|
219 | 1 | } |
|
220 | |||
221 | /** |
||
222 | * Setup plugin constants. |
||
223 | * |
||
224 | * @access private |
||
225 | * |
||
226 | * @since 5.0 |
||
227 | * |
||
228 | * @return void |
||
229 | */ |
||
230 | 1 | private function setup_paths() { |
|
231 | // Plugin Folder Path |
||
232 | 1 | self::$PLUGIN_DIR = plugin_dir_path( __FILE__ ); |
|
233 | |||
234 | // Plugin Folder URL |
||
235 | 1 | self::$PLUGIN_URL = plugin_dir_url( __FILE__ ); |
|
236 | |||
237 | // Plugin Root File |
||
238 | 1 | self::$PLUGIN_FILE = __FILE__; |
|
239 | 1 | } |
|
240 | |||
241 | /** |
||
242 | * Include required files. |
||
243 | * |
||
244 | * @access private |
||
245 | * |
||
246 | * @since 5.0 |
||
247 | * |
||
248 | * @return void |
||
249 | */ |
||
250 | 1 | private function includes() { |
|
251 | 1 | require_once self::$PLUGIN_DIR . '/include/base/class-bd-meta-box-module.php'; |
|
252 | 1 | require_once self::$PLUGIN_DIR . '/include/base/users/class-bd-user-meta-box-module.php'; |
|
253 | 1 | require_once self::$PLUGIN_DIR . '/include/base/class-bd-base-page.php'; |
|
254 | 1 | require_once self::$PLUGIN_DIR . '/include/base/class-bd-page.php'; |
|
255 | |||
256 | 1 | require_once self::$PLUGIN_DIR . '/include/controller/class-bd-controller.php'; |
|
257 | |||
258 | 1 | require_once self::$PLUGIN_DIR . '/include/ui/form.php'; |
|
259 | |||
260 | 1 | require_once self::$PLUGIN_DIR . '/include/posts/class-bulk-delete-posts.php'; |
|
261 | 1 | require_once self::$PLUGIN_DIR . '/include/pages/class-bulk-delete-pages.php'; |
|
262 | |||
263 | 1 | require_once self::$PLUGIN_DIR . '/include/users/class-bd-users-page.php'; |
|
264 | 1 | require_once self::$PLUGIN_DIR . '/include/users/modules/class-bulk-delete-users-by-user-role.php'; |
|
265 | 1 | require_once self::$PLUGIN_DIR . '/include/users/modules/class-bulk-delete-users-by-user-meta.php'; |
|
266 | |||
267 | 1 | require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-meta.php'; |
|
268 | 1 | require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-post-meta.php'; |
|
269 | 1 | require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-comment-meta.php'; |
|
270 | 1 | require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-user-meta.php'; |
|
271 | |||
272 | 1 | require_once self::$PLUGIN_DIR . '/include/misc/class-bulk-delete-misc.php'; |
|
273 | 1 | require_once self::$PLUGIN_DIR . '/include/misc/class-bulk-delete-jetpack-contact-form-messages.php'; |
|
274 | |||
275 | 1 | require_once self::$PLUGIN_DIR . '/include/settings/class-bd-settings-page.php'; |
|
276 | 1 | require_once self::$PLUGIN_DIR . '/include/settings/setting-helpers.php'; |
|
277 | 1 | require_once self::$PLUGIN_DIR . '/include/settings/class-bd-settings.php'; |
|
278 | |||
279 | 1 | require_once self::$PLUGIN_DIR . '/include/system-info/class-bd-system-info-page.php'; |
|
280 | |||
281 | 1 | require_once self::$PLUGIN_DIR . '/include/util/class-bd-util.php'; |
|
282 | 1 | require_once self::$PLUGIN_DIR . '/include/util/query.php'; |
|
283 | |||
284 | 1 | require_once self::$PLUGIN_DIR . '/include/compatibility/simple-login-log.php'; |
|
285 | 1 | require_once self::$PLUGIN_DIR . '/include/compatibility/the-event-calendar.php'; |
|
286 | 1 | require_once self::$PLUGIN_DIR . '/include/compatibility/woocommerce.php'; |
|
287 | 1 | require_once self::$PLUGIN_DIR . '/include/compatibility/advanced-custom-fields-pro.php'; |
|
288 | |||
289 | 1 | require_once self::$PLUGIN_DIR . '/include/deprecated/class-bulk-delete-users.php'; |
|
290 | 1 | require_once self::$PLUGIN_DIR . '/include/deprecated/deprecated.php'; |
|
291 | |||
292 | 1 | require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-addon.php'; |
|
293 | 1 | require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-base-addon.php'; |
|
294 | 1 | require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-scheduler-addon.php'; |
|
295 | |||
296 | 1 | require_once self::$PLUGIN_DIR . '/include/addons/addon-list.php'; |
|
297 | 1 | require_once self::$PLUGIN_DIR . '/include/addons/posts.php'; |
|
298 | 1 | require_once self::$PLUGIN_DIR . '/include/addons/pages.php'; |
|
299 | 1 | require_once self::$PLUGIN_DIR . '/include/addons/util.php'; |
|
300 | |||
301 | 1 | require_once self::$PLUGIN_DIR . '/include/license/class-bd-license.php'; |
|
302 | 1 | require_once self::$PLUGIN_DIR . '/include/license/class-bd-license-handler.php'; |
|
303 | 1 | require_once self::$PLUGIN_DIR . '/include/license/class-bd-edd-api-wrapper.php'; |
|
304 | |||
305 | 1 | require_once self::$PLUGIN_DIR . '/include/ui/admin-ui.php'; |
|
306 | 1 | require_once self::$PLUGIN_DIR . '/include/ui/class-bulk-delete-help-screen.php'; |
|
307 | 1 | } |
|
308 | |||
309 | /** |
||
310 | * Triggered when the `init` hook is fired. |
||
311 | * |
||
312 | * @since 5.7.0 |
||
313 | */ |
||
314 | 1 | public function on_init() { |
|
315 | 1 | $this->load_textdomain(); |
|
316 | 1 | } |
|
317 | |||
318 | /** |
||
319 | * Loads the plugin language files. |
||
320 | * |
||
321 | * @since 5.0 |
||
322 | */ |
||
323 | 1 | private function load_textdomain() { |
|
324 | // Load localization domain |
||
325 | 1 | $this->translations = dirname( plugin_basename( self::$PLUGIN_FILE ) ) . '/languages/'; |
|
326 | 1 | load_plugin_textdomain( 'bulk-delete', false, $this->translations ); |
|
327 | 1 | } |
|
328 | |||
329 | /** |
||
330 | * Loads the plugin's actions and hooks. |
||
331 | * |
||
332 | * @access private |
||
333 | * |
||
334 | * @since 5.0 |
||
335 | * |
||
336 | * @return void |
||
337 | */ |
||
338 | 1 | private function setup_actions() { |
|
339 | 1 | $this->controller = new BD_Controller(); |
|
340 | |||
341 | 1 | add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
342 | |||
343 | /** |
||
344 | * This is Ajax hook, It's runs when user search categories or tags on bulk-delete-posts page |
||
345 | * |
||
346 | * @since 5.7.0 |
||
347 | */ |
||
348 | 1 | add_action( 'wp_ajax_load_taxonomy_term', array( $this, 'load_taxonomy_term' ) ); |
|
349 | |||
350 | 1 | add_filter( 'bd_help_tooltip', 'bd_generate_help_tooltip', 10, 2 ); |
|
351 | |||
352 | 1 | if ( defined( 'BD_DEBUG' ) && BD_DEBUG ) { |
|
353 | add_action( 'bd_after_query', array( $this, 'log_sql_query' ) ); |
||
354 | } |
||
355 | 1 | } |
|
356 | |||
357 | /** |
||
358 | * Log SQL query used by Bulk Delete. |
||
359 | * |
||
360 | * Query is logged only when `BD_DEBUG` is set. |
||
361 | * |
||
362 | * @since 5.6 |
||
363 | * |
||
364 | * @param \WP_Query $wp_query WP Query object. |
||
365 | */ |
||
366 | public function log_sql_query( $wp_query ) { |
||
367 | $query = $wp_query->request; |
||
368 | |||
369 | /** |
||
370 | * Bulk Delete query is getting logged. |
||
371 | * |
||
372 | * @since 5.6 |
||
373 | * |
||
374 | * @param string $query Bulk Delete SQL Query. |
||
375 | */ |
||
376 | do_action( 'bd_log_sql_query', $query ); |
||
377 | |||
378 | error_log( 'Bulk Delete Query: ' . $query ); |
||
379 | } |
||
380 | |||
381 | /** |
||
382 | * Add navigation menu. |
||
383 | */ |
||
384 | public function add_menu() { |
||
385 | add_menu_page( __( 'Bulk WP', 'bulk-delete' ), __( 'Bulk WP', 'bulk-delete' ), 'manage_options', self::POSTS_PAGE_SLUG, array( $this, 'display_posts_page' ), 'dashicons-trash', self::MENU_ORDER ); |
||
386 | |||
387 | $this->posts_page = add_submenu_page( self::POSTS_PAGE_SLUG, __( 'Bulk Delete Posts', 'bulk-delete' ), __( 'Bulk Delete Posts', 'bulk-delete' ), 'delete_posts', self::POSTS_PAGE_SLUG, array( $this, 'display_posts_page' ) ); |
||
388 | $this->pages_page = add_submenu_page( self::POSTS_PAGE_SLUG, __( 'Bulk Delete Pages', 'bulk-delete' ), __( 'Bulk Delete Pages', 'bulk-delete' ), 'delete_pages', self::PAGES_PAGE_SLUG, array( $this, 'display_pages_page' ) ); |
||
389 | |||
390 | /** |
||
391 | * Runs just after adding all *delete* menu items to Bulk WP main menu. |
||
392 | * |
||
393 | * This action is primarily for adding extra *delete* menu items to the Bulk WP main menu. |
||
394 | * |
||
395 | * @since 5.3 |
||
396 | */ |
||
397 | do_action( 'bd_after_primary_menus' ); |
||
398 | |||
399 | /** |
||
400 | * Runs just before adding non-action menu items to Bulk WP main menu. |
||
401 | * |
||
402 | * This action is primarily for adding extra menu items before non-action menu items to the Bulk WP main menu. |
||
403 | * |
||
404 | * @since 5.3 |
||
405 | */ |
||
406 | do_action( 'bd_before_secondary_menus' ); |
||
407 | |||
408 | $this->cron_page = add_submenu_page( self::POSTS_PAGE_SLUG, __( 'Bulk Delete Schedules', 'bulk-delete' ), __( 'Scheduled Jobs', 'bulk-delete' ), 'delete_posts' , self::CRON_PAGE_SLUG , array( $this, 'display_cron_page' ) ); |
||
409 | $this->addon_page = add_submenu_page( self::POSTS_PAGE_SLUG, __( 'Addon Licenses' , 'bulk-delete' ), __( 'Addon Licenses', 'bulk-delete' ), 'activate_plugins', self::ADDON_PAGE_SLUG, array( 'BD_License', 'display_addon_page' ) ); |
||
410 | |||
411 | /** |
||
412 | * Runs just after adding all menu items to Bulk WP main menu. |
||
413 | * |
||
414 | * This action is primarily for adding extra menu items to the Bulk WP main menu. |
||
415 | * |
||
416 | * @since 5.3 |
||
417 | */ |
||
418 | do_action( 'bd_after_all_menus' ); |
||
419 | |||
420 | // enqueue JavaScript |
||
421 | add_action( 'admin_print_scripts-' . $this->posts_page, array( $this, 'add_script' ) ); |
||
422 | add_action( 'admin_print_scripts-' . $this->pages_page, array( $this, 'add_script' ) ); |
||
423 | |||
424 | // delete posts page |
||
425 | add_action( "load-{$this->posts_page}", array( $this, 'add_delete_posts_settings_panel' ) ); |
||
426 | add_action( "add_meta_boxes_{$this->posts_page}", array( $this, 'add_delete_posts_meta_boxes' ) ); |
||
427 | |||
428 | // delete pages page |
||
429 | add_action( "load-{$this->pages_page}", array( $this, 'add_delete_pages_settings_panel' ) ); |
||
430 | add_action( "add_meta_boxes_{$this->pages_page}", array( $this, 'add_delete_pages_meta_boxes' ) ); |
||
431 | } |
||
432 | |||
433 | /** |
||
434 | * Add settings Panel for delete posts page. |
||
435 | */ |
||
436 | public function add_delete_posts_settings_panel() { |
||
437 | /** |
||
438 | * Add contextual help for admin screens. |
||
439 | * |
||
440 | * @since 5.1 |
||
441 | */ |
||
442 | do_action( 'bd_add_contextual_help', $this->posts_page ); |
||
443 | |||
444 | /* Trigger the add_meta_boxes hooks to allow meta boxes to be added */ |
||
445 | do_action( 'add_meta_boxes_' . $this->posts_page, null ); |
||
446 | |||
447 | /* Enqueue WordPress' script for handling the meta boxes */ |
||
448 | wp_enqueue_script( 'postbox' ); |
||
449 | } |
||
450 | |||
451 | /** |
||
452 | * Ajax call back function for getting taxonomies to load select2 options. |
||
453 | * |
||
454 | * @since 5.7.0 |
||
455 | */ |
||
456 | public function load_taxonomy_term(){ |
||
457 | $return = array(); |
||
458 | |||
459 | $terms = get_terms( array( |
||
460 | 'taxonomy' => $_GET['term'], |
||
461 | 'hide_empty' => false, |
||
462 | 'search' => $_GET['q'] |
||
463 | ) ); |
||
464 | |||
465 | foreach ( $terms as $term ) { |
||
466 | $return[] = array( absint($term->term_id), $term->name.' ('. $term->count. __( ' Posts', 'bulk-delete' ) . ')' ); |
||
467 | } |
||
468 | |||
469 | echo json_encode( $return ); |
||
470 | die; |
||
0 ignored issues
–
show
|
|||
471 | } |
||
472 | |||
473 | /** |
||
474 | * Register meta boxes for delete posts page. |
||
475 | */ |
||
476 | public function add_delete_posts_meta_boxes() { |
||
477 | add_meta_box( self::BOX_POST_STATUS , __( 'By Post Status' , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_status_box' , $this->posts_page , 'advanced' ); |
||
478 | add_meta_box( self::BOX_CATEGORY , __( 'By Category' , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_category_box' , $this->posts_page , 'advanced' ); |
||
479 | add_meta_box( self::BOX_TAG , __( 'By Tag' , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_tag_box' , $this->posts_page , 'advanced' ); |
||
480 | add_meta_box( self::BOX_TAX , __( 'By Custom Taxonomy' , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_taxonomy_box' , $this->posts_page , 'advanced' ); |
||
481 | add_meta_box( self::BOX_POST_TYPE , __( 'By Custom Post Type' , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_post_type_box' , $this->posts_page , 'advanced' ); |
||
482 | add_meta_box( self::BOX_URL , __( 'By URL' , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_url_box' , $this->posts_page , 'advanced' ); |
||
483 | add_meta_box( self::BOX_POST_REVISION , __( 'By Post Revision' , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_posts_by_revision_box' , $this->posts_page , 'advanced' ); |
||
484 | |||
485 | /** |
||
486 | * Add meta box in delete posts page |
||
487 | * This hook can be used for adding additional meta boxes in delete posts page. |
||
488 | * |
||
489 | * @since 5.3 |
||
490 | */ |
||
491 | do_action( 'bd_add_meta_box_for_posts' ); |
||
492 | } |
||
493 | |||
494 | /** |
||
495 | * Setup settings panel for delete pages page. |
||
496 | * |
||
497 | * @since 5.0 |
||
498 | */ |
||
499 | public function add_delete_pages_settings_panel() { |
||
500 | /** |
||
501 | * Add contextual help for admin screens. |
||
502 | * |
||
503 | * @since 5.1 |
||
504 | */ |
||
505 | do_action( 'bd_add_contextual_help', $this->pages_page ); |
||
506 | |||
507 | /* Trigger the add_meta_boxes hooks to allow meta boxes to be added */ |
||
508 | do_action( 'add_meta_boxes_' . $this->pages_page, null ); |
||
509 | |||
510 | /* Enqueue WordPress' script for handling the meta boxes */ |
||
511 | wp_enqueue_script( 'postbox' ); |
||
512 | } |
||
513 | |||
514 | /** |
||
515 | * Register meta boxes for delete pages page. |
||
516 | * |
||
517 | * @since 5.0 |
||
518 | */ |
||
519 | public function add_delete_pages_meta_boxes() { |
||
520 | add_meta_box( self::BOX_PAGE_STATUS, __( 'By Page Status', 'bulk-delete' ), 'Bulk_Delete_Pages::render_delete_pages_by_status_box', $this->pages_page, 'advanced' ); |
||
521 | |||
522 | /** |
||
523 | * Add meta box in delete pages page |
||
524 | * This hook can be used for adding additional meta boxes in delete pages page. |
||
525 | * |
||
526 | * @since 5.3 |
||
527 | */ |
||
528 | do_action( 'bd_add_meta_box_for_pages' ); |
||
529 | } |
||
530 | |||
531 | /** |
||
532 | * Enqueue Scripts and Styles. |
||
533 | */ |
||
534 | public function add_script() { |
||
535 | global $wp_scripts; |
||
536 | |||
537 | /** |
||
538 | * Runs just before enqueuing scripts and styles in all Bulk WP admin pages. |
||
539 | * |
||
540 | * This action is primarily for registering or deregistering additional scripts or styles. |
||
541 | * |
||
542 | * @since 5.5.1 |
||
543 | */ |
||
544 | do_action( 'bd_before_admin_enqueue_scripts' ); |
||
545 | |||
546 | wp_enqueue_script( 'jquery-ui-timepicker', plugins_url( '/assets/js/jquery-ui-timepicker-addon.min.js', __FILE__ ), array( 'jquery-ui-slider', 'jquery-ui-datepicker' ), '1.5.4', true ); |
||
547 | wp_enqueue_style( 'jquery-ui-timepicker', plugins_url( '/assets/css/jquery-ui-timepicker-addon.min.css', __FILE__ ), array(), '1.5.4' ); |
||
548 | |||
549 | wp_enqueue_script( 'select2', plugins_url( '/assets/js/select2.min.js', __FILE__ ), array( 'jquery' ), '4.0.0', true ); |
||
550 | wp_enqueue_style( 'select2', plugins_url( '/assets/css/select2.min.css', __FILE__ ), array(), '4.0.0' ); |
||
551 | |||
552 | $postfix = ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) ? '' : '.min'; |
||
553 | wp_enqueue_script( self::JS_HANDLE, plugins_url( '/assets/js/bulk-delete' . $postfix . '.js', __FILE__ ), array( 'jquery-ui-timepicker', 'jquery-ui-tooltip' ), self::VERSION, true ); |
||
554 | wp_enqueue_style( self::CSS_HANDLE, plugins_url( '/assets/css/bulk-delete' . $postfix . '.css', __FILE__ ), array( 'select2' ), self::VERSION ); |
||
555 | |||
556 | $ui = $wp_scripts->query( 'jquery-ui-core' ); |
||
557 | $url = "//ajax.googleapis.com/ajax/libs/jqueryui/{$ui->ver}/themes/smoothness/jquery-ui.css"; |
||
558 | wp_enqueue_style( 'jquery-ui-smoothness', $url, false, $ui->ver ); |
||
559 | |||
560 | /** |
||
561 | * Filter JavaScript array. |
||
562 | * |
||
563 | * This filter can be used to extend the array that is passed to JavaScript |
||
564 | * |
||
565 | * @since 5.4 |
||
566 | */ |
||
567 | $translation_array = apply_filters( 'bd_javascript_array', array( |
||
568 | 'msg' => array(), |
||
569 | 'validators' => array(), |
||
570 | 'dt_iterators' => array(), |
||
571 | 'pre_action_msg' => array(), |
||
572 | 'error_msg' => array(), |
||
573 | 'pro_iterators' => array(), |
||
574 | ) ); |
||
575 | wp_localize_script( self::JS_HANDLE, self::JS_VARIABLE, $translation_array ); |
||
576 | |||
577 | /** |
||
578 | * Runs just after enqueuing scripts and styles in all Bulk WP admin pages. |
||
579 | * |
||
580 | * This action is primarily for registering additional scripts or styles. |
||
581 | * |
||
582 | * @since 5.5.1 |
||
583 | */ |
||
584 | do_action( 'bd_after_admin_enqueue_scripts' ); |
||
585 | } |
||
586 | |||
587 | /** |
||
588 | * Show the delete posts page. |
||
589 | * |
||
590 | * @Todo Move this function to Bulk_Delete_Posts class |
||
591 | */ |
||
592 | public function display_posts_page() { |
||
593 | ?> |
||
594 | <div class="wrap"> |
||
595 | <h2><?php _e( 'Bulk Delete Posts', 'bulk-delete' );?></h2> |
||
596 | <?php settings_errors(); ?> |
||
597 | |||
598 | <form method = "post"> |
||
599 | <?php |
||
600 | // nonce for bulk delete |
||
601 | wp_nonce_field( 'sm-bulk-delete-posts', 'sm-bulk-delete-posts-nonce' ); |
||
602 | |||
603 | /* Used to save closed meta boxes and their order */ |
||
604 | wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); |
||
605 | wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); |
||
606 | ?> |
||
607 | <div id = "poststuff"> |
||
608 | <div id="post-body" class="metabox-holder columns-1"> |
||
609 | |||
610 | <div class="notice notice-warning"> |
||
611 | <p><strong><?php _e( 'WARNING: Posts deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p> |
||
612 | </div> |
||
613 | |||
614 | <div id="postbox-container-2" class="postbox-container"> |
||
615 | <?php do_meta_boxes( '', 'advanced', null ); ?> |
||
616 | </div> <!-- #postbox-container-2 --> |
||
617 | |||
618 | </div> <!-- #post-body --> |
||
619 | </div><!-- #poststuff --> |
||
620 | </form> |
||
621 | </div><!-- .wrap --> |
||
622 | |||
623 | <?php |
||
624 | /** |
||
625 | * Runs just before displaying the footer text in the "Bulk Delete Posts" admin page. |
||
626 | * |
||
627 | * This action is primarily for adding extra content in the footer of "Bulk Delete Posts" admin page. |
||
628 | * |
||
629 | * @since 5.0 |
||
630 | */ |
||
631 | do_action( 'bd_admin_footer_posts_page' ); |
||
632 | } |
||
633 | |||
634 | /** |
||
635 | * Display the delete pages page. |
||
636 | * |
||
637 | * @Todo Move this function to Bulk_Delete_Pages class |
||
638 | * |
||
639 | * @since 5.0 |
||
640 | */ |
||
641 | public function display_pages_page() { |
||
642 | ?> |
||
643 | <div class="wrap"> |
||
644 | <h2><?php _e( 'Bulk Delete Pages', 'bulk-delete' );?></h2> |
||
645 | <?php settings_errors(); ?> |
||
646 | |||
647 | <form method = "post"> |
||
648 | <?php |
||
649 | // nonce for bulk delete |
||
650 | wp_nonce_field( 'sm-bulk-delete-pages', 'sm-bulk-delete-pages-nonce' ); |
||
651 | |||
652 | /* Used to save closed meta boxes and their order */ |
||
653 | wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); |
||
654 | wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); |
||
655 | ?> |
||
656 | <div id = "poststuff"> |
||
657 | <div id="post-body" class="metabox-holder columns-1"> |
||
658 | |||
659 | <div class="notice notice-warning"> |
||
660 | <p><strong><?php _e( 'WARNING: Pages deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p> |
||
661 | </div> |
||
662 | |||
663 | <div id="postbox-container-2" class="postbox-container"> |
||
664 | <?php do_meta_boxes( '', 'advanced', null ); ?> |
||
665 | </div> <!-- #postbox-container-2 --> |
||
666 | |||
667 | </div> <!-- #post-body --> |
||
668 | </div><!-- #poststuff --> |
||
669 | </form> |
||
670 | </div><!-- .wrap --> |
||
671 | |||
672 | <?php |
||
673 | /** |
||
674 | * Runs just before displaying the footer text in the "Bulk Delete Pages" admin page. |
||
675 | * |
||
676 | * This action is primarily for adding extra content in the footer of "Bulk Delete Pages" admin page. |
||
677 | * |
||
678 | * @since 5.0 |
||
679 | */ |
||
680 | do_action( 'bd_admin_footer_pages_page' ); |
||
681 | } |
||
682 | |||
683 | /** |
||
684 | * Display the schedule page. |
||
685 | */ |
||
686 | public function display_cron_page() { |
||
687 | if ( ! class_exists( 'WP_List_Table' ) ) { |
||
688 | require_once ABSPATH . WPINC . '/class-wp-list-table.php'; |
||
689 | } |
||
690 | |||
691 | if ( ! class_exists( 'Cron_List_Table' ) ) { |
||
692 | require_once self::$PLUGIN_DIR . '/include/cron/class-cron-list-table.php'; |
||
693 | } |
||
694 | |||
695 | // Prepare Table of elements |
||
696 | $cron_list_table = new Cron_List_Table(); |
||
697 | $cron_list_table->prepare_items(); |
||
698 | ?> |
||
699 | <div class="wrap"> |
||
700 | <h2><?php _e( 'Bulk Delete Schedules', 'bulk-delete' );?></h2> |
||
701 | <?php settings_errors(); ?> |
||
702 | <?php |
||
703 | // Table of elements |
||
704 | $cron_list_table->display(); |
||
705 | bd_display_available_addon_list(); |
||
706 | ?> |
||
707 | </div> |
||
708 | <?php |
||
709 | /** |
||
710 | * Runs just before displaying the footer text in the "Schedules" admin page. |
||
711 | * |
||
712 | * This action is primarily for adding extra content in the footer of "Schedules" admin page. |
||
713 | * |
||
714 | * @since 5.0 |
||
715 | */ |
||
716 | do_action( 'bd_admin_footer_cron_page' ); |
||
717 | } |
||
718 | } |
||
719 | |||
720 | /** |
||
721 | * The main function responsible for returning the one true Bulk_Delete |
||
722 | * Instance to functions everywhere. |
||
723 | * |
||
724 | * Use this function like you would a global variable, except without needing |
||
725 | * to declare the global. |
||
726 | * |
||
727 | * Example: `<?php $bulk_delete = BULK_DELETE(); ?>` |
||
728 | * |
||
729 | * @since 5.0 |
||
730 | * |
||
731 | * @return Bulk_Delete The one true Bulk_Delete Instance |
||
732 | */ |
||
733 | function BULK_DELETE() { |
||
734 | 1 | return Bulk_Delete::get_instance(); |
|
735 | } |
||
736 | |||
737 | /** |
||
738 | * Load Bulk Delete plugin. |
||
739 | * |
||
740 | * @since 5.7.0 |
||
741 | */ |
||
742 | function load_bulk_delete() { |
||
743 | 1 | $bulk_delete = BULK_DELETE(); |
|
744 | |||
745 | 1 | add_action( 'plugins_loaded', array( $bulk_delete, 'load' ), 101 ); |
|
746 | 1 | } |
|
747 | |||
748 | load_bulk_delete(); |
||
749 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.