diff --git a/classes/ActionScheduler_OptionLock.php b/classes/ActionScheduler_OptionLock.php index 547857a0..4b8d9750 100644 --- a/classes/ActionScheduler_OptionLock.php +++ b/classes/ActionScheduler_OptionLock.php @@ -32,7 +32,7 @@ public function set( $lock_type ) { $new_lock_value = $this->new_lock_value( $lock_type ); // The lock may not exist yet, or may have been deleted. - if ( empty( $existing_lock_value ) ) { + if ( null === $existing_lock_value ) { return (bool) $wpdb->insert( $wpdb->options, array( @@ -65,7 +65,7 @@ public function set( $lock_type ) { * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. */ public function get_expiration( $lock_type ) { - return $this->get_expiration_from( $this->get_existing_lock( $lock_type ) ); + return $this->get_expiration_from( (string) $this->get_existing_lock( $lock_type ) ); } /** @@ -106,18 +106,24 @@ protected function get_key( $lock_type ) { * * @param string $lock_type A string to identify different lock types. * - * @return string + * @return string|null */ private function get_existing_lock( $lock_type ) { global $wpdb; // Now grab the existing lock value, if there is one. - return (string) $wpdb->get_var( + // get_var() returns null for the empty string ('') so we must use get_row(). + $row = $wpdb->get_row( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s", $this->get_key( $lock_type ) ) ); + + if ($row) { + return $row->option_value; + } + return null; } /**