• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / WP_Upgrader::create_lock() – Creates a lock using WordPress options.

You appear to be a bot. Output may be restricted

Description

Creates a lock using WordPress options.

Usage

$bool = WP_Upgrader::create_lock( $lock_name, $release_timeout );

Parameters

$lock_name
( string ) required – The name of this unique lock.
$release_timeout
( int ) optional – Optional. The duration in seconds to respect an existing lock. Default: 1 hour.

Returns

bool False if a lock couldn't be created or if the lock is still valid. True otherwise.

Source

File name: wordpress/wp-admin/includes/class-wp-upgrader.php
Lines:

1 to 34 of 34
  public static function create_lock( $lock_name, $release_timeout = null ) {
    global $wpdb;
    if ( ! $release_timeout ) {
      $release_timeout = HOUR_IN_SECONDS;
    }
    $lock_option = $lock_name . '.lock';

    // Try to lock.
    $lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_option, time() ) );

    if ( ! $lock_result ) {
      $lock_result = get_option( $lock_option );

      // If a lock couldn't be created, and there isn't a lock, bail.
      if ( ! $lock_result ) {
        return false;
      }

      // Check to see if the lock is still valid. If it is, bail.
      if ( $lock_result > ( time() - $release_timeout ) ) {
        return false;
      }

      // There must exist an expired lock, clear it and re-gain it.
      WP_Upgrader::WP_Upgrader::release_lock( $lock_name );

      return WP_Upgrader::WP_Upgrader::create_lock( $lock_name, $release_timeout );
    }

    // Update the lock, as by this point we've definitely got a lock, just need to fire the actions.
    update_option( $lock_option, time() );

    return true;
  }
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 25th November 2019

Primary Sidebar

Information

Function name: WP_Upgrader::create_lock
Class ref: WP_Upgrader
Plugin ref: WordPress
Version: 5.7.1
Sourcefile: wp-admin/includes/class-wp-upgrader.php
File ref: wp-admin/includes/class-wp-upgrader.php
Deprecated?: No
API Letters: C,L,U,W

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.7.1
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites