Completed
Push — 137-feature/refactor-post-modu... ( 580e59 )
by Sudar
07:52
created

bulk-delete.php (10 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
18
use BulkWP\BulkDelete\Core\Base\BasePage;
19
use BulkWP\BulkDelete\Core\Pages\DeletePagesPage;
20
use BulkWP\BulkDelete\Core\Pages\Metabox\DeletePagesByStatusMetabox;
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 5.7.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 5.7.0
90
	 */
91
	private $admin_pages = array();
92
93
	// version
94
	const VERSION                   = '5.6.1';
95
96
	// Numeric constants
97
	const MENU_ORDER                = '26';
98
99
	// page slugs
100
	const POSTS_PAGE_SLUG           = 'bulk-delete-posts';
101
	const PAGES_PAGE_SLUG           = 'bulk-delete-pages';
102
	const CRON_PAGE_SLUG            = 'bulk-delete-cron';
103
	const ADDON_PAGE_SLUG           = 'bulk-delete-addon';
104
105
	// JS constants
106
	const JS_HANDLE                 = 'bulk-delete';
107
	const JS_VARIABLE               = 'BulkWP';
108
109
	const CSS_HANDLE                = 'bulk-delete';
110
111
	// Cron hooks
112
	const CRON_HOOK_CATEGORY        = 'do-bulk-delete-cat';
113
	const CRON_HOOK_POST_STATUS     = 'do-bulk-delete-post-status';
114
	const CRON_HOOK_TAG             = 'do-bulk-delete-tag';
115
	const CRON_HOOK_TAXONOMY        = 'do-bulk-delete-taxonomy';
116
	const CRON_HOOK_POST_TYPE       = 'do-bulk-delete-post-type';
117
	const CRON_HOOK_CUSTOM_FIELD    = 'do-bulk-delete-custom-field';
118
	const CRON_HOOK_TITLE           = 'do-bulk-delete-by-title';
119
	const CRON_HOOK_DUPLICATE_TITLE = 'do-bulk-delete-by-duplicate-title';
120
	const CRON_HOOK_POST_BY_ROLE    = 'do-bulk-delete-posts-by-role';
121
122
	const CRON_HOOK_PAGES_STATUS    = 'do-bulk-delete-pages-by-status';
123
124
	// meta boxes for delete posts
125
	const BOX_POST_STATUS           = 'bd_by_post_status';
126
	const BOX_CATEGORY              = 'bd_by_category';
127
	const BOX_TAG                   = 'bd_by_tag';
128
	const BOX_TAX                   = 'bd_by_tax';
129
	const BOX_POST_TYPE             = 'bd_by_post_type';
130
	const BOX_URL                   = 'bd_by_url';
131
	const BOX_POST_REVISION         = 'bd_by_post_revision';
132
	const BOX_CUSTOM_FIELD          = 'bd_by_custom_field';
133
	const BOX_TITLE                 = 'bd_by_title';
134
	const BOX_DUPLICATE_TITLE       = 'bd_by_duplicate_title';
135
	const BOX_POST_FROM_TRASH       = 'bd_posts_from_trash';
136
	const BOX_POST_BY_ROLE          = 'bd_post_by_user_role';
137
138
	// meta boxes for delete pages
139
	const BOX_PAGE_STATUS           = 'bd_by_page_status';
140
	const BOX_PAGE_FROM_TRASH       = 'bd_pages_from_trash';
141
142
	// Settings constants
143
	const SETTING_OPTION_GROUP      = 'bd_settings';
144
	const SETTING_OPTION_NAME       = 'bd_licenses';
145
	const SETTING_SECTION_ID        = 'bd_license_section';
146
147
	// Transient keys
148
	const LICENSE_CACHE_KEY_PREFIX  = 'bd-license_';
149
150
	const MAX_SELECT2_LIMIT  = 50;
151
152
	// path variables
153
	// Ideally these should be constants, but because of PHP's limitations, these are static variables
154
	public static $PLUGIN_DIR;
155
	public static $PLUGIN_URL;
156
	public static $PLUGIN_FILE;
157
158
	// Instance variables
159
	public $translations;
160
	public $posts_page;
161
	public $pages_page;
162
	public $cron_page;
163
	public $addon_page;
164
	public $settings_page;
165
	public $meta_page;
166
	public $misc_page;
167
	public $display_activate_license_form = false;
168
169
	// Deprecated.
170
	// Will be removed in v6.0
171
	const CRON_HOOK_USER_ROLE = 'do-bulk-delete-users-by-role';
172
	public $users_page;
173
174
	/**
175
	 * Main Bulk_Delete Instance.
176
	 *
177
	 * Insures that only one instance of Bulk_Delete exists in memory at any one
178
	 * time. Also prevents needing to define globals all over the place.
179
	 *
180
	 * @since 5.0
181
	 * @static
182
	 * @staticvar array $instance
183
	 *
184
	 * @see BULK_DELETE()
185
	 *
186
	 * @uses Bulk_Delete::setup_paths() Setup the plugin paths
187
	 * @uses Bulk_Delete::includes() Include the required files
188
	 * @uses Bulk_Delete::load_textdomain() Load text domain for translation
189
	 * @uses Bulk_Delete::setup_actions() Setup the hooks and actions
190
	 *
191
	 * @return Bulk_Delete The one true instance of Bulk_Delete
192
	 */
193 5
	public static function get_instance() {
194 5
		if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Bulk_Delete ) ) {
195 1
			self::$instance = new Bulk_Delete();
196
197 1
			self::$instance->setup_paths();
198 1
			self::$instance->includes();
199
		}
