Panel' ); return $links; } public static function menu() { add_menu_page( 'RavenCache', 'RavenCache', 'manage_options', 'ravencache', array( __CLASS__, 'render' ), self::menu_icon(), 80 ); } public static function assets( $hook ) { if ( 'toplevel_page_ravencache' !== $hook ) { return; } // Wersja z czasem modyfikacji pliku: przeglądarka nie trzyma starego JS/CSS po aktualizacji wtyczki. $css_v = RAVENCACHE_VERSION . '.' . (int) @filemtime( RAVENCACHE_DIR . 'assets/sc-admin-102.css' ); $js_v = RAVENCACHE_VERSION . '.' . (int) @filemtime( RAVENCACHE_DIR . 'assets/sc-admin-102.js' ); wp_enqueue_style( 'ravencache-admin', RAVENCACHE_URL . 'assets/sc-admin-102.css', array(), $css_v ); wp_enqueue_script( 'ravencache-admin', RAVENCACHE_URL . 'assets/sc-admin-102.js', array(), $js_v, true ); wp_localize_script( 'ravencache-admin', 'RavenCache', array( 'ajax' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'ravencache' ), ) ); } /* ================= Komunikaty ================= */ /** Wartość tekstowa z $_POST (tablice i brak klucza dają pusty ciąg). Nonce jest sprawdzany w guard(). */ private static function post_str( $key ) { return isset( $_POST[ $key ] ) && is_string( $_POST[ $key ] ) ? wp_unslash( $_POST[ $key ] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- nonce checked in guard(); callers sanitize. } private static function messages() { return array( 'saved' => array( 'success', 'Settings saved. The cache was cleared so your changes show up right away.' ), 'profile' => array( 'success', 'Profile applied. Check your site in a private window; if something looks wrong, change individual options or go back to a lower profile.' ), 'purged' => array( 'success', 'Cache cleared (locally and in the configured CDN services).' ), 'reset' => array( 'success', 'Default settings restored.' ), 'imported' => array( 'success', 'Settings imported.' ), 'dropin_moved' => array( 'success', 'The foreign advanced-cache.php file was moved to advanced-cache.php.bak and our file was installed.' ), 'dropin_fail' => array( 'error', 'Could not move advanced-cache.php (no write permission in wp-content). Rename it manually via FTP or your file manager.' ), 'badjson' => array( 'error', 'Could not read the settings file (invalid JSON).' ), ); } public static function notices() { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || 'toplevel_page_ravencache' !== $screen->id ) { return; } $msgs = self::messages(); $msg_key = isset( $_GET['ravencache_msg'] ) && is_string( $_GET['ravencache_msg'] ) ? sanitize_key( wp_unslash( $_GET['ravencache_msg'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification -- read-only notice key, whitelisted below. if ( '' !== $msg_key && isset( $msgs[ $msg_key ] ) ) { $m = $msgs[ $msg_key ]; printf( '

%s

', esc_attr( $m[0] ), esc_html( $m[1] ) ); } if ( RavenCache_Settings::get( 'page_cache' ) ) { if ( RavenCache_Server::dropin_foreign() ) { echo '

RavenCache: the wp-content directory contains an advanced-cache.php file from another cache plugin. Deactivate that plugin (for example WP Rocket, W3 Total Cache, or WP Super Cache), otherwise page caching will not work.

File: ' . esc_html( RavenCache_Server::dropin_path() ) . '. If no such plugin is installed anymore, this is a leftover from it. Move this file to a backup (.bak)

'; } elseif ( ! RavenCache_Server::wp_cache_active() ) { echo '

RavenCache: could not enable the constant WP_CACHE. Add it manually to wp-config.php, above the “That\'s all”: define( \'WP_CACHE\', true );

Diagnostyka: katalog WordPressa ' . esc_html( ABSPATH ) . ', WP_CACHE constant: ' . ( defined( 'WP_CACHE' ) ? ( WP_CACHE ? 'true' : 'false' ) : 'niezdefiniowana' ) . ', config file: ' . esc_html( (string) RavenCache_Server::wp_config_path() ) . '. Edit exactly this file. If the line is already there and the constant still does not work, restart PHP in your hosting panel (OPcache).

'; } } $fail = get_transient( 'ravencache_htaccess_fail' ); if ( 'not-writable' === $fail ) { echo '

RavenCache: the .htaccess file is not writable, so the compression and header rules were not added. Use the ready-made snippet on the Advanced tab.

'; } elseif ( 'server-error' === $fail ) { echo '

RavenCache: after the rules were added to .htaccess the server returned a 500 error, so the change was rolled back automatically. Your host does not allow some of the directives; use the configuration snippet on the Advanced tab.

