rules_provider = $rules_provider; } public function detect( string $user_agent ): array { $ua = trim( (string) $user_agent ); if ( '' === $ua ) { return [ 'is_bot' => false ]; } foreach ( $this->rules_provider->get_all_rules() as $rule ) { if ( empty( $rule['pattern'] ) ) { continue; } if ( false !== stripos( $ua, $rule['pattern'] ) ) { return [ 'is_bot' => true, 'bot_slug' => $rule['slug'], 'bot_name' => $rule['name'] ?? $rule['slug'], ]; } } return [ 'is_bot' => false ]; } }