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

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