Completed
Pull Request — dev/6.0.0 (#224)
by Rajan
14:17 queued 07:22
created

bulk-delete.php (4 issues)

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

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

583
		add_action( 'admin_print_scripts-' . /** @scrutinizer ignore-type */ $this->posts_page, array( $pages_page, 'enqueue_assets' ) );
Loading history...
584
585
		// delete posts page
586
		add_action( "load-{$this->posts_page}", array( $this, 'add_delete_posts_settings_panel' ) );
587
		add_action( "add_meta_boxes_{$this->posts_page}", array( $this, 'add_delete_posts_meta_boxes' ) );
588
	}
589
590
	/**
591
	 * Add settings Panel for delete posts page.
592
	 */
593
	public function add_delete_posts_settings_panel() {
594
		/**
595
		 * Add contextual help for admin screens.
596
		 *
597
		 * @since 5.1
598
		 */
599
		do_action( 'bd_add_contextual_help', $this->posts_page );
600
601
		/* Trigger the add_meta_boxes hooks to allow meta boxes to be added */
602
		do_action( 'add_meta_boxes_' . $this->posts_page, null );
603
604
		/* Enqueue WordPress' script for handling the meta boxes */
605
		wp_enqueue_script( 'postbox' );
606
	}
607
608
	/**
609
	 * Ajax call back function for getting taxonomies to load select2 options.
610
	 *
611
	 * @since 6.0.0
612
	 */
613
	public function load_taxonomy_term(){
614
		$response = array();
615
616
		$taxonomy = sanitize_text_field( $_GET['taxonomy'] );
617
618
		$terms = get_terms( array(
619
			'taxonomy'   => $taxonomy,
620
			'hide_empty' => false,
621
			'search'     => sanitize_text_field($_GET['q']),
622
		) );
623
624
		if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
625
			foreach ( $terms as $term ) {
626
				$response[] = array( absint($term->term_id), $term->name . ' (' . $term->count . __( ' Posts', 'bulk-delete' ) . ')' );
627
			}
628
		}
629
630
		echo json_encode( $response );
631
		die;
632
	}
633
634
	/**
635
	 * Register meta boxes for delete posts page.
636
	 */
637
	public function add_delete_posts_meta_boxes() {
638
		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' );
639
		add_meta_box( self::BOX_CATEGORY      , __( 'By Category'          , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_category_box'  , $this->posts_page , 'advanced' );
640
		add_meta_box( self::BOX_TAG           , __( 'By Tag'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_tag_box'       , $this->posts_page , 'advanced' );
641
		add_meta_box( self::BOX_TAX           , __( 'By Custom Taxonomy'   , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_taxonomy_box'  , $this->posts_page , 'advanced' );
642
		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' );
643
		add_meta_box( self::BOX_URL           , __( 'By URL'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_url_box'       , $this->posts_page , 'advanced' );
644
		add_meta_box( self::BOX_POST_REVISION , __( 'By Post Revision'     , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_posts_by_revision_box'         , $this->posts_page , 'advanced' );
645
646
		/**
647
		 * Add meta box in delete posts page
648
		 * This hook can be used for adding additional meta boxes in delete posts page.
649
		 *
650
		 * @since 5.3
651
		 */
652
		do_action( 'bd_add_meta_box_for_posts' );
653
	}
654
655
	/**
656
	 * Enqueue Scripts and Styles.
657
	 */
658
	public function add_script() {
659
		// TODO: Remove this function.
660
661
		$admin_pages = $this->get_admin_pages();
662
		$pages_page  = $admin_pages['bulk-delete-pages'];
663
		$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

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