Making WordPress.org


Ignore:
Timestamp:
05/03/2019 07:03:20 AM (5 years ago)
Author:
dd32
Message:

Plugin Directory: Introduce localised screenshots, allowing plugins to have translated screenshots on the website and within the wp-admin plugin installer.

This works by allowing screenshots located in the /assets/ folder to define the locale of the image, eg. screenshot-1-de_DE.png or screenshot-1-ary.png.

Props ck3lee, dd32.
See #3935.

File:
1 edited

Legend:

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

    r6287 r8729  
    99
    1010    /**
    11      * Banners constructor.
     11     * Screenshots constructor.
    1212     */
    1313    public function __construct() {
     
    2828     */
    2929    public function get_screenshots( $object ) {
    30         $descriptions = get_post_meta( $object['id'], 'screenshots', true ) ?: [];
    31         $screen_shots = get_post_meta( $object['id'], 'assets_screenshots', true ) ?: [];
    32         $response     = [];
    33 
    34         foreach ( $screen_shots as $image ) {
    35             $screen_shot = [
    36                 'src' => esc_url( Template::get_asset_url( $object['id'], $image ) ),
    37             ];
    38 
    39             if ( $descriptions && ! empty( $descriptions[ (int) $image['resolution'] ] ) ) {
    40                 $caption                = $descriptions[ (int) $image['resolution'] ];
    41                 $screen_shot['caption'] = Plugin_I18n::instance()->translate( 'screenshot-' . $image['resolution'], $caption, [ 'post_id' => $object['id'] ] );
    42             }
    43 
    44             $response[] = $screen_shot;
    45         }
    46 
    47         return $response;
     30        // Reduce the Screenshots to the required fields.
     31        return array_values( array_map(
     32            function( $image ) {
     33                return [
     34                    'src'     => $image['src'],
     35                    'caption' => $image['caption'],
     36                ];
     37            },
     38            Template::get_screenshots( $object['id'] )
     39        ) );
    4840    }
    4941}
Note: See TracChangeset for help on using the changeset viewer.