Passed
Push — analysis-8LwQZo ( 2696a6 )
by Sudar
08:46
created

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

370
		load_plugin_textdomain( 'bulk-delete', /** @scrutinizer ignore-type */ false, $this->get_translations_path() );
Loading history...
371 1
	}
372
373
	/**
374
	 * Load all dependencies.
375
	 *
376
	 * @since 6.0.0
377
	 */
378 1
	private function load_dependencies() {
379 1
		$this->controller = new BD_Controller();
380 1
	}
381
382
	/**
383
	 * Loads the plugin's actions and hooks.
384
	 *
385
	 * @access private
386
	 *
387
	 * @since  5.0
388
	 *
389
	 * @return void
390
	 */
391 1
	private function setup_actions() {
392 1
		add_action( 'admin_menu', array( $this, 'on_admin_menu' ) );
393
394
		/**
395
		 * This is Ajax hook, It's runs when user search categories or tags on bulk-delete-posts page.
396
		 *
397
		 * @since 6.0.0
398
		 */
399 1
		add_action( 'wp_ajax_bd_load_taxonomy_term', array( $this, 'load_taxonomy_term' ) );
400
401 1
		add_filter( 'bd_help_tooltip', 'bd_generate_help_tooltip', 10, 2 );
402
403 1
		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...
404
			add_action( 'bd_after_query', array( $this, 'log_sql_query' ) );
405
		}
406 1
	}
407
408
	/**
409
	 * Log SQL query used by Bulk Delete.
410
	 *
411
	 * Query is logged only when `BD_DEBUG` is set.
412
	 *
413
	 * @since 5.6
414
	 *
415
	 * @param \WP_Query $wp_query WP Query object.
416
	 */
417
	public function log_sql_query( $wp_query ) {
418
		$query = $wp_query->request;
419
420
		/**
421
		 * Bulk Delete query is getting logged.
422
		 *
423
		 * @since 5.6
424
		 *
425
		 * @param string $query Bulk Delete SQL Query.
426
		 */
427
		do_action( 'bd_log_sql_query', $query );
428
429
		error_log( 'Bulk Delete Query: ' . $query );
430
	}
431
432
	/**
433
	 * Triggered when the `admin_menu` hook is fired.
434
	 *
435
	 * Register all admin pages.
436
	 *
437
	 * @since 6.0.0
438
	 */
439
	public function on_admin_menu() {
440
		$this->load_legacy_menu();
441
442
		foreach ( $this->get_admin_pages() as $page ) {
443
			$page->register();
444
		}
445
	}
446
447
	/**
448
	 * Get the list of registered admin pages.
449
	 *
450
	 * @since 6.0.0
451
	 *
452
	 * @return BasePage[] List of Admin pages.
453
	 */
454
	private function get_admin_pages() {
455
		if ( empty( $this->admin_pages ) ) {
456
			$pages_page = $this->get_delete_pages_admin_page();
457
458
			$this->admin_pages[ $pages_page->get_page_slug() ] = $pages_page;
459
		}
460
461
		/**
462
		 * List of admin pages.
463
		 *
464
		 * @since 6.0.0
465
		 *
466
		 * @param BasePage[] List of Admin pages.
467
		 */
468
		return apply_filters( 'bd_admin_pages', $this->admin_pages );
469
	}
470
471
	/**
472
	 * Get Bulk Delete Pages admin page.
473
	 *
474
	 * @since 6.0.0
475
	 *
476
	 * @return DeletePagesPage Bulk Move Post admin page.
477
	 */
478
	private function get_delete_pages_admin_page() {
479
		$pages_page = new DeletePagesPage( $this->get_plugin_file() );
480
481
		$pages_page->add_metabox( new DeletePagesByStatusMetabox() );
482
483
		return $pages_page;
484
	}
485
486
	/**
487
	 * Add navigation menu.
488
	 */
