Making WordPress.org


Ignore:
Timestamp:
12/04/2017 06:04:49 PM (7 years ago)
Author:
obenland
Message:

Plugins: Use CDN to deliver directory assets.

See [6230].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/functions.php

    r6231 r6233  
    6060function scripts() {
    6161    $suffix = is_rtl() ? '-rtl' : '';
    62     wp_enqueue_style( 'wporg-plugins-style', get_template_directory_uri() . "/css/style{$suffix}.css", array(), '20171124' );
     62    wp_enqueue_style( 'wporg-plugins-style', get_template_directory_uri() . "/css/style{$suffix}.css", ['open-sans'], '20171124' );
    6363
    6464    wp_enqueue_script( 'wporg-plugins-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
     
    115115    }
    116116
     117    // No Jetpack scripts needed.
     118    add_filter( 'jetpack_implode_frontend_css', '__return_false' );
     119    wp_dequeue_script( 'devicepx' );
    117120}
    118121add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\scripts' );
     122
     123/**
     124 * Filters an enqueued script & style's fully-qualified URL.
     125 *
     126 * @param string $src    The source URL of the enqueued script/style.
     127 * @param string $handle The style's registered handle.
     128 * @return string
     129 */
     130function loader_src( $src, $handle ) {
     131    $cdn_urls = [
     132        'dashicons',
     133        'wp-embed',
     134    //  'wporg-plugins-style',
     135        'wporg-plugins-navigation',
     136        'wporg-plugins-skip-link-focus-fix',
     137        'wporg-plugins-popover',
     138        'wporg-plugins-locale-banner',
     139        'wporg-plugins-stats',
     140        'wporg-plugins-client',
     141    ];
     142
     143    // Use CDN url.
     144    if ( in_array( $handle, $cdn_urls, true ) ) {
     145        $src = str_replace( get_home_url(), 'https://s.w.org', $src );
     146    }
     147
     148    // Remove version argument.
     149    if ( in_array( $handle, ['open-sans'], true ) ) {
     150        $src = remove_query_arg( 'ver', $src );
     151    }
     152
     153    return $src;
     154}
     155add_filter( 'style_loader_src',  __NAMESPACE__ . '\loader_src', 10, 2 );
     156add_filter( 'script_loader_src', __NAMESPACE__ . '\loader_src', 10, 2 );
    119157
    120158/**
Note: See TracChangeset for help on using the changeset viewer.