Completed
Pull Request — dev/6.0.0 (#259)
by Sudar
09:51 queued 07:06
created

bulk-delete.php (4 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\Cron\CronListPage;
20
use BulkWP\BulkDelete\Core\Metas\DeleteMetasPage;
21
use BulkWP\BulkDelete\Core\Metas\Metabox\DeleteCommentMetaMetabox;
22
use BulkWP\BulkDelete\Core\Pages\DeletePagesPage;
23
use BulkWP\BulkDelete\Core\Pages\Metabox\DeletePagesByStatusMetabox;
24
use BulkWP\BulkDelete\Core\Posts\DeletePostsPage;
25
use BulkWP\BulkDelete\Core\Posts\Metabox\DeletePostsByCategoryMetabox;
26
use BulkWP\BulkDelete\Core\Posts\Metabox\DeletePostsByStatusMetabox;
27
use BulkWP\BulkDelete\Core\Posts\Metabox\DeletePostsByTagMetabox;
28
29
/**
30
 * Copyright 2009  Sudar Muthu  (email : [email protected])
31
 * This program is free software; you can redistribute it and/or modify
32
 * it under the terms of the GNU General Public License, version 2, as
33
 * published by the Free Software Foundation.
34
 *
35
 * This program is distributed in the hope that it will be useful,
36
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38
 * GNU General Public License for more details.
39
 *
40
 * You should have received a copy of the GNU General Public License
41
 * along with this program; if not, write to the Free Software
42
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
43
 */
44
defined( 'ABSPATH' ) || exit; // Exit if accessed directly
45
46
/**
47
 * Main Bulk_Delete class.
48
 *
49
 * Singleton @since 5.0
50
 */
51
final class Bulk_Delete {
52
	/**
53
	 * The one true Bulk_Delete instance.
54
	 *
55
	 * @var Bulk_Delete
56
	 *
57
	 * @since 5.0
58
	 */
59
	private static $instance;
60
61
	/**
62
	 * Path to the main plugin file.
63
	 *
64
	 * @var string
65
	 */
66
	private $plugin_file;
67
68
	/**
69
	 * Path where translations are stored.
70
	 *
71
	 * @var string
72
	 */
73
	private $translations_path;
74
75
	/**
76
	 * Is the plugin is loaded?
77
	 *
78
	 * @since 6.0.0
79
	 *
80
	 * @var bool
81
	 */
82
	private $loaded = false;
83
84
	/**
85
	 * Controller that handles all requests and nonce checks.
86
	 *
87
	 * @var \BulkWP\BulkDelete\Core\Controller
88
	 */
89
	private $controller;
90
91
	/**
92
	 * List of Admin pages.
93
	 *
94
	 * @var BasePage[]
95
	 *
96
	 * @since 6.0.0
97
	 */
98
	private $admin_pages = array();
99
100
	// version
101
	const VERSION                   = '5.6.1';
102
103
	// page slugs
104
	const POSTS_PAGE_SLUG           = 'bulk-delete-posts';
105
	const PAGES_PAGE_SLUG           = 'bulk-delete-pages';
106
	const CRON_PAGE_SLUG            = 'bulk-delete-cron';
107
	const ADDON_PAGE_SLUG           = 'bulk-delete-addon';
108
109
	// JS constants
110
	const JS_HANDLE                 = 'bulk-delete';
111
	const CSS_HANDLE                = 'bulk-delete';
112
113
	// Cron hooks
114
	const CRON_HOOK_CATEGORY        = 'do-bulk-delete-cat';
115
	const CRON_HOOK_POST_STATUS     = 'do-bulk-delete-post-status';
116
	const CRON_HOOK_TAG             = 'do-bulk-delete-tag';
117
	const CRON_HOOK_TAXONOMY        = 'do-bulk-delete-taxonomy';
118
	const CRON_HOOK_POST_TYPE       = 'do-bulk-delete-post-type';
119
	const CRON_HOOK_CUSTOM_FIELD    = 'do-bulk-delete-custom-field';
120
	const CRON_HOOK_TITLE           = 'do-bulk-delete-by-title';
121
	const CRON_HOOK_DUPLICATE_TITLE = 'do-bulk-delete-by-duplicate-title';
122
	const CRON_HOOK_POST_BY_ROLE    = 'do-bulk-delete-posts-by-role';
123
124
	const CRON_HOOK_PAGES_STATUS    = 'do-bulk-delete-pages-by-status';
125
126
	// meta boxes for delete posts
127
	const BOX_POST_STATUS           = 'bd_by_post_status';
128
	const BOX_CATEGORY              = 'bd_by_category';
129
	const BOX_TAG                   = 'bd_by_tag';
130
	const BOX_TAX                   = 'bd_by_tax';
131
	const BOX_POST_TYPE             = 'bd_by_post_type';
132
	const BOX_URL                   = 'bd_by_url';
133
	const BOX_POST_REVISION         = 'bd_by_post_revision';
134
	const BOX_CUSTOM_FIELD          = 'bd_by_custom_field';
135
	const BOX_TITLE                 = 'bd_by_title';
136
	const BOX_DUPLICATE_TITLE       = 'bd_by_duplicate_title';
137
	const BOX_POST_FROM_TRASH       = 'bd_posts_from_trash';
138
	const BOX_POST_BY_ROLE          = 'bd_post_by_user_role';
139
140
	// meta boxes for delete pages
141
	const BOX_PAGE_STATUS           = 'bd_by_page_status';
142
	const BOX_PAGE_FROM_TRASH       = 'bd_pages_from_trash';
143
144
	// Settings constants
145
	const SETTING_OPTION_GROUP      = 'bd_settings';
146
	const SETTING_OPTION_NAME       = 'bd_licenses';
147
	const SETTING_SECTION_ID        = 'bd_license_section';
148
149
	// Transient keys
150
	const LICENSE_CACHE_KEY_PREFIX  = 'bd-license_';
151
152
	const MAX_SELECT2_LIMIT  = 50;
153
154
	// path variables
155
	// Ideally these should be constants, but because of PHP's limitations, these are static variables
156
	public static $PLUGIN_DIR;
157
	public static $PLUGIN_URL;
158
	public static $PLUGIN_FILE;
159
160
	// Instance variables
161
	public $translations;
162
	public $posts_page;
163
	public $pages_page;
164
	public $cron_page;
165
	public $addon_page;
166
	public $settings_page;
167
	public $meta_page;
168
	public $misc_page;
169
	public $display_activate_license_form = false;
170
171
	// Deprecated.
172
	// Will be removed in v6.0
173
	const CRON_HOOK_USER_ROLE = 'do-bulk-delete-users-by-role';
174
	public $users_page;
175
176
	/**
177
	 * Main Bulk_Delete Instance.
178
	 *
179
	 * Insures that only one instance of Bulk_Delete exists in memory at any one
180
	 * time. Also prevents needing to define globals all over the place.
181
	 *
182
	 * @since 5.0
183
	 * @static
184
	 * @staticvar array $instance
185
	 *
186
	 * @see BULK_DELETE()
187
	 *
188
	 * @uses Bulk_Delete::setup_paths() Setup the plugin paths
189
	 * @uses Bulk_Delete::includes() Include the required files
190
	 * @uses Bulk_Delete::load_textdomain() Load text domain for translation
191
	 * @uses Bulk_Delete::setup_actions() Setup the hooks and actions
192 5
	 *
193 5
	 * @return Bulk_Delete The one true instance of Bulk_Delete
194 1
	 */
195
	public static function get_instance() {
196 1
		if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Bulk_Delete ) ) {
197 1
			self::$instance = new Bulk_Delete();
198
199
			self::$instance->setup_paths();
200 5
			self::$instance->includes();
201
		}
202
203
		return self::$instance;
204
	}
205
206
	/**
207
	 * Load the plugin if it is not loaded.
208 1
	 *
209 1
	 * This function will be invoked in the `plugins_loaded` hook.
210
	 */
211
	public function load() {
212
		if ( $this->loaded ) {
213 1
			return;
214
		}
215 1
216 1
		add_action( 'init', array( $this, 'on_init' ) );
217
218 1
		$this->load_dependencies();
219
		$this->setup_actions();
220
221
		$this->loaded = true;
222
223
		/**
224
		 * Bulk Delete plugin loaded.
225 1
		 *
226 1
		 * @since 6.0.0
227
		 */
228
		do_action( 'bd_loaded' );
229
	}
230
231
	/**
232
	 * Throw error on object clone.
233
	 *
234
	 * The whole idea of the singleton design pattern is that there is a single
235
	 * object therefore, we don't want the object to be cloned.
236
	 *
237
	 * @since  5.0
238
	 * @access protected
239 1
	 *
240
	 * @return void
241 1
	 */
242 1
	public function __clone() {
243
		// Cloning instances of the class is forbidden
244
		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'bulk-delete' ), '5.0' );
