Making WordPress.org


Ignore:
Timestamp:
02/07/2024 06:09:45 AM (2 years ago)
Author:
dd32
Message:

Trac: Use assets from the W.org CDN, to avoid CORS issues.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/trac.wordpress.org/templates/update-headers.php

    r13182 r13183  
    8080
    8181            return $prefix_id . $m['suffix'];
     82        },
     83        $html
     84    );
     85
     86    /*
     87     * Use CDN assets, to avoid CORS issues.
     88     * Until https://github.com/WordPress/wporg-mu-plugins/pull/430 is resolved.
     89     */
     90    $html = preg_replace_callback(
     91        '!(?P<url>https://wordpress.org/wp-(includes|content)/[^\'"]+)!i',
     92        function( $m ) {
     93            $url  = str_replace( 'https://wordpress.org/', 'https://s.w.org/', $m['url'] );
     94            $hash = md5( file_get_contents( $m['url'] ) );
     95
     96            if ( preg_match( '/([?&](ver)=[^&]+)/i', $url, $m ) ) {
     97                $url = str_replace( $m[0], $m[0] . '-' . $hash, $url );
     98            } else {
     99                $url .= ( str_contains( $url, '?' ) ? '&' : '?' ) . 'ver=' . $hash;
     100            }
     101
     102            return $url;
    82103        },
    83104        $html
Note: See TracChangeset for help on using the changeset viewer.