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

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