Test Setup Failed
Push — 218-fix/metabox-for-delete-pos... ( 47167a...76f661 )
by
unknown
02:56
created

bulk-delete.php (1 issue)

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
use BulkWP\BulkDelete\Core\Base\BasePage;
18
use BulkWP\BulkDelete\Core\Controller;
19
use BulkWP\BulkDelete\Core\Pages\DeletePagesPage;
20
use BulkWP\BulkDelete\Core\Pages\Metabox\DeletePagesByStatusMetabox;
21
use BulkWP\BulkDelete\Core\Posts\DeletePostsPage;
22
use BulkWP\BulkDelete\Core\Posts\Metabox\DeletePostsByCategoryMetabox;
23
use BulkWP\BulkDelete\Core\Posts\Metabox\DeletePostsByStatusMetabox;
24
25
/**
26
 * Copyright 2009  Sudar Muthu  (email : [email protected])
27
 * This program is free software; you can redistribute it and/or modify
28
 * it under the terms of the GNU General Public License, version 2, as
29
 * published by the Free Software Foundation.
30
 *
31
 * This program is distributed in the hope that it will be useful,
32
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34
 * GNU General Public License for more details.
35
 *
36
 * You should have received a copy of the GNU General Public License
37
 * along with this program; if not, write to the Free Software
38
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
39
 */
40
defined( 'ABSPATH' ) || exit; // Exit if accessed directly
41
42
/**
43
 * Main Bulk_Delete class.
44
 *
45
 * Singleton @since 5.0
46
 */
