|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class acf_location { |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* __construct |
|
7
|
|
|
* |
|
8
|
|
|
* Initialize filters, action, variables and includes |
|
9
|
|
|
* |
|
10
|
|
|
* @type function |
|
11
|
|
|
* @date 23/06/12 |
|
12
|
|
|
* @since 5.0.0 |
|
13
|
|
|
* |
|
14
|
|
|
* @param n/a |
|
15
|
|
|
* @return n/a |
|
16
|
|
|
*/ |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
function __construct() { |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
// Post |
|
21
|
|
|
add_filter( 'acf/location/rule_match/post_type', array($this, 'rule_match_post_type'), 10, 3 ); |
|
22
|
|
|
add_filter( 'acf/location/rule_match/post', array($this, 'rule_match_post'), 10, 3 ); |
|
23
|
|
|
add_filter( 'acf/location/rule_match/post_category', array($this, 'rule_match_post_taxonomy'), 10, 3 ); |
|
24
|
|
|
add_filter( 'acf/location/rule_match/post_format', array($this, 'rule_match_post_format'), 10, 3 ); |
|
25
|
|
|
add_filter( 'acf/location/rule_match/post_status', array($this, 'rule_match_post_status'), 10, 3 ); |
|
26
|
|
|
add_filter( 'acf/location/rule_match/post_taxonomy', array($this, 'rule_match_post_taxonomy'), 10, 3 ); |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
// Page |
|
30
|
|
|
add_filter( 'acf/location/rule_match/page', array($this, 'rule_match_post'), 10, 3 ); |
|
31
|
|
|
add_filter( 'acf/location/rule_match/page_type', array($this, 'rule_match_page_type'), 10, 3 ); |
|
32
|
|
|
add_filter( 'acf/location/rule_match/page_parent', array($this, 'rule_match_page_parent'), 10, 3 ); |
|
33
|
|
|
add_filter( 'acf/location/rule_match/page_template', array($this, 'rule_match_page_template'), 10, 3 ); |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
// User |
|
37
|
|
|
add_filter( 'acf/location/rule_match/current_user', array($this, 'rule_match_current_user'), 10, 3 ); |
|
38
|
|
|
add_filter( 'acf/location/rule_match/current_user_role', array($this, 'rule_match_current_user_role'), 10, 3 ); |
|
39
|
|
|
add_filter( 'acf/location/rule_match/user_form', array($this, 'rule_match_user_form'), 10, 3 ); |
|
40
|
|
|
add_filter( 'acf/location/rule_match/user_role', array($this, 'rule_match_user_role'), 10, 3 ); |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
// Form |
|
44
|
|
|
add_filter( 'acf/location/rule_match/taxonomy', array($this, 'rule_match_taxonomy'), 10, 3 ); |
|
45
|
|
|
add_filter( 'acf/location/rule_match/attachment', array($this, 'rule_match_attachment'), 10, 3 ); |
|
46
|
|
|
add_filter( 'acf/location/rule_match/comment', array($this, 'rule_match_comment'), 10, 3 ); |
|
47
|
|
|
add_filter( 'acf/location/rule_match/widget', array($this, 'rule_match_widget'), 10, 3 ); |
|
48
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/* |
|
53
|
|
|
* rule_match_post_type |
|
54
|
|
|
* |
|
55
|
|
|
* This function will match a location rule and return true or false |
|
56
|
|
|
* |
|
57
|
|
|
* @type filter |
|
58
|
|
|
* @date 3/01/13 |
|
59
|
|
|
* @since 3.5.7 |
|
60
|
|
|
* |
|
61
|
|
|
* @param $match (boolean) |
|
62
|
|
|
* @param $rule (array) |
|
63
|
|
|
* @return $options (array) |
|
64
|
|
|
*/ |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
View Code Duplication |
function rule_match_post_type( $match, $rule, $options ) { |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
// vars |
|
69
|
|
|
$post_type = $options['post_type']; |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
// find post type for current post |
|
73
|
|
|
if( !$post_type ) { |
|
74
|
|
|
|
|
75
|
|
|
if( !$options['post_id'] ) { |
|
76
|
|
|
|
|
77
|
|
|
return false; |
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$post_type = get_post_type( $options['post_id'] ); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
// compare |
|
86
|
|
|
if( $rule['operator'] == "==" ) { |
|
87
|
|
|
|
|
88
|
|
|
$match = ( $post_type === $rule['value'] ); |
|
89
|
|
|
|
|
90
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
91
|
|
|
|
|
92
|
|
|
$match = ( $post_type !== $rule['value'] ); |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
// return |
|
98
|
|
|
return $match; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
/* |
|
103
|
|
|
* rule_match_current_user |
|
104
|
|
|
* |
|
105
|
|
|
* This function will match a location rule and return true or false |
|
106
|
|
|
* |
|
107
|
|
|
* @type filter |
|
108
|
|
|
* @date 3/01/13 |
|
109
|
|
|
* @since 3.5.7 |
|
110
|
|
|
* |
|
111
|
|
|
* @param $match (boolean) |
|
112
|
|
|
* @param $rule (array) |
|
113
|
|
|
* @return $options (array) |
|
114
|
|
|
*/ |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
function rule_match_current_user( $match, $rule, $options ) { |
|
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
// logged in |
|
119
|
|
View Code Duplication |
if( $rule['value'] == 'logged_in' ) { |
|
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
if( $rule['operator'] == "==" ) { |
|
122
|
|
|
|
|
123
|
|
|
$match = is_user_logged_in(); |
|
124
|
|
|
|
|
125
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
126
|
|
|
|
|
127
|
|
|
$match = !is_user_logged_in(); |
|
128
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
return $match; |
|
132
|
|
|
|
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
// front end |
|
137
|
|
View Code Duplication |
if( $rule['value'] == 'viewing_front' ) { |
|
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
if( $rule['operator'] == "==" ) { |
|
140
|
|
|
|
|
141
|
|
|
$match = !is_admin(); |
|
142
|
|
|
|
|
143
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
144
|
|
|
|
|
145
|
|
|
$match = is_admin(); |
|
146
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
return $match; |
|
150
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
// back end |
|
155
|
|
View Code Duplication |
if( $rule['value'] == 'viewing_back' ) { |
|
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
if( $rule['operator'] == "==" ) { |
|
158
|
|
|
|
|
159
|
|
|
$match = is_admin(); |
|
160
|
|
|
|
|
161
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
162
|
|
|
|
|
163
|
|
|
$match = !is_admin(); |
|
164
|
|
|
|
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
return $match; |
|
168
|
|
|
|
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
// return |
|
173
|
|
|
return $match; |
|
174
|
|
|
|
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
|
|
178
|
|
|
/* |
|
179
|
|
|
* rule_match_current_user_role |
|
180
|
|
|
* |
|
181
|
|
|
* This function will match a location rule and return true or false |
|
182
|
|
|
* |
|
183
|
|
|
* @type filter |
|
184
|
|
|
* @date 3/01/13 |
|
185
|
|
|
* @since 3.5.7 |
|
186
|
|
|
* |
|
187
|
|
|
* @param $match (boolean) |
|
188
|
|
|
* @param $rule (array) |
|
189
|
|
|
* @return $options (array) |
|
190
|
|
|
*/ |
|
|
|
|
|
|
191
|
|
|
|
|
192
|
|
|
function rule_match_current_user_role( $match, $rule, $options ) { |
|
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
// bail early if not logged in |
|
195
|
|
|
if( !is_user_logged_in() ) { |
|
196
|
|
|
|
|
197
|
|
|
return false; |
|
198
|
|
|
|
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
// vars |
|
203
|
|
|
$user = wp_get_current_user(); |
|
204
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
// compare |
|
207
|
|
|
if( $rule['operator'] == "==" ) { |
|
208
|
|
|
|
|
209
|
|
View Code Duplication |
if( $rule['value'] == 'super_admin' ) { |
|
|
|
|
|
|
210
|
|
|
|
|
211
|
|
|
$match = is_super_admin( $user->ID ); |
|
212
|
|
|
|
|
213
|
|
|
} else { |
|
214
|
|
|
|
|
215
|
|
|
$match = in_array( $rule['value'], $user->roles ); |
|
216
|
|
|
|
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
220
|
|
|
|
|
221
|
|
View Code Duplication |
if( $rule['value'] == 'super_admin' ) { |
|
|
|
|
|
|
222
|
|
|
|
|
223
|
|
|
$match = !is_super_admin( $user->ID ); |
|
224
|
|
|
|
|
225
|
|
|
} else { |
|
226
|
|
|
|
|
227
|
|
|
$match = ( ! in_array( $rule['value'], $user->roles ) ); |
|
228
|
|
|
|
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
|
|
234
|
|
|
// return |
|
235
|
|
|
return $match; |
|
236
|
|
|
|
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
|
|
240
|
|
|
/* |
|
241
|
|
|
* rule_match_post |
|
242
|
|
|
* |
|
243
|
|
|
* This function will match a location rule and return true or false |
|
244
|
|
|
* |
|
245
|
|
|
* @type filter |
|
246
|
|
|
* @date 3/01/13 |
|
247
|
|
|
* @since 3.5.7 |
|
248
|
|
|
* |
|
249
|
|
|
* @param $match (boolean) |
|
250
|
|
|
* @param $rule (array) |
|
251
|
|
|
* @return $options (array) |
|
252
|
|
|
*/ |
|
|
|
|
|
|
253
|
|
|
|
|
254
|
|
|
function rule_match_post( $match, $rule, $options ) { |
|
|
|
|
|
|
255
|
|
|
|
|
256
|
|
|
// vars |
|
257
|
|
|
$post_id = $options['post_id']; |
|
258
|
|
|
|
|
259
|
|
|
|
|
260
|
|
|
// validation |
|
261
|
|
|
if( !$post_id ) { |
|
262
|
|
|
|
|
263
|
|
|
return false; |
|
264
|
|
|
|
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
|
|
268
|
|
|
// translate $rule['value'] |
|
269
|
|
|
// - this variable will hold the original post_id, but $options['post_id'] will hold the translated version |
|
270
|
|
|
//if( function_exists('icl_object_id') ) |
|
271
|
|
|
//{ |
|
272
|
|
|
// $rule['value'] = icl_object_id( $rule['value'], $options['post_type'], true ); |
|
273
|
|
|
//} |
|
274
|
|
|
|
|
275
|
|
|
|
|
276
|
|
|
// compare |
|
277
|
|
|
if( $rule['operator'] == "==") { |
|
278
|
|
|
|
|
279
|
|
|
$match = ( $options['post_id'] == $rule['value'] ); |
|
280
|
|
|
|
|
281
|
|
|
} elseif( $rule['operator'] == "!=") { |
|
282
|
|
|
|
|
283
|
|
|
$match = ( $options['post_id'] != $rule['value'] ); |
|
284
|
|
|
|
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
|
|
288
|
|
|
// return |
|
289
|
|
|
return $match; |
|
290
|
|
|
|
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
|
|
294
|
|
|
/* |
|
295
|
|
|
* rule_match_post_taxonomy |
|
296
|
|
|
* |
|
297
|
|
|
* This function will match a location rule and return true or false |
|
298
|
|
|
* |
|
299
|
|
|
* @type filter |
|
300
|
|
|
* @date 3/01/13 |
|
301
|
|
|
* @since 3.5.7 |
|
302
|
|
|
* |
|
303
|
|
|
* @param $match (boolean) |
|
304
|
|
|
* @param $rule (array) |
|
305
|
|
|
* @return $options (array) |
|
306
|
|
|
*/ |
|
|
|
|
|
|
307
|
|
|
|
|
308
|
|
|
function rule_match_post_taxonomy( $match, $rule, $options ) { |
|
|
|
|
|
|
309
|
|
|
|
|
310
|
|
|
// validate |
|
311
|
|
|
if( !$options['post_id'] ) { |
|
312
|
|
|
|
|
313
|
|
|
return false; |
|
314
|
|
|
|
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
|
|
318
|
|
|
// vars |
|
319
|
|
|
$terms = $options['post_taxonomy']; |
|
320
|
|
|
|
|
321
|
|
|
|
|
322
|
|
|
// get term data |
|
323
|
|
|
// - selected term may have a numeric slug '123' (user reported on forum), so always check slug first |
|
324
|
|
|
$data = acf_decode_taxonomy_term( $rule['value'] ); |
|
325
|
|
|
$term = get_term_by( 'slug', $data['term'], $data['taxonomy'] ); |
|
326
|
|
|
|
|
327
|
|
|
|
|
328
|
|
|
// attempt get term via ID (ACF4 uses ID) |
|
329
|
|
|
if( !$term && is_numeric($data['term']) ) { |
|
330
|
|
|
|
|
331
|
|
|
$term = get_term_by( 'id', $data['term'], $data['taxonomy'] ); |
|
332
|
|
|
|
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
|
|
336
|
|
|
// bail early if no term |
|
337
|
|
|
if( !$term ) { |
|
338
|
|
|
|
|
339
|
|
|
return false; |
|
340
|
|
|
|
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
|
|
344
|
|
|
// post type |
|
345
|
|
|
if( !$options['post_type'] ) { |
|
346
|
|
|
|
|
347
|
|
|
$options['post_type'] = get_post_type( $options['post_id'] ); |
|
348
|
|
|
|
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
|
|
352
|
|
|
// get terms |
|
353
|
|
|
// - allow an empty array (sent via JS) to avoid loading the real post's terms |
|
354
|
|
|
if( !is_array($terms) ) { |
|
355
|
|
|
|
|
356
|
|
|
$terms = wp_get_post_terms( $options['post_id'], $term->taxonomy, array('fields' => 'ids') ); |
|
357
|
|
|
|
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
|
|
361
|
|
|
// If no terms, this is a new post and should be treated as if it has the "Uncategorized" (1) category ticked |
|
362
|
|
|
if( empty($terms) ) { |
|
363
|
|
|
|
|
364
|
|
|
if( is_object_in_taxonomy($options['post_type'], 'category') ) { |
|
365
|
|
|
|
|
366
|
|
|
$terms = array( 1 ); |
|
367
|
|
|
|
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
|
|
373
|
|
|
// compare |
|
374
|
|
|
if( $rule['operator'] == "==") { |
|
375
|
|
|
|
|
376
|
|
|
$match = in_array($term->term_id, $terms); |
|
377
|
|
|
|
|
378
|
|
|
} elseif( $rule['operator'] == "!=") { |
|
379
|
|
|
|
|
380
|
|
|
$match = !in_array($term->term_id, $terms); |
|
381
|
|
|
|
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
|
|
385
|
|
|
// return |
|
386
|
|
|
return $match; |
|
387
|
|
|
|
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
|
|
391
|
|
|
/* |
|
392
|
|
|
* rule_match_post_format |
|
393
|
|
|
* |
|
394
|
|
|
* This function will match a location rule and return true or false |
|
395
|
|
|
* |
|
396
|
|
|
* @type filter |
|
397
|
|
|
* @date 3/01/13 |
|
398
|
|
|
* @since 3.5.7 |
|
399
|
|
|
* |
|
400
|
|
|
* @param $match (boolean) |
|
401
|
|
|
* @param $rule (array) |
|
402
|
|
|
* @return $options (array) |
|
403
|
|
|
*/ |
|
|
|
|
|
|
404
|
|
|
|
|
405
|
|
|
function rule_match_post_format( $match, $rule, $options ) { |
|
|
|
|
|
|
406
|
|
|
|
|
407
|
|
|
// vars |
|
408
|
|
|
$post_format = $options['post_format']; |
|
409
|
|
|
|
|
410
|
|
|
|
|
411
|
|
|
// new post format? |
|
412
|
|
|
if( !$post_format ) { |
|
413
|
|
|
|
|
414
|
|
|
// validate |
|
415
|
|
|
if( !$options['post_id'] ) { |
|
416
|
|
|
|
|
417
|
|
|
return false; |
|
418
|
|
|
|
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
|
|
422
|
|
|
// post type |
|
423
|
|
|
if( !$options['post_type'] ) { |
|
424
|
|
|
|
|
425
|
|
|
$options['post_type'] = get_post_type( $options['post_id'] ); |
|
426
|
|
|
|
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
|
|
|
|
430
|
|
|
// does post_type support 'post-format' |
|
431
|
|
|
if( post_type_supports( $options['post_type'], 'post-formats' ) ) { |
|
432
|
|
|
|
|
433
|
|
|
$post_format = get_post_format( $options['post_id'] ); |
|
434
|
|
|
|
|
435
|
|
|
if( $post_format === false ) { |
|
436
|
|
|
|
|
437
|
|
|
$post_format = 'standard'; |
|
438
|
|
|
|
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
|
|
446
|
|
|
// compare |
|
447
|
|
|
if( $rule['operator'] == "==") { |
|
448
|
|
|
|
|
449
|
|
|
$match = ( $post_format === $rule['value'] ); |
|
450
|
|
|
|
|
451
|
|
|
} elseif( $rule['operator'] == "!=") { |
|
452
|
|
|
|
|
453
|
|
|
$match = ( $post_format !== $rule['value'] ); |
|
454
|
|
|
|
|
455
|
|
|
} |
|
456
|
|
|
|
|
457
|
|
|
|
|
458
|
|
|
// return |
|
459
|
|
|
return $match; |
|
460
|
|
|
|
|
461
|
|
|
} |
|
462
|
|
|
|
|
463
|
|
|
|
|
464
|
|
|
/* |
|
465
|
|
|
* rule_match_post_status |
|
466
|
|
|
* |
|
467
|
|
|
* This function will match a location rule and return true or false |
|
468
|
|
|
* |
|
469
|
|
|
* @type filter |
|
470
|
|
|
* @date 3/01/13 |
|
471
|
|
|
* @since 3.5.7 |
|
472
|
|
|
* |
|
473
|
|
|
* @param $match (boolean) |
|
474
|
|
|
* @param $rule (array) |
|
475
|
|
|
* @return $options (array) |
|
476
|
|
|
*/ |
|
|
|
|
|
|
477
|
|
|
|
|
478
|
|
View Code Duplication |
function rule_match_post_status( $match, $rule, $options ) { |
|
|
|
|
|
|
479
|
|
|
|
|
480
|
|
|
// validate |
|
481
|
|
|
if( !$options['post_id'] ) { |
|
482
|
|
|
|
|
483
|
|
|
return false; |
|
484
|
|
|
|
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
|
|
488
|
|
|
// vars |
|
489
|
|
|
$post_status = get_post_status( $options['post_id'] ); |
|
490
|
|
|
|
|
491
|
|
|
|
|
492
|
|
|
// auto-draft = draft |
|
493
|
|
|
if( $post_status == 'auto-draft' ) { |
|
494
|
|
|
|
|
495
|
|
|
$post_status = 'draft'; |
|
496
|
|
|
|
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
|
|
500
|
|
|
// compare |
|
501
|
|
|
if( $rule['operator'] == "==") { |
|
502
|
|
|
|
|
503
|
|
|
$match = ( $post_status === $rule['value'] ); |
|
504
|
|
|
|
|
505
|
|
|
} elseif( $rule['operator'] == "!=") { |
|
506
|
|
|
|
|
507
|
|
|
$match = ( $post_status !== $rule['value'] ); |
|
508
|
|
|
|
|
509
|
|
|
} |
|
510
|
|
|
|
|
511
|
|
|
|
|
512
|
|
|
// return |
|
513
|
|
|
return $match; |
|
514
|
|
|
|
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
|
|
518
|
|
|
/* |
|
519
|
|
|
* rule_match_page_type |
|
520
|
|
|
* |
|
521
|
|
|
* This function will match a location rule and return true or false |
|
522
|
|
|
* |
|
523
|
|
|
* @type filter |
|
524
|
|
|
* @date 3/01/13 |
|
525
|
|
|
* @since 3.5.7 |
|
526
|
|
|
* |
|
527
|
|
|
* @param $match (boolean) |
|
528
|
|
|
* @param $rule (array) |
|
529
|
|
|
* @return $options (array) |
|
530
|
|
|
*/ |
|
|
|
|
|
|
531
|
|
|
|
|
532
|
|
|
function rule_match_page_type( $match, $rule, $options ) { |
|
|
|
|
|
|
533
|
|
|
|
|
534
|
|
|
// validation |
|
535
|
|
|
if( !$options['post_id'] ) { |
|
536
|
|
|
|
|
537
|
|
|
return false; |
|
538
|
|
|
|
|
539
|
|
|
} |
|
540
|
|
|
|
|
541
|
|
|
|
|
542
|
|
|
// get post |
|
543
|
|
|
$post = get_post( $options['post_id'] ); |
|
544
|
|
|
|
|
545
|
|
|
|
|
546
|
|
|
// compare |
|
547
|
|
|
if( $rule['value'] == 'front_page') { |
|
548
|
|
|
|
|
549
|
|
|
// vars |
|
550
|
|
|
$front_page = (int) get_option('page_on_front'); |
|
551
|
|
|
|
|
552
|
|
|
|
|
553
|
|
|
// compare |
|
554
|
|
View Code Duplication |
if( $rule['operator'] == "==" ) { |
|
|
|
|
|
|
555
|
|
|
|
|
556
|
|
|
$match = ( $front_page == $post->ID ); |
|
557
|
|
|
|
|
558
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
559
|
|
|
|
|
560
|
|
|
$match = ( $front_page != $post->ID ); |
|
561
|
|
|
|
|
562
|
|
|
} |
|
563
|
|
|
|
|
564
|
|
|
} elseif( $rule['value'] == 'posts_page') { |
|
565
|
|
|
|
|
566
|
|
|
// vars |
|
567
|
|
|
$posts_page = (int) get_option('page_for_posts'); |
|
568
|
|
|
|
|
569
|
|
|
|
|
570
|
|
|
// compare |
|
571
|
|
View Code Duplication |
if( $rule['operator'] == "==" ) { |
|
|
|
|
|
|
572
|
|
|
|
|
573
|
|
|
$match = ( $posts_page == $post->ID ); |
|
574
|
|
|
|
|
575
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
576
|
|
|
|
|
577
|
|
|
$match = ( $posts_page != $post->ID ); |
|
578
|
|
|
|
|
579
|
|
|
} |
|
580
|
|
|
|
|
581
|
|
View Code Duplication |
} elseif( $rule['value'] == 'top_level') { |
|
|
|
|
|
|
582
|
|
|
|
|
583
|
|
|
// vars |
|
584
|
|
|
$post_parent = $post->post_parent; |
|
585
|
|
|
|
|
586
|
|
|
|
|
587
|
|
|
// override |
|
588
|
|
|
if( $options['page_parent'] ) { |
|
589
|
|
|
|
|
590
|
|
|
$post_parent = $options['page_parent']; |
|
591
|
|
|
|
|
592
|
|
|
} |
|
593
|
|
|
|
|
594
|
|
|
|
|
595
|
|
|
// compare |
|
596
|
|
|
if( $rule['operator'] == "==" ) { |
|
597
|
|
|
|
|
598
|
|
|
$match = ( $post_parent == 0 ); |
|
599
|
|
|
|
|
600
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
601
|
|
|
|
|
602
|
|
|
$match = ( $post_parent != 0 ); |
|
603
|
|
|
|
|
604
|
|
|
} |
|
605
|
|
|
|
|
606
|
|
|
} elseif( $rule['value'] == 'parent' ) { |
|
607
|
|
|
|
|
608
|
|
|
// get children |
|
609
|
|
|
$children = get_pages(array( |
|
610
|
|
|
'post_type' => $post->post_type, |
|
611
|
|
|
'child_of' => $post->ID, |
|
612
|
|
|
)); |
|
613
|
|
|
|
|
614
|
|
|
|
|
615
|
|
|
// compare |
|
616
|
|
|
if( $rule['operator'] == "==" ) { |
|
617
|
|
|
|
|
618
|
|
|
$match = ( count($children) > 0 ); |
|
619
|
|
|
|
|
620
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
621
|
|
|
|
|
622
|
|
|
$match = ( count($children) == 0 ); |
|
623
|
|
|
|
|
624
|
|
|
} |
|
625
|
|
|
|
|
626
|
|
View Code Duplication |
} elseif( $rule['value'] == 'child') { |
|
|
|
|
|
|
627
|
|
|
|
|
628
|
|
|
// vars |
|
629
|
|
|
$post_parent = $post->post_parent; |
|
630
|
|
|
|
|
631
|
|
|
|
|
632
|
|
|
// override |
|
633
|
|
|
if( $options['page_parent'] ) { |
|
634
|
|
|
|
|
635
|
|
|
$post_parent = $options['page_parent']; |
|
636
|
|
|
|
|
637
|
|
|
} |
|
638
|
|
|
|
|
639
|
|
|
|
|
640
|
|
|
// compare |
|
641
|
|
|
if( $rule['operator'] == "==" ) { |
|
642
|
|
|
|
|
643
|
|
|
$match = ( $post_parent != 0 ); |
|
644
|
|
|
|
|
645
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
646
|
|
|
|
|
647
|
|
|
$match = ( $post_parent == 0 ); |
|
648
|
|
|
|
|
649
|
|
|
} |
|
650
|
|
|
|
|
651
|
|
|
} |
|
652
|
|
|
|
|
653
|
|
|
|
|
654
|
|
|
// return |
|
655
|
|
|
return $match; |
|
656
|
|
|
|
|
657
|
|
|
} |
|
658
|
|
|
|
|
659
|
|
|
|
|
660
|
|
|
/* |
|
661
|
|
|
* rule_match_page_parent |
|
662
|
|
|
* |
|
663
|
|
|
* This function will match a location rule and return true or false |
|
664
|
|
|
* |
|
665
|
|
|
* @type filter |
|
666
|
|
|
* @date 3/01/13 |
|
667
|
|
|
* @since 3.5.7 |
|
668
|
|
|
* |
|
669
|
|
|
* @param $match (boolean) |
|
670
|
|
|
* @param $rule (array) |
|
671
|
|
|
* @return $options (array) |
|
672
|
|
|
*/ |
|
|
|
|
|
|
673
|
|
|
|
|
674
|
|
|
function rule_match_page_parent( $match, $rule, $options ) { |
|
|
|
|
|
|
675
|
|
|
|
|
676
|
|
|
// validation |
|
677
|
|
|
if( !$options['post_id'] ) { |
|
678
|
|
|
|
|
679
|
|
|
return false; |
|
680
|
|
|
|
|
681
|
|
|
} |
|
682
|
|
|
|
|
683
|
|
|
|
|
684
|
|
|
// vars |
|
685
|
|
|
$post = get_post( $options['post_id'] ); |
|
686
|
|
|
|
|
687
|
|
|
|
|
688
|
|
|
// post parent |
|
689
|
|
|
$post_parent = $post->post_parent; |
|
690
|
|
|
if( $options['page_parent'] ) { |
|
691
|
|
|
|
|
692
|
|
|
$post_parent = $options['page_parent']; |
|
693
|
|
|
|
|
694
|
|
|
} |
|
695
|
|
|
|
|
696
|
|
|
|
|
697
|
|
|
// compare |
|
698
|
|
|
if( $rule['operator'] == "==" ) { |
|
699
|
|
|
|
|
700
|
|
|
$match = ( $post_parent == $rule['value'] ); |
|
701
|
|
|
|
|
702
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
703
|
|
|
|
|
704
|
|
|
$match = ( $post_parent != $rule['value'] ); |
|
705
|
|
|
|
|
706
|
|
|
} |
|
707
|
|
|
|
|
708
|
|
|
|
|
709
|
|
|
// return |
|
710
|
|
|
return $match; |
|
711
|
|
|
|
|
712
|
|
|
} |
|
713
|
|
|
|
|
714
|
|
|
|
|
715
|
|
|
/* |
|
716
|
|
|
* rule_match_page_template |
|
717
|
|
|
* |
|
718
|
|
|
* This function will match a location rule and return true or false |
|
719
|
|
|
* |
|
720
|
|
|
* @type filter |
|
721
|
|
|
* @date 3/01/13 |
|
722
|
|
|
* @since 3.5.7 |
|
723
|
|
|
* |
|
724
|
|
|
* @param $match (boolean) |
|
725
|
|
|
* @param $rule (array) |
|
726
|
|
|
* @return $options (array) |
|
727
|
|
|
*/ |
|
|
|
|
|
|
728
|
|
|
|
|
729
|
|
|
function rule_match_page_template( $match, $rule, $options ) { |
|
|
|
|
|
|
730
|
|
|
|
|
731
|
|
|
// vars |
|
732
|
|
|
$page_template = $options['page_template']; |
|
733
|
|
|
|
|
734
|
|
|
|
|
735
|
|
|
// get page template |
|
736
|
|
|
if( !$page_template && $options['post_id'] ) { |
|
737
|
|
|
|
|
738
|
|
|
$page_template = get_post_meta( $options['post_id'], '_wp_page_template', true ); |
|
739
|
|
|
|
|
740
|
|
|
} |
|
741
|
|
|
|
|
742
|
|
|
|
|
743
|
|
|
// get page template again |
|
744
|
|
|
if( ! $page_template ) { |
|
745
|
|
|
|
|
746
|
|
|
$post_type = $options['post_type']; |
|
747
|
|
|
|
|
748
|
|
|
if( !$post_type && $options['post_id'] ) { |
|
749
|
|
|
|
|
750
|
|
|
$post_type = get_post_type( $options['post_id'] ); |
|
751
|
|
|
|
|
752
|
|
|
} |
|
753
|
|
|
|
|
754
|
|
|
if( $post_type === 'page' ) { |
|
755
|
|
|
|
|
756
|
|
|
$page_template = "default"; |
|
757
|
|
|
|
|
758
|
|
|
} |
|
759
|
|
|
} |
|
760
|
|
|
|
|
761
|
|
|
|
|
762
|
|
|
// compare |
|
763
|
|
|
if( $rule['operator'] == "==" ) { |
|
764
|
|
|
|
|
765
|
|
|
$match = ( $page_template === $rule['value'] ); |
|
766
|
|
|
|
|
767
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
768
|
|
|
|
|
769
|
|
|
$match = ( $page_template !== $rule['value'] ); |
|
770
|
|
|
|
|
771
|
|
|
} |
|
772
|
|
|
|
|
773
|
|
|
|
|
774
|
|
|
// return |
|
775
|
|
|
return $match; |
|
776
|
|
|
|
|
777
|
|
|
} |
|
778
|
|
|
|
|
779
|
|
|
|
|
780
|
|
|
/* |
|
781
|
|
|
* rule_match_user_form |
|
782
|
|
|
* |
|
783
|
|
|
* This function will match a location rule and return true or false |
|
784
|
|
|
* |
|
785
|
|
|
* @type filter |
|
786
|
|
|
* @date 3/01/13 |
|
787
|
|
|
* @since 3.5.7 |
|
788
|
|
|
* |
|
789
|
|
|
* @param $match (boolean) |
|
790
|
|
|
* @param $rule (array) |
|
791
|
|
|
* @return $options (array) |
|
792
|
|
|
*/ |
|
|
|
|
|
|
793
|
|
|
|
|
794
|
|
|
function rule_match_user_form( $match, $rule, $options ) { |
|
|
|
|
|
|
795
|
|
|
|
|
796
|
|
|
// vars |
|
797
|
|
|
$user_form = $options['user_form']; |
|
798
|
|
|
|
|
799
|
|
|
|
|
800
|
|
|
// add is treated the same as edit |
|
801
|
|
|
if( $user_form === 'add' ) { |
|
802
|
|
|
|
|
803
|
|
|
$user_form = 'edit'; |
|
804
|
|
|
|
|
805
|
|
|
} |
|
806
|
|
|
|
|
807
|
|
|
|
|
808
|
|
|
// compare |
|
809
|
|
|
if( $user_form ) { |
|
810
|
|
|
|
|
811
|
|
|
if( $rule['operator'] == "==" ) { |
|
812
|
|
|
|
|
813
|
|
|
$match = ( $user_form == $rule['value'] ); |
|
814
|
|
|
|
|
815
|
|
|
|
|
816
|
|
|
// override for "all" |
|
817
|
|
|
if( $rule['value'] === 'all' ) { |
|
818
|
|
|
|
|
819
|
|
|
$match = true; |
|
820
|
|
|
|
|
821
|
|
|
} |
|
822
|
|
|
|
|
823
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
824
|
|
|
|
|
825
|
|
|
$match = ( $user_form != $rule['value'] ); |
|
826
|
|
|
|
|
827
|
|
|
|
|
828
|
|
|
// override for "all" |
|
829
|
|
|
if( $rule['value'] === 'all' ) { |
|
830
|
|
|
|
|
831
|
|
|
$match = false; |
|
832
|
|
|
|
|
833
|
|
|
} |
|
834
|
|
|
|
|
835
|
|
|
} |
|
836
|
|
|
|
|
837
|
|
|
} |
|
838
|
|
|
|
|
839
|
|
|
|
|
840
|
|
|
// return |
|
841
|
|
|
return $match; |
|
842
|
|
|
} |
|
843
|
|
|
|
|
844
|
|
|
|
|
845
|
|
|
/* |
|
846
|
|
|
* rule_match_user_role |
|
847
|
|
|
* |
|
848
|
|
|
* This function will match a location rule and return true or false |
|
849
|
|
|
* |
|
850
|
|
|
* @type filter |
|
851
|
|
|
* @date 3/01/13 |
|
852
|
|
|
* @since 3.5.7 |
|
853
|
|
|
* |
|
854
|
|
|
* @param $match (boolean) |
|
855
|
|
|
* @param $rule (array) |
|
856
|
|
|
* @return $options (array) |
|
857
|
|
|
*/ |
|
|
|
|
|
|
858
|
|
|
|
|
859
|
|
|
function rule_match_user_role( $match, $rule, $options ) { |
|
|
|
|
|
|
860
|
|
|
|
|
861
|
|
|
// vars |
|
862
|
|
|
$user_id = $options['user_id']; |
|
863
|
|
|
$user_role = $options['user_role']; |
|
864
|
|
|
|
|
865
|
|
|
|
|
866
|
|
|
// user form AJAX will send through user_form |
|
867
|
|
|
if( $user_role ) { |
|
868
|
|
|
|
|
869
|
|
|
if( $rule['operator'] == "==" ) { |
|
870
|
|
|
|
|
871
|
|
|
if( $user_role === $rule['value'] ) { |
|
872
|
|
|
|
|
873
|
|
|
$match = true; |
|
874
|
|
|
|
|
875
|
|
|
} |
|
876
|
|
|
|
|
877
|
|
|
|
|
878
|
|
|
// override for "all" |
|
879
|
|
|
if( $rule['value'] === 'all' ) { |
|
880
|
|
|
|
|
881
|
|
|
$match = true; |
|
882
|
|
|
|
|
883
|
|
|
} |
|
884
|
|
|
|
|
885
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
886
|
|
|
|
|
887
|
|
|
if( $user_role !== $rule['value'] ) { |
|
888
|
|
|
|
|
889
|
|
|
$match = true; |
|
890
|
|
|
|
|
891
|
|
|
} |
|
892
|
|
|
|
|
893
|
|
|
|
|
894
|
|
|
// override for "all" |
|
895
|
|
|
if( $rule['value'] === 'all' ) { |
|
896
|
|
|
|
|
897
|
|
|
$match = false; |
|
898
|
|
|
|
|
899
|
|
|
} |
|
900
|
|
|
|
|
901
|
|
|
} |
|
902
|
|
|
|
|
903
|
|
|
} elseif( $user_id ) { |
|
904
|
|
|
|
|
905
|
|
|
if( $rule['operator'] == "==" ) { |
|
906
|
|
|
|
|
907
|
|
View Code Duplication |
if( $user_id === 'new' ) { |
|
|
|
|
|
|
908
|
|
|
|
|
909
|
|
|
// case: add user |
|
910
|
|
|
$match = ( $rule['value'] == get_option('default_role') ); |
|
911
|
|
|
|
|
912
|
|
|
} else { |
|
913
|
|
|
|
|
914
|
|
|
// case: edit user |
|
915
|
|
|
$match = ( user_can($user_id, $rule['value']) ); |
|
916
|
|
|
|
|
917
|
|
|
} |
|
918
|
|
|
|
|
919
|
|
|
|
|
920
|
|
|
// override for "all" |
|
921
|
|
|
if( $rule['value'] === 'all' ) { |
|
922
|
|
|
|
|
923
|
|
|
$match = true; |
|
924
|
|
|
|
|
925
|
|
|
} |
|
926
|
|
|
|
|
927
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
928
|
|
|
|
|
929
|
|
View Code Duplication |
if( $user_id === 'new' ) { |
|
|
|
|
|
|
930
|
|
|
|
|
931
|
|
|
// case: add user |
|
932
|
|
|
$match = ( $rule['value'] != get_option('default_role') ); |
|
933
|
|
|
|
|
934
|
|
|
} else { |
|
935
|
|
|
|
|
936
|
|
|
// case: edit user |
|
937
|
|
|
$match = ( !user_can($user_id, $rule['value']) ); |
|
938
|
|
|
|
|
939
|
|
|
} |
|
940
|
|
|
|
|
941
|
|
|
|
|
942
|
|
|
// override for "all" |
|
943
|
|
|
if( $rule['value'] === 'all' ) { |
|
944
|
|
|
|
|
945
|
|
|
$match = false; |
|
946
|
|
|
|
|
947
|
|
|
} |
|
948
|
|
|
|
|
949
|
|
|
} |
|
950
|
|
|
|
|
951
|
|
|
} |
|
952
|
|
|
|
|
953
|
|
|
|
|
954
|
|
|
// return |
|
955
|
|
|
return $match; |
|
956
|
|
|
|
|
957
|
|
|
} |
|
958
|
|
|
|
|
959
|
|
|
|
|
960
|
|
|
|
|
961
|
|
|
/* |
|
962
|
|
|
* rule_match_taxonomy |
|
963
|
|
|
* |
|
964
|
|
|
* This function will match a location rule and return true or false |
|
965
|
|
|
* |
|
966
|
|
|
* @type filter |
|
967
|
|
|
* @date 3/01/13 |
|
968
|
|
|
* @since 3.5.7 |
|
969
|
|
|
* |
|
970
|
|
|
* @param $match (boolean) |
|
971
|
|
|
* @param $rule (array) |
|
972
|
|
|
* @return $options (array) |
|
973
|
|
|
*/ |
|
|
|
|
|
|
974
|
|
|
|
|
975
|
|
View Code Duplication |
function rule_match_taxonomy( $match, $rule, $options ) { |
|
|
|
|
|
|
976
|
|
|
|
|
977
|
|
|
// vars |
|
978
|
|
|
$taxonomy = $options['taxonomy']; |
|
979
|
|
|
|
|
980
|
|
|
|
|
981
|
|
|
// validate |
|
982
|
|
|
if( !$taxonomy ) { |
|
983
|
|
|
|
|
984
|
|
|
return false; |
|
985
|
|
|
|
|
986
|
|
|
} |
|
987
|
|
|
|
|
988
|
|
|
|
|
989
|
|
|
// compare |
|
990
|
|
|
if( $rule['operator'] == "==" ) { |
|
991
|
|
|
|
|
992
|
|
|
$match = ( $taxonomy == $rule['value'] ); |
|
993
|
|
|
|
|
994
|
|
|
// override for "all" |
|
995
|
|
|
if( $rule['value'] == "all" ) { |
|
996
|
|
|
|
|
997
|
|
|
$match = true; |
|
998
|
|
|
|
|
999
|
|
|
} |
|
1000
|
|
|
|
|
1001
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
1002
|
|
|
|
|
1003
|
|
|
$match = ( $taxonomy != $rule['value'] ); |
|
1004
|
|
|
|
|
1005
|
|
|
// override for "all" |
|
1006
|
|
|
if( $rule['value'] == "all" ) { |
|
1007
|
|
|
|
|
1008
|
|
|
$match = false; |
|
1009
|
|
|
|
|
1010
|
|
|
} |
|
1011
|
|
|
|
|
1012
|
|
|
} |
|
1013
|
|
|
|
|
1014
|
|
|
|
|
1015
|
|
|
// return |
|
1016
|
|
|
return $match; |
|
1017
|
|
|
|
|
1018
|
|
|
} |
|
1019
|
|
|
|
|
1020
|
|
|
|
|
1021
|
|
|
/* |
|
1022
|
|
|
* rule_match_attachment |
|
1023
|
|
|
* |
|
1024
|
|
|
* This function will match a location rule and return true or false |
|
1025
|
|
|
* |
|
1026
|
|
|
* @type filter |
|
1027
|
|
|
* @date 3/01/13 |
|
1028
|
|
|
* @since 3.5.7 |
|
1029
|
|
|
* |
|
1030
|
|
|
* @param $match (boolean) |
|
1031
|
|
|
* @param $rule (array) |
|
1032
|
|
|
* @return $options (array) |
|
1033
|
|
|
*/ |
|
|
|
|
|
|
1034
|
|
|
|
|
1035
|
|
View Code Duplication |
function rule_match_attachment( $match, $rule, $options ) { |
|
|
|
|
|
|
1036
|
|
|
|
|
1037
|
|
|
// vars |
|
1038
|
|
|
$attachment = $options['attachment']; |
|
1039
|
|
|
|
|
1040
|
|
|
|
|
1041
|
|
|
// validate |
|
1042
|
|
|
if( ! $attachment ) { |
|
1043
|
|
|
|
|
1044
|
|
|
return false; |
|
1045
|
|
|
|
|
1046
|
|
|
} |
|
1047
|
|
|
|
|
1048
|
|
|
|
|
1049
|
|
|
// compare |
|
1050
|
|
|
if( $rule['operator'] == "==" ) { |
|
1051
|
|
|
|
|
1052
|
|
|
$match = ( $attachment == $rule['value'] ); |
|
1053
|
|
|
|
|
1054
|
|
|
// override for "all" |
|
1055
|
|
|
if( $rule['value'] == "all" ) { |
|
1056
|
|
|
|
|
1057
|
|
|
$match = true; |
|
1058
|
|
|
|
|
1059
|
|
|
} |
|
1060
|
|
|
|
|
1061
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
1062
|
|
|
|
|
1063
|
|
|
$match = ( $attachment != $rule['value'] ); |
|
1064
|
|
|
|
|
1065
|
|
|
// override for "all" |
|
1066
|
|
|
if( $rule['value'] == "all" ) { |
|
1067
|
|
|
|
|
1068
|
|
|
$match = false; |
|
1069
|
|
|
|
|
1070
|
|
|
} |
|
1071
|
|
|
|
|
1072
|
|
|
} |
|
1073
|
|
|
|
|
1074
|
|
|
|
|
1075
|
|
|
// return |
|
1076
|
|
|
return $match; |
|
1077
|
|
|
|
|
1078
|
|
|
} |
|
1079
|
|
|
|
|
1080
|
|
|
|
|
1081
|
|
|
|
|
1082
|
|
|
/* |
|
1083
|
|
|
* rule_match_comment |
|
1084
|
|
|
* |
|
1085
|
|
|
* This function will match a location rule and return true or false |
|
1086
|
|
|
* |
|
1087
|
|
|
* @type filter |
|
1088
|
|
|
* @date 3/01/13 |
|
1089
|
|
|
* @since 3.5.7 |
|
1090
|
|
|
* |
|
1091
|
|
|
* @param $match (boolean) |
|
1092
|
|
|
* @param $rule (array) |
|
1093
|
|
|
* @return $options (array) |
|
1094
|
|
|
*/ |
|
|
|
|
|
|
1095
|
|
|
|
|
1096
|
|
View Code Duplication |
function rule_match_comment( $match, $rule, $options ) { |
|
|
|
|
|
|
1097
|
|
|
|
|
1098
|
|
|
// vars |
|
1099
|
|
|
$comment = $options['comment']; |
|
1100
|
|
|
|
|
1101
|
|
|
|
|
1102
|
|
|
// validate |
|
1103
|
|
|
if( ! $comment ) { |
|
1104
|
|
|
|
|
1105
|
|
|
return false; |
|
1106
|
|
|
|
|
1107
|
|
|
} |
|
1108
|
|
|
|
|
1109
|
|
|
|
|
1110
|
|
|
// compare |
|
1111
|
|
|
if( $rule['operator'] == "==" ) { |
|
1112
|
|
|
|
|
1113
|
|
|
$match = ( $comment == $rule['value'] ); |
|
1114
|
|
|
|
|
1115
|
|
|
// override for "all" |
|
1116
|
|
|
if( $rule['value'] == "all" ) { |
|
1117
|
|
|
|
|
1118
|
|
|
$match = true; |
|
1119
|
|
|
|
|
1120
|
|
|
} |
|
1121
|
|
|
|
|
1122
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
1123
|
|
|
|
|
1124
|
|
|
$match = ( $comment != $rule['value'] ); |
|
1125
|
|
|
|
|
1126
|
|
|
// override for "all" |
|
1127
|
|
|
if( $rule['value'] == "all" ) { |
|
1128
|
|
|
|
|
1129
|
|
|
$match = false; |
|
1130
|
|
|
|
|
1131
|
|
|
} |
|
1132
|
|
|
|
|
1133
|
|
|
} |
|
1134
|
|
|
|
|
1135
|
|
|
|
|
1136
|
|
|
// return |
|
1137
|
|
|
return $match; |
|
1138
|
|
|
|
|
1139
|
|
|
} |
|
1140
|
|
|
|
|
1141
|
|
|
|
|
1142
|
|
|
/* |
|
1143
|
|
|
* rule_match_widget |
|
1144
|
|
|
* |
|
1145
|
|
|
* This function will match a location rule and return true or false |
|
1146
|
|
|
* |
|
1147
|
|
|
* @type filter |
|
1148
|
|
|
* @date 3/01/13 |
|
1149
|
|
|
* @since 3.5.7 |
|
1150
|
|
|
* |
|
1151
|
|
|
* @param $match (boolean) |
|
1152
|
|
|
* @param $rule (array) |
|
1153
|
|
|
* @return $options (array) |
|
1154
|
|
|
*/ |
|
|
|
|
|
|
1155
|
|
|
|
|
1156
|
|
View Code Duplication |
function rule_match_widget( $match, $rule, $options ) { |
|
|
|
|
|
|
1157
|
|
|
|
|
1158
|
|
|
// vars |
|
1159
|
|
|
$widget = $options['widget']; |
|
1160
|
|
|
|
|
1161
|
|
|
|
|
1162
|
|
|
// validate |
|
1163
|
|
|
if( ! $widget ) { |
|
1164
|
|
|
|
|
1165
|
|
|
return false; |
|
1166
|
|
|
|
|
1167
|
|
|
} |
|
1168
|
|
|
|
|
1169
|
|
|
|
|
1170
|
|
|
// compare |
|
1171
|
|
|
if( $rule['operator'] == "==" ) { |
|
1172
|
|
|
|
|
1173
|
|
|
$match = ( $widget == $rule['value'] ); |
|
1174
|
|
|
|
|
1175
|
|
|
// override for "all" |
|
1176
|
|
|
if( $rule['value'] == "all" ) { |
|
1177
|
|
|
|
|
1178
|
|
|
$match = true; |
|
1179
|
|
|
|
|
1180
|
|
|
} |
|
1181
|
|
|
|
|
1182
|
|
|
} elseif( $rule['operator'] == "!=" ) { |
|
1183
|
|
|
|
|
1184
|
|
|
$match = ( $widget != $rule['value'] ); |
|
1185
|
|
|
|
|
1186
|
|
|
// override for "all" |
|
1187
|
|
|
if( $rule['value'] == "all" ) { |
|
1188
|
|
|
|
|
1189
|
|
|
$match = false; |
|
1190
|
|
|
|
|
1191
|
|
|
} |
|
1192
|
|
|
|
|
1193
|
|
|
} |
|
1194
|
|
|
|
|
1195
|
|
|
|
|
1196
|
|
|
// return |
|
1197
|
|
|
return $match; |
|
1198
|
|
|
} |
|
1199
|
|
|
|
|
1200
|
|
|
} |
|
1201
|
|
|
|
|
1202
|
|
|
new acf_location(); |
|
1203
|
|
|
|
|
1204
|
|
|
|
|
1205
|
|
|
/* |
|
1206
|
|
|
* acf_get_field_group_visibility |
|
1207
|
|
|
* |
|
1208
|
|
|
* This function will look at the given field group's location rules and compare them against |
|
1209
|
|
|
* the args given to see if this field group is to be shown or not. |
|
1210
|
|
|
* |
|
1211
|
|
|
* @type function |
|
1212
|
|
|
* @date 7/10/13 |
|
1213
|
|
|
* @since 5.0.0 |
|
1214
|
|
|
* |
|
1215
|
|
|
* @param $field group (array) |
|
1216
|
|
|
* @param $args (array) |
|
1217
|
|
|
* @return (boolean) |
|
1218
|
|
|
*/ |
|
1219
|
|
|
|
|
1220
|
|
|
function acf_get_field_group_visibility( $field_group, $args = array() ) { |
|
1221
|
|
|
|
|
1222
|
|
|
// vars |
|
1223
|
|
|
$args = acf_parse_args($args, array( |
|
1224
|
|
|
'post_id' => 0, |
|
1225
|
|
|
'post_type' => 0, |
|
1226
|
|
|
'page_template' => 0, |
|
1227
|
|
|
'page_parent' => 0, |
|
1228
|
|
|
'page_type' => 0, |
|
1229
|
|
|
'post_format' => 0, |
|
1230
|
|
|
'post_taxonomy' => null, |
|
1231
|
|
|
'taxonomy' => 0, |
|
1232
|
|
|
'user_id' => 0, |
|
1233
|
|
|
'user_role' => 0, |
|
1234
|
|
|
'user_form' => 0, |
|
1235
|
|
|
'attachment' => 0, |
|
1236
|
|
|
'comment' => 0, |
|
1237
|
|
|
'widget' => 0, |
|
1238
|
|
|
'lang' => 0, |
|
1239
|
|
|
'ajax' => false |
|
1240
|
|
|
)); |
|
1241
|
|
|
|
|
1242
|
|
|
|
|
1243
|
|
|
// bail early if not active |
|
1244
|
|
|
if( !$field_group['active'] ) { |
|
1245
|
|
|
|
|
1246
|
|
|
return false; |
|
1247
|
|
|
|
|
1248
|
|
|
} |
|
1249
|
|
|
|
|
1250
|
|
|
|
|
1251
|
|
|
// WPML |
|
1252
|
|
|
if( defined('ICL_LANGUAGE_CODE') ) { |
|
1253
|
|
|
|
|
1254
|
|
|
$args['lang'] = ICL_LANGUAGE_CODE; |
|
1255
|
|
|
|
|
1256
|
|
|
} |
|
1257
|
|
|
|
|
1258
|
|
|
|
|
1259
|
|
|
// vars |
|
1260
|
|
|
$visibility = false; |
|
1261
|
|
|
|
|
1262
|
|
|
|
|
1263
|
|
|
// loop through location rules |
|
1264
|
|
|
foreach( $field_group['location'] as $group_id => $group ) { |
|
1265
|
|
|
|
|
1266
|
|
|
// start of as true, this way, any rule that doesn't match will cause this varaible to false |
|
1267
|
|
|
$match_group = true; |
|
1268
|
|
|
|
|
1269
|
|
|
|
|
1270
|
|
|
// loop over group rules |
|
1271
|
|
|
if( !empty($group) ) { |
|
1272
|
|
|
|
|
1273
|
|
|
foreach( $group as $rule_id => $rule ) { |
|
1274
|
|
|
|
|
1275
|
|
|
$match = apply_filters( 'acf/location/rule_match/' . $rule['param'] , false, $rule, $args ); |
|
1276
|
|
|
|
|
1277
|
|
|
if( !$match ) { |
|
1278
|
|
|
|
|
1279
|
|
|
$match_group = false; |
|
1280
|
|
|
break; |
|
1281
|
|
|
|
|
1282
|
|
|
} |
|
1283
|
|
|
|
|
1284
|
|
|
} |
|
1285
|
|
|
|
|
1286
|
|
|
} |
|
1287
|
|
|
|
|
1288
|
|
|
|
|
1289
|
|
|
// all rules must havematched! |
|
1290
|
|
|
if( $match_group ) { |
|
1291
|
|
|
|
|
1292
|
|
|
$visibility = true; |
|
1293
|
|
|
|
|
1294
|
|
|
} |
|
1295
|
|
|
|
|
1296
|
|
|
} |
|
1297
|
|
|
|
|
1298
|
|
|
|
|
1299
|
|
|
// return |
|
1300
|
|
|
return $visibility; |
|
1301
|
|
|
} |
|
1302
|
|
|
|
|
1303
|
|
|
?> |
|
|
|
|
|
|
1304
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.