'; } } /* ================= Obsługa formularzy ================= */ private static function guard( $action ) { if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'You do not have permission.', 403 ); } check_admin_referer( $action ); } private static function back( $msg, $tab = '' ) { $url = add_query_arg( array( 'page' => 'ravencache', 'ravencache_msg' => $msg ), admin_url( 'admin.php' ) ); if ( $tab ) { $url .= '#' . rawurlencode( $tab ); } wp_safe_redirect( $url ); exit; } public static function post_save() { self::guard( 'ravencache_save' ); $tab = sanitize_key( self::post_str( 'tab' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- the nonce is verified in self::guard() above. if ( ! isset( RavenCache_Settings::schema()[ $tab ] ) ) { self::back( 'saved' ); } $input = isset( $_POST['sc'] ) && is_array( $_POST['sc'] ) ? wp_unslash( $_POST['sc'] ) : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- nonce verified in self::guard(); values are sanitized per field in RavenCache_Settings::save_tab(). RavenCache_Settings::save_tab( $input, $tab ); self::back( 'saved', $tab ); } public static function post_profile() { self::guard( 'ravencache_profile' ); RavenCache_Settings::apply_profile( isset( $_POST['level'] ) ? (int) $_POST['level'] : 0 ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- the nonce is verified in self::guard() above. self::back( 'profile', 'dashboard' ); } /** Przenosi osierocony, obcy advanced-cache.php do kopii .bak i instaluje nasz plik. */ public static function post_dropin_backup() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'You do not have permission.', 403 ); } check_admin_referer( 'ravencache_dropin_backup' ); $f = RavenCache_Server::dropin_path(); $ok = true; if ( RavenCache_Server::dropin_foreign() ) { $bak = $f . '.bak'; if ( file_exists( $bak ) ) { $bak = $f . '.' . time() . '.bak'; } $ok = RavenCache_Fs::move( $f, $bak ); } if ( $ok ) { RavenCache_Server::install_dropin(); } self::back( $ok ? 'dropin_moved' : 'dropin_fail', 'dashboard' ); } public static function post_purge_all() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'You do not have permission.', 403 ); } check_admin_referer( 'ravencache_purge_all' ); RavenCache_Purge::all(); $ref = wp_get_referer(); if ( $ref && false === strpos( $ref, 'page=ravencache' ) ) { wp_safe_redirect( $ref ); exit; } self::back( 'purged', 'dashboard' ); } public static function post_purge_url() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'You do not have permission.', 403 ); } check_admin_referer( 'ravencache_purge_url' ); $u = isset( $_GET['u'] ) && is_string( $_GET['u'] ) ? esc_url_raw( wp_unslash( $_GET['u'] ) ) : ''; if ( $u && wp_parse_url( $u, PHP_URL_HOST ) === wp_parse_url( home_url(), PHP_URL_HOST ) ) { RavenCache_Purge::urls( array( $u ) ); wp_safe_redirect( $u ); exit; } self::back( 'purged', 'dashboard' ); } public static function post_reset() { self::guard( 'ravencache_reset' ); RavenCache_Settings::reset(); self::back( 'reset', 'dashboard' ); } public static function post_import() { self::guard( 'ravencache_import' ); $json = self::post_str( 'json' ); // phpcs:ignore if ( RavenCache_Settings::import_json( $json ) ) { self::back( 'imported', 'adv' ); } self::back( 'badjson', 'adv' ); } /* ================= AJAX ================= */ public static function ajax() { if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'msg' => 'You do not have permission.' ), 403 ); } check_ajax_referer( 'ravencache', 'nonce' ); $do = sanitize_key( self::post_str( 'do' ) ); switch ( $do ) { case 'cf_verify': $r = RavenCache_Cloudflare::verify(); self::reply( $r['ok'], $r['msg'] ); break; case 'cf_detect': $r = RavenCache_Cloudflare::detect_zone(); self::reply( $r['ok'], $r['msg'], isset( $r['zone'] ) ? array( 'zone' => $r['zone'] ) : array() ); break; case 'cf_purge': $r = RavenCache_Cloudflare::purge_all(); self::reply( $r['ok'], $r['msg'] ); break; case 'cf_settings': self::need_cf(); $r = RavenCache_Cloudflare::get_settings(); if ( ! $r['ok'] ) { self::reply( false, 'Error: ' . $r['msg'] ); } $rows = ''; foreach ( RavenCache_Cloudflare::recommended() as $id => $def ) { $cur = isset( $r['settings'][ $id ] ) ? $r['settings'][ $id ] : '—'; $match = ( (string) $cur === (string) $def[0] ); $rows .= '' . esc_html( $def[1] ) . '' . esc_html( is_scalar( $cur ) ? (string) $cur : wp_json_encode( $cur ) ) . '' . ( $match ? 'zgodne' : 'zalecane: ' . esc_html( (string) $def[0] ) . '' ) . ''; } self::reply( true, 'Current zone settings:', array( 'html' => '' . $rows . '
SettingNowRating
' ) ); break; case 'cf_apply': self::need_cf(); $only = isset( $_POST['ids'] ) && is_array( $_POST['ids'] ) ? array_map( 'sanitize_key', wp_unslash( $_POST['ids'] ) ) : array(); // phpcs:ignore if ( ! $only ) { self::reply( false, 'Select at least one setting.' ); } $res = RavenCache_Cloudflare::apply_recommended( $only ); $html = '' ) ); break; case 'cf_rules_install': self::need_cf(); $r = RavenCache_Cloudflare::install_cache_rules(); self::reply( $r['ok'], $r['msg'] ); break; case 'cf_rules_remove': self::need_cf(); $r = RavenCache_Cloudflare::remove_cache_rules(); self::reply( $r['ok'], $r['msg'] ); break; case 'cf_dev_on': case 'cf_dev_off': self::need_cf(); $r = RavenCache_Cloudflare::dev_mode( 'cf_dev_on' === $do ); self::reply( $r['ok'], $r['msg'] ); break; case 'bunny_test': $r = RavenCache_CDN::bunny_purge(); self::reply( $r['ok'], $r['msg'] ); break; case 'http_test': $r = RavenCache_CDN::http_purge( true, array() ); self::reply( $r['ok'], $r['msg'] ); break; case 'purge_all': RavenCache_Purge::all( false ); $msgs = RavenCache_Purge::remote_now( true, array() ); self::reply( true, 'Wyczyszczono cache lokalny. ' . implode( ' ', $msgs ) ); break; case 'preload': $n = RavenCache_Preload::build_queue(); self::reply( true, 'Kolejka preload utworzona: ' . $n . ' URLs. Pages will be warmed in batches in the background (WP-Cron).' ); break; case 'test_headers': self::test_headers(); break; case 'ht_save': case 'ht_remove': case 'ht_restore': if ( function_exists( 'set_time_limit' ) ) { @set_time_limit( 120 ); // phpcs:ignore } if ( 'ht_save' === $do ) { $res = RavenCache_Htaccess::save( self::post_str( 'content' ), 'edit' ); // phpcs:ignore } elseif ( 'ht_remove' === $do ) { $res = RavenCache_Htaccess::remove_block( sanitize_text_field( self::post_str( 'name' ) ) ); } else { $res = RavenCache_Htaccess::restore( sanitize_file_name( self::post_str( 'name' ) ) ); } self::reply( $res['ok'], $res['msg'], array( 'reload' => (bool) $res['ok'] ) ); break; case 'report': case 'report_probe': // Szybka odpowiedź JSON nawet przy ostrzeżeniach PHP i wolnych żądaniach do własnej strony. if ( function_exists( 'set_time_limit' ) ) { @set_time_limit( 120 ); // phpcs:ignore } ob_start(); $txt = 'report' === $do ? RavenCache_Report::head_text() : RavenCache_Report::probe_text(); while ( ob_get_level() ) { ob_end_clean(); } $txt = function_exists( 'mb_convert_encoding' ) ? mb_convert_encoding( $txt, 'UTF-8', 'UTF-8' ) : $txt; wp_send_json_success( array( 'msg' => 'report' === $do ? 'Report ready (the page test will be added in a moment).' : 'Page test added.', 'report' => $txt ) ); break; case 'fonts_clear': RavenCache_Fonts::clear(); RavenCache_Purge::all(); self::reply( true, 'Local font copies removed. They will be downloaded again the next time a page is displayed.' ); break; case 'sync': RavenCache_Server::sync_all(); self::reply( true, 'Config file, cache drop-in, and server rules recreated.' ); break; case 'webp_bulk': $off = isset( $_POST['offset'] ) ? max( 0, (int) $_POST['offset'] ) : 0; if ( ! RavenCache_Media::supported() ) { self::reply( false, 'The server cannot write WebP (no Imagick with WebP or GD with imagewebp).' ); } $r = RavenCache_Media::bulk_batch( $off ); wp_send_json_success( array( 'msg' => 'Przetworzono ' . $r['done'] . ' z ' . $r['total'] . ' images.', 'progress' => $r ) ); break; case 'db_run': $tasks = isset( $_POST['tasks'] ) && is_array( $_POST['tasks'] ) ? array_map( 'sanitize_key', wp_unslash( $_POST['tasks'] ) ) : array(); // phpcs:ignore $tasks = array_values( array_intersect( $tasks, array_keys( RavenCache_Database::tasks() ) ) ); if ( ! $tasks ) { self::reply( false, 'Select the tasks to run.' ); } $res = RavenCache_Database::run( $tasks ); $txt = array(); foreach ( $res as $k => $v ) { $txt[] = RavenCache_Database::tasks()[ $k ] . ': ' . $v; } self::reply( true, 'Gotowe. ' . implode( '; ', $txt ) ); break; case 'autoload_off': $name = sanitize_text_field( self::post_str( 'name' ) ); // phpcs:ignore if ( '' === $name || RavenCache_Database::option_is_protected( $name ) ) { self::reply( false, 'This option is protected and cannot be changed from here.' ); } if ( ! function_exists( 'wp_set_option_autoload' ) ) { self::reply( false, 'This feature requires WordPress 6.4 or newer.' ); } wp_set_option_autoload( $name, false ); self::reply( true, 'Autoload disabled for: ' . $name . ' (the option still exists, it just loads on demand).' ); break; default: self::reply( false, 'Unknown action.' ); } } private static function need_cf() { if ( ! RavenCache_Cloudflare::has_credentials() ) { self::reply( false, 'Save your Cloudflare API token or key first.' ); } if ( '' === RavenCache_Cloudflare::zone() ) { self::reply( false, 'Detect or enter the Zone ID first.' ); } } private static function reply( $ok, $msg, $extra = array() ) { $data = array_merge( array( 'msg' => $msg ), $extra ); if ( $ok ) { wp_send_json_success( $data ); } wp_send_json_error( $data ); } private static function test_headers() { $url = home_url( '/' ); $args = array( 'timeout' => 20, 'redirection' => 0, 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), 'headers' => array( 'Accept-Encoding' => 'gzip', 'User-Agent' => 'RavenCache-Test/1.0' ) ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- core WordPress filter. $rows = array(); for ( $i = 1; $i <= 2; $i++ ) { $t = microtime( true ); $r = wp_remote_get( $url, $args ); $ms = (int) round( ( microtime( true ) - $t ) * 1000 ); if ( is_wp_error( $r ) ) { self::reply( false, 'Error connecting to your own site: ' . $r->get_error_message() ); } $h = wp_remote_retrieve_headers( $r ); $rows[] = array( 'try' => $i, 'ms' => $ms, 'code' => wp_remote_retrieve_response_code( $r ), 'cache' => isset( $h['x-ravencache'] ) ? $h['x-ravencache'] : '—', 'enc' => isset( $h['content-encoding'] ) ? $h['content-encoding'] : '—', 'cc' => isset( $h['cache-control'] ) ? $h['cache-control'] : '—', 'cf' => isset( $h['cf-cache-status'] ) ? $h['cf-cache-status'] : '—', 'server' => isset( $h['server'] ) ? $h['server'] : '—', 'size' => strlen( wp_remote_retrieve_body( $r ) ), ); } $html = ''; foreach ( $rows as $x ) { $html .= ''; } $html .= '
RequestTimeHTTPX-RavenCacheCompressionCache-ControlCF-Cache-StatusServer
' . (int) $x['try'] . '' . (int) $x['ms'] . ' ms' . (int) $x['code'] . '' . esc_html( $x['cache'] ) . '' . esc_html( $x['enc'] ) . '' . esc_html( $x['cc'] ) . '' . esc_html( $x['cf'] ) . '' . esc_html( $x['server'] ) . '
'; $hit = ( 'HIT' === strtoupper( (string) $rows[1]['cache'] ) ); $msg = $hit ? 'The cache works: the second response came from the cache (' . $rows[1]['ms'] . ' ms vs ' . $rows[0]['ms'] . ' ms).' : 'The second response is not a HIT. Turn on the “X-RavenCache header” option on the Advanced tab and check the reason (BYPASS: …) in the headers.'; self::reply( $hit, $msg, array( 'html' => $html ) ); } /* ================= Renderowanie ================= */ private static function deps() { return array( 'cache_ttl' => 'page_cache', 'cache_gzip' => 'page_cache', 'cache_mobile' => 'page_cache', 'purge_mode' => 'page_cache', 'cache_preload' => 'page_cache', 'preload_batch' => 'cache_preload', 'preload_sitemap' => 'cache_preload', 'edge_ttl' => 'edge_headers', 'js_defer_exclude' => 'js_defer', 'js_delay_list' => 'js_delay', 'js_delay_exclude' => 'js_delay', 'js_delay_timeout' => 'js_delay', 'css_async' => 'critical_css', 'css_async_exclude' => 'css_async', 'speculation_eagerness' => 'speculation', 'lazy_skip' => 'lazy_images', 'webp_quality' => 'webp', 'cdn_url' => 'cdn_rewrite', 'cdn_dirs' => 'cdn_rewrite', 'cf_auth' => 'cf_enabled', 'cf_token' => 'cf_enabled', 'cf_email' => 'cf_enabled', 'cf_key' => 'cf_enabled', 'cf_zone' => 'cf_enabled', 'bunny_key' => 'bunny_enabled', 'bunny_zone' => 'bunny_enabled', 'purge_http_url' => 'purge_http', 'purge_http_all' => 'purge_http', 'static_days' => 'htaccess', ); } private static function risk_label( $r ) { $m = array( 0 => array( 'bezpieczne', 'sc-r0' ), 1 => array( 'medium risk', 'sc-r1' ), 2 => array( 'agresywne', 'sc-r2' ) ); return $m[ min( 2, max( 0, (int) $r ) ) ]; } private static function option_text( $f, $v ) { if ( 'checkbox' === $f['type'] ) { return $v ? 'on' : 'off'; } if ( 'select' === $f['type'] ) { return isset( $f['options'][ $v ] ) ? $f['options'][ $v ] : (string) $v; } return (string) $v; } private static function profile_chip( $f ) { $names = array( 1 => 'B', 2 => 'Z', 3 => 'A' ); if ( isset( $f['p'] ) ) { $p = (int) $f['p']; return 'profil ' . $names[ $p ] . '+'; } if ( isset( $f['pv'] ) ) { $parts = array(); foreach ( $f['pv'] as $lvl => $val ) { $parts[] = $names[ $lvl ] . ': ' . self::option_text( $f, $val ); } return '' . esc_html( implode( ' · ', $parts ) ) . ''; } return 'manual'; } private static function render_field( $f ) { $id = $f['id']; $val = RavenCache_Settings::get( $id ); $name = 'sc[' . $id . ']'; $risk = self::risk_label( $f['risk'] ); $deps = self::deps(); $dep = isset( $deps[ $id ] ) ? ' data-dep="' . esc_attr( $deps[ $id ] ) . '"' : ''; $hay = strtolower( $f['label'] . ' ' . $f['desc'] . ' ' . $id ); echo '
'; // phpcs:ignore echo '
'; echo ' ' . esc_html( $risk[0] ) . ' ' . self::profile_chip( $f ); // phpcs:ignore if ( '' !== $f['desc'] ) { echo '

