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
|
|
|
/** |
19
|
|
|
* Copyright 2009 Sudar Muthu (email : [email protected]) |
20
|
|
|
* This program is free software; you can redistribute it and/or modify |
21
|
|
|
* it under the terms of the GNU General Public License, version 2, as |
22
|
|
|
* published by the Free Software Foundation. |
23
|
|
|
* |
24
|
|
|
* This program is distributed in the hope that it will be useful, |
25
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
26
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27
|
|
|
* GNU General Public License for more details. |
28
|
|
|
* |
29
|
|
|
* You should have received a copy of the GNU General Public License |
30
|
|
|
* along with this program; if not, write to the Free Software |
31
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
32
|
|
|
*/ |
33
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Main Bulk_Delete class. |
37
|
|
|
* |
38
|
|
|
* Singleton @since 5.0 |
39
|
|
|
*/ |
40
|
|
|
final class Bulk_Delete { |
41
|
|
|
/** |
42
|
|
|
* @var Bulk_Delete The one true Bulk_Delete |
43
|
|
|
* |
44
|
|
|
* @since 5.0 |
45
|
|
|
*/ |
46
|
|
|
private static $instance; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Is the plugin is loaded? |
50
|
|
|
* |
51
|
|
|
* @since 5.7.0 |
52
|
|
|
* |
53
|
|
|
* @var bool |
54
|
|
|
*/ |
55
|
|
|
private $loaded = false; |
56
|
|
|
|
57
|
|
|
private $controller; |
58
|
|
|
|
59
|
|
|
// version |
60
|
|
|
const VERSION = '5.6.1'; |
61
|
|
|
|
62
|
|
|
// Numeric constants |
63
|
|
|
const MENU_ORDER = '26'; |
64
|
|
|
|
65
|
|
|
// page slugs |
66
|
|
|
const POSTS_PAGE_SLUG = 'bulk-delete-posts'; |
67
|
|
|
const PAGES_PAGE_SLUG = 'bulk-delete-pages'; |
68
|
|
|
const CRON_PAGE_SLUG = 'bulk-delete-cron'; |
69
|
|
|
const ADDON_PAGE_SLUG = 'bulk-delete-addon'; |
70
|
|
|
|
71
|
|
|
// JS constants |
72
|
|
|
const JS_HANDLE = 'bulk-delete'; |
73
|
|
|
const JS_VARIABLE = 'BulkWP'; |
74
|
|
|
|
75
|
|
|
const CSS_HANDLE = 'bulk-delete'; |
76
|
|
|
|
77
|
|
|
// Cron hooks |
78
|
|
|
const CRON_HOOK_CATEGORY = 'do-bulk-delete-cat'; |
79
|
|
|
const CRON_HOOK_POST_STATUS = 'do-bulk-delete-post-status'; |
80
|
|
|
const CRON_HOOK_TAG = 'do-bulk-delete-tag'; |
81
|
|
|
const CRON_HOOK_TAXONOMY = 'do-bulk-delete-taxonomy'; |
82
|
|
|
const CRON_HOOK_POST_TYPE = 'do-bulk-delete-post-type'; |
83
|
|
|
const CRON_HOOK_CUSTOM_FIELD = 'do-bulk-delete-custom-field'; |
84
|
|
|
const CRON_HOOK_TITLE = 'do-bulk-delete-by-title'; |
85
|
|
|
const CRON_HOOK_DUPLICATE_TITLE = 'do-bulk-delete-by-duplicate-title'; |
86
|
|
|
const CRON_HOOK_POST_BY_ROLE = 'do-bulk-delete-posts-by-role'; |
87
|
|
|
|
88
|
|
|
const CRON_HOOK_PAGES_STATUS = 'do-bulk-delete-pages-by-status'; |
89
|
|
|
|
90
|
|
|
// meta boxes for delete posts |
91
|
|
|
const BOX_POST_STATUS = 'bd_by_post_status'; |
92
|
|
|
const BOX_CATEGORY = 'bd_by_category'; |
93
|
|
|
const BOX_TAG = 'bd_by_tag'; |
94
|
|
|
const BOX_TAX = 'bd_by_tax'; |
95
|
|
|
const BOX_POST_TYPE = 'bd_by_post_type'; |
96
|
|
|
const BOX_URL = 'bd_by_url'; |
97
|
|
|
const BOX_POST_REVISION = 'bd_by_post_revision'; |
98
|
|
|
const BOX_CUSTOM_FIELD = 'bd_by_custom_field'; |
99
|
|
|
const BOX_TITLE = 'bd_by_title'; |
100
|
|
|
const BOX_DUPLICATE_TITLE = 'bd_by_duplicate_title'; |
101
|
|
|
const BOX_POST_FROM_TRASH = 'bd_posts_from_trash'; |
102
|
|
|
const BOX_POST_BY_ROLE = 'bd_post_by_user_role'; |
103
|
|
|
|
104
|
|
|
// meta boxes for delete pages |
105
|
|
|
const BOX_PAGE_STATUS = 'bd_by_page_status'; |
106
|
|
|
const BOX_PAGE_FROM_TRASH = 'bd_pages_from_trash'; |
107
|
|
|
|
108
|
|
|
// Settings constants |
109
|
|
|
const SETTING_OPTION_GROUP = 'bd_settings'; |
110
|
|
|
const SETTING_OPTION_NAME = 'bd_licenses'; |
111
|
|
|
const SETTING_SECTION_ID = 'bd_license_section'; |
112
|
|
|
|
113
|
|
|
// Transient keys |
114
|
|
|
const LICENSE_CACHE_KEY_PREFIX = 'bd-license_'; |
115
|
|
|
|
116
|
|
|
const MAX_SELECT2_LIMIT = 50; |
117
|
|
|
|
118
|
|
|
// path variables |
119
|
|
|
// Ideally these should be constants, but because of PHP's limitations, these are static variables |
120
|
|
|
public static $PLUGIN_DIR; |
121
|
|
|
public static $PLUGIN_URL; |
122
|
|
|
public static $PLUGIN_FILE; |
123
|
|
|
|
124
|
|
|
// Instance variables |
125
|
|
|
public $translations; |
126
|
|
|
public $posts_page; |
127
|
|
|
public $pages_page; |
128
|
|
|
public $cron_page; |
129
|
|
|
public $addon_page; |
130
|
|
|
public $settings_page; |
131
|
|
|
public $meta_page; |
132
|
|
|
public $misc_page; |
133
|
|
|
public $display_activate_license_form = false; |
134
|
|
|
|
135
|
|
|
// Deprecated. |
136
|
|
|
// Will be removed in v6.0 |
137
|
|
|
const CRON_HOOK_USER_ROLE = 'do-bulk-delete-users-by-role'; |
138
|
|
|
public $users_page; |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Main Bulk_Delete Instance. |
142
|
|
|
* |
143
|
|
|
* Insures that only one instance of Bulk_Delete exists in memory at any one |
144
|
|
|
* time. Also prevents needing to define globals all over the place. |
145
|
|
|
* |
146
|
|
|
* @since 5.0 |
147
|
|
|
* @static |
148
|
|
|
* @staticvar array $instance |
149
|
|
|
* |
150
|
|
|
* @see BULK_DELETE() |
151
|
|
|
* |
152
|
|
|
* @uses Bulk_Delete::setup_paths() Setup the plugin paths |
153
|
|
|
* @uses Bulk_Delete::includes() Include the required files |
154
|
|
|
* @uses Bulk_Delete::load_textdomain() Load text domain for translation |
155
|
|
|
* @uses Bulk_Delete::setup_actions() Setup the hooks and actions |
156
|
|
|
* |
157
|
|
|
* @return Bulk_Delete The one true instance of Bulk_Delete |
158
|
|
|
*/ |
159
|
5 |
|
public static function get_instance() { |
160
|
5 |
|
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Bulk_Delete ) ) { |
161
|
1 |
|
self::$instance = new Bulk_Delete(); |
162
|
|
|
|
163
|
1 |
|
self::$instance->setup_paths(); |
164
|
1 |
|
self::$instance->includes(); |
165
|
|
|
} |
166
|
|
|
|
167
|
5 |
|
return self::$instance; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Load the plugin if it is not loaded. |
172
|
|
|
* |
173
|
|
|
* This function will be invoked in the `plugins_loaded` hook. |
174
|
|
|
*/ |
175
|
1 |
|
public function load() { |
176
|
1 |
|
if ( $this->loaded ) { |
177
|
|
|
return; |
178
|
|
|
} |
179
|
|
|
|
180
|
1 |
|
add_action( 'init', array( $this, 'on_init' ) ); |
181
|
|
|
|
182
|
1 |
|
$this->setup_actions(); |
183
|
|
|
|
184
|
1 |
|
$this->loaded = true; |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Bulk Delete plugin loaded. |
188
|
|
|
* |
189
|
|
|
* @since 5.7.0 |
190
|
|
|
*/ |
191
|
1 |
|
do_action( 'bd_loaded' ); |
192
|
1 |
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Throw error on object clone. |
196
|
|
|
* |
197
|
|
|
* The whole idea of the singleton design pattern is that there is a single |
198
|
|
|
* object therefore, we don't want the object to be cloned. |
199
|
|
|
* |
200
|
|
|
* @since 5.0 |
201
|
|
|
* @access protected |
202
|
|
|
* |
203
|
|
|
* @return void |
204
|
|
|
*/ |
205
|
1 |
|
public function __clone() { |
206
|
|
|
// Cloning instances of the class is forbidden |
207
|
1 |
|
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bulk-delete' ), '5.0' ); |
208
|
1 |
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Disable unserializing of the class. |
212
|
|
|
* |
213
|
|
|
* @since 5.0 |
214
|
|
|
* @access protected |
215
|
|
|
* |
216
|
|
|
* @return void |
217
|
|
|
*/ |
218
|
1 |
|
public function __wakeup() { |
219
|
|
|
// Unserializing instances of the class is forbidden |
220
|
1 |
|
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bulk-delete' ), '5.0' ); |
221
|
1 |
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Setup plugin constants. |
225
|
|
|
* |
226
|
|
|
* @access private |
227
|
|
|
* |
228
|
|
|
* @since 5.0 |
229
|
|
|
* |
230
|
|
|
* @return void |
231
|
|
|
*/ |
232
|
1 |
|
private function setup_paths() { |
233
|
|
|
// Plugin Folder Path |
234
|
1 |
|
self::$PLUGIN_DIR = plugin_dir_path( __FILE__ ); |
235
|
|
|
|
236
|
|
|
// Plugin Folder URL |
237
|
1 |
|
self::$PLUGIN_URL = plugin_dir_url( __FILE__ ); |
238
|
|
|
|
239
|
|
|
// Plugin Root File |
240
|
1 |
|
self::$PLUGIN_FILE = __FILE__; |
241
|
1 |
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Include required files. |
245
|
|
|
* |
246
|
|
|
* @access private |
247
|
|
|
* |
248
|
|
|
* @since 5.0 |
249
|
|
|
* |
250
|
|
|
* @return void |
251
|
|
|
*/ |
252
|
1 |
|
private function includes() { |
253
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/base/class-bd-meta-box-module.php'; |
254
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/base/users/class-bd-user-meta-box-module.php'; |
255
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/base/class-bd-base-page.php'; |
256
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/base/class-bd-page.php'; |
257
|
|
|
|
258
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/controller/class-bd-controller.php'; |
259
|
|
|
|
260
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/ui/form.php'; |
261
|
|
|
|
262
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/posts/class-bulk-delete-posts.php'; |
263
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/pages/class-bulk-delete-pages.php'; |
264
|
|
|
|
265
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/users/class-bd-users-page.php'; |
266
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/users/modules/class-bulk-delete-users-by-user-role.php'; |
267
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/users/modules/class-bulk-delete-users-by-user-meta.php'; |
268
|
|
|
|
269
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-meta.php'; |
270
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-post-meta.php'; |
271
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-comment-meta.php'; |
272
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/meta/class-bulk-delete-user-meta.php'; |
273
|
|
|
|
274
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/misc/class-bulk-delete-misc.php'; |
275
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/misc/class-bulk-delete-jetpack-contact-form-messages.php'; |
276
|
|
|
|
277
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/settings/class-bd-settings-page.php'; |
278
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/settings/setting-helpers.php'; |
279
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/settings/class-bd-settings.php'; |
280
|
|
|
|
281
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/system-info/class-bd-system-info-page.php'; |
282
|
|
|
|
283
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/util/class-bd-util.php'; |
284
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/util/query.php'; |
285
|
|
|
|
286
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/compatibility/simple-login-log.php'; |
287
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/compatibility/the-event-calendar.php'; |
288
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/compatibility/woocommerce.php'; |
289
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/compatibility/advanced-custom-fields-pro.php'; |
290
|
|
|
|
291
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/deprecated/class-bulk-delete-users.php'; |
292
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/deprecated/deprecated.php'; |
293
|
|
|
|
294
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-addon.php'; |
295
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-base-addon.php'; |
296
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/addons/base/class-bd-scheduler-addon.php'; |
297
|
|
|
|
298
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/addons/addon-list.php'; |
299
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/addons/posts.php'; |
300
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/addons/pages.php'; |
301
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/addons/util.php'; |
302
|
|
|
|
303
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/license/class-bd-license.php'; |
304
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/license/class-bd-license-handler.php'; |
305
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/license/class-bd-edd-api-wrapper.php'; |
306
|
|
|
|
307
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/ui/admin-ui.php'; |
308
|
1 |
|
require_once self::$PLUGIN_DIR . '/include/ui/class-bulk-delete-help-screen.php'; |
309
|
1 |
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Triggered when the `init` hook is fired. |
313
|
|
|
* |
314
|
|
|
* @since 5.7.0 |
315
|
|
|
*/ |
316
|
1 |
|
public function on_init() { |
317
|
1 |
|
$this->load_textdomain(); |
318
|
1 |
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Loads the plugin language files. |
322
|
|
|
* |
323
|
|
|
* @since 5.0 |
324
|
|
|
*/ |
325
|
1 |
|
private function load_textdomain() { |
326
|
|
|
// Load localization domain |
327
|
1 |
|
$this->translations = dirname( plugin_basename( self::$PLUGIN_FILE ) ) . '/languages/'; |
328
|
1 |
|
load_plugin_textdomain( 'bulk-delete', false, $this->translations ); |
|
|
|
|
329
|
1 |
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Loads the plugin's actions and hooks. |
333
|
|
|
* |
334
|
|
|
* @access private |
335
|
|
|
* |
336
|
|
|
* @since 5.0 |
337
|
|
|
* |
338
|
|
|
* @return void |
339
|
|
|
*/ |
340
|
1 |
|
private function setup_actions() { |
341
|
1 |
|
$this->controller = new BD_Controller(); |
342
|
|
|
|
343
|
1 |
|
add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* This is Ajax hook, It's runs when user search categories or tags on bulk-delete-posts page |
347
|
|
|
* |
348
|
|
|
* @since 5.7.0 |
349
|
|
|
*/ |
350
|
1 |
|
add_action( 'wp_ajax_load_taxonomy_term', array( $this, 'load_taxonomy_term' ) ); |
351
|
|
|
|
352
|
1 |
|
add_filter( 'bd_help_tooltip', 'bd_generate_help_tooltip', 10, 2 ); |
353
|
|
|
|
354
|
1 |
|
if ( defined( 'BD_DEBUG' ) && BD_DEBUG ) { |
|
|
|
|
355
|
|
|
add_action( 'bd_after_query', array( $this, 'log_sql_query' ) ); |
356
|
|
|
} |
357
|
1 |
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* Log SQL query used by Bulk Delete. |
361
|
|
|
* |
362
|
|
|
* Query is logged only when `BD_DEBUG` is set. |
363
|
|
|
* |
364
|
|
|
* @since 5.6 |
365
|
|
|
* |
366
|
|
|
* @param \WP_Query $wp_query WP Query object. |
367
|
|
|
*/ |
368
|
|
|
public function log_sql_query( $wp_query ) { |
369
|
|
|
$query = $wp_query->request; |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* Bulk Delete query is getting logged. |
373
|
|
|
* |
374
|
|
|
* @since 5.6 |
375
|
|
|
* |
376
|
|
|
* @param string $query Bulk Delete SQL Query. |
377
|
|
|
*/ |
378
|
|
|
do_action( 'bd_log_sql_query', $query ); |
379
|
|
|
|
380
|
|
|
error_log( 'Bulk Delete Query: ' . $query ); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Add navigation menu. |
385
|
|
|
*/ |
386
|
|
|
public function add_menu() { |
387
|
|
|
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 ); |
|
|
|
|
388
|
|
|
|
389
|
|
|
$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' ) ); |
390
|
|
|
$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' ) ); |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Runs just after adding all *delete* menu items to Bulk WP main menu. |
394
|
|
|
* |
395
|
|
|
* This action is primarily for adding extra *delete* menu items to the Bulk WP main menu. |
396
|
|
|
* |
397
|
|
|
* @since 5.3 |
398
|
|
|
*/ |
399
|
|
|
do_action( 'bd_after_primary_menus' ); |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Runs just before adding non-action menu items to Bulk WP main menu. |
403
|
|
|
* |
404
|
|
|
* This action is primarily for adding extra menu items before non-action menu items to the Bulk WP main menu. |
405
|
|
|
* |
406
|
|
|
* @since 5.3 |
407
|
|
|
*/ |
408
|
|
|
do_action( 'bd_before_secondary_menus' ); |
409
|
|
|
|
410
|
|
|
$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' ) ); |
411
|
|
|
$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' ) ); |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* Runs just after adding all menu items to Bulk WP main menu. |
415
|
|
|
* |
416
|
|
|
* This action is primarily for adding extra menu items to the Bulk WP main menu. |
417
|
|
|
* |
418
|
|
|
* @since 5.3 |
419
|
|
|
*/ |
420
|
|
|
do_action( 'bd_after_all_menus' ); |
421
|
|
|
|
422
|
|
|
// enqueue JavaScript |
423
|
|
|
add_action( 'admin_print_scripts-' . $this->posts_page, array( $this, 'add_script' ) ); |
|
|
|
|
424
|
|
|
add_action( 'admin_print_scripts-' . $this->pages_page, array( $this, 'add_script' ) ); |
|
|
|
|
425
|
|
|
|
426
|
|
|
// delete posts page |
427
|
|
|
add_action( "load-{$this->posts_page}", array( $this, 'add_delete_posts_settings_panel' ) ); |
428
|
|
|
add_action( "add_meta_boxes_{$this->posts_page}", array( $this, 'add_delete_posts_meta_boxes' ) ); |
429
|
|
|
|
430
|
|
|
// delete pages page |
431
|
|
|
add_action( "load-{$this->pages_page}", array( $this, 'add_delete_pages_settings_panel' ) ); |
432
|
|
|
add_action( "add_meta_boxes_{$this->pages_page}", array( $this, 'add_delete_pages_meta_boxes' ) ); |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* Add settings Panel for delete posts page. |
437
|
|
|
*/ |
438
|
|
|
public function add_delete_posts_settings_panel() { |
439
|
|
|
/** |
440
|
|
|
* Add contextual help for admin screens. |
441
|
|
|
* |
442
|
|
|
* @since 5.1 |
443
|
|
|
*/ |
444
|
|
|
do_action( 'bd_add_contextual_help', $this->posts_page ); |
445
|
|
|
|
446
|
|
|
/* Trigger the add_meta_boxes hooks to allow meta boxes to be added */ |
447
|
|
|
do_action( 'add_meta_boxes_' . $this->posts_page, null ); |
448
|
|
|
|
449
|
|
|
/* Enqueue WordPress' script for handling the meta boxes */ |
450
|
|
|
wp_enqueue_script( 'postbox' ); |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* Ajax call back function for getting taxonomies to load select2 options. |
455
|
|
|
* |
456
|
|
|
* @since 5.7.0 |
457
|
|
|
*/ |
458
|
|
|
public function load_taxonomy_term(){ |
459
|
|
|
$response = array(); |
460
|
|
|
|
461
|
|
|
$taxonomy = sanitize_text_field( $_GET['taxonomy'] ); |
462
|
|
|
|
463
|
|
|
$terms = get_terms( array( |
464
|
|
|
'taxonomy' => $taxonomy, |
465
|
|
|
'hide_empty' => false, |
466
|
|
|
'search' => $_GET['q'] |
467
|
|
|
) ); |
468
|
|
|
|
469
|
|
|
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ |
470
|
|
|
foreach ( $terms as $term ) { |
471
|
|
|
$response[] = array( absint($term->term_id), $term->name.' ('. $term->count. __( ' Posts', 'bulk-delete' ) . ')' ); |
472
|
|
|
} |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
echo json_encode( $response ); |
476
|
|
|
die; |
|
|
|
|
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* Register meta boxes for delete posts page. |
481
|
|
|
*/ |
482
|
|
|
public function add_delete_posts_meta_boxes() { |
483
|
|
|
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' ); |
484
|
|
|
add_meta_box( self::BOX_CATEGORY , __( 'By Category' , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_category_box' , $this->posts_page , 'advanced' ); |
485
|
|
|
add_meta_box( self::BOX_TAG , __( 'By Tag' , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_tag_box' , $this->posts_page , 'advanced' ); |
486
|
|
|
add_meta_box( self::BOX_TAX , __( 'By Custom Taxonomy' , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_taxonomy_box' , $this->posts_page , 'advanced' ); |
487
|
|
|
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' ); |
488
|
|
|
add_meta_box( self::BOX_URL , __( 'By URL' , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_delete_posts_by_url_box' , $this->posts_page , 'advanced' ); |
489
|
|
|
add_meta_box( self::BOX_POST_REVISION , __( 'By Post Revision' , 'bulk-delete' ) , 'Bulk_Delete_Posts::render_posts_by_revision_box' , $this->posts_page , 'advanced' ); |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* Add meta box in delete posts page |
493
|
|
|
* This hook can be used for adding additional meta boxes in delete posts page. |
494
|
|
|
* |
495
|
|
|
* @since 5.3 |
496
|
|
|
*/ |
497
|
|
|
do_action( 'bd_add_meta_box_for_posts' ); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
/** |
501
|
|
|
* Setup settings panel for delete pages page. |
502
|
|
|
* |
503
|
|
|
* @since 5.0 |
504
|
|
|
*/ |
505
|
|
|
public function add_delete_pages_settings_panel() { |
506
|
|
|
/** |
507
|
|
|
* Add contextual help for admin screens. |
508
|
|
|
* |
509
|
|
|
* @since 5.1 |
510
|
|
|
*/ |
511
|
|
|
do_action( 'bd_add_contextual_help', $this->pages_page ); |
512
|
|
|
|
513
|
|
|
/* Trigger the add_meta_boxes hooks to allow meta boxes to be added */ |
514
|
|
|
do_action( 'add_meta_boxes_' . $this->pages_page, null ); |
515
|
|
|
|
516
|
|
|
/* Enqueue WordPress' script for handling the meta boxes */ |
517
|
|
|
wp_enqueue_script( 'postbox' ); |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* Register meta boxes for delete pages page. |
522
|
|
|
* |
523
|
|
|
* @since 5.0 |
524
|
|
|
*/ |
525
|
|
|
public function add_delete_pages_meta_boxes() { |
526
|
|
|
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' ); |
527
|
|
|
|
528
|
|
|
/** |
529
|
|
|
* Add meta box in delete pages page |
530
|
|
|
* This hook can be used for adding additional meta boxes in delete pages page. |
531
|
|
|
* |
532
|
|
|
* @since 5.3 |
533
|
|
|
*/ |
534
|
|
|
do_action( 'bd_add_meta_box_for_pages' ); |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
/** |
538
|
|
|
* Enqueue Scripts and Styles. |
539
|
|
|
*/ |
540
|
|
|
public function add_script() { |
541
|
|
|
global $wp_scripts; |
542
|
|
|
|
543
|
|
|
/** |
544
|
|
|
* Runs just before enqueuing scripts and styles in all Bulk WP admin pages. |
545
|
|
|
* |
546
|
|
|
* This action is primarily for registering or deregistering additional scripts or styles. |
547
|
|
|
* |
548
|
|
|
* @since 5.5.1 |
549
|
|
|
*/ |
550
|
|
|
do_action( 'bd_before_admin_enqueue_scripts' ); |
551
|
|
|
|
552
|
|
|
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 ); |
553
|
|
|
wp_enqueue_style( 'jquery-ui-timepicker', plugins_url( '/assets/css/jquery-ui-timepicker-addon.min.css', __FILE__ ), array(), '1.5.4' ); |
554
|
|
|
|
555
|
|
|
wp_enqueue_script( 'select2', plugins_url( '/assets/js/select2.min.js', __FILE__ ), array( 'jquery' ), '4.0.0', true ); |
556
|
|
|
wp_enqueue_style( 'select2', plugins_url( '/assets/css/select2.min.css', __FILE__ ), array(), '4.0.0' ); |
557
|
|
|
|
558
|
|
|
$postfix = ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) ? '' : '.min'; |
559
|
|
|
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 ); |
560
|
|
|
wp_enqueue_style( self::CSS_HANDLE, plugins_url( '/assets/css/bulk-delete' . $postfix . '.css', __FILE__ ), array( 'select2' ), self::VERSION ); |
561
|
|
|
|
562
|
|
|
$ui = $wp_scripts->query( 'jquery-ui-core' ); |
563
|
|
|
$url = "//ajax.googleapis.com/ajax/libs/jqueryui/{$ui->ver}/themes/smoothness/jquery-ui.css"; |
564
|
|
|
wp_enqueue_style( 'jquery-ui-smoothness', $url, false, $ui->ver ); |
|
|
|
|
565
|
|
|
|
566
|
|
|
/** |
567
|
|
|
* Filter JavaScript array. |
568
|
|
|
* |
569
|
|
|
* This filter can be used to extend the array that is passed to JavaScript |
570
|
|
|
* |
571
|
|
|
* @since 5.4 |
572
|
|
|
*/ |
573
|
|
|
$translation_array = apply_filters( 'bd_javascript_array', array( |
574
|
|
|
'msg' => array(), |
575
|
|
|
'validators' => array(), |
576
|
|
|
'dt_iterators' => array(), |
577
|
|
|
'pre_action_msg' => array(), |
578
|
|
|
'error_msg' => array(), |
579
|
|
|
'pro_iterators' => array(), |
580
|
|
|
) ); |
581
|
|
|
wp_localize_script( self::JS_HANDLE, self::JS_VARIABLE, $translation_array ); |
582
|
|
|
|
583
|
|
|
/** |
584
|
|
|
* Runs just after enqueuing scripts and styles in all Bulk WP admin pages. |
585
|
|
|
* |
586
|
|
|
* This action is primarily for registering additional scripts or styles. |
587
|
|
|
* |
588
|
|
|
* @since 5.5.1 |
589
|
|
|
*/ |
590
|
|
|
do_action( 'bd_after_admin_enqueue_scripts' ); |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
/** |
594
|
|
|
* Show the delete posts page. |
595
|
|
|
* |
596
|
|
|
* @Todo Move this function to Bulk_Delete_Posts class |
597
|
|
|
*/ |
598
|
|
|
public function display_posts_page() { |
599
|
|
|
?> |
600
|
|
|
<div class="wrap"> |
601
|
|
|
<h2><?php _e( 'Bulk Delete Posts', 'bulk-delete' );?></h2> |
602
|
|
|
<?php settings_errors(); ?> |
603
|
|
|
|
604
|
|
|
<form method = "post"> |
605
|
|
|
<?php |
606
|
|
|
// nonce for bulk delete |
607
|
|
|
wp_nonce_field( 'sm-bulk-delete-posts', 'sm-bulk-delete-posts-nonce' ); |
608
|
|
|
|
609
|
|
|
/* Used to save closed meta boxes and their order */ |
610
|
|
|
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); |
611
|
|
|
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); |
612
|
|
|
?> |
613
|
|
|
<div id = "poststuff"> |
614
|
|
|
<div id="post-body" class="metabox-holder columns-1"> |
615
|
|
|
|
616
|
|
|
<div class="notice notice-warning"> |
617
|
|
|
<p><strong><?php _e( 'WARNING: Posts deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p> |
618
|
|
|
</div> |
619
|
|
|
|
620
|
|
|
<div id="postbox-container-2" class="postbox-container"> |
621
|
|
|
<?php do_meta_boxes( '', 'advanced', null ); ?> |
622
|
|
|
</div> <!-- #postbox-container-2 --> |
623
|
|
|
|
624
|
|
|
</div> <!-- #post-body --> |
625
|
|
|
</div><!-- #poststuff --> |
626
|
|
|
</form> |
627
|
|
|
</div><!-- .wrap --> |
628
|
|
|
|
629
|
|
|
<?php |
630
|
|
|
/** |
631
|
|
|
* Runs just before displaying the footer text in the "Bulk Delete Posts" admin page. |
632
|
|
|
* |
633
|
|
|
* This action is primarily for adding extra content in the footer of "Bulk Delete Posts" admin page. |
634
|
|
|
* |
635
|
|
|
* @since 5.0 |
636
|
|
|
*/ |
637
|
|
|
do_action( 'bd_admin_footer_posts_page' ); |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
/** |
641
|
|
|
* Display the delete pages page. |
642
|
|
|
* |
643
|
|
|
* @Todo Move this function to Bulk_Delete_Pages class |
644
|
|
|
* |
645
|
|
|
* @since 5.0 |
646
|
|
|
*/ |
647
|
|
|
public function display_pages_page() { |
648
|
|
|
?> |
649
|
|
|
<div class="wrap"> |
650
|
|
|
<h2><?php _e( 'Bulk Delete Pages', 'bulk-delete' );?></h2> |
651
|
|
|
<?php settings_errors(); ?> |
652
|
|
|
|
653
|
|
|
<form method = "post"> |
654
|
|
|
<?php |
655
|
|
|
// nonce for bulk delete |
656
|
|
|
wp_nonce_field( 'sm-bulk-delete-pages', 'sm-bulk-delete-pages-nonce' ); |
657
|
|
|
|
658
|
|
|
/* Used to save closed meta boxes and their order */ |
659
|
|
|
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); |
660
|
|
|
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); |
661
|
|
|
?> |
662
|
|
|
<div id = "poststuff"> |
663
|
|
|
<div id="post-body" class="metabox-holder columns-1"> |
664
|
|
|
|
665
|
|
|
<div class="notice notice-warning"> |
666
|
|
|
<p><strong><?php _e( 'WARNING: Pages deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p> |
667
|
|
|
</div> |
668
|
|
|
|
669
|
|
|
<div id="postbox-container-2" class="postbox-container"> |
670
|
|
|
<?php do_meta_boxes( '', 'advanced', null ); ?> |
671
|
|
|
</div> <!-- #postbox-container-2 --> |
672
|
|
|
|
673
|
|
|
</div> <!-- #post-body --> |
674
|
|
|
</div><!-- #poststuff --> |
675
|
|
|
</form> |
676
|
|
|
</div><!-- .wrap --> |
677
|
|
|
|
678
|
|
|
<?php |
679
|
|
|
/** |
680
|
|
|
* Runs just before displaying the footer text in the "Bulk Delete Pages" admin page. |
681
|
|
|
* |
682
|
|
|
* This action is primarily for adding extra content in the footer of "Bulk Delete Pages" admin page. |
683
|
|
|
* |
684
|
|
|
* @since 5.0 |
685
|
|
|
*/ |
686
|
|
|
do_action( 'bd_admin_footer_pages_page' ); |
687
|
|
|
} |
688
|
|
|
|
689
|
|
|
/** |
690
|
|
|
* Display the schedule page. |
691
|
|
|
*/ |
692
|
|
|
public function display_cron_page() { |
693
|
|
|
if ( ! class_exists( 'WP_List_Table' ) ) { |
694
|
|
|
require_once ABSPATH . WPINC . '/class-wp-list-table.php'; |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
if ( ! class_exists( 'Cron_List_Table' ) ) { |
698
|
|
|
require_once self::$PLUGIN_DIR . '/include/cron/class-cron-list-table.php'; |
699
|
|
|
} |
700
|
|
|
|
701
|
|
|
// Prepare Table of elements |
702
|
|
|
$cron_list_table = new Cron_List_Table(); |
703
|
|
|
$cron_list_table->prepare_items(); |
704
|
|
|
?> |
705
|
|
|
<div class="wrap"> |
706
|
|
|
<h2><?php _e( 'Bulk Delete Schedules', 'bulk-delete' );?></h2> |
707
|
|
|
<?php settings_errors(); ?> |
708
|
|
|
<?php |
709
|
|
|
// Table of elements |
710
|
|
|
$cron_list_table->display(); |
711
|
|
|
bd_display_available_addon_list(); |
712
|
|
|
?> |
713
|
|
|
</div> |
714
|
|
|
<?php |
715
|
|
|
/** |
716
|
|
|
* Runs just before displaying the footer text in the "Schedules" admin page. |
717
|
|
|
* |
718
|
|
|
* This action is primarily for adding extra content in the footer of "Schedules" admin page. |
719
|
|
|
* |
720
|
|
|
* @since 5.0 |
721
|
|
|
*/ |
722
|
|
|
do_action( 'bd_admin_footer_cron_page' ); |
723
|
|
|
} |
724
|
|
|
} |
725
|
|
|
|
726
|
|
|
/** |
727
|
|
|
* The main function responsible for returning the one true Bulk_Delete |
728
|
|
|
* Instance to functions everywhere. |
729
|
|
|
* |
730
|
|
|
* Use this function like you would a global variable, except without needing |
731
|
|
|
* to declare the global. |
732
|
|
|
* |
733
|
|
|
* Example: `<?php $bulk_delete = BULK_DELETE(); ?>` |
734
|
|
|
* |
735
|
|
|
* @since 5.0 |
736
|
|
|
* |
737
|
|
|
* @return Bulk_Delete The one true Bulk_Delete Instance |
738
|
|
|
*/ |
739
|
|
|
function BULK_DELETE() { |
740
|
1 |
|
return Bulk_Delete::get_instance(); |
741
|
|
|
} |
742
|
|
|
|
743
|
|
|
/** |
744
|
|
|
* Load Bulk Delete plugin. |
745
|
|
|
* |
746
|
|
|
* @since 5.7.0 |
747
|
|
|
*/ |
748
|
|
|
function load_bulk_delete() { |
749
|
1 |
|
$bulk_delete = BULK_DELETE(); |
750
|
|
|
|
751
|
1 |
|
add_action( 'plugins_loaded', array( $bulk_delete, 'load' ), 101 ); |
752
|
1 |
|
} |
753
|
|
|
|
754
|
|
|
load_bulk_delete(); |
755
|
|
|
|