|null $active plugin attivi; null legge active_plugins * @param (callable(string):mixed)|null $option lettura opzioni; null usa get_option * @return list */ public static function detect(?array $active = null, ?callable $option = null): array { $active ??= (array) get_option('active_plugins', []); $option ??= static fn (string $name): mixed => get_option($name); $found = []; if ( in_array('autoptimize/autoptimize.php', $active, true) && $option('autoptimize_css_aggregate') === 'on' ) { $found[] = self::row( 'autoptimize', 'Autoptimize', __('Disable "Aggregate CSS" in Autoptimize or exclude the folder wp-content/uploads/nucleo/.', 'nucleo') ); } if ( in_array('autoptimize/autoptimize.php', $active, true) && ($option('autoptimize_js_aggregate') === 'on' || $option('autoptimize_js') === 'on') ) { $found[] = self::row( 'autoptimize', 'Autoptimize', __('Disable "Aggregate JS" and "Optimize JS" in Autoptimize or exclude the folder wp-content/uploads/nucleo/.', 'nucleo'), true ); } if (in_array('wp-rocket/wp-rocket.php', $active, true)) { $settings = $option('wp_rocket_settings'); if (is_array($settings) && !empty($settings['minify_concatenate_css'])) { $found[] = self::row( 'wp-rocket', 'WP Rocket', __('Disable "Concatenate CSS files" in WP Rocket or exclude the folder wp-content/uploads/nucleo/.', 'nucleo') ); } if ( is_array($settings) && (!empty($settings['minify_concatenate_js']) || !empty($settings['minify_js']) || !empty($settings['defer_all_js'])) ) { $found[] = self::row( 'wp-rocket', 'WP Rocket', __('Disable "Concatenate JS files", "Minify JS" and "Load JavaScript deferred" in WP Rocket or exclude the folder wp-content/uploads/nucleo/.', 'nucleo'), true ); } } if (in_array('litespeed-cache/litespeed-cache.php', $active, true)) { if ((bool) $option('litespeed.conf.optm-css_comb')) { $found[] = self::row( 'litespeed', 'LiteSpeed Cache', __('Disable "Combine CSS" in LiteSpeed Cache or exclude the folder wp-content/uploads/nucleo/.', 'nucleo') ); } if ( (bool) $option('litespeed.conf.optm-js_comb') || (bool) $option('litespeed.conf.optm-js_min') || (bool) $option('litespeed.conf.optm-js_defer') ) { $found[] = self::row( 'litespeed', 'LiteSpeed Cache', __('Disable "Combine JS", "Minify JS" and "Load JS deferred" in LiteSpeed Cache or exclude the folder wp-content/uploads/nucleo/.', 'nucleo'), true ); } } if (in_array('w3-total-cache/w3-total-cache.php', $active, true)) { $found[] = [ 'plugin' => 'w3tc', 'issue' => __('If CSS merging in W3 Total Cache is enabled, it regenerates different files per page and cancels the per-template CSS variants of Nucleo; the setting lives in a file, so it must be checked by hand.', 'nucleo'), 'fix' => __('Check the CSS minify settings of W3 Total Cache and disable merging, or exclude the folder wp-content/uploads/nucleo/.', 'nucleo'), ]; $found[] = [ 'plugin' => 'w3tc', 'issue' => __('If JS merging, minification or deferral in W3 Total Cache is enabled, it can change the scripts of Nucleo blocks on every page; the setting lives in a file, so it must be checked by hand.', 'nucleo'), 'fix' => __('Check the JS minify settings of W3 Total Cache and disable merging and deferral, or exclude the folder wp-content/uploads/nucleo/.', 'nucleo'), ]; } if (in_array('fast-velocity-minify/fvm.php', $active, true)) { $found[] = self::row( 'fvm', 'Fast Velocity Minify', __('Disable CSS combining in Fast Velocity Minify or exclude the folder wp-content/uploads/nucleo/.', 'nucleo') ); $found[] = self::row( 'fvm', 'Fast Velocity Minify', __('Disable JS combining in Fast Velocity Minify or exclude the folder wp-content/uploads/nucleo/.', 'nucleo'), true ); } return $found; } /** User meta con l'impronta dei conflitti già chiusi dall'utente. */ private const DISMISSED = 'nucleo_conflicts_dismissed'; private const DISMISS_ACTION = 'nucleo_dismiss_conflicts'; public static function register(): void { add_action('admin_notices', [self::class, 'renderNotice']); add_action('admin_post_' . self::DISMISS_ACTION, [self::class, 'dismiss']); } /** * Avviso dei conflitti per gli amministratori. Si chiude con il link "Dismiss" e resta chiuso finché l'elenco * dei conflitti non cambia; sparisce da solo quando i plugin in conflitto non sono più attivi. */ public static function renderNotice(): void { if (!current_user_can('manage_options')) { return; } $found = self::detect(); if ($found === [] || get_user_meta(get_current_user_id(), self::DISMISSED, true) === self::fingerprint($found)) { return; } $dismiss = wp_nonce_url(admin_url('admin-post.php?action=' . self::DISMISS_ACTION), self::DISMISS_ACTION); echo '

' . esc_html__('Nucleo: cache conflicts detected', 'nucleo') . '

' . esc_html__('Dismiss', 'nucleo') . '

'; } /** Chiude l'avviso per l'utente corrente e torna alla pagina di prima. */ public static function dismiss(): void { if (!current_user_can('manage_options')) { wp_die(esc_html__('You are not allowed to do this.', 'nucleo'), '', ['response' => 403]); } check_admin_referer(self::DISMISS_ACTION); update_user_meta(get_current_user_id(), self::DISMISSED, self::fingerprint(self::detect())); wp_safe_redirect(wp_get_referer() ?: admin_url()); exit; } /** @param list $found */ private static function fingerprint(array $found): string { return md5((string) wp_json_encode(array_column($found, 'issue'))); } /** @return array{plugin:string,issue:string,fix:string} */ private static function row(string $plugin, string $label, string $fix, bool $js = false): array { $issue = $js ? sprintf(/* translators: %s: name of the cache plugin */ __('JS merging or deferral in %s can change the scripts of Nucleo blocks, such as the gallery script, on every page.', 'nucleo'), $label) : sprintf(/* translators: %s: name of the cache plugin */ __('CSS merging in %s regenerates different files per page and cancels the per-template CSS variants of Nucleo.', 'nucleo'), $label); return [ 'plugin' => $plugin, 'issue' => $issue, 'fix' => $fix, ]; } }