Move themes_api() to theme.php so that it is available to themes.php. see #14936
git-svn-id: http://svn.automattic.com/wordpress/trunk@15727 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
62176cc636
commit
fbfa3ea53d
|
@ -19,52 +19,6 @@ $theme_field_defaults = array( 'description' => true, 'sections' => false, 'test
|
||||||
'tags' => true, 'num_ratings' => true
|
'tags' => true, 'num_ratings' => true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve theme installer pages from WordPress Themes API.
|
|
||||||
*
|
|
||||||
* It is possible for a theme to override the Themes API result with three
|
|
||||||
* filters. Assume this is for themes, which can extend on the Theme Info to
|
|
||||||
* offer more choices. This is very powerful and must be used with care, when
|
|
||||||
* overridding the filters.
|
|
||||||
*
|
|
||||||
* The first filter, 'themes_api_args', is for the args and gives the action as
|
|
||||||
* the second parameter. The hook for 'themes_api_args' must ensure that an
|
|
||||||
* object is returned.
|
|
||||||
*
|
|
||||||
* The second filter, 'themes_api', is the result that would be returned.
|
|
||||||
*
|
|
||||||
* @since 2.8.0
|
|
||||||
*
|
|
||||||
* @param string $action
|
|
||||||
* @param array|object $args Optional. Arguments to serialize for the Theme Info API.
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
function themes_api($action, $args = null) {
|
|
||||||
|
|
||||||
if ( is_array($args) )
|
|
||||||
$args = (object)$args;
|
|
||||||
|
|
||||||
if ( !isset($args->per_page) )
|
|
||||||
$args->per_page = 24;
|
|
||||||
|
|
||||||
$args = apply_filters('themes_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter.
|
|
||||||
$res = apply_filters('themes_api', false, $action, $args); //NOTE: Allows a theme to completely override the builtin WordPress.org API.
|
|
||||||
|
|
||||||
if ( ! $res ) {
|
|
||||||
$request = wp_remote_post('http://api.wordpress.org/themes/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) );
|
|
||||||
if ( is_wp_error($request) ) {
|
|
||||||
$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() );
|
|
||||||
} else {
|
|
||||||
$res = unserialize($request['body']);
|
|
||||||
if ( ! $res )
|
|
||||||
$res = new WP_Error('themes_api_failed', __('An unknown error occured'), $request['body']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//var_dump(array($args, $res));
|
|
||||||
return apply_filters('themes_api_result', $res, $action, $args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve list of WordPress theme features (aka theme tags)
|
* Retrieve list of WordPress theme features (aka theme tags)
|
||||||
*
|
*
|
||||||
|
|
|
@ -353,4 +353,49 @@ function get_theme_feature_list() {
|
||||||
return $wporg_features;
|
return $wporg_features;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve theme installer pages from WordPress Themes API.
|
||||||
|
*
|
||||||
|
* It is possible for a theme to override the Themes API result with three
|
||||||
|
* filters. Assume this is for themes, which can extend on the Theme Info to
|
||||||
|
* offer more choices. This is very powerful and must be used with care, when
|
||||||
|
* overridding the filters.
|
||||||
|
*
|
||||||
|
* The first filter, 'themes_api_args', is for the args and gives the action as
|
||||||
|
* the second parameter. The hook for 'themes_api_args' must ensure that an
|
||||||
|
* object is returned.
|
||||||
|
*
|
||||||
|
* The second filter, 'themes_api', is the result that would be returned.
|
||||||
|
*
|
||||||
|
* @since 2.8.0
|
||||||
|
*
|
||||||
|
* @param string $action
|
||||||
|
* @param array|object $args Optional. Arguments to serialize for the Theme Info API.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function themes_api($action, $args = null) {
|
||||||
|
|
||||||
|
if ( is_array($args) )
|
||||||
|
$args = (object)$args;
|
||||||
|
|
||||||
|
if ( !isset($args->per_page) )
|
||||||
|
$args->per_page = 24;
|
||||||
|
|
||||||
|
$args = apply_filters('themes_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter.
|
||||||
|
$res = apply_filters('themes_api', false, $action, $args); //NOTE: Allows a theme to completely override the builtin WordPress.org API.
|
||||||
|
|
||||||
|
if ( ! $res ) {
|
||||||
|
$request = wp_remote_post('http://api.wordpress.org/themes/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) );
|
||||||
|
if ( is_wp_error($request) ) {
|
||||||
|
$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() );
|
||||||
|
} else {
|
||||||
|
$res = unserialize($request['body']);
|
||||||
|
if ( ! $res )
|
||||||
|
$res = new WP_Error('themes_api_failed', __('An unknown error occured'), $request['body']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//var_dump(array($args, $res));
|
||||||
|
return apply_filters('themes_api_result', $res, $action, $args);
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue