Completed
Push — master ( 2a5bdf...b12cef )
by Sudar
08:15 queued 04:50
created

Bulk_Delete::add_script()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 51
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 21
nc 4
nop 0
dl 0
loc 51
rs 9.4109
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
	private $controller;
49
50
	// version
51
	const VERSION                   = '5.6.1';
52
53
	// Numeric constants
54
	const MENU_ORDER                = '26';
55
56
	// page slugs
57
	const POSTS_PAGE_SLUG           = 'bulk-delete-posts';
58
	const PAGES_PAGE_SLUG           = 'bulk-delete-pages';
59
	const CRON_PAGE_SLUG            = 'bulk-delete-cron';
60
	const ADDON_PAGE_SLUG           = 'bulk-delete-addon';
61
62
	// JS constants
63
	const JS_HANDLE                 = 'bulk-delete';
64
	const JS_VARIABLE               = 'BulkWP';
65
66
	const CSS_HANDLE                = 'bulk-delete';
67
68
	// Cron hooks
69
	const CRON_HOOK_CATEGORY        = 'do-bulk-delete-cat';
70
	const CRON_HOOK_POST_STATUS     = 'do-bulk-delete-post-status';
71
	const CRON_HOOK_TAG             = 'do-bulk-delete-tag';
72
	const CRON_HOOK_TAXONOMY        = 'do-bulk-delete-taxonomy';
73
	const CRON_HOOK_POST_TYPE       = 'do-bulk-delete-post-type';
74
	const CRON_HOOK_CUSTOM_FIELD    = 'do-bulk-delete-custom-field';
75
	const CRON_HOOK_TITLE           = 'do-bulk-delete-by-title';
76
	const CRON_HOOK_DUPLICATE_TITLE = 'do-bulk-delete-by-duplicate-title';
77
	const CRON_HOOK_POST_BY_ROLE    = 'do-bulk-delete-posts-by-role';
78
79
	const CRON_HOOK_PAGES_STATUS    = 'do-bulk-delete-pages-by-status';
80
81
	// meta boxes for delete posts
82
	const BOX_POST_STATUS           = 'bd_by_post_status';
83
	const BOX_CATEGORY              = 'bd_by_category';
84
	const BOX_TAG                   = 'bd_by_tag';
85
	const BOX_TAX                   = 'bd_by_tax';
86
	const BOX_POST_TYPE             = 'bd_by_post_type';
87
	const BOX_URL                   = 'bd_by_url';
88
	const BOX_POST_REVISION         = 'bd_by_post_revision';
89
	const BOX_CUSTOM_FIELD          = 'bd_by_custom_field';
90
	const BOX_TITLE                 = 'bd_by_title';
91
	const BOX_DUPLICATE_TITLE       = 'bd_by_duplicate_title';
92
	const BOX_POST_FROM_TRASH       = 'bd_posts_from_trash';
93
	const BOX_POST_BY_ROLE          = 'bd_post_by_user_role';
94
95
	// meta boxes for delete pages
96
	const BOX_PAGE_STATUS           = 'bd_by_page_status';
97
	const BOX_PAGE_FROM_TRASH       = 'bd_pages_from_trash';
98
99
	// Settings constants
100
	const SETTING_OPTION_GROUP      = 'bd_settings';
101
	const SETTING_OPTION_NAME       = 'bd_licenses';
102
	const SETTING_SECTION_ID        = 'bd_license_section';
103
104
	// Transient keys
105
	const LICENSE_CACHE_KEY_PREFIX  = 'bd-license_';
106
107
	// path variables
108
	// Ideally these should be constants, but because of PHP's limitations, these are static variables
109
	public static $PLUGIN_DIR;
110
	public static $PLUGIN_URL;
111
	public static $PLUGIN_FILE;
112
113
	// Instance variables
114
	public $translations;
115
	public $posts_page;
116
	public $pages_page;
117
	public $cron_page;
118
	public $addon_page;
119
	public $settings_page;
120
	public $meta_page;
121
	public $misc_page;
122
	public $display_activate_license_form = false;
123
124
	// Deprecated.
125
	// Will be removed in v6.0
126
	const CRON_HOOK_USER_ROLE = 'do-bulk-delete-users-by-role';