' . esc_html( $f['desc'] ) . '

'; } echo '
'; switch ( $f['type'] ) { case 'checkbox': echo ''; // phpcs:ignore break; case 'number': echo ''; // phpcs:ignore break; case 'select': echo ''; break; case 'textarea': case 'code': $rows = isset( $f['rows'] ) ? (int) $f['rows'] : 5; echo ''; // phpcs:ignore break; case 'secret': $const_set = RavenCache_Settings::secret( $id ) !== (string) $val && '' !== RavenCache_Settings::secret( $id ); $has = '' !== RavenCache_Settings::secret( $id ); echo ''; // phpcs:ignore if ( $has ) { echo '

Leave empty to keep the current value. Enter “-” to remove it.

'; } break; default: echo ''; // phpcs:ignore } echo '
'; } public static function render() { if ( ! current_user_can( 'manage_options' ) ) { return; } $tabs = RavenCache_Settings::tabs(); $prof = (int) RavenCache_Settings::get( 'profile' ); $profs = RavenCache_Settings::profiles(); echo '
'; echo '

RavenCache v' . esc_html( RAVENCACHE_VERSION ) . '

'; echo '
'; self::status_chip( 'Page cache', (bool) RavenCache_Settings::get( 'page_cache' ) ); self::status_chip( 'Cloudflare', RavenCache_Cloudflare::configured() ); echo 'Profile: ' . esc_html( $prof && isset( $profs[ $prof ] ) ? $profs[ $prof ]['label'] : 'custom' ) . ''; echo '
'; echo '
'; echo ''; foreach ( $tabs as $slug => $label ) { echo '
'; if ( 'dashboard' === $slug ) { self::tab_dashboard(); } elseif ( 'ai' === $slug && class_exists( 'RavenCache_AI' ) ) { RavenCache_AI::render_tab(); } elseif ( 'license' === $slug && class_exists( 'RavenCache_License' ) ) { RavenCache_License::render_tab(); } else { self::tab_form( $slug, $label ); } echo '
'; } echo '
'; } private static function status_chip( $label, $on ) { echo '' . esc_html( $label ) . ': ' . ( $on ? 'on' : 'off' ) . ''; } /* ---------- Zakładka z formularzem ---------- */ private static function tab_form( $slug, $label ) { echo '
'; wp_nonce_field( 'ravencache_save' ); echo ''; if ( 'cdn' === $slug ) { self::tools_cloudflare(); } if ( 'media' === $slug ) { self::tools_media_top(); } foreach ( RavenCache_Settings::schema()[ $slug ] as $section => $fields ) { echo '

