PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.3.7
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.3.7
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 2.3.7, at includes/class-convertkit-settings.php

327 lines 6.4 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|int 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 the Global non-inline Form Plugin setting.
207 *
208 * @since 2.3.3
209 *
210 * @return string|int Non-inline Form (blank string|form id)
211 */
212 public function get_non_inline_form() {
213
214 // Return blank string if no inline form is specified.
215 if ( ! $this->has_non_inline_form() ) {
216 return '';
217 }
218
219 return $this->settings['non_inline_form'];
220
221 }
222
223 /**
224 * Returns whether the Global non-inline Form has been set in the Plugin settings.
225 *
226 * @since 2.3.3
227 *
228 * @return bool Global non-inline Form setting specified in Plugin Settings.
229 */
230 public function has_non_inline_form() {
231
232 return ( ! empty( $this->settings['non_inline_form'] ) ? true : false );
233
234 }
235
236 /**
237 * Returns whether debugging is enabled in the Plugin settings.
238 *
239 * @since 1.9.6
240 *
241 * @return bool
242 */
243 public function debug_enabled() {
244
245 return ( $this->settings['debug'] === 'on' ? true : false );
246
247 }
248
249 /**
250 * Returns whether scripts are disabled in the Plugin settings.
251 *
252 * @since 1.9.6
253 *
254 * @return bool
255 */
256 public function scripts_disabled() {
257
258 return ( $this->settings['no_scripts'] === 'on' ? true : false );
259
260 }
261
262 /**
263 * Returns whether stylesheets are disabled in the Plugin settings.
264 *
265 * @since 1.9.6.9
266 *
267 * @return bool
268 */
269 public function css_disabled() {
270
271 return ( $this->settings['no_css'] === 'on' ? true : false );
272
273 }
274
275 /**
276 * The default settings, used when the ConvertKit Plugin Settings haven't been saved
277 * e.g. on a new installation.
278 *
279 * @since 1.9.6
280 *
281 * @return array
282 */
283 public function get_defaults() {
284
285 $defaults = array(
286 'api_key' => '', // string.
287 'api_secret' => '', // string.
288 'non_inline_form' => '', // string.
289 'debug' => '', // blank|on.
290 'no_scripts' => '', // blank|on.
291 'no_css' => '', // blank|on.
292 );
293
294 // Add Post Type Default Forms.
295 foreach ( convertkit_get_supported_post_types() as $post_type ) {
296 $defaults[ $post_type . '_form' ] = 0; // -1, 0 or Form ID.
297 }
298
299 /**
300 * The default settings, used when the ConvertKit Plugin Settings haven't been saved
301 * e.g. on a new installation.
302 *
303 * @since 1.9.6
304 *
305 * @param array $defaults Default Settings.
306 */
307 $defaults = apply_filters( 'convertkit_settings_get_defaults', $defaults );
308
309 return $defaults;
310
311 }
312
313 /**
314 * Saves the given array of settings to the WordPress options table.
315 *
316 * @since 1.9.8.4
317 *
318 * @param array $settings Settings.
319 */
320 public function save( $settings ) {
321
322 update_option( self::SETTINGS_NAME, array_merge( $this->get(), $settings ) );
323
324 }
325
326 }
327