Completed
Push — dev/6.0.0 ( d32e31...891eb3 )
by Sudar
06:46
created

Bulk_Delete::get_instance()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 3
rs 9.6666
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 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
	// 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 6.0.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 6.0.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() );
372 1
	}
373
374
	/**
375
	 * Load all dependencies.
376
	 *
377
	 * @since 6.0.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 6.0.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 ) {
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 6.0.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 6.0.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 6.0.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 6.0.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 );
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
495
		/**
496
		 * Runs just after adding all *delete* menu items to Bulk WP main menu.
497
		 *
498
		 * This action is primarily for adding extra *delete* menu items to the Bulk WP main menu.
499
		 *
500
		 * @since 5.3
501
		 */
502
		do_action( 'bd_after_primary_menus' );
503
504
		/**
505
		 * Runs just before adding non-action menu items to Bulk WP main menu.
506
		 *
507
		 * This action is primarily for adding extra menu items before non-action menu items to the Bulk WP main menu.
508
		 *
509
		 * @since 5.3
510
		 */
511
		do_action( 'bd_before_secondary_menus' );
512
513
		$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' ) );
514
		$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' ) );
515
516
		/**
517
		 * Runs just after adding all menu items to Bulk WP main menu.
518
		 *
519
		 * This action is primarily for adding extra menu items to the Bulk WP main menu.
520
		 *
521
		 * @since 5.3
522
		 */
523
		do_action( 'bd_after_all_menus' );
524
525
		$admin_pages = $this->get_admin_pages();
526
		$pages_page = $admin_pages['bulk-delete-pages'];
527
528
		// enqueue JavaScript
529
		add_action( 'admin_print_scripts-' . $this->posts_page, array( $pages_page, 'enqueue_assets' ) );
530
531
		// delete posts page
532
		add_action( "load-{$this->posts_page}", array( $this, 'add_delete_posts_settings_panel' ) );
533
		add_action( "add_meta_boxes_{$this->posts_page}", array( $this, 'add_delete_posts_meta_boxes' ) );
534
	}
535
536
	/**
537
	 * Add settings Panel for delete posts page.
538
	 */
539
	public function add_delete_posts_settings_panel() {
540
		/**
541
		 * Add contextual help for admin screens.
542
		 *
543
		 * @since 5.1
544
		 */
545
		do_action( 'bd_add_contextual_help', $this->posts_page );
546
547
		/* Trigger the add_meta_boxes hooks to allow meta boxes to be added */
548
		do_action( 'add_meta_boxes_' . $this->posts_page, null );
549
550
		/* Enqueue WordPress' script for handling the meta boxes */
551
		wp_enqueue_script( 'postbox' );
552
	}
553
554
	/**
555
	 * Ajax call back function for getting taxonomies to load select2 options.
556
	 *
557
	 * @since 6.0.0
558
	 */
559
	public function load_taxonomy_term(){
560
		$response = array();
561
562
		$taxonomy = sanitize_text_field( $_GET['taxonomy'] );
563
564
		$terms = get_terms( array(
565
			'taxonomy'   => $taxonomy,
566
			'hide_empty' => false,
567
			'search'     => sanitize_text_field($_GET['q']),
568
		) );
569
570
		if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
571
			foreach ( $terms as $term ) {
572
				$response[] = array( absint($term->term_id), $term->name . ' (' . $term->count . __( ' Posts', 'bulk-delete' ) . ')' );
573
			}
574
		}
575
576
		echo json_encode( $response );
577
		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...
578
	}
579
580
	/**
581
	 * Register meta boxes for delete posts page.
582
	 */
