Making WordPress.org


Ignore:
Timestamp:
02/10/2015 12:18:47 AM (10 years ago)
Author:
obenland
Message:

WP.org Themes: Use Photon for theme screenshots.

The Theme Directory feeds off of images to illustrate themes, so we will always
have a sizable footprint. In listings, screenshots are retina, so four times
the size they could be, on single they are over 700px wide. No reason not to
try our best to keep it managable though!

Using Photon will cut page weight to about half of what it is now.
We're adjusting the size to only what we need and remove all meta data.

See https://wordpress.slack.com/archives/meta/p1423518323000926

Fixes #845.

File:
1 edited

Legend:

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

    r1212 r1238  
    241241
    242242    foreach ( $api->themes as &$theme ) {
    243         $theme->name        = wp_kses( $theme->name,        $themes_allowedtags );
    244         $theme->author      = wp_kses( $theme->author,      $themes_allowedtags );
    245         $theme->version     = wp_kses( $theme->version,     $themes_allowedtags );
    246         $theme->description = wp_kses( $theme->description, $themes_allowedtags );
    247         $theme->num_ratings = number_format_i18n( $theme->num_ratings );
    248         $theme->preview_url = set_url_scheme( $theme->preview_url );
     243        $theme->name           = wp_kses( $theme->name,        $themes_allowedtags );
     244        $theme->author         = wp_kses( $theme->author,      $themes_allowedtags );
     245        $theme->version        = wp_kses( $theme->version,     $themes_allowedtags );
     246        $theme->description    = wp_kses( $theme->description, $themes_allowedtags );
     247        $theme->num_ratings    = number_format_i18n( $theme->num_ratings );
     248        $theme->preview_url    = set_url_scheme( $theme->preview_url );
     249        wporg_themes_photon_screen_shot( $theme );
    249250    }
    250251
     
    264265    }
    265266
    266     $theme->name        = wp_kses( $theme->name,        $themes_allowedtags );
    267     $theme->author      = wp_kses( $theme->author,      $themes_allowedtags );
    268     $theme->version     = wp_kses( $theme->version,     $themes_allowedtags );
    269     $theme->description = wp_kses( $theme->description, $themes_allowedtags );
    270     $theme->num_ratings = number_format_i18n( $theme->num_ratings );
    271     $theme->preview_url = set_url_scheme( $theme->preview_url );
     267    $theme->name           = wp_kses( $theme->name,        $themes_allowedtags );
     268    $theme->author         = wp_kses( $theme->author,      $themes_allowedtags );
     269    $theme->version        = wp_kses( $theme->version,     $themes_allowedtags );
     270    $theme->description    = wp_kses( $theme->description, $themes_allowedtags );
     271    $theme->num_ratings    = number_format_i18n( $theme->num_ratings );
     272    $theme->preview_url    = set_url_scheme( $theme->preview_url );
     273    wporg_themes_photon_screen_shot( $theme );
    272274
    273275    wp_send_json_success( $theme );
     
    275277add_action( 'wp_ajax_theme-info',        'wporg_themes_theme_info' );
    276278add_action( 'wp_ajax_nopriv_theme-info', 'wporg_themes_theme_info' );
     279
     280/**
     281 * Photon-ifies the screen shot URL.
     282 *
     283 * @param object $theme
     284 * @return object
     285 */
     286function wporg_themes_photon_screen_shot( $theme ) {
     287    if ( preg_match( '/screenshot.(jpg|jpeg|png|gif)/', $theme->screenshot_url, $match ) ) {
     288        $theme->screenshot_url = sprintf( 'https://i0.wp.com/themes.svn.wordpress.org/%1$s/%2$s/%3$s',
     289            $theme->slug,
     290            $theme->version,
     291            $match[0]
     292        );
     293    }
     294    return $theme;
     295}
    277296
    278297/**
Note: See TracChangeset for help on using the changeset viewer.