Completed
Push — dev/6.0.0 ( f67a01...23fee9 )
by Sudar
07:10
created

Bulk_Delete::add_delete_posts_meta_boxes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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

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

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

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