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

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