Make WordPress Core


Ignore:
Timestamp:
10/05/2010 01:24:41 PM (14 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-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/**
Note: See TracChangeset for help on using the changeset viewer.