123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- if ( ! class_exists( 'ACF_Location_Post_Template' ) ) :
- class ACF_Location_Post_Template extends ACF_Location {
-
- public function initialize() {
- $this->name = 'post_template';
- $this->label = __( 'Post Template', 'acf' );
- $this->category = 'post';
- $this->object_type = 'post';
- }
-
- 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;
- }
-
- $post_templates = acf_get_post_templates();
- if ( ! isset( $post_templates[ $post_type ] ) ) {
- return false;
- }
-
- if ( isset( $screen['page_template'] ) ) {
- $page_template = $screen['page_template'];
- } elseif ( isset( $screen['post_id'] ) ) {
- $page_template = get_post_meta( $screen['post_id'], '_wp_page_template', true );
- } else {
- $page_template = '';
- }
-
- if ( $page_template === '' ) {
- $page_template = 'default';
- }
-
- return $this->compare_to_rule( $page_template, $rule );
- }
-
- public function get_values( $rule ) {
- return array_merge(
- array(
- 'default' => apply_filters( 'default_page_template_title', __( 'Default Template', 'acf' ) ),
- ),
- acf_get_post_templates()
- );
- }
-
- public function get_object_subtype( $rule ) {
- if ( $rule['operator'] === '==' ) {
- $post_templates = acf_get_post_templates();
-
- if ( $rule['value'] === 'default' ) {
- return array_keys( $post_templates );
-
- } else {
- $post_types = array();
- foreach ( $post_templates as $post_type => $templates ) {
- if ( isset( $templates[ $rule['value'] ] ) ) {
- $post_types[] = $post_type;
- }
- }
- return $post_types;
- }
- }
- return '';
- }
- }
-
- acf_register_location_type( 'ACF_Location_Post_Template' );
- endif;
|