Changeset 15124
- Timestamp:
- 09/02/2026 12:39:00 PM (2 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 2 added
- 1 edited
-
shortcodes/class-screenshots.php (modified) (6 diffs)
-
tests/Screenshots_Photon_Srcset_Test.php (added)
-
tests/fixtures/production-environment.php (added)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-screenshots.php
r15011 r15124 184 184 185 185 /** 186 * Adds preconnect / dns-prefetch hints to the Photon CDNhost on186 * Adds preconnect / dns-prefetch hints to the screenshot host on 187 187 * single-plugin pages so the browser can warm up the TLS handshake 188 * while the page HTML is still streaming. Saves ~50–150 ms on the 189 * first thumbnail paint for cold visitors. Hooked from 188 * while the page HTML is still streaming. Hooked from 190 189 * `class-plugin-directory.php` via the `wp_resource_hints` filter. 191 190 * … … 201 200 if ( 'preconnect' === $relation_type ) { 202 201 $urls[] = array( 203 'href' => 'https:// i0.wp.com',202 'href' => 'https://ps.w.org', 204 203 'crossorigin' => 'anonymous', 205 204 ); 206 205 } elseif ( 'dns-prefetch' === $relation_type ) { 207 $urls[] = 'https:// i0.wp.com';206 $urls[] = 'https://ps.w.org'; 208 207 } 209 208 … … 370 369 371 370 // Record the full-resolution source and intrinsic dimensions for the 372 // lightbox-state repair in fix_lightbox_metadata(). The grid thumbnail 373 // loads a Photon-shrunk srcset candidate, so core (which has no real 374 // attachment to query) would otherwise enlarge that small image; this 375 // hands the lightbox the lossless original at its true size. 371 // lightbox-state repair in fix_lightbox_metadata(). Core has no real 372 // attachment to query for these external assets, so this hands the 373 // lightbox the lossless original at its true size. 376 374 self::$lightbox_meta[ (int) $id ] = array( 377 375 'url' => $src, … … 451 449 * 452 450 * The empty `uploadedSrc` leaves the lightbox with no full-resolution 453 * image to enlarge, and the `'none'` dimensions make core's view 454 * script fall back to the *thumbnail's* natural size — which on 455 * production is a Photon-shrunk srcset candidate (≤900px, often the 456 * 300px tile). The enlarged view therefore renders tiny. On 457 * environments without Photon the thumbnail is the full-resolution 458 * original, which is why the bug is invisible on local / staging. 451 * image to enlarge, and the `'none'` dimensions leave core's view script 452 * without the source image's intrinsic size. 459 453 * 460 454 * Core keys its lightbox metadata by a per-render `uniqid()` (exposed … … 464 458 * merges with `array_replace_recursive()` (later call wins), and this 465 459 * filter runs at priority 20 — after core's priority-15 pass — so the 466 * corrected values override the broken ones. `lightboxSrcset` is 467 * cleared so the enlarged image loads the lossless original rather than 468 * a capped Photon candidate. 460 * corrected values override the broken ones. `lightboxSrcset` is cleared 461 * so the enlarged image loads the lossless original. 469 462 * 470 463 * @param string $block_content Rendered Image block markup. … … 558 551 559 552 /** 560 * Builds a revision-aware Photon `srcset` for a screenshot. 553 * Temporarily disables the Photon `srcset` for screenshots. 554 * 555 * Photon drops the revision query string when transform arguments are 556 * present, which can leave resized screenshots pinned to stale source data. 557 * 558 * @see https://meta.trac.wordpress.org/ticket/8331 559 * @see https://code.trac.wordpress.org/ticket/79#comment:1 561 560 * 562 561 * @param array $screenshot Screenshot metadata. 563 * @return string Attribute fragment ready to interpolate into `<img>`, 564 * including the leading space, or empty string. 562 * @return string Empty string while Photon resizing is disabled. 565 563 */ 566 564 protected static function photon_srcset( $screenshot ) { 567 $env = function_exists( 'wp_get_environment_type' ) ? wp_get_environment_type() : 'production'; 568 if ( 'production' !== $env && 'staging' !== $env ) { 569 return ''; 570 } 571 572 $source_url = Template::get_asset_url( null, $screenshot, false ); 573 $source_query = wp_parse_url( $source_url, PHP_URL_QUERY ); 574 $photon_base = str_replace( 'https://', 'https://i0.wp.com/', remove_query_arg( 'rev', $source_url ) ); 575 576 // Photon only forwards the source query string when it is passed through `q`. 577 $photon_base = add_query_arg( 'q', $source_query, $photon_base ); 578 $widths = array( 300, 600, 900 ); 579 $srcset = array(); 580 581 foreach ( $widths as $width ) { 582 $srcset[] = add_query_arg( 'w', $width, $photon_base ) . ' ' . $width . 'w'; 583 } 584 585 return sprintf( 586 ' srcset="%1$s" sizes="(max-width: 599px) 50vw, 33vw"', 587 esc_attr( implode( ', ', $srcset ) ) 588 ); 565 566 unset( $screenshot ); 567 568 return ''; 589 569 } 590 570
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)