PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / trunk
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization vtrunk
4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 All 135 releases
← All changes | vendor/codeinwp/themeisle-sdk/src/Product.php +76 -3 3.0.1 → trunk View file →
@@ -70,8 +70,14 @@
70 70 * @var string $key The product ready key.
71 71 */
72 72 private $key;
73 73 /**
74 + * Author URL
75 + *
76 + * @var string $author_url The author url.
77 + */
78 + private $author_url;
79 + /**
74 80 * Product store url.
75 81 *
76 82 * @var string $store_url The store url.
77 83 */
@@ -106,11 +112,18 @@
106 112 * @var string $version The product version.
107 113 */
108 114 private $version;
109 115 /**
116 + * Holds a map of loaded products objects.
117 + *
118 + * @var array Array of loaded products.
119 + */
120 + private static $cached_products = [];
121 + /**
110 122 * Root api endpoint.
111 123 */
112 124 const API_URL = 'https://api.themeisle.com/';
125 +
113 126 /**
114 127 * ThemeIsle_SDK_Product constructor.
115 128 *
116 129 * @param string $basefile Product basefile.
@@ -125,15 +138,55 @@
125 138 }
126 139 $install = get_option( $this->get_key() . '_install', 0 );
127 140 if ( 0 === $install ) {
128 141 $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 +
129 149 update_option( $this->get_key() . '_install', time() );
130 150 }
131 - $this->install = $install;
151 + $this->install = (int) $install;
152 + self::$cached_products[ crc32( $basefile ) ] = $this;
153 + $current_version = get_option( $this->slug . '_version', '' );
132 154
155 + if ( $current_version !== $this->version && wp_cache_add( "{$this->slug}_version_upgrade", true, '', HOUR_IN_SECONDS ) ) {
156 + /**
157 + * Action to be triggered when the product is updated.
158 + *
159 + * @param string $current_version The current version of the product.
160 + * @param string $new_version The new version of the product.
161 + * @param string $basefile The basefile of the product.
162 + */
163 + do_action( "themeisle_sdk_update_{$this->slug}", $current_version, $this->version, $basefile );
164 +
165 + // Update the version of the product.
166 + update_option( "{$this->slug}_version", $this->version );
167 + wp_cache_delete( "{$this->slug}_version_upgrade" );
168 + }
133 169 }
134 170
135 171 /**
172 + * Return a product.
173 + *
174 + * @param string $basefile Product basefile.
175 + *
176 + * @return Product Product Object.
177 + */
178 + public static function get( $basefile ) {
179 + $key = crc32( $basefile );
180 + if ( isset( self::$cached_products[ $key ] ) ) {
181 + return self::$cached_products[ $key ];
182 + }
183 + self::$cached_products[ $key ] = new Product( $basefile );
184 +
185 + return self::$cached_products[ $key ];
186 + }
187 +
188 + /**
136 189 * Setup props from path.
137 190 */
138 191 public function setup_from_path() {
139 192 $this->file = basename( $this->basefile );
@@ -156,9 +209,9 @@
156 209 * @param string $string the String to be normalized for cron handler.
157 210 *
158 211 * @return string $name The normalized string.
159 212 */
160 - static function key_ready_name( $string ) {
213 + public static function key_ready_name( $string ) {
161 214 return str_replace( '-', '_', strtolower( trim( $string ) ) );
162 215 }
163 216
164 217 /**
@@ -315,9 +368,19 @@
315 368 *
316 369 * @return string Friendly name.
317 370 */
318 371 public function get_friendly_name() {
319 - $name = apply_filters( $this->get_key() . '_friendly_name', trim( str_replace( 'Lite', '', $this->get_name() ) ) );
372 + $name = trim( str_replace( 'Lite', '', $this->get_name() ) );
373 + if ( defined( 'OTTER_BLOCKS_BASEFILE' ) && OTTER_BLOCKS_BASEFILE === $this->basefile ) {
374 + $name = 'Otter Blocks';
375 + }
376 + if ( defined( 'OPTML_BASEFILE' ) && OPTML_BASEFILE === $this->basefile ) {
377 + $name = 'Optimole';
378 + }
379 + if ( defined( 'WPMM_FILE' ) && WPMM_FILE === $this->basefile ) {
380 + $name = 'LightStart';
381 + }
382 + $name = apply_filters( $this->get_key() . '_friendly_name', $name );
320 383 $name = rtrim( $name, '- ()' );
321 384
322 385 return $name;
323 386 }
@@ -322,8 +385,17 @@
322 385 return $name;
323 386 }
324 387
325 388 /**
389 + * Return the product version cache key.
390 + *
391 + * @return string The product version cache key.
392 + */
393 + public function get_cache_key() {
394 + return $this->get_key() . '_' . preg_replace( '/[^0-9a-zA-Z ]/m', '', $this->get_version() ) . 'versions';
395 + }
396 +
397 + /**
326 398 * Getter for product name.
327 399 *
328 400 * @return string The product name.
329 401 */
@@ -372,8 +444,9 @@
372 444 return add_query_arg(
373 445 [
374 446 'name' => rawurlencode( $this->get_name() ),
375 447 'edd_action' => 'view_changelog',
448 + 'locale' => get_user_locale(),
376 449 ],
377 450 $this->get_store_url()
378 451 );
379 452 }