"Overview", "settings" => "Cache & media", "diagnostics" => "Inspect a page", "recovery" => "Recovery", ]); } public static function form(string $op, string $tab): void { echo '
'; wp_nonce_field("ssfspeed_action"); } public static function button(string $label): void { echo '"; } /** Only declared, typed fields may be passed on to an action or an extension. */ private static function fields(string $op): array { $schemas = [ "settings" => [ "enabled" => "flag", "lazy" => "flag", "products" => "flag", "ttl" => "number", "hero" => "number", Core::EXCLUDED_PATHS => "paths", "defer" => "keys", ], "inspect" => ["path" => "path"], "purge_path" => ["path" => "path"], "pro_save" => [ "mode" => "key", "page_ids" => "ids", "delay" => "keys", "remove_scripts" => "keys", "remove_styles" => "keys", "preload_ids" => "ids", "schedule" => "key", ], "image_batch" => ["image_ids" => "ids", "format" => "key"], "image_delivery" => ["delivery" => "flag", "hero_id" => "number"], "agency_roles" => ["roles" => "keys", "client_label" => "text"], "agency_preview" => ["profile" => "profile"], ]; $out = []; foreach ($schemas[$op] ?? [] as $key => $type) { // Called only from the capability- and nonce-verified POST handler. The schema above selects the validator. $raw = isset($_POST[$key]) ? wp_unslash($_POST[$key]) : ""; // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Each allowlisted field is validated below before leaving this method. $out[$key] = self::field($type, $raw); } return $out; } private static function field(string $type, $raw) { $scalar = is_scalar($raw) ? (string) $raw : ""; switch ($type) { case "flag": return $scalar === "1"; case "number": return absint($scalar); case "path": return Engine::path(trim($scalar)); case "paths": case "keys": case "ids": $parts = is_array($raw) ? $raw : preg_split( $type === "paths" ? "/\R/" : "/[\s,]+/", $scalar, ); $result = []; foreach ($parts as $v) { if (!is_scalar($v)) { continue; } $v = $type === "paths" ? Engine::path(trim((string) $v)) : ($type === "keys" ? sanitize_key((string) $v) : absint($v)); if ($v !== "" && $v !== 0) { $result[] = $v; } } return array_values(array_unique($result)); case "key": return sanitize_key($scalar); case "profile": if (strlen($scalar) > 32000) { return ""; } $data = json_decode($scalar, true); if ( !is_array($data) || ($data["schema"] ?? "") !== "ssfspeed-profile-v1" || !is_array($data["free"] ?? null) || !is_array($data["pro"] ?? null) ) { return ""; } $clean = []; foreach ( [ "mode" => "key", "page_ids" => "ids", "delay" => "keys", "remove_scripts" => "keys", "remove_styles" => "keys", "preload_ids" => "ids", "schedule" => "key", ] as $k => $t ) { $clean[$k] = self::field($t, $data["pro"][$k] ?? ""); } $free = []; foreach ( [ "enabled" => "flag", "lazy" => "flag", "products" => "flag", "ttl" => "number", "hero" => "number", Core::EXCLUDED_PATHS => "paths", "defer" => "keys", ] as $k => $t ) { $free[$k] = self::field($t, $data["free"][$k] ?? ""); } return wp_json_encode([ "schema" => "ssfspeed-profile-v1", "free" => Core::sanitize($free), "pro" => $clean, ]); default: return sanitize_text_field($scalar); } } public static function handle(): void { if (!current_user_can("manage_options")) { wp_die("Administrator access required.", "", ["response" => 403]); } if (!isset($_SERVER["REQUEST_METHOD"]) || sanitize_key(wp_unslash($_SERVER["REQUEST_METHOD"])) !== "post") { wp_die("POST required.", "", ["response" => 405]); } $nonce = isset($_POST["_wpnonce"]) && is_string($_POST["_wpnonce"]) ? sanitize_text_field(wp_unslash($_POST["_wpnonce"])) : ""; if (!wp_verify_nonce($nonce, "ssfspeed_action")) { wp_die("Invalid or expired request.", "", ["response" => 403]); } $op = isset($_POST["op"]) && is_string($_POST["op"]) ? sanitize_key(wp_unslash($_POST["op"])) : ""; $tab = isset($_POST["tab"]) && is_string($_POST["tab"]) ? sanitize_key(wp_unslash($_POST["tab"])) : "overview"; $message = ""; switch ($op) { case "install": $message = Core::install(); break; case "settings": Core::save(self::fields("settings")); $message = "Settings saved; old cache invalidated."; break; case "purge": Core::purge(); $message = "All cache entries invalidated."; break; case "rollback": $message = Core::rollback(); break; case "disable": $s = Core::settings(); $s["enabled"] = false; Core::save($s, "Disable cache"); $message = "Cache disabled; saved settings retained."; break; case "inspect": set_transient( "ssfspeed_inspect_" . get_current_user_id(), Core::inspect(self::fields("inspect")["path"]), 600, ); $message = "Inspection ready."; break; case "export": self::download( [ "schema" => "ssfspeed-free-settings-v1", "version" => SSFSPEED_VERSION, "settings" => Core::settings(), "exported_at" => gmdate("c"), ], "ssf-speed-settings.json", ); break; default: $message = apply_filters( "ssfspeed_action_result", "Unknown action.", $op, self::fields($op), ); } set_transient("ssfspeed_notice_" . get_current_user_id(), $message, 90); wp_safe_redirect( admin_url( "admin.php?page=ssf-speed-cache&tab=" . rawurlencode( array_key_exists($tab, self::tabs()) ? $tab : "overview", ), ), ); exit(); } public static function download(array $data, string $filename): void { nocache_headers(); header("Content-Type: application/json; charset=utf-8"); header( 'Content-Disposition: attachment; filename="' . sanitize_file_name($filename) . '"', ); echo wp_json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); exit(); } public static function render(): void { if (!current_user_can("manage_options")) { return; } // This read-only navigation choice is allowlisted below; no action is performed. $tab = isset($_GET["tab"]) && is_string($_GET["tab"]) ? sanitize_key(wp_unslash($_GET["tab"])) : "overview"; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only tab selection. $tabs = self::tabs(); if (!isset($tabs[$tab])) { $tab = "overview"; } echo '

SMART SOLUTIONS FRAMEWORK / PERFORMANCE

SSF Speed Cache ' . esc_html(SSFSPEED_VERSION) . '

Faster public pages. Clear decisions. Changes you can reverse.

"; $notice = get_transient("ssfspeed_notice_" . get_current_user_id()); if ($notice) { echo '
' . esc_html($notice) . "
"; delete_transient("ssfspeed_notice_" . get_current_user_id()); } $s = Core::settings(); $conflict = Core::conflict(); if ($conflict) { echo '
Page caching is paused while this provider/configuration is present: ' . esc_html($conflict) . ". Keep one page-cache owner.
"; } if ($tab === "overview") { $c = Core::config(); echo '

PAGE CACHE

' . ($s["enabled"] && Core::ready() && !$conflict ? "Enabled" : "Not enabled") . "

Cookie-free public GET requests only. The first eligible visit builds a cache entry.

"; self::form("install", "overview"); self::button("Enable early page cache"); echo '

PUBLIC PATH INVENTORY

' . count($c["paths"] ?? []) . ' paths

Published posts and pages, indexed in batches. Product pages require explicit opt-in.

FRESHNESS

' . (int) $s["ttl"] . " seconds

Changes to content, theme, widgets or tracked shop settings invalidate cached pages.

"; self::form("purge", "overview"); self::button("Clear all cache"); echo '

Start with a real public-page check

  1. Back up and test on staging. Confirm your hosting does not already own page caching.
  2. Set define(\'WP_CACHE\', true); in wp-config.php if your host has not set it.
  3. Enable the cache, then visit a supported page twice in a browser without site cookies.
  4. Look for X-SSF-Speed-Cache: HIT on the second response. Interactive/token-bearing pages are deliberately bypassed.

No database credentials, server configuration or existing foreign drop-in files are overwritten. HTTPS reverse proxies must expose the correct scheme to WordPress.

'; } elseif ($tab === "settings") { echo "

Cache and media controls

"; self::form("settings", $tab); foreach ( [ "enabled" => "Enable page caching (owned drop-in and WP_CACHE must already be installed)", "lazy" => "Lazy-load content images after the first two, preserving explicit loading choices", "products" => "Include public WooCommerce products after reviewing personalized pricing and extensions", ] as $k => $label ) { echo '"; } echo '

Dependency-bearing, inline-data and protected scripts are skipped.

"; self::button("Save controls"); echo '

Click-to-load YouTube

Place [ssf_speed_video id="VIDEO_ID" title="Watch the demonstration"] in content. The local preview makes no YouTube request until clicked. The visitor then loads an external YouTube player.

'; } elseif ($tab === "diagnostics") { echo "

Why is a page cached—or bypassed?

Inspect a local path. The report assumes an anonymous request with no cookies.

"; self::form("inspect", $tab); echo ''; self::button("Inspect path"); echo ""; $r = get_transient("ssfspeed_inspect_" . get_current_user_id()); if ($r) { echo "
" .
                    esc_html(
                        wp_json_encode(
                            $r,
                            JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES,
                        ),
                    ) .
                    "
"; } echo "

Always bypassed

Cookies, authorization, query strings, non-GET methods, protected paths, private/draft/password pages, carts, checkout and accounts. Responses containing forms, tokens, private cache headers or unsupported variations are not stored.

Custom personalization must be excluded and tested by the site owner. This tool cannot certify every third-party extension.

"; } elseif ($tab === "recovery") { echo '

Restore settings

Restore the previous Free configuration and invalidate the cache.

'; self::form("rollback", $tab); self::button("Restore previous settings"); echo "

Disable caching

Retain configuration while stopping cache reads and writes.

"; self::form("disable", $tab); self::button("Disable cache"); echo "

Export settings

Download a configuration copy for your records.

"; self::form("export", $tab); self::button("Export JSON"); echo "

Recent changes

"; foreach ( array_reverse((array) get_option("ssfspeed_history", [])) as $row ) { echo ""; } echo "
UTC timeAction
" . esc_html($row["time"]) . "" . esc_html($row["action"]) . "
"; } else { do_action("ssfspeed_render_tab", $tab); } echo "
"; } }