PluginProbe
Elementor Website Builder – more than just a page builder / 3.18.3
Elementor Website Builder – more than just a page builder v3.18.3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | includes/user.php +19 -95 4.2.13.18.3 View file →
@@ -17,32 +17,23 @@
17 17 */
18 18 class User {
19 19
20 20 /**
21 - * Holds the admin notices key.
22 - *
23 - * @var string Admin notices key.
21 + * The admin notices key.
24 22 */
25 23 const ADMIN_NOTICES_KEY = 'elementor_admin_notices';
26 24
27 - /**
28 - * Holds the editor introduction screen key.
29 - *
30 - * @var string Introduction key.
31 - */
32 25 const INTRODUCTION_KEY = 'elementor_introduction';
33 26
34 - /**
35 - * Holds the beta tester key.
36 - *
37 - * @var string Beta tester key.
38 - */
39 27 const BETA_TESTER_META_KEY = 'elementor_beta_tester';
40 28
41 29 /**
30 + * API URL.
31 + *
42 32 * Holds the URL of the Beta Tester Opt-in API.
43 33 *
44 34 * @since 1.0.0
35 + * @access private
45 36 *
46 37 * @var string API URL.
47 38 */
48 39 const BETA_TESTER_API_URL = 'https://my.elementor.com/api/v1/beta_tester/';
@@ -47,17 +38,8 @@
47 38 */
48 39 const BETA_TESTER_API_URL = 'https://my.elementor.com/api/v1/beta_tester/';
49 40
50 41 /**
51 - * Holds the dismissed editor notices key.
52 - *
53 - * @since 3.19.0
54 - *
55 - * @var string Editor notices key.
56 - */
57 - const DISMISSED_EDITOR_NOTICES_KEY = 'elementor_dismissed_editor_notices';
58 -
59 - /**
60 42 * Init.
61 43 *
62 44 * Initialize Elementor user.
63 45 *
@@ -72,9 +54,8 @@
72 54 add_action( 'elementor/ajax/register_actions', [ __CLASS__, 'register_ajax_actions' ] );
73 55 }
74 56
75 57 /**
76 - * @param Ajax $ajax
77 58 * @since 2.1.0
78 59 * @access public
79 60 * @static
80 61 */
@@ -80,9 +61,8 @@
80 61 */
81 62 public static function register_ajax_actions( Ajax $ajax ) {
82 63 $ajax->register_ajax_action( 'introduction_viewed', [ __CLASS__, 'set_introduction_viewed' ] );
83 64 $ajax->register_ajax_action( 'beta_tester_signup', [ __CLASS__, 'register_as_beta_tester' ] );
84 - $ajax->register_ajax_action( 'dismissed_editor_notices', [ __CLASS__, 'set_dismissed_editor_notices' ] );
85 65 }
86 66
87 67 /**
88 68 * Is current user can edit.
@@ -200,11 +180,11 @@
200 180 return is_array( $notices ) ? $notices : [];
201 181 }
202 182
203 183 /**
204 - * Is admin notice viewed.
184 + * Is user notice viewed.
205 185 *
206 - * Whether the admin notice was viewed by the current user.
186 + * Whether the notice was viewed by the user.
207 187 *
208 188 * @since 1.0.0
209 189 * @access public
210 190 * @static
@@ -210,9 +190,9 @@
210 190 * @static
211 191 *
212 192 * @param int $notice_id The notice ID.
213 193 *
214 - * @return bool Whether the admin notice was viewed by the user.
194 + * @return bool Whether the notice was viewed by the user.
215 195 */
216 196 public static function is_user_notice_viewed( $notice_id ) {
217 197 $notices = self::get_user_notices();
218 198
@@ -228,27 +208,11 @@
228 208 return $notices[ $notice_id ]['is_viewed'] ?? false;
229 209 }
230 210
231 211 /**
232 - * Checks whether the current user is allowed to upload JSON files.
233 - *
234 - * Note: The 'json-upload' capability is managed by the Role Manager as a part of its blacklist restrictions.
235 - * In this context, we are negating the user's permission check to use it as a whitelist, allowing uploads.
236 - *
237 - * @return bool Whether the current user can upload JSON files.
238 - */
239 - public static function is_current_user_can_upload_json() {
240 - return current_user_can( 'manage_options' ) || ! Plugin::instance()->role_manager->user_can( 'json-upload' );
241 - }
242 -
243 - public static function is_current_user_can_use_custom_html() {
244 - return current_user_can( 'manage_options' ) || ! Plugin::instance()->role_manager->user_can( 'custom-html' );
245 - }
246 -
247 - /**
248 212 * Set admin notice as viewed.
249 213 *
250 - * Flag the admin notice as viewed by the current user, using an authenticated ajax request.
214 + * Flag the user admin notice as viewed using an authenticated ajax request.
251 215 *
252 216 * Fired by `wp_ajax_elementor_set_admin_notice_viewed` action.
253 217 *
254 218 * @since 1.0.0
@@ -262,10 +226,8 @@
262 226 if ( ! $notice_id ) {
263 227 wp_die();
264 228 }
265 229
266 - check_admin_referer( 'elementor_set_admin_notice_viewed' );
267 -
268 230 self::set_user_notice( $notice_id );
269 231
270 232 if ( ! wp_doing_ajax() ) {
271 233 wp_safe_redirect( admin_url() );
@@ -275,11 +237,11 @@
275 237 wp_die();
276 238 }
277 239
278 240 /**
279 - * @param string $notice_id
280 - * @param bool $is_viewed
281 - * @param array $meta
241 + * @param $notice_id
242 + * @param $is_viewed
243 + * @param $meta
282 244 *
283 245 * @return void
284 246 */
285 247 public static function set_user_notice( $notice_id, $is_viewed = true, $meta = null ) {
@@ -310,13 +272,13 @@
310 272 update_user_meta( get_current_user_id(), self::INTRODUCTION_KEY, $user_introduction_meta );
311 273 }
312 274
313 275 /**
314 - * @throws \Exception If the user cannot install plugins.
276 + * @throws \Exception
315 277 */
316 278 public static function register_as_beta_tester( array $data ) {
317 279 if ( ! current_user_can( 'install_plugins' ) ) {
318 - throw new \Exception( 'You do not have permission to install plugins.' );
280 + throw new \Exception( __( 'You do not have permissions to install plugins on this site.', 'elementor' ) );
319 281 }
320 282
321 283 update_user_meta( get_current_user_id(), self::BETA_TESTER_META_KEY, true );
322 284 $response = wp_safe_remote_post(
@@ -362,56 +324,18 @@
362 324 return $user_introduction_meta;
363 325 }
364 326
365 327 /**
366 - * Get a user option with a fallback value.
328 + * Get a user option with default value as fallback.
367 329 *
368 - * @param string $option Option key.
369 - * @param int $user_id User ID.
370 - * @param mixed $fallback Default fallback value.
330 + * @param string $option - Option key.
331 + * @param int $user_id - User ID
332 + * @param mixed $default - Default fallback value.
371 333 *
372 334 * @return mixed
373 335 */
374 - public static function get_user_option_with_default( $option, $user_id, $fallback ) {
336 + public static function get_user_option_with_default( $option, $user_id, $default ) {
375 337 $value = get_user_option( $option, $user_id );
376 338
377 - return ( false === $value ) ? $fallback : $value;
378 - }
379 -
380 - /**
381 - * Get dismissed editor notices.
382 - *
383 - * Retrieve the list of dismissed editor notices for the current user.
384 - *
385 - * @since 3.19.0
386 - * @access public
387 - * @static
388 - *
389 - * @return array A list of dismissed editor notices.
390 - */
391 - public static function get_dismissed_editor_notices() {
392 - $notices = get_user_meta( get_current_user_id(), self::DISMISSED_EDITOR_NOTICES_KEY, true );
393 -
394 - return is_array( $notices ) ? $notices : [];
395 - }
396 -
397 - /**
398 - * Set dismissed editor notices for the current user.
399 - *
400 - * @since 3.19.0
401 - * @access public
402 - * @static
403 - *
404 - * @param array $data Editor notices.
405 - *
406 - * @return void
407 - */
408 - public static function set_dismissed_editor_notices( array $data ) {
409 - $editor_notices = self::get_dismissed_editor_notices();
410 -
411 - if ( ! in_array( $data['dismissId'], $editor_notices, true ) ) {
412 - $editor_notices[] = $data['dismissId'];
413 -
414 - update_user_meta( get_current_user_id(), self::DISMISSED_EDITOR_NOTICES_KEY, $editor_notices );
415 - }
339 + return ( false === $value ) ? $default : $value;
416 340 }
417 341 }