Making WordPress.org

Changeset 4559


Ignore:
Timestamp:
12/19/2016 07:00:06 AM (7 years ago)
Author:
dd32
Message:

Plugin Directory: Allow us to return the FAQ section with <h4> instead of <dl> for existing WordPress versions.
Also fixes the hot_tags endpoint to work correctly.

See #2112.

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

Legend:

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

    r4505 r4559  
    112112        }
    113113        $result['sections']['reviews'] = $this->get_plugin_reviews_markup( $post->post_name );
     114        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        }
     118       
    114119        $result['description'] = $result['sections']['description'];
    115120
     
    271276    }
    272277
     278    /**
     279     * Return a 'simplified' markup for the FAQ screen.
     280     * WordPress only supports a whitelisted selection of tags, `<dl>` is not one of them.
     281     *
     282     * @see https://core.trac.wordpress.org/browser/tags/4.7/src/wp-admin/includes/plugin-install.php#L478
     283     * @param string $markup The existing Markup.
     284     * @return string Them markup with `<dt>` replaced with `<h4>` and `<dd>` with `<p>`.
     285     */
     286    protected function get_simplified_faq_markup( $markup ) {
     287        $markup = str_replace(
     288            array( '<dl>', '</dl>', '<dt>', '</dt>', '<dd>', '</dd>' ),
     289            array( '',      '',     '<h4>', '</h4>', '<p>',  '</p>'  ),
     290            $markup
     291        );
     292
     293        return $markup;
     294    }
     295
    273296}
    274297
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-popular-tags.php

    r4125 r4559  
    2525     */
    2626    function popular_tags( $request ) {
    27         $terms = get_terms( 'plugin_tags', array( 'hide_empty' => false, 'orderby' => 'count', 'order' => 'DESC' ) );
     27        $terms = get_terms( 'plugin_tags', array(
     28            'hide_empty' => true,
     29            'orderby' => 'count',
     30            'order' => 'DESC',
     31            'number' => 1000
     32        ) );
    2833
    2934        $response = array();
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api-request.php

    r4197 r4559  
    4747        'sections'          => true,
    4848        'tags'              => true,
    49         'tested'            => true,       
     49        'tested'            => true,
     50        'enhanced_faq'      => false,
    5051    );
    5152
     
    6566        'short_description' => true,
    6667        'tags'              => true,
    67         'tested'            => true,   
     68        'tested'            => true,
     69        'enhanced_faq'      => false,
    6870    );
    6971
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api.php

    r4125 r4559  
    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'] );
    114120            }
    115121        }
     
    180186     */
    181187    public function popular_tags( $request ) {
    182         if ( false === ( $response = false&& wp_cache_get( $cache_key = $this->popular_tags_cache_key( $request ), self::CACHE_GROUP ) ) ) {
    183             $response = $this->internal_rest_api_call( 'plugins/v1/popular-categories', array( 'locale' => $request->locale ) );
     188        if ( false === ( $response = wp_cache_get( $cache_key = $this->popular_tags_cache_key( $request ), self::CACHE_GROUP ) ) ) {
     189            $response = $this->internal_rest_api_call( 'plugins/v1/popular-tags', array( 'locale' => $request->locale ) );
    184190
    185191            if ( 200 != $response->status ) {
     
    191197        }
    192198
    193         if ( $request->number && count( $response ) > $request->number ) {
    194             $response = array_slice( $response, 0, $request->number, true );
     199        $number_items_requested = 100;
     200        if ( !empty( $request->number ) ) {
     201            $number_items_requested = $request->number;
     202        }
     203
     204        if ( count( $response ) > $number_items_requested ) {
     205            $response = array_slice( $response, 0, $number_items_requested, true );
    195206        }
    196207
    197208        $this->output( (object) $response );
    198209    }
    199     /**
    200      * Generates a cache key for a 'hot_categories' API request.
     210
     211    /**
     212     * Generates a cache key for a 'hot_tags' API request.
    201213     */
    202214    protected function popular_tags_cache_key( $request ) {
    203         return 'hot_categories:' . $request->locale;
     215        return 'hot_tags:' . $request->locale;;
    204216    }
    205217
Note: See TracChangeset for help on using the changeset viewer.