200
201 5
		return self::$instance;
202
	}
203
204
	/**
205
	 * Load the plugin if it is not loaded.
206
	 *
207
	 * This function will be invoked in the `plugins_loaded` hook.
208
	 */
209 1
	public function load() {
210 1
		if ( $this->loaded ) {
211
			return;
212
		}
213
214 1
		add_action( 'init', array( $this, 'on_init' ) );
215
216 1
		$this->load_dependencies();
217 1
		$this->setup_actions();
218
219 1
		$this->loaded = true;
220
221
		/**
222
		 * Bulk Delete plugin loaded.
223
		 *
224
		 * @since 5.7.0
225
		 */
226 1
		do_action( 'bd_loaded' );
227 1
	}
228
229
	/**
230
	 * Throw error on object clone.
231
	 *
232
	 * The whole idea of the singleton design pattern is that there is a single
233
	 * object therefore, we don't want the object to be cloned.
234
	 *
235
	 * @since  5.0
236
	 * @access protected
237
	 *
238
	 * @return void
239
	 */
240 1
	public function __clone() {
241
		// Cloning instances of the class is forbidden
242 1
		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'bulk-delete' ), '5.0' );
243 1
	}
244
245
	/**
246
	 * Disable unserializing of the class.
247
	 *
248
	 * @since  5.0
249
	 * @access protected
250
	 *
251
	 * @return void
252
	 */
253 1
	public function __wakeup() {
254
		// Unserializing instances of the class is forbidden
255 1
		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'bulk-delete' ), '5.0' );
256 1
	}
257
258
	/**
259
	 * Setup plugin constants.
260
	 *
261
	 * @access private
262
	 *
263
	 * @since  5.0
264
	 *
265
	 * @return void
266
	 */
267 1
	private function setup_paths() {
268
		// Plugin Folder Path
269 1
		self::$PLUGIN_DIR = plugin_dir_path( __FILE__ );
270
271
		// Plugin Folder URL
272 1
		self::$PLUGIN_URL = plugin_dir_url( __FILE__ );
273
274
		// Plugin Root File
275 1
		self::$PLUGIN_FILE = __FILE__;
276 1
	}
277
278
	/**
279
	 * Include required files.
280
	 *
281
	 * // TODO: Replace includes with autoloader.
282
	 *
283
	 * @access private
284
	 *
285
	 * @since  5.0
286
	 *
287
	 * @return void
288
	 */
