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