PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.1.9
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.1.9
3.4.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 All 195 releases
← All changes | includes/functions.php +296 -36 2.3.33.1.9 View file →
@@ -16,8 +16,9 @@
16 16 function convertkit_plugin_activate( $network_wide ) {
17 17
18 18 // Initialise Plugin.
19 19 $convertkit = WP_ConvertKit();
20 + $convertkit->initialize();
20 21
21 22 // Check if we are on a multisite install, activating network wide, or a single install.
22 23 if ( ! is_multisite() || ! $network_wide ) {
23 24 // Single Site activation.
@@ -57,8 +58,9 @@
57 58 }
58 59
59 60 // Initialise Plugin.
60 61 $convertkit = WP_ConvertKit();
62 + $convertkit->initialize();
61 63
62 64 // Run installation routine.
63 65 switch_to_blog( $site_or_blog_id );
64 66 $convertkit->get_class( 'setup' )->activate();
@@ -76,8 +78,9 @@
76 78 function convertkit_plugin_deactivate( $network_wide ) {
77 79
78 80 // Initialise Plugin.
79 81 $convertkit = WP_ConvertKit();
82 + $convertkit->initialize();
80 83
81 84 // Check if we are on a multisite install, activating network wide, or a single install.
82 85 if ( ! is_multisite() || ! $network_wide ) {
83 86 // Single Site activation.
@@ -106,13 +109,32 @@
106 109 * @return array Post Types
107 110 */
108 111 function convertkit_get_supported_post_types() {
109 112
113 + // Define supported Post Types.
110 114 $post_types = array(
111 115 'page',
112 116 'post',
113 117 );
114 118
119 + // If public Custom Post Types can be fetched, include them now.
120 + if ( function_exists( 'get_post_types' ) ) {
121 + // Get public Custom Post Types.
122 + $custom_post_types = (array) get_post_types(
123 + array(
124 + 'public' => true,
125 +
126 + // Don't include WordPress' built in Post Types, such as attachment, revisino and nav_menu_item.
127 + '_builtin' => false,
128 + )
129 + );
130 +
131 + $post_types = array_merge(
132 + $post_types,
133 + array_keys( $custom_post_types )
134 + );
135 + }
136 +
115 137 /**
116 138 * Defines the Post Types that support ConvertKit Forms.
117 139 *
118 140 * @since 1.9.6
@@ -129,28 +151,16 @@
129 151 * Helper method to get supported Post Types for Restricted Content (Member's Content)
130 152 *
131 153 * @since 2.1.0
132 154 *
155 + * @deprecated 2.4.3 No longer used by internal code and not recommended. Use `convertkit_get_supported_post_types` instead.
156 + *
133 157 * @return array Post Types
134 158 */
135 159 function convertkit_get_supported_restrict_content_post_types() {
136 160
137 - $post_types = array(
138 - 'page',
139 - 'post',
140 - );
161 + return convertkit_get_supported_post_types();
141 162
142 - /**
143 - * Defines the Post Types that support Restricted Content / Members Content functionality.
144 - *
145 - * @since 2.0.0
146 - *
147 - * @param array $post_types Post Types
148 - */
149 - $post_types = apply_filters( 'convertkit_get_supported_restrict_content_post_types', $post_types );
150 -
151 - return $post_types;
152 -
153 163 }
154 164
155 165 /**
156 166 * Helper method to get registered Shortcodes.
@@ -248,8 +258,33 @@
248 258
249 259 }
250 260
251 261 /**
262 + * Helper method to get registered importers that can replace third party
263 + * form shortcodes and blocks with Kit form shortcodes and blocks.
264 + *
265 + * @since 3.1.7
266 + *
267 + * @return array Importers.
268 + */
269 +function convertkit_get_form_importers() {
270 +
271 + $importers = array();
272 +
273 + /**
274 + * Registers form importers for the ConvertKit Plugin.
275 + *
276 + * @since 3.1.7
277 + *
278 + * @param array $importers Importers.
279 + */
280 + $importers = apply_filters( 'convertkit_get_form_importers', $importers );
281 +
282 + return $importers;
283 +
284 +}
285 +
286 +/**
252 287 * Helper method to return the Plugin Settings Link
253 288 *
254 289 * @since 1.9.6
255 290 *
@@ -304,9 +339,9 @@
304 339 'utm_source' => 'wordpress',
305 340 'utm_term' => get_locale(),
306 341 'utm_content' => 'convertkit',
307 342 ),
308 - 'https://app.convertkit.com/users/signup'
343 + 'https://app.kit.com/users/signup'
309 344 );
310 345
311 346 }
312 347
@@ -324,9 +359,9 @@
324 359 'utm_source' => 'wordpress',
325 360 'utm_term' => get_locale(),
326 361 'utm_content' => 'convertkit',
327 362 ),
328 - 'https://app.convertkit.com/'
363 + 'https://app.kit.com/'
329 364 );
330 365
331 366 }
332 367
@@ -344,21 +379,21 @@
344 379 'utm_source' => 'wordpress',
345 380 'utm_term' => get_locale(),
346 381 'utm_content' => 'convertkit',
347 382 ),
348 - 'https://app.convertkit.com/account_settings/billing/'
383 + 'https://app.kit.com/account_settings/billing/'
349 384 );
350 385
351 386 }
352 387
353 388 /**
354 - * Helper method to return the URL the user needs to visit on the ConvertKit app to obtain their API Key and Secret.
389 + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Form or Landing Page.
355 390 *
356 - * @since 1.9.6.1
391 + * @since 2.2.3
357 392 *
358 - * @return string ConvertKit App URL.
393 + * @return string ConvertKit App URL
359 394 */
360 -function convertkit_get_api_key_url() {
395 +function convertkit_get_new_form_url() {
361 396
362 397 return add_query_arg(
363 398 array(
364 399 'utm_source' => 'wordpress',
@@ -364,21 +399,21 @@
364 399 'utm_source' => 'wordpress',
365 400 'utm_term' => get_locale(),
366 401 'utm_content' => 'convertkit',
367 402 ),
368 - 'https://app.convertkit.com/account_settings/advanced_settings/'
403 + 'https://app.kit.com/forms/new/'
369 404 );
370 405
371 406 }
372 407
373 408 /**
374 - * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Form or Landing Page.
409 + * Helper method to return the URL the user needs to visit to edit ConvertKit forms.
375 410 *
376 411 * @since 2.2.3
377 412 *
378 - * @return string ConvertKit App URL
413 + * @return string ConvertKit Form Editor URL.
379 414 */
380 -function convertkit_get_new_form_url() {
415 +function convertkit_get_form_editor_url() {
381 416
382 417 return add_query_arg(
383 418 array(
384 419 'utm_source' => 'wordpress',
@@ -384,21 +419,21 @@
384 419 'utm_source' => 'wordpress',
385 420 'utm_term' => get_locale(),
386 421 'utm_content' => 'convertkit',
387 422 ),
388 - 'https://app.convertkit.com/forms/new/'
423 + 'https://app.kit.com/forms'
389 424 );
390 425
391 426 }
392 427
393 428 /**
394 - * Helper method to return the URL the user needs to visit to edit ConvertKit forms.
429 + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Landing Page.
395 430 *
396 - * @since 2.2.3
431 + * @since 2.5.5
397 432 *
398 - * @return string ConvertKit Form Editor URL.
433 + * @return string ConvertKit App URL
399 434 */
400 -function convertkit_get_form_editor_url() {
435 +function convertkit_get_new_landing_page_url() {
401 436
402 437 return add_query_arg(
403 438 array(
404 439 'utm_source' => 'wordpress',
@@ -404,9 +439,9 @@
404 439 'utm_source' => 'wordpress',
405 440 'utm_term' => get_locale(),
406 441 'utm_content' => 'convertkit',
407 442 ),
408 - 'https://app.convertkit.com/forms'
443 + 'https://app.kit.com/pages/new/'
409 444 );
410 445
411 446 }
412 447
@@ -424,9 +459,9 @@
424 459 'utm_source' => 'wordpress',
425 460 'utm_term' => get_locale(),
426 461 'utm_content' => 'convertkit',
427 462 ),
428 - 'https://app.convertkit.com/subscribers/'
463 + 'https://app.kit.com/subscribers/'
429 464 );
430 465
431 466 }
432 467
@@ -444,9 +479,9 @@
444 479 'utm_source' => 'wordpress',
445 480 'utm_term' => get_locale(),
446 481 'utm_content' => 'convertkit',
447 482 ),
448 - 'https://app.convertkit.com/campaigns/'
483 + 'https://app.kit.com/campaigns/'
449 484 );
450 485
451 486 }
452 487
@@ -466,9 +501,9 @@
466 501 'utm_term' => get_locale(),
467 502 'utm_content' => 'convertkit',
468 503 ),
469 504 sprintf(
470 - 'https://app.convertkit.com/campaigns/%s/draft',
505 + 'https://app.kit.com/campaigns/%s/draft',
471 506 $broadcast_id
472 507 )
473 508 );
474 509
@@ -488,9 +523,9 @@
488 523 'utm_source' => 'wordpress',
489 524 'utm_term' => get_locale(),
490 525 'utm_content' => 'convertkit',
491 526 ),
492 - 'https://app.convertkit.com/products/new/'
527 + 'https://app.kit.com/products/new/'
493 528 );
494 529
495 530 }
496 531
@@ -544,4 +579,229 @@
544 579 // Return file's contents.
545 580 return $contents;
546 581
547 582 }
583 +
584 +/**
585 + * Returns a dropdown field commonly used for settings, comprising of:
586 + * - Do not subscribe
587 + * - Subscribe
588 + * - Subscribe to Form
589 + *
590 + * @since 2.5.2
591 + *
592 + * @param string $name Field name.
593 + * @param string $value Field value.
594 + * @param string $id Field ID attribute.
595 + * @param string $css_class Field CSS class(es).
596 + * @param string $context Resource context.
597 + * @param bool|array $additional_options Additional <option> key/value pairs.
598 + */
599 +function convertkit_get_subscription_dropdown_field( $name, $value, $id, $css_class = '', $context = '', $additional_options = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
600 +
601 + // Load resource classes.
602 + $forms = new ConvertKit_Resource_Forms( $context );
603 + $tags = new ConvertKit_Resource_Tags( $context );
604 + $sequences = new ConvertKit_Resource_Sequences( $context );
605 +
606 + ob_start();
607 + include CONVERTKIT_PLUGIN_PATH . '/views/backend/subscription-dropdown-field.php';
608 + $output = trim( ob_get_clean() );
609 +
610 + // Return output.
611 + return $output;
612 +
613 +}
614 +
615 +/**
616 + * Helper method to safely call get_current_screen(), returning false
617 + * if the function is not available or returns null.
618 + *
619 + * Otherwise returns the given WP_Screen property.
620 + *
621 + * @since 2.5.9
622 + *
623 + * @param string $property WP_Screen property to return.
624 + * @return bool|string
625 + */
626 +function convertkit_get_current_screen( $property ) {
627 +
628 + // Bail if we cannot determine the screen.
629 + if ( ! function_exists( 'get_current_screen' ) ) {
630 + return false;
631 + }
632 +
633 + // Get screen.
634 + $screen = get_current_screen();
635 +
636 + // Bail if the screen couldn't be determined.
637 + if ( is_null( $screen ) ) {
638 + return false;
639 + }
640 +
641 + // Return property.
642 + return $screen->$property;
643 +
644 +}
645 +
646 +/**
647 + * Outputs the Intercom help widget script.
648 + *
649 + * @since 2.7.2
650 + */
651 +function convertkit_output_intercom_messenger() {
652 +
653 + ?>
654 + <script>
655 + const KIT_INTERCOM_APP_ID = 'e4n3xtxz';
656 + window.intercomSettings = {
657 + api_base: 'https://api-iam.intercom.io',
658 + app_id: KIT_INTERCOM_APP_ID
659 + };
660 + </script>
661 +
662 + <script>
663 + (function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/' + KIT_INTERCOM_APP_ID;var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s, x);};if(document.readyState==='complete'){l();}else if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();
664 + </script>
665 + <?php
666 +
667 +}
668 +
669 +/**
670 + * Checks if the given Theme is active.
671 + *
672 + * @since 3.1.4
673 + *
674 + * @param string $theme_name Theme name.
675 + * @return bool
676 + */
677 +function convertkit_is_theme_active( $theme_name ) {
678 +
679 + // Assume Theme isn't active if we can't detect it.
680 + if ( ! function_exists( 'wp_get_theme' ) ) {
681 + return false;
682 + }
683 +
684 + // Check the Parent Theme if we're on a Child Theme.
685 + if ( wp_get_theme()->parent() ) {
686 + $theme = wp_get_theme()->parent();
687 + } else {
688 + $theme = wp_get_theme();
689 + }
690 +
691 + return strtolower( $theme->get( 'Name' ) ) === strtolower( $theme_name );
692 +
693 +}
694 +
695 +/**
696 + * Returns permitted HTML output when using wp_kses( ..., convertkit_kses_allowed_html()).
697 + *
698 + * @since 2.8.5
699 + */
700 +function convertkit_kses_allowed_html() {
701 +
702 + // Get WordPress' permitted HTML elements.
703 + $elements = wp_kses_allowed_html( 'post' );
704 +
705 + // Add form elements.
706 + $form_elements = array(
707 + 'input' => array(
708 + 'type' => true,
709 + 'id' => true,
710 + 'name' => true,
711 + 'class' => true,
712 + 'value' => true,
713 + 'checked' => true,
714 + 'min' => true,
715 + 'max' => true,
716 + 'step' => true,
717 + 'data-*' => true,
718 + ),
719 + 'select' => array(
720 + 'id' => true,
721 + 'name' => true,
722 + 'class' => true,
723 + 'size' => true,
724 + 'multiple' => true,
725 + 'data-*' => true,
726 + ),
727 + 'option' => array(
728 + 'value' => true,
729 + 'selected' => true,
730 + 'data-*' => true,
731 + ),
732 + 'optgroup' => array(
733 + 'label' => true,
734 + 'data-*' => true,
735 + ),
736 + 'label' => array(
737 + 'for' => true,
738 + ),
739 + );
740 +
741 + return array_merge( $elements, $form_elements );
742 +
743 +}
744 +
745 +/**
746 + * Saves the new access token, refresh token and its expiry, and schedules
747 + * a WordPress Cron event to refresh the token on expiry.
748 + *
749 + * @since 3.1.1
750 + *
751 + * @param array $result New Access Token, Refresh Token and Expiry.
752 + * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
753 + */
754 +function convertkit_maybe_update_credentials( $result, $client_id ) {
755 +
756 + // Don't save these credentials if they're not for this Client ID.
757 + // They're for another Kit Plugin that uses OAuth.
758 + if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) {
759 + return;
760 + }
761 +
762 + $settings = new ConvertKit_Settings();
763 + $settings->update_credentials( $result );
764 +
765 +}
766 +
767 +/**
768 + * Deletes the stored access token, refresh token and its expiry from the Plugin settings,
769 + * and clears any existing scheduled WordPress Cron event to refresh the token on expiry,
770 + * when either:
771 + * - The access token is invalid
772 + * - The access token expired, and refreshing failed
773 + *
774 + * @since 3.1.1
775 + *
776 + * @param WP_Error $result Error result.
777 + * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
778 + */
779 +function convertkit_maybe_delete_credentials( $result, $client_id ) {
780 +
781 + // Don't save these credentials if they're not for this Client ID.
782 + // They're for another Kit Plugin that uses OAuth.
783 + if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) {
784 + return;
785 + }
786 +
787 + // If the error isn't a 401, don't delete credentials.
788 + // This could be e.g. a temporary network error, rate limit or similar.
789 + if ( $result->get_error_data( 'convertkit_api_error' ) !== 401 ) {
790 + return;
791 + }
792 +
793 + // Persist an error notice in the WordPress Administration until the user fixes the problem.
794 + WP_ConvertKit()->get_class( 'admin_notices' )->add( 'authorization_failed' );
795 +
796 + $settings = new ConvertKit_Settings();
797 + $settings->delete_credentials();
798 +
799 +}
800 +
801 +// Update Access Token when refreshed by the API class.
802 +add_action( 'convertkit_api_get_access_token', 'convertkit_maybe_update_credentials', 10, 2 );
803 +add_action( 'convertkit_api_refresh_token', 'convertkit_maybe_update_credentials', 10, 2 );
804 +
805 +// Delete credentials if the API class uses a invalid access token.
806 +// This prevents the Plugin making repetitive API requests that will 401.
807 +add_action( 'convertkit_api_access_token_invalid', 'convertkit_maybe_delete_credentials', 10, 2 );