1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Old version of Bulk_Delete. |
4
|
|
|
* |
5
|
|
|
* This class is deprecated since 6.0.0. But included here for backward compatibility. |
6
|
|
|
* Don't depend on functionality from this class. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
use BulkWP\BulkDelete\Core\BulkDelete; |
10
|
|
|
|
11
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Main Bulk_Delete class. |
15
|
|
|
* |
16
|
|
|
* @since 5.0 Singleton |
17
|
|
|
* @since 6.0.0 Deprecated. |
18
|
|
|
*/ |
19
|
|
|
final class Bulk_Delete { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The one true Bulk_Delete instance. |
23
|
|
|
* |
24
|
|
|
* @var Bulk_Delete |
25
|
|
|
* |
26
|
|
|
* @since 5.0 |
27
|
|
|
*/ |
28
|
|
|
private static $instance; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Path to the main plugin file. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $plugin_file; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Path where translations are stored. |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $translations_path; |
|
|
|
|
43
|
|
|
|
44
|
|
|
// version |
45
|
|
|
const VERSION = '5.6.1'; |
46
|
|
|
|
47
|
|
|
// page slugs |
48
|
|
|
const POSTS_PAGE_SLUG = 'bulk-delete-posts'; |
49
|
|
|
const PAGES_PAGE_SLUG = 'bulk-delete-pages'; |
50
|
|
|
const CRON_PAGE_SLUG = 'bulk-delete-cron'; |
51
|
|
|
const ADDON_PAGE_SLUG = 'bulk-delete-addon'; |
52
|
|
|
|
53
|
|
|
// JS constants |
54
|
|
|
const JS_HANDLE = 'bulk-delete'; |
55
|
|
|
const CSS_HANDLE = 'bulk-delete'; |
56
|
|
|
|
57
|
|
|
// Cron hooks |
58
|
|
|
const CRON_HOOK_CATEGORY = 'do-bulk-delete-cat'; |
59
|
|
|
const CRON_HOOK_POST_STATUS = 'do-bulk-delete-post-status'; |
60
|
|
|
const CRON_HOOK_TAG = 'do-bulk-delete-tag'; |
61
|
|
|
const CRON_HOOK_TAXONOMY = 'do-bulk-delete-taxonomy'; |
62
|
|
|
const CRON_HOOK_POST_TYPE = 'do-bulk-delete-post-type'; |
63
|
|
|
const CRON_HOOK_CUSTOM_FIELD = 'do-bulk-delete-custom-field'; |
64
|
|
|
const CRON_HOOK_TITLE = 'do-bulk-delete-by-title'; |
65
|
|
|
const CRON_HOOK_DUPLICATE_TITLE = 'do-bulk-delete-by-duplicate-title'; |
66
|
|
|
const CRON_HOOK_POST_BY_ROLE = 'do-bulk-delete-posts-by-role'; |
67
|
|
|
|
68
|
|
|
const CRON_HOOK_PAGES_STATUS = 'do-bulk-delete-pages-by-status'; |
69
|
|
|
|
70
|
|
|
// meta boxes for delete posts |
71
|
|
|
const BOX_POST_STATUS = 'bd_by_post_status'; |
72
|
|
|
const BOX_CATEGORY = 'bd_by_category'; |
73
|
|
|
const BOX_TAG = 'bd_by_tag'; |
74
|
|
|
const BOX_TAX = 'bd_by_tax'; |
75
|
|
|
const BOX_POST_TYPE = 'bd_by_post_type'; |
76
|
|
|
const BOX_URL = 'bd_by_url'; |
77
|
|
|
const BOX_POST_REVISION = 'bd_by_post_revision'; |
78
|
|
|
const BOX_CUSTOM_FIELD = 'bd_by_custom_field'; |
79
|
|
|
const BOX_TITLE = 'bd_by_title'; |
80
|
|
|
const BOX_DUPLICATE_TITLE = 'bd_by_duplicate_title'; |
81
|
|
|
const BOX_POST_FROM_TRASH = 'bd_posts_from_trash'; |
82
|
|
|
const BOX_POST_BY_ROLE = 'bd_post_by_user_role'; |
83
|
|
|
|
84
|
|
|
// meta boxes for delete pages |
85
|
|
|
const BOX_PAGE_STATUS = 'bd_by_page_status'; |
86
|
|
|
const BOX_PAGE_FROM_TRASH = 'bd_pages_from_trash'; |
87
|
|
|
|
88
|
|
|
// Settings constants |
89
|
|
|
const SETTING_OPTION_GROUP = 'bd_settings'; |
90
|
|
|
const SETTING_OPTION_NAME = 'bd_licenses'; |
91
|
|
|
const SETTING_SECTION_ID = 'bd_license_section'; |
92
|
|
|
|
93
|
|
|
// Transient keys |
94
|
|
|
const LICENSE_CACHE_KEY_PREFIX = 'bd-license_'; |
95
|
|
|
|
96
|
|
|
const MAX_SELECT2_LIMIT = 50; |
97
|
|
|
|
98
|
|
|
// path variables |
99
|
|
|
// Ideally these should be constants, but because of PHP's limitations, these are static variables |
100
|
|
|
public static $PLUGIN_DIR; |
101
|
|
|
public static $PLUGIN_FILE; |
102
|
|
|
|
103
|
|
|
// Instance variables |
104
|
|
|
public $translations; |
105
|
|
|
public $posts_page; |
106
|
|
|
public $pages_page; |
107
|
|
|
public $cron_page; |
108
|
|
|
public $addon_page; |
109
|
|
|
public $settings_page; |
110
|
|
|
public $meta_page; |
111
|
|
|
public $misc_page; |
112
|
|
|
public $display_activate_license_form = false; |
113
|
|
|
|
114
|
|
|
// Deprecated. |
115
|
|
|
// Will be removed in v6.0 |
116
|
|
|
const CRON_HOOK_USER_ROLE = 'do-bulk-delete-users-by-role'; |
117
|
|
|
public $users_page; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Main Bulk_Delete Instance. |
121
|
|
|
* |
122
|
|
|
* Insures that only one instance of Bulk_Delete exists in memory at any one |
123
|
|
|
* time. Also prevents needing to define globals all over the place. |
124
|
|
|
* |
125
|
|
|
* @since 5.0 |
126
|
|
|
* @static |
127
|
|
|
* @staticvar array $instance |
128
|
|
|
* |
129
|
|
|
* @see BULK_DELETE() |
130
|
|
|
* |
131
|
|
|
* @return Bulk_Delete The one true instance of Bulk_Delete |
132
|
|
|
*/ |
133
|
|
|
public static function get_instance() { |
134
|
|
|
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Bulk_Delete ) ) { |
135
|
|
|
self::$instance = new Bulk_Delete(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
return self::$instance; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Throw error on object clone. |
143
|
|
|
* |
144
|
|
|
* The whole idea of the singleton design pattern is that there is a single |
145
|
|
|
* object therefore, we don't want the object to be cloned. |
146
|
|
|
* |
147
|
|
|
* @since 5.0 |
148
|
|
|
* @access protected |
149
|
|
|
* |
150
|
|
|
* @return void |
151
|
|
|
*/ |
152
|
|
|
public function __clone() { |
153
|
|
|
// Cloning instances of the class is forbidden |
154
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bulk-delete' ), '5.0' ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Disable unserializing of the class. |
159
|
|
|
* |
160
|
|
|
* @since 5.0 |
161
|
|
|
* @access protected |
162
|
|
|
* |
163
|
|
|
* @return void |
164
|
|
|
*/ |
165
|
|
|
public function __wakeup() { |
166
|
|
|
// Unserializing instances of the class is forbidden |
167
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bulk-delete' ), '5.0' ); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Set path to main plugin file. |
172
|
|
|
* |
173
|
|
|
* @param string $plugin_file Path to main plugin file. |
174
|
|
|
*/ |
175
|
|
|
public function set_plugin_file( $plugin_file ) { |
176
|
|
|
$this->plugin_file = $plugin_file; |
177
|
|
|
|
178
|
|
|
self::$PLUGIN_DIR = plugin_dir_path( $plugin_file ); |
179
|
|
|
self::$PLUGIN_FILE = $plugin_file; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Get path to main plugin file. |
184
|
|
|
* |
185
|
|
|
* @return string Plugin file. |
186
|
|
|
*/ |
187
|
|
|
public function get_plugin_file() { |
188
|
|
|
return $this->plugin_file; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Monkey patch the old `add_script` method. |
193
|
|
|
* |
194
|
|
|
* @since 6.0.0 |
195
|
|
|
*/ |
196
|
|
|
public function add_script() { |
197
|
|
|
$bd = BulkDelete::get_instance(); |
198
|
|
|
|
199
|
|
|
$primary_pages = $bd->get_primary_pages(); |
200
|
|
|
$post_page = $primary_pages[ self::POSTS_PAGE_SLUG ]; |
201
|
|
|
|
202
|
|
|
$post_page->enqueue_assets(); |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* The main function responsible for returning the one true Bulk_Delete |
208
|
|
|
* Instance to functions everywhere. |
209
|
|
|
* |
210
|
|
|
* Use this function like you would a global variable, except without needing |
211
|
|
|
* to declare the global. |
212
|
|
|
* |
213
|
|
|
* Example: `<?php $bulk_delete = BULK_DELETE(); ?>` |
214
|
|
|
* |
215
|
|
|
* @since 5.0 |
216
|
|
|
* |
217
|
|
|
* @return Bulk_Delete The one true Bulk_Delete Instance |
218
|
|
|
*/ |
219
|
|
|
function BULK_DELETE() { |
220
|
|
|
return Bulk_Delete::get_instance(); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
function bd_setup_backward_compatibility( $plugin_file ) { |
224
|
|
|
$bd = BULK_DELETE(); |
225
|
|
|
$bd->set_plugin_file( $plugin_file ); |
226
|
|
|
} |
227
|
|
|
add_action( 'bd_loaded', 'bd_setup_backward_compatibility' ); |
228
|
|
|
|