127
	public $users_page;
128
129
	/**
130
	 * Main Bulk_Delete Instance.
131
	 *
132
	 * Insures that only one instance of Bulk_Delete exists in memory at any one
133
	 * time. Also prevents needing to define globals all over the place.
134
	 *
135
	 * @since 5.0
136
	 * @static
137
	 * @staticvar array $instance
138
	 *
139
	 * @see BULK_DELETE()
140
	 *
141
	 * @uses Bulk_Delete::setup_paths() Setup the plugin paths
142
	 * @uses Bulk_Delete::includes() Include the required files
143
	 * @uses Bulk_Delete::load_textdomain() Load text domain for translation
144
	 * @uses Bulk_Delete::setup_actions() Setup the hooks and actions
145
	 *
146
	 * @return Bulk_Delete The one true instance of Bulk_Delete
147
	 */
148
	public static function instance() {
149
		if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Bulk_Delete ) ) {
150
			self::$instance = new Bulk_Delete;
151
			self::$instance->setup_paths();
152
			self::$instance->includes();
153
			self::$instance->load_textdomain();
154
			self::$instance->setup_actions();
155
		}
156
157
		return self::$instance;
158
	}
159
160
	/**
161
	 * Throw error on object clone.
162
	 *
163
	 * The whole idea of the singleton design pattern is that there is a single
164
	 * object therefore, we don't want the object to be cloned.
165
	 *
166
	 * @since  5.0
167
	 * @access protected
168
	 *
169
	 * @return void
170
	 */
171
	public function __clone() {
172
		// Cloning instances of the class is forbidden
173
		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'bulk-delete' ), '5.0' );
174
	}
175
176
	/**
177
	 * Disable unserializing of the class.
178
	 *
179
	 * @since  5.0
180
	 * @access protected
181
	 *
182
	 * @return void
183
	 */
184
	public function __wakeup() {
185
		// Unserializing instances of the class is forbidden
186
		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'bulk-delete' ), '5.0' );
187
	}
188
189
	/**
190
	 * Setup plugin constants.
191
	 *
192
	 * @access private
193
	 *
194
	 * @since  5.0
195
	 *
196
	 * @return void
197
	 */
198
	private function setup_paths() {
199
		// Plugin Folder Path
200
		self::$PLUGIN_DIR = plugin_dir_path( __FILE__ );
201
202
		// Plugin Folder URL
203
		self::$PLUGIN_URL = plugin_dir_url( __FILE__ );
204
205
		// Plugin Root File
206
		self::$PLUGIN_FILE = __FILE__;
207
	}
208
209
	/**
210
	 * Include required files.
211
	 *
212
	 * @access private
213
	 *
214
	 * @since  5.0
215
	 *
216
	 * @return void
217
	 */
