PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.9.1
Secure Custom Fields v6.9.1
6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / locations / class-acf-location-post-template.php
secure-custom-fields / includes / locations Last commit date
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-template.php
125 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 if ( ! class_exists( 'ACF_Location_Post_Template' ) ) :
8
9 class ACF_Location_Post_Template 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_template';
21 $this->label = __( 'Post Template', '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 // Check if this post type has templates.
49 $post_templates = acf_get_post_templates();
50 if ( ! isset( $post_templates[ $post_type ] ) ) {
51 return false;
52 }
53
54 // Get page template allowing for screen or database value.
55 if ( isset( $screen['page_template'] ) ) {
56 $page_template = $screen['page_template'];
57 } elseif ( isset( $screen['post_id'] ) ) {
58 $page_template = get_post_meta( $screen['post_id'], '_wp_page_template', true );
59 } else {
60 $page_template = '';
61 }
62
63 // Treat empty value as default template.
64 if ( $page_template === '' ) {
65 $page_template = 'default';
66 }
67
68 // Compare rule against $page_template.
69 return $this->compare_to_rule( $page_template, $rule );
70 }
71
72 /**
73 * Returns an array of possible values for this rule type.
74 *
75 * @date 9/4/20
76 * @since ACF 5.9.0
77 *
78 * @param array $rule A location rule.
79 * @return array
80 */
81 public function get_values( $rule ) {
82 return array_merge(
83 array(
84 'default' => apply_filters( 'default_page_template_title', __( 'Default Template', 'secure-custom-fields' ), 'meta-box' ),
85 ),
86 acf_get_post_templates()
87 );
88 }
89
90 /**
91 * Returns the object_subtype connected to this location.
92 *
93 * @date 1/4/20
94 * @since ACF 5.9.0
95 *
96 * @param array $rule A location rule.
97 * @return string|array
98 */
99 public function get_object_subtype( $rule ) {
100 if ( $rule['operator'] === '==' ) {
101 $post_templates = acf_get_post_templates();
102
103 // If "default", return array of all post types which have templates.
104 if ( $rule['value'] === 'default' ) {
105 return array_keys( $post_templates );
106
107 // Otherwise, generate list of post types that have the selected template.
108 } else {
109 $post_types = array();
110 foreach ( $post_templates as $post_type => $templates ) {
111 if ( isset( $templates[ $rule['value'] ] ) ) {
112 $post_types[] = $post_type;
113 }
114 }
115 return $post_types;
116 }
117 }
118 return '';
119 }
120 }
121
122 // initialize
123 acf_register_location_type( 'ACF_Location_Post_Template' );
124 endif; // class_exists check
125