WordPress.org

Make WordPress Core

Changeset 15727


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

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

Location:
trunk/wp-admin/includes
Files:
2 edited

Legend:

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

    r15655 r15727  
    1919    'tags' => true, 'num_ratings' => true
    2020);
    21 
    22 
    23 /**
    24  * Retrieve theme installer pages from WordPress Themes API.
    25  *
    26  * It is possible for a theme to override the Themes API result with three
    27  * filters. Assume this is for themes, which can extend on the Theme Info to
    28  * offer more choices. This is very powerful and must be used with care, when
    29  * overridding the filters.
    30  *
    31  * The first filter, 'themes_api_args', is for the args and gives the action as
    32  * the second parameter. The hook for 'themes_api_args' must ensure that an
    33  * object is returned.
    34  *
    35  * The second filter, 'themes_api', is the result that would be returned.
    36  *
    37  * @since 2.8.0
    38  *
    39  * @param string $action
    40  * @param array|object $args Optional. Arguments to serialize for the Theme Info API.
    41  * @return mixed
    42  */
    43 function themes_api($action, $args = null) {
    44 
    45     if ( is_array($args) )
    46         $args = (object)$args;
    47 
    48     if ( !isset($args->per_page) )
    49         $args->per_page = 24;
    50 
    51     $args = apply_filters('themes_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter.
    52     $res = apply_filters('themes_api', false, $action, $args); //NOTE: Allows a theme to completely override the builtin WordPress.org API.
    53 
    54     if ( ! $res ) {
    55         $request = wp_remote_post('http://api.wordpress.org/themes/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) );
    56         if ( is_wp_error($request) ) {
    57             $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() );
    58         } else {
    59             $res = unserialize($request['body']);
    60             if ( ! $res )
    61             $res = new WP_Error('themes_api_failed', __('An unknown error occured'), $request['body']);
    62         }
    63     }
    64     //var_dump(array($args, $res));
    65     return apply_filters('themes_api_result', $res, $action, $args);
    66 }
    6721
    6822/**
  • 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.