Passed
Push — 192-feature/delete-posts-by-UR... ( 1476b6...c42657 )
by Rajan
07:17 queued 03:37
created

bulk-delete.php (6 issues)

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

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

379
		load_plugin_textdomain( 'bulk-delete', /** @scrutinizer ignore-type */ false, $this->get_translations_path() );
Loading history...
380
	}
381
382
	/**
383
	 * Load all dependencies.
384
	 *
385
	 * @since 6.0.0
386
	 */
387
	private function load_dependencies() {
388
		$this->controller = new Controller();
389
	}
390
391
	/**
392
	 * Loads the plugin's actions and hooks.
393
	 *
394
	 * @access private
395
	 *
396
	 * @since  5.0
397
	 *
398
	 * @return void
399
	 */
400
	private function setup_actions() {
401
		add_action( 'admin_menu', array( $this, 'on_admin_menu' ) );
402
403
		/**
404
		 * This is Ajax hook, It's runs when user search categories or tags on bulk-delete-posts page.
405
		 *
406
		 * @since 6.0.0
407
		 */
408
		add_action( 'wp_ajax_bd_load_taxonomy_term', array( $this, 'load_taxonomy_term' ) );
409
410
		add_filter( 'bd_help_tooltip', 'bd_generate_help_tooltip', 10, 2 );
411
412
		add_filter( 'plugin_action_links', array( $this, 'filter_plugin_action_links' ), 10, 2 );
413
414
		if ( defined( 'BD_DEBUG' ) && BD_DEBUG ) {
0 ignored issues
show
The constant BD_DEBUG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
415
			add_action( 'bd_after_query', array( $this, 'log_sql_query' ) );
416
		}
417
	}
418
419
	/**
420
	 * Adds the settings link in the Plugin page.
421
	 *
422
	 * Based on http://striderweb.com/nerdaphernalia/2008/06/wp-use-action-links/.
423
	 *
424
	 * @staticvar string $this_plugin
425
	 *
426
	 * @param array  $action_links Action Links.
427
	 * @param string $file         Plugin file name.
428
	 *
429
	 * @return array Modified links.
430
	 */
431
	public function filter_plugin_action_links( $action_links, $file ) {
432
		static $this_plugin;
433
434
		if ( ! $this_plugin ) {
435
			$this_plugin = plugin_basename( $this->get_plugin_file() );
436
		}
437
438
		if ( $file == $this_plugin ) {
439
			/**
440
			 * Filter plugin action links added by Bulk Move.
441
			 *
442
			 * @since 6.0.0
443
			 *
444
			 * @param array Plugin Links.
445
			 */
446
			$bm_action_links = apply_filters( 'bd_plugin_action_links', array() );
447
448
			if ( ! empty( $bm_action_links ) ) {
449
				$action_links = array_merge( $bm_action_links, $action_links );
450
			}
451
		}
452
453
		return $action_links;
454
	}
455
456
	/**
457
	 * Log SQL query used by Bulk Delete.
458
	 *
459
	 * Query is logged only when `BD_DEBUG` is set.
460
	 *
461
	 * @since 5.6
462
	 *
463
	 * @param \WP_Query $wp_query WP Query object.
464
	 */
465
	public function log_sql_query( $wp_query ) {
466
		$query = $wp_query->request;
467
468
		/**
469
		 * Bulk Delete query is getting logged.
470
		 *
471
		 * @since 5.6
472
		 *
473
		 * @param string $query Bulk Delete SQL Query.
474
		 */
475
		do_action( 'bd_log_sql_query', $query );
476
477
		error_log( 'Bulk Delete Query: ' . $query );
478
	}
479
480
	/**
481
	 * Triggered when the `admin_menu` hook is fired.
482
	 *
483
	 * Register all admin pages.
484
	 *
485
	 * @since 6.0.0
486
	 */
487
	public function on_admin_menu() {
488
		foreach ( $this->get_admin_pages() as $page ) {
489
			$page->register();
490
		}
491
492
		$this->load_legacy_menu();
493
	}
