ACF_Location_Post_Taxonomy::match()publicACF 5.9.0

Matches the provided rule against the screen args returning a bool result.

{} Это метод класса: ACF_Location_Post_Taxonomy{}

Хуков нет.

Возвращает

true|false.

Использование

$ACF_Location_Post_Taxonomy = new ACF_Location_Post_Taxonomy();
$ACF_Location_Post_Taxonomy->match( $rule, $screen, $field_group );
$rule(массив) (обязательный)
The location rule.
$screen(массив) (обязательный)
The screen args.
$field_group(массив) (обязательный)
The field group settings.

Список изменений

С версии 5.9.0 Введена.

Код ACF_Location_Post_Taxonomy::match() ACF 5.10.2

public function match( $rule, $screen, $field_group ) {

	// Check screen args.
	if ( isset( $screen['post_id'] ) ) {
		$post_id = $screen['post_id'];
	} elseif ( isset( $screen['attachment_id'] ) ) {
		$post_id = $screen['attachment_id'];
	} else {
		return false;
	}

	// Get WP_Term from rule value.
	$term = acf_get_term( $rule['value'] );
	if ( ! $term || is_wp_error( $term ) ) {
		return false;
	}

	// Get terms connected to post.
	if ( isset( $screen['post_terms'] ) ) {
		$post_terms = acf_maybe_get( $screen['post_terms'], $term->taxonomy, array() );
	} else {
		$post_terms = wp_get_post_terms( $post_id, $term->taxonomy, array( 'fields' => 'ids' ) );
	}

	// If no post terms are found, and we are dealing with the "category" taxonomy, treat as default "Uncategorized" category.
	if ( ! $post_terms && $term->taxonomy == 'category' ) {
		$post_terms = array( 1 );
	}

	// Search $post_terms for a match.
	$result = ( in_array( $term->term_id, $post_terms ) || in_array( $term->slug, $post_terms ) );

	// Reverse result for "!=" operator.
	if ( $rule['operator'] === '!=' ) {
		return ! $result;
	}
	return $result;
}