abstract-acf-legacy-location.php
1 year ago
abstract-acf-location.php
1 year ago
class-acf-location-attachment.php
1 year ago
class-acf-location-block.php
1 year ago
class-acf-location-comment.php
1 year ago
class-acf-location-current-user-role.php
1 year ago
class-acf-location-current-user.php
1 year ago
class-acf-location-nav-menu-item.php
1 year ago
class-acf-location-nav-menu.php
1 year ago
class-acf-location-options-page.php
1 year ago
class-acf-location-page-parent.php
1 year ago
class-acf-location-page-template.php
1 year ago
class-acf-location-page-type.php
1 year ago
class-acf-location-page.php
1 year ago
class-acf-location-post-category.php
1 year ago
class-acf-location-post-format.php
1 year ago
class-acf-location-post-status.php
1 year ago
class-acf-location-post-taxonomy.php
1 year ago
class-acf-location-post-template.php
1 year ago
class-acf-location-post-type.php
1 year ago
class-acf-location-post.php
1 year ago
class-acf-location-taxonomy.php
1 year ago
class-acf-location-user-form.php
1 year ago
class-acf-location-user-role.php
1 year ago
class-acf-location-widget.php
1 year ago
index.php
1 year ago
class-acf-location-post-type.php
95 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; // Exit if accessed directly |
| 5 | } |
| 6 | |
| 7 | if ( ! class_exists( 'ACF_Location_Post_Type' ) ) : |
| 8 | |
| 9 | class ACF_Location_Post_Type extends ACF_Location { |
| 10 | |
| 11 | /** |
| 12 | * Initializes props. |
| 13 | * |
| 14 | * @date 5/03/2014 |
| 15 | * @since ACF 5.0.0 |
| 16 | * |
| 17 | * @return void |
| 18 | */ |
| 19 | public function initialize() { |
| 20 | $this->name = 'post_type'; |
| 21 | $this->label = __( 'Post Type', 'secure-custom-fields' ); |
| 22 | $this->category = 'post'; |
| 23 | $this->object_type = 'post'; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Matches the provided rule against the screen args returning a bool result. |
| 28 | * |
| 29 | * @date 9/4/20 |
| 30 | * @since ACF 5.9.0 |
| 31 | * |
| 32 | * @param array $rule The location rule. |
| 33 | * @param array $screen The screen args. |
| 34 | * @param array $field_group The field group settings. |
| 35 | * @return boolean |
| 36 | */ |
| 37 | public function match( $rule, $screen, $field_group ) { |
| 38 | |
| 39 | // Check screen args. |
| 40 | if ( isset( $screen['post_type'] ) ) { |
| 41 | $post_type = $screen['post_type']; |
| 42 | } elseif ( isset( $screen['post_id'] ) ) { |
| 43 | $post_type = get_post_type( $screen['post_id'] ); |
| 44 | } else { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | // Compare rule against $post_type. |
| 49 | return $this->compare_to_rule( $post_type, $rule ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Returns an array of possible values for this rule type. |
| 54 | * |
| 55 | * @date 9/4/20 |
| 56 | * @since ACF 5.9.0 |
| 57 | * |
| 58 | * @param array $rule A location rule. |
| 59 | * @return array |
| 60 | */ |
| 61 | public function get_values( $rule ) { |
| 62 | |
| 63 | // Get post types. |
| 64 | $post_types = acf_get_post_types( |
| 65 | array( |
| 66 | 'show_ui' => 1, |
| 67 | 'exclude' => array( 'attachment' ), |
| 68 | ) |
| 69 | ); |
| 70 | |
| 71 | // Return array of [type => label]. |
| 72 | return acf_get_pretty_post_types( $post_types ); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Returns the object_subtype connected to this location. |
| 77 | * |
| 78 | * @date 1/4/20 |
| 79 | * @since ACF 5.9.0 |
| 80 | * |
| 81 | * @param array $rule A location rule. |
| 82 | * @return string|array |
| 83 | */ |
| 84 | public function get_object_subtype( $rule ) { |
| 85 | if ( $rule['operator'] === '==' ) { |
| 86 | return $rule['value']; |
| 87 | } |
| 88 | return ''; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // initialize |
| 93 | acf_register_location_type( 'ACF_Location_Post_Type' ); |
| 94 | endif; // class_exists check |
| 95 |