ACF_Location::compare_to_rule │ public │ ACF 5.8.1

Compares the given value and rule params returning true when they match.

Method of the class: ACF_Location{}

No Hooks.

Returns

boolean.

Usage

$ACF_Location = new ACF_Location();
$ACF_Location->compare_to_rule( $value, $rule );
$value(mixed) (required)
The value to compare against.
$rule(array) (required)
The location rule data.

Changelog

Since 5.8.1 Introduced.

ACF_Location::compare_to_rule() code ACF 6.8.8

public function compare_to_rule( $value, $rule ) {
	$rule_value = $rule['value'] ?? '';
	$result     = ( $value == $rule_value );

	// Allow "all" to match any value.
	if ( $rule_value === 'all' ) {
		$result = true;
	}

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