Making WordPress.org

Changeset 4560


Ignore:
Timestamp:
12/19/2016 07:17:41 AM (8 years ago)
Author:
dd32
Message:

Plugin Directory: Expose Screenshots in the sections section of the API response so WordPress can display them.

See #2112

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
3 edited

Legend:

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

    r4559 r4560  
    111111            $result['sections'][ $_pages[ $i ] ] = apply_filters( 'the_content', $_pages[ $i + 1 ], $_pages[ $i ] );
    112112        }
     113        $result['sections']['screenshots'] = ''; // placeholder to put screenshots prior to reviews at the end.
    113114        $result['sections']['reviews'] = $this->get_plugin_reviews_markup( $post->post_name );
     115
    114116        if ( !empty( $result['sections']['faq'] ) ) {
    115             $result['sections']['enhanced_faq'] = $result['sections']['faq'];
    116             $result['sections']['faq'] = $this->get_simplified_faq_markup( $result['sections']['enhanced_faq'] );
     117            $result['sections']['faq'] = $this->get_simplified_faq_markup( $result['sections']['faq'] );
    117118        }
    118119       
     
    135136                'caption' => array_key_exists( $image['resolution'], $descriptions ) ? $descriptions[ $image['resolution'] ] : ''
    136137            );
     138        }
     139
     140        if ( $result['screenshots'] ) {
     141            $result['sections']['screenshots'] = $this->get_screenshot_markup( $result['screenshots'] );
     142        } else {
     143            unset( $result['sections']['screenshots'] );
    137144        }
    138145
     
    294301    }
    295302
     303    protected function get_screenshot_markup( $screenshots ) {
     304        $markup = '<ol>';
     305
     306        foreach ( $screenshots as $shot ) {
     307            if ( $shot['caption'] ) {
     308                $markup .= sprintf(
     309                    '<li><a href="%1$s"><img src="%1$s" alt="%2$s"></a><p>%3$s</p></li>',
     310                    esc_attr( $shot['src'] ),
     311                    esc_attr( $shot['caption'] ),
     312                    $shot['caption']
     313                );
     314            } else {
     315                $markup .= sprintf(
     316                    '<li><a href="%1$s"><img src="%1$s" alt=""></a></li>',
     317                    esc_attr( $shot['src'] )
     318                );
     319            }
     320        }
     321
     322        $markup .= '</ol>';
     323        return $markup;
     324    }
     325
    296326}
    297327
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api-request.php

    r4559 r4560  
    4848        'tags'              => true,
    4949        'tested'            => true,
    50         'enhanced_faq'      => false,
    5150    );
    5251
     
    6766        'tags'              => true,
    6867        'tested'            => true,
    69         'enhanced_faq'      => false,
    7068    );
    7169
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api.php

    r4559 r4560  
    112112            if ( 'reviews' === $field && ! $include ) {
    113113                unset( $response['sections']['reviews'] );
    114             }
    115             if ( 'enhanced_faq' === $field ) {
    116                 if ( $include ) {
    117                      $response['sections']['faq'] = $response['sections']['enhanced_faq'];
    118                 }
    119                 unset( $response['sections']['enhanced_faq'] );
    120114            }
    121115        }
     
    213207     */
    214208    protected function popular_tags_cache_key( $request ) {
    215         return 'hot_tags:' . $request->locale;;
     209        return 'hot_tags:' . $request->locale;
    216210    }
    217211
Note: See TracChangeset for help on using the changeset viewer.