Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from newfold-labs/feature/shorter-expiration-fo…
Browse files Browse the repository at this point in the history
…r-provided-data

use a flag `is_provided` to set a shorter expiration date for cdata
  • Loading branch information
circlecube authored Dec 16, 2022
2 parents 8e83090 + 6467b05 commit f5bb379
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions includes/CustomerBluehost.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class CustomerBluehost {
*/
private const RETRY_COUNT = 'bh_cdata_retry_count';

private static $is_provided = false;

/**
* Collect customer data
*
Expand Down Expand Up @@ -151,9 +153,15 @@ private static function refresh_data() {
*/
private static function save_data( $data ) {

// save to option and set new expiry
// save data to option
\update_option( self::CUST_DATA, $data );
\update_option( self::CUST_DATA_EXP, time() + MONTH_IN_SECONDS ); // set expiration to now + 1 month (30 days)

// set expiration
if ( self::$is_provided ) {
\update_option( self::CUST_DATA_EXP, time() + DAY_IN_SECONDS ); // set expiration to now + 1 day
} else {
\update_option( self::CUST_DATA_EXP, time() + MONTH_IN_SECONDS ); // set expiration to now + 1 month (30 days)
}
}

/**
Expand All @@ -175,6 +183,7 @@ public static function provided( $path ) {
&& is_object( $decoded = json_decode( $provided ) )
) {
$provided = $decoded;
self::$is_provided = true;
\delete_option( $key );
}
break;
Expand Down Expand Up @@ -252,6 +261,7 @@ public static function connect( $path ) {
}

self::clear_throttle();
self::$is_provided = false;
return json_decode( wp_remote_retrieve_body( $response ) );
}

Expand Down

0 comments on commit f5bb379

Please sign in to comment.