acf_get_field_group_visibility()ACF 5.0.0

acf_get_field_group_visibility

Returns true if the given field group's location rules match the given $args.

Хуков нет.

Возвращает

true|false.

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

acf_get_field_group_visibility( $field_group, $args );
$field_group (обязательный)
-
$args(массив)
An array of location args.
По умолчанию: array()

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

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

Код acf_get_field_group_visibility() ACF 5.10.2

function acf_get_field_group_visibility( $field_group, $args = array() ) {

	// Check if active.
	if ( ! $field_group['active'] ) {
		return false;
	}

	// Check if location rules exist
	if ( $field_group['location'] ) {

		// Get the current screen.
		$screen = acf_get_location_screen( $args );

		// Loop through location groups.
		foreach ( $field_group['location'] as $group ) {

			// ignore group if no rules.
			if ( empty( $group ) ) {
				continue;
			}

			// Loop over rules and determine if all rules match.
			$match_group = true;
			foreach ( $group as $rule ) {
				if ( ! acf_match_location_rule( $rule, $screen, $field_group ) ) {
					$match_group = false;
					break;
				}
			}

			// If this group matches, show the field group.
			if ( $match_group ) {
				return true;
			}
		}
	}

	// Return default.
	return false;
}