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-archive.php
99 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_location_post_type_archive')): |
| 8 | |
| 9 | class acfe_location_post_type_archive extends acfe_location{ |
| 10 | |
| 11 | /** |
| 12 | * initialize |
| 13 | * |
| 14 | * @return void |
| 15 | */ |
| 16 | function initialize(){ |
| 17 | |
| 18 | $this->name = 'post_type_archive'; |
| 19 | $this->label = __('Post Type Archive', 'acfe'); |
| 20 | $this->category = 'post'; |
| 21 | $this->after = 'post_type'; |
| 22 | |
| 23 | } |
| 24 | |
| 25 | |
| 26 | /** |
| 27 | * rule_values |
| 28 | * |
| 29 | * @param $choices |
| 30 | * |
| 31 | * @return array |
| 32 | */ |
| 33 | function rule_values($choices){ |
| 34 | |
| 35 | // get post types archives |
| 36 | $post_types = acf_get_post_types(array( |
| 37 | 'acfe_admin_archive' => true |
| 38 | )); |
| 39 | |
| 40 | // append pretty post types |
| 41 | $pretty_post_types = array(); |
| 42 | |
| 43 | if(!empty($post_types)){ |
| 44 | $pretty_post_types = acf_get_pretty_post_types($post_types); |
| 45 | } |
| 46 | |
| 47 | // merge choices |
| 48 | $choices = array('all' => __('All', 'acf')); |
| 49 | $choices = array_merge($choices, $pretty_post_types); |
| 50 | |
| 51 | // return choices |
| 52 | return $choices; |
| 53 | |
| 54 | } |
| 55 | |
| 56 | |
| 57 | /** |
| 58 | * rule_match |
| 59 | * |
| 60 | * @param $result |
| 61 | * @param $rule |
| 62 | * @param $screen |
| 63 | * |
| 64 | * $rule = array( |
| 65 | * 'param' => 'post_type_archive', |
| 66 | * 'operator' => '==', |
| 67 | * 'value' => 'my-post-type', |
| 68 | * ) |
| 69 | * |
| 70 | * $screen = array( |
| 71 | * 'lang' => false, |
| 72 | * 'ajax' => false, |
| 73 | * 'options_page' => 'my-post-type-archive', |
| 74 | * 'acfe_post_type_archive' => true, |
| 75 | * ) |
| 76 | * |
| 77 | * @return bool |
| 78 | */ |
| 79 | function rule_match($result, $rule, $screen){ |
| 80 | |
| 81 | // validate screen & rule |
| 82 | if(!acfe_get($screen, 'options_page') || !acfe_get($screen, 'acfe_post_type_archive') || !acfe_get($rule, 'value')){ |
| 83 | return $result; |
| 84 | } |
| 85 | |
| 86 | // prepare compare |
| 87 | $value = $screen['options_page']; |
| 88 | $rule['value'] = "{$rule['value']}-archive"; |
| 89 | |
| 90 | // compare $value with $rule['value'] |
| 91 | return $this->compare($value, $rule); |
| 92 | |
| 93 | } |
| 94 | |
| 95 | } |
| 96 | |
| 97 | acf_register_location_rule('acfe_location_post_type_archive'); |
| 98 | |
| 99 | endif; |