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