Skip to content

Commit

Permalink
prevent update of transient data if the callback returns a WP_Error o…
Browse files Browse the repository at this point in the history
…r false
  • Loading branch information
Ryan Kanner committed Dec 12, 2016
1 parent 157196a commit 8c5ea5f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions includes/class-dfm-transients.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public function set( $data ) {
return;
}

if ( false === $data || is_wp_error( $data ) ) {
return;
}

switch ( $this->transient_object->cache_type ) {
case 'transient':
$this->save_to_transient( $data );
Expand Down Expand Up @@ -204,19 +208,19 @@ private function get_from_transient() {

if ( false === $data ) {
$data = call_user_func( $this->transient_object->callback, $this->modifier );
$this->save_to_transient( $data );
$this->set( $data );
} elseif ( $this->is_expired( $data ) && ! $this->is_locked() ) {
$this->lock_update();
if ( $this->should_soft_expire() ) {
new DFM_Async_Handler( $this->transient, $this->modifier, $this->lock_key );
} else {
$data = call_user_func( $this->transient_object->callback, $this->modifier );
$this->save_to_transient( $data );
$this->set( $data );
$this->unlock_update();
}
}

if ( $this->should_expire() && $this->should_soft_expire() && is_array( $data ) ) {
if ( $this->should_expire() && $this->should_soft_expire() && is_array( $data ) && array_key_exists( 'data', $data ) ) {
$data = $data['data'];
}

Expand All @@ -237,19 +241,19 @@ private function get_from_meta( $type ) {

if ( false === $data ) {
$data = call_user_func( $this->transient_object->callback, $this->modifier );
$this->save_to_metadata( $data, $type );
$this->set( $data );
} elseif ( $this->is_expired( $data ) && ! $this->is_locked() ) {
$this->lock_update();
if ( $this->should_soft_expire() ) {
new DFM_Async_Handler( $this->transient, $this->modifier, $this->lock_key );
} else {
$data = call_user_func( $this->transient_object->callback, $this->modifier );
$this->save_to_metadata( $data, $type );
$this->set( $data );
$this->unlock_update();
}
}

if ( $this->should_expire() && is_array( $data ) ) {
if ( $this->should_expire() && is_array( $data ) && array_key_exists( 'data', $data ) ) {
$data = $data['data'];
}

Expand Down

0 comments on commit 8c5ea5f

Please sign in to comment.