245
	}
246
247
	/**
248
	 * Disable unserializing of the class.
249
	 *
250
	 * @since  5.0
251
	 * @access protected
252 1
	 *
253
	 * @return void
254 1
	 */
255 1
	public function __wakeup() {
256
		// Unserializing instances of the class is forbidden
257
		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'bulk-delete' ), '5.0' );
258
	}
259
260
	/**
261
	 * Setup plugin constants.
262
	 *
263
	 * @access private
264
	 *
265
	 * @since  5.0
266 1
	 *
267
	 * @return void
268 1
	 */
269
	private function setup_paths() {
270
		// Plugin Folder Path
271 1
		self::$PLUGIN_DIR = plugin_dir_path( __FILE__ );
272
273
		// Plugin Folder URL
274 1
		self::$PLUGIN_URL = plugin_dir_url( __FILE__ );
275 1
276
		// Plugin Root File
277
		self::$PLUGIN_FILE = __FILE__;
278
	}
279
280
	/**
281
	 * Include required files.
282
	 *
283
	 * // TODO: Replace includes with autoloader.
284
	 *
285
	 * @access private
286
	 *
287
	 * @since  5.0
288 1
	 *
289 1
	 * @return void
290 1
	 */
291
	private function includes() {
292 1
		require_once self::$PLUGIN_DIR . '/include/helpers/common.php';
293 1
294
		require_once self::$PLUGIN_DIR . '/include/Core/Base/Mixin/Fetcher.php';
295 1
		require_once self::$PLUGIN_DIR . '/include/Core/Base/Mixin/Renderer.php';
296 1
297 1
		require_once self::$PLUGIN_DIR . '/include/Core/Base/BasePage.php';
298
		require_once self::$PLUGIN_DIR . '/include/Core/Base/MetaboxPage.php';
299 1
		require_once self::$PLUGIN_DIR . '/include/Core/Base/BaseMetabox.php';
300 1
301 1
		require_once self::$PLUGIN_DIR . '/include/Core/Pages/DeletePagesPage.php';
302 1
		require_once self::$PLUGIN_DIR . '/include/Core/Posts/DeletePostsPage.php';
303
		require_once self::$PLUGIN_DIR . '/include/Core/Metas/DeleteMetasPage.php';
304 1
305 1
		require_once self::$PLUGIN_DIR . '/include/Core/Posts/PostsMetabox.php';
306 1
		require_once self::$PLUGIN_DIR . '/include/Core/Posts/Metabox/DeletePostsByStatusMetabox.php';
307 1
		require_once self::$PLUGIN_DIR . '/include/Core/Posts/Metabox/DeletePostsByCategoryMetabox.php';
308
		require_once self::$PLUGIN_DIR . '/include/Core/Posts/Metabox/DeletePostsByTagMetabox.php';
309 1
310
		require_once self::$PLUGIN_DIR . '/include/Core/Pages/PagesMetabox.php';
311 1
		require_once self::$PLUGIN_DIR . '/include/Core/Pages/Metabox/DeletePagesByStatusMetabox.php';
312
313 1
		require_once self::$PLUGIN_DIR . '/include/Core/Metas/MetasMetabox.php';
314
		require_once self::$PLUGIN_DIR . '/include/Core/Metas/Metabox/DeleteCommentMetaMetabox.php';
315
316 1
		require_once self::$PLUGIN_DIR . '/include/Core/Cron/CronListPage.php';
317 1
		require_once self::$PLUGIN_DIR . '/include/Core/Cron/CronListTable.php';
318 1
319
		require_once self::$PLUGIN_DIR . '/include/base/class-bd-meta-box-module.php';
320 1
		require_once self::$PLUGIN_DIR . '/include/base/users/class-bd-user-meta-box-module.php';
321 1
		require_once self::$PLUGIN_DIR . '/include/base/class-bd-base-page.php';
322 1
		require_once self::$PLUGIN_DIR . '/include/base/class-bd-page.php';
323 1
324
		require_once self::$PLUGIN_DIR . '/include/Core/Controller.php';
325 1
326 1
		require_once self::$PLUGIN_DIR . '/include/ui/form.php';
327
328 1
		require_once self::$PLUGIN_DIR . '/include/posts/class-bulk-delete-posts.php';
329 1
//		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...
330 1
331
		require_once self::$PLUGIN_DIR . '/include/users/class-bd-users-page.php';
332 1
		require_once self::$PLUGIN_DIR . '/include/users/modules/class-bulk-delete-users-by-user-role.php';
333
		require_once self::$PLUGIN_DIR . '/include/users/modules/class-bulk-delete-users-by-user-meta.php';
334 1
335 1
//		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-meta.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% 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...
336
//		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-post-meta.php';
337 1
//		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-user-meta.php';
338 1
//		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-comment-meta.php';
339 1
340 1
		require_once self::$PLUGIN_DIR . '/include/misc/class-bulk-delete-misc.php';
341
		require_once self::$PLUGIN_DIR . '/include/misc/class-bulk-delete-jetpack-contact-form-messages.php';
342 1
343 1
		require_once self::$PLUGIN_DIR . '/include/settings/class-bd-settings-page.php';
344
		require_once self::$PLUGIN_DIR . '/include/settings/setting-helpers.php';
345 1
		require_once self::$PLUGIN_DIR . '/include/settings/class-bd-settings.php';
346 1
347 1
		require_once self::$PLUGIN_DIR . '/include/system-info/class-bd-system-info-page.php';
348
349 1
		require_once self::$PLUGIN_DIR . '/include/util/class-bd-util.php';
350 1
		require_once self::$PLUGIN_DIR . '/include/util/query.php';
351 1
352 1
		require_once self::$PLUGIN_DIR . '/include/compatibility/simple-login-log.php';
353
		require_once self::$PLUGIN_DIR . '/include/compatibility/the-event-calendar.php';
354 1
		require_once self::$PLUGIN_DIR . '/include/compatibility/woocommerce.php';
355 1
		require_once self::$PLUGIN_DIR . '/include/compatibility/advanced-custom-fields-pro.php';
356 1
357
		require_once self::$PLUGIN_DIR . '/include/deprecated/class-bulk-delete-users.php';
358 1
		require_once self::$PLUGIN_DIR . '/include/deprecated/deprecated.php';
359 1
360 1
		require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-addon.php';
361
		require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-base-addon.php';
362
		require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-scheduler-addon.php';
363
364
		require_once self::$PLUGIN_DIR . '/include/addons/addon-list.php';
365
		require_once self::$PLUGIN_DIR . '/include/addons/posts.php';
366
		require_once self::$PLUGIN_DIR . '/include/addons/pages.php';
367 1
		require_once self::$PLUGIN_DIR . '/include/addons/util.php';
368 1
369 1
		require_once self::$PLUGIN_DIR . '/include/license/class-bd-license.php';
370
		require_once self::$PLUGIN_DIR . '/include/license/class-bd-license-handler.php';
371
		require_once self::$PLUGIN_DIR . '/include/license/class-bd-edd-api-wrapper.php';
372
373
		require_once self::$PLUGIN_DIR . '/include/ui/admin-ui.php';
374
		require_once self::$PLUGIN_DIR . '/include/ui/class-bulk-delete-help-screen.php';
375
	}
