From 8c5ea5ffb381159128a56bce4b11b12756a453dc Mon Sep 17 00:00:00 2001 From: Ryan Kanner Date: Mon, 12 Dec 2016 12:41:41 -0700 Subject: [PATCH] prevent update of transient data if the callback returns a WP_Error or false --- includes/class-dfm-transients.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/includes/class-dfm-transients.php b/includes/class-dfm-transients.php index 1158635..c9933ed 100644 --- a/includes/class-dfm-transients.php +++ b/includes/class-dfm-transients.php @@ -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 ); @@ -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']; } @@ -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']; }