Making WordPress.org

Changeset 6462


Ignore:
Timestamp:
01/30/2018 03:18:52 AM (6 years ago)
Author:
dd32
Message:

Theme Directory: API: Move the Themes_API class into the plugin, making api.wordpress.org/themes/info/ a wrapper for it.

See #1630

Location:
sites/trunk
Files:
1 deleted
4 edited

Legend:

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

    r6418 r6462  
    99if ( defined( 'JSON_RESPONSE' ) && JSON_RESPONSE ) {
    1010    $request = isset( $_REQUEST['request'] ) ? (object) wp_unslash( $_REQUEST['request'] ) : '';
     11    $format = 'json';
    1112} else {
    1213    $post_request = isset( $_POST['request'] ) ? urldecode( wp_unslash( $_POST['request'] ) ) : '';
     
    1617
    1718    $request = unserialize( $post_request );
     19
     20    $format = 'php';
    1821}
     22
    1923$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
    2024
    21 // Load the Themes API.
    22 if ( ! class_exists( 'Themes_API' ) ) {
    23     require_once __DIR__ . '/class-themes-api.php';
    24 }
    25 
    26 // Instantiate the API and serve the result.
    27 $api = new Themes_API( $action, $request );
    28 echo $api->get_result();
     25// Serve an API request.
     26echo wporg_themes_query_api( $action, $request, $format );
  • sites/trunk/api.wordpress.org/public_html/themes/theme-directory/1.0/index.php

    r6418 r6462  
    5555        }
    5656
    57         $theme_slug = $_REQUEST['theme'];
     57        $theme_slug = wp_unslash( $_REQUEST['theme'] );
    5858
    5959        if ( 'add-favorite' == $_REQUEST['action'] ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-themes-api.php

    r6419 r6462  
    118118     * @return string|void
    119119     */
    120     public function get_result() {
    121         if ( defined( 'JSON_RESPONSE' ) && JSON_RESPONSE ) {
     120    public function get_result( $format = 'raw' ) {
     121        if ( 'json' === $format ) {
    122122            return wp_json_encode( $this->response );
    123         } else {
     123        } elseif ( 'php' === $format ) {
    124124            return serialize( $this->response );
     125        } else { // 'raw' === $format, or anything else.
     126            return $this->response;
    125127        }
    126128    }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php

    r6419 r6462  
    788788
    789789/**
    790  * Makes a query against api.wordpress.org/themes/info/1.0/ without making a HTTP call
    791  * Switches to the appropriate blog for the query.
    792  */
    793 function wporg_themes_query_api( $method, $args = array() ) {
     790 * Make a query against the api.wordpress.org/themes/info/ API
     791 * This function can be used to access the API without making an external HTTP call.
     792 *
     793 * NOTE: The API also calls this function.
     794 *
     795 * @param $method string The Method being called. Valid values: 'query_themes', 'theme_information', 'hot_tags', 'feature_list', and 'get_commercial_shops'
     796 * @param $args   array  The arguements for the call.
     797 * @param $format string The format to return the data in. Valid values: 'json', 'php', 'raw' (default)
     798 */
     799function wporg_themes_query_api( $method, $args = array(), $format = 'raw' ) {
    794800    if ( ! class_exists( 'Themes_API' ) ) {
    795         if ( file_exists( __DIR__ . '/class-themes-api.php' ) ) {
    796             include_once __DIR__ . '/class-themes-api.php';
    797         } else {
    798             include_once API_WPORGPATH . 'themes/info/1.0/class-themes-api.php';
    799         }
     801        include_once __DIR__ . '/class-themes-api.php';
    800802    }
    801803
    802804    $api = new Themes_API( $method, $args );
    803805
    804     return $api->response;
     806    return $api->get_result( $format );
    805807}
    806808
Note: See TracChangeset for help on using the changeset viewer.