376 1
377 1
	/**
378 1
	 * Triggered when the `init` hook is fired.
379
	 *
380
	 * @since 6.0.0
381
	 */
382
	public function on_init() {
383
		$this->load_textdomain();
384
	}
385 1
386 1
	/**
387 1
	 * Loads the plugin language files.
388
	 *
389
	 * @since  5.0
390
	 */
391
	private function load_textdomain() {
392
		load_plugin_textdomain( 'bulk-delete', false, $this->get_translations_path() );
393
	}
394
395
	/**
396
	 * Load all dependencies.
397
	 *
398 1
	 * @since 6.0.0
399 1
	 */
400
	private function load_dependencies() {
401
		$this->controller = new Controller();
402
		$this->controller->load();
403
	}
404
405
	/**
406 1
	 * Loads the plugin's actions and hooks.
407
	 *
408 1
	 * @access private
409
	 *
410 1
	 * @since  5.0
411
	 *
412 1
	 * @return void
413
	 */
414
	private function setup_actions() {
415 1
		add_action( 'admin_menu', array( $this, 'on_admin_menu' ) );
416
	}
417
418
	/**
419
	 * Triggered when the `admin_menu` hook is fired.
420
	 *
421
	 * Register all admin pages.
422
	 *
423
	 * @since 6.0.0
424
	 */
