Making WordPress.org

Changeset 6484


Ignore:
Timestamp:
01/31/2018 04:07:08 AM (9 years ago)
Author:
dd32
Message:

Theme Directory: API: Allow for querying multiple themes on the theme_information action through the 'slugs' parameter.

Example: ​https://api.wordpress.org/themes/info/1.2/?action=theme_information&request[slugs][]=twentyten&request[slugs][]=twentyeleven

See #1304

File:
1 edited

Legend:

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

    r6465 r6484  
    294294
    295295        /**
     296         * Retrieve specific information about multiple theme.
     297         */
     298        public function theme_information_multiple() {
     299                if ( empty( $this->request->slugs ) ) {
     300                        $this->response = (object) array( 'error' => 'Slugs not provided' );
     301                        return;
     302                }
     303
     304                $slugs = is_array( $this->request->slugs ) ? $this->request->slugs : explode( ',', $this->request->slugs );
     305                $slugs = array_unique( array_map( 'trim', $slugs ) );
     306
     307                if ( count( $slugs ) > 100 ) {
     308                        $this->response = (object) array( 'error' => 'A maximum of 100 themes can be queried at once.' );
     309                        return;
     310                }
     311
     312                $response = array();
     313                unset( $this->request->slugs ); // So it doesn't affect caching.
     314                foreach ( $slugs as $slug ) {
     315                        $this->request->slug = $slug;
     316                        $this->theme_information();
     317                        $response[ $slug ] = $this->response;
     318                }
     319
     320                $this->response = $response;
     321        }
     322
     323        /**
    296324         * Retrieve specific information about a theme.
    297325         */
    298326        public function theme_information() {
    299327                global $post;
     328
     329                // Support the 'slugs' parameter to fetch multiple themes at once.
     330                if ( ! empty( $this->request->slugs ) ) {
     331                        $this->theme_information_multiple();
     332                        return;
     333                }
     334
    300335                // Theme slug to identify theme.
    301336                if ( empty( $this->request->slug ) ) {
Note: See TracChangeset for help on using the changeset viewer.