From 3e7aa4076346ea1da36bf6f3e28e12d76ac6f89f Mon Sep 17 00:00:00 2001 From: trgino Date: Sun, 10 Sep 2023 20:29:40 +0300 Subject: [PATCH] v3.7.7 released --- core/library/Optimisthub_Update_Checker.php | 41 +++++++++++---------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/core/library/Optimisthub_Update_Checker.php b/core/library/Optimisthub_Update_Checker.php index f613b89..4beedd5 100644 --- a/core/library/Optimisthub_Update_Checker.php +++ b/core/library/Optimisthub_Update_Checker.php @@ -17,7 +17,7 @@ class Optimisthub_Update_Checker public function __construct() { - $this->plugin_slug = 'moka-woocommerce-master'; + $this->plugin_slug = OPTIMISTHUB_MOKA_BASENAME; $this->version = OPTIMISTHUB_MOKA_PAY_VERSION; $this->cache_key = 'moka_woocommerce_update_check'; $this->cache_allowed = true; @@ -37,13 +37,13 @@ public function __construct() public function request() { $remote = get_transient( $this->cache_key ); - if( false === $remote || ! $this->cache_allowed ) - { + if( $remote && $this->cache_allowed ) { + return $remote; + }else{ $remote = wp_remote_post( $this->endpoint, [ 'method' => 'POST', - 'timeout' => 45, - 'redirection' => 5, + 'timeout' => 30, 'httpversion' => '1.0', 'blocking' => true, 'headers' => [], @@ -58,26 +58,27 @@ public function request() ); if( - is_wp_error( $remote ) - || 200 !== wp_remote_retrieve_response_code( $remote ) + is_wp_error( $remote ) + || 200 != wp_remote_retrieve_response_code( $remote ) || empty( wp_remote_retrieve_body( $remote ) ) ) { return false; } + + $remote = json_decode( wp_remote_retrieve_body( $remote ) ); + + if( !$remote || !isset($remote->data) ) + { + return false; + } + + $remote = data_get($remote,'data'); set_transient( $this->cache_key, $remote, DAY_IN_SECONDS ); - } - - $remote = json_decode( wp_remote_retrieve_body( $remote ) ); - $remote = data_get($remote, 'data'); + return $remote; - if( ! $remote ) - { - return false; } - - return $remote; } /** @@ -145,7 +146,7 @@ public function info( $response, $action, $args ) */ public function update( $transient ) { - if ( empty($transient->checked ) ) { + if ( isset($transient->checked ) && empty($transient->checked ) ) { return $transient; } @@ -157,7 +158,7 @@ public function update( $transient ) { ) { $_response = new stdClass(); $_response->slug = $this->plugin_slug; - $_response->plugin = 'moka-woocommerce-master/index.php'; + $_response->plugin = OPTIMISTHUB_MOKA_BASENAME; $_response->new_version = data_get($remote, 'version'); $_response->tested = data_get($remote, 'tested'); $_response->package = data_get($remote, 'download_url'); @@ -182,8 +183,8 @@ public function purge() global $options; if ( $this->cache_allowed - && 'update' === data_get($options, 'action') && $options['action'] - && 'plugin' === data_get($options, 'type') && $options[ 'type' ] + && isset($options['action']) && $options['action'] && 'update' === data_get($options, 'action') + && isset($options['type']) && $options['type'] && 'plugin' === data_get($options, 'type') ) { delete_transient( $this->cache_key ); }