425
	public function on_admin_menu() {
426
		foreach ( $this->get_admin_pages() as $page ) {
427
			$page->register();
428
		}
429
430
		$this->load_legacy_menu();
431
	}
432
433
	/**
434
	 * Get the list of registered admin pages.
435
	 *
436
	 * @since 6.0.0
437
	 *
438
	 * @return BasePage[] List of Admin pages.
439
	 */
440
	private function get_admin_pages() {
441
		if ( empty( $this->admin_pages ) ) {
442
			$posts_page     = $this->get_delete_posts_admin_page();
443
			$pages_page     = $this->get_delete_pages_admin_page();
444
			$metas_page     = $this->get_delete_metas_admin_page();
445
			$cron_list_page = $this->get_cron_list_admin_page();
446
447
			$this->admin_pages[ $posts_page->get_page_slug() ]     = $posts_page;
448
			$this->admin_pages[ $pages_page->get_page_slug() ]     = $pages_page;
449
			$this->admin_pages[ $metas_page->get_page_slug() ]     = $metas_page;
450
			$this->admin_pages[ $cron_list_page->get_page_slug() ] = $cron_list_page;
451
		}
452
453
		/**
454
		 * List of admin pages.
455
		 *
456
		 * @since 6.0.0
457
		 *
458
		 * @param BasePage[] List of Admin pages.
459
		 */
460
		return apply_filters( 'bd_admin_pages', $this->admin_pages );
461
	}
