Making WordPress.org


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

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

See #2112

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.