Making WordPress.org

Changeset 15124


Ignore:
Timestamp:
09/02/2026 12:39:00 PM (2 months ago)
Author:
bor0
Message:

Plugin Directory: Temporarily disable Photon screenshot srcset in Plugin Directory

Props alexodiy, bor0, obenland, medavidallsop.
Closes ​https://github.com/WordPress/wordpress.org/pull/859.
Fixes #8331.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-screenshots.php

    r15011 r15124  
    184184
    185185        /**
    186          * Adds preconnect / dns-prefetch hints to the Photon CDN host on
     186         * Adds preconnect / dns-prefetch hints to the screenshot host on
    187187         * 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
    190189         * `class-plugin-directory.php` via the `wp_resource_hints` filter.
    191190         *
    … …  
    201200                if ( 'preconnect' === $relation_type ) {
    202201                        $urls[] = array(
    203                                 'href'        => 'https://i0.wp.com',
     202                                'href'        => 'https://ps.w.org',
    204203                                'crossorigin' => 'anonymous',
    205204                        );
    206205                } elseif ( 'dns-prefetch' === $relation_type ) {
    207                         $urls[] = 'https://i0.wp.com';
     206                        $urls[] = 'https://ps.w.org';
    208207                }
    209208
    … …  
    370369
    371370                // 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.
    376374                self::$lightbox_meta[ (int) $id ] = array(
    377375                        'url'    => $src,
    … …  
    451449         *
    452450         * 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.
    459453         *
    460454         * Core keys its lightbox metadata by a per-render `uniqid()` (exposed
    … …  
    464458         * merges with `array_replace_recursive()` (later call wins), and this
    465459         * 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.
    469462         *
    470463         * @param string $block_content Rendered Image block markup.
    … …  
    558551
    559552        /**
    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
    561560         *
    562561         * @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.
    565563         */
    566564        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 '';
    589569        }
    590570
Note: See TracChangeset for help on using the changeset viewer.