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
|
|
|
* @property null|string translations |
17
|
|
|
* @property null|string posts_page |
18
|
|
|
* @property null|string pages_page |
19
|
|
|
* |
20
|
|
|
* @since 5.0 Singleton |
21
|
|
|
* @since 6.0.0 Deprecated. |
22
|
|
|
*/ |
23
|
|
|
final class Bulk_Delete { |
24
|
|
|
/** |
25
|
|
|
* The one true Bulk_Delete instance. |
26
|
|
|
* |
27
|
|
|
* @var Bulk_Delete |
28
|
|
|
* |
29
|
|
|
* @since 5.0 |
30
|
|
|
*/ |
31
|
|
|
private static $instance; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Path to the main plugin file. |
35
|
|
|
* |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $plugin_file; |
39
|
|
|
|
40
|
|
|
// Deprecated constants. They are defined here for backward compatibility. |
41
|
|
|
const VERSION = '5.6.1'; |
42
|
|
|
|
43
|
|
|
const JS_HANDLE = 'bulk-delete'; |
44
|
|
|
|
45
|
|
|
// Cron hooks. |
46
|
|
|
const CRON_HOOK_PAGES_STATUS = 'do-bulk-delete-pages-by-status'; // used in Scheduler For Deleting Pages by Post status add-on v0.6. |
47
|
|
|
|
48
|
|
|
const CRON_HOOK_POST_STATUS = 'do-bulk-delete-post-status'; // used in Scheduler For Deleting Posts by Post status add-on v0.6. |
49
|
|
|
const CRON_HOOK_CATEGORY = 'do-bulk-delete-cat'; // used in Scheduler For Deleting Posts by Category add-on v0.6. |
50
|
|
|
const CRON_HOOK_TAG = 'do-bulk-delete-tag'; // used in Scheduler For Deleting Posts by Tag add-on v0.6. |
51
|
|
|
const CRON_HOOK_TAXONOMY = 'do-bulk-delete-taxonomy'; // used in Scheduler For Deleting Posts by Taxonomy add-on v0.6. |
52
|
|
|
const CRON_HOOK_POST_TYPE = 'do-bulk-delete-post-type'; // used in Scheduler For Deleting Posts by Post Type add-on v0.6. |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
// page slugs |
56
|
|
|
const POSTS_PAGE_SLUG = 'bulk-delete-posts'; |
57
|
|
|
const PAGES_PAGE_SLUG = 'bulk-delete-pages'; |
58
|
|
|
const CRON_PAGE_SLUG = 'bulk-delete-cron'; |
59
|
|
|
const ADDON_PAGE_SLUG = 'bulk-delete-addon'; |
60
|
|
|
|
61
|
|
|
// Cron hooks |
62
|
|
|
const CRON_HOOK_CUSTOM_FIELD = 'do-bulk-delete-custom-field'; |
63
|
|
|
const CRON_HOOK_TITLE = 'do-bulk-delete-by-title'; |
64
|
|
|
const CRON_HOOK_DUPLICATE_TITLE = 'do-bulk-delete-by-duplicate-title'; |
65
|
|
|
const CRON_HOOK_POST_BY_ROLE = 'do-bulk-delete-posts-by-role'; |
66
|
|
|
|
67
|
|
|
// meta boxes for delete posts |
68
|
|
|
const BOX_CUSTOM_FIELD = 'bd_by_custom_field'; |
69
|
|
|
const BOX_TITLE = 'bd_by_title'; |
70
|
|
|
const BOX_DUPLICATE_TITLE = 'bd_by_duplicate_title'; |
71
|
|
|
const BOX_POST_FROM_TRASH = 'bd_posts_from_trash'; |
72
|
|
|
const BOX_POST_BY_ROLE = 'bd_post_by_user_role'; |
73
|
|
|
|
74
|
|
|
// meta boxes for delete pages |
75
|
|
|
const BOX_PAGE_FROM_TRASH = 'bd_pages_from_trash'; |
76
|
|
|
|
77
|
|
|
// Settings constants |
78
|
|
|
const SETTING_OPTION_GROUP = 'bd_settings'; |
79
|
|
|
const SETTING_OPTION_NAME = 'bd_licenses'; |
80
|
|
|
const SETTING_SECTION_ID = 'bd_license_section'; |
81
|
|
|
|
82
|
|
|
// Transient keys |
83
|
|
|
const LICENSE_CACHE_KEY_PREFIX = 'bd-license_'; |
84
|
|
|
|
85
|
|
|
// path variables |
86
|
|
|
// Ideally these should be constants, but because of PHP's limitations, these are static variables |
87
|
|
|
public static $PLUGIN_DIR; |
88
|
|
|
public static $PLUGIN_FILE; |
89
|
|
|
|
90
|
|
|
// Instance variables |
91
|
|
|
public $settings_page; |
92
|
|
|
public $meta_page; |
93
|
|
|
public $misc_page; |
94
|
|
|
public $display_activate_license_form = false; |
95
|
|
|
|
96
|
|
|
// Deprecated. |
97
|
|
|
// Will be removed in v6.0 |
98
|
|
|
const CRON_HOOK_USER_ROLE = 'do-bulk-delete-users-by-role'; |
99
|
|
|
public $users_page; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Main Bulk_Delete Instance. |
103
|
|
|
* |
104
|
|
|
* Insures that only one instance of Bulk_Delete exists in memory at any one |
105
|
|
|
* time. Also prevents needing to define globals all over the place. |
106
|
|
|
* |
107
|
|
|
* @since 5.0 |
108
|
|
|
* @static |
109
|
|
|
* @staticvar array $instance |
110
|
|
|
* |
111
|
|
|
* @see BULK_DELETE() |
112
|
|
|
* |
113
|
|
|
* @return Bulk_Delete The one true instance of Bulk_Delete |
114
|
|
|
*/ |
115
|
|
|
public static function get_instance() { |
116
|
|
|
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Bulk_Delete ) ) { |
117
|
|
|
self::$instance = new Bulk_Delete(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return self::$instance; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Throw error on object clone. |
125
|
|
|
* |
126
|
|
|
* The whole idea of the singleton design pattern is that there is a single |
127
|
|
|
* object therefore, we don't want the object to be cloned. |
128
|
|
|
* |
129
|
|
|
* @since 5.0 |
130
|
|
|
* @access protected |
131
|
|
|
* |
132
|
|
|
* @return void |
133
|
|
|
*/ |
134
|
|
|
public function __clone() { |
135
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bulk-delete' ), '5.0' ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Disable unserializing of the class. |
140
|
|
|
* |
141
|
|
|
* @since 5.0 |
142
|
|
|
* @access protected |
143
|
|
|
* |
144
|
|
|
* @return void |
145
|
|
|
*/ |
146
|
|
|
public function __wakeup() { |
147
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bulk-delete' ), '5.0' ); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Set path to main plugin file. |
152
|
|
|
* |
153
|
|
|
* @param string $plugin_file Path to main plugin file. |
154
|
|
|
*/ |
155
|
|
|
public function set_plugin_file( $plugin_file ) { |
156
|
|
|
$this->plugin_file = $plugin_file; |
157
|
|
|
|
158
|
|
|
self::$PLUGIN_DIR = plugin_dir_path( $plugin_file ); |
159
|
|
|
self::$PLUGIN_FILE = $plugin_file; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Get path to main plugin file. |
164
|
|
|
* |
165
|
|
|
* @return string Plugin file. |
166
|
|
|
*/ |
167
|
|
|
public function get_plugin_file() { |
168
|
|
|
return $this->plugin_file; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Monkey patch the old `add_script` method. |
173
|
|
|
* |
174
|
|
|
* @since 6.0.0 |
175
|
|
|
*/ |
176
|
|
|
public function add_script() { |
177
|
|
|
$bd = BulkDelete::get_instance(); |
178
|
|
|
|
179
|
|
|
$primary_pages = $bd->get_primary_pages(); |
180
|
|
|
$post_page = $primary_pages[ self::POSTS_PAGE_SLUG ]; |
181
|
|
|
|
182
|
|
|
$post_page->enqueue_assets(); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Provide access to old public fields through Magic method. |
187
|
|
|
* |
188
|
|
|
* This function is added to provide backward compatibility and will be eventually removed from future versions. |
189
|
|
|
* |
190
|
|
|
* @since 6.0.0 |
191
|
|
|
* |
192
|
|
|
* @param string $name Field. |
193
|
|
|
* |
194
|
|
|
* @return null|string |
195
|
|
|
*/ |
196
|
|
|
public function __get( $name ) { |
197
|
|
|
$new_bd = BulkDelete::get_instance(); |
198
|
|
|
|
199
|
|
|
switch ( $name ) { |
200
|
|
|
case 'translations': |
201
|
|
|
return $new_bd->get_translations_path(); |
202
|
|
|
break; |
|
|
|
|
203
|
|
|
|
204
|
|
|
case 'posts_page': |
205
|
|
|
return $new_bd->get_page_hook_suffix( 'bulk-delete-posts' ); |
206
|
|
|
break; |
207
|
|
|
|
208
|
|
|
case 'pages_page': |
209
|
|
|
return $new_bd->get_page_hook_suffix( 'bulk-delete-pages' ); |
210
|
|
|
break; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
$trace = debug_backtrace(); |
214
|
|
|
trigger_error( 'Undefined property via __get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE ); |
215
|
|
|
|
216
|
|
|
return null; |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* The main function responsible for returning the one true Bulk_Delete |
222
|
|
|
* Instance to functions everywhere. |
223
|
|
|
* |
224
|
|
|
* Use this function like you would a global variable, except without needing |
225
|
|
|
* to declare the global. |
226
|
|
|
* |
227
|
|
|
* Example: `<?php $bulk_delete = BULK_DELETE(); ?>` |
228
|
|
|
* |
229
|
|
|
* @since 5.0 |
230
|
|
|
* |
231
|
|
|
* @return Bulk_Delete The one true Bulk_Delete Instance |
232
|
|
|
*/ |
233
|
|
|
function BULK_DELETE() { |
234
|
|
|
return Bulk_Delete::get_instance(); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Setup old Bulk_Delete class for backward compatibility reasons. |
239
|
|
|
* |
240
|
|
|
* Eventually this will be removed. |
241
|
|
|
* |
242
|
|
|
* @since 6.0.0 |
243
|
|
|
* |
244
|
|
|
* @param string $plugin_file Main plugin file. |
245
|
|
|
*/ |
246
|
|
|
function bd_setup_backward_compatibility( $plugin_file ) { |
247
|
|
|
$bd = BULK_DELETE(); |
248
|
|
|
$bd->set_plugin_file( $plugin_file ); |
249
|
|
|
} |
250
|
|
|
add_action( 'bd_loaded', 'bd_setup_backward_compatibility' ); |
251
|
|
|
|
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.