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-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-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-taxonomy.php
116 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 5.0.0 |
| 16 | * |
| 17 | * @param void |
| 18 | * @return void |
| 19 | */ |
| 20 | public function initialize() { |
| 21 | $this->name = 'post_taxonomy'; |
| 22 | $this->label = __( 'Post Taxonomy', 'acf' ); |
| 23 | $this->category = 'post'; |
| 24 | $this->object_type = 'post'; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Matches the provided rule against the screen args returning a bool result. |
| 29 | * |
| 30 | * @date 9/4/20 |
| 31 | * @since 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 | } elseif ( isset( $screen['attachment_id'] ) ) { |
| 44 | $post_id = $screen['attachment_id']; |
| 45 | } else { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | // Get WP_Term from rule value. |
| 50 | $term = acf_get_term( $rule['value'] ); |
| 51 | if ( ! $term || is_wp_error( $term ) ) { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | // Get terms connected to post. |
| 56 | if ( isset( $screen['post_terms'] ) ) { |
| 57 | $post_terms = acf_maybe_get( $screen['post_terms'], $term->taxonomy, array() ); |
| 58 | } else { |
| 59 | $post_terms = wp_get_post_terms( $post_id, $term->taxonomy, array( 'fields' => 'ids' ) ); |
| 60 | } |
| 61 | |
| 62 | // If no post terms are found, and we are dealing with the "category" taxonomy, treat as default "Uncategorized" category. |
| 63 | if ( ! $post_terms && $term->taxonomy == 'category' ) { |
| 64 | $post_terms = array( 1 ); |
| 65 | } |
| 66 | |
| 67 | // Search $post_terms for a match. |
| 68 | $result = ( in_array( $term->term_id, $post_terms ) || in_array( $term->slug, $post_terms ) ); |
| 69 | |
| 70 | // Reverse result for "!=" operator. |
| 71 | if ( $rule['operator'] === '!=' ) { |
| 72 | return ! $result; |
| 73 | } |
| 74 | return $result; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Returns an array of possible values for this rule type. |
| 79 | * |
| 80 | * @date 9/4/20 |
| 81 | * @since 5.9.0 |
| 82 | * |
| 83 | * @param array $rule A location rule. |
| 84 | * @return array |
| 85 | */ |
| 86 | public function get_values( $rule ) { |
| 87 | return acf_get_taxonomy_terms(); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Returns the object_subtype connected to this location. |
| 92 | * |
| 93 | * @date 1/4/20 |
| 94 | * @since 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 | $term = acf_decode_term( $rule['value'] ); |
| 102 | if ( $term ) { |
| 103 | $taxonomy = get_taxonomy( $term['taxonomy'] ); |
| 104 | if ( $taxonomy ) { |
| 105 | return $taxonomy->object_type; |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | return ''; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // initialize |
| 114 | acf_register_location_type( 'ACF_Location_Post_Taxonomy' ); |
| 115 | endif; // class_exists check |
| 116 |