494
495
	/**
496
	 * Get the list of registered admin pages.
497
	 *
498
	 * @since 6.0.0
499
	 *
500
	 * @return BasePage[] List of Admin pages.
501
	 */
502
	private function get_admin_pages() {
503
		if ( empty( $this->admin_pages ) ) {
504
			$posts_page = $this->get_delete_posts_admin_page();
505
			$pages_page = $this->get_delete_pages_admin_page();
506
507
			$this->admin_pages[ $posts_page->get_page_slug() ] = $posts_page;
508
			$this->admin_pages[ $pages_page->get_page_slug() ] = $pages_page;
509
		}
510
511
		/**
512
		 * List of admin pages.
513
		 *
514
		 * @since 6.0.0
515
		 *
516
		 * @param BasePage[] List of Admin pages.
517
		 */
518
		return apply_filters( 'bd_admin_pages', $this->admin_pages );
519
	}
520
521
	/**
522
	 * Get Bulk Delete Posts admin page.
523
	 *
524
	 * @return \BulkWP\BulkDelete\Core\Posts\DeletePostsPage
525
	 */
526
	private function get_delete_posts_admin_page() {
527
		$posts_page = new DeletePostsPage( $this->get_plugin_file() );
528
529
		$posts_page->add_metabox( new DeletePostsByStatusMetabox() );
530
		$posts_page->add_metabox( new DeletePostsByCategoryMetabox() );
531
		$posts_page->add_metabox( new DeletePostsByTagMetabox() );
532
		$posts_page->add_metabox( new DeletePostsByURLMetabox() );
533
534
		return $posts_page;
535
	}
536
537
	/**
538
	 * Get Bulk Delete Pages admin page.
539
	 *
540
	 * @since 6.0.0
541
	 *
542
	 * @return DeletePagesPage Bulk Move Post admin page.
543
	 */
544
	private function get_delete_pages_admin_page() {
545
		$pages_page = new DeletePagesPage( $this->get_plugin_file() );
546
547
		$pages_page->add_metabox( new DeletePagesByStatusMetabox() );
548
549
		return $pages_page;
550
	}
551
552
	/**
553
	 * Add navigation menu.
554
	 */
555
	public function load_legacy_menu() {
556
		$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' ) );
557
558
		/**
559
		 * Runs just after adding all *delete* menu items to Bulk WP main menu.
560
		 *
561
		 * This action is primarily for adding extra *delete* menu items to the Bulk WP main menu.
562
		 *
563
		 * @since 5.3
564
		 */
565
		do_action( 'bd_after_primary_menus' );
566
567
		/**
568
		 * Runs just before adding non-action menu items to Bulk WP main menu.
569
		 *
570
		 * This action is primarily for adding extra menu items before non-action menu items to the Bulk WP main menu.
571
		 *
572
		 * @since 5.3
573
		 */
574
		do_action( 'bd_before_secondary_menus' );
575
576
		$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' ) );
577
		$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' ) );
578
579
		/**
580
		 * Runs just after adding all menu items to Bulk WP main menu.
581
		 *
582
		 * This action is primarily for adding extra menu items to the Bulk WP main menu.
583
		 *
584
		 * @since 5.3
585
		 */
586
		do_action( 'bd_after_all_menus' );
587
588
		$admin_pages = $this->get_admin_pages();
589
		$pages_page  = $admin_pages['bulk-delete-pages'];
590
591
		// enqueue JavaScript
592
		add_action( 'admin_print_scripts-' . $this->posts_page, array( $pages_page, 'enqueue_assets' ) );
0 ignored issues
show
Are you sure $this->posts_page of type false|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

592
		add_action( 'admin_print_scripts-' . /** @scrutinizer ignore-type */ $this->posts_page, array( $pages_page, 'enqueue_assets' ) );
Loading history...
593
594
		// delete posts page
595
		add_action( "load-{$this->posts_page}", array( $this, 'add_delete_posts_settings_panel' ) );
596
		add_action( "add_meta_boxes_{$this->posts_page}", array( $this, 'add_delete_posts_meta_boxes' ) );
597
	}
