PluginProbe ʕ •ᴥ•ʔ
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel / trunk
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel vtrunk
trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / freemius / includes / class-fs-lock.php
foogallery / freemius / includes Last commit date
customizer 7 months ago debug 2 years ago entities 7 months ago managers 7 months ago sdk 2 years ago supplements 3 years ago .DS_Store 7 months ago class-freemius-abstract.php 3 years ago class-freemius.php 7 months ago class-fs-admin-notices.php 3 years ago class-fs-api.php 7 months ago class-fs-garbage-collector.php 7 months ago class-fs-hook-snapshot.php 7 months ago class-fs-lock.php 3 years ago class-fs-logger.php 7 months ago class-fs-options.php 8 years ago class-fs-plugin-updater.php 7 months ago class-fs-security.php 7 months ago class-fs-storage.php 7 months ago class-fs-user-lock.php 3 years ago fs-core-functions.php 7 months ago fs-essential-functions.php 2 years ago fs-html-escaping-functions.php 7 months ago fs-plugin-info-dialog.php 7 months ago index.php 3 years ago l10n.php 3 years 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 }