' . esc_html( $section ) . '

'; foreach ( $fields as $f ) { self::render_field( $f ); } echo '
'; } if ( 'db' === $slug ) { self::tools_db(); } if ( 'adv' === $slug ) { self::tools_adv(); } echo '
Saving clears the cache so your changes show up right away.
'; echo '
'; if ( 'adv' === $slug ) { self::tools_htaccess(); self::tools_adv_forms(); } } /* ---------- Panel główny ---------- */ private static function tab_dashboard() { $profs = RavenCache_Settings::profiles(); $cur = (int) RavenCache_Settings::get( 'profile' ); echo '

Profiles: quick start

A profile sets many options at once. You can then change each option separately on the tabs. Changing one by hand switches the profile to “custom.”

'; foreach ( $profs as $lvl => $p ) { echo '
'; wp_nonce_field( 'ravencache_profile' ); echo ''; echo '

' . esc_html( $p['label'] ) . ( $cur === $lvl ? ' active' : '' ) . '

' . esc_html( $p['desc'] ) . '

'; echo '
'; } echo '
'; // Szybkie akcje. $st = RavenCache_Purge::stats(); echo '

Quick actions

'; echo '

In cache: ' . (int) $st['files'] . ' files, ' . esc_html( size_format( $st['bytes'] ) ) . ''; $last = (int) get_option( 'ravencache_last_purge', 0 ); if ( $last ) { echo ' · last purge: ' . esc_html( human_time_diff( $last ) ) . ' ago'; } if ( RavenCache_Preload::remaining() ) { echo ' · preload: remaining ' . (int) RavenCache_Preload::remaining() . ' URLs'; } echo '

