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

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