462
463
	/**
464
	 * Get Bulk Delete Posts admin page.
465
	 *
466
	 * @return \BulkWP\BulkDelete\Core\Posts\DeletePostsPage
467
	 */
468
	private function get_delete_posts_admin_page() {
469
		$posts_page = new DeletePostsPage( $this->get_plugin_file() );
470
471
		$posts_page->add_metabox( new DeletePostsByStatusMetabox() );
472
		$posts_page->add_metabox( new DeletePostsByCategoryMetabox() );
473
		$posts_page->add_metabox( new DeletePostsByTagMetabox() );
474
475
		return $posts_page;
476
	}
477
478
	/**
479
	 * Get Bulk Delete Pages admin page.
480
	 *
481
	 * @since 6.0.0
482
	 *
483
	 * @return \BulkWP\BulkDelete\Core\Pages\DeletePagesPage
484
	 */
485
	private function get_delete_pages_admin_page() {
486
		$pages_page = new DeletePagesPage( $this->get_plugin_file() );
487
488
		$pages_page->add_metabox( new DeletePagesByStatusMetabox() );
489
490
		return $pages_page;
491
	}
492
493
	/**
494
	 * Get Bulk Delete Metas admin page.
495
	 *
496
	 * @since 6.0.0
497
	 *
498
	 * @return BulkWP\BulkDelete\Core\Metas\DeleteMetasPage
499
	 */
500
	private function get_delete_metas_admin_page() {
501
		$metas_page = new DeleteMetasPage( $this->get_plugin_file() );
502
503
		$metas_page->add_metabox( new DeleteCommentMetaMetabox() );
504
505
		return $metas_page;
506
	}