'; echo ''; echo ''; echo ''; echo ''; echo '
'; RavenCache_Perf::render_card(); echo '

Configuration dump for diagnostics

The panel script did not load (an old version is cached in the browser or CDN). Refresh the page with Ctrl+F5, and if that does not help, clear the Cloudflare / hosting cache for the plugin files.

Generates a report: environment, cache status, all settings, a home page test (desktop and mobile, twice), and an HTML analysis of what blocks the first render. The report does not include API keys, passwords, or page content. Copy it and paste it into the conversation.

'; echo '
'; echo '
'; self::health_table(); } /** Ikona w menu administratora (pojedynczy kolor, WordPress dopasowuje ją do motywu panelu). */ private static function menu_icon() { $f = RAVENCACHE_DIR . 'assets/menu-icon.svg'; return is_readable( $f ) ? 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( $f ) ) : 'dashicons-performance'; // phpcs:ignore } private static function health_table() { $rows = array(); $add = function ( $label, $level, $text ) use ( &$rows ) { $rows[] = array( $label, $level, $text ); }; if ( RavenCache_Settings::get( 'page_cache' ) ) { if ( RavenCache_Server::dropin_foreign() ) { $add( 'Page cache', 'bad', 'Found advanced-cache.php from another plugin, so the RavenCache page cache is not active.' ); } elseif ( ! RavenCache_Server::dropin_is_ours() ) { $add( 'Page cache', 'bad', 'wp-content/advanced-cache.php is missing (is the directory not writable?). Click “Recreate config.”' ); } elseif ( ! RavenCache_Server::wp_cache_active() ) { $add( 'Page cache', 'warn', 'The WP_CACHE constant is missing from wp-config.php.' ); } else { $add( 'Page cache', 'ok', 'Aktywny (drop-in + WP_CACHE).' ); } } else { $add( 'Page cache', 'info', 'Off. This is the most effective single optimization; turn it on in the “Page cache” tab.' ); } $add( 'Cache directory', wp_is_writable( WP_CONTENT_DIR ) ? 'ok' : 'bad', wp_is_writable( WP_CONTENT_DIR ) ? 'wp-content is writable.' : 'wp-content is not writable, so the cache cannot save files.' ); $php = PHP_VERSION; $add( 'PHP version', version_compare( $php, '8.1', '>=' ) ? 'ok' : ( version_compare( $php, '7.4', '>=' ) ? 'warn' : 'bad' ), $php . ( version_compare( $php, '8.1', '>=' ) ? '' : ' – nowsze PHP (8.2/8.3) bywa o 20–40% szybsze. Zaktualizuj u hostingodawcy.' ) ); $opc = function_exists( 'opcache_get_status' ) && ini_get( 'opcache.enable' ); $add( 'OPcache', $opc ? 'ok' : 'bad', $opc ? 'On.' : 'Off. This is one of the most important PHP settings. Ask your host to enable it.' ); $obj = wp_using_ext_object_cache(); $add( 'Persistent object cache (Redis/Memcached)', $obj ? 'ok' : 'warn', $obj ? 'Active.' : 'None. For stores, sites with logins, and large databases, install Redis plus the Redis Object Cache plugin to cut database queries.' ); $add( 'WP-Cron', ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? 'ok' : 'info', ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? 'Disabled: you are using a system cron (good).' : 'WP-Cron runs on page visits. For reliable preloading and database cleanup, set up a system cron: */5 * * * * wget -q -O- ' . site_url( '/wp-cron.php?doing_wp_cron' ) . ' i DISABLE_WP_CRON.' ); $webp = RavenCache_Media::supported(); $add( 'WebP support on the server', $webp ? 'ok' : 'warn', $webp ? 'Yes (' . $webp . ').' : 'None (needs Imagick with WebP or GD with imagewebp).' ); $al = RavenCache_Database::autoload_report( 1 ); $kb = round( $al['total'] / 1024 ); $add( 'Autoload options in the database', $al['total'] < 800 * 1024 ? 'ok' : ( $al['total'] < 2 * 1024 * 1024 ? 'warn' : 'bad' ), $kb . ' KB w ' . $al['count'] . ' options loaded on every request' . ( $al['total'] >= 800 * 1024 ? ' – too much, check the report on the “Database” tab.' : '.' ) ); $add( 'Permalinks', get_option( 'permalink_structure' ) ? 'ok' : 'warn', get_option( 'permalink_structure' ) ? 'Pretty permalinks are on.' : '“Plain” permalinks (?p=123) are on, which is worse for SEO and caching. Change it under Settings → Permalinks.' ); $add( 'HTTPS', is_ssl() ? 'ok' : 'warn', is_ssl() ? 'Active.' : 'The site is not served over HTTPS (HTTP/2/3 and Cloudflare require HTTPS).' ); $add( 'PHP memory limit', 'info', WP_MEMORY_LIMIT . ' (WP), ' . ini_get( 'memory_limit' ) . ' (PHP)' ); $conflicts = array(); $map = array( 'WP Rocket' => 'wp-rocket/wp-rocket.php', 'W3 Total Cache' => 'w3-total-cache/w3-total-cache.php', 'WP Super Cache' => 'wp-super-cache/wp-cache.php', 'WP Fastest Cache' => 'wp-fastest-cache/wpFastestCache.php', 'LiteRavenCache' => 'literavencache/literavencache.php', 'Autoptimize' => 'autoptimize/autoptimize.php', 'WP-Optimize' => 'wp-optimize/wp-optimize.php', 'Hummingbird' => 'hummingbird-performance/wp-hummingbird.php', 'Cache Enabler' => 'cache-enabler/cache-enabler.php', 'Breeze' => 'breeze/breeze.php', 'SG Optimizer' => 'sg-cachepress/sg-cachepress.php' ); foreach ( $map as $name => $file ) { if ( is_plugin_active( $file ) ) { $conflicts[] = $name; } } $add( 'Conflicts with other plugins', $conflicts ? 'bad' : 'ok', $conflicts ? 'Aktywne: ' . implode( ', ', $conflicts ) . '. Two cache/optimization plugins at once cause errors; keep only one.' : 'No other cache plugins detected.' ); $cf = get_option( 'ravencache_cf_last' ); if ( RavenCache_Cloudflare::configured() ) { $add( 'Cloudflare', ! empty( $cf ) && empty( $cf['ok'] ) ? 'warn' : 'ok', empty( $cf ) ? 'Connected, no purges yet.' : ( $cf['msg'] . ' (' . human_time_diff( $cf['time'] ) . ' ago)' ) ); } else { $add( 'Cloudflare', 'info', 'Not connected. See the “Cloudflare & CDN” tab.' ); } echo '

