PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 2.3.8
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v2.3.8
2.9.1 2.9.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 2.0.0 2.1.0 2.2.0 2.3.2 2.3.3 2.3.5 2.3.6 2.3.8 2.3.9 2.4.3 All 37 releases
← All changes | freemius/includes/class-fs-user-lock.php +10 -46 1.3.02.3.8 View file →
@@ -9,20 +9,18 @@
9 9 if ( ! defined( 'ABSPATH' ) ) {
10 10 exit;
11 11 }
12 12
13 + require_once WP_FS__DIR_INCLUDES . '/class-fs-lock.php';
14 +
13 15 /**
14 16 * Class FS_User_Lock
15 17 */
16 18 class FS_User_Lock {
17 19 /**
18 - * @var int
20 + * @var FS_Lock
19 21 */
20 - private $_wp_user_id;
21 - /**
22 - * @var int
23 - */
24 - private $_thread_id;
22 + private $_lock;
25 23
26 24 #--------------------------------------------------------------------------------
27 25 #region Singleton
28 26 #--------------------------------------------------------------------------------
@@ -48,13 +46,13 @@
48 46
49 47 #endregion
50 48
51 49 private function __construct() {
52 - $this->_wp_user_id = Freemius::get_current_wp_user_id();
53 - $this->_thread_id = mt_rand( 0, 32000 );
50 + $current_user_id = Freemius::get_current_wp_user_id();
51 +
52 + $this->_lock = new FS_Lock( "locked_{$current_user_id}" );
54 53 }
55 54
56 -
57 55 /**
58 56 * Try to acquire lock. If the lock is already set or is being acquired by another locker, don't do anything.
59 57 *
60 58 * @author Vova Feldman (@svovaf)
@@ -64,22 +62,9 @@
64 62 *
65 63 * @return bool TRUE if successfully acquired lock.
66 64 */
67 65 function try_lock( $expiration = 0 ) {
68 - if ( $this->is_locked() ) {
69 - // Already locked.
70 - return false;
71 - }
72 -
73 - set_site_transient( "locked_{$this->_wp_user_id}", $this->_thread_id, $expiration );
74 -
75 - if ( $this->has_lock() ) {
76 - set_site_transient( "locked_{$this->_wp_user_id}", true, $expiration );
77 -
78 - return true;
79 - }
80 -
81 - return false;
66 + return $this->_lock->try_lock( $expiration );
82 67 }
83 68
84 69 /**
85 70 * Acquire lock regardless if it's already acquired by another locker or not.
@@ -89,24 +74,12 @@
89 74 *
90 75 * @param int $expiration
91 76 */
92 77 function lock( $expiration = 0 ) {
93 - set_site_transient( "locked_{$this->_wp_user_id}", true, $expiration );
78 + $this->_lock->lock( $expiration );
94 79 }
95 80
96 81 /**
97 - * Checks if lock is currently acquired.
98 - *
99 - * @author Vova Feldman (@svovaf)
100 - * @since 2.1.0
101 - *
102 - * @return bool
103 - */
104 - function is_locked() {
105 - return ( false !== get_site_transient( "locked_{$this->_wp_user_id}" ) );
106 - }
107 -
108 - /**
109 82 * Unlock the lock.
110 83 *
111 84 * @author Vova Feldman (@svovaf)
112 85 * @since 2.1.0
@@ -111,16 +84,7 @@
111 84 * @author Vova Feldman (@svovaf)
112 85 * @since 2.1.0
113 86 */
114 87 function unlock() {
115 - delete_site_transient( "locked_{$this->_wp_user_id}" );
116 - }
117 -
118 - /**
119 - * Checks if lock is currently acquired by the current locker.
120 - *
121 - * @return bool
122 - */
123 - private function has_lock() {
124 - return ( $this->_thread_id == get_site_transient( "locked_{$this->_wp_user_id}" ) );
88 + $this->_lock->unlock();
125 89 }
126 90 }