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

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