218
	private function includes() {
219
		require_once self::$PLUGIN_DIR . '/include/base/class-bd-meta-box-module.php';
220
		require_once self::$PLUGIN_DIR . '/include/base/users/class-bd-user-meta-box-module.php';
221
		require_once self::$PLUGIN_DIR . '/include/base/class-bd-base-page.php';
222
		require_once self::$PLUGIN_DIR . '/include/base/class-bd-page.php';
223
224
		require_once self::$PLUGIN_DIR . '/include/controller/class-bd-controller.php';
225
226
		require_once self::$PLUGIN_DIR . '/include/ui/form.php';
227
228
		require_once self::$PLUGIN_DIR . '/include/posts/class-bulk-delete-posts.php';
229
		require_once self::$PLUGIN_DIR . '/include/pages/class-bulk-delete-pages.php';
230
231
		require_once self::$PLUGIN_DIR . '/include/users/class-bd-users-page.php';
232
		require_once self::$PLUGIN_DIR . '/include/users/modules/class-bulk-delete-users-by-user-role.php';
233
		require_once self::$PLUGIN_DIR . '/include/users/modules/class-bulk-delete-users-by-user-meta.php';
234
235
		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-meta.php';
236
		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-post-meta.php';
237
		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-comment-meta.php';
238
		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-user-meta.php';
239
240
		require_once self::$PLUGIN_DIR . '/include/misc/class-bulk-delete-misc.php';
241
		require_once self::$PLUGIN_DIR . '/include/misc/class-bulk-delete-jetpack-contact-form-messages.php';
242
243
		require_once self::$PLUGIN_DIR . '/include/settings/class-bd-settings-page.php';
244
		require_once self::$PLUGIN_DIR . '/include/settings/setting-helpers.php';
245
		require_once self::$PLUGIN_DIR . '/include/settings/class-bd-settings.php';
246
247
		require_once self::$PLUGIN_DIR . '/include/system-info/class-bd-system-info-page.php';
248
249
		require_once self::$PLUGIN_DIR . '/include/util/class-bd-util.php';
250
		require_once self::$PLUGIN_DIR . '/include/util/query.php';
251
252
		require_once self::$PLUGIN_DIR . '/include/compatibility/simple-login-log.php';
253
		require_once self::$PLUGIN_DIR . '/include/compatibility/the-event-calendar.php';
254
		require_once self::$PLUGIN_DIR . '/include/compatibility/woocommerce.php';
255
		require_once self::$PLUGIN_DIR . '/include/compatibility/advanced-custom-fields-pro.php';
256
257
		require_once self::$PLUGIN_DIR . '/include/deprecated/class-bulk-delete-users.php';
258
		require_once self::$PLUGIN_DIR . '/include/deprecated/deprecated.php';
259
260
		require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-addon.php';
261
		require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-base-addon.php';
262
		require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-scheduler-addon.php';
263
264
		require_once self::$PLUGIN_DIR . '/include/addons/addon-list.php';
265
		require_once self::$PLUGIN_DIR . '/include/addons/posts.php';
266
		require_once self::$PLUGIN_DIR . '/include/addons/pages.php';
267
		require_once self::$PLUGIN_DIR . '/include/addons/util.php';
268
269
		require_once self::$PLUGIN_DIR . '/include/license/class-bd-license.php';
270
		require_once self::$PLUGIN_DIR . '/include/license/class-bd-license-handler.php';
271
		require_once self::$PLUGIN_DIR . '/include/license/class-bd-edd-api-wrapper.php';
272
273
		require_once self::$PLUGIN_DIR . '/include/ui/admin-ui.php';
274
		require_once self::$PLUGIN_DIR . '/include/ui/class-bulk-delete-help-screen.php';
275
	}
276
277
	/**
278
	 * Loads the plugin language files.
279
	 *
280
	 * @since  5.0
281
	 */
282
	public function load_textdomain() {
283
		// Load localization domain
284
		$this->translations = dirname( plugin_basename( self::$PLUGIN_FILE ) ) . '/languages/';
285
		load_plugin_textdomain( 'bulk-delete', false, $this->translations );
286
	}
287
288
	/**
289
	 * Loads the plugin's actions and hooks.
290
	 *
291
	 * @access private
292
	 *
293
	 * @since  5.0
294
	 *
295
	 * @return void
296
	 */
297
	private function setup_actions() {
298
		$this->controller = new BD_Controller();
299
300
		add_action( 'admin_menu', array( $this, 'add_menu' ) );
301
302
		add_filter( 'bd_help_tooltip', 'bd_generate_help_tooltip', 10, 2 );
303
304
		if ( defined( 'BD_DEBUG' ) && BD_DEBUG ) {
305
			add_action( 'bd_after_query', array( $this, 'log_sql_query' ) );
306
		}
307
	}
308
309
	/**
310
	 * Log SQL query used by Bulk Delete.
311
	 *
312
	 * Query is logged only when `BD_DEBUG` is set.
313
	 *
314
	 * @since 5.6
315
	 *
316
	 * @param \WP_Query $wp_query WP Query object.
317
	 */
318
	public function log_sql_query( $wp_query ) {
319
		$query = $wp_query->request;
320
321
		/**
322
		 * Bulk Delete query is getting logged.
323
		 *
324
		 * @since 5.6
325
		 *
326
		 * @param string $query Bulk Delete SQL Query.
327
		 */
328
		do_action( 'bd_log_sql_query', $query );
329
330
		error_log( 'Bulk Delete Query: ' . $query );
331
	}
332
333
	/**
334
	 * Add navigation menu.
335
	 */
336
	public function add_menu() {
337
		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 );
338
339
		$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' ) );
