1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Deprecated and backward compatibility code. |
4
|
|
|
* Don't depend on the code in this file. It would be removed in future versions of the plugin. |
5
|
|
|
* |
6
|
|
|
* @author Sudar |
7
|
|
|
* |
8
|
|
|
* @package BulkDelete\Util\Deprecated |
9
|
|
|
* |
10
|
|
|
* @since 5.5 |
11
|
|
|
*/ |
12
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Backward compatibility for delete options. |
16
|
|
|
* |
17
|
|
|
* @since 5.5 |
18
|
|
|
* |
19
|
|
|
* @param array $options Old options. |
20
|
|
|
* @param \BulkWP\BulkDelete\Core\Base\BaseModule $module Modules. |
21
|
|
|
* |
22
|
|
|
* @return array New options. |
23
|
|
|
*/ |
24
|
|
|
function bd_delete_options_compatibility( $options, $module ) { |
25
|
36 |
|
if ( 'delete_pages_by_status' === $module->get_action() ) { |
26
|
6 |
|
return $options; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
// Convert bool keys to boolean |
30
|
30 |
|
$bool_keys = array( 'restrict', 'force_delete', 'private' ); |
31
|
30 |
|
foreach ( $bool_keys as $key ) { |
32
|
30 |
|
if ( array_key_exists( $key, $options ) ) { |
33
|
30 |
|
$options[ $key ] = bd_to_bool( $options[ $key ] ); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// convert old date comparison operators |
38
|
30 |
|
if ( array_key_exists( 'date_op', $options ) && array_key_exists( 'days', $options ) ) { |
39
|
23 |
|
if ( '<' == $options['date_op'] ) { |
40
|
|
|
$options['date_op'] = 'before'; |
41
|
23 |
|
} elseif ( '>' == $options['date_op'] ) { |
42
|
|
|
$options['date_op'] = 'after'; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
30 |
|
return $options; |
47
|
|
|
} |
48
|
|
|
add_filter( 'bd_delete_options', 'bd_delete_options_compatibility', 10, 2 ); |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Handle backward compatibility for Delete Pages by status delete options. |
52
|
|
|
* |
53
|
|
|
* Backward compatibility code. Will eventually be removed. |
54
|
|
|
* |
55
|
|
|
* @since 6.0.0 |
56
|
|
|
* |
57
|
|
|
* @param array $options Delete Options. |
58
|
|
|
* @param \BulkWP\BulkDelete\Core\Base\BaseModule $metabox Modules. |
59
|
|
|
* |
60
|
|
|
* @return array Processed delete options. |
61
|
|
|
*/ |
62
|
|
|
function bd_convert_old_options_for_delete_pages( $options, $metabox ) { |
63
|
36 |
|
if ( 'delete_pages_by_status' !== $metabox->get_action() ) { |
64
|
30 |
|
return $options; |
65
|
|
|
} |
66
|
|
|
|
67
|
6 |
|
if ( array_key_exists( 'page_op', $options ) ) { |
68
|
|
|
$options['date_op'] = $options['page_op']; |
69
|
|
|
$options['days'] = $options['page_days']; |
70
|
|
|
} |
71
|
|
|
|
72
|
6 |
|
return $options; |
73
|
|
|
} |
74
|
|
|
add_filter( 'bd_delete_options', 'bd_convert_old_options_for_delete_pages', 10, 2 ); |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Handle backward compatibility for Delete Posts by category delete options. |
78
|
|
|
* |
79
|
|
|
* Backward compatibility code. Will be removed in future Bulk Delete releases. |
80
|
|
|
* |
81
|
|
|
* @since 6.0.0 |
82
|
|
|
* |
83
|
|
|
* @param array $options Delete Options. |
84
|
|
|
* |
85
|
|
|
* @return array Processed delete options. |
86
|
|
|
*/ |
87
|
|
|
function bd_convert_old_options_for_delete_posts_by_category( $options ) { |
88
|
36 |
|
if ( array_key_exists( 'cats_op', $options ) ) { |
89
|
|
|
$options['date_op'] = $options['cats_op']; |
90
|
|
|
$options['days'] = $options['cats_days']; |
91
|
|
|
} |
92
|
|
|
|
93
|
36 |
|
return $options; |
94
|
|
|
} |
95
|
|
|
add_filter( 'bd_delete_options', 'bd_convert_old_options_for_delete_posts_by_category' ); |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Handle backward compatibility for Delete Posts by tag delete options. |
99
|
|
|
* |
100
|
|
|
* Backward compatibility code. Will be removed in future Bulk Delete releases. |
101
|
|
|
* |
102
|
|
|
* @since 6.0.0 |
103
|
|
|
* |
104
|
|
|
* @param array $options Delete Options. |
105
|
|
|
* @param \BulkWP\BulkDelete\Core\Base\BaseModule $metabox Modules. |
106
|
|
|
* |
107
|
|
|
* @return array Processed delete options. |
108
|
|
|
*/ |
109
|
|
|
function bd_convert_old_options_for_delete_posts_by_tag( $options, $metabox ) { |
110
|
36 |
|
if ( 'delete_posts_by_tag' !== $metabox->get_action() ) { |
111
|
28 |
|
return $options; |
112
|
|
|
} |
113
|
|
|
|
114
|
8 |
|
if ( array_key_exists( 'tags_op', $options ) ) { |
115
|
|
|
$options['date_op'] = $options['tags_op']; |
116
|
|
|
$options['days'] = $options['tags_days']; |
117
|
|
|
} |
118
|
|
|
|
119
|
8 |
|
return $options; |
120
|
|
|
} |
121
|
|
|
add_filter( 'bd_delete_options', 'bd_convert_old_options_for_delete_posts_by_tag', 10, 2 ); |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Handle backward compatibility for Delete Posts by status delete options. |
125
|
|
|
* |
126
|
|
|
* Backward compatibility code. Will be removed in Bulk Delete v6.0. |
127
|
|
|
* |
128
|
|
|
* @since 5.6.0 |
129
|
|
|
* @since 6.0.0 Added Modules parameter. |
130
|
|
|
* |
131
|
|
|
* @param array $delete_options Delete Options. |
132
|
|
|
* @param \BulkWP\BulkDelete\Core\Base\BaseModule $metabox Modules. |
133
|
|
|
* |
134
|
|
|
* @return array Processed delete options. |
135
|
|
|
*/ |
136
|
|
|
function bd_convert_old_options_for_delete_post_by_status( $delete_options, $metabox ) { |
137
|
36 |
|
if ( 'delete_posts_by_status' !== $metabox->get_action() ) { |
138
|
25 |
|
return $delete_options; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
// Format changed in 5.5.0. |
142
|
11 |
|
if ( array_key_exists( 'post_status_op', $delete_options ) ) { |
143
|
|
|
$delete_options['date_op'] = $delete_options['post_status_op']; |
144
|
|
|
$delete_options['days'] = $delete_options['post_status_days']; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
// Format changed in 5.6.0. |
148
|
11 |
|
if ( isset( $delete_options['sticky'] ) ) { |
149
|
|
|
if ( 'sticky' === $delete_options['sticky'] ) { |
150
|
|
|
$delete_options['delete-sticky-posts'] = true; |
151
|
|
|
} else { |
152
|
|
|
$delete_options['delete-sticky-posts'] = false; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
156
|
11 |
|
if ( ! isset( $delete_options['post_status'] ) ) { |
157
|
|
|
$delete_options['post_status'] = array(); |
158
|
|
|
} |
159
|
|
|
|
160
|
11 |
|
$old_statuses = array( 'publish', 'draft', 'pending', 'future', 'private' ); |
161
|
|
|
|
162
|
11 |
|
foreach ( $old_statuses as $old_status ) { |
163
|
11 |
|
if ( isset( $delete_options[ $old_status ] ) ) { |
164
|
11 |
|
$delete_options['post_status'][] = $old_status; |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
168
|
11 |
|
if ( isset( $delete_options['drafts'] ) && 'drafts' === $delete_options['drafts'] ) { |
169
|
|
|
$delete_options['post_status'][] = 'draft'; |
170
|
|
|
} |
171
|
|
|
|
172
|
11 |
|
return $delete_options; |
173
|
|
|
} |
174
|
|
|
add_filter( 'bd_delete_options', 'bd_convert_old_options_for_delete_post_by_status', 10, 2 ); |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Handle backward compatibility for Delete Posts by Taxonomy delete options. |
178
|
|
|
* |
179
|
|
|
* Backward compatibility code. Will be removed in Bulk Delete v6.0. |
180
|
|
|
* |
181
|
|
|
* @since 6.0.0 |
182
|
|
|
* |
183
|
|
|
* @param array $delete_options Delete Options. |
184
|
|
|
* @param \BulkWP\BulkDelete\Core\Base\BaseModule $metabox Modules. |
185
|
|
|
* |
186
|
|
|
* @return array Processed delete options. |
187
|
|
|
*/ |
188
|
|
|
function bd_convert_old_options_for_delete_post_by_taxonomy( $delete_options, $metabox ) { |
189
|
36 |
|
if ( 'bd_delete_posts_by_taxonomy' !== $metabox->get_action() ) { |
190
|
36 |
|
return $delete_options; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
if ( array_key_exists( 'taxs_op', $delete_options ) ) { |
194
|
|
|
$delete_options['date_op'] = $delete_options['taxs_op']; |
195
|
|
|
$delete_options['days'] = $delete_options['taxs_days']; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
return $delete_options; |
199
|
|
|
} |
200
|
|
|
add_filter( 'bd_delete_options', 'bd_convert_old_options_for_delete_post_by_taxonomy', 10, 2 ); |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Handle backward compatibility for Delete Posts by Post type delete options. |
204
|
|
|
* |
205
|
|
|
* Backward compatibility code. Will be removed in Bulk Delete v6.0. |
206
|
|
|
* |
207
|
|
|
* @since 6.0.0 |
208
|
|
|
* |
209
|
|
|
* @param array $delete_options Delete Options. |
210
|
|
|
* @param \BulkWP\BulkDelete\Core\Base\BaseModule $metabox Modules. |
211
|
|
|
* |
212
|
|
|
* @return array Processed delete options. |
213
|
|
|
*/ |
214
|
|
|
function bd_convert_old_options_for_delete_post_by_post_type( $delete_options, $metabox ) { |
215
|
36 |
|
if ( 'delete_posts_by_post_type' !== $metabox->get_action() ) { |
216
|
36 |
|
return $delete_options; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
if ( array_key_exists( 'types_op', $delete_options ) ) { |
220
|
|
|
$delete_options['date_op'] = $delete_options['types_op']; |
221
|
|
|
$delete_options['days'] = $delete_options['types_days']; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
return $delete_options; |
225
|
|
|
} |
226
|
|
|
add_filter( 'bd_delete_options', 'bd_convert_old_options_for_delete_post_by_post_type', 10, 2 ); |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Enable cron for old pro addons that required separate JavaScript. |
230
|
|
|
* This will be removed in v6.0. |
231
|
|
|
* |
232
|
|
|
* @since 5.5 |
233
|
|
|
* |
234
|
|
|
* @param array $js_array JavaScript Array |
235
|
|
|
* |
236
|
|
|
* @return array Modified JavaScript Array |
237
|
|
|
*/ |
238
|
|
|
function bd_enable_cron_for_old_addons( $js_array ) { |
239
|
|
|
if ( ! function_exists( 'is_plugin_active' ) ) { |
240
|
|
|
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
if ( is_plugin_active( 'bulk-delete-scheduler-for-deleting-users-by-role/bulk-delete-scheduler-for-deleting-users-by-role.php' ) ) { |
244
|
|
|
$js_array['pro_iterators'][] = 'u_role'; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
return $js_array; |
248
|
|
|
} |
249
|
|
|
add_filter( 'bd_javascript_array', 'bd_enable_cron_for_old_addons' ); |
250
|
|
|
|
251
|
|
|
// Deprecated functions. |
252
|
|
|
|
253
|
|
|
if ( ! function_exists( 'array_get' ) ) { |
254
|
|
|
/** |
255
|
|
|
* Deprecated. Use `bd_array_get`. |
256
|
|
|
* |
257
|
|
|
* @param mixed $array |
258
|
|
|
* @param mixed $key |
259
|
|
|
* @param mixed|null $default |
260
|
|
|
*/ |
261
|
|
|
function array_get( $array, $key, $default = null ) { |
262
|
|
|
return bd_array_get( $array, $key, $default ); |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
if ( ! function_exists( 'array_get_bool' ) ) { |
267
|
|
|
/** |
268
|
|
|
* Deprecated. Use `bd_array_get_bool`. |
269
|
|
|
* |
270
|
|
|
* @param mixed $array |
271
|
|
|
* @param mixed $key |
272
|
|
|
* @param mixed $default |
273
|
|
|
*/ |
274
|
|
|
function array_get_bool( $array, $key, $default = false ) { |
275
|
|
|
return bd_array_get_bool( $array, $key, $default ); |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|