289 1
	private function includes() {
290 1
		require_once self::$PLUGIN_DIR . '/include/Core/Base/BasePage.php';
291 1
		require_once self::$PLUGIN_DIR . '/include/Core/Base/MetaboxPage.php';
292 1
		require_once self::$PLUGIN_DIR . '/include/Core/Pages/DeletePagesPage.php';
293
294 1
		require_once self::$PLUGIN_DIR . '/include/Core/Base/BaseMetabox.php';
295 1
		require_once self::$PLUGIN_DIR . '/include/Core/Pages/PagesMetabox.php';
296 1
		require_once self::$PLUGIN_DIR . '/include/Core/Pages/Metabox/DeletePagesByStatusMetabox.php';
297
298 1
		require_once self::$PLUGIN_DIR . '/include/base/class-bd-meta-box-module.php';
299 1
		require_once self::$PLUGIN_DIR . '/include/base/users/class-bd-user-meta-box-module.php';
300 1
		require_once self::$PLUGIN_DIR . '/include/base/class-bd-base-page.php';
301 1
		require_once self::$PLUGIN_DIR . '/include/base/class-bd-page.php';
302
303 1
		require_once self::$PLUGIN_DIR . '/include/controller/class-bd-controller.php';
304
305 1
		require_once self::$PLUGIN_DIR . '/include/ui/form.php';
306
307 1
		require_once self::$PLUGIN_DIR . '/include/posts/class-bulk-delete-posts.php';
308
//		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...
309
310 1
		require_once self::$PLUGIN_DIR . '/include/users/class-bd-users-page.php';
311 1
		require_once self::$PLUGIN_DIR . '/include/users/modules/class-bulk-delete-users-by-user-role.php';
312 1
		require_once self::$PLUGIN_DIR . '/include/users/modules/class-bulk-delete-users-by-user-meta.php';
313
314 1
		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-meta.php';
315 1
		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-post-meta.php';
316 1
		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-comment-meta.php';
317 1
		require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-user-meta.php';
318
319 1
		require_once self::$PLUGIN_DIR . '/include/misc/class-bulk-delete-misc.php';
320 1
		require_once self::$PLUGIN_DIR . '/include/misc/class-bulk-delete-jetpack-contact-form-messages.php';
321
322 1
		require_once self::$PLUGIN_DIR . '/include/settings/class-bd-settings-page.php';
323 1
		require_once self::$PLUGIN_DIR . '/include/settings/setting-helpers.php';
324 1
		require_once self::$PLUGIN_DIR . '/include/settings/class-bd-settings.php';
325
326 1
		require_once self::$PLUGIN_DIR . '/include/system-info/class-bd-system-info-page.php';
327
328 1
		require_once self::$PLUGIN_DIR . '/include/util/class-bd-util.php';
329 1
		require_once self::$PLUGIN_DIR . '/include/util/query.php';
330
331 1
		require_once self::$PLUGIN_DIR . '/include/compatibility/simple-login-log.php';
332 1
		require_once self::$PLUGIN_DIR . '/include/compatibility/the-event-calendar.php';
333 1
		require_once self::$PLUGIN_DIR . '/include/compatibility/woocommerce.php';
334 1
		require_once self::$PLUGIN_DIR . '/include/compatibility/advanced-custom-fields-pro.php';
335
336 1
		require_once self::$PLUGIN_DIR . '/include/deprecated/class-bulk-delete-users.php';
337 1
		require_once self::$PLUGIN_DIR . '/include/deprecated/deprecated.php';
338
339 1
		require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-addon.php';
340 1
		require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-base-addon.php';
341 1
		require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-scheduler-addon.php';
342
343 1
		require_once self::$PLUGIN_DIR . '/include/addons/addon-list.php';
344 1
		require_once self::$PLUGIN_DIR . '/include/addons/posts.php';
345 1
		require_once self::$PLUGIN_DIR . '/include/addons/pages.php';
346 1
		require_once self::$PLUGIN_DIR . '/include/addons/util.php';
347
348 1
		require_once self::$PLUGIN_DIR . '/include/license/class-bd-license.php';
349 1
		require_once self::$PLUGIN_DIR . '/include/license/class-bd-license-handler.php';
350 1
		require_once self::$PLUGIN_DIR . '/include/license/class-bd-edd-api-wrapper.php';
351
352 1
		require_once self::$PLUGIN_DIR . '/include/ui/admin-ui.php';
353 1
		require_once self::$PLUGIN_DIR . '/include/ui/class-bulk-delete-help-screen.php';
354 1
	}