Environment diagnostics

'; foreach ( $rows as $r ) { echo ''; } echo '
' . esc_html( $r[0] ) . '' . esc_html( $r[2] ) . '
'; } /* ---------- Narzędzia w zakładkach ---------- */ private static function tools_cloudflare() { echo '

Cloudflare tools

'; echo '

Fill in the details below and save, then use the buttons. How to get a token: Cloudflare → My Profile → API Tokens → Create Token → “Create Custom Token.” Permissions: Zone · Cache Purge · Purge, Zone · Zone Settings · Edit, Zone · Zone · Read, Zone · Cache Rules · Edit. Zone resources: only your domain.

'; echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; echo '

Recommended zone settings

Select which settings to change in your zone. Nothing changes without your click. Features not available on your plan are skipped with a message.

'; foreach ( RavenCache_Cloudflare::recommended() as $id => $def ) { echo ''; } echo ''; echo '
'; echo '

HTML cache at the Cloudflare edge (Cache Rules)

By default Cloudflare does not cache HTML. The button adds two rules: (1) cache HTML according to the headers sent by RavenCache, (2) bypass the cache for wp-admin, login, logged-in users, commenters, the cart, and excluded URLs. Existing rules in the zone are left untouched. Requires the “Send Cache-Control headers for CDN” option on the Page cache tab. Result: visitors worldwide get the page from the nearest CDN node, and your server is relieved.

