Automattic\WooCommerce\Internal\Caches
VersionStringGenerator::get_version
Get the current version string for an ID.
If no version exists and $generate is true, a new version will be created. If no version exists and $generate is false, null will be returned.
Method of the class: VersionStringGenerator{}
No Hooks.
Returns
String|null. Version string, or null if not found and $generate is false.
Usage
$VersionStringGenerator = new VersionStringGenerator(); $VersionStringGenerator->get_version( $id, $generate ): ?string;
- $id(string) (required)
- The ID to get the version string for.
- $generate(true|false)
- Whether to generate a new version if one doesn't exist.
Default: true
Changelog
| Since 10.4.0 | Introduced. |
VersionStringGenerator::get_version() VersionStringGenerator::get version code WC 10.4.3
public function get_version( string $id, bool $generate = true ): ?string {
$this->validate_input( $id );
$cache_key = $this->get_cache_key( $id );
$found = false;
$version = wp_cache_get( $cache_key, self::CACHE_GROUP, false, $found );
if ( ! $found ) {
if ( ! $generate ) {
return null;
}
$version = $this->generate_version( $id );
} else {
// Refresh the cache lifetime.
$this->store_version( $id, $version );
}
return $version;
}