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