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-post-type-all.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_location_post_type_all')): |
| 8 | |
| 9 | class acfe_location_post_type_all{ |
| 10 | |
| 11 | /** |
| 12 | * construct |
| 13 | */ |
| 14 | function __construct(){ |
| 15 | |
| 16 | add_filter('acf/location/rule_values/post_type', array($this, 'rule_values')); |
| 17 | add_filter('acf/location/rule_match/post_type', array($this, 'rule_match'), 10, 3); |
| 18 | |
| 19 | } |
| 20 | |
| 21 | |
| 22 | /** |
| 23 | * rule_values |
| 24 | * |
| 25 | * @param $choices |
| 26 | * |
| 27 | * @return string[]|void[] |
| 28 | */ |
| 29 | function rule_values($choices){ |
| 30 | |
| 31 | return array_merge(array( |
| 32 | 'all' => __('All', 'acf') |
| 33 | ), $choices); |
| 34 | |
| 35 | } |
| 36 | |
| 37 | |
| 38 | /** |
| 39 | * rule_match |
| 40 | * |
| 41 | * @param $match |
| 42 | * @param $rule |
| 43 | * @param $options |
| 44 | * |
| 45 | * @return bool |
| 46 | */ |
| 47 | function rule_match($match, $rule, $options){ |
| 48 | |
| 49 | // rule value might be empty |
| 50 | // in case a field group use a custom location type from third party plugin |
| 51 | // if the third party plugin is disabled, acf will fallback to "Post Type == ''" |
| 52 | // and pass thru this rule because it's the first one |
| 53 | if(empty($rule['value'])){ |
| 54 | return $match; |
| 55 | } |
| 56 | |
| 57 | if($rule['value'] !== 'all'){ |
| 58 | return $match; |
| 59 | } |
| 60 | |
| 61 | if(!acfe_get($options, 'post_type')){ |
| 62 | return $match; |
| 63 | } |
| 64 | |
| 65 | $post_types = acf_get_post_types(); |
| 66 | |
| 67 | $match = in_array($options['post_type'], $post_types); |
| 68 | |
| 69 | if($rule['operator'] === '!='){ |
| 70 | $match = !$match; |
| 71 | } |
| 72 | |
| 73 | return $match; |
| 74 | |
| 75 | } |
| 76 | |
| 77 | } |
| 78 | |
| 79 | acf_new_instance('acfe_location_post_type_all'); |
| 80 | |
| 81 | endif; |