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

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