WC_Install::create_lock
Attempts to acquire an installation lock.
Method of the class: WC_Install{}
No Hooks.
Returns
true|false. True if a lock was acquired, otherwise false.
Usage
$result = WC_Install::create_lock(): bool;
WC_Install::create_lock() WC Install::create lock code WC 10.7.0
private static function create_lock(): bool {
global $wpdb;
// Insert will fail if it already exists so this functions as a mutex.
$created_lock = $wpdb->query(
$wpdb->prepare(
"INSERT INTO {$wpdb->options} (option_name, option_value, autoload) VALUES ('wc_installing', %d, 'no')",
time()
)
);
// Take over the lock if it's stale (older than 10 minutes).
if ( ! $created_lock ) {
$created_lock = $wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->options} SET option_value = %d WHERE option_name = 'wc_installing' AND option_value < %d",
time(),
time() - ( MINUTE_IN_SECONDS * 10 )
)
);
}
if ( $created_lock ) {
// Set the transient for backward compatibility in case others are relying on it to signal an ongoing install.
set_transient( 'wc_installing', 'yes', MINUTE_IN_SECONDS * 10 );
return true;
}
return false;
}