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

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