PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.0.7
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.0.7
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
leadin / public / data / class-user.php

class-user.php in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.0.7, at public/data/class-user.php

60 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Leadin\data;
4
5 /**
6 * Static function that wraps the WordPress current user functions.
7 */
8 class User {
9 /**
10 * Return the first role of the current user. If unauthenticated, return 'visitor'.
11 */
12 public static function get_role() {
13 global $current_user;
14
15 if ( is_user_logged_in() ) {
16 $user_roles = $current_user->roles;
17 $user_role = array_shift( $user_roles );
18 } else {
19 $user_role = 'visitor';
20 }
21
22 return $user_role;
23 }
24
25 /**
26 * Return true if the current user has the `manage_options` capability.
27 */
28 public static function is_admin() {
29 return current_user_can( 'manage_options' );
30 }
31
32 /**
33 * Set metadata for current user
34 *
35 * @param String $key metadata key to store data in.
36 * @param String $data metadata value to store.
37 */
38 public static function set_metadata( $key, $data ) {
39 update_user_meta( get_current_user_id(), $key, $data );
40 }
41
42 /**
43 * Fetch metadata stored for this user by key
44 *
45 * @param String $key metadata to retrieve by the key.
46 */
47 public static function get_metadata( $key ) {
48 return get_user_meta( get_current_user_id(), $key, true );
49 }
50
51 /**
52 * Delete metadata associated with this user
53 *
54 * @param String $key key to delete metadata for.
55 */
56 public static function delete_metadata( $key ) {
57 delete_user_meta( get_current_user_id(), $key );
58 }
59 }
60