507
508
	/**
509
	 * Get the Cron List admin page.
510
	 *
511
	 * @since 6.0.0
512
	 *
513
	 * @return \BulkWP\BulkDelete\Core\Cron\CronListPage
514
	 */
515
	private function get_cron_list_admin_page() {
516
		$cron_list_page = new CronListPage( $this->get_plugin_file() );
517
518
		return $cron_list_page;
519
	}
520
521
	/**
522
	 * Add navigation menu.
523
	 */
524
	public function load_legacy_menu() {
525
		$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' ) );
526
527
		/**
528
		 * Runs just after adding all *delete* menu items to Bulk WP main menu.
529
		 *
530
		 * This action is primarily for adding extra *delete* menu items to the Bulk WP main menu.
531
		 *
532
		 * @since 5.3
533
		 */
534
		do_action( 'bd_after_primary_menus' );
535
536
		/**
537
		 * Runs just before adding non-action menu items to Bulk WP main menu.
538
		 *
539
		 * This action is primarily for adding extra menu items before non-action menu items to the Bulk WP main menu.
540
		 *
541
		 * @since 5.3
542
		 */
543
		do_action( 'bd_before_secondary_menus' );
544
545
		$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' ) );
546
547
		/**
548
		 * Runs just after adding all menu items to Bulk WP main menu.
549
		 *
550
		 * This action is primarily for adding extra menu items to the Bulk WP main menu.
551
		 *
552
		 * @since 5.3
553
		 */
554
		do_action( 'bd_after_all_menus' );
555
556
		$admin_pages = $this->get_admin_pages();
557
		$pages_page  = $admin_pages['bulk-delete-pages'];
558
559
		// enqueue JavaScript
560
		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

560
		add_action( 'admin_print_scripts-' . /** @scrutinizer ignore-type */ $this->posts_page, array( $pages_page, 'enqueue_assets' ) );
Loading history...
561
562
		// delete posts page
563
		add_action( "load-{$this->posts_page}", array( $this, 'add_delete_posts_settings_panel' ) );
564
		add_action( "add_meta_boxes_{$this->posts_page}", array( $this, 'add_delete_posts_meta_boxes' ) );
565
	}
566
567
	/**
568
	 * Add settings Panel for delete posts page.
569
	 */
570
	public function add_delete_posts_settings_panel() {
571
		/**
572
		 * Add contextual help for admin screens.
573
		 *
574
		 * @since 5.1
575
		 */
576
		do_action( 'bd_add_contextual_help', $this->posts_page );
577
578
		/* Trigger the add_meta_boxes hooks to allow meta boxes to be added */
579
		do_action( 'add_meta_boxes_' . $this->posts_page, null );
580
581
		/* Enqueue WordPress' script for handling the meta boxes */
582
		wp_enqueue_script( 'postbox' );
583
	}
584
585
	/**
586
	 * Register meta boxes for delete posts page.
587
	 */
