PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / trunk
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages vtrunk
3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 All 194 releases
convertkit / includes / class-convertkit-user.php

class-convertkit-user.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages trunk, at includes/class-convertkit-user.php

115 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit User class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Class to read ConvertKit Settings for the given User.
11 *
12 * @since 1.9.6
13 */
14 class ConvertKit_User {
15
16 /**
17 * Holds the Meta Key that stores ConvertKit settings on a per-User basis
18 *
19 * @var string
20 */
21 const META_KEY = 'convertkit_tags';
22
23 /**
24 * Holds the User ID
25 *
26 * @since 1.9.6
27 *
28 * @var int
29 */
30 public $user_id = 0;
31
32 /**
33 * Holds the User's Settings
34 *
35 * @var array
36 */
37 private $settings = array();
38
39 /**
40 * Constructor. Populates the settings based on the given User ID.
41 *
42 * @since 1.9.6
43 *
44 * @param int $user_id User ID.
45 */
46 public function __construct( $user_id ) {
47
48 // Assign User's ID to the object.
49 $this->user_id = $user_id;
50
51 // Get User Meta.
52 $meta = get_user_meta( $user_id, self::META_KEY, true );
53 if ( ! $meta ) {
54 // Fallback to default settings.
55 $meta = $this->get_default_settings();
56 }
57
58 // Assign User's Settings to the object.
59 $this->settings = $meta;
60
61 }
62
63 /**
64 * Returns settings for the User.
65 *
66 * @since 1.9.6
67 *
68 * @return array
69 */
70 public function get() {
71
72 return $this->settings;
73
74 }
75
76 /**
77 * Saves User settings to the User.
78 *
79 * @since 1.9.6
80 *
81 * @param array $meta Settings.
82 */
83 public function save( $meta ) {
84
85 return update_user_meta( $this->user_id, self::META_KEY, $meta );
86
87 }
88
89 /**
90 * The default settings, used to populate the User's Settings when a User
91 * has no Settings.
92 *
93 * @since 1.9.6
94 *
95 * @return array
96 */
97 public function get_default_settings() {
98
99 $defaults = array();
100
101 /**
102 * The default settings, used to populate the User's Settings when a User has no Settings.
103 *
104 * @since 1.9.6
105 *
106 * @param array $defaults Default Settings.
107 */
108 $defaults = apply_filters( 'convertkit_user_get_default_settings', $defaults );
109
110 return $defaults;
111
112 }
113
114 }
115