Skip to content

Commit 52c8e12

Browse files
committed
fix settings cached options
1 parent 8640f6d commit 52c8e12

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

inc/admin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ public function daily_sync() {
10761076
// Here the account got deactivated, in this case we check if the user is using offloaded images and we roll them back.
10771077
if ( isset( $data['status'] ) && $data['status'] === 'inactive' ) {
10781078
// We check if the user has images offloaded.
1079-
if ( $this->settings->get( 'transfer_status' ) !== 'offload_images' ) {
1079+
if ( $this->settings->get( 'offload_media' ) === 'disabled' ) {
10801080
return;
10811081
}
10821082

@@ -1085,6 +1085,7 @@ public function daily_sync() {
10851085
if ( $in_progress ) {
10861086
$this->settings->update( 'offloading_status', 'disabled' );
10871087
}
1088+
$this->settings->update( 'rollback_status', 'enabled' );
10881089
// We start the rollback process.
10891090
Optml_Logger::instance()->add_log( 'rollback_images', 'Account deactivated, starting rollback.' );
10901091
Optml_Media_Offload::get_image_count( 'rollback_images', false );

inc/settings.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class Optml_Settings {
113113
*
114114
* @var array All options.
115115
*/
116-
private $options;
116+
private static $options;
117117

118118
/**
119119
* Optml_Settings constructor.
@@ -123,11 +123,11 @@ public function __construct() {
123123

124124
$this->namespace = OPTML_NAMESPACE . '_settings';
125125
$this->default_schema = apply_filters( 'optml_default_settings', $this->default_schema );
126-
$this->options = wp_parse_args( get_option( $this->namespace, $this->default_schema ), $this->default_schema );
126+
self::$options = wp_parse_args( get_option( $this->namespace, $this->default_schema ), $this->default_schema );
127127

128128
if ( defined( 'OPTIML_ENABLED_MU' ) && defined( 'OPTIML_MU_SITE_ID' ) && $this->to_boolean( constant( 'OPTIML_ENABLED_MU' ) ) && constant( 'OPTIML_MU_SITE_ID' ) ) {
129129
switch_to_blog( constant( 'OPTIML_MU_SITE_ID' ) );
130-
$this->options = wp_parse_args( get_option( $this->namespace, $this->default_schema ), $this->default_schema );
130+
self::$options = wp_parse_args( get_option( $this->namespace, $this->default_schema ), $this->default_schema );
131131
restore_current_blog();
132132
}
133133

@@ -164,7 +164,7 @@ public function __construct() {
164164
continue;
165165
}
166166
$sanitized_value = ( $type === 'bool' ) ? ( $value === 'on' ? 'enabled' : 'disabled' ) : (int) $value;
167-
$this->options[ $key ] = $sanitized_value;
167+
self::$options[ $key ] = $sanitized_value;
168168
}
169169
}
170170
}
@@ -201,7 +201,7 @@ public function get( $key ) {
201201
return null;
202202
}
203203

204-
return isset( $this->options[ $key ] ) ? $this->options[ $key ] : '';
204+
return isset( self::$options[ $key ] ) ? self::$options[ $key ] : '';
205205
}
206206

207207
/**
@@ -412,13 +412,13 @@ public function update_frontend_banner_from_remote( $value ) {
412412
return false;
413413
}
414414

415-
$opts = $this->options;
415+
$opts = self::$options;
416416
$opts['banner_frontend'] = $value ? 'enabled' : 'disabled';
417417

418418
$update = update_option( $this->namespace, $opts, false );
419419

420420
if ( $update ) {
421-
$this->options = $opts;
421+
self::$options = $opts;
422422
}
423423

424424
return $update;
@@ -440,7 +440,7 @@ public function update( $key, $value ) {
440440
if ( ! $this->is_main_mu_site() ) {
441441
return false;
442442
}
443-
$opt = $this->options;
443+
$opt = self::$options;
444444

445445
if ( $key === 'banner_frontend' ) {
446446
$api = new Optml_Api();
@@ -450,9 +450,11 @@ public function update( $key, $value ) {
450450
}
451451

452452
$opt[ $key ] = $value;
453+
453454
$update = update_option( $this->namespace, $opt, false );
455+
454456
if ( $update ) {
455-
$this->options = $opt;
457+
self::$options = $opt;
456458
}
457459
if ( apply_filters( 'optml_dont_trigger_settings_updated', false ) === false ) {
458460
do_action( 'optml_settings_updated' );
@@ -695,11 +697,11 @@ public function get_cdn_url() {
695697
*/
696698
public function reset() {
697699
$reset_schema = $this->default_schema;
698-
$reset_schema['filters'] = $this->options['filters'];
700+
$reset_schema['filters'] = self::$options['filters'];
699701

700702
$update = update_option( $this->namespace, $reset_schema );
701703
if ( $update ) {
702-
$this->options = $reset_schema;
704+
self::$options = $reset_schema;
703705
}
704706
wp_unschedule_hook( Optml_Admin::SYNC_CRON );
705707
wp_unschedule_hook( Optml_Admin::ENRICH_CRON );

0 commit comments

Comments
 (0)