PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 2.0.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v2.0.2
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
← All changes | includes/Utils/Options.php +40 -77 3.6.32.0.2 View file →
@@ -9,21 +9,21 @@
9 9 use function get_current_user_id;
10 10
11 11 class Options extends Base {
12 12 /**
13 - * Current User Id
13 + * Currest User Id
14 14 * @var integer
15 15 */
16 - private $current_user;
16 + private $current_user = 0;
17 17
18 18 /**
19 19 * User has any api?
20 20 * @var boolean
21 21 */
22 - private $has_api;
22 + private $has_api = false;
23 23
24 24 /**
25 - * Automatically invoked and set up the properties.
25 + * Autometically invoked and setup the properties.
26 26 */
27 27 public function __construct(){
28 28 $this->current_user = get_current_user_id();
29 29 $this->has_api = ! empty( $this->get( 'api_key', '', $this->current_user ) );
@@ -32,9 +32,9 @@
32 32 /**
33 33 * Get the current user ID.
34 34 * @return int
35 35 */
36 - public function current_user_id(): int {
36 + public function current_user_id(){
37 37 return $this->current_user;
38 38 }
39 39
40 40 /**
@@ -40,104 +40,101 @@
40 40 /**
41 41 * Can a user link another templately account in a setup?.
42 42 * @return boolean
43 43 */
44 - public function link_account(): bool {
45 - return $this->who_am_i() === 'link' && ! $this->has_api;
44 + public function link_account() {
45 + return $this->whoami() === 'link' && ! $this->has_api;
46 46 }
47 47
48 - public function unlink_account(): bool {
49 - return ( $this->who_am_i() === 'link' || $this->who_am_i() === 'local' ) && $this->has_api;
48 + public function unlink_account() {
49 + return ( $this->whoami() === 'link' || $this->whoami() === 'local' ) && $this->has_api;
50 50 }
51 -
52 51 /**
53 52 * Get determined who am I.
54 53 * @return string
55 54 */
56 - public function who_am_i(): string {
57 - $_who_am_i = 'local';
55 + public function whoami(){
56 + $_whoami = 'local';
58 57
59 58 if( $this->is_global() > 0 && $this->is_global() === $this->current_user ) {
60 - $_who_am_i = 'global';
59 + $_whoami = 'global';
61 60 }
62 61
63 62 if( $this->is_global() > 0 && $this->is_global() !== $this->current_user ) {
64 - $_who_am_i = 'link';
63 + $_whoami = 'link';
65 64 }
66 65
67 66 if( $this->is_global() == 0 ) {
68 - $_who_am_i = 'local';
67 + $_whoami = 'local';
69 68 }
70 69
71 - return $_who_am_i;
70 + return $_whoami;
72 71 }
73 -
74 72 /**
75 73 * Get user id determine dynamically
76 74 * @return integer
77 75 */
78 - private function user_id(): int {
79 - $_who_am_i = $this->who_am_i();
76 + private function user_id(){
77 + $_whoami = $this->whoami();
78 + // Helper::log( '_whoami: ' . $_whoami );
80 79
81 80 if( ! empty( $_SERVER['REQUEST_URI'] ) ) {
82 81 $parse_uri = explode( '/', substr( $_SERVER['REQUEST_URI'], 0, strpos( $_SERVER['REQUEST_URI'], '?' ) ) );
83 - if( $_who_am_i === 'link' && array_pop( $parse_uri ) === 'login' ) {
82 + if( $_whoami === 'link' && array_pop( $parse_uri ) === 'login' ) {
84 83 return $this->current_user;
85 84 }
86 85 }
87 86
88 - if( $_who_am_i === 'link' && $this->has_api ) {
87 + if( $_whoami === 'link' && $this->has_api ) {
89 88 return $this->current_user;
90 89 }
91 90
92 - return $_who_am_i === 'local' ? $this->current_user : $this->is_global();
91 + return $_whoami === 'local' ? $this->current_user : $this->is_global();
93 92 }
94 -
95 93 /**
96 94 * Globally logged in and the User ID of globally logged-in user.
97 95 * @return integer
98 96 */
99 - public function is_global(): int {
97 + public function is_global(){
100 98 return intval( get_option('_templately_global_login', 0) );
101 99 }
102 -
103 100 /**
104 101 * Set global login flag
105 102 * @return boolean
106 103 */
107 - public static function set_global_login(): bool {
104 + public static function set_global_login() {
108 105 return update_option('_templately_global_login', get_current_user_id(), 'no');
109 106 }
110 -
111 107 /**
112 108 * Remove global login flag
113 109 * @return boolean
114 110 */
115 - public function remove_global_login(): bool {
111 + public function remove_global_login() {
116 112 return delete_option( '_templately_global_login' );
117 113 }
118 114
119 - public function is_globally_signed(): bool {
120 - return $this->who_am_i() !== 'local';
115 + public function is_globally_signed() {
116 + return $this->whoami() !== 'local';
121 117 }
122 -
123 - public function signed_as_global(): bool {
118 + public function signed_as_global() {
124 119 return $this->current_user === $this->is_global();
125 120 }
126 -
127 121 /**
128 - * Set optional user meta or option data
122 + * Set optional usermeta or option data
129 123 *
130 124 * @param string $key
131 125 * @param mixed $value
132 - * @param null $user_id
133 126 * @return boolean
134 127 */
135 - public function set( $key, $value, $user_id = null ): bool {
128 + public function set( $key, $value, $user_id = null ){
136 129 $key = '_templately_' . $key;
137 130
138 - $updated = $this->update_user_meta( $user_id, $key, $value );
131 + if( $user_id === null ) {
132 + $user_id = $this->user_id();
133 + }
139 134
135 + $updated = update_user_meta( $user_id, $key, $value );
136 +
140 137 if( $key === '_templately_api_key' && $updated ) {
141 138 $this->has_api = true;
142 139 }
143 140
@@ -142,11 +139,10 @@
142 139 }
143 140
144 141 return $updated;
145 142 }
146 -
147 143 /**
148 - * Get optional user meta or option data
144 + * Get optional usermeta or option data
149 145 *
150 146 * @param string $key
151 147 * @param mixed $default
152 148 * @return mixed
@@ -152,21 +148,20 @@
152 148 * @return mixed
153 149 */
154 150 public function get( $key, $default = false, $user_id = null ){
155 151 $key = '_templately_' . $key;
156 - $_user_meta = $this->get_user_meta( $user_id, $key, true );
152 + $_user_meta = get_user_meta( is_null( $user_id ) ? $this->user_id() : $user_id, $key, true );
157 153 return ! empty( $_user_meta ) ? $_user_meta : $default;
158 154 }
159 -
160 155 /**
161 - * Remove options data or user meta
156 + * Remove options data or usermeta
162 157 *
163 158 * @param string $key
164 159 * @return Options
165 160 */
166 - public function remove( string $key ): Options {
161 + public function remove( $key ){
167 162 $key = '_templately_' . $key;
168 - $updated = $this->delete_user_meta( $key );
163 + $updated = delete_user_meta( $this->user_id(), $key ); // delete user meta
169 164
170 165 if( $key === '_templately_api_key' && $updated ) {
171 166 $this->has_api = false;
172 167 }
@@ -173,40 +168,8 @@
173 168
174 169 return $this;
175 170 }
176 171
177 - public function get_user_meta( $user_id, $key = '', $single = false ) {
178 - $user_id = is_null( $user_id ) ? $this->user_id() : $user_id;
179 -
180 - if( ! is_multisite() ) {
181 - return get_user_meta( $user_id, $key, $single);
182 - }
183 -
184 - return get_user_option( $key, $user_id );
185 - }
186 -
187 - public function update_user_meta($user_id, $meta_key, $meta_value) {
188 - $user_id = is_null( $user_id ) ? $this->user_id() : $user_id;
189 -
190 - if( ! is_multisite() ) {
191 - return update_user_meta( $user_id, $meta_key, $meta_value );
192 - }
193 -
194 - return update_user_option( $user_id, $meta_key, $meta_value, $this->_is_global() );
195 - }
196 -
197 - public function delete_user_meta( $meta_key ): bool {
198 - if( ! is_multisite() ) {
199 - return delete_user_meta( $this->user_id(), $meta_key );
200 - }
201 -
202 - return delete_user_option( $this->user_id(), $meta_key, $this->_is_global() );
203 - }
204 -
205 - private function _is_global() {
206 - return apply_filters( 'templately_multisite_is_global', false );
207 - }
208 -
209 172 /**
210 173 * Get option data
211 174 *
212 175 * @since 2.0.1
@@ -230,8 +193,8 @@
230 193 * @param string $autoload
231 194 *
232 195 * @return bool
233 196 */
234 - public function update_option( $key, $value, $autoload = 'no' ): bool {
197 + public function update_option( $key, $value, $autoload = 'no' ){
235 198 return update_option( $key, $value, $autoload );
236 199 }
237 200 }