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

444 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
149 /**
150 * Initialize integration classes for the frontend web site.
151 *
152 * @since 1.9.6
153 */
154 do_action( 'convertkit_initialize_frontend' );
155
156 }
157
158 /**
159 * Initialize classes required globally, across the WordPress Administration, CLI, Cron and Frontend
160 * web site.
161 *
162 * @since 1.9.6
163 */
164 private function initialize_global() {
165
166 $this->classes['ajax'] = new ConvertKit_AJAX();
167 $this->classes['blocks_convertkit_broadcasts'] = new ConvertKit_Block_Broadcasts();
168 $this->classes['blocks_convertkit_content'] = new ConvertKit_Block_Content();
169 $this->classes['blocks_convertkit_formtrigger'] = new ConvertKit_Block_Form_Trigger();
170 $this->classes['blocks_convertkit_form'] = new ConvertKit_Block_Form();
171 $this->classes['blocks_convertkit_product'] = new ConvertKit_Block_Product();
172 $this->classes['block_formatter_form_link'] = new ConvertKit_Block_Formatter_Form_Link();
173 $this->classes['block_formatter_product_link'] = new ConvertKit_Block_Formatter_Product_Link();
174 $this->classes['pre_publish_action_broadcast_export'] = new ConvertKit_Pre_Publish_Action_Broadcast_Export();
175 $this->classes['broadcasts_exporter'] = new ConvertKit_Broadcasts_Exporter();
176 $this->classes['broadcasts_importer'] = new ConvertKit_Broadcasts_Importer();
177 $this->classes['divi'] = new ConvertKit_Divi();
178 $this->classes['elementor'] = new ConvertKit_Elementor();
179 $this->classes['gutenberg'] = new ConvertKit_Gutenberg();
180 $this->classes['media_library'] = new ConvertKit_Media_Library();
181 $this->classes['output_restrict_content'] = new ConvertKit_Output_Restrict_Content();
182 $this->classes['review_request'] = new ConvertKit_Review_Request( 'Kit', 'convertkit', CONVERTKIT_PLUGIN_PATH );
183 $this->classes['preview_output'] = new ConvertKit_Preview_Output();
184 $this->classes['setup'] = new ConvertKit_Setup();
185 $this->classes['shortcodes'] = new ConvertKit_Shortcodes();
186 $this->classes['widgets'] = new ConvertKit_Widgets();
187
188 // Run the setup's update process on WordPress' init hook.
189 // Doing this sooner may result in errors with WordPress functions that are not yet
190 // available to the update routine.
191 add_action( 'init', array( $this, 'init' ) );
192
193 /**
194 * Initialize integration classes for the frontend web site.
195 *
196 * @since 1.9.6
197 */
198 do_action( 'convertkit_initialize_global' );
199
200 }
201
202 /**
203 * Runs the Plugin's initialization and update routines, which checks if
204 * the Plugin has just been updated to a newer version,
205 * and if so runs any specific processes that might be needed.
206 *
207 * @since 1.9.7.4
208 */
209 public function init() {
210
211 $this->get_class( 'setup' )->initialize();
212 $this->get_class( 'setup' )->update();
213
214 }
215
216 /**
217 * Improved version of WordPress' is_admin(), which includes whether we're
218 * editing on the frontend using a Page Builder.
219 *
220 * @since 1.9.6
221 *
222 * @return bool Is Admin or Frontend Editor Request
223 */
224 public function is_admin_or_frontend_editor() {
225
226 // If we're in the wp-admin, return true.
227 if ( is_admin() ) {
228 return true;
229 }
230
231 // Pro.
232 if ( array_key_exists( 'REQUEST_URI', $_SERVER ) ) {
233 if ( strpos( sanitize_text_field( $_SERVER['REQUEST_URI'] ), '/pro/' ) !== false ) {
234 return true;
235 }
236 if ( strpos( sanitize_text_field( $_SERVER['REQUEST_URI'] ), '/x/' ) !== false ) {
237 return true;
238 }
239 if ( strpos( sanitize_text_field( $_SERVER['REQUEST_URI'] ), 'cornerstone-endpoint' ) !== false ) {
240 return true;
241 }
242 }
243
244 // If the request global exists, check for specific request keys which tell us
245 // that we're using a frontend editor.
246 // Avada Live.
247 // phpcs:disable WordPress.Security.NonceVerification.Recommended
248 if ( array_key_exists( 'fb-edit', $_REQUEST ) ) {
249 return true;
250 }
251
252 // Beaver Builder.
253 if ( array_key_exists( 'fl_builder', $_REQUEST ) ) {
254 return true;
255 }
256
257 // Brizy.
258 if ( array_key_exists( 'brizy-edit', $_REQUEST ) ) {
259 return true;
260 }
261
262 // Cornerstone (AJAX).
263 if ( array_key_exists( '_cs_nonce', $_REQUEST ) ) {
264 return true;
265 }
266
267 // Divi.
268 if ( array_key_exists( 'et_fb', $_REQUEST ) ) {
269 return true;
270 }
271
272 // Elementor.
273 if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( $_REQUEST['action'] ) === 'elementor' ) {
274 return true;
275 }
276
277 // Kallyas.
278 if ( array_key_exists( 'zn_pb_edit', $_REQUEST ) ) {
279 return true;
280 }
281
282 // Oxygen.
283 if ( array_key_exists( 'ct_builder', $_REQUEST ) ) {
284 return true;
285 }
286
287 // Thrive Architect.
288 if ( array_key_exists( 'tve', $_REQUEST ) ) {
289 return true;
290 }
291
292 // Visual Composer.
293 if ( array_key_exists( 'vcv-editable', $_REQUEST ) ) {
294 return true;
295 }
296
297 // WPBakery Page Builder.
298 if ( array_key_exists( 'vc_editable', $_REQUEST ) ) {
299 return true;
300 }
301
302 // Zion Builder.
303 if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( $_REQUEST['action'] ) === 'zion_builder_active' ) {
304 return true;
305 }
306
307 // Assume we're not in the Administration interface.
308 $is_admin_or_frontend_editor = false;
309
310 /**
311 * Filters whether the current request is a WordPress Administration / Frontend Editor request or not.
312 *
313 * Page Builders can set this to true to allow ConvertKit to load its administration functionality.
314 *
315 * @since 1.9.6
316 *
317 * @param bool $is_admin_or_frontend_editor Is WordPress Administration / Frontend Editor request.
318 */
319 $is_admin_or_frontend_editor = apply_filters( 'convertkit_is_admin_or_frontend_editor', $is_admin_or_frontend_editor );
320
321 // phpcs:enable
322
323 // Return filtered result.
324 return $is_admin_or_frontend_editor;
325
326 }
327
328 /**
329 * Detects if the request is through the WP-CLI
330 *
331 * @since 1.9.6
332 *
333 * @return bool Is WP-CLI Request
334 */
335 public function is_cli() {
336
337 if ( ! defined( 'WP_CLI' ) ) {
338 return false;
339 }
340 if ( ! WP_CLI ) {
341 return false;
342 }
343
344 return true;
345
346 }
347
348 /**
349 * Detects if the request is through the WP CRON
350 *
351 * @since 1.9.6
352 *
353 * @return bool Is WP CRON Request
354 */
355 public function is_cron() {
356
357 if ( ! defined( 'DOING_CRON' ) ) {
358 return false;
359 }
360 if ( ! DOING_CRON ) {
361 return false;
362 }
363
364 return true;
365
366 }
367
368 /**
369 * Loads the plugin's translated strings, if available.
370 *
371 * @since 1.0.0
372 */
373 public function load_language_files() {
374
375 // If the .mo file for a given language is available in WP_LANG_DIR/convertkit
376 // i.e. it's available as a translation at https://translate.wordpress.org/projects/wp-plugins/convertkit/,
377 // it will be used instead of the .mo file in convertkit/languages.
378 load_plugin_textdomain( 'convertkit', false, 'convertkit/languages' );
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