Make WordPress Core


Ignore:
Timestamp:
10/05/2010 01:24:41 PM (15 years ago)
Author:
ryan
Message:

Move themes_api() to theme.php so that it is available to themes.php. see #14936

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/theme.php

    r15655 r15727  
    354354}
    355355
     356/**
     357 * Retrieve theme installer pages from WordPress Themes API.
     358 *
     359 * It is possible for a theme to override the Themes API result with three
     360 * filters. Assume this is for themes, which can extend on the Theme Info to
     361 * offer more choices. This is very powerful and must be used with care, when
     362 * overridding the filters.
     363 *
     364 * The first filter, 'themes_api_args', is for the args and gives the action as
     365 * the second parameter. The hook for 'themes_api_args' must ensure that an
     366 * object is returned.
     367 *
     368 * The second filter, 'themes_api', is the result that would be returned.
     369 *
     370 * @since 2.8.0
     371 *
     372 * @param string $action
     373 * @param array|object $args Optional. Arguments to serialize for the Theme Info API.
     374 * @return mixed
     375 */
     376function themes_api($action, $args = null) {
     377
     378    if ( is_array($args) )
     379        $args = (object)$args;
     380
     381    if ( !isset($args->per_page) )
     382        $args->per_page = 24;
     383
     384    $args = apply_filters('themes_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter.
     385    $res = apply_filters('themes_api', false, $action, $args); //NOTE: Allows a theme to completely override the builtin WordPress.org API.
     386
     387    if ( ! $res ) {
     388        $request = wp_remote_post('http://api.wordpress.org/themes/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) );
     389        if ( is_wp_error($request) ) {
     390            $res = new WP_Error('themes_api_failed', __('An Unexpected HTTP Error occured during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $request->get_error_message() );
     391        } else {
     392            $res = unserialize($request['body']);
     393            if ( ! $res )
     394            $res = new WP_Error('themes_api_failed', __('An unknown error occured'), $request['body']);
     395        }
     396    }
     397    //var_dump(array($args, $res));
     398    return apply_filters('themes_api_result', $res, $action, $args);
     399}
     400
    356401?>
Note: See TracChangeset for help on using the changeset viewer.