getArray( 'selected_roles', 'sanitize_key' ); $operator = Params::post()->getKey( 'operator', 'is' ); if ( empty( $selected_roles ) ) { // When no roles are selected, we assume a match. wp_send_json_success( [ 'match' => true ] ); } $current_user_roles = is_user_logged_in() ? wp_get_current_user()->roles ?? [] : []; $match = false; $intersection = array_intersect( $current_user_roles, $selected_roles ); if ( ! empty( $intersection ) ) { // User has at least one of the selected roles $match = true; } $final_result = ( $operator === 'is_not' ) ? ! $match : $match; wp_send_json_success( [ 'match' => $final_result ] ); } }