583
	public function add_delete_posts_meta_boxes() {
584
		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' );
585
		add_meta_box( self::BOX_CATEGORY      , __( 'By Category'          , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_category_box'  , $this->posts_page , 'advanced' );
586
		add_meta_box( self::BOX_TAG           , __( 'By Tag'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_tag_box'       , $this->posts_page , 'advanced' );
587
		add_meta_box( self::BOX_TAX           , __( 'By Custom Taxonomy'   , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_taxonomy_box'  , $this->posts_page , 'advanced' );
588
		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' );
589
		add_meta_box( self::BOX_URL           , __( 'By URL'               , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_url_box'       , $this->posts_page , 'advanced' );
590
		add_meta_box( self::BOX_POST_REVISION , __( 'By Post Revision'     , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_posts_by_revision_box'         , $this->posts_page , 'advanced' );
591
592
		/**
593
		 * Add meta box in delete posts page
594
		 * This hook can be used for adding additional meta boxes in delete posts page.
595
		 *
596
		 * @since 5.3
597
		 */
598
		do_action( 'bd_add_meta_box_for_posts' );
599
	}
600
601
	/**
602
	 * Enqueue Scripts and Styles.
603
	 */
604
	public function add_script() {
605
		// TODO: Remove this function.
606
607
		$admin_pages = $this->get_admin_pages();
608
		$pages_page = $admin_pages['bulk-delete-pages'];
609
		$pages_page->enqueue_assets();
610
	}
611
612
	/**
613
	 * Show the delete posts page.
614
	 *
615
	 * @Todo Move this function to Bulk_Delete_Posts class
616
	 */
617
	public function display_posts_page() {
618
?>
619
<div class="wrap">
620
    <h2><?php _e( 'Bulk Delete Posts', 'bulk-delete' );?></h2>
621
    <?php settings_errors(); ?>
622
623
    <form method = "post">
624
<?php
625
		// nonce for bulk delete
626
		wp_nonce_field( 'sm-bulk-delete-posts', 'sm-bulk-delete-posts-nonce' );
627
628
		/* Used to save closed meta boxes and their order */
629
		wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
630
		wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
631
?>
632
    <div id = "poststuff">
633
        <div id="post-body" class="metabox-holder columns-1">
634
635
            <div class="notice notice-warning">
636
                <p><strong><?php _e( 'WARNING: Posts deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p>
637
            </div>
638
639
            <div id="postbox-container-2" class="postbox-container">
640
                <?php do_meta_boxes( '', 'advanced', null ); ?>
641
            </div> <!-- #postbox-container-2 -->
642
643
        </div> <!-- #post-body -->
644
    </div><!-- #poststuff -->
645
    </form>
646
</div><!-- .wrap -->
647
648
<?php
649
		/**
650
		 * Runs just before displaying the footer text in the "Bulk Delete Posts" admin page.
651
		 *
652
		 * This action is primarily for adding extra content in the footer of "Bulk Delete Posts" admin page.
653
		 *
654
		 * @since 5.0
655
		 */
656
		do_action( 'bd_admin_footer_posts_page' );
657
	}
658
659
	/**
660
	 * Display the schedule page.
661
	 */
662
	public function display_cron_page() {
663
		if ( ! class_exists( 'WP_List_Table' ) ) {
664
			require_once ABSPATH . WPINC . '/class-wp-list-table.php';
665
		}
666
667
		if ( ! class_exists( 'Cron_List_Table' ) ) {
668
			require_once self::$PLUGIN_DIR . '/include/cron/class-cron-list-table.php';
669
		}
670
671
		// Prepare Table of elements
672
		$cron_list_table = new Cron_List_Table();
673
		$cron_list_table->prepare_items();
674
?>
675
    <div class="wrap">
676
        <h2><?php _e( 'Bulk Delete Schedules', 'bulk-delete' );?></h2>
677
        <?php settings_errors(); ?>
678
<?php
679
		// Table of elements
680
		$cron_list_table->display();
681
		bd_display_available_addon_list();
682
?>
683
    </div>
684
<?php
685
		/**
686
		 * Runs just before displaying the footer text in the "Schedules" admin page.
687
		 *
688
		 * This action is primarily for adding extra content in the footer of "Schedules" admin page.
689
		 *
690
		 * @since 5.0
691
		 */
692
		do_action( 'bd_admin_footer_cron_page' );
693
	}
694
695
	/**
696
	 * Get path to main plugin file.
697
	 *
698
	 * @return string Plugin file.
699
	 */
700
	public function get_plugin_file() {
701
		return $this->plugin_file;
702
	}
703
704
	/**
705
	 * Set path to main plugin file.
706
	 *
707
	 * @param string $plugin_file Path to main plugin file.
708
	 */
709
	public function set_plugin_file( $plugin_file ) {
710
		$this->plugin_file       = $plugin_file;
711
		$this->translations_path = dirname( plugin_basename( $this->get_plugin_file() ) ) . '/languages/';
712
	}
713
714
	/**
715
	 * Get path to translations.
716
	 *
717
	 * @return string Translations path.
718
	 */
719
	public function get_translations_path() {
720
		return $this->translations_path;
721
	}
722
}
723
724
/**
725
 * The main function responsible for returning the one true Bulk_Delete
726
 * Instance to functions everywhere.
727
 *
728
 * Use this function like you would a global variable, except without needing
729
 * to declare the global.
730
 *
731
 * Example: `<?php $bulk_delete = BULK_DELETE(); ?>`
732
 *
733
 * @since 5.0
734
 *
735
 * @return Bulk_Delete The one true Bulk_Delete Instance
736
 */
737
function BULK_DELETE() {
738
	return Bulk_Delete::get_instance();
739
}
740
741
/**
742
 * Load Bulk Delete plugin.
743
 *
744
 * @since 6.0.0
745
 */
746
function load_bulk_delete() {
747
	$bulk_delete = BULK_DELETE();
748
	$bulk_delete->set_plugin_file( __FILE__ );
749
750
	add_action( 'plugins_loaded', array( $bulk_delete, 'load' ), 101 );
751
}
752
753
load_bulk_delete();
754