355
356
	/**
357
	 * Triggered when the `init` hook is fired.
358
	 *
359
	 * @since 5.7.0
360
	 */
361 1
	public function on_init() {
362 1
		$this->load_textdomain();
363 1
	}
364
365
	/**
366
	 * Loads the plugin language files.
367
	 *
368
	 * @since  5.0
369
	 */
370 1
	private function load_textdomain() {
371 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

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

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

530
		add_action( 'admin_print_scripts-' . /** @scrutinizer ignore-type */ $this->posts_page, array( $pages_page, 'enqueue_assets' ) );
Loading history...
531
//		add_action( 'admin_print_scripts-' . $this->pages_page, array( $this, 'add_script' ) );
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...
532
533
		// delete posts page
534
		add_action( "load-{$this->posts_page}", array( $this, 'add_delete_posts_settings_panel' ) );
535
		add_action( "add_meta_boxes_{$this->posts_page}", array( $this, 'add_delete_posts_meta_boxes' ) );
536
537
		// delete pages page
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% 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...
538
//		add_action( "load-{$this->pages_page}", array( $this, 'add_delete_pages_settings_panel' ) );
539
//		add_action( "add_meta_boxes_{$this->pages_page}", array( $this, 'add_delete_pages_meta_boxes' ) );
540
	}
541
542
	/**
543
	 * Add settings Panel for delete posts page.
544
	 */
545
	public function add_delete_posts_settings_panel() {
546
		/**
547
		 * Add contextual help for admin screens.
548
		 *
549
		 * @since 5.1
550
		 */
551
		do_action( 'bd_add_contextual_help', $this->posts_page );
552
553
		/* Trigger the add_meta_boxes hooks to allow meta boxes to be added */
554
		do_action( 'add_meta_boxes_' . $this->posts_page, null );
555
556
		/* Enqueue WordPress' script for handling the meta boxes */
557
		wp_enqueue_script( 'postbox' );
558
	}
559
560
	/**
561
	 * Ajax call back function for getting taxonomies to load select2 options.
562
	 *
563
	 * @since 5.7.0
564
	 */
565
	public function load_taxonomy_term(){
566
		$response = array();
567
568
		$taxonomy = sanitize_text_field( $_GET['taxonomy'] );
569
570
		$terms = get_terms( array(
571
			'taxonomy'   => $taxonomy,
572
			'hide_empty' => false,
573
			'search'     => sanitize_text_field($_GET['q']),
574
		) );
575
576
		if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
577
			foreach ( $terms as $term ) {
578
				$response[] = array( absint($term->term_id), $term->name . ' (' . $term->count . __( ' Posts', 'bulk-delete' ) . ')' );
579
			}
580
		}
581
582
		echo json_encode( $response );
583
		die;
0 ignored issues
show
Using exit here is not recommended.

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

Loading history...
584
	}
585
586
	/**
587
	 * Register meta boxes for delete posts page.
588
	 */
