PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.37
Code Manager v1.0.37
1.0.48 1.0.47 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
code-manager / freemius / includes / class-fs-lock.php
code-manager / freemius / includes Last commit date
customizer 1 year ago debug 1 year ago entities 1 year ago managers 1 year ago sdk 1 year ago supplements 1 year ago class-freemius-abstract.php 1 year ago class-freemius.php 1 year ago class-fs-admin-notices.php 1 year ago class-fs-api.php 1 year ago class-fs-garbage-collector.php 1 year ago class-fs-lock.php 1 year ago class-fs-logger.php 1 year ago class-fs-options.php 1 year ago class-fs-plugin-updater.php 1 year ago class-fs-security.php 1 year ago class-fs-storage.php 1 year ago class-fs-user-lock.php 1 year ago fs-core-functions.php 1 year ago fs-essential-functions.php 1 year ago fs-html-escaping-functions.php 1 year ago fs-plugin-info-dialog.php 1 year ago index.php 1 year ago l10n.php 1 year ago
class-fs-lock.php
110 lines
1 <?php
2 /**
3 * @package Freemius
4 * @copyright Copyright (c) 2015, Freemius, Inc.
5 * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6 * @since 2.5.1
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Class FS_Lock
15 *
16 * @author Vova Feldman (@svovaf)
17 * @since 2.5.1
18 */
19 class FS_Lock {
20 /**
21 * @var int Random ID representing the current PHP thread.
22 */
23 private static $_thread_id;
24 /**
25 * @var string
26 */
27 private $_lock_id;
28
29 /**
30 * @param string $lock_id
31 */
32 function __construct( $lock_id ) {
33 if ( ! fs_starts_with( $lock_id, WP_FS___OPTION_PREFIX ) ) {
34 $lock_id = WP_FS___OPTION_PREFIX . $lock_id;
35 }
36
37 $this->_lock_id = $lock_id;
38
39 if ( ! isset( self::$_thread_id ) ) {
40 self::$_thread_id = mt_rand( 0, 32000 );
41 }
42 }
43
44 /**
45 * Try to acquire lock. If the lock is already set or is being acquired by another locker, don't do anything.
46 *
47 * @param int $expiration
48 *
49 * @return bool TRUE if successfully acquired lock.
50 */
51 function try_lock( $expiration = 0 ) {
52 if ( $this->is_locked() ) {
53 // Already locked.
54 return false;
55 }
56
57 set_site_transient( $this->_lock_id, self::$_thread_id, $expiration );
58
59 if ( $this->has_lock() ) {
60 $this->lock($expiration);
61
62 return true;
63 }
64
65 return false;
66 }
67
68 /**
69 * Acquire lock regardless if it's already acquired by another locker or not.
70 *
71 * @author Vova Feldman (@svovaf)
72 * @since 2.1.0
73 *
74 * @param int $expiration
75 */
76 function lock( $expiration = 0 ) {
77 set_site_transient( $this->_lock_id, true, $expiration );
78 }
79
80 /**
81 * Checks if lock is currently acquired.
82 *
83 * @author Vova Feldman (@svovaf)
84 * @since 2.1.0
85 *
86 * @return bool
87 */
88 function is_locked() {
89 return ( false !== get_site_transient( $this->_lock_id ) );
90 }
91
92 /**
93 * Unlock the lock.
94 *
95 * @author Vova Feldman (@svovaf)
96 * @since 2.1.0
97 */
98 function unlock() {
99 delete_site_transient( $this->_lock_id );
100 }
101
102 /**
103 * Checks if lock is currently acquired by the current locker.
104 *
105 * @return bool
106 */
107 protected function has_lock() {
108 return ( self::$_thread_id == get_site_transient( $this->_lock_id ) );
109 }
110 }