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

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