diff --git a/includes/License/Manager.php b/includes/License/Manager.php index da4b242..7a04778 100644 --- a/includes/License/Manager.php +++ b/includes/License/Manager.php @@ -443,23 +443,25 @@ final class Manager { public static function is_localhost(): bool { $host = wp_parse_url( home_url(), PHP_URL_HOST ); - // Common localhost identifiers. - $localhost_hosts = array( + $localhost_patterns = array( 'localhost', '127.0.0.1', '::1', ); - if ( in_array( $host, $localhost_hosts, true ) ) { + // Check exact matches. + if ( in_array( $host, $localhost_patterns, true ) ) { return true; } - // Common local development TLDs. - $local_tlds = array( '.local', '.test', '.localhost', '.dev.local' ); - foreach ( $local_tlds as $tld ) { - if ( str_ends_with( $host, $tld ) ) { - return true; - } + // Check .localhost TLD (e.g., mysite.localhost). + if ( str_ends_with( $host, '.localhost' ) ) { + return true; + } + + // Check .local TLD (common for local development). + if ( str_ends_with( $host, '.local' ) ) { + return true; } return false; diff --git a/includes/Prometheus/Integration.php b/includes/Prometheus/Integration.php index 7fa9a68..ac6ea63 100644 --- a/includes/Prometheus/Integration.php +++ b/includes/Prometheus/Integration.php @@ -76,6 +76,30 @@ class Integration { return $this->prometheus_active; } + /** + * Collect metrics for early metrics mode. + * + * This static method can be called directly by wp-prometheus during early + * metrics mode when the wp_prometheus_collect_metrics hook is skipped. + * + * Usage in wp-prometheus early metrics handler: + * + * ```php + * // After creating the collector, before rendering: + * if ( class_exists( 'WP_FediStream\Prometheus\Integration' ) ) { + * \WP_FediStream\Prometheus\Integration::collect_early_metrics( $collector ); + * } + * ``` + * + * @param object $collector The Prometheus collector instance. + * @return void + */ + public static function collect_early_metrics( object $collector ): void { + $integration = new self(); + $integration->prometheus_active = true; // Force active since we're being called directly. + $integration->collect_metrics( $collector ); + } + /** * Collect FediStream metrics. *