: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace WPML\Utilities;
class Lock implements ILock {
public function __construct( \wpdb $wpdb, $name ) {
$this->name = 'wpml.' . $name . '.lock';
* Creates a lock using WordPress options ( Based on WP class WP_Upgrader ).
* @param int $release_timeout Optional. The duration in seconds to respect an existing lock.
* @return bool False if a lock couldn't be created or if the lock is still valid. True otherwise.
public function create( $release_timeout = null ) {
if ( ! $release_timeout ) {
$release_timeout = HOUR_IN_SECONDS;
$lock_result = $this->wpdb->query( $this->wpdb->prepare( "INSERT IGNORE INTO {$this->wpdb->options} ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $this->name, time() ) );
$lock_result = get_option( $this->name );
// If a lock couldn't be created, and there isn't a lock, bail.
// Check to see if the lock is still valid. If it is, bail.
if ( $lock_result > ( time() - $release_timeout ) ) {
// There must exist an expired lock, clear it and re-gain it.
return $this->create( $release_timeout );
// Update the lock, as by this point we've definitely got a lock, just need to fire the actions.
update_option( $this->name, time() );
* Releases an upgrader lock.
* @return bool True if the lock was successfully released. False on failure.
public function release() {
return delete_option( $this->name );