Automattic\WP\Cron_Control\Lock::reset_lock PHP Method

reset_lock() public static method

Clear a lock's current values, in order to free it
public static reset_lock ( $lock, $expires )
    public static function reset_lock($lock, $expires = 0)
    {
        wp_cache_set(self::get_key($lock), 0, null, $expires);
        wp_cache_set(self::get_key($lock, 'timestamp'), time(), null, $expires);
        return true;
    }

Usage Example

 /**
  * Retrieve a lock's current value, or reset it
  */
 private function get_reset_lock($args, $assoc_args, $lock_name, $lock_limit, $lock_description)
 {
     // Output information about the lock
     \WP_CLI::line($lock_description . "\n");
     \WP_CLI::line(sprintf(__('Maximum: %s', 'automattic-cron-control'), number_format_i18n($lock_limit)) . "\n");
     // Reset requested
     if (isset($assoc_args['reset'])) {
         \WP_CLI::warning(__('Resetting lock...', 'automattic-cron-control') . "\n");
         $lock = \Automattic\WP\Cron_Control\Lock::get_lock_value($lock_name);
         $timestamp = \Automattic\WP\Cron_Control\Lock::get_lock_timestamp($lock_name);
         \WP_CLI::line(sprintf(__('Previous value: %s', 'automattic-cron-control'), number_format_i18n($lock)));
         \WP_CLI::line(sprintf(__('Previously modified: %s GMT', 'automattic-cron-control'), date(TIME_FORMAT, $timestamp)) . "\n");
         \WP_CLI::confirm(sprintf(__('Are you sure you want to reset this lock?', 'automattic-cron-control')));
         \WP_CLI::line('');
         \Automattic\WP\Cron_Control\Lock::reset_lock($lock_name);
         \WP_CLI::success(__('Lock reset', 'automattic-cron-control') . "\n");
         \WP_CLI::line(__('New lock values:', 'automattic-cron-control'));
     }
     // Output lock state
     $lock = \Automattic\WP\Cron_Control\Lock::get_lock_value($lock_name);
     $timestamp = \Automattic\WP\Cron_Control\Lock::get_lock_timestamp($lock_name);
     \WP_CLI::line(sprintf(__('Current value: %s', 'automattic-cron-control'), number_format_i18n($lock)));
     \WP_CLI::line(sprintf(__('Last modified: %s GMT', 'automattic-cron-control'), date(TIME_FORMAT, $timestamp)));
 }