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

441 lines 12.8 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['plugin_sidebar_post_settings'] = new ConvertKit_Plugin_Sidebar_Post_Settings();
200 $this->classes['broadcasts_exporter'] = new ConvertKit_Broadcasts_Exporter();
201 $this->classes['broadcasts_importer'] = new ConvertKit_Broadcasts_Importer();
202 $this->classes['elementor'] = new ConvertKit_Elementor();
203 $this->classes['gutenberg'] = new ConvertKit_Gutenberg();
204 $this->classes['media_library'] = new ConvertKit_Media_Library();
205 $this->classes['output_restrict_content'] = new ConvertKit_Output_Restrict_Content();
206 $this->classes['review_request'] = new ConvertKit_Review_Request( 'Kit', 'convertkit', CONVERTKIT_PLUGIN_PATH );
207 $this->classes['preview_output'] = new ConvertKit_Preview_Output();
208 $this->classes['setup'] = new ConvertKit_Setup();
209 $this->classes['shortcodes'] = new ConvertKit_Shortcodes();
210
211 /**
212 * Initialize integration classes for the frontend web site.
213 *
214 * @since 1.9.6
215 */
216 do_action( 'convertkit_initialize_global' );
217
218 }
219
220 /**
221 * Runs the Plugin's initialization and update routines, which checks if
222 * the Plugin has just been updated to a newer version,
223 * and if so runs any specific processes that might be needed.
224 *
225 * @since 1.9.7.4
226 */
227 public function setup() {
228
229 $this->get_class( 'setup' )->initialize();
230 $this->get_class( 'setup' )->update();
231
232 }
233
234 /**
235 * Improved version of WordPress' is_admin(), which includes whether we're
236 * editing on the frontend using a Page Builder.
237 *
238 * @since 1.9.6
239 *
240 * @return bool Is Admin or Frontend Editor Request
241 */
242 public function is_admin_or_frontend_editor() {
243
244 // If we're in the wp-admin, return true.
245 if ( is_admin() ) {
246 return true;
247 }
248
249 // Pro.
250 if ( array_key_exists( 'REQUEST_URI', $_SERVER ) ) {
251 if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/pro/' ) !== false ) {
252 return true;
253 }
254 if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/x/' ) !== false ) {
255 return true;
256 }
257 if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'cornerstone-endpoint' ) !== false ) {
258 return true;
259 }
260 }
261
262 // If the request global exists, check for specific request keys which tell us
263 // that we're using a frontend editor.
264 // Avada Live.
265 // phpcs:disable WordPress.Security.NonceVerification.Recommended
266 if ( array_key_exists( 'fb-edit', $_REQUEST ) ) {
267 return true;
268 }
269
270 // Beaver Builder.
271 if ( array_key_exists( 'fl_builder', $_REQUEST ) ) {
272 return true;
273 }
274
275 // Brizy.
276 if ( array_key_exists( 'brizy-edit', $_REQUEST ) ) {
277 return true;
278 }
279
280 // Cornerstone (AJAX).
281 if ( array_key_exists( '_cs_nonce', $_REQUEST ) ) {
282 return true;
283 }
284
285 // Divi.
286 if ( array_key_exists( 'et_fb', $_REQUEST ) ) {
287 return true;
288 }
289
290 // Elementor.
291 if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) === 'elementor' ) {
292 return true;
293 }
294
295 // Kallyas.
296 if ( array_key_exists( 'zn_pb_edit', $_REQUEST ) ) {
297 return true;
298 }
299
300 // Oxygen.
301 if ( array_key_exists( 'ct_builder', $_REQUEST ) ) {
302 return true;
303 }
304
305 // Thrive Architect.
306 if ( array_key_exists( 'tve', $_REQUEST ) ) {
307 return true;
308 }
309
310 // Visual Composer.
311 if ( array_key_exists( 'vcv-editable', $_REQUEST ) ) {
312 return true;
313 }
314
315 // WPBakery Page Builder.
316 if ( array_key_exists( 'vc_editable', $_REQUEST ) ) {
317 return true;
318 }
319
320 // Zion Builder.
321 if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) === 'zion_builder_active' ) {
322 return true;
323 }
324
325 // Assume we're not in the Administration interface.
326 $is_admin_or_frontend_editor = false;
327
328 /**
329 * Filters whether the current request is a WordPress Administration / Frontend Editor request or not.
330 *
331 * Page Builders can set this to true to allow ConvertKit to load its administration functionality.
332 *
333 * @since 1.9.6
334 *
335 * @param bool $is_admin_or_frontend_editor Is WordPress Administration / Frontend Editor request.
336 */
337 $is_admin_or_frontend_editor = apply_filters( 'convertkit_is_admin_or_frontend_editor', $is_admin_or_frontend_editor );
338
339 // phpcs:enable
340
341 // Return filtered result.
342 return $is_admin_or_frontend_editor;
343
344 }
345
346 /**
347 * Detects if the request is through the WP-CLI
348 *
349 * @since 1.9.6
350 *
351 * @return bool Is WP-CLI Request
352 */
353 public function is_cli() {
354
355 if ( ! defined( 'WP_CLI' ) ) {
356 return false;
357 }
358 if ( ! WP_CLI ) {
359 return false;
360 }
361
362 return true;
363
364 }
365
366 /**
367 * Detects if the request is through the WP CRON
368 *
369 * @since 1.9.6
370 *
371 * @return bool Is WP CRON Request
372 */
373 public function is_cron() {
374
375 return wp_doing_cron();
376
377 }
378
379 /**
380 * Returns the given class
381 *
382 * @since 1.9.6
383 *
384 * @param string $name Class Name.
385 * @return object Class Object
386 */
387 public function get_class( $name ) {
388
389 // If the class hasn't been loaded, throw a WordPress die screen
390 // to avoid a PHP fatal error.
391 if ( ! isset( $this->classes[ $name ] ) ) {
392 // Define the error.
393 $error = new WP_Error(
394 'convertkit_get_class',
395 sprintf(
396 /* translators: %1$s: PHP class name */
397 __( 'Kit Error: Could not load Plugin class <strong>%1$s</strong>', 'convertkit' ),
398 $name
399 )
400 );
401
402 // Depending on the request, return or display an error.
403 // Admin UI.
404 if ( is_admin() ) {
405 wp_die(
406 esc_attr( $error->get_error_message() ),
407 esc_html__( 'Kit Error', 'convertkit' ),
408 array(
409 'back_link' => true,
410 )
411 );
412 }
413
414 // Cron / CLI.
415 return $error;
416 }
417
418 // Return the class object.
419 return $this->classes[ $name ];
420
421 }
422
423 /**
424 * Returns the singleton instance of the class.
425 *
426 * @since 1.1.6
427 *
428 * @return object Class.
429 */
430 public static function get_instance() {
431
432 if ( null === self::$instance ) {
433 self::$instance = new self();
434 }
435
436 return self::$instance;
437
438 }
439
440 }
441