PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 1.9.7.2
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v1.9.7.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 2.3.2 2.3.3 All 194 releases
convertkit / includes / class-convertkit-settings.php

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

268 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Plugin Settings class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Class to read ConvertKit Plugin Settings.
11 *
12 * @since 1.9.6
13 */
14 class ConvertKit_Settings {
15
16 /**
17 * Holds the Settings Key that stores site wide ConvertKit settings
18 *
19 * @var string
20 */
21 const SETTINGS_NAME = '_wp_convertkit_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 = array_merge( $this->get_defaults(), $settings );
46 }
47
48 }
49
50 /**
51 * Returns Plugin 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 * Returns the API Key Plugin setting.
65 *
66 * @since 1.9.6
67 *
68 * @return string
69 */
70 public function get_api_key() {
71
72 // Return API Key from constant, if defined.
73 if ( defined( 'CONVERTKIT_API_KEY' ) ) {
74 return CONVERTKIT_API_KEY;
75 }
76
77 // Return API Key from settings.
78 return $this->settings['api_key'];
79
80 }
81
82 /**
83 * Returns whether the API Key has been set in the Plugin settings.
84 *
85 * @since 1.9.6
86 *
87 * @return bool
88 */
89 public function has_api_key() {
90
91 return ( ! empty( $this->get_api_key() ) ? true : false );
92
93 }
94
95 /**
96 * Returns whether the API Key is stored as a constant in the wp-config.php file.
97 *
98 * @since 1.9.6
99 *
100 * @return bool
101 */
102 public function is_api_key_a_constant() {
103
104 return defined( 'CONVERTKIT_API_KEY' );
105
106 }
107
108 /**
109 * Returns the API Secret Plugin setting.
110 *
111 * @since 1.9.6
112 *
113 * @return string
114 */
115 public function get_api_secret() {
116
117 // Return API Secret from constant, if defined.
118 if ( defined( 'CONVERTKIT_API_SECRET' ) ) {
119 return CONVERTKIT_API_SECRET;
120 }
121
122 // Return API Secret from settings.
123 return $this->settings['api_secret'];
124
125 }
126
127 /**
128 * Returns whether the API Secret has been set in the Plugin settings.
129 *
130 * @since 1.9.6
131 *
132 * @return bool
133 */
134 public function has_api_secret() {
135
136 return ( ! empty( $this->get_api_secret() ) ? true : false );
137
138 }
139
140 /**
141 * Returns whether the API Secret is stored as a constant in the wp-config.php file.
142 *
143 * @since 1.9.6
144 *
145 * @return bool
146 */
147 public function is_api_secret_a_constant() {
148
149 return defined( 'CONVERTKIT_API_SECRET' );
150
151 }
152
153 /**
154 * Returns whether the API Key and Secret have been set in the Plugin settings.
155 *
156 * @since 1.9.6
157 *
158 * @return bool
159 */
160 public function has_api_key_and_secret() {
161
162 return $this->has_api_key() && $this->has_api_secret();
163
164 }
165
166 /**
167 * Returns the Default Form Plugin setting.
168 *
169 * @since 1.9.6
170 *
171 * @param string $post_type Post Type.
172 * @return string Default Form (default|form id)
173 */
174 public function get_default_form( $post_type ) {
175
176 // Return default if this Post Type doesn't exist as a setting.
177 if ( ! array_key_exists( $post_type . '_form', $this->settings ) ) {
178 return 'default';
179 }
180
181 // Backward compat. where older Plugin versions would store API errors in the option value
182 // with id = -2 and name = 'Error contacting API'.
183 if ( is_array( $this->settings[ $post_type . '_form' ] ) ) {
184 return 'default';
185 }
186
187 return $this->settings[ $post_type . '_form' ];
188
189 }
190
191 /**
192 * Returns whether the Default Form has been set in the Plugin settings.
193 *
194 * @since 1.9.6
195 *
196 * @param string $post_type Post Type.
197 * @return bool Post Type has a Default Form setting specified in Plugin Settings.
198 */
199 public function has_default_form( $post_type ) {
200
201 return ( ! empty( $this->settings[ $post_type . '_form' ] ) ? true : false );
202
203 }
204
205 /**
206 * Returns whether debugging is enabled in the Plugin settings.
207 *
208 * @since 1.9.6
209 *
210 * @return bool
211 */
212 public function debug_enabled() {
213
214 return ( $this->settings['debug'] === 'on' ? true : false );
215
216 }
217
218 /**
219 * Returns whether scripts are disabled in the Plugin settings.
220 *
221 * @since 1.9.6
222 *
223 * @return bool
224 */
225 public function scripts_disabled() {
226
227 return ( $this->settings['no_scripts'] === 'on' ? true : false );
228
229 }
230
231 /**
232 * The default settings, used when the ConvertKit Plugin Settings haven't been saved
233 * e.g. on a new installation.
234 *
235 * @since 1.9.6
236 *
237 * @return array
238 */
239 public function get_defaults() {
240
241 $defaults = array(
242 'api_key' => '', // string.
243 'api_secret' => '', // string.
244 'debug' => '', // blank|on.
245 'no_scripts' => '', // blank|on.
246 );
247
248 // Add Post Type Default Forms.
249 foreach ( convertkit_get_supported_post_types() as $post_type ) {
250 $defaults[ $post_type . '_form' ] = 0; // -1, 0 or Form ID.
251 }
252
253 /**
254 * The default settings, used when the ConvertKit Plugin Settings haven't been saved
255 * e.g. on a new installation.
256 *
257 * @since 1.9.6
258 *
259 * @param array $defaults
260 */
261 $defaults = apply_filters( 'convertkit_settings_get_defaults', $defaults );
262
263 return $defaults;
264
265 }
266
267 }
268