47
final class Bulk_Delete {
48
	/**
49
	 * The one true Bulk_Delete instance.
50
	 *
51
	 * @var Bulk_Delete
52
	 *
53
	 * @since 5.0
54
	 */
55
	private static $instance;
56
57
	/**
58
	 * Path to the main plugin file.
59
	 *
60
	 * @var string
61
	 */
62
	private $plugin_file;
63
64
	/**
65
	 * Path where translations are stored.
66
	 *
67
	 * @var string
68
	 */
69
	private $translations_path;
70
71
	/**
72
	 * Is the plugin is loaded?
73
	 *
74
	 * @since 6.0.0
75
	 *
76
	 * @var bool
77
	 */
78
	private $loaded = false;
79
80
	/**
81
	 * Controller that handles all requests and nonce checks.
82
	 *
83
	 * @var \BulkWP\BulkDelete\Core\Controller
84
	 */
85
	private $controller;
86
87
	/**
88
	 * List of Admin pages.
89
	 *
90
	 * @var BasePage[]
91
	 *
92
	 * @since 6.0.0
93
	 */
94
	private $admin_pages = array();
95
96
	// version
97
	const VERSION                   = '5.6.1';
98
99
	// page slugs
100
	const POSTS_PAGE_SLUG           = 'bulk-delete-posts';
101
	const PAGES_PAGE_SLUG           = 'bulk-delete-pages';
102
	const CRON_PAGE_SLUG            = 'bulk-delete-cron';
103
	const ADDON_PAGE_SLUG           = 'bulk-delete-addon';
104
105
	// JS constants
106
	const JS_HANDLE                 = 'bulk-delete';
107
	const CSS_HANDLE                = 'bulk-delete';
108
109
	// Cron hooks
110
	const CRON_HOOK_CATEGORY        = 'do-bulk-delete-cat';
111
	const CRON_HOOK_POST_STATUS     = 'do-bulk-delete-post-status';
112
	const CRON_HOOK_TAG             = 'do-bulk-delete-tag';
113
	const CRON_HOOK_TAXONOMY        = 'do-bulk-delete-taxonomy';
114
	const CRON_HOOK_POST_TYPE       = 'do-bulk-delete-post-type';
115
	const CRON_HOOK_CUSTOM_FIELD    = 'do-bulk-delete-custom-field';
116
	const CRON_HOOK_TITLE           = 'do-bulk-delete-by-title';
117
	const CRON_HOOK_DUPLICATE_TITLE = 'do-bulk-delete-by-duplicate-title';
118
	const CRON_HOOK_POST_BY_ROLE    = 'do-bulk-delete-posts-by-role';
119
120
	const CRON_HOOK_PAGES_STATUS    = 'do-bulk-delete-pages-by-status';
121
122
	// meta boxes for delete posts
123
	const BOX_POST_STATUS           = 'bd_by_post_status';
124
	const BOX_CATEGORY              = 'bd_by_category';
125
	const BOX_TAG                   = 'bd_by_tag';
126
	const BOX_TAX                   = 'bd_by_tax';
127
	const BOX_POST_TYPE             = 'bd_by_post_type';
128
	const BOX_URL                   = 'bd_by_url';
129
	const BOX_POST_REVISION         = 'bd_by_post_revision';
130
	const BOX_CUSTOM_FIELD          = 'bd_by_custom_field';
131
	const BOX_TITLE                 = 'bd_by_title';
132
	const BOX_DUPLICATE_TITLE       = 'bd_by_duplicate_title';
133
	const BOX_POST_FROM_TRASH       = 'bd_posts_from_trash';
134
	const BOX_POST_BY_ROLE          = 'bd_post_by_user_role';
135
136
	// meta boxes for delete pages
137
	const BOX_PAGE_STATUS           = 'bd_by_page_status';
138
	const BOX_PAGE_FROM_TRASH       = 'bd_pages_from_trash';
139
140
	// Settings constants
141
	const SETTING_OPTION_GROUP      = 'bd_settings';
142
	const SETTING_OPTION_NAME       = 'bd_licenses';
143
	const SETTING_SECTION_ID        = 'bd_license_section';
144
145
	// Transient keys
146
	const LICENSE_CACHE_KEY_PREFIX  = 'bd-license_';
147
148
	const MAX_SELECT2_LIMIT  = 50;
149
150
	// path variables
151
	// Ideally these should be constants, but because of PHP's limitations, these are static variables
152
	public static $PLUGIN_DIR;
153
	public static $PLUGIN_URL;
154
	public static $PLUGIN_FILE;
155
156
	// Instance variables
157
	public $translations;
158
	public $posts_page;
159
	public $pages_page;
160
	public $cron_page;
161
	public $addon_page;
162
	public $settings_page;
163
	public $meta_page;
164
	public $misc_page;
165
	public $display_activate_license_form = false;
166
167
	// Deprecated.
168
	// Will be removed in v6.0
169
	const CRON_HOOK_USER_ROLE = 'do-bulk-delete-users-by-role';
170
	public $users_page;
171
172
	/**
173
	 * Main Bulk_Delete Instance.
174
	 *
175
	 * Insures that only one instance of Bulk_Delete exists in memory at any one
176
	 * time. Also prevents needing to define globals all over the place.
177
	 *
178
	 * @since 5.0
179
	 * @static
180
	 * @staticvar array $instance
181
	 *
182
	 * @see BULK_DELETE()
183
	 *
184
	 * @uses Bulk_Delete::setup_paths() Setup the plugin paths
185
	 * @uses Bulk_Delete::includes() Include the required files
186
	 * @uses Bulk_Delete::load_textdomain() Load text domain for translation
187
	 * @uses Bulk_Delete::setup_actions() Setup the hooks and actions
188
	 *
189
	 * @return Bulk_Delete The one true instance of Bulk_Delete
190
	 */
191 5
	public static function get_instance() {
192 5
		if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Bulk_Delete ) ) {
193 1
			self::$instance = new Bulk_Delete();
194
195 1
			self::$instance->setup_paths();
196 1
			self::$instance->includes();
197
		}
198
199 5
		return self::$instance;
200
	}