'; echo '
'; $last = get_option( 'ravencache_cf_last' ); if ( $last ) { echo '

Last Cloudflare purge: ' . esc_html( $last['msg'] ) . ' (' . esc_html( human_time_diff( $last['time'] ) ) . ' ago)

'; } echo '
'; echo '

Test other services

Save the settings below first.

'; } private static function tools_media_top() { echo '

WebP: convert existing images

'; $drv = RavenCache_Media::supported(); echo '

Server support: ' . ( $drv ? 'yes (' . esc_html( $drv ) . ')' : 'brak' ) . '. JPEG/PNG images in the library: ' . (int) RavenCache_Media::webp_count() . '. New files are converted automatically on upload (if the WebP option is on). Below you can convert images uploaded earlier; originals stay unchanged.

'; echo '
'; echo '

Local Google Fonts

Locally saved stylesheets: ' . (int) RavenCache_Fonts::count() . '.

'; } private static function tools_db() { $c = RavenCache_Database::counts(); echo '

Manual cleanup

Select tasks and run them. Back up your database before making larger changes.

'; foreach ( RavenCache_Database::tasks() as $id => $label ) { echo ''; // phpcs:ignore } echo '
TaskTo clean
' . esc_html( $label ) . '' . ( 'optimize' === $id ? (int) $c[ $id ] . ' tabel' : (int) $c[ $id ] ) . '
'; $al = RavenCache_Database::autoload_report( 15 ); echo '

