server = $server; $this->conflicts = $conflicts; } public function recommendations() { $items = array(); $cache = (array) get_option( 'nbh_performance_cache_stats', array() ); $failures = (array) get_option( 'nbh_performance_asset_failures', array() ); $server = $this->server->report(); if ( empty( $cache['files'] ) && get_option( 'nbh_performance_cache_enabled', 0 ) ) { $items[] = $this->item( 'empty-cache', 80, 'warning', __( 'Warm the page cache', 'nbh-performance' ), __( 'Page caching is enabled but no cached pages are currently reported.', 'nbh-performance' ), 'enable_preload', array() ); } if ( count( $failures ) >= 5 || get_option( 'nbh_performance_asset_emergency_rollback', 0 ) ) { $items[] = $this->item( 'asset-failures', 100, 'critical', __( 'Recover unstable asset optimization', 'nbh-performance' ), __( 'Recent asset failures indicate that aggressive optimization should be rolled back.', 'nbh-performance' ), 'rollback_assets', array( 'failures' => count( $failures ) ) ); } foreach ( $this->conflicts->diagnose() as $issue ) { if ( in_array( $issue['severity'], array( 'critical', 'warning' ), true ) ) { $items[] = $this->item( 'conflict-' . $issue['id'], 'critical' === $issue['severity'] ? 99 : 75, $issue['severity'], __( 'Resolve optimization overlap', 'nbh-performance' ), $issue['message'], isset( $issue['group'] ) ? 'rollback_' . sanitize_key( $issue['group'] ) : null, array( 'group' => isset( $issue['group'] ) ? $issue['group'] : '' ) ); } } if ( isset( $server['compression']['brotli']['enabled'] ) && ! $server['compression']['brotli']['enabled'] ) { $items[] = $this->item( 'brotli', 45, 'info', __( 'Consider Brotli compression', 'nbh-performance' ), __( 'Brotli was not detected. Enable it at the server or CDN when supported.', 'nbh-performance' ), null, array() ); } if ( isset( $server['hosting']['tier'] ) && 'constrained' === $server['hosting']['tier'] ) { $items[] = $this->item( 'constrained-hosting', 70, 'warning', __( 'Use conservative background processing', 'nbh-performance' ), __( 'The server appears resource-constrained, so aggressive preload concurrency is not recommended.', 'nbh-performance' ), 'conservative_preload', array() ); } $items = apply_filters( 'nbh_performance_intelligence_recommendations', $items ); $items = is_array( $items ) ? $items : array(); usort( $items, static function ( $a, $b ) { return (int) $b['priority'] <=> (int) $a['priority']; } ); return array_slice( $items, 0, 20 ); } private function item( $id, $priority, $severity, $title, $reason, $action, array $evidence ) { return array( 'id' => sanitize_key( $id ), 'priority' => (int) $priority, 'severity' => $severity, 'title' => $title, 'reason' => $reason, 'action' => $action, 'evidence' => $evidence, ); } }