← All changes
|
includes/modules/ResourceHints/ResourceHintsModule.php
+25
-0
1.3.7
→
1.4.0
View file →
| @@ -240,9 +240,34 @@ | ||
| 240 | 240 | if ( is_array( $lazy ) && ! empty( $lazy['lazy_images'] ) && ! empty( $lazy['excluded_images'] ) && is_array( $lazy['excluded_images'] ) ) { |
| 241 | 241 | $opts['eager_excluded_images'] = array_values( array_filter( array_map( 'strval', $lazy['excluded_images'] ) ) ); |
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | + $opts['page_url'] = self::current_page_url(); | |
| 244 | 245 | return $opts; |
| 246 | + } | |
| 247 | + | |
| 248 | + /** | |
| 249 | + * The URL of the page being served, for the LCP preload candidate seam. | |
| 250 | + * Empty outside a request (CLI, tests). | |
| 251 | + * | |
| 252 | + * The site's scheme and host with the request path as the browser sent | |
| 253 | + * it. Not home_url( REQUEST_URI ): on a site in a subfolder both carry the | |
| 254 | + * folder, which then appeared twice. And not sanitize_text_field(), which | |
| 255 | + * drops percent-encoded octets, so `/caf%C3%A9/` lost its é. | |
| 256 | + */ | |
| 257 | + private static function current_page_url(): string { | |
| 258 | + if ( ! isset( $_SERVER['REQUEST_URI'] ) || ! function_exists( 'home_url' ) ) { | |
| 259 | + return ''; | |
| 260 | + } | |
| 261 | + $uri = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ); | |
| 262 | + if ( '' === $uri || '/' !== $uri[0] ) { | |
| 263 | + return ''; | |
| 264 | + } | |
| 265 | + $home = wp_parse_url( home_url( '/' ) ); | |
| 266 | + $scheme = isset( $home['scheme'] ) ? $home['scheme'] : 'https'; | |
| 267 | + $host = isset( $home['host'] ) ? $home['host'] : ''; | |
| 268 | + $port = isset( $home['port'] ) ? ':' . $home['port'] : ''; | |
| 269 | + return '' === $host ? '' : $scheme . '://' . $host . $port . $uri; | |
| 245 | 270 | } |
| 246 | 271 | |
| 247 | 272 | public function cli_commands(): array { |
| 248 | 273 | return array( |