| @@ -28,12 +28,12 @@ | ||
| 28 | 28 | public const VERSION = '1.0.0'; |
| 29 | 29 | |
| 30 | 30 | public function ui_metadata(): array { |
| 31 | 31 | return array( |
| 32 | - 'label' => 'Preloader', | |
| 33 | - 'tab_label' => 'Crawl Now', // its own tab on the Preloader page | |
| 32 | + 'label' => __( 'Preloader', 'xspeed' ), | |
| 33 | + 'tab_label' => __( 'Crawl Now', 'xspeed' ), // its own tab on the Preloader page | |
| 34 | 34 | 'icon' => 'Wand2', |
| 35 | - 'description' => 'Crawl the sitemap to warm cache so visitors never hit a cold MISS.', | |
| 35 | + 'description' => __( 'Crawl the sitemap to warm cache so visitors never hit a cold MISS.', 'xspeed' ), | |
| 36 | 36 | // Custom panel wraps the schema-driven settings with a |
| 37 | 37 | // Start/Stop control surface + a live status readout |
| 38 | 38 | // (queue depth, last URL, recent errors). |
| 39 | 39 | 'custom_panel' => 'PreloaderHost', |
| @@ -39,15 +39,44 @@ | ||
| 39 | 39 | 'custom_panel' => 'PreloaderHost', |
| 40 | 40 | ); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | + /** | |
| 44 | + * Surface a firewall refusing our warmer. | |
| 45 | + * | |
| 46 | + * A 403/406 on a warm used to reach the admin only as "HTTP 403" buried | |
| 47 | + * in the activity log, so a site whose every warm was refused looked | |
| 48 | + * simply idle — newly published posts were never warmed and nothing said | |
| 49 | + * why. The page is fine; the fix is a server rule, so the notice names | |
| 50 | + * the user-agent to allow. (#481) | |
| 51 | + */ | |
| 52 | + public function ui_notices(): array { | |
| 53 | + $block = Preloader::firewall_block(); | |
| 54 | + if ( null === $block ) { | |
| 55 | + return array(); | |
| 56 | + } | |
| 57 | + | |
| 58 | + return array( | |
| 59 | + array( | |
| 60 | + 'tone' => 'warn', | |
| 61 | + 'title' => __( 'Your server is blocking the xSpeed cache warmer', 'xspeed' ), | |
| 62 | + 'body' => sprintf( | |
| 63 | + /* translators: 1: HTTP status code, 2: the user-agent xSpeed sends. */ | |
| 64 | + __( 'A warm request was refused with HTTP %1$d, which is how a firewall answers when it judges a request by its user-agent. Pages are not being warmed, so the first visitor to each new page waits for an uncached render. Allow the user-agent "%2$s" in your server\'s bad-bot rules — on xCloud this is the 8G firewall — or change it with the xspeed_preloader_user_agent filter. This notice clears itself once a warm gets through.', 'xspeed' ), | |
| 65 | + (int) $block['code'], | |
| 66 | + (string) ( $block['user_agent'] ?? Preloader::user_agent() ) | |
| 67 | + ), | |
| 68 | + ), | |
| 69 | + ); | |
| 70 | + } | |
| 71 | + | |
| 43 | 72 | public function settings_schema(): array { |
| 44 | 73 | return array( |
| 45 | 74 | 'enabled' => array( |
| 46 | 75 | 'type' => 'bool', |
| 47 | 76 | 'default' => false, |
| 48 | - 'label' => 'Enable Preloader', | |
| 49 | - 'description' => 'When on, xSpeed crawls the sitemap on the schedule below and warms the page cache.', | |
| 77 | + 'label' => __( 'Enable Preloader', 'xspeed' ), | |
| 78 | + 'description' => __( 'When on, xSpeed crawls the sitemap on the schedule below and warms the page cache.', 'xspeed' ), | |
| 50 | 79 | ), |
| 51 | 80 | 'schedule' => array( |
| 52 | 81 | 'type' => 'enum', |
| 53 | 82 | 'default' => 'manual', |
| @@ -57,10 +86,10 @@ | ||
| 57 | 86 | 'hourly' => 'Hourly', |
| 58 | 87 | 'daily' => 'Daily', |
| 59 | 88 | 'weekly' => 'Weekly', |
| 60 | 89 | ), |
| 61 | - 'label' => 'Schedule', | |
| 62 | - 'description' => 'How often to start a fresh crawl. Manual means you trigger it from the dashboard.', | |
| 90 | + 'label' => __( 'Schedule', 'xspeed' ), | |
| 91 | + 'description' => __( 'How often to start a fresh crawl. Manual means you trigger it from the dashboard.', 'xspeed' ), | |
| 63 | 92 | 'dependsOn' => array( 'field' => 'enabled' ), |
| 64 | 93 | ), |
| 65 | 94 | 'batch_size' => array( |
| 66 | 95 | 'type' => 'int', |
| @@ -66,31 +95,31 @@ | ||
| 66 | 95 | 'type' => 'int', |
| 67 | 96 | 'default' => 5, |
| 68 | 97 | 'min' => 1, |
| 69 | 98 | 'max' => 50, |
| 70 | - 'label' => 'Batch Size', | |
| 71 | - 'description' => 'URLs warmed per cron tick. Higher = faster crawl, more load on the origin.', | |
| 99 | + 'label' => __( 'Batch Size', 'xspeed' ), | |
| 100 | + 'description' => __( 'URLs warmed per cron tick. Higher = faster crawl, more load on the origin.', 'xspeed' ), | |
| 72 | 101 | 'dependsOn' => array( 'field' => 'enabled' ), |
| 73 | 102 | ), |
| 74 | 103 | 'sitemap_url' => array( |
| 75 | 104 | 'type' => 'string', |
| 76 | 105 | 'default' => '', |
| 77 | - 'label' => 'Sitemap URL (optional)', | |
| 78 | - 'description' => 'Override the auto-detected WordPress core sitemap (/wp-sitemap.xml). Leave blank for default.', | |
| 106 | + 'label' => __( 'Sitemap URL (optional)', 'xspeed' ), | |
| 107 | + 'description' => __( 'Override the auto-detected WordPress core sitemap (/wp-sitemap.xml). Leave blank for default.', 'xspeed' ), | |
| 79 | 108 | 'dependsOn' => array( 'field' => 'enabled' ), |
| 80 | 109 | ), |
| 81 | 110 | 'warm_on_publish' => array( |
| 82 | 111 | 'type' => 'bool', |
| 83 | 112 | 'default' => true, |
| 84 | - 'label' => 'Warm new content immediately', | |
| 85 | - 'description' => 'When a post or page is published, fetch it once so the first visitor sees a cache HIT, not a cold MISS.', | |
| 113 | + 'label' => __( 'Warm new content immediately', 'xspeed' ), | |
| 114 | + 'description' => __( 'When a post or page is published, fetch it once so the first visitor sees a cache HIT, not a cold MISS.', 'xspeed' ), | |
| 86 | 115 | 'dependsOn' => array( 'field' => 'enabled' ), |
| 87 | 116 | ), |
| 88 | 117 | 'warm_on_comment' => array( |
| 89 | 118 | 'type' => 'bool', |
| 90 | 119 | 'default' => false, |
| 91 | - 'label' => 'Re-warm after comments', | |
| 92 | - 'description' => 'Re-warm a page after a comment is posted (Cache purges the page on comment; this fetches it back into cache).', | |
| 120 | + 'label' => __( 'Re-warm after comments', 'xspeed' ), | |
| 121 | + 'description' => __( 'Re-warm a page after a comment is posted (Cache purges the page on comment; this fetches it back into cache).', 'xspeed' ), | |
| 93 | 122 | 'dependsOn' => array( 'field' => 'enabled' ), |
| 94 | 123 | ), |
| 95 | 124 | ); |
| 96 | 125 | } |
| @@ -140,8 +169,27 @@ | ||
| 140 | 169 | ); |
| 141 | 170 | } |
| 142 | 171 | |
| 143 | 172 | public function boot(): void { |
| 173 | + /* | |
| 174 | + * Deferred to `init`. This module reads its own settings to decide | |
| 175 | + * what to hook, and reading settings builds settings_schema(), whose | |
| 176 | + * labels are declared through __(). boot() runs on `plugins_loaded`, | |
| 177 | + * before `after_setup_theme` — the point WordPress 6.7+ treats as the | |
| 178 | + * earliest safe moment to translate — so doing that here fires | |
| 179 | + * _load_textdomain_just_in_time on every request AND resolves the | |
| 180 | + * labels against a domain that is not loaded yet. | |
| 181 | + * | |
| 182 | + * Everything below hooks actions that fire after `init`, so running | |
| 183 | + * one hook later is equivalent. | |
| 184 | + */ | |
| 185 | + add_action( 'init', array( $this, 'boot_on_init' ) ); | |
| 186 | + } | |
| 187 | + | |
| 188 | + /** | |
| 189 | + * The real boot body — see boot() for why it runs on `init`. | |
| 190 | + */ | |
| 191 | + public function boot_on_init(): void { | |
| 144 | 192 | add_action( Preloader::CRON_HOOK, array( Preloader::class, 'tick' ) ); |
| 145 | 193 | add_action( 'xspeed_preloader_recurring', array( Preloader::class, 'recurring_kickoff' ) ); |
| 146 | 194 | |
| 147 | 195 | // Apply schedule changes immediately whenever this module's |