PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.0.6
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.0.6
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-wp-convertkit.php

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

435 lines 12.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Class ConvertKit
11 *
12 * @package ConvertKit
13 * @author ConvertKit
14 */
15 class WP_ConvertKit {
16
17 /**
18 * Holds the class object.
19 *
20 * @since 1.9.6
21 *
22 * @var object
23 */
24 private static $instance;
25
26 /**
27 * Holds singleton initialized classes that include
28 * action and filter hooks.
29 *
30 * @since 1.9.6
31 *
32 * @var array
33 */
34 private $classes = array();
35
36 /**
37 * Constructor. Acts as a bootstrap to load the rest of the plugin
38 *
39 * @since 1.9.6
40 */
41 public function __construct() {
42
43 // Initialize classes that have hooks prior to the `init` hook.
44 // Divi Theme requires us to do this, although the Divi Builder Plugin works fine when loading
45 // our integration on `init`.
46 $this->classes['divi'] = new ConvertKit_Divi();
47 $this->classes['widgets'] = new ConvertKit_Widgets();
48
49 // Initialize Plugin classes on init, so the `_load_textdomain_just_in_time` warning isn't triggered.
50 add_action( 'init', array( $this, 'initialize' ), 1 );
51 add_action( 'init', array( $this, 'setup' ), 2 );
52
53 }
54
55 /**
56 * Initialize classes.
57 *
58 * @since 2.7.7
59 */
60 public function initialize() {
61
62 $this->initialize_admin();
63 $this->initialize_admin_or_frontend_editor();
64 $this->initialize_cli_cron();
65 $this->initialize_frontend();
66 $this->initialize_global();
67
68 }
69
70 /**
71 * Initialize classes for the WordPress Administration interface
72 *
73 * @since 1.9.6
74 */
75 private function initialize_admin() {
76
77 // Bail if this request isn't for the WordPress Administration interface.
78 if ( ! is_admin() ) {
79 return;
80 }
81
82 $this->classes['admin_bulk_edit'] = new ConvertKit_Admin_Bulk_Edit();
83 $this->classes['admin_cache_plugins'] = new ConvertKit_Admin_Cache_Plugins();
84 $this->classes['admin_category'] = new ConvertKit_Admin_Category();
85 $this->classes['admin_landing_page'] = new ConvertKit_Admin_Landing_Page();
86 $this->classes['admin_notices'] = new ConvertKit_Admin_Notices();
87 $this->classes['admin_post'] = new ConvertKit_Admin_Post();
88 $this->classes['admin_quick_edit'] = new ConvertKit_Admin_Quick_Edit();
89 $this->classes['admin_refresh_resources'] = new ConvertKit_Admin_Refresh_Resources();
90 $this->classes['admin_restrict_content'] = new ConvertKit_Admin_Restrict_Content();
91 $this->classes['admin_settings'] = new ConvertKit_Admin_Settings();
92 $this->classes['admin_setup_wizard_landing_page'] = new ConvertKit_Admin_Setup_Wizard_Landing_Page();
93 $this->classes['admin_setup_wizard_plugin'] = new ConvertKit_Admin_Setup_Wizard_Plugin();
94 $this->classes['admin_setup_wizard_restrict_content'] = new ConvertKit_Admin_Setup_Wizard_Restrict_Content();
95 $this->classes['admin_tinymce'] = new ConvertKit_Admin_TinyMCE();
96
97 /**
98 * Initialize integration classes for the WordPress Administration interface.
99 *
100 * @since 1.9.6
101 */
102 do_action( 'convertkit_initialize_admin' );
103
104 }
105
106 /**
107 * Initialize classes for the WordPress Administration interface or a frontend Page Builder
108 *
109 * @since 1.9.6
110 */
111 private function initialize_admin_or_frontend_editor() {
112
113 // Bail if this request isn't for the WordPress Administration interface and isn't for a frontend Page Builder.
114 if ( ! $this->is_admin_or_frontend_editor() ) {
115 return;
116 }
117
118 /**
119 * Initialize integration classes for the WordPress Administration interface or a frontend Page Builder.
120 *
121 * @since 1.9.6
122 */
123 do_action( 'convertkit_initialize_admin_or_frontend_editor' );
124
125 }
126
127 /**
128 * Initialize classes for WP-CLI and WP-Cron
129 *
130 * @since 2.5.2
131 */
132 private function initialize_cli_cron() {
133
134 // Bail if this isn't a CLI or CRON request.
135 if ( ! $this->is_cli() && ! $this->is_cron() ) {
136 return;
137 }
138
139 /**
140 * Initialize integration classes for WP-CLI and WP-Cron.
141 *
142 * @since 1.9.6
143 */
144 do_action( 'convertkit_initialize_cli_cron' );
145
146 }
147
148 /**
149 * Initialize classes for the frontend web site
150 *
151 * @since 1.9.6
152 */
153 private function initialize_frontend() {
154
155 // Bail if this request isn't for the frontend web site.
156 if ( is_admin() ) {
157 return;
158 }
159
160 $this->classes['cache_plugins'] = new ConvertKit_Cache_Plugins();
161 $this->classes['output'] = new ConvertKit_Output();
162 $this->classes['output_broadcasts'] = new ConvertKit_Output_Broadcasts();
163
164 /**
165 * Initialize integration classes for the frontend web site.
166 *
167 * @since 1.9.6
168 */
169 do_action( 'convertkit_initialize_frontend' );
170
171 }
172
173 /**
174 * Initialize classes required globally, across the WordPress Administration, CLI, Cron and Frontend
175 * web site.
176 *
177 * @since 1.9.6
178 */
179 private function initialize_global() {
180
181 $this->classes['ajax'] = new ConvertKit_AJAX();
182 $this->classes['blocks_convertkit_broadcasts'] = new ConvertKit_Block_Broadcasts();
183 $this->classes['blocks_convertkit_content'] = new ConvertKit_Block_Content();
184 $this->classes['blocks_convertkit_formtrigger'] = new ConvertKit_Block_Form_Trigger();
185 $this->classes['blocks_convertkit_form'] = new ConvertKit_Block_Form();
186 $this->classes['blocks_convertkit_form_builder'] = new ConvertKit_Block_Form_Builder();
187 $this->classes['blocks_convertkit_form_builder_field_email'] = new ConvertKit_Block_Form_Builder_Field_Email();
188 $this->classes['blocks_convertkit_form_builder_field_name'] = new ConvertKit_Block_Form_Builder_Field_Name();
189 $this->classes['blocks_convertkit_form_builder_field_custom'] = new ConvertKit_Block_Form_Builder_Field_Custom();
190 $this->classes['blocks_convertkit_product'] = new ConvertKit_Block_Product();
191 $this->classes['block_formatter_form_link'] = new ConvertKit_Block_Formatter_Form_Link();
192 $this->classes['block_formatter_product_link'] = new ConvertKit_Block_Formatter_Product_Link();
193 $this->classes['pre_publish_action_broadcast_export'] = new ConvertKit_Pre_Publish_Action_Broadcast_Export();
194 $this->classes['broadcasts_exporter'] = new ConvertKit_Broadcasts_Exporter();
195 $this->classes['broadcasts_importer'] = new ConvertKit_Broadcasts_Importer();
196 $this->classes['elementor'] = new ConvertKit_Elementor();
197 $this->classes['gutenberg'] = new ConvertKit_Gutenberg();
198 $this->classes['media_library'] = new ConvertKit_Media_Library();
199 $this->classes['output_restrict_content'] = new ConvertKit_Output_Restrict_Content();
200 $this->classes['review_request'] = new ConvertKit_Review_Request( 'Kit', 'convertkit', CONVERTKIT_PLUGIN_PATH );
201 $this->classes['preview_output'] = new ConvertKit_Preview_Output();
202 $this->classes['setup'] = new ConvertKit_Setup();
203 $this->classes['shortcodes'] = new ConvertKit_Shortcodes();
204
205 /**
206 * Initialize integration classes for the frontend web site.
207 *
208 * @since 1.9.6
209 */
210 do_action( 'convertkit_initialize_global' );
211
212 }
213
214 /**
215 * Runs the Plugin's initialization and update routines, which checks if
216 * the Plugin has just been updated to a newer version,
217 * and if so runs any specific processes that might be needed.
218 *
219 * @since 1.9.7.4
220 */
221 public function setup() {
222
223 $this->get_class( 'setup' )->initialize();
224 $this->get_class( 'setup' )->update();
225
226 }
227
228 /**
229 * Improved version of WordPress' is_admin(), which includes whether we're
230 * editing on the frontend using a Page Builder.
231 *
232 * @since 1.9.6
233 *
234 * @return bool Is Admin or Frontend Editor Request
235 */
236 public function is_admin_or_frontend_editor() {
237
238 // If we're in the wp-admin, return true.
239 if ( is_admin() ) {
240 return true;
241 }
242
243 // Pro.
244 if ( array_key_exists( 'REQUEST_URI', $_SERVER ) ) {
245 if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/pro/' ) !== false ) {
246 return true;
247 }
248 if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/x/' ) !== false ) {
249 return true;
250 }
251 if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'cornerstone-endpoint' ) !== false ) {
252 return true;
253 }
254 }
255
256 // If the request global exists, check for specific request keys which tell us
257 // that we're using a frontend editor.
258 // Avada Live.
259 // phpcs:disable WordPress.Security.NonceVerification.Recommended
260 if ( array_key_exists( 'fb-edit', $_REQUEST ) ) {
261 return true;
262 }
263
264 // Beaver Builder.
265 if ( array_key_exists( 'fl_builder', $_REQUEST ) ) {
266 return true;
267 }
268
269 // Brizy.
270 if ( array_key_exists( 'brizy-edit', $_REQUEST ) ) {
271 return true;
272 }
273
274 // Cornerstone (AJAX).
275 if ( array_key_exists( '_cs_nonce', $_REQUEST ) ) {
276 return true;
277 }
278
279 // Divi.
280 if ( array_key_exists( 'et_fb', $_REQUEST ) ) {
281 return true;
282 }
283
284 // Elementor.
285 if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) === 'elementor' ) {
286 return true;
287 }
288
289 // Kallyas.
290 if ( array_key_exists( 'zn_pb_edit', $_REQUEST ) ) {
291 return true;
292 }
293
294 // Oxygen.
295 if ( array_key_exists( 'ct_builder', $_REQUEST ) ) {
296 return true;
297 }
298
299 // Thrive Architect.
300 if ( array_key_exists( 'tve', $_REQUEST ) ) {
301 return true;
302 }
303
304 // Visual Composer.
305 if ( array_key_exists( 'vcv-editable', $_REQUEST ) ) {
306 return true;
307 }
308
309 // WPBakery Page Builder.
310 if ( array_key_exists( 'vc_editable', $_REQUEST ) ) {
311 return true;
312 }
313
314 // Zion Builder.
315 if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) === 'zion_builder_active' ) {
316 return true;
317 }
318
319 // Assume we're not in the Administration interface.
320 $is_admin_or_frontend_editor = false;
321
322 /**
323 * Filters whether the current request is a WordPress Administration / Frontend Editor request or not.
324 *
325 * Page Builders can set this to true to allow ConvertKit to load its administration functionality.
326 *
327 * @since 1.9.6
328 *
329 * @param bool $is_admin_or_frontend_editor Is WordPress Administration / Frontend Editor request.
330 */
331 $is_admin_or_frontend_editor = apply_filters( 'convertkit_is_admin_or_frontend_editor', $is_admin_or_frontend_editor );
332
333 // phpcs:enable
334
335 // Return filtered result.
336 return $is_admin_or_frontend_editor;
337
338 }
339
340 /**
341 * Detects if the request is through the WP-CLI
342 *
343 * @since 1.9.6
344 *
345 * @return bool Is WP-CLI Request
346 */
347 public function is_cli() {
348
349 if ( ! defined( 'WP_CLI' ) ) {
350 return false;
351 }
352 if ( ! WP_CLI ) {
353 return false;
354 }
355
356 return true;
357
358 }
359
360 /**
361 * Detects if the request is through the WP CRON
362 *
363 * @since 1.9.6
364 *
365 * @return bool Is WP CRON Request
366 */
367 public function is_cron() {
368
369 return wp_doing_cron();
370
371 }
372
373 /**
374 * Returns the given class
375 *
376 * @since 1.9.6
377 *
378 * @param string $name Class Name.
379 * @return object Class Object
380 */
381 public function get_class( $name ) {
382
383 // If the class hasn't been loaded, throw a WordPress die screen
384 // to avoid a PHP fatal error.
385 if ( ! isset( $this->classes[ $name ] ) ) {
386 // Define the error.
387 $error = new WP_Error(
388 'convertkit_get_class',
389 sprintf(
390 /* translators: %1$s: PHP class name */
391 __( 'Kit Error: Could not load Plugin class <strong>%1$s</strong>', 'convertkit' ),
392 $name
393 )
394 );
395
396 // Depending on the request, return or display an error.
397 // Admin UI.
398 if ( is_admin() ) {
399 wp_die(
400 esc_attr( $error->get_error_message() ),
401 esc_html__( 'Kit Error', 'convertkit' ),
402 array(
403 'back_link' => true,
404 )
405 );
406 }
407
408 // Cron / CLI.
409 return $error;
410 }
411
412 // Return the class object.
413 return $this->classes[ $name ];
414
415 }
416
417 /**
418 * Returns the singleton instance of the class.
419 *
420 * @since 1.1.6
421 *
422 * @return object Class.
423 */
424 public static function get_instance() {
425
426 if ( null === self::$instance ) {
427 self::$instance = new self();
428 }
429
430 return self::$instance;
431
432 }
433
434 }
435