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/routes/class-plugin.php

    r7282 r8729  
    155155        $result['download_link']     = Template::download_link( $post );
    156156
    157         $result['screenshots'] = array();
    158         $descriptions          = get_post_meta( $post->ID, 'screenshots', true ) ?: array();
    159         $screen_shots          = get_post_meta( $post->ID, 'assets_screenshots', true ) ?: array();
    160 
    161         /*
    162          * Find the image that corresponds with the text.
    163          * The image numbers are stored within the 'resolution' key.
    164          */
    165         foreach ( $screen_shots as $image ) {
    166             $src     = Template::get_asset_url( $post, $image );
    167             $caption = '';
    168             if ( $descriptions && ! empty( $descriptions[ (int) $image['resolution'] ] ) ) {
    169                 $caption = $descriptions[ (int) $image['resolution'] ];
    170                 $caption = Plugin_I18n::instance()->translate( 'screenshot-' . $image['resolution'], $caption, [ 'post_id' => $post->ID ] );
    171             }
    172 
    173             $result['screenshots'][ $image['resolution'] ] = compact( 'src', 'caption' );
    174         }
     157        // Reduce images to caption + src
     158        $result['screenshots'] = array_map(
     159            function( $image ) {
     160                return [
     161                    'src'     => $image['src'],
     162                    'caption' => $image['caption'],
     163                ];
     164            },
     165            Template::get_screenshots( $post )
     166        );
    175167
    176168        if ( $result['screenshots'] ) {
Note: See TracChangeset for help on using the changeset viewer.