340
		$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' ) );
341
342
		/**
343
		 * Runs just after adding all *delete* menu items to Bulk WP main menu.
344
		 *
345
		 * This action is primarily for adding extra *delete* menu items to the Bulk WP main menu.
346
		 *
347
		 * @since 5.3
348
		 */
349
		do_action( 'bd_after_primary_menus' );
350
351
		/**
352
		 * Runs just before adding non-action menu items to Bulk WP main menu.
353
		 *
354
		 * This action is primarily for adding extra menu items before non-action menu items to the Bulk WP main menu.
355
		 *
356
		 * @since 5.3
357
		 */
358
		do_action( 'bd_before_secondary_menus' );
359
360
		$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' ) );
361
		$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' ) );
362
363
		/**
364
		 * Runs just after adding all menu items to Bulk WP main menu.
365
		 *
366
		 * This action is primarily for adding extra menu items to the Bulk WP main menu.
367
		 *
368
		 * @since 5.3
369
		 */
370
		do_action( 'bd_after_all_menus' );
371
372
		// enqueue JavaScript
373
		add_action( 'admin_print_scripts-' . $this->posts_page, array( $this, 'add_script' ) );
374
		add_action( 'admin_print_scripts-' . $this->pages_page, array( $this, 'add_script' ) );
375
376
		// delete posts page
377
		add_action( "load-{$this->posts_page}", array( $this, 'add_delete_posts_settings_panel' ) );
378
		add_action( "add_meta_boxes_{$this->posts_page}", array( $this, 'add_delete_posts_meta_boxes' ) );
379
380
		// delete pages page
381
		add_action( "load-{$this->pages_page}", array( $this, 'add_delete_pages_settings_panel' ) );
382
		add_action( "add_meta_boxes_{$this->pages_page}", array( $this, 'add_delete_pages_meta_boxes' ) );
383
	}
384
385
	/**
386
	 * Add settings Panel for delete posts page.
387
	 */
388
	public function add_delete_posts_settings_panel() {
389
		/**
390
		 * Add contextual help for admin screens.
391
		 *
392
		 * @since 5.1
393
		 */
394
		do_action( 'bd_add_contextual_help', $this->posts_page );
395
396
		/* Trigger the add_meta_boxes hooks to allow meta boxes to be added */
397
		do_action( 'add_meta_boxes_' . $this->posts_page, null );
398
399
		/* Enqueue WordPress' script for handling the meta boxes */
400
		wp_enqueue_script( 'postbox' );
401
	}
402
403
	/**
404
	 * Register meta boxes for delete posts page.
405
	 */
