-
Notifications
You must be signed in to change notification settings - Fork 57
/
is_admin-acf-location-rule.php
40 lines (37 loc) · 1.08 KB
/
is_admin-acf-location-rule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/*
Location rule to for is_admin
So a field group in admin only or on front end only
*/
add_action('acf/location/rule_types', 'acf_add_special_rule_type');
function acf_add_special_rule_type($choices) {
if (!isset($choices['Special'])) {
$choices['Special'] = array();
}
if (!isset($choices['Special']['is_admin'])) {
$choices['Special']['is_admin'] = 'is_admin';
}
return $choices;
}
add_filter('acf/location/rule_values/is_admin', 'acf_location_rules_values_special_is_admin');
function acf_location_rules_values_special_is_admin($choices) {
$choices['true'] = 'true';
$choices['false'] = 'false';
return $choices;
}
add_filter('acf/location/rule_match/is_admin', 'acf_location_rules_match_is_admin', 10, 3);
function acf_location_rules_match_is_admin($match, $rule, $options) {
if ($rule['param'] != 'is_admin') {
return $match;
}
if ($rule['operator'] == '==') {
$match = is_admin();
} elseif ($rule['operator'] == '!=') {
$match = !is_admin();
}
if ($rule['value'] != 'true') {
$match = !$match;
}
return $match;
}
?>