PluginProbe
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN / 1.3.7
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN v1.3.7
1.3.7 1.3.6 1.3.5 1.3.4 1.3.3 1.3.2 1.3.1 1.3.0 1.2.4 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 All 33 releases
← All changes | includes/modules/Fonts/FontsModule.php +45 -15 1.2.4 → 1.3.7 View file →
@@ -31,11 +31,12 @@
31 31 public const VERSION = '1.0.0';
32 32
33 33 public function ui_metadata(): array {
34 34 return array(
35 - 'label' => 'Fonts',
35 + 'label' => __( 'Fonts', 'xspeed' ),
36 36 'icon' => 'Type',
37 - 'description' => 'Stop web fonts from blocking text. Adds display=swap to Google Fonts and preloads the fonts you mark critical.',
37 + 'description' => __( 'Shows text right away while web fonts load, and preloads key fonts.', 'xspeed' ),
38 + 'group' => 'performance',
38 39 );
39 40 }
40 41
41 42 public function settings_schema(): array {
@@ -42,22 +43,41 @@
42 43 return array(
43 44 'font_display_swap' => array(
44 45 'type' => 'bool',
45 46 'default' => true,
46 - 'label' => 'Add font-display: swap',
47 - 'description' => 'Append display=swap to Google Fonts URLs so text renders immediately in a fallback face while the web font loads. No effect on URLs that already declare a display value.',
47 + 'label' => __( 'Show text while fonts load', 'xspeed' ),
48 + 'description' => __( 'Google Fonts text shows at once in a standard font, then switches when the web font arrives.', 'xspeed' ),
48 49 ),
49 50 'preload_fonts' => array(
50 51 'type' => 'list',
51 52 'default' => array(),
52 53 'item_type' => 'url',
53 - 'label' => 'Preload Font URLs',
54 - 'description' => 'One absolute font URL per line (woff2/woff/ttf/otf). Each becomes a <link rel="preload" as="font" crossorigin> in the head so the browser starts downloading before the CSS parses. Use only for fonts that render above the fold.',
54 + 'label' => __( 'Fonts to preload', 'xspeed' ),
55 + 'description' => __( 'One full font file URL per line (woff2, woff, ttf or otf). The browser fetches these first, so list only fonts used at the top of the page.', 'xspeed' ),
55 56 ),
56 57 );
57 58 }
58 59
59 60 public function boot(): void {
61 + /*
62 + * Deferred to `init`. This module reads its own settings to decide
63 + * what to hook, and reading settings builds settings_schema(), whose
64 + * labels are declared through __(). boot() runs on `plugins_loaded`,
65 + * before `after_setup_theme` — the point WordPress 6.7+ treats as the
66 + * earliest safe moment to translate — so doing that here fires
67 + * _load_textdomain_just_in_time on every request AND resolves the
68 + * labels against a domain that is not loaded yet.
69 + *
70 + * Everything below hooks actions that fire after `init`, so running
71 + * one hook later is equivalent.
72 + */
73 + add_action( 'init', array( $this, 'boot_on_init' ) );
74 + }
75 +
76 + /**
77 + * The real boot body — see boot() for why it runs on `init`.
78 + */
79 + public function boot_on_init(): void {
60 80 // Frontend-only rewriting. Admin / cron / AJAX / REST never
61 81 // render <link rel="stylesheet"> tags we should touch.
62 82 if ( is_admin()
63 83 || ( defined( 'DOING_AJAX' ) && DOING_AJAX )
@@ -109,18 +129,28 @@
109 129 }
110 130
111 131 $href = $m[2];
112 132
113 - // Already has a display param — leave it alone (respect the theme /
114 - // plugin that set it). The href here has been through esc_url(),
115 - // which encodes "&" as the entity "&#038;", so a real URL like
116 - // ...?family=Roboto&display=optional arrives as
117 - // ...?family=Roboto&#038;display=optional — the char before
118 - // "display=" is then ";" (tail of the entity), not "&", and the old
119 - // [?&]display= guard missed it, double-appending a second display.
120 - // Decode entities before the check so it matches either form.
121 - // (FBS-82161)
133 + // A display param the theme set is respected ONLY when it is one of
134 + // the non-blocking choices (swap / fallback / optional) — someone
135 + // picked those deliberately and each is a defensible trade. `auto`
136 + // and `block` are the values this setting exists to remove: `auto`
137 + // IS block behavior in every engine, and it is almost never a
138 + // choice — it is the default a theme's enqueue happened to emit.
139 + // "Respecting" it turned the switch into a no-op on exactly the
140 + // sites that need it: a live text-LCP measured a 5.5s render delay
141 + // behind flatsome's `display=auto` Poppins URL while this option
142 + // was on and its label promised the opposite. WP Rocket and
143 + // LiteSpeed rewrite these too. The href here has been through
144 + // esc_url(), which encodes "&" as "&#038;" — decode before
145 + // matching, rewrite on the ORIGINAL encoded href so str_replace
146 + // finds it in the tag verbatim. (FBS-82161)
122 147 $href_decoded = html_entity_decode( $href, ENT_QUOTES | ENT_HTML5 );
148 + if ( preg_match( '/([?&])display=(auto|block)(&|$)/i', $href_decoded ) ) {
149 + $new_href = preg_replace( '/((?:[?&]|&#0*38;|&#[xX]0*26;|&amp;)display=)(?:auto|block)(?=&|$)/i', '$1swap', $href );
150 +
151 + return str_replace( $href, $new_href, $tag );
152 + }
123 153 if ( preg_match( '/[?&]display=/i', $href_decoded ) ) {
124 154 return $tag;
125 155 }
126 156