Making WordPress.org


Ignore:
Timestamp:
01/13/2017 08:13:14 AM (8 years ago)
Author:
dd32
Message:

Plugin Directory: Use the Jetpack photon CDN function rather than rolling our own; don't fetch banner assets through the CDN during plugin imports.

File:
1 edited

Legend:

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

    r4622 r4657  
    363363     * @param int|\WP_Post|null $post  Optional. Post ID or post object. Defaults to global $post.
    364364     * @param array             $asset Assets folder information.
     365     * @param bool              $cdn   Optional. If the url should be CDN'ised. Default true.
    365366     * @return string
    366367     */
    367     public static function get_asset_url( $post, $asset ) {
     368    public static function get_asset_url( $post, $asset, $cdn = true ) {
    368369        if ( ! empty( $asset['location'] ) && 'plugin' == $asset['location'] ) {
    369370
    370371            // Screenshots in the plugin folder - /plugins/plugin-name/screenshot-1.png.
    371             $format = 'https://i0.wp.com/plugins.svn.wordpress.org/!svn/bc/%1$s/%2$s/trunk/%3$s?strip=all';
     372            $format = 'https://plugins.svn.wordpress.org/!svn/bc/%1$s/%2$s/trunk/%3$s';
    372373        } else {
    373374
    374375            // Images in the assets folder - /plugin-name/assets/screenshot-1.png.
    375             $format = 'https://i0.wp.com/plugins.svn.wordpress.org/!svn/bc/%1$s/%2$s/assets/%3$s?strip=all';
     376            $format = 'https://plugins.svn.wordpress.org/!svn/bc/%1$s/%2$s/assets/%3$s';
    376377        }
    377378
    378379        // Photon does not support SVG files. https://github.com/Automattic/jetpack/issues/81
    379380        if ( strpos( $asset['filename'], '.svg' ) ) {
    380             $format = str_replace( 'i0.wp.com/', '', $format );
    381         }
    382 
    383         return esc_url( sprintf(
     381            $cdn = false;
     382        }
     383
     384        $url = sprintf(
    384385            $format,
    385386            $asset['revision'],
    386387            get_post( $post )->post_name,
    387388            $asset['filename']
    388         ) );
     389        );
     390
     391        // Use Jetpacks Photon CDN when available.
     392        if ( $cdn && function_exists( 'jetpack_photon_url' ) ) {
     393            $url = jetpack_photon_url( $url, array( 'strip' => 'all' ) );
     394        }
     395
     396        return esc_url( $url );
    389397    }
    390398
Note: See TracChangeset for help on using the changeset viewer.