PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.10
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.10
4.4.10 4.4.9.1 4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 All 142 releases
← All changes | inc/Services/AddonService.php +31 -28 4.4.9 → 4.4.10 View file →
@@ -26,9 +26,9 @@
26 26 *
27 27 * @package LearnPress\Services
28 28 * @change from LP_Manager_Addons class old
29 29 * @since 4.2.1
30 - * @version 1.0.1
30 + * @version 1.0.2
31 31 */
32 32 class AddonService {
33 33 use Singleton;
34 34
@@ -47,8 +47,9 @@
47 47 /**
48 48 * @var string Link active site.
49 49 */
50 50 private $link_active_site = 'https://updates.thimpress.com/thim-addon-market/active-site';
51 + public $link_extend_site = 'https://thimpress.com/extend-license/?purchase_code={purchase_code}';
51 52 /**
52 53 * @var string Link download plugin from org.
53 54 */
54 55 public $link_org = 'https://downloads.wordpress.org/plugin/';
@@ -109,9 +110,9 @@
109 110
110 111 if ( ! is_wp_error( $response )
111 112 && 200 === wp_remote_retrieve_response_code( $response ) ) {
112 113 $data = LP_Helper::json_decode( wp_remote_retrieve_body( $response ) );
113 - $lp_cache->set_cache( $key_cache, $data, 5 * MINUTE_IN_SECONDS );
114 + $lp_cache->set_cache( $key_cache, $data, 2 * MINUTE_IN_SECONDS );
114 115 } else {
115 116 throw new Exception( $response->get_error_message() );
116 117 }
117 118 }
@@ -165,8 +166,10 @@
165 166 * @param object $addons List addons keyed by slug.
166 167 *
167 168 * @return object
168 169 * @throws Exception
170 + * @since 4.4.9
171 + * @version 1.0.0
169 172 */
170 173 public function get_addons_purchased( object $addons ): object {
171 174 $addons_purchase = LP_Settings::get_option( $this->key_purchase_addons, [] );
172 175 if ( empty( $addons_purchase ) ) {
@@ -176,32 +179,34 @@
176 179 $lp_cache = new LP_Cache( true );
177 180 $key_cache = 'addons_purchased_info';
178 181 $addons_cache = $lp_cache->get_cache( $key_cache );
179 182 if ( false !== $addons_cache ) {
180 - return json_decode( wp_json_encode( $addons_cache ) );
181 - }
183 + $data = json_decode( wp_json_encode( $addons_cache ) );
184 + } else {
185 + $args = [
186 + 'method' => 'POST',
187 + 'body' => [
188 + 'addons_purchase' => $addons_purchase,
189 + ],
190 + 'timeout' => 30,
191 + 'user-agent' => site_url(),
192 + ];
182 193
183 - $args = [
184 - 'method' => 'POST',
185 - 'body' => [
186 - 'addons_purchase' => $addons_purchase,
187 - ],
188 - 'timeout' => 30,
189 - 'user-agent' => site_url(),
190 - ];
194 + $result = wp_remote_post( $this->link_addons_purchased, $args );
195 + if ( is_wp_error( $result ) ) {
196 + throw new Exception( $result->get_error_message() );
197 + }
191 198
192 - $result = wp_remote_post( $this->link_addons_purchased, $args );
193 - if ( is_wp_error( $result ) ) {
194 - throw new Exception( $result->get_error_message() );
195 - }
199 + $data_str = wp_remote_retrieve_body( $result );
200 + if ( preg_match( '/^Error.*/', $data_str ) ) {
201 + throw new Exception( $data_str );
202 + }
196 203
197 - $data_str = wp_remote_retrieve_body( $result );
198 - if ( preg_match( '/^Error.*/', $data_str ) ) {
199 - throw new Exception( $data_str );
204 + $data = LP_Helper::json_decode( $data_str );
205 +
206 + $lp_cache->set_cache( $key_cache, $data, 12 * HOUR_IN_SECONDS );
200 207 }
201 208
202 - $data = LP_Helper::json_decode( $data_str );
203 -
204 209 foreach ( $addons as $key => $addon ) {
205 210 if ( isset( $data->{$key} ) ) {
206 211 $addons->{$key}->purchase_info = $data->{$key};
207 212 }
@@ -206,15 +211,13 @@
206 211 $addons->{$key}->purchase_info = $data->{$key};
207 212 }
208 213 }
209 214
210 - $lp_cache->set_cache( $key_cache, $addons );
211 -
212 215 return $addons;
213 216 }
214 217
215 218 /**
216 - * Validate a purchase code with the add-ons service before storing it.
219 + * Get purchase info for an add-on from the ThimPress service and persist the code locally.
217 220 *
218 221 * @param string $addon_slug Add-on slug.
219 222 * @param string $purchase_code Purchase code.
220 223 *
@@ -220,9 +223,9 @@
220 223 *
221 224 * @return object Purchase information returned by the service.
222 225 * @throws Exception When the code cannot be validated.
223 226 */
224 - public function validate_and_save_purchase_code( string $addon_slug, string $purchase_code ): object {
227 + public function get_addon_purchase_info( string $addon_slug, string $purchase_code ): object {
225 228 $purchase_code = trim( $purchase_code );
226 229
227 230 if ( empty( $addon_slug ) || empty( $purchase_code ) ) {
228 231 throw new Exception( __( 'Purchase code is invalid!', 'learnpress' ) );
@@ -255,13 +258,13 @@
255 258 if ( ! is_object( $data ) || ! isset( $data->{$addon_slug} ) || ! is_object( $data->{$addon_slug} ) ) {
256 259 throw new Exception( __( 'Purchase code is invalid!', 'learnpress' ) );
257 260 }
258 261
259 - $key_purchase = LP_Settings::get_option( $this->key_purchase_addons, array() );
262 + /*$key_purchase = LP_Settings::get_option( $this->key_purchase_addons, array() );
260 263 $key_purchase[ $addon_slug ] = $purchase_code;
261 264 LP_Settings::update_option( $this->key_purchase_addons, $key_purchase );
262 265
263 - $this->clear_addons_purchased_cache();
266 + $this->clear_addons_purchased_cache();*/
264 267
265 268 return $data->{$addon_slug};
266 269 }
267 270
@@ -324,9 +327,8 @@
324 327 // For addon must buy.
325 328 if ( 0 == $addon['is_free'] ) {
326 329 $key_purchase = LP_Settings::get_option( $this->key_purchase_addons, [] );
327 330 $key_purchase[ $addon['slug'] ] = $purchase_code;
328 - LP_Settings::update_option( $this->key_purchase_addons, $key_purchase );
329 331
330 332 $args['body']['purchase_code'] = $purchase_code;
331 333 }
332 334
@@ -485,8 +487,9 @@
485 487 // Save keys purchase code of addons to table WP Options.
486 488 $key_purchases = LP_Settings::get_option( $this->key_purchase_addons, [] );
487 489 $key_purchases[ $addon_slug ] = $purchase_code;
488 490 LP_Settings::update_option( $this->key_purchase_addons, $key_purchases );
491 + $this->clear_addons_purchased_cache();
489 492 }
490 493
491 494 /**
492 495 * Get list addon have new version.