PluginProbe
Elementor Website Builder – more than just a page builder / 3.17.2
Elementor Website Builder – more than just a page builder v3.17.2
4.3.1 4.3.0 4.3.0-beta3 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 All 454 releases
← All changes | includes/user.php +19 -99 4.3.0-beta23.17.2 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.
@@ -126,12 +106,8 @@
126 106 if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) {
127 107 return false;
128 108 }
129 109
130 - if ( function_exists( 'wc_get_page_id' ) && intval( wc_get_page_id( 'shop' ) ) === $post->ID ) {
131 - return false;
132 - }
133 -
134 110 return true;
135 111 }
136 112
137 113 /**
@@ -204,11 +180,11 @@
204 180 return is_array( $notices ) ? $notices : [];
205 181 }
206 182
207 183 /**
208 - * Is admin notice viewed.
184 + * Is user notice viewed.
209 185 *
210 - * Whether the admin notice was viewed by the current user.
186 + * Whether the notice was viewed by the user.
211 187 *
212 188 * @since 1.0.0
213 189 * @access public
214 190 * @static
@@ -214,9 +190,9 @@
214 190 * @static
215 191 *
216 192 * @param int $notice_id The notice ID.
217 193 *
218 - * @return bool Whether the admin notice was viewed by the user.
194 + * @return bool Whether the notice was viewed by the user.
219 195 */
220 196 public static function is_user_notice_viewed( $notice_id ) {
221 197 $notices = self::get_user_notices();
222 198
@@ -232,27 +208,11 @@
232 208 return $notices[ $notice_id ]['is_viewed'] ?? false;
233 209 }
234 210
235 211 /**
236 - * Checks whether the current user is allowed to upload JSON files.
237 - *
238 - * Note: The 'json-upload' capability is managed by the Role Manager as a part of its blacklist restrictions.
239 - * In this context, we are negating the user's permission check to use it as a whitelist, allowing uploads.
240 - *
241 - * @return bool Whether the current user can upload JSON files.
242 - */
243 - public static function is_current_user_can_upload_json() {
244 - return current_user_can( 'manage_options' ) || ! Plugin::instance()->role_manager->user_can( 'json-upload' );
245 - }
246 -
247 - public static function is_current_user_can_use_custom_html() {
248 - return current_user_can( 'manage_options' ) || ! Plugin::instance()->role_manager->user_can( 'custom-html' );
249 - }
250 -
251 - /**
252 212 * Set admin notice as viewed.
253 213 *
254 - * 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.
255 215 *
256 216 * Fired by `wp_ajax_elementor_set_admin_notice_viewed` action.
257 217 *
258 218 * @since 1.0.0
@@ -266,10 +226,8 @@
266 226 if ( ! $notice_id ) {
267 227 wp_die();
268 228 }
269 229
270 - check_admin_referer( 'elementor_set_admin_notice_viewed' );
271 -
272 230 self::set_user_notice( $notice_id );
273 231
274 232 if ( ! wp_doing_ajax() ) {
275 233 wp_safe_redirect( admin_url() );
@@ -279,11 +237,11 @@
279 237 wp_die();
280 238 }
281 239
282 240 /**
283 - * @param string $notice_id
284 - * @param bool $is_viewed
285 - * @param array $meta
241 + * @param $notice_id
242 + * @param $is_viewed
243 + * @param $meta
286 244 *
287 245 * @return void
288 246 */
289 247 public static function set_user_notice( $notice_id, $is_viewed = true, $meta = null ) {
@@ -314,13 +272,13 @@
314 272 update_user_meta( get_current_user_id(), self::INTRODUCTION_KEY, $user_introduction_meta );
315 273 }
316 274
317 275 /**
318 - * @throws \Exception If the user cannot install plugins.
276 + * @throws \Exception
319 277 */
320 278 public static function register_as_beta_tester( array $data ) {
321 279 if ( ! current_user_can( 'install_plugins' ) ) {
322 - 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' ) );
323 281 }
324 282
325 283 update_user_meta( get_current_user_id(), self::BETA_TESTER_META_KEY, true );
326 284 $response = wp_safe_remote_post(
@@ -366,56 +324,18 @@
366 324 return $user_introduction_meta;
367 325 }
368 326
369 327 /**
370 - * Get a user option with a fallback value.
328 + * Get a user option with default value as fallback.
371 329 *
372 - * @param string $option Option key.
373 - * @param int $user_id User ID.
374 - * @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.
375 333 *
376 334 * @return mixed
377 335 */
378 - 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 ) {
379 337 $value = get_user_option( $option, $user_id );
380 338
381 - return ( false === $value ) ? $fallback : $value;
382 - }
383 -
384 - /**
385 - * Get dismissed editor notices.
386 - *
387 - * Retrieve the list of dismissed editor notices for the current user.
388 - *
389 - * @since 3.19.0
390 - * @access public
391 - * @static
392 - *
393 - * @return array A list of dismissed editor notices.
394 - */
395 - public static function get_dismissed_editor_notices() {
396 - $notices = get_user_meta( get_current_user_id(), self::DISMISSED_EDITOR_NOTICES_KEY, true );
397 -
398 - return is_array( $notices ) ? $notices : [];
399 - }
400 -
401 - /**
402 - * Set dismissed editor notices for the current user.
403 - *
404 - * @since 3.19.0
405 - * @access public
406 - * @static
407 - *
408 - * @param array $data Editor notices.
409 - *
410 - * @return void
411 - */
412 - public static function set_dismissed_editor_notices( array $data ) {
413 - $editor_notices = self::get_dismissed_editor_notices();
414 -
415 - if ( ! in_array( $data['dismissId'], $editor_notices, true ) ) {
416 - $editor_notices[] = $data['dismissId'];
417 -
418 - update_user_meta( get_current_user_id(), self::DISMISSED_EDITOR_NOTICES_KEY, $editor_notices );
419 - }
339 + return ( false === $value ) ? $default : $value;
420 340 }
421 341 }