201
202
	/**
203
	 * Load the plugin if it is not loaded.
204
	 *
205
	 * This function will be invoked in the `plugins_loaded` hook.
206
	 */
207 1
	public function load() {
208 1
		if ( $this->loaded ) {
209
			return;
210
		}
211
212 1
		add_action( 'init', array( $this, 'on_init' ) );
213
214 1
		$this->load_dependencies();
215 1
		$this->setup_actions();
216
217 1
		$this->loaded = true;
218
219
		/**
220
		 * Bulk Delete plugin loaded.
221
		 *
222
		 * @since 6.0.0
223
		 */
224 1
		do_action( 'bd_loaded' );
225 1
	}
226
227
	/**
228
	 * Throw error on object clone.
229
	 *
230
	 * The whole idea of the singleton design pattern is that there is a single
231
	 * object therefore, we don't want the object to be cloned.
232
	 *
233
	 * @since  5.0
234
	 * @access protected
235
	 *
236
	 * @return void
237
	 */
238 1
	public function __clone() {
239
		// Cloning instances of the class is forbidden
240 1
		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'bulk-delete' ), '5.0' );
241 1
	}
242
243
	/**
244
	 * Disable unserializing of the class.
245
	 *
246
	 * @since  5.0
247
	 * @access protected
248
	 *
249
	 * @return void
250
	 */
251 1
	public function __wakeup() {
252
		// Unserializing instances of the class is forbidden
253 1
		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'bulk-delete' ), '5.0' );
254 1
	}
255
256
	/**
257
	 * Setup plugin constants.
258
	 *
259
	 * @access private
260
	 *
261
	 * @since  5.0
262
	 *
263
	 * @return void
264
	 */
265 1
	private function setup_paths() {
266
		// Plugin Folder Path
267 1
		self::$PLUGIN_DIR = plugin_dir_path( __FILE__ );
268
269
		// Plugin Folder URL
270 1
		self::$PLUGIN_URL = plugin_dir_url( __FILE__ );
271
272
		// Plugin Root File
273 1
		self::$PLUGIN_FILE = __FILE__;
274 1
	}
275
276
	/**
277
	 * Include required files.
278
	 *
279
	 * // TODO: Replace includes with autoloader.
280
	 *
281
	 * @access private
282
	 *
283
	 * @since  5.0
284
	 *
285
	 * @return void
286
	 */