Autoload options report

“Autoload” options are loaded from the database on EVERY request. Total: ' . esc_html( size_format( $al['total'] ) ) . ' w ' . (int) $al['count'] . ' options. A value above ~1 MB noticeably slows the site, usually because of leftovers from removed plugins. Disabling autoload does not delete the option, it just stops loading it every time (the plugin fetches it when needed).

'; echo ''; foreach ( $al['rows'] as $row ) { $prot = RavenCache_Database::option_is_protected( $row['option_name'] ); echo ''; // phpcs:ignore } echo '
OptionSize
' . esc_html( $row['option_name'] ) . '' . esc_html( size_format( (int) $row['size'] ) ) . '' . ( $prot ? 'chroniona' : '' ) . '
'; } private static function tools_adv() { echo '

Server configuration: ready-made snippets

'; $apache = RavenCache_Server::server_is_apache_like(); echo '

Detected server: ' . esc_html( isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : 'nieznany' ) . '. ' . ( $apache ? '.htaccess rules are supported.' : '.htaccess rules do not work on Nginx. Paste the snippet below into your server configuration (or ask your host).' ) . '

'; echo '

Nginx

'; echo '

Apache (.htaccess)

'; } private static function tools_htaccess() { $src = RavenCache_Htaccess::read(); $ok = RavenCache_Htaccess::writable(); echo '

.htaccess editor

'; echo '

File: ' . esc_html( RavenCache_Htaccess::path() ) . '. Every save backs up the previous version and checks that the home page and login respond without a 5xx error. If they do not, the previous version is restored automatically. You write rules at your own risk: a syntax error can take the site down before the test has a chance to roll it back.

'; if ( ! RavenCache_Server::server_is_apache_like() ) { echo '

This server does not look like Apache/LiteSpeed, so .htaccess may be ignored.

'; } if ( ! $ok ) { echo '

The file or directory is not writable, so editing is disabled.

'; } $blocks = RavenCache_Htaccess::blocks( $src ); if ( $blocks ) { $lbl = array( 'core' => 'WordPress', 'ours' => 'RavenCache', 'foreign' => 'another cache plugin', 'other' => 'inne' ); echo '

Blocks in the file

'; foreach ( $blocks as $b ) { echo ''; } echo '
BlockLinesType
' . esc_html( $b['name'] ) . '' . (int) $b['lines'] . '' . ( 'foreign' === $b['kind'] ? '' : '' ) . esc_html( $lbl[ $b['kind'] ] ) . ( 'foreign' === $b['kind'] ? '' : '' ) . ''; if ( $ok && 'core' !== $b['kind'] ) { echo ''; } echo '
'; } echo '

Contents

'; if ( $ok ) { echo '
'; } echo '
'; $bk = RavenCache_Htaccess::backups(); if ( $bk && $ok ) { echo '

Backups (last ' . (int) RavenCache_Htaccess::KEEP . ')

'; foreach ( $bk as $b ) { echo ''; } echo '
' . esc_html( $b['file'] ) . '' . esc_html( size_format( $b['size'] ) ) . '
'; } echo '
'; } private static function tools_adv_forms() { echo '

Backup and reset

'; echo '

The export does not include API keys. You can move the configuration to other sites.

'; echo ''; echo '
'; wp_nonce_field( 'ravencache_import' ); echo '

Import

'; echo '
'; wp_nonce_field( 'ravencache_reset' ); echo '

'; } }