Skip to content

Commit 1792342

Browse files
authored
adds utms zips support
1 parent 0727d2c commit 1792342

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/Loader.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ public static function init() {
344344
}
345345
}
346346
self::$available_modules = $modules;
347+
348+
add_action( 'themeisle_sdk_first_activation', array( __CLASS__, 'activate' ) );
347349
}
348350
}
349351

@@ -390,6 +392,28 @@ public static function add_product( $base_file ) {
390392
return self::$instance;
391393
}
392394

395+
/**
396+
* Activate the product routine.
397+
*
398+
* @param string $file The base file of the product.
399+
*
400+
* @return void
401+
*/
402+
public static function activate( $file ) {
403+
404+
$dirname = trailingslashit( dirname( ( $file ) ) );
405+
if ( ! file_exists( $dirname . '_reference.php' ) ) {
406+
return;
407+
}
408+
$reference_data = require_once $dirname . '_reference.php';
409+
if ( ! is_array( $reference_data ) ||
410+
! isset( $reference_data['key'] ) ||
411+
! isset( $reference_data['value'] ) ||
412+
! preg_match( '/^[a-zA-Z0-9_]+_reference_key$/', $reference_data['key'] ) ) {
413+
return;
414+
}
415+
add_option( $reference_data['key'], sanitize_key( $reference_data['value'] ) );
416+
}
393417
/**
394418
* Get all registered modules by the SDK.
395419
*

src/Product.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,36 @@ public function __construct( $basefile ) {
139139
$install = get_option( $this->get_key() . '_install', 0 );
140140
if ( 0 === $install ) {
141141
$install = time();
142+
/**
143+
* Action to be triggered when the product is first activated.
144+
*
145+
* @param string $basefile The basefile of the product.
146+
*/
147+
do_action( 'themeisle_sdk_first_activation', $basefile );
148+
142149
update_option( $this->get_key() . '_install', time() );
143150
}
144151
$this->install = $install;
145152
self::$cached_products[ crc32( $basefile ) ] = $this;
153+
$current_version = get_option( $this->slug . '_version', '' );
154+
155+
if ( $current_version !== $this->version && wp_cache_get( "{$this->slug}_version_upgrade" ) === false ) {
156+
// Set the cache lock to avoid multiple calls.
157+
wp_cache_set( "{$this->slug}_version_upgrade", true, HOUR_IN_SECONDS );
158+
/**
159+
* Action to be triggered when the product is updated.
160+
*
161+
* @param string $current_version The current version of the product.
162+
* @param string $new_version The new version of the product.
163+
* @param string $basefile The basefile of the product.
164+
*/
165+
do_action( "themeisle_sdk_update_{$this->slug}", $current_version, $this->version, $basefile );
166+
167+
// Update the version of the product.
168+
update_option( "{$this->slug}_version", $this->version );
169+
// Delete the cache lock.
170+
wp_cache_delete( "{$this->slug}_version_upgrade" );
171+
}
146172
}
147173

148174
/**

0 commit comments

Comments
 (0)