'Browser Cache', 'icon' => 'Clock', 'description' => 'Tell browsers (and intermediate CDNs) how long to cache static assets and HTML.', ); } public function settings_schema(): array { return array( 'enabled' => array( 'type' => 'bool', 'default' => false, 'label' => 'Enable browser cache headers', 'description' => 'On Apache/LiteSpeed this writes Cache-Control + Expires rules into .htaccess. On nginx it just stores the settings — you paste the snippet into your server block manually.', ), 'asset_ttl' => array( 'type' => 'int', 'default' => Browser_Cache::DEFAULT_ASSET_TTL, 'min' => 0, 'max' => 31536000, 'label' => 'Static asset TTL (seconds)', 'description' => 'Cache lifetime for CSS, JS, fonts, images. Defaults to 1 year + immutable (the industry-standard "fingerprinted assets never change" pattern).', ), 'html_ttl' => array( 'type' => 'int', 'default' => Browser_Cache::DEFAULT_HTML_TTL, 'min' => 0, 'max' => 31536000, 'label' => 'HTML TTL (seconds)', 'description' => 'Cache lifetime for the HTML document itself. Keep short (default 1h) so post edits roll out same-day.', ), ); } public function boot(): void { add_action( 'update_option_xspeed_module_browser-cache', array( $this, 'on_settings_change' ), 10, 2 ); add_action( 'add_option_xspeed_module_browser-cache', array( $this, 'on_settings_added' ), 10, 2 ); } public function on_settings_change( $old, $new ): void { if ( ! is_array( $new ) ) { return; } Browser_Cache::apply( ! empty( $new['enabled'] ), $new ); } public function on_settings_added( $name, $value ): void { if ( ! is_array( $value ) ) { return; } Browser_Cache::apply( ! empty( $value['enabled'] ), $value ); } public function ui_notices(): array { if ( class_exists( '\\XSpeed\\Server' ) && ! Server::supports_htaccess() ) { return array( array( 'tone' => 'info', 'title' => 'Manual nginx config required', 'body' => "Your server doesn't support .htaccess. After saving, copy the nginx snippet below into your server block.\n\n" . Browser_Cache::nginx_snippet( $this->get_settings() ), ), ); } return array(); } public function deactivate(): void { Browser_Cache::apply( false ); } public function cli_commands(): array { return array( array( 'name' => 'xspeed browser-cache', 'callback' => array( $this, 'cli_handler' ), 'shortdesc' => 'Print the Apache or nginx browser-cache snippet.', 'synopsis' => array( array( 'type' => 'positional', 'name' => 'flavor', 'options' => array( 'apache', 'nginx' ), 'optional' => true, ), ), ), ); } public function cli_handler( array $args, array $assoc ): void { $flavor = $args[0] ?? 'apache'; $opts = $this->get_settings(); if ( 'nginx' === $flavor ) { \WP_CLI::log( Browser_Cache::nginx_snippet( $opts ) ); return; } foreach ( Browser_Cache::apache_rules( $opts ) as $line ) { \WP_CLI::log( $line ); } } }