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

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