PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.9.4
Secure Custom Fields v6.9.4
6.9.5 6.9.4 6.9.3 6.9.2 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-taxonomy.php
secure-custom-fields / includes / locations Last commit date
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-post-taxonomy.php
115 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 if ( ! class_exists( 'ACF_Location_Post_Taxonomy' ) ) :
8
9 class ACF_Location_Post_Taxonomy 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_taxonomy';
21 $this->label = __( 'Post Taxonomy', '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_id'] ) ) {
41 $post_id = $screen['post_id'];
42 } elseif ( isset( $screen['attachment_id'] ) ) {
43 $post_id = $screen['attachment_id'];
44 } else {
45 return false;
46 }
47
48 // Get WP_Term from rule value.
49 $term = acf_get_term( $rule['value'] ?? '' );
50 if ( ! $term || is_wp_error( $term ) ) {
51 return false;
52 }
53
54 // Get terms connected to post.
55 if ( isset( $screen['post_terms'] ) ) {
56 $post_terms = acf_maybe_get( $screen['post_terms'], $term->taxonomy, array() );
57 } else {
58 $post_terms = wp_get_post_terms( $post_id, $term->taxonomy, array( 'fields' => 'ids' ) );
59 }
60
61 // If no post terms are found, and we are dealing with the "category" taxonomy, treat as default "Uncategorized" category.
62 if ( ! $post_terms && $term->taxonomy == 'category' ) {
63 $post_terms = array( 1 );
64 }
65
66 // Search $post_terms for a match.
67 $result = ( in_array( $term->term_id, $post_terms ) || in_array( $term->slug, $post_terms ) );
68
69 // Reverse result for "!=" operator.
70 if ( ( $rule['operator'] ?? '' ) === '!=' ) {
71 return ! $result;
72 }
73 return $result;
74 }
75
76 /**
77 * Returns an array of possible values for this rule type.
78 *
79 * @date 9/4/20
80 * @since ACF 5.9.0
81 *
82 * @param array $rule A location rule.
83 * @return array
84 */
85 public function get_values( $rule ) {
86 return acf_get_taxonomy_terms();
87 }
88
89 /**
90 * Returns the object_subtype connected to this location.
91 *
92 * @date 1/4/20
93 * @since ACF 5.9.0
94 *
95 * @param array $rule A location rule.
96 * @return string|array
97 */
98 public function get_object_subtype( $rule ) {
99 if ( ( $rule['operator'] ?? '' ) === '==' ) {
100 $term = acf_decode_term( $rule['value'] ?? '' );
101 if ( $term ) {
102 $taxonomy = get_taxonomy( $term['taxonomy'] );
103 if ( $taxonomy ) {
104 return $taxonomy->object_type;
105 }
106 }
107 }
108 return '';
109 }
110 }
111
112 // initialize
113 acf_register_location_type( 'ACF_Location_Post_Taxonomy' );
114 endif; // class_exists check
115