WordPress.org

Making WordPress.org

Changeset 6497


Ignore:
Timestamp:
02/01/2018 04:27:56 AM (4 years ago)
Author:
dd32
Message:

Theme Directory: API: Update the list of fields to include by default in teh info/1.2 API endpoints.

See #111.

File:
1 edited

Legend:

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

    r6489 r6497  
    357357        if ( defined( 'THEMES_API_VERSION' ) && THEMES_API_VERSION >= 1.2 ) {
    358358            $defaults['extended_author'] = true;
     359            $defaults['num_ratings'] = true;
     360            $detaults['parent'] = true;
    359361        }
    360362
     
    411413    public function query_themes() {
    412414        global $wp_query;
    413         // If there is a cached result, return that.
    414         $cache_key = sanitize_key( __METHOD__ . ':' . get_locale() . ':' . md5( serialize( $this->request ) ) );
    415         if ( false !== ( $this->response = wp_cache_get( $cache_key, $this->cache_group ) ) && empty( $this->request->cache_buster ) ) {
    416             return;
    417         }
    418 
    419         if ( isset( $wp_query ) && $wp_query->query_vars ) {
    420             $this->result = $wp_query;
    421         } else {
    422             $this->result = $this->perform_wp_query();
    423         }
    424 
    425         if ( empty( $this->request->fields ) ) {
    426             $this->request->fields = array();
    427         }
    428 
    429         // Basic information about the request.
    430         $this->response = (object) array(
    431             'info'   => array(),
    432             'themes' => array(),
    433         );
    434 
    435         // Basic information about the request.
    436         $this->response->info = array(
    437             'page'    => max( 1, $this->result->query_vars['paged'] ),
    438             'pages'   => max( 1, $this->result->max_num_pages ),
    439             'results' => (int) $this->result->found_posts,
    440         );
    441415
    442416        // Set which fields wanted by default:
     
    447421            'template'    => true,
    448422        );
     423        if ( defined( 'THEMES_API_VERSION' ) && THEMES_API_VERSION >= 1.2 ) {
     424            $defaults['extended_author'] = true;
     425            $defaults['num_ratings'] = true;
     426            $detaults['parent'] = true;
     427        }
    449428
    450429        $this->fields = array_merge( $this->fields, $defaults, (array) $this->request->fields );
     430
     431        // If there is a cached result, return that.
     432        $cache_key = sanitize_key( __METHOD__ . ':' . get_locale() . ':' . md5( serialize( $this->request ) . serialize( $this->fields ) ) );
     433        if ( false !== ( $this->response = wp_cache_get( $cache_key, $this->cache_group ) ) && empty( $this->request->cache_buster ) ) {
     434            return;
     435        }
     436
     437        if ( isset( $wp_query ) && $wp_query->query_vars ) {
     438            $this->result = $wp_query;
     439        } else {
     440            $this->result = $this->perform_wp_query();
     441        }
     442
     443        if ( empty( $this->request->fields ) ) {
     444            $this->request->fields = array();
     445        }
     446
     447        // Basic information about the request.
     448        $this->response = (object) array(
     449            'info'   => array(),
     450            'themes' => array(),
     451        );
     452
     453        // Basic information about the request.
     454        $this->response->info = array(
     455            'page'    => max( 1, $this->result->query_vars['paged'] ),
     456            'pages'   => max( 1, $this->result->max_num_pages ),
     457            'results' => (int) $this->result->found_posts,
     458        );
    451459
    452460        // Fill up the themes lists.
     
    605613                'profile' => 'https://profiles.wordpress.org/' . $author->user_nicename,
    606614                'avatar' => 'https://secure.gravatar.com/avatar/' . md5( $author->user_email ) . '?s=96&d=monsterid&r=g',
    607                 'user_nicename' => $author->user_nicename,
    608615                'display_name'  => $author->display_name,
    609616            );
Note: See TracChangeset for help on using the changeset viewer.