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 $meta_page; |
91
|
|
|
public $misc_page; |
92
|
|
|
public $display_activate_license_form = false; |
93
|
|
|
|
94
|
|
|
// Deprecated. |
95
|
|
|
// Will be removed in v6.0 |
96
|
|
|
const CRON_HOOK_USER_ROLE = 'do-bulk-delete-users-by-role'; |
97
|
|
|
public $users_page; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Main Bulk_Delete Instance. |
101
|
|
|
* |
102
|
|
|
* Insures that only one instance of Bulk_Delete exists in memory at any one |
103
|
|
|
* time. Also prevents needing to define globals all over the place. |
104
|
|
|
* |
105
|
|
|
* @since 5.0 |
106
|
|
|
* @static |
107
|
|
|
* @staticvar array $instance |
108
|
|
|
* |
109
|
|
|
* @see BULK_DELETE() |
110
|
|
|
* |
111
|
|
|
* @return Bulk_Delete The one true instance of Bulk_Delete |
112
|
|
|
*/ |
113
|
|
|
public static function get_instance() { |
114
|
|
|
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Bulk_Delete ) ) { |
115
|
|
|
self::$instance = new Bulk_Delete(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return self::$instance; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Throw error on object clone. |
123
|
|
|
* |
124
|
|
|
* The whole idea of the singleton design pattern is that there is a single |
125
|
|
|
* object therefore, we don't want the object to be cloned. |
126
|
|
|
* |
127
|
|
|
* @since 5.0 |
128
|
|
|
* @access protected |
129
|
|
|
* |
130
|
|
|
* @return void |
131
|
|
|
*/ |
132
|
|
|
public function __clone() { |
133
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bulk-delete' ), '5.0' ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Disable unserializing of the class. |
138
|
|
|
* |
139
|
|
|
* @since 5.0 |
140
|
|
|
* @access protected |
141
|
|
|
* |
142
|
|
|
* @return void |
143
|
|
|
*/ |
144
|
|
|
public function __wakeup() { |
145
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'bulk-delete' ), '5.0' ); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Set path to main plugin file. |
150
|
|
|
* |
151
|
|
|
* @param string $plugin_file Path to main plugin file. |
152
|
|
|
*/ |
153
|
|
|
public function set_plugin_file( $plugin_file ) { |
154
|
|
|
$this->plugin_file = $plugin_file; |
155
|
|
|
|
156
|
|
|
self::$PLUGIN_DIR = plugin_dir_path( $plugin_file ); |
157
|
|
|
self::$PLUGIN_FILE = $plugin_file; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Get path to main plugin file. |
162
|
|
|
* |
163
|
|
|
* @return string Plugin file. |
164
|
|
|
*/ |
165
|
|
|
public function get_plugin_file() { |
166
|
|
|
return $this->plugin_file; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Monkey patch the old `add_script` method. |
171
|
|
|
* |
172
|
|
|
* @since 6.0.0 |
173
|
|
|
*/ |
174
|
|
|
public function add_script() { |
175
|
|
|
$bd = BulkDelete::get_instance(); |
176
|
|
|
|
177
|
|
|
$primary_pages = $bd->get_primary_pages(); |
178
|
|
|
$post_page = $primary_pages[ self::POSTS_PAGE_SLUG ]; |
179
|
|
|
|
180
|
|
|
$post_page->enqueue_assets(); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Provide access to old public fields through Magic method. |
185
|
|
|
* |
186
|
|
|
* This function is added to provide backward compatibility and will be eventually removed from future versions. |
187
|
|
|
* |
188
|
|
|
* @since 6.0.0 |
189
|
|
|
* |
190
|
|
|
* @param string $name Field. |
191
|
|
|
* |
192
|
|
|
* @return string|null |
193
|
|
|
*/ |
194
|
|
|
public function __get( $name ) { |
195
|
|
|
$new_bd = BulkDelete::get_instance(); |
196
|
|
|
|
197
|
|
|
switch ( $name ) { |
198
|
|
|
case 'translations': |
199
|
|
|
return $new_bd->get_translations_path(); |
200
|
|
|
break; |
|
|
|
|
201
|
|
|
|
202
|
|
|
case 'posts_page': |
203
|
|
|
return $new_bd->get_page_hook_suffix( 'bulk-delete-posts' ); |
204
|
|
|
break; |
205
|
|
|
|
206
|
|
|
case 'pages_page': |
207
|
|
|
return $new_bd->get_page_hook_suffix( 'bulk-delete-pages' ); |
208
|
|
|
break; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
$trace = debug_backtrace(); |
212
|
|
|
trigger_error( 'Undefined property via __get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE ); |
213
|
|
|
|
214
|
|
|
return null; |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* The main function responsible for returning the one true Bulk_Delete |
220
|
|
|
* Instance to functions everywhere. |
221
|
|
|
* |
222
|
|
|
* Use this function like you would a global variable, except without needing |
223
|
|
|
* to declare the global. |
224
|
|
|
* |
225
|
|
|
* Example: `<?php $bulk_delete = BULK_DELETE(); ?>` |
226
|
|
|
* |
227
|
|
|
* @since 5.0 |
228
|
|
|
* |
229
|
|
|
* @return Bulk_Delete The one true Bulk_Delete Instance |
230
|
|
|
*/ |
231
|
|
|
function BULK_DELETE() { |
232
|
|
|
return Bulk_Delete::get_instance(); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Setup old Bulk_Delete class for backward compatibility reasons. |
237
|
|
|
* |
238
|
|
|
* Eventually this will be removed. |
239
|
|
|
* |
240
|
|
|
* @since 6.0.0 |
241
|
|
|
* |
242
|
|
|
* @param string $plugin_file Main plugin file. |
243
|
|
|
*/ |
244
|
|
|
function bd_setup_backward_compatibility( $plugin_file ) { |
245
|
|
|
$bd = BULK_DELETE(); |
246
|
|
|
$bd->set_plugin_file( $plugin_file ); |
247
|
|
|
} |
248
|
|
|
add_action( 'bd_loaded', 'bd_setup_backward_compatibility' ); |
249
|
|
|
|
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.