287 1
	private function includes() {
288 1
		require_once self::$PLUGIN_DIR . '/include/Core/Base/BasePage.php';
289 1
		require_once self::$PLUGIN_DIR . '/include/Core/Base/MetaboxPage.php';
290
291 1
		require_once self::$PLUGIN_DIR . '/include/Core/Pages/DeletePagesPage.php';
292 1
		require_once self::$PLUGIN_DIR . '/include/Core/Posts/DeletePostsPage.php';
293
294 1
		require_once self::$PLUGIN_DIR . '/include/Core/Base/BaseMetabox.php';
295 1
		require_once self::$PLUGIN_DIR . '/include/Core/Pages/PagesMetabox.php';
296 1
		require_once self::$PLUGIN_DIR . '/include/Core/Pages/Metabox/DeletePagesByStatusMetabox.php';
297
298 1
		require_once self::$PLUGIN_DIR . '/include/Core/Posts/PostsMetabox.php';
299 1
		require_once self::$PLUGIN_DIR . '/include/Core/Posts/Metabox/DeletePostsByStatusMetabox.php';
300 1
		require_once self::$PLUGIN_DIR . '/include/Core/Posts/Metabox/DeletePostsByCategoryMetabox.php';
301
302 1
		require_once self::$PLUGIN_DIR . '/include/base/class-bd-meta-box-module.php';
303 1
		require_once self::$PLUGIN_DIR . '/include/base/users/class-bd-user-meta-box-module.php';
304 1
		require_once self::$PLUGIN_DIR . '/include/base/class-bd-base-page.php';
305 1
		require_once self::$PLUGIN_DIR . '/include/base/class-bd-page.php';
306
307 1
		require_once self::$PLUGIN_DIR . '/include/Core/Controller.php';
308
309 1
		require_once self::$PLUGIN_DIR . '/include/ui/form.php';
310
311 1
		require_once self::$PLUGIN_DIR . '/include/posts/class-bulk-delete-posts.php';
312
//		require_once self::$PLUGIN_DIR . '/include/pages/class-bulk-delete-pages.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
313
314 1
		require_once self::$PLUGIN_DIR . '/include/users/class-bd-users-page.php';
315 1
		require_once self::$PLUGIN_DIR . '/include/users/modules/class-bulk-delete-users-by-user-role.php';
316 1
		require_once self::$PLUGIN_DIR . '/include/users/modules/class-bulk-delete-users-by-user-meta.php';
317
318 1
		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-meta.php';
319 1
		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-post-meta.php';
320 1
		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-comment-meta.php';
321 1
		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-user-meta.php';
322
323 1
		require_once self::$PLUGIN_DIR . '/include/misc/class-bulk-delete-misc.php';
324 1
		require_once self::$PLUGIN_DIR . '/include/misc/class-bulk-delete-jetpack-contact-form-messages.php';
325
326 1
		require_once self::$PLUGIN_DIR . '/include/settings/class-bd-settings-page.php';
327 1
		require_once self::$PLUGIN_DIR . '/include/settings/setting-helpers.php';
328 1
		require_once self::$PLUGIN_DIR . '/include/settings/class-bd-settings.php';
329
330 1
		require_once self::$PLUGIN_DIR . '/include/system-info/class-bd-system-info-page.php';
331
332 1
		require_once self::$PLUGIN_DIR . '/include/util/class-bd-util.php';
333 1
		require_once self::$PLUGIN_DIR . '/include/util/query.php';
334
335 1
		require_once self::$PLUGIN_DIR . '/include/compatibility/simple-login-log.php';
336 1
		require_once self::$PLUGIN_DIR . '/include/compatibility/the-event-calendar.php';
337 1
		require_once self::$PLUGIN_DIR . '/include/compatibility/woocommerce.php';
338 1
		require_once self::$PLUGIN_DIR . '/include/compatibility/advanced-custom-fields-pro.php';
339
340 1
		require_once self::$PLUGIN_DIR . '/include/deprecated/class-bulk-delete-users.php';
341 1
		require_once self::$PLUGIN_DIR . '/include/deprecated/deprecated.php';
342
343 1
		require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-addon.php';
344 1
		require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-base-addon.php';
345 1
		require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-scheduler-addon.php';
346
347 1
		require_once self::$PLUGIN_DIR . '/include/addons/addon-list.php';
348 1
		require_once self::$PLUGIN_DIR . '/include/addons/posts.php';
349 1
		require_once self::$PLUGIN_DIR . '/include/addons/pages.php';
350 1
		require_once self::$PLUGIN_DIR . '/include/addons/util.php';
351
352 1
		require_once self::$PLUGIN_DIR . '/include/license/class-bd-license.php';
353 1
		require_once self::$PLUGIN_DIR . '/include/license/class-bd-license-handler.php';
354 1
		require_once self::$PLUGIN_DIR . '/include/license/class-bd-edd-api-wrapper.php';
355
356 1
		require_once self::$PLUGIN_DIR . '/include/ui/admin-ui.php';
357 1
		require_once self::$PLUGIN_DIR . '/include/ui/class-bulk-delete-help-screen.php';
358 1
	}
359
360
	/**
361
	 * Triggered when the `init` hook is fired.
362
	 *
363
	 * @since 6.0.0
364
	 */
365 1
	public function on_init() {
366 1
		$this->load_textdomain();
367 1
	}
368
369
	/**
370
	 * Loads the plugin language files.
371
	 *
372
	 * @since  5.0
373
	 */