588
	public function add_delete_posts_meta_boxes() {
589
		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' );
590
		add_meta_box( self::BOX_CATEGORY      , __( 'By Category'          , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_category_box'  , $this->posts_page , 'advanced' );
591
		add_meta_box( self::BOX_TAG           , __( 'By Tag'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_tag_box'       , $this->posts_page , 'advanced' );
592
		add_meta_box( self::BOX_TAX           , __( 'By Custom Taxonomy'   , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_taxonomy_box'  , $this->posts_page , 'advanced' );
593
		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' );
594
		add_meta_box( self::BOX_URL           , __( 'By URL'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_url_box'       , $this->posts_page , 'advanced' );
595
		add_meta_box( self::BOX_POST_REVISION , __( 'By Post Revision'     , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_posts_by_revision_box'         , $this->posts_page , 'advanced' );
596
597
		/**
598
		 * Add meta box in delete posts page
599
		 * This hook can be used for adding additional meta boxes in delete posts page.
600
		 *
601
		 * @since 5.3
602
		 */
603
		do_action( 'bd_add_meta_box_for_posts' );
604
	}
605
606
	/**
607
	 * Enqueue Scripts and Styles.
608
	 */
609
	public function add_script() {
610
		// TODO: Remove this function.
611
612
		$admin_pages = $this->get_admin_pages();
613
		$pages_page  = $admin_pages['bulk-delete-pages'];
614
		$pages_page->enqueue_assets();
0 ignored issues
show
The method enqueue_assets() does not exist on BulkWP\BulkDelete\Core\Base\BasePage. It seems like you code against a sub-type of BulkWP\BulkDelete\Core\Base\BasePage such as BulkWP\BulkDelete\Core\Base\MetaboxPage. ( Ignorable by Annotation )

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

614
		$pages_page->/** @scrutinizer ignore-call */ 
615
               enqueue_assets();
Loading history...
615
	}
616
617
	/**
618
	 * Show the delete posts page.
619
	 *
620
	 * @Todo Move this function to Bulk_Delete_Posts class
621
	 */
622
	public function display_posts_page() {
623
?>
624
<div class="wrap">
625
    <h2><?php _e( 'Bulk Delete Posts', 'bulk-delete' );?></h2>
626
    <?php settings_errors(); ?>
627
628
    <form method = "post">
629
<?php
630
		// nonce for bulk delete
631
		wp_nonce_field( 'sm-bulk-delete-posts', 'sm-bulk-delete-posts-nonce' );
632
633
		/* Used to save closed meta boxes and their order */
634
		wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
635
		wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
636
?>
637
    <div id = "poststuff">
638
        <div id="post-body" class="metabox-holder columns-1">
639
640
            <div class="notice notice-warning">
641
                <p><strong><?php _e( 'WARNING: Posts deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p>
642
            </div>
643
644
            <div id="postbox-container-2" class="postbox-container">
645
                <?php do_meta_boxes( '', 'advanced', null ); ?>
646
            </div> <!-- #postbox-container-2 -->
647
648
        </div> <!-- #post-body -->
649
    </div><!-- #poststuff -->
650
    </form>
651
</div><!-- .wrap -->
652
653
<?php
654
		/**
655
		 * Runs just before displaying the footer text in the "Bulk Delete Posts" admin page.
656
		 *
657
		 * This action is primarily for adding extra content in the footer of "Bulk Delete Posts" admin page.
658
		 *
659
		 * @since 5.0
660
		 */
661
		do_action( 'bd_admin_footer_posts_page' );
662
	}
663
664
	/**
665
	 * Get path to main plugin file.
666
	 *
667
	 * @return string Plugin file.
668
	 */
669
	public function get_plugin_file() {
670
		return $this->plugin_file;
671
	}
672
673
	/**
674
	 * Set path to main plugin file.
675
	 *
676
	 * @param string $plugin_file Path to main plugin file.
677
	 */
678
	public function set_plugin_file( $plugin_file ) {
679
		$this->plugin_file       = $plugin_file;
680
		$this->translations_path = dirname( plugin_basename( $this->get_plugin_file() ) ) . '/languages/';
681
	}
682
683
	/**
684
	 * Get path to translations.
685
	 *
686
	 * @return string Translations path.
687
	 */
688
	public function get_translations_path() {
689
		return $this->translations_path;
690
	}
691
}
692
693
/**
694
 * The main function responsible for returning the one true Bulk_Delete
695
 * Instance to functions everywhere.
696
 *
697
 * Use this function like you would a global variable, except without needing
698
 * to declare the global.
699
 *
700
 * Example: `<?php $bulk_delete = BULK_DELETE(); ?>`
701
 *
702
 * @since 5.0
703
 *
704
 * @return Bulk_Delete The one true Bulk_Delete Instance
705
 */
706
function BULK_DELETE() {
707
	return Bulk_Delete::get_instance();
708
}
709
710
/**
711
 * Load Bulk Delete plugin.
712
 *
713
 * @since 6.0.0
714
 */
715
function load_bulk_delete() {
716
	$bulk_delete = BULK_DELETE();
717
	$bulk_delete->set_plugin_file( __FILE__ );
718
719
	add_action( 'plugins_loaded', array( $bulk_delete, 'load' ), 101 );
720
}
721
722
load_bulk_delete();
723