598
599
	/**
600
	 * Add settings Panel for delete posts page.
601
	 */
602
	public function add_delete_posts_settings_panel() {
603
		/**
604
		 * Add contextual help for admin screens.
605
		 *
606
		 * @since 5.1
607
		 */
608
		do_action( 'bd_add_contextual_help', $this->posts_page );
609
610
		/* Trigger the add_meta_boxes hooks to allow meta boxes to be added */
611
		do_action( 'add_meta_boxes_' . $this->posts_page, null );
612
613
		/* Enqueue WordPress' script for handling the meta boxes */
614
		wp_enqueue_script( 'postbox' );
615
	}
616
617
	/**
618
	 * Ajax call back function for getting taxonomies to load select2 options.
619
	 *
620
	 * @since 6.0.0
621
	 */
622
	public function load_taxonomy_term(){
623
		$response = array();
624
625
		$taxonomy = sanitize_text_field( $_GET['taxonomy'] );
626
627
		$terms = get_terms( array(
628
			'taxonomy'   => $taxonomy,
629
			'hide_empty' => false,
630
			'search'     => sanitize_text_field($_GET['q']),
631
		) );
632
633
		if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
634
			foreach ( $terms as $term ) {
635
				$response[] = array( absint($term->term_id), $term->name . ' (' . $term->count . __( ' Posts', 'bulk-delete' ) . ')' );
636
			}
637
		}
638
639
		echo json_encode( $response );
640
		die;
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
641
	}
642
643
	/**
644
	 * Register meta boxes for delete posts page.
645
	 */
