Making WordPress.org

Changeset 6465


Ignore:
Timestamp:
01/30/2018 05:54:05 AM (7 years ago)
Author:
dd32
Message:

Theme Directory: API: Add an info./1.2 endpoint which returns real errors in the event a theme cannot be found.

Back-compat behaviour for info/1.0 and info/1.1 is to return false in the event a theme cannot be located.

See #111

Location:
sites/trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/themes/info/1.0/index.php

    r6462 r6465  
    55
    66require dirname( dirname( dirname( __DIR__ ) ) ) . '/wp-init.php';
     7
     8if ( ! defined( 'THEMES_API_SUPPORTS_ERRORS' ) ) {
     9    define( 'THEMES_API_SUPPORTS_ERRORS', false );
     10}
    711
    812// Set up action and request information.
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-themes-api.php

    r6462 r6465  
    119119     */
    120120    public function get_result( $format = 'raw' ) {
     121        $response = $this->response;
     122
     123        // Back-compat behaviour:
     124        if ( defined( 'THEMES_API_SUPPORTS_ERRORS' ) && ! THEMES_API_SUPPORTS_ERRORS ) {
     125            if ( isset( $this->response->error ) && 'Theme not found' == $this->response->error ) {
     126                $response = false;
     127            }
     128        }
     129
    121130        if ( 'json' === $format ) {
    122             return wp_json_encode( $this->response );
     131            return wp_json_encode( $response );
    123132        } elseif ( 'php' === $format ) {
    124             return serialize( $this->response );
     133            return serialize( $response );
    125134        } else { // 'raw' === $format, or anything else.
    126             return $this->response;
     135            return $response;
    127136        }
    128137    }
     
    327336            ) );
    328337
    329             if ( ! empty( $themes ) ) {
     338            if ( $themes ) {
    330339                $this->response = $this->fill_theme( $themes[0] );
     340            } else {
     341                $this->response = (object) array( 'error' => 'Theme not found' ); // Check get_result() if changing this string.
    331342            }
    332343        }
Note: See TracChangeset for help on using the changeset viewer.