PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.3
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.3
3.4.3 3.4.2 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 All 196 releases
convertkit / includes / integrations / wishlist / class-convertkit-wishlist-settings.php

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

157 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Wishlist Settings class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Class to read ConvertKit Wishlist Integration Settings.
11 *
12 * @since 1.9.6
13 */
14 class ConvertKit_Wishlist_Settings {
15
16 /**
17 * Holds the Settings Key that stores this integration's settings.
18 *
19 * @var string
20 */
21 const SETTINGS_NAME = '_wp_convertkit_integration_wishlistmember_settings';
22
23 /**
24 * Holds the Settings
25 *
26 * @var array
27 */
28 private $settings = array();
29
30 /**
31 * Constructor. Reads settings from options table, falling back to defaults
32 * if no settings exist.
33 *
34 * @since 1.9.6
35 */
36 public function __construct() {
37
38 // Get Settings.
39 $settings = get_option( self::SETTINGS_NAME );
40
41 // If no Settings exist, falback to default settings.
42 if ( ! $settings ) {
43 $this->settings = $this->get_defaults();
44 } else {
45 $this->settings = $settings;
46 }
47
48 }
49
50 /**
51 * Returns Integration settings.
52 *
53 * @since 1.9.6
54 *
55 * @return array
56 */
57 public function get() {
58
59 return $this->settings;
60
61 }
62
63 /**
64 * Checks if any settings are defined.
65 *
66 * @since 1.9.6
67 *
68 * @return bool
69 */
70 public function has_settings() {
71
72 if ( empty( $this->get() ) ) {
73 return false;
74 }
75
76 return true;
77
78 }
79
80 /**
81 * Returns the ConvertKit subscribe setting that is mapped against the given WishList Member Level ID.
82 *
83 * @since 2.5.4
84 *
85 * @param int $wlm_level_id WishList Member Level ID.
86 * @return bool|string false|subscribe|form:id|tag:id|sequence:id.
87 */
88 public function get_convertkit_add_setting_by_wishlist_member_level_id( $wlm_level_id ) {
89
90 // Bail if no settings exist.
91 if ( ! $this->has_settings() ) {
92 return false;
93 }
94
95 // Bail if no mapping exists.
96 if ( ! array_key_exists( $wlm_level_id . '_add', $this->get() ) ) {
97 return false;
98 }
99
100 return $this->get()[ $wlm_level_id . '_add' ];
101
102 }
103
104 /**
105 * Returns the ConvertKit remove setting that is mapped against the given WishList Member Level ID.
106 *
107 * @since 1.9.6
108 *
109 * @param int $wlm_level_id WishList Member Level ID.
110 * @return bool|string false|subscribe|unsubscribe|form:id|tag:id|sequence:id.
111 */
112 public function get_convertkit_remove_setting_by_wishlist_member_level_id( $wlm_level_id ) {
113
114 // Bail if no settings exist.
115 if ( ! $this->has_settings() ) {
116 return false;
117 }
118
119 // Bail if no mapping exists.
120 if ( ! array_key_exists( $wlm_level_id . '_remove', $this->get() ) ) {
121 return false;
122 }
123
124 return $this->get()[ $wlm_level_id . '_remove' ];
125
126 }
127
128 /**
129 * The default settings, used when WishList's Settings haven't been saved
130 * e.g. on a new installation or when the WishList Plugin has just been activated
131 * for the first time.
132 *
133 * @since 1.9.6
134 *
135 * @return array
136 */
137 public function get_defaults() {
138
139 $defaults = array();
140
141 /**
142 * The default settings, used when WishList's Settings haven't been saved
143 * e.g. on a new installation or when the WishList Plugin has just been activated
144 * for the first time.
145 *
146 * @since 1.9.6
147 *
148 * @param array $defaults Default Settings.
149 */
150 $defaults = apply_filters( 'convertkit_wishlist_settings_get_defaults', $defaults );
151
152 return $defaults;
153
154 }
155
156 }
157