WC_Helper::get_local_woo_themes
Get locally installed Woo themes.
Scanning every installed theme is expensive, so the result is cached for the rest of the request. Pass false after installing or removing a theme to rescan and refresh the cache.
Method of the class: WC_Helper{}
No Hooks.
Returns
array.
Usage
$result = WC_Helper::get_local_woo_themes( $use_cache );
- $use_cache(true|false)
- Whether to return the cached list when one exists.
Default:true
Changelog
| Since 11.2.0 | Introduced. |
| Since 11.2.0 | Added the $use_cache parameter. |
WC_Helper::get_local_woo_themes() WC Helper::get local woo themes code WC 11.2.1
public static function get_local_woo_themes( bool $use_cache = true ) {
if ( $use_cache && null !== self::$local_woo_themes_cache ) {
return self::$local_woo_themes_cache;
}
$themes = wp_get_themes();
$woo_themes = array();
foreach ( $themes as $theme ) {
$header = $theme->get( 'Woo' );
// Backwards compatibility for theme_info.txt.
if ( ! $header ) {
$txt = $theme->get_stylesheet_directory() . '/theme_info.txt';
if ( is_readable( $txt ) ) {
$txt = file_get_contents( $txt );
$txt = preg_split( '#\s#', $txt );
if ( is_array( $txt ) && count( $txt ) >= 2 ) {
$header = sprintf( '%d:%s', $txt[0], $txt[1] );
}
}
}
if ( empty( $header ) ) {
continue;
}
list( $product_id, $file_id ) = explode( ':', $header );
if ( empty( $product_id ) || empty( $file_id ) ) {
continue;
}
$data = array(
'Name' => $theme->get( 'Name' ),
'Version' => $theme->get( 'Version' ),
'Woo' => $header,
'_filename' => $theme->get_stylesheet() . '/style.css',
'_stylesheet' => $theme->get_stylesheet(),
'_product_id' => absint( $product_id ),
'_file_id' => $file_id,
'_type' => 'theme',
'slug' => dirname( $theme->get_stylesheet() ),
);
$woo_themes[ $data['_filename'] ] = $data;
}
self::$local_woo_themes_cache = $woo_themes;
return $woo_themes;
}