Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a CDNise mu-plugin #430

Open
wants to merge 19 commits into
base: trunk
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update cdn-assets.php
  • Loading branch information
dd32 authored Aug 21, 2023
commit 472e76b41081c2b2901fd154a81f72dede2ef754
17 changes: 11 additions & 6 deletions mu-plugins/cdn/cdn-assets.php
Original file line number Diff line number Diff line change
@@ -27,21 +27,26 @@ function with_filemtime_cachebuster( $link, $handle = '' ) {
return $link;
}

// Profiles is hosted on BuddyPress, which is not available via the CDN.
if ( 'profiles.wordpress.org' === $hostname ) {
// Several sites are hosted on other Multisites, which are not available via this CDN.
$other_networks = [
'profiles.wordpress.org',
'events.wordpress.org',
];
if ( in_array( $hostname, $other_networks, true ) {
return $link;
}

$url_args = [];
// Trim the scheme & hostname off.
$relative_url = preg_replace( '!^(\w+:)?//[^/]+/!', '', $link );
// Trim any sub-site path off.

// Trim any sub-site path off - We only use single-depth on WordPress.org at present.
$relative_url = preg_replace( '!^[^/]+/(wp-(?:content|includes|admin)/)!', '$1', $relative_url );

if ( str_contains( $relative_url, '?' ) ) {
list( $filepath, $url_part_args ) = explode( '?', $relative_url, 2 );

parse_str( $url_part_args, $url_args );
wp_parse_str( $url_part_args, $url_args );
} else {
$filepath = $relative_url;
// No `$url_args` here.
@@ -62,7 +67,7 @@ function with_filemtime_cachebuster( $link, $handle = '' ) {

// Set the version to the file modification time, for consistency.
$version = false;
if ( ! is_timestamp( $url_args['ver'] ) ) {
if ( ! is_timestamp( $url_args['ver'] ) && file_exists( ABSPATH . $filepath ) ) {
$version = filemtime( ABSPATH . $filepath );
}
if ( ! $version ) {
@@ -115,4 +120,4 @@ function is_timestamp( $string ) {
$string >= 1262304000 /* Y2.01K - 2010-01-01 */ &&
$string <= time()
);
}
}