1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Utility class for deleting Jetpack Contact Form Messages. |
4
|
|
|
* |
5
|
|
|
* @since 5.3 |
6
|
|
|
* |
7
|
|
|
* @author Sudar |
8
|
|
|
* |
9
|
|
|
* @package BulkDelete\Misc |
10
|
|
|
*/ |
11
|
|
|
class Bulk_Delete_Jetpack_Contact_Form_Message { |
12
|
|
|
// box slugs |
13
|
|
|
const BOX_JETPACK_MESSAGES = 'bd-jetpack-feedback'; |
14
|
|
|
|
15
|
|
|
const FEEDBACK_POST_TYPE = 'feedback'; |
16
|
|
|
const CRON_HOOK = 'do-bulk-delete-feedback'; |
17
|
|
|
const CRON_NAME = 'Bulk Delete Jetpack Contact Form Messages'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Register Jetpack Feedback meta box for delete misc page. |
21
|
|
|
* |
22
|
|
|
* @static |
23
|
|
|
* |
24
|
|
|
* @since 5.3 |
25
|
|
|
*/ |
26
|
|
|
public static function add_delete_jetpack_messages_meta_box() { |
27
|
|
|
$bd = BULK_DELETE(); |
28
|
|
|
|
29
|
|
|
add_meta_box( |
30
|
|
|
self::BOX_JETPACK_MESSAGES, |
31
|
|
|
__( 'Bulk Delete Jetpack Contact Form Messages', 'bulk-delete' ), |
32
|
|
|
array( __CLASS__, 'render_delete_jetpack_messages_box' ), |
33
|
|
|
$bd->misc_page, |
34
|
|
|
'advanced' |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Render Jetpack Feedback meta box for delete misc page. |
40
|
|
|
* |
41
|
|
|
* @static |
42
|
|
|
* |
43
|
|
|
* @since 5.3 |
44
|
|
|
*/ |
45
|
|
|
public static function render_delete_jetpack_messages_box() { |
46
|
|
|
if ( Bulk_Delete_Misc::is_misc_box_hidden( self::BOX_JETPACK_MESSAGES ) ) { |
47
|
|
|
printf( __( 'This section just got enabled. Kindly <a href = "%1$s">refresh</a> the page to fully enable it.', 'bulk-delete' ), 'admin.php?page=' . Bulk_Delete_Misc::MISC_PAGE_SLUG ); |
48
|
|
|
|
49
|
|
|
return; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ( ! self::is_jetpack_contact_active() ) { |
53
|
|
|
?> |
54
|
|
|
<!-- Delete Jetpack Feedback box start--> |
55
|
|
|
<p> |
56
|
|
|
<span style="color:red"> |
57
|
|
|
<?php _e( 'Jetpack contact form is not enabled.', 'bulk-delete' ); ?> |
58
|
|
|
</span> |
59
|
|
|
</p> |
60
|
|
|
<!-- Delete Jetpack Feedback box end--> |
61
|
|
|
<?php |
62
|
|
|
} else { |
63
|
|
|
$feedback_count = wp_count_posts( self::FEEDBACK_POST_TYPE ); |
64
|
|
|
?> |
65
|
|
|
<!-- Delete Jetpack Feedback box start--> |
66
|
|
|
<fieldset class="options"> |
67
|
|
|
<table class="optiontable"> |
68
|
|
|
<tr> |
69
|
|
|
<td scope="row" > |
70
|
|
|
<input name="smbd_feedback_use_filter" value = "false" type = "radio" checked> |
71
|
|
|
</td> |
72
|
|
|
<td> |
73
|
|
|
<label for="smbd_feedback"><?php echo __( 'Delete all Contact Form Messages', 'bulk-delete' ), ' ( ', $feedback_count->publish, ' ', __( 'in total', 'bulk-delete' ), ' )'; ?></label> |
74
|
|
|
</td> |
75
|
|
|
</tr> |
76
|
|
|
|
77
|
|
|
<tr> |
78
|
|
|
<td scope="row" > |
79
|
|
|
<input name="smbd_feedback_use_filter" id="smbd_feedback_use_filter" value = "true" type = "radio" disabled> |
80
|
|
|
</td> |
81
|
|
|
<td> |
82
|
|
|
<label for="smbd_feedback"><?php _e( 'Delete Messages based on filters', 'bulk-delete' ); ?></label> |
83
|
|
|
<span class = "bd-feedback-pro" style = "color:red; vertical-align: middle;"><?php _e( 'Only available in Pro Addon', 'bulk-delete' ); ?> <a href = "http://bulkwp.com/addons/bulk-delete-jetpack-contact-form-messages/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-jcm" target="_blank">Buy now</a></span> |
84
|
|
|
</td> |
85
|
|
|
</tr> |
86
|
|
|
</table> |
87
|
|
|
<?php |
88
|
|
|
/** |
89
|
|
|
* Add more fields to the delete jetpack messages form |
90
|
|
|
* This hook can be used to add more fields to the delete jetpack messages form. |
91
|
|
|
* |
92
|
|
|
* @since 5.3 |
93
|
|
|
*/ |
94
|
|
|
do_action( 'bd_delete_jetpack_messages_form' ); |
95
|
|
|
?> |
96
|
|
|
<table class="optiontable"> |
97
|
|
|
<tr> |
98
|
|
|
<td colspan="2"> |
99
|
|
|
<h4><?php _e( 'Choose your date options', 'bulk-delete' ); ?></h4> |
100
|
|
|
</td> |
101
|
|
|
</tr> |
102
|
|
|
|
103
|
|
|
<tr> |
104
|
|
|
<td scope="row"> |
105
|
|
|
<input name="smbd_feedback_restrict" id ="smbd_feedback_restrict" value = "true" type = "checkbox"> |
106
|
|
|
</td> |
107
|
|
|
<td> |
108
|
|
|
<?php _e( 'Only restrict to posts which are ', 'bulk-delete' );?> |
109
|
|
|
<select name="smbd_feedback_op" id="smbd_feedback_op" disabled> |
110
|
|
|
<option value ="<"><?php _e( 'older than', 'bulk-delete' );?></option> |
111
|
|
|
<option value =">"><?php _e( 'posted within last', 'bulk-delete' );?></option> |
112
|
|
|
</select> |
113
|
|
|
<input type ="textbox" name="smbd_feedback_days" id ="smbd_feedback_days" value ="0" maxlength="4" size="4" disabled><?php _e( 'days', 'bulk-delete' );?> |
114
|
|
|
</td> |
115
|
|
|
</tr> |
116
|
|
|
|
117
|
|
|
<tr> |
118
|
|
|
<td scope="row"> |
119
|
|
|
<input name="smbd_feedback_limit" id="smbd_feedback_limit" value = "true" type = "checkbox"> |
120
|
|
|
</td> |
121
|
|
|
<td> |
122
|
|
|
<?php _e( 'Only delete first ', 'bulk-delete' );?> |
123
|
|
|
<input type ="textbox" name="smbd_feedback_limit_to" id="smbd_feedback_limit_to" disabled value ="0" maxlength="4" size="4"><?php _e( 'posts.', 'bulk-delete' );?> |
124
|
|
|
<?php _e( 'Use this option if there are more than 1000 posts and the script times out.', 'bulk-delete' ) ?> |
125
|
|
|
</td> |
126
|
|
|
</tr> |
127
|
|
|
|
128
|
|
|
<tr> |
129
|
|
|
<td colspan="2"> |
130
|
|
|
<h4><?php _e( 'Choose your deletion options', 'bulk-delete' ); ?></h4> |
131
|
|
|
</td> |
132
|
|
|
</tr> |
133
|
|
|
|
134
|
|
|
<tr> |
135
|
|
|
<td scope="row" colspan="2"> |
136
|
|
|
<input name="smbd_feedback_force_delete" value = "false" type = "radio" checked="checked"> <?php _e( 'Move to Trash', 'bulk-delete' ); ?> |
137
|
|
|
<input name="smbd_feedback_force_delete" value = "true" type = "radio"> <?php _e( 'Delete permanently', 'bulk-delete' ); ?> |
138
|
|
|
</td> |
139
|
|
|
</tr> |
140
|
|
|
|
141
|
|
|
<tr> |
142
|
|
|
<td scope="row" colspan="2"> |
143
|
|
|
<input name="smbd_feedback_cron" value = "false" type = "radio" checked="checked" > <?php _e( 'Delete now', 'bulk-delete' ); ?> |
144
|
|
|
<input name="smbd_feedback_cron" value = "true" type = "radio" id = "smbd_feedback_cron" disabled > <?php _e( 'Schedule', 'bulk-delete' ); ?> |
145
|
|
|
<input name="smbd_feedback_cron_start" id = "smbd_feedback_cron_start" value = "now" type = "text" disabled><?php _e( 'repeat ', 'bulk-delete' );?> |
146
|
|
|
<select name = "smbd_feedback_cron_freq" id = "smbd_feedback_cron_freq" disabled> |
147
|
|
|
<option value = "-1"><?php _e( "Don't repeat", 'bulk-delete' ); ?></option> |
148
|
|
|
<?php |
149
|
|
|
$schedules = wp_get_schedules(); |
150
|
|
|
foreach ( $schedules as $key => $value ) { |
151
|
|
|
?> |
152
|
|
|
<option value = "<?php echo $key; ?>"><?php echo $value['display']; ?></option> |
153
|
|
|
<?php |
154
|
|
|
} |
155
|
|
|
?> |
156
|
|
|
</select> |
157
|
|
|
<span class = "bd-feedback-pro" style = "color:red"><?php _e( 'Only available in Pro Addon', 'bulk-delete' ); ?> <a href = "http://bulkwp.com/addons/bulk-delete-jetpack-contact-form-messages/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-jcm" target="_blank">Buy now</a></span> |
158
|
|
|
</td> |
159
|
|
|
</tr> |
160
|
|
|
|
161
|
|
|
</table> |
162
|
|
|
</fieldset> |
163
|
|
|
<p class="submit"> |
164
|
|
|
<button type='submit' name='bd_action' value='delete_jetpack_messages' class='button-primary'><?php _e( 'Bulk Delete ', 'bulk-delete' ) ?>»</button> |
165
|
|
|
</p> |
166
|
|
|
<!-- Delete Jetpack Feedback box end--> |
167
|
|
|
<?php |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Filter JS Array and add validation hooks. |
173
|
|
|
* |
174
|
|
|
* @since 5.4 |
175
|
|
|
* @static |
176
|
|
|
* |
177
|
|
|
* @param array $js_array JavaScript Array |
178
|
|
|
* |
179
|
|
|
* @return array Modified JavaScript Array |
180
|
|
|
*/ |
181
|
|
|
public static function filter_js_array( $js_array ) { |
182
|
|
|
$js_array['dt_iterators'][] = '_feedback'; |
183
|
|
|
$js_array['validators']['delete_jetpack_messages'] = 'noValidation'; |
184
|
|
|
|
185
|
|
|
$js_array['pre_action_msg']['delete_jetpack_messages'] = 'deleteJetpackWarning'; |
186
|
|
|
$js_array['msg']['deleteJetpackWarning'] = __( 'Are you sure you want to delete all the Jetpack contact form messages based on the selected filters?', 'bulk-delete' ); |
187
|
|
|
|
188
|
|
|
return $js_array; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Controller for deleting Jetpack contact form messages. |
193
|
|
|
* |
194
|
|
|
* @static |
195
|
|
|
* |
196
|
|
|
* @since 5.3 |
197
|
|
|
*/ |
198
|
|
|
public static function do_delete_jetpack_messages() { |
199
|
|
|
$delete_options = array(); |
200
|
|
|
|
201
|
|
|
$delete_options['use_filter'] = array_get( $_POST, 'smbd_feedback_use_filter', 'false' ); |
202
|
|
|
|
203
|
|
|
$delete_options['restrict'] = array_get( $_POST, 'smbd_feedback_restrict', false ); |
204
|
|
|
$delete_options['limit_to'] = absint( array_get( $_POST, 'smbd_feedback_limit_to', 0 ) ); |
205
|
|
|
$delete_options['force_delete'] = array_get( $_POST, 'smbd_feedback_force_delete', 'false' ); |
206
|
|
|
|
207
|
|
|
$delete_options['feedback_op'] = array_get( $_POST, 'smbd_feedback_op' ); |
208
|
|
|
$delete_options['feedback_days'] = array_get( $_POST, 'smbd_feedback_days' ); |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Delete jetpack feedback delete options filter |
212
|
|
|
* This filter is for processing filtering options for deleting jetpack message. |
213
|
|
|
* |
214
|
|
|
* @since 5.3 |
215
|
|
|
*/ |
216
|
|
|
$delete_options = apply_filters( 'bd_delete_jetpack_messages_delete_options', $delete_options, $_POST ); |
217
|
|
|
|
218
|
|
|
if ( 'true' == array_get( $_POST, 'smbd_feedback_cron', 'false' ) ) { |
219
|
|
|
$freq = $_POST['smbd_feedback_cron_freq']; |
220
|
|
|
$time = strtotime( $_POST['smbd_feedback_cron_start'] ) - ( get_option( 'gmt_offset' ) * 60 * 60 ); |
221
|
|
|
|
222
|
|
|
if ( $freq == -1 ) { |
223
|
|
|
wp_schedule_single_event( $time, self::CRON_HOOK, array( $delete_options ) ); |
224
|
|
|
} else { |
225
|
|
|
wp_schedule_event( $time, $freq, self::CRON_HOOK, array( $delete_options ) ); |
226
|
|
|
} |
227
|
|
|
$msg = __( 'Jetpack contact form messages with the selected criteria are scheduled for deletion.', 'bulk-delete' ) . ' ' . |
228
|
|
|
sprintf( __( 'See the full list of <a href = "%s">scheduled tasks</a>' , 'bulk-delete' ), get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=' . Bulk_Delete::CRON_PAGE_SLUG ); |
229
|
|
|
} else { |
230
|
|
|
$deleted_count = self::delete_jetpack_messages( $delete_options ); |
231
|
|
|
$msg = sprintf( _n( 'Deleted %d Jetpack contact form message', 'Deleted %d Jetpack contact form messages' , $deleted_count, 'bulk-delete' ), $deleted_count ); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
add_settings_error( |
235
|
|
|
Bulk_Delete_Misc::MISC_PAGE_SLUG, |
236
|
|
|
'deleted-posts', |
237
|
|
|
$msg, |
238
|
|
|
'updated' |
239
|
|
|
); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Delete Jetpack contact form messages. |
244
|
|
|
* |
245
|
|
|
* @static |
246
|
|
|
* |
247
|
|
|
* @since 5.3 |
248
|
|
|
* |
249
|
|
|
* @param array $delete_options Options for deleting |
250
|
|
|
* |
251
|
|
|
* @return int Number of posts that were deleted |
252
|
|
|
*/ |
253
|
|
|
public static function delete_jetpack_messages( $delete_options ) { |
254
|
|
|
$count = 0; |
255
|
|
|
$use_filter = $delete_options['use_filter']; |
256
|
|
|
|
257
|
|
|
$options = array( |
258
|
|
|
'post_status' => 'publish', |
259
|
|
|
'post_type' => self::FEEDBACK_POST_TYPE, |
260
|
|
|
); |
261
|
|
|
|
262
|
|
|
$limit_to = $delete_options['limit_to']; |
263
|
|
|
|
264
|
|
|
if ( $limit_to > 0 ) { |
265
|
|
|
$options['showposts'] = $limit_to; |
266
|
|
|
} else { |
267
|
|
|
$options['nopaging'] = 'true'; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
$force_delete = $delete_options['force_delete']; |
271
|
|
|
|
272
|
|
|
if ( 'true' == $force_delete ) { |
273
|
|
|
$force_delete = true; |
274
|
|
|
} else { |
275
|
|
|
$force_delete = false; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
if ( 'true' == $delete_options['restrict'] ) { |
279
|
|
|
$options['op'] = $delete_options['feedback_op']; |
280
|
|
|
$options['days'] = $delete_options['feedback_days']; |
281
|
|
|
|
282
|
|
|
if ( ! class_exists( 'Bulk_Delete_By_Days' ) ) { |
283
|
|
|
require_once Bulk_Delete::$PLUGIN_DIR . '/include/util/class-bulk-delete-by-days.php'; |
284
|
|
|
} |
285
|
|
|
new Bulk_Delete_By_Days; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
$post_ids = bd_query( $options ); |
289
|
|
|
foreach ( $post_ids as $post_id ) { |
290
|
|
|
if ( 'true' == $use_filter ) { |
291
|
|
|
/** |
292
|
|
|
* Process additional filters for deleting jetpack messages. |
293
|
|
|
* |
294
|
|
|
* @since 5.3 |
295
|
|
|
*/ |
296
|
|
|
$can_delete = apply_filters( 'bd_delete_jetpack_messages_can_delete', $delete_options, $post_id ); |
297
|
|
|
if ( ! $can_delete ) { |
298
|
|
|
continue; |
299
|
|
|
} |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
// $force delete parameter to custom post types doesn't work |
303
|
|
|
if ( $force_delete ) { |
304
|
|
|
wp_delete_post( $post_id, true ); |
305
|
|
|
} else { |
306
|
|
|
wp_trash_post( $post_id ); |
307
|
|
|
} |
308
|
|
|
$count++; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
return $count; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Check whether Jetpack Contact Form is active. |
316
|
|
|
* |
317
|
|
|
* @static |
318
|
|
|
* |
319
|
|
|
* @since 5.3 |
320
|
|
|
* |
321
|
|
|
* @return bool True if active, False otherwise |
322
|
|
|
*/ |
323
|
|
|
public static function is_jetpack_contact_active() { |
324
|
|
|
$jetpack_active_modules = get_option( 'jetpack_active_modules' ); |
325
|
|
|
if ( class_exists( 'Jetpack', false ) && $jetpack_active_modules && in_array( 'contact-form', $jetpack_active_modules ) ) { |
326
|
|
|
return true; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
return false; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* Append filtering options to the delete feedback page. |
334
|
|
|
* |
335
|
|
|
* @since 0.1 |
336
|
|
|
* @static |
337
|
|
|
*/ |
338
|
|
|
public static function add_filtering_options() { |
339
|
|
|
?> |
340
|
|
|
<table class="optiontable" id="jetpack-filters" style="display:none;"> |
341
|
|
|
<tr> |
342
|
|
|
<td colspan="2"> |
343
|
|
|
<h4><?php _e( 'Choose your filtering options', 'bulk-delete' ); ?></h4> |
344
|
|
|
</td> |
345
|
|
|
</tr> |
346
|
|
|
|
347
|
|
|
<tr> |
348
|
|
|
<td scope="row"> |
349
|
|
|
<input name="smbd_feedback_author_name_filter" id ="smbd_feedback_author_name_filter" value = "true" type = "checkbox"> |
350
|
|
|
</td> |
351
|
|
|
<td> |
352
|
|
|
<?php _e( 'Only if author name ', 'bulk-delete' );?> |
353
|
|
|
<select name="smbd_feedback_author_name_op" id="smbd_feedback_author_name_op" disabled> |
354
|
|
|
<option value ="is"><?php _e( 'is', 'bulk-delete' );?></option> |
355
|
|
|
<option value ="is-not"><?php _e( 'is not', 'bulk-delete' );?></option> |
356
|
|
|
</select> |
357
|
|
|
<input type ="textbox" name="smbd_feedback_author_name_value" id ="smbd_feedback_author_name_value" disabled placeholder="<?php _e( 'Author Name', 'bulk-delete' ); ?>"> |
358
|
|
|
</td> |
359
|
|
|
</tr> |
360
|
|
|
|
361
|
|
|
<tr> |
362
|
|
|
<td scope="row"> |
363
|
|
|
<input name="smbd_feedback_author_email_filter" id ="smbd_feedback_author_email_filter" value = "true" type = "checkbox"> |
364
|
|
|
</td> |
365
|
|
|
<td> |
366
|
|
|
<?php _e( 'Only if author email ', 'bulk-delete' );?> |
367
|
|
|
<select name="smbd_feedback_author_email_op" id="smbd_feedback_author_email_op" disabled> |
368
|
|
|
<option value ="is"><?php _e( 'is', 'bulk-delete' );?></option> |
369
|
|
|
<option value ="is-not"><?php _e( 'is not', 'bulk-delete' );?></option> |
370
|
|
|
</select> |
371
|
|
|
<input type ="textbox" name="smbd_feedback_author_email_value" id ="smbd_feedback_author_email_value" disabled placeholder="<?php _e( 'Author Email', 'bulk-delete' ); ?>"> |
372
|
|
|
</td> |
373
|
|
|
</tr> |
374
|
|
|
|
375
|
|
|
<tr> |
376
|
|
|
<td scope="row"> |
377
|
|
|
<input name="smbd_feedback_author_ip_filter" id ="smbd_feedback_author_ip_filter" value = "true" type = "checkbox"> |
378
|
|
|
</td> |
379
|
|
|
<td> |
380
|
|
|
<?php _e( 'Only if author ip ', 'bulk-delete' );?> |
381
|
|
|
<select name="smbd_feedback_author_ip_op" id="smbd_feedback_author_ip_op" disabled> |
382
|
|
|
<option value ="is"><?php _e( 'is', 'bulk-delete' );?></option> |
383
|
|
|
<option value ="is-not"><?php _e( 'is not', 'bulk-delete' );?></option> |
384
|
|
|
</select> |
385
|
|
|
<input type ="textbox" name="smbd_feedback_author_ip_value" id ="smbd_feedback_author_ip_value" disabled placeholder="<?php _e( 'Author ip', 'bulk-delete' ); ?>"> |
386
|
|
|
</td> |
387
|
|
|
</tr> |
388
|
|
|
</table> |
389
|
|
|
<?php |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Process additional delete options. |
394
|
|
|
* |
395
|
|
|
* @since 0.1 |
396
|
|
|
* @static |
397
|
|
|
* |
398
|
|
|
* @param array $delete_options Delete options array |
399
|
|
|
* @param array $post The Post array |
400
|
|
|
* |
401
|
|
|
* @return array Processed delete options array |
402
|
|
|
*/ |
403
|
|
|
public static function process_filtering_options( $delete_options, $post ) { |
404
|
|
|
$filters = array(); |
405
|
|
|
|
406
|
|
|
if ( 'true' == array_get( $post, 'smbd_feedback_use_filter', 'false' ) ) { |
407
|
|
|
foreach ( array( 'name', 'email', 'ip' ) as $filter_name ) { |
408
|
|
|
if( 'true' == array_get( $post, "smbd_feedback_author_{$filter_name}_filter", 'false' ) ) { |
409
|
|
|
$filters[$filter_name] = array( |
410
|
|
|
'op' => array_get( $post, "smbd_feedback_author_{$filter_name}_op", 'is' ), |
411
|
|
|
'value' => array_get( $post, "smbd_feedback_author_{$filter_name}_value", '' ), |
412
|
|
|
); |
413
|
|
|
} |
414
|
|
|
} |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
$delete_options['filters'] = $filters; |
418
|
|
|
|
419
|
|
|
return $delete_options; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Whether the current message should be deleted based on user selection. |
424
|
|
|
* |
425
|
|
|
* @static |
426
|
|
|
* |
427
|
|
|
* @since 0.1 |
428
|
|
|
* |
429
|
|
|
* @param array $delete_options List of options chosen by the user |
430
|
|
|
* @param int $post_id Post id |
431
|
|
|
* |
432
|
|
|
* @return bool True if the message should be deleted, False otherwise |
433
|
|
|
*/ |
434
|
|
|
public static function can_delete( $delete_options, $post_id ) { |
435
|
|
|
$can_delete = false; |
436
|
|
|
|
437
|
|
|
if ( Bulk_Delete_Jetpack_Contact_Form_Message::is_jetpack_contact_active() ) { |
|
|
|
|
438
|
|
|
$content_fields = Grunion_Contact_Form_Plugin::parse_fields_from_content( $post_id ); |
439
|
|
|
|
440
|
|
|
$author_name = $content_fields['_feedback_author']; |
441
|
|
|
$author_email = $content_fields['_feedback_author_email']; |
442
|
|
|
$author_ip = $content_fields['_feedback_ip']; |
443
|
|
|
|
444
|
|
|
$filters = $delete_options['filters']; |
445
|
|
|
foreach ( $filters as $name => $filter ) { |
446
|
|
|
$field = "author_{$name}"; |
447
|
|
|
if ( 'is' == $filter['op'] ) { |
448
|
|
|
if ( $$field == $filter['value'] ) { |
449
|
|
|
$can_delete = true; |
450
|
|
|
} |
451
|
|
|
} else { |
452
|
|
|
if ( $$field != $filter['value'] ) { |
453
|
|
|
$can_delete = true; |
454
|
|
|
} |
455
|
|
|
} |
456
|
|
|
} |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
return $can_delete; |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
/** |
463
|
|
|
* Hook handler. |
464
|
|
|
* |
465
|
|
|
* @since 0.1 |
466
|
|
|
* @static |
467
|
|
|
* |
468
|
|
|
* @param array $delete_options Delete options array |
469
|
|
|
*/ |
470
|
|
|
public static function do_delete_jetpack_messages_cron( $delete_options ) { |
471
|
|
|
do_action( 'bd_before_scheduler', self::CRON_NAME ); |
472
|
|
|
$count = self::delete_jetpack_messages( $delete_options ); |
473
|
|
|
do_action( 'bd_after_scheduler', self::CRON_NAME, $count ); |
474
|
|
|
} |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
// hooks |
478
|
|
|
add_action( 'bd_add_meta_box_for_misc' , array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'add_delete_jetpack_messages_meta_box' ) ); |
479
|
|
|
add_action( 'bd_delete_jetpack_messages', array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'do_delete_jetpack_messages' ) ); |
480
|
|
|
|
481
|
|
|
add_filter( 'bd_javascript_array', array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'filter_js_array' ) ); |
482
|
|
|
add_action( 'bd_delete_jetpack_messages_form', array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'add_filtering_options' ) ); |
483
|
|
|
|
484
|
|
|
add_filter( 'bd_delete_jetpack_messages_delete_options', array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'process_filtering_options' ), 10, 2 ); |
485
|
|
|
add_filter( 'bd_delete_jetpack_messages_can_delete', array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'can_delete' ), 10, 2 ); |
486
|
|
|
|
487
|
|
|
// cron hooks |
488
|
|
|
add_action( Bulk_Delete_Jetpack_Contact_Form_Message::CRON_HOOK, array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'do_delete_jetpack_messages_cron' ), 10, 1 ); |
489
|
|
|
?> |
490
|
|
|
|
This check looks for accesses to local static members using the fully qualified name instead of
self::
.While this is perfectly valid, the fully qualified name of
Certificate::TRIPLEDES_CBC
could just as well be replaced byself::TRIPLEDES_CBC
. Referencing local members withself::
assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.