374 1
	private function load_textdomain() {
375 1
		load_plugin_textdomain( 'bulk-delete', false, $this->get_translations_path() );
376 1
	}
377
378
	/**
379
	 * Load all dependencies.
380
	 *
381
	 * @since 6.0.0
382
	 */
383 1
	private function load_dependencies() {
384 1
		$this->controller = new Controller();
385 1
	}
386
387
	/**
388
	 * Loads the plugin's actions and hooks.
389
	 *
390
	 * @access private
391
	 *
392
	 * @since  5.0
393
	 *
394
	 * @return void
395
	 */
396 1
	private function setup_actions() {
397 1
		add_action( 'admin_menu', array( $this, 'on_admin_menu' ) );
398
399
		/**
400
		 * This is Ajax hook, It's runs when user search categories or tags on bulk-delete-posts page.
401
		 *
402
		 * @since 6.0.0
403
		 */
404 1
		add_action( 'wp_ajax_bd_load_taxonomy_term', array( $this, 'load_taxonomy_term' ) );
405
406 1
		add_filter( 'bd_help_tooltip', 'bd_generate_help_tooltip', 10, 2 );
407
408 1
		add_filter( 'plugin_action_links', array( $this, 'filter_plugin_action_links' ), 10, 2 );
409
410 1
		if ( defined( 'BD_DEBUG' ) && BD_DEBUG ) {
411
			add_action( 'bd_after_query', array( $this, 'log_sql_query' ) );
412
		}
413 1
	}
414
415
	/**
416
	 * Adds the settings link in the Plugin page.
417
	 *
418
	 * Based on http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/.
419
	 *
420
	 * @staticvar string $this_plugin
421
	 *
422
	 * @param array  $action_links Action Links.
423
	 * @param string $file         Plugin file name.
424
	 *
425
	 * @return array Modified links.
426
	 */
427
	public function filter_plugin_action_links( $action_links, $file ) {
428
		static $this_plugin;
429
430
		if ( ! $this_plugin ) {
431
			$this_plugin = plugin_basename( $this->get_plugin_file() );
432
		}
433
434
		if ( $file == $this_plugin ) {
435
			/**
436
			 * Filter plugin action links added by Bulk Move.
437
			 *
438
			 * @since 6.0.0
439
			 *
440
			 * @param array Plugin Links.
441
			 */
442
			$bm_action_links = apply_filters( 'bd_plugin_action_links', array() );
443
444
			if ( ! empty( $bm_action_links ) ) {
445
				$action_links = array_merge( $bm_action_links, $action_links );
446
			}
447
		}
448
449
		return $action_links;
450
	}
451
452
	/**
453
	 * Log SQL query used by Bulk Delete.
454
	 *
455
	 * Query is logged only when `BD_DEBUG` is set.
456
	 *
457
	 * @since 5.6
458
	 *
459
	 * @param \WP_Query $wp_query WP Query object.
460
	 */
461
	public function log_sql_query( $wp_query ) {
462
		$query = $wp_query->request;
463
464
		/**
465
		 * Bulk Delete query is getting logged.
466
		 *
467
		 * @since 5.6
468
		 *
469
		 * @param string $query Bulk Delete SQL Query.
470
		 */
471
		do_action( 'bd_log_sql_query', $query );
472
473
		error_log( 'Bulk Delete Query: ' . $query );
474
	}
475
476
	/**
477
	 * Triggered when the `admin_menu` hook is fired.
478
	 *
479
	 * Register all admin pages.
480
	 *
481
	 * @since 6.0.0
482
	 */
483
	public function on_admin_menu() {
484
		foreach ( $this->get_admin_pages() as $page ) {
485
			$page->register();
486
		}
487
488
		$this->load_legacy_menu();
489
	}
490
491
	/**
492
	 * Get the list of registered admin pages.
493
	 *
494
	 * @since 6.0.0
495
	 *
496
	 * @return BasePage[] List of Admin pages.
497
	 */
