1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- if ( ! class_exists( 'ACF_Location_Page_Template' ) ) :
- class ACF_Location_Page_Template extends ACF_Location {
-
- public function initialize() {
- $this->name = 'page_template';
- $this->label = __( 'Page Template', 'acf' );
- $this->category = 'page';
- $this->object_type = 'post';
- $this->object_subtype = 'page';
- }
-
- public function match( $rule, $screen, $field_group ) {
-
- if ( isset( $screen['post_type'] ) ) {
- $post_type = $screen['post_type'];
- } elseif ( isset( $screen['post_id'] ) ) {
- $post_type = get_post_type( $screen['post_id'] );
- } else {
- return false;
- }
-
-
- if ( $rule['value'] === 'default' && $post_type !== 'page' ) {
- return false;
- }
-
- return acf_get_location_type( 'post_template' )->match( $rule, $screen, $field_group );
- }
-
- public function get_values( $rule ) {
- $post_templates = acf_get_post_templates();
- return array_merge(
- array(
- 'default' => apply_filters( 'default_page_template_title', __( 'Default Template', 'acf' ) ),
- ),
- $post_templates['page']
- );
- }
- }
-
- acf_register_location_type( 'ACF_Location_Page_Template' );
- endif;
|