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-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-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-page-type.php
122 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; // Exit if accessed directly |
| 5 | } |
| 6 | |
| 7 | if ( ! class_exists( 'ACF_Location_Page_Type' ) ) : |
| 8 | |
| 9 | class ACF_Location_Page_Type extends ACF_Location { |
| 10 | |
| 11 | /** |
| 12 | * Initializes props. |
| 13 | * |
| 14 | * @date 5/03/2014 |
| 15 | * @since 5.0.0 |
| 16 | * |
| 17 | * @param void |
| 18 | * @return void |
| 19 | */ |
| 20 | public function initialize() { |
| 21 | $this->name = 'page_type'; |
| 22 | $this->label = __( 'Page Type', 'acf' ); |
| 23 | $this->category = 'page'; |
| 24 | $this->object_type = 'post'; |
| 25 | $this->object_subtype = 'page'; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Matches the provided rule against the screen args returning a bool result. |
| 30 | * |
| 31 | * @date 9/4/20 |
| 32 | * @since 5.9.0 |
| 33 | * |
| 34 | * @param array $rule The location rule. |
| 35 | * @param array $screen The screen args. |
| 36 | * @param array $field_group The field group settings. |
| 37 | * @return boolean |
| 38 | */ |
| 39 | public function match( $rule, $screen, $field_group ) { |
| 40 | |
| 41 | // Check screen args. |
| 42 | if ( isset( $screen['post_id'] ) ) { |
| 43 | $post_id = $screen['post_id']; |
| 44 | } else { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | // Get post. |
| 49 | $post = get_post( $post_id ); |
| 50 | if ( ! $post ) { |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | // Compare. |
| 55 | switch ( $rule['value'] ) { |
| 56 | case 'front_page': |
| 57 | $front_page = (int) get_option( 'page_on_front' ); |
| 58 | $result = ( $front_page === $post->ID ); |
| 59 | break; |
| 60 | |
| 61 | case 'posts_page': |
| 62 | $posts_page = (int) get_option( 'page_for_posts' ); |
| 63 | $result = ( $posts_page === $post->ID ); |
| 64 | break; |
| 65 | |
| 66 | case 'top_level': |
| 67 | $page_parent = (int) ( isset( $screen['page_parent'] ) ? $screen['page_parent'] : $post->post_parent ); |
| 68 | $result = ( $page_parent === 0 ); |
| 69 | break; |
| 70 | |
| 71 | case 'parent': |
| 72 | $children = get_posts( |
| 73 | array( |
| 74 | 'post_type' => $post->post_type, |
| 75 | 'post_parent' => $post->ID, |
| 76 | 'posts_per_page' => 1, |
| 77 | 'fields' => 'ids', |
| 78 | ) |
| 79 | ); |
| 80 | $result = ! empty( $children ); |
| 81 | break; |
| 82 | |
| 83 | case 'child': |
| 84 | $page_parent = (int) ( isset( $screen['page_parent'] ) ? $screen['page_parent'] : $post->post_parent ); |
| 85 | $result = ( $page_parent !== 0 ); |
| 86 | break; |
| 87 | |
| 88 | default: |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | // Reverse result for "!=" operator. |
| 93 | if ( $rule['operator'] === '!=' ) { |
| 94 | return ! $result; |
| 95 | } |
| 96 | return $result; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Returns an array of possible values for this rule type. |
| 101 | * |
| 102 | * @date 9/4/20 |
| 103 | * @since 5.9.0 |
| 104 | * |
| 105 | * @param array $rule A location rule. |
| 106 | * @return array |
| 107 | */ |
| 108 | public function get_values( $rule ) { |
| 109 | return array( |
| 110 | 'front_page' => __( 'Front Page', 'acf' ), |
| 111 | 'posts_page' => __( 'Posts Page', 'acf' ), |
| 112 | 'top_level' => __( 'Top Level Page (no parent)', 'acf' ), |
| 113 | 'parent' => __( 'Parent Page (has children)', 'acf' ), |
| 114 | 'child' => __( 'Child Page (has parent)', 'acf' ), |
| 115 | ); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // initialize |
| 120 | acf_register_location_type( 'ACF_Location_Page_Type' ); |
| 121 | endif; // class_exists check |
| 122 |