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