406
	public function add_delete_posts_meta_boxes() {
407
		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' );
408
		add_meta_box( self::BOX_CATEGORY      , __( 'By Category'          , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_category_box'  , $this->posts_page , 'advanced' );
409
		add_meta_box( self::BOX_TAG           , __( 'By Tag'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_tag_box'       , $this->posts_page , 'advanced' );
410
		add_meta_box( self::BOX_TAX           , __( 'By Custom Taxonomy'   , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_taxonomy_box'  , $this->posts_page , 'advanced' );
411
		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' );
412
		add_meta_box( self::BOX_URL           , __( 'By URL'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_url_box'       , $this->posts_page , 'advanced' );
413
		add_meta_box( self::BOX_POST_REVISION , __( 'By Post Revision'     , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_posts_by_revision_box'         , $this->posts_page , 'advanced' );
414
415
		/**
416
		 * Add meta box in delete posts page
417
		 * This hook can be used for adding additional meta boxes in delete posts page.
418
		 *
419
		 * @since 5.3
420
		 */
421
		do_action( 'bd_add_meta_box_for_posts' );
422
	}
423
424
	/**
425
	 * Setup settings panel for delete pages page.
426
	 *
427
	 * @since 5.0
428
	 */
429
	public function add_delete_pages_settings_panel() {
430
		/**
431
		 * Add contextual help for admin screens.
432
		 *
433
		 * @since 5.1
434
		 */
435
		do_action( 'bd_add_contextual_help', $this->pages_page );
436
437
		/* Trigger the add_meta_boxes hooks to allow meta boxes to be added */
438
		do_action( 'add_meta_boxes_' . $this->pages_page, null );
439
440
		/* Enqueue WordPress' script for handling the meta boxes */
441
		wp_enqueue_script( 'postbox' );
442
	}
443
444
	/**
445
	 * Register meta boxes for delete pages page.
446
	 *
447
	 * @since 5.0
448
	 */
449
	public function add_delete_pages_meta_boxes() {
450
		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' );
451
452
		/**
453
		 * Add meta box in delete pages page
454
		 * This hook can be used for adding additional meta boxes in delete pages page.
455
		 *
456
		 * @since 5.3
457
		 */
458
		do_action( 'bd_add_meta_box_for_pages' );
459
	}
460
461
	/**
462
	 * Enqueue Scripts and Styles.
463
	 */
464
	public function add_script() {
465
		global $wp_scripts;
466
467
		/**
468
		 * Runs just before enqueuing scripts and styles in all Bulk WP admin pages.
469
		 *
470
		 * This action is primarily for registering or deregistering additional scripts or styles.
471
		 *
472
		 * @since 5.5.1
473
		 */
474
		do_action( 'bd_before_admin_enqueue_scripts' );
475
476
		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 );
477
		wp_enqueue_style( 'jquery-ui-timepicker', plugins_url( '/assets/css/jquery-ui-timepicker-addon.min.css', __FILE__ ), array(), '1.5.4' );
478
479
		wp_enqueue_script( 'select2', plugins_url( '/assets/js/select2.min.js', __FILE__ ), array( 'jquery' ), '4.0.0', true );
480
		wp_enqueue_style( 'select2', plugins_url( '/assets/css/select2.min.css', __FILE__ ), array(), '4.0.0' );
481
482
		$postfix = ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) ? '' : '.min';
483
		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 );
484
		wp_enqueue_style( self::CSS_HANDLE, plugins_url( '/assets/css/bulk-delete' . $postfix . '.css', __FILE__ ), array( 'select2' ), self::VERSION );
485
486
		$ui  = $wp_scripts->query( 'jquery-ui-core' );
487
		$url = "//ajax.googleapis.com/ajax/libs/jqueryui/{$ui->ver}/themes/smoothness/jquery-ui.css";
488
		wp_enqueue_style( 'jquery-ui-smoothness', $url, false, $ui->ver );
489
490
		/**
491
		 * Filter JavaScript array.
492
		 *
493
		 * This filter can be used to extend the array that is passed to JavaScript
494
		 *
495
		 * @since 5.4
496
		 */
497
		$translation_array = apply_filters( 'bd_javascript_array', array(
498
				'msg'            => array(),
499
				'validators'     => array(),
500
				'dt_iterators'   => array(),
501
				'pre_action_msg' => array(),
502
				'error_msg'      => array(),
503
				'pro_iterators'  => array(),
504
			) );
505
		wp_localize_script( self::JS_HANDLE, self::JS_VARIABLE, $translation_array );
506
507
		/**
508
		 * Runs just after enqueuing scripts and styles in all Bulk WP admin pages.
509
		 *
510
		 * This action is primarily for registering additional scripts or styles.
511
		 *
512
		 * @since 5.5.1
513
		 */
514
		do_action( 'bd_after_admin_enqueue_scripts' );
515
	}
516
517
	/**
518
	 * Show the delete posts page.
519
	 *
520
	 * @Todo Move this function to Bulk_Delete_Posts class
521
	 */
522
	public function display_posts_page() {
523
?>
524
<div class="wrap">
525
    <h2><?php _e( 'Bulk Delete Posts', 'bulk-delete' );?></h2>
526
    <?php settings_errors(); ?>
527
528
    <form method = "post">
529
<?php
530
		// nonce for bulk delete
531
		wp_nonce_field( 'sm-bulk-delete-posts', 'sm-bulk-delete-posts-nonce' );
532
533
		/* Used to save closed meta boxes and their order */
534
		wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
535
		wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
536
?>
537
    <div id = "poststuff">
538
        <div id="post-body" class="metabox-holder columns-1">
539
540
            <div class="notice notice-warning">
541
                <p><strong><?php _e( 'WARNING: Posts deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p>
542
            </div>
543
544
            <div id="postbox-container-2" class="postbox-container">
545
                <?php do_meta_boxes( '', 'advanced', null ); ?>
546
            </div> <!-- #postbox-container-2 -->
547
548
        </div> <!-- #post-body -->
549
    </div><!-- #poststuff -->
550
    </form>
551
</div><!-- .wrap -->
552
553
<?php
554
		/**
555
		 * Runs just before displaying the footer text in the "Bulk Delete Posts" admin page.
556
		 *
557
		 * This action is primarily for adding extra content in the footer of "Bulk Delete Posts" admin page.
558
		 *
559
		 * @since 5.0
560
		 */
561
		do_action( 'bd_admin_footer_posts_page' );
562
	}
563
564
	/**
565
	 * Display the delete pages page.
566
	 *
567
	 * @Todo Move this function to Bulk_Delete_Pages class
568
	 *
569
	 * @since 5.0
570
	 */
571
	public function display_pages_page() {
572
?>
573
<div class="wrap">
574
    <h2><?php _e( 'Bulk Delete Pages', 'bulk-delete' );?></h2>
575
    <?php settings_errors(); ?>
576
577
    <form method = "post">
578
<?php
579
		// nonce for bulk delete
580
		wp_nonce_field( 'sm-bulk-delete-pages', 'sm-bulk-delete-pages-nonce' );
581
582
		/* Used to save closed meta boxes and their order */
583
		wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
584
		wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
585
?>
586
    <div id = "poststuff">
587
        <div id="post-body" class="metabox-holder columns-1">
588
589
            <div class="notice notice-warning">
590
                <p><strong><?php _e( 'WARNING: Pages deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p>
591
            </div>
592
593
            <div id="postbox-container-2" class="postbox-container">
594
                <?php do_meta_boxes( '', 'advanced', null ); ?>
595
            </div> <!-- #postbox-container-2 -->
596
597
        </div> <!-- #post-body -->
598
    </div><!-- #poststuff -->
599
    </form>
600
</div><!-- .wrap -->
601
602
<?php
603
		/**
604
		 * Runs just before displaying the footer text in the "Bulk Delete Pages" admin page.
605
		 *
606
		 * This action is primarily for adding extra content in the footer of "Bulk Delete Pages" admin page.
607
		 *
608
		 * @since 5.0
609
		 */
610
		do_action( 'bd_admin_footer_pages_page' );
611
	}
612
613
	/**
614
	 * Display the schedule page.
615
	 */
616
	public function display_cron_page() {
617
		if ( ! class_exists( 'WP_List_Table' ) ) {
618
			require_once ABSPATH . WPINC . '/class-wp-list-table.php';
619
		}
620
621
		if ( ! class_exists( 'Cron_List_Table' ) ) {
622
			require_once self::$PLUGIN_DIR . '/include/cron/class-cron-list-table.php';
623
		}
624
625
		// Prepare Table of elements
626
		$cron_list_table = new Cron_List_Table();
627
		$cron_list_table->prepare_items();
628
?>
629
    <div class="wrap">
630
        <h2><?php _e( 'Bulk Delete Schedules', 'bulk-delete' );?></h2>
631
        <?php settings_errors(); ?>
632
<?php
633
		// Table of elements
634
		$cron_list_table->display();
635
		bd_display_available_addon_list();
636
?>
637
    </div>
638
<?php
639
		/**
640
		 * Runs just before displaying the footer text in the "Schedules" admin page.
641
		 *
642
		 * This action is primarily for adding extra content in the footer of "Schedules" admin page.
643
		 *
644
		 * @since 5.0
645
		 */
646
		do_action( 'bd_admin_footer_cron_page' );
647
	}
648
}
649
650
/**
651
 * The main function responsible for returning the one true Bulk_Delete
652
 * Instance to functions everywhere.
653
 *
654
 * Use this function like you would a global variable, except without needing
655
 * to declare the global.
656
 *
657
 * Example: `<?php $bulk_delete = BULK_DELETE(); ?>`
658
 *
659
 * @since 5.0
660
 *
661
 * @return Bulk_Delete The one true Bulk_Delete Instance
662
 */
663
function BULK_DELETE() {
664
	return Bulk_Delete::instance();
665
}
666
667
// Get BULK_DELETE Running
668
BULK_DELETE();
669