498
	private function get_admin_pages() {
499
		if ( empty( $this->admin_pages ) ) {
500
			$posts_page = $this->get_delete_posts_admin_page();
501
			$pages_page = $this->get_delete_pages_admin_page();
502
503
			$this->admin_pages[ $posts_page->get_page_slug() ] = $posts_page;
504
			$this->admin_pages[ $pages_page->get_page_slug() ] = $pages_page;
505
		}
506
507
		/**
508
		 * List of admin pages.
509
		 *
510
		 * @since 6.0.0
511
		 *
512
		 * @param BasePage[] List of Admin pages.
513
		 */
514
		return apply_filters( 'bd_admin_pages', $this->admin_pages );
515
	}
516
517
	/**
518
	 * Get Bulk Delete Posts admin page.
519
	 *
520
	 * @return \BulkWP\BulkDelete\Core\Posts\DeletePostsPage
521
	 */
522
	private function get_delete_posts_admin_page() {
523
		$posts_page = new DeletePostsPage( $this->get_plugin_file() );
524
525
		$posts_page->add_metabox( new DeletePostsByStatusMetabox() );
526
		$posts_page->add_metabox( new DeletePostsByCategoryMetabox() );
527
528
		return $posts_page;
529
	}
530
531
	/**
532
	 * Get Bulk Delete Pages admin page.
533
	 *
534
	 * @since 6.0.0
535
	 *
536
	 * @return DeletePagesPage Bulk Move Post admin page.
537
	 */
538
	private function get_delete_pages_admin_page() {
539
		$pages_page = new DeletePagesPage( $this->get_plugin_file() );
540
541
		$pages_page->add_metabox( new DeletePagesByStatusMetabox() );
542
543
		return $pages_page;
544
	}
545
546
	/**
547
	 * Add navigation menu.
548
	 */
549
	public function load_legacy_menu() {
550
		$this->posts_page = add_submenu_page( self::POSTS_PAGE_SLUG, __( 'Bulk Delete Posts - Old', 'bulk-delete' ), __( 'Bulk Delete Posts - Old', 'bulk-delete' ), 'delete_posts', 'bulk-delete-posts-old', array( $this, 'display_posts_page' ) );
551
552
		/**
553
		 * Runs just after adding all *delete* menu items to Bulk WP main menu.
554
		 *
555
		 * This action is primarily for adding extra *delete* menu items to the Bulk WP main menu.
556
		 *
557
		 * @since 5.3
558
		 */
559
		do_action( 'bd_after_primary_menus' );
560
561
		/**
562
		 * Runs just before adding non-action menu items to Bulk WP main menu.
563
		 *
564
		 * This action is primarily for adding extra menu items before non-action menu items to the Bulk WP main menu.
565
		 *
566
		 * @since 5.3
567
		 */
568
		do_action( 'bd_before_secondary_menus' );
569
570
		$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' ) );
571
		$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' ) );
572
573
		/**
574
		 * Runs just after adding all menu items to Bulk WP main menu.
575
		 *
576
		 * This action is primarily for adding extra menu items to the Bulk WP main menu.
577
		 *
578
		 * @since 5.3
579
		 */
580
		do_action( 'bd_after_all_menus' );
581
582
		$admin_pages = $this->get_admin_pages();
583
		$pages_page  = $admin_pages['bulk-delete-pages'];
584
585
		// enqueue JavaScript
586
		add_action( 'admin_print_scripts-' . $this->posts_page, array( $pages_page, 'enqueue_assets' ) );
587
588
		// delete posts page
589
		add_action( "load-{$this->posts_page}", array( $this, 'add_delete_posts_settings_panel' ) );
590
		add_action( "add_meta_boxes_{$this->posts_page}", array( $this, 'add_delete_posts_meta_boxes' ) );
591
	}
