location-post-type-all.php
3 months ago
location-post-type-archive.php
3 months ago
location-post-type-list.php
3 months ago
location-taxonomy-list.php
3 months ago
location.php
3 months ago
location.php
163 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * acfe_location |
| 9 | */ |
| 10 | if(!class_exists('acfe_location')): |
| 11 | |
| 12 | class acfe_location extends acf_location{ |
| 13 | |
| 14 | // vars |
| 15 | public $after = ''; |
| 16 | |
| 17 | } |
| 18 | |
| 19 | endif; |
| 20 | |
| 21 | |
| 22 | /** |
| 23 | * acfe_location_rules |
| 24 | */ |
| 25 | if(!class_exists('acfe_location_rules')): |
| 26 | |
| 27 | class acfe_location_rules{ |
| 28 | |
| 29 | /** |
| 30 | * construct |
| 31 | */ |
| 32 | function __construct(){ |
| 33 | |
| 34 | add_filter('acf/location/rule_types', array($this, 'location_rules_types')); |
| 35 | |
| 36 | } |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * location_rules_types |
| 41 | * |
| 42 | * @param $groups |
| 43 | * |
| 44 | * @return mixed |
| 45 | */ |
| 46 | function location_rules_types($groups){ |
| 47 | |
| 48 | // loop groups |
| 49 | foreach($groups as $group => $locations){ |
| 50 | |
| 51 | // loop locations |
| 52 | foreach($locations as $location_name => $location_label){ |
| 53 | |
| 54 | // get location type |
| 55 | $location_type = acf_get_location_type($location_name); |
| 56 | |
| 57 | // validate location type and move using "after" prop |
| 58 | if(!empty($location_type) && !empty($location_type->after) && isset($groups[ $group ][ $location_type->after ])){ |
| 59 | $groups[ $group ] = acfe_after($groups[ $group ], $location_type->after, array($location_name => $location_label)); |
| 60 | } |
| 61 | |
| 62 | } |
| 63 | |
| 64 | |
| 65 | } |
| 66 | |
| 67 | // return |
| 68 | return $groups; |
| 69 | |
| 70 | } |
| 71 | |
| 72 | } |
| 73 | |
| 74 | new acfe_location_rules(); |
| 75 | |
| 76 | endif; |
| 77 | |
| 78 | |
| 79 | /** |
| 80 | * acfe_compare_location_rule |
| 81 | * |
| 82 | * @param $value |
| 83 | * @param $rule |
| 84 | * @param $all_as_wildcard |
| 85 | * |
| 86 | * @return bool|int |
| 87 | */ |
| 88 | function acfe_compare_location_rule($value, $rule, $all_as_wildcard = true){ |
| 89 | |
| 90 | if($rule['operator'] === '=='){ |
| 91 | |
| 92 | if($rule['value'] === 'all' && $all_as_wildcard){ |
| 93 | return true; |
| 94 | } |
| 95 | |
| 96 | return $value == $rule['value']; |
| 97 | |
| 98 | }elseif($rule['operator'] === '!='){ |
| 99 | |
| 100 | if($rule['value'] === 'all' && $all_as_wildcard){ |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | return $value != $rule['value']; |
| 105 | |
| 106 | }elseif($rule['operator'] === '<'){ |
| 107 | return $value < $rule['value']; |
| 108 | |
| 109 | }elseif($rule['operator'] === '<='){ |
| 110 | return $value <= $rule['value']; |
| 111 | |
| 112 | }elseif($rule['operator'] === '>'){ |
| 113 | return $value > $rule['value']; |
| 114 | |
| 115 | }elseif($rule['operator'] === '>='){ |
| 116 | return $value >= $rule['value']; |
| 117 | |
| 118 | }elseif($rule['operator'] === 'contains'){ |
| 119 | return stripos($value, $rule['value']) !== false; |
| 120 | |
| 121 | }elseif($rule['operator'] === '!contains'){ |
| 122 | return stripos($value, $rule['value']) === false; |
| 123 | |
| 124 | }elseif($rule['operator'] === 'starts'){ |
| 125 | return stripos($value, $rule['value']) === 0; |
| 126 | |
| 127 | }elseif($rule['operator'] === '!starts'){ |
| 128 | return stripos($value, $rule['value']) !== 0; |
| 129 | |
| 130 | }elseif($rule['operator'] === 'ends'){ |
| 131 | return acfe_ends_with($value, $rule['value']); |
| 132 | |
| 133 | }elseif($rule['operator'] === '!ends'){ |
| 134 | return !acfe_ends_with($value, $rule['value']); |
| 135 | |
| 136 | }elseif($rule['operator'] === 'regex'){ |
| 137 | return preg_match('/' . $rule['value'] . '/', $value); |
| 138 | |
| 139 | }elseif($rule['operator'] === '!regex'){ |
| 140 | return !preg_match('/' . $rule['value'] . '/', $value); |
| 141 | |
| 142 | }elseif($rule['operator'] === '=count'){ |
| 143 | return count($value) == $rule['value']; |
| 144 | |
| 145 | }elseif($rule['operator'] === '!=count'){ |
| 146 | return count($value) != $rule['value']; |
| 147 | |
| 148 | }elseif($rule['operator'] === '>count'){ |
| 149 | return count($value) > $rule['value']; |
| 150 | |
| 151 | }elseif($rule['operator'] === '>=count'){ |
| 152 | return count($value) >= $rule['value']; |
| 153 | |
| 154 | }elseif($rule['operator'] === '<count'){ |
| 155 | return count($value) < $rule['value']; |
| 156 | |
| 157 | }elseif($rule['operator'] === '<=count'){ |
| 158 | return count($value) <= $rule['value']; |
| 159 | } |
| 160 | |
| 161 | return false; |
| 162 | |
| 163 | } |