Making WordPress.org

Changeset 4657


Ignore:
Timestamp:
01/13/2017 08:13:14 AM (10 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.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 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
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r4622 r4657  
    183183                if ( $first_banner = reset( $assets['banner'] ) ) {
    184184                        // The Banners are not stored locally, which is why a URL is used here
    185                         $banner_average_color = Tools::get_image_average_color( Template::get_asset_url( $plugin, $first_banner ) );
     185                        $banner_average_color = Tools::get_image_average_color( Template::get_asset_url( $plugin, $first_banner, false /* no CDN */ ) );
    186186                }
    187187                update_post_meta( $plugin->ID, 'assets_banners_color', wp_slash( $banner_average_color ) );
Note: See TracChangeset for help on using the changeset viewer.