| @@ -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', |
| @@ -44,10 +44,10 @@ | ||
| 44 | 44 | return array( |
| 45 | 45 | 'enabled' => array( |
| 46 | 46 | 'type' => 'bool', |
| 47 | 47 | 'default' => false, |
| 48 | - 'label' => 'Enable Preloader', | |
| 49 | - 'description' => 'When on, xSpeed crawls the sitemap on the schedule below and warms the page cache.', | |
| 48 | + 'label' => __( 'Enable Preloader', 'xspeed' ), | |
| 49 | + 'description' => __( 'When on, xSpeed crawls the sitemap on the schedule below and warms the page cache.', 'xspeed' ), | |
| 50 | 50 | ), |
| 51 | 51 | 'schedule' => array( |
| 52 | 52 | 'type' => 'enum', |
| 53 | 53 | 'default' => 'manual', |
| @@ -57,10 +57,11 @@ | ||
| 57 | 57 | 'hourly' => 'Hourly', |
| 58 | 58 | 'daily' => 'Daily', |
| 59 | 59 | 'weekly' => 'Weekly', |
| 60 | 60 | ), |
| 61 | - 'label' => 'Schedule', | |
| 62 | - 'description' => 'How often to start a fresh crawl. Manual means you trigger it from the dashboard.', | |
| 61 | + 'label' => __( 'Schedule', 'xspeed' ), | |
| 62 | + 'description' => __( 'How often to start a fresh crawl. Manual means you trigger it from the dashboard.', 'xspeed' ), | |
| 63 | + 'dependsOn' => array( 'field' => 'enabled' ), | |
| 63 | 64 | ), |
| 64 | 65 | 'batch_size' => array( |
| 65 | 66 | 'type' => 'int', |
| 66 | 67 | 'default' => 5, |
| @@ -65,28 +66,32 @@ | ||
| 65 | 66 | 'type' => 'int', |
| 66 | 67 | 'default' => 5, |
| 67 | 68 | 'min' => 1, |
| 68 | 69 | 'max' => 50, |
| 69 | - 'label' => 'Batch Size', | |
| 70 | - 'description' => 'URLs warmed per cron tick. Higher = faster crawl, more load on the origin.', | |
| 70 | + 'label' => __( 'Batch Size', 'xspeed' ), | |
| 71 | + 'description' => __( 'URLs warmed per cron tick. Higher = faster crawl, more load on the origin.', 'xspeed' ), | |
| 72 | + 'dependsOn' => array( 'field' => 'enabled' ), | |
| 71 | 73 | ), |
| 72 | 74 | 'sitemap_url' => array( |
| 73 | 75 | 'type' => 'string', |
| 74 | 76 | 'default' => '', |
| 75 | - 'label' => 'Sitemap URL (optional)', | |
| 76 | - 'description' => 'Override the auto-detected WordPress core sitemap (/wp-sitemap.xml). Leave blank for default.', | |
| 77 | + 'label' => __( 'Sitemap URL (optional)', 'xspeed' ), | |
| 78 | + 'description' => __( 'Override the auto-detected WordPress core sitemap (/wp-sitemap.xml). Leave blank for default.', 'xspeed' ), | |
| 79 | + 'dependsOn' => array( 'field' => 'enabled' ), | |
| 77 | 80 | ), |
| 78 | 81 | 'warm_on_publish' => array( |
| 79 | 82 | 'type' => 'bool', |
| 80 | 83 | 'default' => true, |
| 81 | - 'label' => 'Warm new content immediately', | |
| 82 | - 'description' => 'When a post or page is published, fetch it once so the first visitor sees a cache HIT, not a cold MISS.', | |
| 84 | + 'label' => __( 'Warm new content immediately', 'xspeed' ), | |
| 85 | + '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 | + 'dependsOn' => array( 'field' => 'enabled' ), | |
| 83 | 87 | ), |
| 84 | 88 | 'warm_on_comment' => array( |
| 85 | 89 | 'type' => 'bool', |
| 86 | 90 | 'default' => false, |
| 87 | - 'label' => 'Re-warm after comments', | |
| 88 | - 'description' => 'Re-warm a page after a comment is posted (Cache purges the page on comment; this fetches it back into cache).', | |
| 91 | + 'label' => __( 'Re-warm after comments', 'xspeed' ), | |
| 92 | + 'description' => __( 'Re-warm a page after a comment is posted (Cache purges the page on comment; this fetches it back into cache).', 'xspeed' ), | |
| 93 | + 'dependsOn' => array( 'field' => 'enabled' ), | |
| 89 | 94 | ), |
| 90 | 95 | ); |
| 91 | 96 | } |
| 92 | 97 | |
| @@ -121,8 +126,9 @@ | ||
| 121 | 126 | array( |
| 122 | 127 | 'name' => 'xspeed preloader', |
| 123 | 128 | 'callback' => array( $this, 'cli_handler' ), |
| 124 | 129 | 'shortdesc' => 'Drive the cache preloader (start | stop | status).', |
| 130 | + 'ai_hint' => 'Cache warming: crawl the site so visitors hit a warm cache instead of paying for the first render. Use after a full purge, or when the first visitor to each page reports a slow load.', | |
| 125 | 131 | 'synopsis' => array( |
| 126 | 132 | array( |
| 127 | 133 | 'type' => 'positional', |
| 128 | 134 | 'name' => 'action', |
| @@ -134,8 +140,27 @@ | ||
| 134 | 140 | ); |
| 135 | 141 | } |
| 136 | 142 | |
| 137 | 143 | public function boot(): void { |
| 144 | + /* | |
| 145 | + * Deferred to `init`. This module reads its own settings to decide | |
| 146 | + * what to hook, and reading settings builds settings_schema(), whose | |
| 147 | + * labels are declared through __(). boot() runs on `plugins_loaded`, | |
| 148 | + * before `after_setup_theme` — the point WordPress 6.7+ treats as the | |
| 149 | + * earliest safe moment to translate — so doing that here fires | |
| 150 | + * _load_textdomain_just_in_time on every request AND resolves the | |
| 151 | + * labels against a domain that is not loaded yet. | |
| 152 | + * | |
| 153 | + * Everything below hooks actions that fire after `init`, so running | |
| 154 | + * one hook later is equivalent. | |
| 155 | + */ | |
| 156 | + add_action( 'init', array( $this, 'boot_on_init' ) ); | |
| 157 | + } | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * The real boot body — see boot() for why it runs on `init`. | |
| 161 | + */ | |
| 162 | + public function boot_on_init(): void { | |
| 138 | 163 | add_action( Preloader::CRON_HOOK, array( Preloader::class, 'tick' ) ); |
| 139 | 164 | add_action( 'xspeed_preloader_recurring', array( Preloader::class, 'recurring_kickoff' ) ); |
| 140 | 165 | |
| 141 | 166 | // Apply schedule changes immediately whenever this module's |