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

425 lines 10.2 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 public 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_category'] = new ConvertKit_Admin_Category();
69 $this->classes['admin_post'] = new ConvertKit_Admin_Post();
70 $this->classes['admin_quick_edit'] = new ConvertKit_Admin_Quick_Edit();
71 $this->classes['admin_refresh_resources'] = new ConvertKit_Admin_Refresh_Resources();
72 $this->classes['admin_settings'] = new ConvertKit_Admin_Settings();
73 $this->classes['admin_setup_wizard_plugin'] = new ConvertKit_Admin_Setup_Wizard_Plugin();
74 $this->classes['admin_tinymce'] = new ConvertKit_Admin_TinyMCE();
75 $this->classes['admin_user'] = new ConvertKit_Admin_User();
76
77 /**
78 * Initialize integration classes for the WordPress Administration interface.
79 *
80 * @since 1.9.6
81 */
82 do_action( 'convertkit_initialize_admin' );
83
84 }
85
86 /**
87 * Initialize classes for the WordPress Administration interface or a frontend Page Builder
88 *
89 * @since 1.9.6
90 */
91 private function initialize_admin_or_frontend_editor() {
92
93 // Bail if this request isn't for the WordPress Administration interface and isn't for a frontend Page Builder.
94 if ( ! $this->is_admin_or_frontend_editor() ) {
95 return;
96 }
97
98 /**
99 * Initialize integration classes for the WordPress Administration interface or a frontend Page Builder.
100 *
101 * @since 1.9.6
102 */
103 do_action( 'convertkit_initialize_admin_or_frontend_editor' );
104
105 }
106
107 /**
108 * Initialize classes for WP-CLI and WP-Cron
109 *
110 * @since 2.5.2
111 */
112 private function initialize_cli_cron() {
113
114 // Bail if this isn't a CLI or CRON request.
115 if ( ! $this->is_cli() && ! $this->is_cron() ) {
116 return;
117 }
118
119 /**
120 * Initialize integration classes for WP-CLI and WP-Cron.
121 *
122 * @since 1.9.6
123 */
124 do_action( 'convertkit_initialize_cli_cron' );
125
126 }
127
128 /**
129 * Initialize classes for the frontend web site
130 *
131 * @since 1.9.6
132 */
133 private function initialize_frontend() {
134
135 // Bail if this request isn't for the frontend web site.
136 if ( is_admin() ) {
137 return;
138 }
139
140 $this->classes['output'] = new ConvertKit_Output();
141
142 /**
143 * Initialize integration classes for the frontend web site.
144 *
145 * @since 1.9.6
146 */
147 do_action( 'convertkit_initialize_frontend' );
148
149 }
150
151 /**
152 * Initialize classes required globally, across the WordPress Administration, CLI, Cron and Frontend
153 * web site.
154 *
155 * @since 1.9.6
156 */
157 private function initialize_global() {
158
159 $this->classes['ajax'] = new ConvertKit_AJAX();
160 $this->classes['blocks_convertkit_broadcasts'] = new ConvertKit_Block_Broadcasts();
161 $this->classes['blocks_convertkit_content'] = new ConvertKit_Block_Content();
162 $this->classes['blocks_convertkit_product'] = new ConvertKit_Block_Product();
163 $this->classes['blocks_convertkit_form'] = new ConvertKit_Block_Form();
164 $this->classes['elementor'] = new ConvertKit_Elementor();
165 $this->classes['gutenberg'] = new ConvertKit_Gutenberg();
166 $this->classes['post_type_product'] = new ConvertKit_Post_Type_Product();
167 $this->classes['review_request'] = new ConvertKit_Review_Request( 'ConvertKit', 'convertkit', CONVERTKIT_PLUGIN_PATH );
168 $this->classes['preview_output'] = new ConvertKit_Preview_Output();
169 $this->classes['setup'] = new ConvertKit_Setup();
170 $this->classes['shortcodes'] = new ConvertKit_Shortcodes();
171 $this->classes['widgets'] = new ConvertKit_Widgets();
172
173 // Run the setup's update process on WordPress' init hook.
174 // Doing this sooner may result in errors with WordPress functions that are not yet
175 // available to the update routine.
176 add_action( 'init', array( $this, 'update' ) );
177
178 /**
179 * Initialize integration classes for the frontend web site.
180 *
181 * @since 1.9.6
182 */
183 do_action( 'convertkit_initialize_global' );
184
185 }
186
187 /**
188 * Runs the Plugin's update routine, which checks if
189 * the Plugin has just been updated to a newer version,
190 * and if so runs any specific processes that might be needed.
191 *
192 * @since 1.9.7.4
193 */
194 public function update() {
195
196 $this->get_class( 'setup' )->update();
197
198 }
199
200 /**
201 * Improved version of WordPress' is_admin(), which includes whether we're
202 * editing on the frontend using a Page Builder.
203 *
204 * @since 1.9.6
205 *
206 * @return bool Is Admin or Frontend Editor Request
207 */
208 public function is_admin_or_frontend_editor() {
209
210 // If we're in the wp-admin, return true.
211 if ( is_admin() ) {
212 return true;
213 }
214
215 // Pro.
216 if ( array_key_exists( 'REQUEST_URI', $_SERVER ) ) {
217 if ( strpos( sanitize_text_field( $_SERVER['REQUEST_URI'] ), '/pro/' ) !== false ) {
218 return true;
219 }
220 if ( strpos( sanitize_text_field( $_SERVER['REQUEST_URI'] ), '/x/' ) !== false ) {
221 return true;
222 }
223 if ( strpos( sanitize_text_field( $_SERVER['REQUEST_URI'] ), 'cornerstone-endpoint' ) !== false ) {
224 return true;
225 }
226 }
227
228 // If the request global exists, check for specific request keys which tell us
229 // that we're using a frontend editor.
230 // Avada Live.
231 // phpcs:disable WordPress.Security.NonceVerification.Recommended
232 if ( array_key_exists( 'fb-edit', $_REQUEST ) ) {
233 return true;
234 }
235
236 // Beaver Builder.
237 if ( array_key_exists( 'fl_builder', $_REQUEST ) ) {
238 return true;
239 }
240
241 // Brizy.
242 if ( array_key_exists( 'brizy-edit', $_REQUEST ) ) {
243 return true;
244 }
245
246 // Cornerstone (AJAX).
247 if ( array_key_exists( '_cs_nonce', $_REQUEST ) ) {
248 return true;
249 }
250
251 // Divi.
252 if ( array_key_exists( 'et_fb', $_REQUEST ) ) {
253 return true;
254 }
255
256 // Elementor.
257 if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( $_REQUEST['action'] ) === 'elementor' ) {
258 return true;
259 }
260
261 // Kallyas.
262 if ( array_key_exists( 'zn_pb_edit', $_REQUEST ) ) {
263 return true;
264 }
265
266 // Oxygen.
267 if ( array_key_exists( 'ct_builder', $_REQUEST ) ) {
268 return true;
269 }
270
271 // Thrive Architect.
272 if ( array_key_exists( 'tve', $_REQUEST ) ) {
273 return true;
274 }
275
276 // Visual Composer.
277 if ( array_key_exists( 'vcv-editable', $_REQUEST ) ) {
278 return true;
279 }
280
281 // WPBakery Page Builder.
282 if ( array_key_exists( 'vc_editable', $_REQUEST ) ) {
283 return true;
284 }
285
286 // Zion Builder.
287 if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( $_REQUEST['action'] ) === 'zion_builder_active' ) {
288 return true;
289 }
290
291 // Assume we're not in the Administration interface.
292 $is_admin_or_frontend_editor = false;
293
294 /**
295 * Filters whether the current request is a WordPress Administration / Frontend Editor request or not.
296 *
297 * Page Builders can set this to true to allow ConvertKit to load its administration functionality.
298 *
299 * @since 1.9.6
300 *
301 * @param bool $is_admin_or_frontend_editor Is WordPress Administration / Frontend Editor request.
302 */
303 $is_admin_or_frontend_editor = apply_filters( 'convertkit_is_admin_or_frontend_editor', $is_admin_or_frontend_editor );
304
305 // phpcs:enable
306
307 // Return filtered result.
308 return $is_admin_or_frontend_editor;
309
310 }
311
312 /**
313 * Detects if the request is through the WP-CLI
314 *
315 * @since 1.9.6
316 *
317 * @return bool Is WP-CLI Request
318 */
319 public function is_cli() {
320
321 if ( ! defined( 'WP_CLI' ) ) {
322 return false;
323 }
324 if ( ! WP_CLI ) {
325 return false;
326 }
327
328 return true;
329
330 }
331
332 /**
333 * Detects if the request is through the WP CRON
334 *
335 * @since 1.9.6
336 *
337 * @return bool Is WP CRON Request
338 */
339 public function is_cron() {
340
341 if ( ! defined( 'DOING_CRON' ) ) {
342 return false;
343 }
344 if ( ! DOING_CRON ) {
345 return false;
346 }
347
348 return true;
349
350 }
351
352 /**
353 * Loads plugin textdomain
354 *
355 * @since 1.0.0
356 */
357 public function load_language_files() {
358
359 load_plugin_textdomain( 'convertkit', false, basename( dirname( CONVERTKIT_PLUGIN_FILE ) ) . '/languages/' ); // @phpstan-ignore-line.
360
361 }
362
363 /**
364 * Returns the given class
365 *
366 * @since 1.9.6
367 *
368 * @param string $name Class Name.
369 * @return object Class Object
370 */
371 public function get_class( $name ) {
372
373 // If the class hasn't been loaded, throw a WordPress die screen
374 // to avoid a PHP fatal error.
375 if ( ! isset( $this->classes[ $name ] ) ) {
376 // Define the error.
377 $error = new WP_Error(
378 'convertkit_get_class',
379 sprintf(
380 /* translators: %1$s: PHP class name */
381 __( 'ConvertKit Error: Could not load Plugin class <strong>%1$s</strong>', 'convertkit' ),
382 $name
383 )
384 );
385
386 // Depending on the request, return or display an error.
387 // Admin UI.
388 if ( is_admin() ) {
389 wp_die(
390 esc_attr( $error->get_error_message() ),
391 esc_html__( 'ConvertKit Error', 'convertkit' ),
392 array(
393 'back_link' => true,
394 )
395 );
396 }
397
398 // Cron / CLI.
399 return $error;
400 }
401
402 // Return the class object.
403 return $this->classes[ $name ];
404
405 }
406
407 /**
408 * Returns the singleton instance of the class.
409 *
410 * @since 1.1.6
411 *
412 * @return object Class.
413 */
414 public static function get_instance() {
415
416 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { // @phpstan-ignore-line.
417 self::$instance = new self();
418 }
419
420 return self::$instance;
421
422 }
423
424 }
425