489
	public function load_legacy_menu() {
490
		add_menu_page( __( 'Bulk WP', 'bulk-delete' ), __( 'Bulk WP', 'bulk-delete' ), 'manage_options', self::POSTS_PAGE_SLUG, array( $this, 'display_posts_page' ), 'dashicons-trash', self::MENU_ORDER );
0 ignored issues
show
self::MENU_ORDER of type string is incompatible with the type integer expected by parameter $position of add_menu_page(). ( Ignorable by Annotation )

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

490
		add_menu_page( __( 'Bulk WP', 'bulk-delete' ), __( 'Bulk WP', 'bulk-delete' ), 'manage_options', self::POSTS_PAGE_SLUG, array( $this, 'display_posts_page' ), 'dashicons-trash', /** @scrutinizer ignore-type */ self::MENU_ORDER );
Loading history...
491
492
		$this->posts_page = add_submenu_page( self::POSTS_PAGE_SLUG, __( 'Bulk Delete Posts', 'bulk-delete' ), __( 'Bulk Delete Posts', 'bulk-delete' ), 'delete_posts', self::POSTS_PAGE_SLUG, array( $this, 'display_posts_page' ) );
493
494
		/**
495
		 * Runs just after adding all *delete* menu items to Bulk WP main menu.
496
		 *
497
		 * This action is primarily for adding extra *delete* menu items to the Bulk WP main menu.
498
		 *
499
		 * @since 5.3
500
		 */
501
		do_action( 'bd_after_primary_menus' );
502
503
		/**
504
		 * Runs just before adding non-action menu items to Bulk WP main menu.
505
		 *
506
		 * This action is primarily for adding extra menu items before non-action menu items to the Bulk WP main menu.
507
		 *
508
		 * @since 5.3
509
		 */
510
		do_action( 'bd_before_secondary_menus' );
511
512
		$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' ) );
513
		$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' ) );
514
515
		/**
516
		 * Runs just after adding all menu items to Bulk WP main menu.
517
		 *
518
		 * This action is primarily for adding extra menu items to the Bulk WP main menu.
519
		 *
520
		 * @since 5.3
521
		 */
522
		do_action( 'bd_after_all_menus' );
523
524
		$admin_pages = $this->get_admin_pages();
525
		$pages_page  = $admin_pages['bulk-delete-pages'];
526
527
		// enqueue JavaScript
528
		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

528
		add_action( 'admin_print_scripts-' . /** @scrutinizer ignore-type */ $this->posts_page, array( $pages_page, 'enqueue_assets' ) );
Loading history...
529
530
		// delete posts page
531
		add_action( "load-{$this->posts_page}", array( $this, 'add_delete_posts_settings_panel' ) );
532
		add_action( "add_meta_boxes_{$this->posts_page}", array( $this, 'add_delete_posts_meta_boxes' ) );
533
	}
534
535
	/**
536
	 * Add settings Panel for delete posts page.
537
	 */
538
	public function add_delete_posts_settings_panel() {
539
		/**
540
		 * Add contextual help for admin screens.
541
		 *
542
		 * @since 5.1
543
		 */
544
		do_action( 'bd_add_contextual_help', $this->posts_page );
545
546
		/* Trigger the add_meta_boxes hooks to allow meta boxes to be added */
547
		do_action( 'add_meta_boxes_' . $this->posts_page, null );
548
549
		/* Enqueue WordPress' script for handling the meta boxes */
550
		wp_enqueue_script( 'postbox' );
551
	}
552
553
	/**
554
	 * Ajax call back function for getting taxonomies to load select2 options.
555
	 *
556
	 * @since 6.0.0
557
	 */
558
	public function load_taxonomy_term(){
559
		$response = array();
560
561
		$taxonomy = sanitize_text_field( $_GET['taxonomy'] );
562
563
		$terms = get_terms( array(
564
			'taxonomy'   => $taxonomy,
565
			'hide_empty' => false,
566
			'search'     => sanitize_text_field($_GET['q']),
567
		) );
568
569
		if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
570
			foreach ( $terms as $term ) {
571
				$response[] = array( absint($term->term_id), $term->name . ' (' . $term->count . __( ' Posts', 'bulk-delete' ) . ')' );
572
			}
573
		}
574
575
		echo json_encode( $response );
576
		die;
577
	}
578
579
	/**
580
	 * Register meta boxes for delete posts page.
581
	 */
582
	public function add_delete_posts_meta_boxes() {
583
		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' );
584
		add_meta_box( self::BOX_CATEGORY      , __( 'By Category'          , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_category_box'  , $this->posts_page , 'advanced' );
585
		add_meta_box( self::BOX_TAG           , __( 'By Tag'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_tag_box'       , $this->posts_page , 'advanced' );
586
		add_meta_box( self::BOX_TAX           , __( 'By Custom Taxonomy'   , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_taxonomy_box'  , $this->posts_page , 'advanced' );
587
		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' );
588
		add_meta_box( self::BOX_URL           , __( 'By URL'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_url_box'       , $this->posts_page , 'advanced' );
589
		add_meta_box( self::BOX_POST_REVISION , __( 'By Post Revision'     , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_posts_by_revision_box'         , $this->posts_page , 'advanced' );
590
591
		/**
592
		 * Add meta box in delete posts page
593
		 * This hook can be used for adding additional meta boxes in delete posts page.
594
		 *
595
		 * @since 5.3
596
		 */
597
		do_action( 'bd_add_meta_box_for_posts' );
598
	}
599
600
	/**
601
	 * Enqueue Scripts and Styles.
602
	 */
603
	public function add_script() {
604
		// TODO: Remove this function.
605
606
		$admin_pages = $this->get_admin_pages();
607
		$pages_page  = $admin_pages['bulk-delete-pages'];
608
		$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

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