589
	public function add_delete_posts_meta_boxes() {
590
		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' );
591
		add_meta_box( self::BOX_CATEGORY      , __( 'By Category'          , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_category_box'  , $this->posts_page , 'advanced' );
592
		add_meta_box( self::BOX_TAG           , __( 'By Tag'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_tag_box'       , $this->posts_page , 'advanced' );
593
		add_meta_box( self::BOX_TAX           , __( 'By Custom Taxonomy'   , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_taxonomy_box'  , $this->posts_page , 'advanced' );
594
		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' );
595
		add_meta_box( self::BOX_URL           , __( 'By URL'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_url_box'       , $this->posts_page , 'advanced' );
596
		add_meta_box( self::BOX_POST_REVISION , __( 'By Post Revision'     , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_posts_by_revision_box'         , $this->posts_page , 'advanced' );
597
598
		/**
599
		 * Add meta box in delete posts page
600
		 * This hook can be used for adding additional meta boxes in delete posts page.
601
		 *
602
		 * @since 5.3
603
		 */
604
		do_action( 'bd_add_meta_box_for_posts' );
605
	}
606
607
	/**
608
	 * Setup settings panel for delete pages page.
609
	 *
610
	 * @since 5.0
611
	 */
612
	public function add_delete_pages_settings_panel() {
613
		/**
614
		 * Add contextual help for admin screens.
615
		 *
616
		 * @since 5.1
617
		 */
618
		do_action( 'bd_add_contextual_help', $this->pages_page );
619
620
		/* Trigger the add_meta_boxes hooks to allow meta boxes to be added */
621
		do_action( 'add_meta_boxes_' . $this->pages_page, null );
622
623
		/* Enqueue WordPress' script for handling the meta boxes */
624
		wp_enqueue_script( 'postbox' );
625
	}
626
627
	/**
628
	 * Register meta boxes for delete pages page.
629
	 *
630
	 * @since 5.0
631
	 */
632
	public function add_delete_pages_meta_boxes() {
633
		add_meta_box( self::BOX_PAGE_STATUS, __( 'By Page Status', 'bulk-delete' ), 'Bulk_Delete_Pages::render_delete_pages_by_status_box', $this->pages_page, 'advanced' );
634
635
		/**
636
		 * Add meta box in delete pages page
637
		 * This hook can be used for adding additional meta boxes in delete pages page.
638
		 *
639
		 * @since 5.3
640
		 */
641
		do_action( 'bd_add_meta_box_for_pages' );
642
	}
643
644
	/**
645
	 * Enqueue Scripts and Styles.
646
	 */
647
	public function add_script() {
648
		global $wp_scripts;
649
650
		/**
651
		 * Runs just before enqueuing scripts and styles in all Bulk WP admin pages.
652
		 *
653
		 * This action is primarily for registering or deregistering additional scripts or styles.
654
		 *
655
		 * @since 5.5.1
656
		 */
657
		do_action( 'bd_before_admin_enqueue_scripts' );
658
659
		wp_enqueue_script( 'jquery-ui-timepicker', plugins_url( '/assets/js/jquery-ui-timepicker-addon.min.js', __FILE__ ), array( 'jquery-ui-slider', 'jquery-ui-datepicker' ), '1.5.4', true );
660
		wp_enqueue_style( 'jquery-ui-timepicker', plugins_url( '/assets/css/jquery-ui-timepicker-addon.min.css', __FILE__ ), array(), '1.5.4' );
661
662
		wp_enqueue_script( 'select2', plugins_url( '/assets/js/select2.min.js', __FILE__ ), array( 'jquery' ), '4.0.0', true );
663
		wp_enqueue_style( 'select2', plugins_url( '/assets/css/select2.min.css', __FILE__ ), array(), '4.0.0' );
664
665
		$postfix = ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) ? '' : '.min';
666
		wp_enqueue_script( self::JS_HANDLE, plugins_url( '/assets/js/bulk-delete' . $postfix . '.js', __FILE__ ), array( 'jquery-ui-timepicker', 'jquery-ui-tooltip' ), self::VERSION, true );
667
		wp_enqueue_style( self::CSS_HANDLE, plugins_url( '/assets/css/bulk-delete' . $postfix . '.css', __FILE__ ), array( 'select2' ), self::VERSION );
668
669
		$ui  = $wp_scripts->query( 'jquery-ui-core' );
670
		$url = "//ajax.googleapis.com/ajax/libs/jqueryui/{$ui->ver}/themes/smoothness/jquery-ui.css";
671
		wp_enqueue_style( 'jquery-ui-smoothness', $url, false, $ui->ver );
0 ignored issues
show
false of type false is incompatible with the type array expected by parameter $deps of wp_enqueue_style(). ( Ignorable by Annotation )

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

671
		wp_enqueue_style( 'jquery-ui-smoothness', $url, /** @scrutinizer ignore-type */ false, $ui->ver );
Loading history...
672
673
		/**
674
		 * Filter JavaScript array.
675
		 *
676
		 * This filter can be used to extend the array that is passed to JavaScript
677
		 *
678
		 * @since 5.4
679
		 */
680
		$translation_array = apply_filters( 'bd_javascript_array', array(
681
				'msg'            => array(),
682
				'validators'     => array(),
683
				'dt_iterators'   => array(),
684
				'pre_action_msg' => array(),
685
				'error_msg'      => array(),
686
				'pro_iterators'  => array(),
687
			) );
688
		wp_localize_script( self::JS_HANDLE, self::JS_VARIABLE, $translation_array );
689
690
		/**
691
		 * Runs just after enqueuing scripts and styles in all Bulk WP admin pages.
692
		 *
693
		 * This action is primarily for registering additional scripts or styles.
694
		 *
695
		 * @since 5.5.1
696
		 */
697
		do_action( 'bd_after_admin_enqueue_scripts' );
698
	}
699
700
	/**
701
	 * Show the delete posts page.
702
	 *
703
	 * @Todo Move this function to Bulk_Delete_Posts class
704
	 */
705
	public function display_posts_page() {
706
?>
707
<div class="wrap">
708
    <h2><?php _e( 'Bulk Delete Posts', 'bulk-delete' );?></h2>
709
    <?php settings_errors(); ?>
710
711
    <form method = "post">
712
<?php
713
		// nonce for bulk delete
714
		wp_nonce_field( 'sm-bulk-delete-posts', 'sm-bulk-delete-posts-nonce' );
715
716
		/* Used to save closed meta boxes and their order */
717
		wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
718
		wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
719
?>
720
    <div id = "poststuff">
721
        <div id="post-body" class="metabox-holder columns-1">
722
723
            <div class="notice notice-warning">
724
                <p><strong><?php _e( 'WARNING: Posts deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p>
725
            </div>
726
727
            <div id="postbox-container-2" class="postbox-container">
728
                <?php do_meta_boxes( '', 'advanced', null ); ?>
729
            </div> <!-- #postbox-container-2 -->
730
731
        </div> <!-- #post-body -->
732
    </div><!-- #poststuff -->
733
    </form>
734
</div><!-- .wrap -->
735
736
<?php
737
		/**
738
		 * Runs just before displaying the footer text in the "Bulk Delete Posts" admin page.
739
		 *
740
		 * This action is primarily for adding extra content in the footer of "Bulk Delete Posts" admin page.
741
		 *
742
		 * @since 5.0
743
		 */
744
		do_action( 'bd_admin_footer_posts_page' );
745
	}
746
747
	/**
748
	 * Display the delete pages page.
749
	 *
750
	 * @Todo Move this function to Bulk_Delete_Pages class
751
	 *
752
	 * @since 5.0
753
	 */
754
	public function display_pages_page() {
755
?>
756
<div class="wrap">
757
    <h2><?php _e( 'Bulk Delete Pages', 'bulk-delete' );?></h2>
758
    <?php settings_errors(); ?>
759
760
    <form method = "post">
761
<?php
762
		// nonce for bulk delete
763
		wp_nonce_field( 'sm-bulk-delete-pages', 'sm-bulk-delete-pages-nonce' );
764
765
		/* Used to save closed meta boxes and their order */
766
		wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
767
		wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
768
?>
769
    <div id = "poststuff">
770
        <div id="post-body" class="metabox-holder columns-1">
771
772
            <div class="notice notice-warning">
773
                <p><strong><?php _e( 'WARNING: Pages deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p>
774
            </div>
775
776
            <div id="postbox-container-2" class="postbox-container">
777
                <?php do_meta_boxes( '', 'advanced', null ); ?>
778
            </div> <!-- #postbox-container-2 -->
779
780
        </div> <!-- #post-body -->
781
    </div><!-- #poststuff -->
782
    </form>
783
</div><!-- .wrap -->
784
785
<?php
786
		/**
787
		 * Runs just before displaying the footer text in the "Bulk Delete Pages" admin page.
788
		 *
789
		 * This action is primarily for adding extra content in the footer of "Bulk Delete Pages" admin page.
790
		 *
791
		 * @since 5.0
792
		 */
793
		do_action( 'bd_admin_footer_pages_page' );
794
	}
795
796
	/**
797
	 * Display the schedule page.
798
	 */
799
	public function display_cron_page() {
800
		if ( ! class_exists( 'WP_List_Table' ) ) {
801
			require_once ABSPATH . WPINC . '/class-wp-list-table.php';
802
		}
803
804
		if ( ! class_exists( 'Cron_List_Table' ) ) {
805
			require_once self::$PLUGIN_DIR . '/include/cron/class-cron-list-table.php';
806
		}
807
808
		// Prepare Table of elements
809
		$cron_list_table = new Cron_List_Table();
810
		$cron_list_table->prepare_items();
811
?>
812
    <div class="wrap">
813
        <h2><?php _e( 'Bulk Delete Schedules', 'bulk-delete' );?></h2>
814
        <?php settings_errors(); ?>
815
<?php
816
		// Table of elements
817
		$cron_list_table->display();
818
		bd_display_available_addon_list();
819
?>
820
    </div>
821
<?php
822
		/**
823
		 * Runs just before displaying the footer text in the "Schedules" admin page.
824
		 *
825
		 * This action is primarily for adding extra content in the footer of "Schedules" admin page.
826
		 *
827
		 * @since 5.0
828
		 */
829
		do_action( 'bd_admin_footer_cron_page' );
830
	}
831
832
	/**
833
	 * Get path to main plugin file.
834
	 *
835
	 * @return string Plugin file.
836
	 */
837 1
	public function get_plugin_file() {
838 1
		return $this->plugin_file;
839
	}
840
841
	/**
842
	 * Set path to main plugin file.
843
	 *
844
	 * @param string $plugin_file Path to main plugin file.
845
	 */
846 1
	public function set_plugin_file( $plugin_file ) {
847 1
		$this->plugin_file       = $plugin_file;
848 1
		$this->translations_path = dirname( plugin_basename( $this->get_plugin_file() ) ) . '/languages/';
849 1
	}
850
851
	/**
852
	 * Get path to translations.
853
	 *
854
	 * @return string Translations path.
855
	 */
856 1
	public function get_translations_path() {
857 1
		return $this->translations_path;
858
	}
859
}
860
861
/**
862
 * The main function responsible for returning the one true Bulk_Delete
863
 * Instance to functions everywhere.
864
 *
865
 * Use this function like you would a global variable, except without needing
866
 * to declare the global.
867
 *
868
 * Example: `<?php $bulk_delete = BULK_DELETE(); ?>`
869
 *
870
 * @since 5.0
871
 *
872
 * @return Bulk_Delete The one true Bulk_Delete Instance
873
 */
874
function BULK_DELETE() {
875 1
	return Bulk_Delete::get_instance();
876
}
877
878
/**
879
 * Load Bulk Delete plugin.
880
 *
881
 * @since 5.7.0
882
 */
883
function load_bulk_delete() {
884 1
	$bulk_delete = BULK_DELETE();
885 1
	$bulk_delete->set_plugin_file( __FILE__ );
886
887 1
	add_action( 'plugins_loaded', array( $bulk_delete, 'load' ), 101 );
888 1
}
889
890
load_bulk_delete();
891