ACF_Location_User_Role::match
Matches the provided rule against the screen args returning a bool result.
Method of the class: ACF_Location_User_Role{}
No Hooks.
Returns
true|false.
Usage
$ACF_Location_User_Role = new ACF_Location_User_Role(); $ACF_Location_User_Role->match( $rule, $screen, $field_group );
- $rule(array) (required)
- The location rule.
- $screen(array) (required)
- The screen args.
- $field_group(array) (required)
- The field group settings.
Changelog
| Since 5.9.0 | Introduced. |
ACF_Location_User_Role::match() ACF Location User Role::match code ACF 6.8.8
public function match( $rule, $screen, $field_group ) {
// Check screen args.
if ( isset( $screen['user_role'] ) ) {
$user_role = $screen['user_role'];
} elseif ( isset( $screen['user_id'] ) ) {
$user_id = $screen['user_id'];
$user_role = '';
// Determine $user_role from $user_id.
if ( $user_id === 'new' ) {
$user_role = get_option( 'default_role' );
// Check if user can, and if so, set the value allowing them to match.
} elseif ( ( $rule['value'] ?? '' ) && user_can( $user_id, $rule['value'] ) ) {
$user_role = $rule['value'];
}
} else {
return false;
}
// Compare rule against $user_role.
return $this->compare_to_rule( $user_role, $rule );
}