Retrieves theme installer pages from the WordPress.org Themes API.
Description
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 overriding 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', allows a plugin to override the WordPress.org Theme API entirely. If $action is 'query_themes', 'theme_information', or 'feature_list', an object MUST be passed. If $action is 'hot_tags', an array should be passed. Finally, the third filter, 'themes_api_result', makes it possible to filter the response object or array, depending on the $action type. Supported arguments per action: <table> <thead> <tr> <th>Argument Name</th> <th style="text-align: center;">'query_themes'</th> <th style="text-align: center;">'theme_information'</th> <th style="text-align: center;">'hot_tags'</th> <th style="text-align: center;">'feature_list'</th> </tr> </thead> <tbody> <tr> <td>$slug</td> <td style="text-align: center;">No</td> <td style="text-align: center;">Yes</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> </tr> <tr> <td>$per_page</td> <td style="text-align: center;">Yes</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> </tr> <tr> <td>$page</td> <td style="text-align: center;">Yes</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> </tr> <tr> <td>$number</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> <td style="text-align: center;">Yes</td> <td style="text-align: center;">No</td> </tr> <tr> <td>$search</td> <td style="text-align: center;">Yes</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> </tr> <tr> <td>$tag</td> <td style="text-align: center;">Yes</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> </tr> <tr> <td>$author</td> <td style="text-align: center;">Yes</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> </tr> <tr> <td>$user</td> <td style="text-align: center;">Yes</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> </tr> <tr> <td>$browse</td> <td style="text-align: center;">Yes</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> </tr> <tr> <td>$locale</td> <td style="text-align: center;">Yes</td> <td style="text-align: center;">Yes</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> </tr> <tr> <td>$fields</td> <td style="text-align: center;">Yes</td> <td style="text-align: center;">Yes</td> <td style="text-align: center;">No</td> <td style="text-align: center;">No</td> </tr> </tbody> </table>
Parameters
$actionstring
API action to perform: Accepts 'query_themes', 'theme_information', 'hot_tags' or 'feature_list'.
$argsarray|objectoptional
Array or object of arguments to serialize for the Themes API. Default empty array.Default: array()
$localestringdefault: is the value of get_locale()
Locale to provide context-sensitive results.
$fieldsarray
{ Array of fields which should or should not be returned.
$descriptionbooldefault: false
Whether to return the theme full description.
$sectionsbooldefault: false
Whether to return the theme readme sections: description, installation, FAQ, screenshots, other notes, and changelog.
$ratingbooldefault: false
Whether to return the rating in percent and total number of ratings.
$ratingsbooldefault: false
Whether to return the number of rating for each star (1-5).
$downloadedbooldefault: false
Whether to return the download count.
$downloadlinkbooldefault: false
Whether to return the download link for the package.
$last_updatedbooldefault: false
Whether to return the date of the last update.
$tagsbooldefault: false
Whether to return the assigned tags.
$homepagebooldefault: false
Whether to return the theme homepage link.
$screenshotsbooldefault: false
Whether to return the screenshots.
$screenshot_countintdefault: 1
Number of screenshots to return.
$screenshot_urlbooldefault: false
Whether to return the URL of the first screenshot.
$photon_screenshotsbooldefault: false
Whether to return the screenshots via Photon.
$templatebooldefault: false
Whether to return the slug of the parent theme.
$parentbooldefault: false
Whether to return the slug, name and homepage of the parent theme.
$versionsbooldefault: false
Whether to return the list of all available versions.
$theme_urlbooldefault: false
Whether to return theme's URL.
$extended_authorbooldefault: false. }
Whether to return nicename or nicename and display name.
Return
object|array|WP_Error
Response object or array on success, WP_Error on failure. See the <a href="https://developer.wordpress.org/reference/functions/themes_api/">https://developer.wordpress.org/reference/functions/themes_api/</a> function reference article for more information on the make-up of possible return objects depending on the value of $action.
Hooks fired · 3
3 hooks fire while themes_api() runs, in this order:
491functionthemes_api($action,$args=array()){492if(is_array($args)){493$args=(object)$args;494}495496if('query_themes'===$action){497if(!isset($args->per_page)){498$args->per_page=24;499}500}501502if(!isset($args->locale)){503$args->locale=get_user_locale();504}505506if(!isset($args->wp_version)){507$args->wp_version=substr(wp_get_wp_version(),0,3);// x.y508}509510/**511 * Filters arguments used to query for installer pages from the WordPress.org Themes API.512 *513 * Important: An object MUST be returned to this filter.514 *515 * @since 2.8.0516 *517 * @param object $args Arguments used to query for installer pages from the WordPress.org Themes API.518 * @param string $action Requested action. Likely values are 'theme_information',519 * 'feature_list', or 'query_themes'.520 */521$args=apply_filters('themes_api_args',$args,$action);522523/**524 * Filters whether to override the WordPress.org Themes API.525 *526 * Returning a non-false value will effectively short-circuit the WordPress.org API request.527 *528 * If `$action` is 'query_themes', 'theme_information', or 'feature_list', an object MUST529 * be passed. If `$action` is 'hot_tags', an array should be passed.530 *531 * @since 2.8.0532 *533 * @param false|object|array $override Whether to override the WordPress.org Themes API. Default false.534 * @param string $action Requested action. Likely values are 'theme_information',535 * 'feature_list', or 'query_themes'.536 * @param object $args Arguments used to query for installer pages from the Themes API.537 */538$res=apply_filters('themes_api',false,$action,$args);539540if(!$res){541$url='http://api.wordpress.org/themes/info/1.2/';542$url=add_query_arg(543array(544'action'=>$action,545'request'=>$args,546),547$url548);549550$http_url=$url;551$ssl=wp_http_supports(array('ssl'));552if($ssl){553$url=set_url_scheme($url,'https');554}555556$http_args=array(557'timeout'=>15,558'user-agent'=>'WordPress/'.wp_get_wp_version().'; '.home_url('/'),559);560$request=wp_remote_get($url,$http_args);561562if($ssl&&is_wp_error($request)){563if(!wp_doing_ajax()){564wp_trigger_error(565__FUNCTION__,566sprintf(567/* translators: %s: Support forums URL. */568__('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.'),569__('https://wordpress.org/support/forums/')570).' '.__('(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)'),
History
Introduced in 2.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-admin/includes/theme.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.