592
593
	/**
594
	 * Add settings Panel for delete posts page.
595
	 */
596
	public function add_delete_posts_settings_panel() {
597
		/**
598
		 * Add contextual help for admin screens.
599
		 *
600
		 * @since 5.1
601
		 */
602
		do_action( 'bd_add_contextual_help', $this->posts_page );
603
604
		/* Trigger the add_meta_boxes hooks to allow meta boxes to be added */
605
		do_action( 'add_meta_boxes_' . $this->posts_page, null );
606
607
		/* Enqueue WordPress' script for handling the meta boxes */
608
		wp_enqueue_script( 'postbox' );
609
	}
610
611
	/**
612
	 * Ajax call back function for getting taxonomies to load select2 options.
613
	 *
614
	 * @since 6.0.0
615
	 */
616
	public function load_taxonomy_term(){
617
		$response = array();
618
619
		$taxonomy = sanitize_text_field( $_GET['taxonomy'] );
620
621
		$terms = get_terms( array(
622
			'taxonomy'   => $taxonomy,
623
			'hide_empty' => false,
624
			'search'     => sanitize_text_field($_GET['q']),
625
		) );
626
627
		if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
628
			foreach ( $terms as $term ) {
629
				$response[] = array( absint($term->term_id), $term->name . ' (' . $term->count . __( ' Posts', 'bulk-delete' ) . ')' );
630
			}
631
		}
632
633
		echo json_encode( $response );
634
		die;
635
	}
636
637
	/**
638
	 * Register meta boxes for delete posts page.
639
	 */
640
	public function add_delete_posts_meta_boxes() {
641
		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' );
642
		add_meta_box( self::BOX_CATEGORY      , __( 'By Category'          , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_category_box'  , $this->posts_page , 'advanced' );
643
		add_meta_box( self::BOX_TAG           , __( 'By Tag'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_tag_box'       , $this->posts_page , 'advanced' );
644
		add_meta_box( self::BOX_TAX           , __( 'By Custom Taxonomy'   , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_taxonomy_box'  , $this->posts_page , 'advanced' );
645
		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' );
646
		add_meta_box( self::BOX_URL           , __( 'By URL'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_url_box'       , $this->posts_page , 'advanced' );
647
		add_meta_box( self::BOX_POST_REVISION , __( 'By Post Revision'     , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_posts_by_revision_box'         , $this->posts_page , 'advanced' );
648
649
		/**
650
		 * Add meta box in delete posts page
651
		 * This hook can be used for adding additional meta boxes in delete posts page.
652
		 *
653
		 * @since 5.3
654
		 */
655
		do_action( 'bd_add_meta_box_for_posts' );
656
	}
657
658
	/**
659
	 * Enqueue Scripts and Styles.
660
	 */
661
	public function add_script() {
662
		// TODO: Remove this function.
663
664
		$admin_pages = $this->get_admin_pages();
665
		$pages_page  = $admin_pages['bulk-delete-pages'];
666
		$pages_page->enqueue_assets();
667
	}
668
669
	/**
670
	 * Show the delete posts page.
671
	 *
672
	 * @Todo Move this function to Bulk_Delete_Posts class
673
	 */
674
	public function display_posts_page() {
675
?>
676
<div class="wrap">
677
    <h2><?php _e( 'Bulk Delete Posts', 'bulk-delete' );?></h2>
678
    <?php settings_errors(); ?>
679
680
    <form method = "post">
681
<?php
682
		// nonce for bulk delete
683
		wp_nonce_field( 'sm-bulk-delete-posts', 'sm-bulk-delete-posts-nonce' );
684
685
		/* Used to save closed meta boxes and their order */
686
		wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
687
		wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
688
?>
689
    <div id = "poststuff">
690
        <div id="post-body" class="metabox-holder columns-1">
691
692
            <div class="notice notice-warning">
693
                <p><strong><?php _e( 'WARNING: Posts deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p>
694
            </div>
695
696
            <div id="postbox-container-2" class="postbox-container">
697
                <?php do_meta_boxes( '', 'advanced', null ); ?>
698
            </div> <!-- #postbox-container-2 -->
699
700
        </div> <!-- #post-body -->
701
    </div><!-- #poststuff -->
702
    </form>
703
</div><!-- .wrap -->
704
705
<?php
706
		/**
707
		 * Runs just before displaying the footer text in the "Bulk Delete Posts" admin page.
708
		 *
709
		 * This action is primarily for adding extra content in the footer of "Bulk Delete Posts" admin page.
710
		 *
711
		 * @since 5.0
712
		 */
713
		do_action( 'bd_admin_footer_posts_page' );
714
	}
715
716
	/**
717
	 * Display the schedule page.
718
	 */
719
	public function display_cron_page() {
720
		if ( ! class_exists( 'WP_List_Table' ) ) {
721
			require_once ABSPATH . WPINC . '/class-wp-list-table.php';
722
		}
723
724
		if ( ! class_exists( 'Cron_List_Table' ) ) {
725
			require_once self::$PLUGIN_DIR . '/include/cron/class-cron-list-table.php';
726
		}
727
728
		// Prepare Table of elements
729
		$cron_list_table = new Cron_List_Table();
730
		$cron_list_table->prepare_items();
731
?>
732
    <div class="wrap">
733
        <h2><?php _e( 'Bulk Delete Schedules', 'bulk-delete' );?></h2>
734
        <?php settings_errors(); ?>
735
<?php
736
		// Table of elements
737
		$cron_list_table->display();
738
		bd_display_available_addon_list();
739
?>
740
    </div>
741
<?php
742
		/**
743
		 * Runs just before displaying the footer text in the "Schedules" admin page.
744
		 *
745
		 * This action is primarily for adding extra content in the footer of "Schedules" admin page.
746
		 *
747
		 * @since 5.0
748
		 */
749
		do_action( 'bd_admin_footer_cron_page' );
750
	}
751
752
	/**
753
	 * Get path to main plugin file.
754
	 *
755
	 * @return string Plugin file.
756
	 */
757 1
	public function get_plugin_file() {
758 1
		return $this->plugin_file;
759
	}
760
761
	/**
762
	 * Set path to main plugin file.
763
	 *
764
	 * @param string $plugin_file Path to main plugin file.
765
	 */
766 1
	public function set_plugin_file( $plugin_file ) {
767 1
		$this->plugin_file       = $plugin_file;
768 1
		$this->translations_path = dirname( plugin_basename( $this->get_plugin_file() ) ) . '/languages/';
769 1
	}
770
771
	/**
772
	 * Get path to translations.
773
	 *
774
	 * @return string Translations path.
775
	 */
776 1
	public function get_translations_path() {
777 1
		return $this->translations_path;
778
	}
779
}
780
781
/**
782
 * The main function responsible for returning the one true Bulk_Delete
783
 * Instance to functions everywhere.
784
 *
785
 * Use this function like you would a global variable, except without needing
786
 * to declare the global.
787
 *
788
 * Example: `<?php $bulk_delete = BULK_DELETE(); ?>`
789
 *
790
 * @since 5.0
791
 *
792
 * @return Bulk_Delete The one true Bulk_Delete Instance
793
 */
794
function BULK_DELETE() {
795 1
	return Bulk_Delete::get_instance();
796
}
797
798
/**
799
 * Load Bulk Delete plugin.
800
 *
801
 * @since 6.0.0
802
 */
803
function load_bulk_delete() {
804 1
	$bulk_delete = BULK_DELETE();
805 1
	$bulk_delete->set_plugin_file( __FILE__ );
806
807 1
	add_action( 'plugins_loaded', array( $bulk_delete, 'load' ), 101 );
808 1
}
809
810
load_bulk_delete();
811