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

440 lines 11.6 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_notices'] = new ConvertKit_Admin_Notices();
71 $this->classes['admin_post'] = new ConvertKit_Admin_Post();
72 $this->classes['admin_quick_edit'] = new ConvertKit_Admin_Quick_Edit();
73 $this->classes['admin_refresh_resources'] = new ConvertKit_Admin_Refresh_Resources();
74 $this->classes['admin_restrict_content'] = new ConvertKit_Admin_Restrict_Content();
75 $this->classes['admin_settings'] = new ConvertKit_Admin_Settings();
76 $this->classes['admin_setup_wizard_plugin'] = new ConvertKit_Admin_Setup_Wizard_Plugin();
77 $this->classes['admin_setup_wizard_restrict_content'] = new ConvertKit_Admin_Setup_Wizard_Restrict_Content();
78 $this->classes['admin_tinymce'] = new ConvertKit_Admin_TinyMCE();
79 $this->classes['admin_user'] = new ConvertKit_Admin_User();
80
81 /**
82 * Initialize integration classes for the WordPress Administration interface.
83 *
84 * @since 1.9.6
85 */
86 do_action( 'convertkit_initialize_admin' );
87
88 }
89
90 /**
91 * Initialize classes for the WordPress Administration interface or a frontend Page Builder
92 *
93 * @since 1.9.6
94 */
95 private function initialize_admin_or_frontend_editor() {
96
97 // Bail if this request isn't for the WordPress Administration interface and isn't for a frontend Page Builder.
98 if ( ! $this->is_admin_or_frontend_editor() ) {
99 return;
100 }
101
102 /**
103 * Initialize integration classes for the WordPress Administration interface or a frontend Page Builder.
104 *
105 * @since 1.9.6
106 */
107 do_action( 'convertkit_initialize_admin_or_frontend_editor' );
108
109 }
110
111 /**
112 * Initialize classes for WP-CLI and WP-Cron
113 *
114 * @since 2.5.2
115 */
116 private function initialize_cli_cron() {
117
118 // Bail if this isn't a CLI or CRON request.
119 if ( ! $this->is_cli() && ! $this->is_cron() ) {
120 return;
121 }
122
123 /**
124 * Initialize integration classes for WP-CLI and WP-Cron.
125 *
126 * @since 1.9.6
127 */
128 do_action( 'convertkit_initialize_cli_cron' );
129
130 }
131
132 /**
133 * Initialize classes for the frontend web site
134 *
135 * @since 1.9.6
136 */
137 private function initialize_frontend() {
138
139 // Bail if this request isn't for the frontend web site.
140 if ( is_admin() ) {
141 return;
142 }
143
144 $this->classes['cache_plugins'] = new ConvertKit_Cache_Plugins();
145 $this->classes['output'] = new ConvertKit_Output();
146
147 /**
148 * Initialize integration classes for the frontend web site.
149 *
150 * @since 1.9.6
151 */
152 do_action( 'convertkit_initialize_frontend' );
153
154 }
155
156 /**
157 * Initialize classes required globally, across the WordPress Administration, CLI, Cron and Frontend
158 * web site.
159 *
160 * @since 1.9.6
161 */
162 private function initialize_global() {
163
164 $this->classes['ajax'] = new ConvertKit_AJAX();
165 $this->classes['blocks_convertkit_broadcasts'] = new ConvertKit_Block_Broadcasts();
166 $this->classes['blocks_convertkit_content'] = new ConvertKit_Block_Content();
167 $this->classes['blocks_convertkit_formtrigger'] = new ConvertKit_Block_Form_Trigger();
168 $this->classes['blocks_convertkit_form'] = new ConvertKit_Block_Form();
169 $this->classes['blocks_convertkit_product'] = new ConvertKit_Block_Product();
170 $this->classes['block_formatter_form_link'] = new ConvertKit_Block_Formatter_Form_Link();
171 $this->classes['block_formatter_product_link'] = new ConvertKit_Block_Formatter_Product_Link();
172 $this->classes['pre_publish_action_broadcast_export'] = new ConvertKit_Pre_Publish_Action_Broadcast_Export();
173 $this->classes['broadcasts_exporter'] = new ConvertKit_Broadcasts_Exporter();
174 $this->classes['broadcasts_importer'] = new ConvertKit_Broadcasts_Importer();
175 $this->classes['elementor'] = new ConvertKit_Elementor();
176 $this->classes['gutenberg'] = new ConvertKit_Gutenberg();
177 $this->classes['media_library'] = new ConvertKit_Media_Library();
178 $this->classes['output_restrict_content'] = new ConvertKit_Output_Restrict_Content();
179 $this->classes['review_request'] = new ConvertKit_Review_Request( 'ConvertKit', 'convertkit', CONVERTKIT_PLUGIN_PATH );
180 $this->classes['preview_output'] = new ConvertKit_Preview_Output();
181 $this->classes['setup'] = new ConvertKit_Setup();
182 $this->classes['shortcodes'] = new ConvertKit_Shortcodes();
183 $this->classes['widgets'] = new ConvertKit_Widgets();
184
185 // Run the setup's update process on WordPress' init hook.
186 // Doing this sooner may result in errors with WordPress functions that are not yet
187 // available to the update routine.
188 add_action( 'init', array( $this, 'update' ) );
189
190 /**
191 * Initialize integration classes for the frontend web site.
192 *
193 * @since 1.9.6
194 */
195 do_action( 'convertkit_initialize_global' );
196
197 }
198
199 /**
200 * Runs the Plugin's update routine, which checks if
201 * the Plugin has just been updated to a newer version,
202 * and if so runs any specific processes that might be needed.
203 *
204 * @since 1.9.7.4
205 */
206 public function update() {
207
208 $this->get_class( 'setup' )->update();
209
210 }
211
212 /**
213 * Improved version of WordPress' is_admin(), which includes whether we're
214 * editing on the frontend using a Page Builder.
215 *
216 * @since 1.9.6
217 *
218 * @return bool Is Admin or Frontend Editor Request
219 */
220 public function is_admin_or_frontend_editor() {
221
222 // If we're in the wp-admin, return true.
223 if ( is_admin() ) {
224 return true;
225 }
226
227 // Pro.
228 if ( array_key_exists( 'REQUEST_URI', $_SERVER ) ) {
229 if ( strpos( sanitize_text_field( $_SERVER['REQUEST_URI'] ), '/pro/' ) !== false ) {
230 return true;
231 }
232 if ( strpos( sanitize_text_field( $_SERVER['REQUEST_URI'] ), '/x/' ) !== false ) {
233 return true;
234 }
235 if ( strpos( sanitize_text_field( $_SERVER['REQUEST_URI'] ), 'cornerstone-endpoint' ) !== false ) {
236 return true;
237 }
238 }
239
240 // If the request global exists, check for specific request keys which tell us
241 // that we're using a frontend editor.
242 // Avada Live.
243 // phpcs:disable WordPress.Security.NonceVerification.Recommended
244 if ( array_key_exists( 'fb-edit', $_REQUEST ) ) {
245 return true;
246 }
247
248 // Beaver Builder.
249 if ( array_key_exists( 'fl_builder', $_REQUEST ) ) {
250 return true;
251 }
252
253 // Brizy.
254 if ( array_key_exists( 'brizy-edit', $_REQUEST ) ) {
255 return true;
256 }
257
258 // Cornerstone (AJAX).
259 if ( array_key_exists( '_cs_nonce', $_REQUEST ) ) {
260 return true;
261 }
262
263 // Divi.
264 if ( array_key_exists( 'et_fb', $_REQUEST ) ) {
265 return true;
266 }
267
268 // Elementor.
269 if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( $_REQUEST['action'] ) === 'elementor' ) {
270 return true;
271 }
272
273 // Kallyas.
274 if ( array_key_exists( 'zn_pb_edit', $_REQUEST ) ) {
275 return true;
276 }
277
278 // Oxygen.
279 if ( array_key_exists( 'ct_builder', $_REQUEST ) ) {
280 return true;
281 }
282
283 // Thrive Architect.
284 if ( array_key_exists( 'tve', $_REQUEST ) ) {
285 return true;
286 }
287
288 // Visual Composer.
289 if ( array_key_exists( 'vcv-editable', $_REQUEST ) ) {
290 return true;
291 }
292
293 // WPBakery Page Builder.
294 if ( array_key_exists( 'vc_editable', $_REQUEST ) ) {
295 return true;
296 }
297
298 // Zion Builder.
299 if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( $_REQUEST['action'] ) === 'zion_builder_active' ) {
300 return true;
301 }
302
303 // Assume we're not in the Administration interface.
304 $is_admin_or_frontend_editor = false;
305
306 /**
307 * Filters whether the current request is a WordPress Administration / Frontend Editor request or not.
308 *
309 * Page Builders can set this to true to allow ConvertKit to load its administration functionality.
310 *
311 * @since 1.9.6
312 *
313 * @param bool $is_admin_or_frontend_editor Is WordPress Administration / Frontend Editor request.
314 */
315 $is_admin_or_frontend_editor = apply_filters( 'convertkit_is_admin_or_frontend_editor', $is_admin_or_frontend_editor );
316
317 // phpcs:enable
318
319 // Return filtered result.
320 return $is_admin_or_frontend_editor;
321
322 }
323
324 /**
325 * Detects if the request is through the WP-CLI
326 *
327 * @since 1.9.6
328 *
329 * @return bool Is WP-CLI Request
330 */
331 public function is_cli() {
332
333 if ( ! defined( 'WP_CLI' ) ) {
334 return false;
335 }
336 if ( ! WP_CLI ) {
337 return false;
338 }
339
340 return true;
341
342 }
343
344 /**
345 * Detects if the request is through the WP CRON
346 *
347 * @since 1.9.6
348 *
349 * @return bool Is WP CRON Request
350 */
351 public function is_cron() {
352
353 if ( ! defined( 'DOING_CRON' ) ) {
354 return false;
355 }
356 if ( ! DOING_CRON ) {
357 return false;
358 }
359
360 return true;
361
362 }
363
364 /**
365 * Loads the plugin's translated strings, if available.
366 *
367 * @since 1.0.0
368 */
369 public function load_language_files() {
370
371 // If the .mo file for a given language is available in WP_LANG_DIR/convertkit
372 // i.e. it's available as a translation at https://translate.wordpress.org/projects/wp-plugins/convertkit/,
373 // it will be used instead of the .mo file in convertkit/languages.
374 load_plugin_textdomain( 'convertkit', false, 'convertkit/languages' );
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 __( 'ConvertKit 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__( 'ConvertKit 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