PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.5.1
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.5.1
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
← All changes | includes/functions.php +17 -365 3.3.82.5.1 View file →
@@ -16,9 +16,8 @@
16 16 function convertkit_plugin_activate( $network_wide ) {
17 17
18 18 // Initialise Plugin.
19 19 $convertkit = WP_ConvertKit();
20 - $convertkit->initialize();
21 20
22 21 // Check if we are on a multisite install, activating network wide, or a single install.
23 22 if ( ! is_multisite() || ! $network_wide ) {
24 23 // Single Site activation.
@@ -58,9 +57,8 @@
58 57 }
59 58
60 59 // Initialise Plugin.
61 60 $convertkit = WP_ConvertKit();
62 - $convertkit->initialize();
63 61
64 62 // Run installation routine.
65 63 switch_to_blog( $site_or_blog_id );
66 64 $convertkit->get_class( 'setup' )->activate();
@@ -78,9 +76,8 @@
78 76 function convertkit_plugin_deactivate( $network_wide ) {
79 77
80 78 // Initialise Plugin.
81 79 $convertkit = WP_ConvertKit();
82 - $convertkit->initialize();
83 80
84 81 // Check if we are on a multisite install, activating network wide, or a single install.
85 82 if ( ! is_multisite() || ! $network_wide ) {
86 83 // Single Site activation.
@@ -118,9 +115,9 @@
118 115
119 116 // If public Custom Post Types can be fetched, include them now.
120 117 if ( function_exists( 'get_post_types' ) ) {
121 118 // Get public Custom Post Types.
122 - $custom_post_types = (array) get_post_types(
119 + $custom_post_types = get_post_types(
123 120 array(
124 121 'public' => true,
125 122
126 123 // Don't include WordPress' built in Post Types, such as attachment, revisino and nav_menu_item.
@@ -127,12 +124,15 @@
127 124 '_builtin' => false,
128 125 )
129 126 );
130 127
131 - $post_types = array_merge(
132 - $post_types,
133 - array_keys( $custom_post_types )
134 - );
128 + // Sanity check an array was returned.
129 + if ( is_array( $custom_post_types ) ) {
130 + $post_types = array_merge(
131 + $post_types,
132 + array_keys( $custom_post_types )
133 + );
134 + }
135 135 }
136 136
137 137 /**
138 138 * Defines the Post Types that support ConvertKit Forms.
@@ -234,32 +234,8 @@
234 234
235 235 }
236 236
237 237 /**
238 - * Helper method to get registered plugin sidebars.
239 - *
240 - * @since 3.3.0
241 - *
242 - * @return array Plugin sidebars
243 - */
244 -function convertkit_get_plugin_sidebars() {
245 -
246 - $plugin_sidebars = array();
247 -
248 - /**
249 - * Registers plugin sidebars for the WordPress block editor.
250 - *
251 - * @since 3.3.0
252 - *
253 - * @param array $plugin_sidebars Plugin sidebars.
254 - */
255 - $plugin_sidebars = apply_filters( 'convertkit_plugin_sidebars', $plugin_sidebars );
256 -
257 - return $plugin_sidebars;
258 -
259 -}
260 -
261 -/**
262 238 * Helper method to get registered pre-publish actions.
263 239 *
264 240 * @since 2.4.0
265 241 *
@@ -282,33 +258,8 @@
282 258
283 259 }
284 260
285 261 /**
286 - * Helper method to get registered importers that can replace third party
287 - * form shortcodes and blocks with Kit form shortcodes and blocks.
288 - *
289 - * @since 3.1.7
290 - *
291 - * @return array Importers.
292 - */
293 -function convertkit_get_form_importers() {
294 -
295 - $importers = array();
296 -
297 - /**
298 - * Registers form importers for the ConvertKit Plugin.
299 - *
300 - * @since 3.1.7
301 - *
302 - * @param array $importers Importers.
303 - */
304 - $importers = apply_filters( 'convertkit_get_form_importers', $importers );
305 -
306 - return $importers;
307 -
308 -}
309 -
310 -/**
311 262 * Helper method to return the Plugin Settings Link
312 263 *
313 264 * @since 1.9.6
314 265 *
@@ -363,9 +314,9 @@
363 314 'utm_source' => 'wordpress',
364 315 'utm_term' => get_locale(),
365 316 'utm_content' => 'convertkit',
366 317 ),
367 - 'https://app.kit.com/users/signup'
318 + 'https://app.convertkit.com/users/signup'
368 319 );
369 320
370 321 }
371 322
@@ -383,9 +334,9 @@
383 334 'utm_source' => 'wordpress',
384 335 'utm_term' => get_locale(),
385 336 'utm_content' => 'convertkit',
386 337 ),
387 - 'https://app.kit.com/'
338 + 'https://app.convertkit.com/'
388 339 );
389 340
390 341 }
391 342
@@ -403,9 +354,9 @@
403 354 'utm_source' => 'wordpress',
404 355 'utm_term' => get_locale(),
405 356 'utm_content' => 'convertkit',
406 357 ),
407 - 'https://app.kit.com/account_settings/billing/'
358 + 'https://app.convertkit.com/account_settings/billing/'
408 359 );
409 360
410 361 }
411 362
@@ -423,9 +374,9 @@
423 374 'utm_source' => 'wordpress',
424 375 'utm_term' => get_locale(),
425 376 'utm_content' => 'convertkit',
426 377 ),
427 - 'https://app.kit.com/forms/new/'
378 + 'https://app.convertkit.com/forms/new/'
428 379 );
429 380
430 381 }
431 382
@@ -443,34 +394,14 @@
443 394 'utm_source' => 'wordpress',
444 395 'utm_term' => get_locale(),
445 396 'utm_content' => 'convertkit',
446 397 ),
447 - 'https://app.kit.com/forms'
398 + 'https://app.convertkit.com/forms'
448 399 );
449 400
450 401 }
451 402
452 403 /**
453 - * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Landing Page.
454 - *
455 - * @since 2.5.5
456 - *
457 - * @return string ConvertKit App URL
458 - */
459 -function convertkit_get_new_landing_page_url() {
460 -
461 - return add_query_arg(
462 - array(
463 - 'utm_source' => 'wordpress',
464 - 'utm_term' => get_locale(),
465 - 'utm_content' => 'convertkit',
466 - ),
467 - 'https://app.kit.com/pages/new/'
468 - );
469 -
470 -}
471 -
472 -/**
473 404 * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Tag.
474 405 *
475 406 * @since 2.3.3
476 407 *
@@ -483,9 +414,9 @@
483 414 'utm_source' => 'wordpress',
484 415 'utm_term' => get_locale(),
485 416 'utm_content' => 'convertkit',
486 417 ),
487 - 'https://app.kit.com/subscribers/'
418 + 'https://app.convertkit.com/subscribers/'
488 419 );
489 420
490 421 }
491 422
@@ -503,9 +434,9 @@
503 434 'utm_source' => 'wordpress',
504 435 'utm_term' => get_locale(),
505 436 'utm_content' => 'convertkit',
506 437 ),
507 - 'https://app.kit.com/campaigns/'
438 + 'https://app.convertkit.com/campaigns/'
508 439 );
509 440
510 441 }
511 442
@@ -525,9 +456,9 @@
525 456 'utm_term' => get_locale(),
526 457 'utm_content' => 'convertkit',
527 458 ),
528 459 sprintf(
529 - 'https://app.kit.com/campaigns/%s/draft',
460 + 'https://app.convertkit.com/campaigns/%s/draft',
530 461 $broadcast_id
531 462 )
532 463 );
533 464
@@ -547,42 +478,14 @@
547 478 'utm_source' => 'wordpress',
548 479 'utm_term' => get_locale(),
549 480 'utm_content' => 'convertkit',
550 481 ),
551 - 'https://app.kit.com/products/new/'
482 + 'https://app.convertkit.com/products/new/'
552 483 );
553 484
554 485 }
555 486
556 487 /**
557 - * Helper method to enqueue the frontend CSS file.
558 - *
559 - * @since 3.2.0
560 - */
561 -function convertkit_enqueue_frontend_css() {
562 -
563 - wp_enqueue_style( 'convertkit-frontend', CONVERTKIT_PLUGIN_URL . 'resources/frontend/css/frontend.css', array(), CONVERTKIT_PLUGIN_VERSION );
564 -
565 -}
566 -
567 -/**
568 - * Helper method to enqueue the frontend JS file.
569 - *
570 - * @since 3.2.0
571 - */
572 -function convertkit_enqueue_frontend_js() {
573 -
574 - wp_enqueue_script(
575 - 'convertkit-js',
576 - CONVERTKIT_PLUGIN_URL . 'resources/frontend/js/dist/frontend.min.js',
577 - array(),
578 - CONVERTKIT_PLUGIN_VERSION,
579 - true
580 - );
581 -
582 -}
583 -
584 -/**
585 488 * Helper method to enqueue Select2 scripts for use within the ConvertKit Plugin.
586 489 *
587 490 * @since 1.9.6.4
588 491 */
@@ -631,255 +534,4 @@
631 534 // Return file's contents.
632 535 return $contents;
633 536
634 537 }
635 -
636 -/**
637 - * Returns a dropdown field commonly used for settings, comprising of:
638 - * - Do not subscribe
639 - * - Subscribe
640 - * - Subscribe to Form
641 - *
642 - * @since 2.5.2
643 - *
644 - * @param string $name Field name.
645 - * @param string $value Field value.
646 - * @param string $id Field ID attribute.
647 - * @param string $css_class Field CSS class(es).
648 - * @param string $context Resource context.
649 - * @param bool|array $additional_options Additional <option> key/value pairs.
650 - */
651 -function convertkit_get_subscription_dropdown_field( $name, $value, $id, $css_class = '', $context = '', $additional_options = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
652 -
653 - // Load resource classes.
654 - $forms = new ConvertKit_Resource_Forms( $context );
655 - $tags = new ConvertKit_Resource_Tags( $context );
656 - $sequences = new ConvertKit_Resource_Sequences( $context );
657 -
658 - ob_start();
659 - include CONVERTKIT_PLUGIN_PATH . '/views/backend/subscription-dropdown-field.php';
660 - $output = trim( ob_get_clean() );
661 -
662 - // Return output.
663 - return $output;
664 -
665 -}
666 -
667 -/**
668 - * Helper method to safely call get_current_screen(), returning false
669 - * if the function is not available or returns null.
670 - *
671 - * Otherwise returns the given WP_Screen property.
672 - *
673 - * @since 2.5.9
674 - *
675 - * @param string $property WP_Screen property to return.
676 - * @return bool|string
677 - */
678 -function convertkit_get_current_screen( $property ) {
679 -
680 - // Bail if we cannot determine the screen.
681 - if ( ! function_exists( 'get_current_screen' ) ) {
682 - return false;
683 - }
684 -
685 - // Get screen.
686 - $screen = get_current_screen();
687 -
688 - // Bail if the screen couldn't be determined.
689 - if ( is_null( $screen ) ) {
690 - return false;
691 - }
692 -
693 - // Return property.
694 - return $screen->$property;
695 -
696 -}
697 -
698 -/**
699 - * Outputs the Intercom help widget script.
700 - *
701 - * @since 2.7.2
702 - */
703 -function convertkit_output_intercom_messenger() {
704 -
705 - ?>
706 - <script>
707 - const KIT_INTERCOM_APP_ID = 'e4n3xtxz';
708 - window.intercomSettings = {
709 - api_base: 'https://api-iam.intercom.io',
710 - app_id: KIT_INTERCOM_APP_ID
711 - };
712 - </script>
713 -
714 - <script>
715 - (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);}}})();
716 - </script>
717 - <?php
718 -
719 -}
720 -
721 -/**
722 - * Checks if the given Theme is active.
723 - *
724 - * @since 3.1.4
725 - *
726 - * @param string $theme_name Theme name.
727 - * @return bool
728 - */
729 -function convertkit_is_theme_active( $theme_name ) {
730 -
731 - // Assume Theme isn't active if we can't detect it.
732 - if ( ! function_exists( 'wp_get_theme' ) ) {
733 - return false;
734 - }
735 -
736 - // Check the Parent Theme if we're on a Child Theme.
737 - if ( wp_get_theme()->parent() ) {
738 - $theme = wp_get_theme()->parent();
739 - } else {
740 - $theme = wp_get_theme();
741 - }
742 -
743 - return strtolower( $theme->get( 'Name' ) ) === strtolower( $theme_name );
744 -
745 -}
746 -
747 -/**
748 - * Returns permitted HTML output when using wp_kses( ..., convertkit_kses_allowed_html()).
749 - *
750 - * @since 2.8.5
751 - */
752 -function convertkit_kses_allowed_html() {
753 -
754 - // Get WordPress' permitted HTML elements.
755 - $elements = wp_kses_allowed_html( 'post' );
756 -
757 - // Add form elements.
758 - $form_elements = array(
759 - 'input' => array(
760 - 'type' => true,
761 - 'id' => true,
762 - 'name' => true,
763 - 'class' => true,
764 - 'value' => true,
765 - 'checked' => true,
766 - 'min' => true,
767 - 'max' => true,
768 - 'step' => true,
769 - 'data-*' => true,
770 - ),
771 - 'select' => array(
772 - 'id' => true,
773 - 'name' => true,
774 - 'class' => true,
775 - 'size' => true,
776 - 'multiple' => true,
777 - 'data-*' => true,
778 - ),
779 - 'option' => array(
780 - 'value' => true,
781 - 'selected' => true,
782 - 'data-*' => true,
783 - ),
784 - 'optgroup' => array(
785 - 'label' => true,
786 - 'data-*' => true,
787 - ),
788 - 'label' => array(
789 - 'for' => true,
790 - ),
791 - );
792 -
793 - return array_merge( $elements, $form_elements );
794 -
795 -}
796 -
797 -/**
798 - * Saves the new access token, refresh token and its expiry, and schedules
799 - * a WordPress Cron event to refresh the token on expiry.
800 - *
801 - * @since 3.1.1
802 - *
803 - * @param array $result New Access Token, Refresh Token and Expiry.
804 - * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
805 - */
806 -function convertkit_maybe_update_credentials( $result, $client_id ) {
807 -
808 - // Don't save these credentials if they're not for this Client ID.
809 - // They're for another Kit Plugin that uses OAuth.
810 - if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) {
811 - return;
812 - }
813 -
814 - $settings = new ConvertKit_Settings();
815 - $settings->update_credentials( $result );
816 -
817 -}
818 -
819 -/**
820 - * Deletes the stored access token, refresh token and its expiry from the Plugin settings,
821 - * and clears any existing scheduled WordPress Cron event to refresh the token on expiry,
822 - * when the user revokes the access token.
823 - *
824 - * @since 3.2.4
825 - *
826 - * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
827 - */
828 -function convertkit_delete_credentials( $client_id ) {
829 -
830 - // Don't delete these credentials if they're not for this Client ID.
831 - // They're for another Kit Plugin that uses OAuth.
832 - if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) {
833 - return;
834 - }
835 -
836 - // Delete Access and Refresh Tokens.
837 - $settings = new ConvertKit_Settings();
838 - $settings->delete_credentials();
839 -
840 -}
841 -
842 -/**
843 - * Deletes the stored access token, refresh token and its expiry from the Plugin settings,
844 - * and clears any existing scheduled WordPress Cron event to refresh the token on expiry,
845 - * when either:
846 - * - The access token is invalid
847 - * - The access token expired, and refreshing failed
848 - *
849 - * @since 3.1.1
850 - *
851 - * @param WP_Error $result Error result.
852 - * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
853 - */
854 -function convertkit_maybe_delete_credentials( $result, $client_id ) {
855 -
856 - // Don't save these credentials if they're not for this Client ID.
857 - // They're for another Kit Plugin that uses OAuth.
858 - if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) {
859 - return;
860 - }
861 -
862 - // If the error isn't a 401, don't delete credentials.
863 - // This could be e.g. a temporary network error, rate limit or similar.
864 - if ( $result->get_error_data( 'convertkit_api_error' ) !== 401 ) {
865 - return;
866 - }
867 -
868 - // Persist an error notice in the WordPress Administration until the user fixes the problem.
869 - WP_ConvertKit()->get_class( 'admin_notices' )->add( 'authorization_failed' );
870 -
871 - $settings = new ConvertKit_Settings();
872 - $settings->delete_credentials();
873 -
874 -}
875 -
876 -// Update Access Token when refreshed by the API class.
877 -add_action( 'convertkit_api_get_access_token', 'convertkit_maybe_update_credentials', 10, 2 );
878 -add_action( 'convertkit_api_refresh_token', 'convertkit_maybe_update_credentials', 10, 2 );
879 -
880 -// Delete credentials when the user revokes the access and refresh tokens.
881 -add_action( 'convertkit_api_revoke_tokens', 'convertkit_delete_credentials', 10, 1 );
882 -
883 -// Delete credentials if the API class uses a invalid access token.
884 -// This prevents the Plugin making repetitive API requests that will 401.
885 -add_action( 'convertkit_api_access_token_invalid', 'convertkit_maybe_delete_credentials', 10, 2 );