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