WC_Admin_Status::get_latest_theme_version()public staticWC 1.0

Get latest version of a theme by slug.

Method of the class: WC_Admin_Status{}

No Hooks.

Return

String. Version number if found.

Usage

$result = WC_Admin_Status::get_latest_theme_version( $theme );
$theme(object) (required)
WP_Theme object.

WC_Admin_Status::get_latest_theme_version() code WC 8.7.0

public static function get_latest_theme_version( $theme ) {
	include_once ABSPATH . 'wp-admin/includes/theme.php';

	$api = themes_api(
		'theme_information',
		array(
			'slug'   => $theme->get_stylesheet(),
			'fields' => array(
				'sections' => false,
				'tags'     => false,
			),
		)
	);

	$update_theme_version = 0;

	// Check .org for updates.
	if ( is_object( $api ) && ! is_wp_error( $api ) && isset( $api->version ) ) {
		$update_theme_version = $api->version;
	} elseif ( strstr( $theme->{'Author URI'}, 'woothemes' ) ) { // Check WooThemes Theme Version.
		$theme_dir          = substr( strtolower( str_replace( ' ', '', $theme->Name ) ), 0, 45 ); // @codingStandardsIgnoreLine.
		$theme_version_data = get_transient( $theme_dir . '_version_data' );

		if ( false === $theme_version_data ) {
			$theme_changelog = wp_safe_remote_get( 'http://dzv365zjfbd8v.cloudfront.net/changelogs/' . $theme_dir . '/changelog.txt' );
			$cl_lines        = explode( "\n", wp_remote_retrieve_body( $theme_changelog ) );
			if ( ! empty( $cl_lines ) ) {
				foreach ( $cl_lines as $line_num => $cl_line ) {
					if ( preg_match( '/^[0-9]/', $cl_line ) ) {
						$theme_date         = str_replace( '.', '-', trim( substr( $cl_line, 0, strpos( $cl_line, '-' ) ) ) );
						$theme_version      = preg_replace( '~[^0-9,.]~', '', stristr( $cl_line, 'version' ) );
						$theme_update       = trim( str_replace( '*', '', $cl_lines[ $line_num + 1 ] ) );
						$theme_version_data = array(
							'date'      => $theme_date,
							'version'   => $theme_version,
							'update'    => $theme_update,
							'changelog' => $theme_changelog,
						);
						set_transient( $theme_dir . '_version_data', $theme_version_data, DAY_IN_SECONDS );
						break;
					}
				}
			}
		}

		if ( ! empty( $theme_version_data['version'] ) ) {
			$update_theme_version = $theme_version_data['version'];
		}
	}

	return $update_theme_version;
}