diff --git a/lib/ecwid_api_v3.php b/lib/ecwid_api_v3.php index 6ff11d31..88b0873d 100644 --- a/lib/ecwid_api_v3.php +++ b/lib/ecwid_api_v3.php @@ -583,8 +583,13 @@ public function get_store_profile( $disable_cache = false ) { $result = EcwidPlatform::fetch_url( $url, $options ); if ( @$result['code'] == '403' ) { - self::set_api_status( self::API_STATUS_ERROR_TOKEN ); - self::save_token( '' ); + if ( get_option( EcwidPlatform::OPTION_ECWID_CHECK_API_RETRY_AFTER, 0 ) == 0 ) { + self::set_api_status( self::API_STATUS_ERROR_TOKEN ); + self::save_token( '' ); + } else { + update_option( EcwidPlatform::OPTION_ECWID_CHECK_API_RETRY_AFTER, time() + 5 * MINUTE_IN_SECONDS ); + } + return false; } @@ -596,7 +601,7 @@ public function get_store_profile( $disable_cache = false ) { $profile = json_decode( $result['data'] ); - EcwidPlatform::cache_set( self::PROFILE_CACHE_NAME, $profile, 60 * 5 ); + EcwidPlatform::cache_set( self::PROFILE_CACHE_NAME, $profile, 10 * MINUTE_IN_SECONDS ); if ( $profile && isset( $profile->settings ) && isset( $profile->settings->hideOutOfStockProductsInStorefront ) ) { EcwidPlatform::set( 'hide_out_of_stock', $profile->settings->hideOutOfStockProductsInStorefront ); diff --git a/lib/ecwid_platform.php b/lib/ecwid_platform.php index e99e7ced..118244db 100644 --- a/lib/ecwid_platform.php +++ b/lib/ecwid_platform.php @@ -20,6 +20,8 @@ class EcwidPlatform { const OPTION_LOG_CACHE = 'ecwid_log_cache'; const OPTION_ECWID_PLUGIN_DATA = 'ecwid_plugin_data'; + const OPTION_ECWID_CHECK_API_RETRY_AFTER = 'ecwid_api_check_retry_after'; + const TRANSIENTS_LIMIT = 500; public static function get_store_id() { @@ -245,7 +247,7 @@ public static function report_error( $error ) { } public static function fetch_url( $url, $options = array() ) { - $api_check_retry_after = get_option( 'ecwid_api_check_retry_after', 0 ); + $api_check_retry_after = get_option( self::OPTION_ECWID_CHECK_API_RETRY_AFTER, 0 ); if ( $api_check_retry_after > time() ) { return array( @@ -275,7 +277,7 @@ public static function fetch_url( $url, $options = array() ) { $retry_after = intval( wp_remote_retrieve_header( $result, 'retry-after' ) ); if ( $retry_after > 0 ) { - update_option( 'ecwid_api_check_retry_after', time() + $retry_after ); + update_option( self::OPTION_ECWID_CHECK_API_RETRY_AFTER, time() + $retry_after ); } } @@ -308,6 +310,10 @@ public static function fetch_url( $url, $options = array() ) { ); } + if ( $return['code'] == 200 ) { + update_option( self::OPTION_ECWID_CHECK_API_RETRY_AFTER, 0 ); + } + return $return; }