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

444 lines 13.2 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_legacy_resource_notice'] = new ConvertKit_Admin_Legacy_Resource_Notice();
87 $this->classes['admin_importer_activecampaign'] = new ConvertKit_Admin_Importer_ActiveCampaign();
88 $this->classes['admin_importer_aweber'] = new ConvertKit_Admin_Importer_AWeber();
89 $this->classes['admin_importer_campaignmonitor'] = new ConvertKit_Admin_Importer_CampaignMonitor();
90 $this->classes['admin_importer_convertkit_legacy_forms'] = new ConvertKit_Admin_Importer_ConvertKit_Legacy_Forms();
91 $this->classes['admin_importer_mc4wp'] = new ConvertKit_Admin_Importer_MC4WP();
92 $this->classes['admin_importer_mailpoet'] = new ConvertKit_Admin_Importer_Mailpoet();
93 $this->classes['admin_importer_newsletter'] = new ConvertKit_Admin_Importer_Newsletter();
94 $this->classes['admin_post'] = new ConvertKit_Admin_Post();
95 $this->classes['admin_quick_edit'] = new ConvertKit_Admin_Quick_Edit();
96 $this->classes['admin_restrict_content'] = new ConvertKit_Admin_Restrict_Content();
97 $this->classes['admin_settings'] = new ConvertKit_Admin_Settings();
98 $this->classes['admin_setup_wizard_landing_page'] = new ConvertKit_Admin_Setup_Wizard_Landing_Page();
99 $this->classes['admin_setup_wizard_plugin'] = new ConvertKit_Admin_Setup_Wizard_Plugin();
100 $this->classes['admin_setup_wizard_restrict_content'] = new ConvertKit_Admin_Setup_Wizard_Restrict_Content();
101
102 /**
103 * Initialize integration classes for the WordPress Administration interface.
104 *
105 * @since 1.9.6
106 */
107 do_action( 'convertkit_initialize_admin' );
108
109 }
110
111 /**
112 * Initialize classes for the WordPress Administration interface or a frontend Page Builder
113 *
114 * @since 1.9.6
115 */
116 private function initialize_admin_or_frontend_editor() {
117
118 // Bail if this request isn't for the WordPress Administration interface and isn't for a frontend Page Builder.
119 if ( ! $this->is_admin_or_frontend_editor() ) {
120 return;
121 }
122
123 /**
124 * Initialize integration classes for the WordPress Administration interface or a frontend Page Builder.
125 *
126 * @since 1.9.6
127 */
128 do_action( 'convertkit_initialize_admin_or_frontend_editor' );
129
130 }
131
132 /**
133 * Initialize classes for WP-CLI and WP-Cron
134 *
135 * @since 2.5.2
136 */
137 private function initialize_cli_cron() {
138
139 // Bail if this isn't a CLI or CRON request.
140 if ( ! $this->is_cli() && ! $this->is_cron() ) {
141 return;
142 }
143
144 /**
145 * Initialize integration classes for WP-CLI and WP-Cron.
146 *
147 * @since 1.9.6
148 */
149 do_action( 'convertkit_initialize_cli_cron' );
150
151 }
152
153 /**
154 * Initialize classes for the frontend web site
155 *
156 * @since 1.9.6
157 */
158 private function initialize_frontend() {
159
160 // Bail if this request isn't for the frontend web site.
161 if ( is_admin() ) {
162 return;
163 }
164
165 $this->classes['cache_plugins'] = new ConvertKit_Cache_Plugins();
166 $this->classes['output'] = new ConvertKit_Output();
167 $this->classes['output_broadcasts'] = new ConvertKit_Output_Broadcasts();
168
169 /**
170 * Initialize integration classes for the frontend web site.
171 *
172 * @since 1.9.6
173 */
174 do_action( 'convertkit_initialize_frontend' );
175
176 }
177
178 /**
179 * Initialize classes required globally, across the WordPress Administration, CLI, Cron and Frontend
180 * web site.
181 *
182 * @since 1.9.6
183 */
184 private function initialize_global() {
185
186 $this->classes['admin_notices'] = new ConvertKit_Admin_Notices();
187 $this->classes['admin_tinymce'] = new ConvertKit_Admin_TinyMCE();
188 $this->classes['admin_refresh_resources'] = new ConvertKit_Admin_Refresh_Resources();
189 $this->classes['blocks_convertkit_broadcasts'] = new ConvertKit_Block_Broadcasts();
190 $this->classes['blocks_convertkit_content'] = new ConvertKit_Block_Content();
191 $this->classes['blocks_convertkit_formtrigger'] = new ConvertKit_Block_Form_Trigger();
192 $this->classes['blocks_convertkit_form'] = new ConvertKit_Block_Form();
193 $this->classes['blocks_convertkit_form_builder'] = new ConvertKit_Block_Form_Builder();
194 $this->classes['blocks_convertkit_form_builder_field_email'] = new ConvertKit_Block_Form_Builder_Field_Email();
195 $this->classes['blocks_convertkit_form_builder_field_name'] = new ConvertKit_Block_Form_Builder_Field_Name();
196 $this->classes['blocks_convertkit_form_builder_field_custom'] = new ConvertKit_Block_Form_Builder_Field_Custom();
197 $this->classes['blocks_convertkit_product'] = new ConvertKit_Block_Product();
198 $this->classes['block_formatter_form_link'] = new ConvertKit_Block_Formatter_Form_Link();
199 $this->classes['block_formatter_product_link'] = new ConvertKit_Block_Formatter_Product_Link();
200 $this->classes['pre_publish_action_broadcast_export'] = new ConvertKit_Pre_Publish_Action_Broadcast_Export();
201 $this->classes['plugin_sidebar_post_settings'] = new ConvertKit_Plugin_Sidebar_Post_Settings();
202 $this->classes['broadcasts_exporter'] = new ConvertKit_Broadcasts_Exporter();
203 $this->classes['broadcasts_importer'] = new ConvertKit_Broadcasts_Importer();
204 $this->classes['elementor'] = new ConvertKit_Elementor();
205 $this->classes['gutenberg'] = new ConvertKit_Gutenberg();
206 $this->classes['media_library'] = new ConvertKit_Media_Library();
207 $this->classes['output_restrict_content'] = new ConvertKit_Output_Restrict_Content();
208 $this->classes['restrict_content_cache'] = new ConvertKit_Restrict_Content_Cache();
209 $this->classes['review_request'] = new ConvertKit_Review_Request( 'Kit', 'convertkit', CONVERTKIT_PLUGIN_PATH );
210 $this->classes['preview_output'] = new ConvertKit_Preview_Output();
211 $this->classes['setup'] = new ConvertKit_Setup();
212 $this->classes['shortcodes'] = new ConvertKit_Shortcodes();
213
214 /**
215 * Initialize integration classes for the frontend web site.
216 *
217 * @since 1.9.6
218 */
219 do_action( 'convertkit_initialize_global' );
220
221 }
222
223 /**
224 * Runs the Plugin's initialization and update routines, which checks if
225 * the Plugin has just been updated to a newer version,
226 * and if so runs any specific processes that might be needed.
227 *
228 * @since 1.9.7.4
229 */
230 public function setup() {
231
232 $this->get_class( 'setup' )->initialize();
233 $this->get_class( 'setup' )->update();
234
235 }
236
237 /**
238 * Improved version of WordPress' is_admin(), which includes whether we're
239 * editing on the frontend using a Page Builder.
240 *
241 * @since 1.9.6
242 *
243 * @return bool Is Admin or Frontend Editor Request
244 */
245 public function is_admin_or_frontend_editor() {
246
247 // If we're in the wp-admin, return true.
248 if ( is_admin() ) {
249 return true;
250 }
251
252 // Pro.
253 if ( array_key_exists( 'REQUEST_URI', $_SERVER ) ) {
254 if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/pro/' ) !== false ) {
255 return true;
256 }
257 if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/x/' ) !== false ) {
258 return true;
259 }
260 if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'cornerstone-endpoint' ) !== false ) {
261 return true;
262 }
263 }
264
265 // If the request global exists, check for specific request keys which tell us
266 // that we're using a frontend editor.
267 // Avada Live.
268 // phpcs:disable WordPress.Security.NonceVerification.Recommended
269 if ( array_key_exists( 'fb-edit', $_REQUEST ) ) {
270 return true;
271 }
272
273 // Beaver Builder.
274 if ( array_key_exists( 'fl_builder', $_REQUEST ) ) {
275 return true;
276 }
277
278 // Brizy.
279 if ( array_key_exists( 'brizy-edit', $_REQUEST ) ) {
280 return true;
281 }
282
283 // Cornerstone (AJAX).
284 if ( array_key_exists( '_cs_nonce', $_REQUEST ) ) {
285 return true;
286 }
287
288 // Divi.
289 if ( array_key_exists( 'et_fb', $_REQUEST ) ) {
290 return true;
291 }
292
293 // Elementor.
294 if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) === 'elementor' ) {
295 return true;
296 }
297
298 // Kallyas.
299 if ( array_key_exists( 'zn_pb_edit', $_REQUEST ) ) {
300 return true;
301 }
302
303 // Oxygen.
304 if ( array_key_exists( 'ct_builder', $_REQUEST ) ) {
305 return true;
306 }
307
308 // Thrive Architect.
309 if ( array_key_exists( 'tve', $_REQUEST ) ) {
310 return true;
311 }
312
313 // Visual Composer.
314 if ( array_key_exists( 'vcv-editable', $_REQUEST ) ) {
315 return true;
316 }
317
318 // WPBakery Page Builder.
319 if ( array_key_exists( 'vc_editable', $_REQUEST ) ) {
320 return true;
321 }
322
323 // Zion Builder.
324 if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) === 'zion_builder_active' ) {
325 return true;
326 }
327
328 // Assume we're not in the Administration interface.
329 $is_admin_or_frontend_editor = false;
330
331 /**
332 * Filters whether the current request is a WordPress Administration / Frontend Editor request or not.
333 *
334 * Page Builders can set this to true to allow ConvertKit to load its administration functionality.
335 *
336 * @since 1.9.6
337 *
338 * @param bool $is_admin_or_frontend_editor Is WordPress Administration / Frontend Editor request.
339 */
340 $is_admin_or_frontend_editor = apply_filters( 'convertkit_is_admin_or_frontend_editor', $is_admin_or_frontend_editor );
341
342 // phpcs:enable
343
344 // Return filtered result.
345 return $is_admin_or_frontend_editor;
346
347 }
348
349 /**
350 * Detects if the request is through the WP-CLI
351 *
352 * @since 1.9.6
353 *
354 * @return bool Is WP-CLI Request
355 */
356 public function is_cli() {
357
358 if ( ! defined( 'WP_CLI' ) ) {
359 return false;
360 }
361 if ( ! WP_CLI ) {
362 return false;
363 }
364
365 return true;
366
367 }
368
369 /**
370 * Detects if the request is through the WP CRON
371 *
372 * @since 1.9.6
373 *
374 * @return bool Is WP CRON Request
375 */
376 public function is_cron() {
377
378 return wp_doing_cron();
379
380 }
381
382 /**
383 * Returns the given class
384 *
385 * @since 1.9.6
386 *
387 * @param string $name Class Name.
388 * @return object Class Object
389 */
390 public function get_class( $name ) {
391
392 // If the class hasn't been loaded, throw a WordPress die screen
393 // to avoid a PHP fatal error.
394 if ( ! isset( $this->classes[ $name ] ) ) {
395 // Define the error.
396 $error = new WP_Error(
397 'convertkit_get_class',
398 sprintf(
399 /* translators: %1$s: PHP class name */
400 __( 'Kit Error: Could not load Plugin class <strong>%1$s</strong>', 'convertkit' ),
401 $name
402 )
403 );
404
405 // Depending on the request, return or display an error.
406 // Admin UI.
407 if ( is_admin() ) {
408 wp_die(
409 esc_attr( $error->get_error_message() ),
410 esc_html__( 'Kit Error', 'convertkit' ),
411 array(
412 'back_link' => true,
413 )
414 );
415 }
416
417 // Cron / CLI.
418 return $error;
419 }
420
421 // Return the class object.
422 return $this->classes[ $name ];
423
424 }
425
426 /**
427 * Returns the singleton instance of the class.
428 *
429 * @since 1.1.6
430 *
431 * @return object Class.
432 */
433 public static function get_instance() {
434
435 if ( null === self::$instance ) {
436 self::$instance = new self();
437 }
438
439 return self::$instance;
440
441 }
442
443 }
444