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)
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).
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 .= '
';
}
self::reply( $ok, $ok ? 'All selected settings applied.' : 'Some settings were not changed (for example, missing token permissions or a feature not available on your plan).', array( 'html' => $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 = '
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 '
' . esc_html( $r[0] ) . '
' . esc_html( $r[2] ) . '
';
}
echo '
';
}
/* ---------- 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.
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.
“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).
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.