Automattic\WooCommerce\Admin\Features\Blueprint
Init::get_installed_wp_org_themes
Get all installed WordPress.org themes.
Method of the class: Init{}
No Hooks.
Returns
Array.
Usage
// private - for code of main (parent) class only $result = $this->get_installed_wp_org_themes();
Init::get_installed_wp_org_themes() Init::get installed wp org themes code WC 10.4.3
private function get_installed_wp_org_themes() {
// Try to get cached theme list.
$wp_org_themes = get_transient( self::INSTALLED_WP_ORG_THEMES_TRANSIENT );
if ( is_array( $wp_org_themes ) ) {
return $wp_org_themes;
}
// Get all installed themes.
$all_themes = $this->wp_get_themes();
$theme_slugs = array();
// Build an array of installed theme slugs.
foreach ( $all_themes as $key => $theme ) {
if ( is_string( $key ) ) {
$theme_slugs[] = strtolower( $key );
}
}
$api_response = $this->wp_themes_api(
'theme_information',
array(
'fields' => array(
'downloadlink' => true,
'sections' => false,
'description' => false,
'rating' => false,
'ratings' => false,
'downloaded' => false,
'last_updated' => false,
'tags' => false,
'homepage' => false,
'screenshots' => false,
'screenshot_url' => false,
'parent' => false,
'versions' => false,
'extended_author' => false,
),
'slugs' => $theme_slugs,
)
);
// If the API fails, return all installed themes.
if ( is_wp_error( $api_response ) ) {
return $all_themes;
}
$wp_org_themes = array_filter(
$all_themes,
function ( $theme ) use ( $api_response ) {
$slug = $theme->get_stylesheet();
return isset( $api_response->{$slug}['download_link'] );
}
);
set_transient( self::INSTALLED_WP_ORG_THEMES_TRANSIENT, $wp_org_themes );
return $wp_org_themes;
}