Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions classes/ActionScheduler_OptionLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 ) );
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down