646
	public function add_delete_posts_meta_boxes() {
647
		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' );
648
		add_meta_box( self::BOX_CATEGORY      , __( 'By Category'          , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_category_box'  , $this->posts_page , 'advanced' );
649
		add_meta_box( self::BOX_TAG           , __( 'By Tag'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_tag_box'       , $this->posts_page , 'advanced' );
650
		add_meta_box( self::BOX_TAX           , __( 'By Custom Taxonomy'   , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_taxonomy_box'  , $this->posts_page , 'advanced' );
651
		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' );
652
		add_meta_box( self::BOX_URL           , __( 'By URL'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_url_box'       , $this->posts_page , 'advanced' );
653
		add_meta_box( self::BOX_POST_REVISION , __( 'By Post Revision'     , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_posts_by_revision_box'         , $this->posts_page , 'advanced' );
654
655
		/**
656
		 * Add meta box in delete posts page
657
		 * This hook can be used for adding additional meta boxes in delete posts page.
658
		 *
659
		 * @since 5.3
660
		 */
661
		do_action( 'bd_add_meta_box_for_posts' );
662
	}
663
664
	/**
665
	 * Enqueue Scripts and Styles.
666
	 */
667
	public function add_script() {
668
		// TODO: Remove this function.
669
670
		$admin_pages = $this->get_admin_pages();
671
		$pages_page  = $admin_pages['bulk-delete-pages'];
672
		$pages_page->enqueue_assets();
0 ignored issues
show
The method enqueue_assets() does not exist on BulkWP\BulkDelete\Core\Base\BasePage. Since it exists in all sub-types, consider adding an abstract or default implementation to BulkWP\BulkDelete\Core\Base\BasePage. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

672
		$pages_page->/** @scrutinizer ignore-call */ 
673
               enqueue_assets();
Loading history...
673
	}
674
675
	/**
676
	 * Show the delete posts page.
677
	 *
678
	 * @Todo Move this function to Bulk_Delete_Posts class
679
	 */
680
	public function display_posts_page() {
681
?>
682
<div class="wrap">
683
    <h2><?php _e( 'Bulk Delete Posts', 'bulk-delete' );?></h2>
684
    <?php settings_errors(); ?>
685
686
    <form method = "post">
687
<?php
688
		// nonce for bulk delete
689
		wp_nonce_field( 'sm-bulk-delete-posts', 'sm-bulk-delete-posts-nonce' );
690
691
		/* Used to save closed meta boxes and their order */
692
		wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
693
		wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
694
?>
695
    <div id = "poststuff">
696
        <div id="post-body" class="metabox-holder columns-1">
697
698
            <div class="notice notice-warning">
699
                <p><strong><?php _e( 'WARNING: Posts deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p>
700
            </div>
701
702
            <div id="postbox-container-2" class="postbox-container">
703
                <?php do_meta_boxes( '', 'advanced', null ); ?>
704
            </div> <!-- #postbox-container-2 -->
705
706
        </div> <!-- #post-body -->
707
    </div><!-- #poststuff -->
708
    </form>
709
</div><!-- .wrap -->
710
711
<?php
712
		/**
713
		 * Runs just before displaying the footer text in the "Bulk Delete Posts" admin page.
714
		 *
715
		 * This action is primarily for adding extra content in the footer of "Bulk Delete Posts" admin page.
716
		 *
717
		 * @since 5.0
718
		 */
719
		do_action( 'bd_admin_footer_posts_page' );
720
	}
721
722
	/**
723
	 * Display the schedule page.
724
	 */
725
	public function display_cron_page() {
726
		if ( ! class_exists( 'WP_List_Table' ) ) {
727
			require_once ABSPATH . WPINC . '/class-wp-list-table.php';
728
		}
729
730
		if ( ! class_exists( 'Cron_List_Table' ) ) {
731
			require_once self::$PLUGIN_DIR . '/include/cron/class-cron-list-table.php';
732
		}
733
734
		// Prepare Table of elements
735
		$cron_list_table = new Cron_List_Table();
736
		$cron_list_table->prepare_items();
737
?>
738
    <div class="wrap">
739
        <h2><?php _e( 'Bulk Delete Schedules', 'bulk-delete' );?></h2>
740
        <?php settings_errors(); ?>
741
<?php
742
		// Table of elements
743
		$cron_list_table->display();
744
		bd_display_available_addon_list();
745
?>
746
    </div>
747
<?php
748
		/**
749
		 * Runs just before displaying the footer text in the "Schedules" admin page.
750
		 *
751
		 * This action is primarily for adding extra content in the footer of "Schedules" admin page.
752
		 *
753
		 * @since 5.0
754
		 */
755
		do_action( 'bd_admin_footer_cron_page' );
756
	}
757
758
	/**
759
	 * Get path to main plugin file.
760
	 *
761
	 * @return string Plugin file.
762
	 */
763
	public function get_plugin_file() {
764
		return $this->plugin_file;
765
	}
766
767
	/**
768
	 * Set path to main plugin file.
769
	 *
770
	 * @param string $plugin_file Path to main plugin file.
771
	 */
772
	public function set_plugin_file( $plugin_file ) {
773
		$this->plugin_file       = $plugin_file;
774
		$this->translations_path = dirname( plugin_basename( $this->get_plugin_file() ) ) . '/languages/';
775
	}
776
777
	/**
778
	 * Get path to translations.
779
	 *
780
	 * @return string Translations path.
781
	 */
782
	public function get_translations_path() {
783
		return $this->translations_path;
784
	}
785
}
786
787
/**
788
 * The main function responsible for returning the one true Bulk_Delete
789
 * Instance to functions everywhere.
790
 *
791
 * Use this function like you would a global variable, except without needing
792
 * to declare the global.
793
 *
794
 * Example: `<?php $bulk_delete = BULK_DELETE(); ?>`
795
 *
796
 * @since 5.0
797
 *
798
 * @return Bulk_Delete The one true Bulk_Delete Instance
799
 */
800
function BULK_DELETE() {
801
	return Bulk_Delete::get_instance();
802
}
803
804
/**
805
 * Load Bulk Delete plugin.
806
 *
807
 * @since 6.0.0
808
 */
809
function load_bulk_delete() {
810
	$bulk_delete = BULK_DELETE();
811
	$bulk_delete->set_plugin_file( __FILE__ );
812
813
	add_action( 'plugins_loaded', array( $bulk_delete, 'load' ), 101 );
814
}
815
816
load_bulk_delete();
817