PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.3.7
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.3.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
← All changes | includes/functions.php +36 -394 3.3.92.3.7 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.
@@ -109,32 +106,13 @@
109 106 * @return array Post Types
110 107 */
111 108 function convertkit_get_supported_post_types() {
112 109
113 - // Define supported Post Types.
114 110 $post_types = array(
115 111 'page',
116 112 'post',
117 113 );
118 114
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 -
137 115 /**
138 116 * Defines the Post Types that support ConvertKit Forms.
139 117 *
140 118 * @since 1.9.6
@@ -147,40 +125,32 @@
147 125
148 126 }
149 127
150 128 /**
151 - * Determines whether the current user can create and publish the given Post Type.
152 - *
153 - * @since 3.3.9
154 - *
155 - * @param string $post_type Post Type.
156 - * @return bool User can create and publish Post Type.
157 - */
158 -function convertkit_user_can_create_published_post_type( $post_type ) {
159 -
160 - $post_type_object = get_post_type_object( $post_type );
161 -
162 - if ( ! $post_type_object ) {
163 - return false;
164 - }
165 -
166 - return current_user_can( $post_type_object->cap->create_posts ) && current_user_can( $post_type_object->cap->publish_posts );
167 -
168 -}
169 -
170 -/**
171 129 * Helper method to get supported Post Types for Restricted Content (Member's Content)
172 130 *
173 131 * @since 2.1.0
174 132 *
175 - * @deprecated 2.4.3 No longer used by internal code and not recommended. Use `convertkit_get_supported_post_types` instead.
176 - *
177 133 * @return array Post Types
178 134 */
179 135 function convertkit_get_supported_restrict_content_post_types() {
180 136
181 - return convertkit_get_supported_post_types();
137 + $post_types = array(
138 + 'page',
139 + 'post',
140 + );
182 141
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 +
183 153 }
184 154
185 155 /**
186 156 * Helper method to get registered Shortcodes.
@@ -254,32 +224,8 @@
254 224
255 225 }
256 226
257 227 /**
258 - * Helper method to get registered plugin sidebars.
259 - *
260 - * @since 3.3.0
261 - *
262 - * @return array Plugin sidebars
263 - */
264 -function convertkit_get_plugin_sidebars() {
265 -
266 - $plugin_sidebars = array();
267 -
268 - /**
269 - * Registers plugin sidebars for the WordPress block editor.
270 - *
271 - * @since 3.3.0
272 - *
273 - * @param array $plugin_sidebars Plugin sidebars.
274 - */
275 - $plugin_sidebars = apply_filters( 'convertkit_plugin_sidebars', $plugin_sidebars );
276 -
277 - return $plugin_sidebars;
278 -
279 -}
280 -
281 -/**
282 228 * Helper method to get registered pre-publish actions.
283 229 *
284 230 * @since 2.4.0
285 231 *
@@ -302,33 +248,8 @@
302 248
303 249 }
304 250
305 251 /**
306 - * Helper method to get registered importers that can replace third party
307 - * form shortcodes and blocks with Kit form shortcodes and blocks.
308 - *
309 - * @since 3.1.7
310 - *
311 - * @return array Importers.
312 - */
313 -function convertkit_get_form_importers() {
314 -
315 - $importers = array();
316 -
317 - /**
318 - * Registers form importers for the ConvertKit Plugin.
319 - *
320 - * @since 3.1.7
321 - *
322 - * @param array $importers Importers.
323 - */
324 - $importers = apply_filters( 'convertkit_get_form_importers', $importers );
325 -
326 - return $importers;
327 -
328 -}
329 -
330 -/**
331 252 * Helper method to return the Plugin Settings Link
332 253 *
333 254 * @since 1.9.6
334 255 *
@@ -383,9 +304,9 @@
383 304 'utm_source' => 'wordpress',
384 305 'utm_term' => get_locale(),
385 306 'utm_content' => 'convertkit',
386 307 ),
387 - 'https://app.kit.com/users/signup'
308 + 'https://app.convertkit.com/users/signup'
388 309 );
389 310
390 311 }
391 312
@@ -403,9 +324,9 @@
403 324 'utm_source' => 'wordpress',
404 325 'utm_term' => get_locale(),
405 326 'utm_content' => 'convertkit',
406 327 ),
407 - 'https://app.kit.com/'
328 + 'https://app.convertkit.com/'
408 329 );
409 330
410 331 }
411 332
@@ -423,21 +344,21 @@
423 344 'utm_source' => 'wordpress',
424 345 'utm_term' => get_locale(),
425 346 'utm_content' => 'convertkit',
426 347 ),
427 - 'https://app.kit.com/account_settings/billing/'
348 + 'https://app.convertkit.com/account_settings/billing/'
428 349 );
429 350
430 351 }
431 352
432 353 /**
433 - * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Form or Landing Page.
354 + * Helper method to return the URL the user needs to visit on the ConvertKit app to obtain their API Key and Secret.
434 355 *
435 - * @since 2.2.3
356 + * @since 1.9.6.1
436 357 *
437 - * @return string ConvertKit App URL
358 + * @return string ConvertKit App URL.
438 359 */
439 -function convertkit_get_new_form_url() {
360 +function convertkit_get_api_key_url() {
440 361
441 362 return add_query_arg(
442 363 array(
443 364 'utm_source' => 'wordpress',
@@ -443,21 +364,21 @@
443 364 'utm_source' => 'wordpress',
444 365 'utm_term' => get_locale(),
445 366 'utm_content' => 'convertkit',
446 367 ),
447 - 'https://app.kit.com/forms/new/'
368 + 'https://app.convertkit.com/account_settings/advanced_settings/'
448 369 );
449 370
450 371 }
451 372
452 373 /**
453 - * Helper method to return the URL the user needs to visit to edit ConvertKit forms.
374 + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Form or Landing Page.
454 375 *
455 376 * @since 2.2.3
456 377 *
457 - * @return string ConvertKit Form Editor URL.
378 + * @return string ConvertKit App URL
458 379 */
459 -function convertkit_get_form_editor_url() {
380 +function convertkit_get_new_form_url() {
460 381
461 382 return add_query_arg(
462 383 array(
463 384 'utm_source' => 'wordpress',
@@ -463,21 +384,21 @@
463 384 'utm_source' => 'wordpress',
464 385 'utm_term' => get_locale(),
465 386 'utm_content' => 'convertkit',
466 387 ),
467 - 'https://app.kit.com/forms'
388 + 'https://app.convertkit.com/forms/new/'
468 389 );
469 390
470 391 }
471 392
472 393 /**
473 - * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Landing Page.
394 + * Helper method to return the URL the user needs to visit to edit ConvertKit forms.
474 395 *
475 - * @since 2.5.5
396 + * @since 2.2.3
476 397 *
477 - * @return string ConvertKit App URL
398 + * @return string ConvertKit Form Editor URL.
478 399 */
479 -function convertkit_get_new_landing_page_url() {
400 +function convertkit_get_form_editor_url() {
480 401
481 402 return add_query_arg(
482 403 array(
483 404 'utm_source' => 'wordpress',
@@ -483,9 +404,9 @@
483 404 'utm_source' => 'wordpress',
484 405 'utm_term' => get_locale(),
485 406 'utm_content' => 'convertkit',
486 407 ),
487 - 'https://app.kit.com/pages/new/'
408 + 'https://app.convertkit.com/forms'
488 409 );
489 410
490 411 }
491 412
@@ -503,9 +424,9 @@
503 424 'utm_source' => 'wordpress',
504 425 'utm_term' => get_locale(),
505 426 'utm_content' => 'convertkit',
506 427 ),
507 - 'https://app.kit.com/subscribers/'
428 + 'https://app.convertkit.com/subscribers/'
508 429 );
509 430
510 431 }
511 432
@@ -523,9 +444,9 @@
523 444 'utm_source' => 'wordpress',
524 445 'utm_term' => get_locale(),
525 446 'utm_content' => 'convertkit',
526 447 ),
527 - 'https://app.kit.com/campaigns/'
448 + 'https://app.convertkit.com/campaigns/'
528 449 );
529 450
530 451 }
531 452
@@ -545,9 +466,9 @@
545 466 'utm_term' => get_locale(),
546 467 'utm_content' => 'convertkit',
547 468 ),
548 469 sprintf(
549 - 'https://app.kit.com/campaigns/%s/draft',
470 + 'https://app.convertkit.com/campaigns/%s/draft',
550 471 $broadcast_id
551 472 )
552 473 );
553 474
@@ -567,42 +488,14 @@
567 488 'utm_source' => 'wordpress',
568 489 'utm_term' => get_locale(),
569 490 'utm_content' => 'convertkit',
570 491 ),
571 - 'https://app.kit.com/products/new/'
492 + 'https://app.convertkit.com/products/new/'
572 493 );
573 494
574 495 }
575 496
576 497 /**
577 - * Helper method to enqueue the frontend CSS file.
578 - *
579 - * @since 3.2.0
580 - */
581 -function convertkit_enqueue_frontend_css() {
582 -
583 - wp_enqueue_style( 'convertkit-frontend', CONVERTKIT_PLUGIN_URL . 'resources/frontend/css/frontend.css', array(), CONVERTKIT_PLUGIN_VERSION );
584 -
585 -}
586 -
587 -/**
588 - * Helper method to enqueue the frontend JS file.
589 - *
590 - * @since 3.2.0
591 - */
592 -function convertkit_enqueue_frontend_js() {
593 -
594 - wp_enqueue_script(
595 - 'convertkit-js',
596 - CONVERTKIT_PLUGIN_URL . 'resources/frontend/js/dist/frontend.min.js',
597 - array(),
598 - CONVERTKIT_PLUGIN_VERSION,
599 - true
600 - );
601 -
602 -}
603 -
604 -/**
605 498 * Helper method to enqueue Select2 scripts for use within the ConvertKit Plugin.
606 499 *
607 500 * @since 1.9.6.4
608 501 */
@@ -651,255 +544,4 @@
651 544 // Return file's contents.
652 545 return $contents;
653 546
654 547 }
655 -
656 -/**
657 - * Returns a dropdown field commonly used for settings, comprising of:
658 - * - Do not subscribe
659 - * - Subscribe
660 - * - Subscribe to Form
661 - *
662 - * @since 2.5.2
663 - *
664 - * @param string $name Field name.
665 - * @param string $value Field value.
666 - * @param string $id Field ID attribute.
667 - * @param string $css_class Field CSS class(es).
668 - * @param string $context Resource context.
669 - * @param bool|array $additional_options Additional <option> key/value pairs.
670 - */
671 -function convertkit_get_subscription_dropdown_field( $name, $value, $id, $css_class = '', $context = '', $additional_options = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
672 -
673 - // Load resource classes.
674 - $forms = new ConvertKit_Resource_Forms( $context );
675 - $tags = new ConvertKit_Resource_Tags( $context );
676 - $sequences = new ConvertKit_Resource_Sequences( $context );
677 -
678 - ob_start();
679 - include CONVERTKIT_PLUGIN_PATH . '/views/backend/subscription-dropdown-field.php';
680 - $output = trim( ob_get_clean() );
681 -
682 - // Return output.
683 - return $output;
684 -
685 -}
686 -
687 -/**
688 - * Helper method to safely call get_current_screen(), returning false
689 - * if the function is not available or returns null.
690 - *
691 - * Otherwise returns the given WP_Screen property.
692 - *
693 - * @since 2.5.9
694 - *
695 - * @param string $property WP_Screen property to return.
696 - * @return bool|string
697 - */
698 -function convertkit_get_current_screen( $property ) {
699 -
700 - // Bail if we cannot determine the screen.
701 - if ( ! function_exists( 'get_current_screen' ) ) {
702 - return false;
703 - }
704 -
705 - // Get screen.
706 - $screen = get_current_screen();
707 -
708 - // Bail if the screen couldn't be determined.
709 - if ( is_null( $screen ) ) {
710 - return false;
711 - }
712 -
713 - // Return property.
714 - return $screen->$property;
715 -
716 -}
717 -
718 -/**
719 - * Outputs the Intercom help widget script.
720 - *
721 - * @since 2.7.2
722 - */
723 -function convertkit_output_intercom_messenger() {
724 -
725 - ?>
726 - <script>
727 - const KIT_INTERCOM_APP_ID = 'e4n3xtxz';
728 - window.intercomSettings = {
729 - api_base: 'https://api-iam.intercom.io',
730 - app_id: KIT_INTERCOM_APP_ID
731 - };
732 - </script>
733 -
734 - <script>
735 - (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);}}})();
736 - </script>
737 - <?php
738 -
739 -}
740 -
741 -/**
742 - * Checks if the given Theme is active.
743 - *
744 - * @since 3.1.4
745 - *
746 - * @param string $theme_name Theme name.
747 - * @return bool
748 - */
749 -function convertkit_is_theme_active( $theme_name ) {
750 -
751 - // Assume Theme isn't active if we can't detect it.
752 - if ( ! function_exists( 'wp_get_theme' ) ) {
753 - return false;
754 - }
755 -
756 - // Check the Parent Theme if we're on a Child Theme.
757 - if ( wp_get_theme()->parent() ) {
758 - $theme = wp_get_theme()->parent();
759 - } else {
760 - $theme = wp_get_theme();
761 - }
762 -
763 - return strtolower( $theme->get( 'Name' ) ) === strtolower( $theme_name );
764 -
765 -}
766 -
767 -/**
768 - * Returns permitted HTML output when using wp_kses( ..., convertkit_kses_allowed_html()).
769 - *
770 - * @since 2.8.5
771 - */
772 -function convertkit_kses_allowed_html() {
773 -
774 - // Get WordPress' permitted HTML elements.
775 - $elements = wp_kses_allowed_html( 'post' );
776 -
777 - // Add form elements.
778 - $form_elements = array(
779 - 'input' => array(
780 - 'type' => true,
781 - 'id' => true,
782 - 'name' => true,
783 - 'class' => true,
784 - 'value' => true,
785 - 'checked' => true,
786 - 'min' => true,
787 - 'max' => true,
788 - 'step' => true,
789 - 'data-*' => true,
790 - ),
791 - 'select' => array(
792 - 'id' => true,
793 - 'name' => true,
794 - 'class' => true,
795 - 'size' => true,
796 - 'multiple' => true,
797 - 'data-*' => true,
798 - ),
799 - 'option' => array(
800 - 'value' => true,
801 - 'selected' => true,
802 - 'data-*' => true,
803 - ),
804 - 'optgroup' => array(
805 - 'label' => true,
806 - 'data-*' => true,
807 - ),
808 - 'label' => array(
809 - 'for' => true,
810 - ),
811 - );
812 -
813 - return array_merge( $elements, $form_elements );
814 -
815 -}
816 -
817 -/**
818 - * Saves the new access token, refresh token and its expiry, and schedules
819 - * a WordPress Cron event to refresh the token on expiry.
820 - *
821 - * @since 3.1.1
822 - *
823 - * @param array $result New Access Token, Refresh Token and Expiry.
824 - * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
825 - */
826 -function convertkit_maybe_update_credentials( $result, $client_id ) {
827 -
828 - // Don't save these credentials if they're not for this Client ID.
829 - // They're for another Kit Plugin that uses OAuth.
830 - if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) {
831 - return;
832 - }
833 -
834 - $settings = new ConvertKit_Settings();
835 - $settings->update_credentials( $result );
836 -
837 -}
838 -
839 -/**
840 - * Deletes the stored access token, refresh token and its expiry from the Plugin settings,
841 - * and clears any existing scheduled WordPress Cron event to refresh the token on expiry,
842 - * when the user revokes the access token.
843 - *
844 - * @since 3.2.4
845 - *
846 - * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
847 - */
848 -function convertkit_delete_credentials( $client_id ) {
849 -
850 - // Don't delete these credentials if they're not for this Client ID.
851 - // They're for another Kit Plugin that uses OAuth.
852 - if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) {
853 - return;
854 - }
855 -
856 - // Delete Access and Refresh Tokens.
857 - $settings = new ConvertKit_Settings();
858 - $settings->delete_credentials();
859 -
860 -}
861 -
862 -/**
863 - * Deletes the stored access token, refresh token and its expiry from the Plugin settings,
864 - * and clears any existing scheduled WordPress Cron event to refresh the token on expiry,
865 - * when either:
866 - * - The access token is invalid
867 - * - The access token expired, and refreshing failed
868 - *
869 - * @since 3.1.1
870 - *
871 - * @param WP_Error $result Error result.
872 - * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
873 - */
874 -function convertkit_maybe_delete_credentials( $result, $client_id ) {
875 -
876 - // Don't save these credentials if they're not for this Client ID.
877 - // They're for another Kit Plugin that uses OAuth.
878 - if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) {
879 - return;
880 - }
881 -
882 - // If the error isn't a 401, don't delete credentials.
883 - // This could be e.g. a temporary network error, rate limit or similar.
884 - if ( $result->get_error_data( 'convertkit_api_error' ) !== 401 ) {
885 - return;
886 - }
887 -
888 - // Persist an error notice in the WordPress Administration until the user fixes the problem.
889 - WP_ConvertKit()->get_class( 'admin_notices' )->add( 'authorization_failed' );
890 -
891 - $settings = new ConvertKit_Settings();
892 - $settings->delete_credentials();
893 -
894 -}
895 -
896 -// Update Access Token when refreshed by the API class.
897 -add_action( 'convertkit_api_get_access_token', 'convertkit_maybe_update_credentials', 10, 2 );
898 -add_action( 'convertkit_api_refresh_token', 'convertkit_maybe_update_credentials', 10, 2 );
899 -
900 -// Delete credentials when the user revokes the access and refresh tokens.
901 -add_action( 'convertkit_api_revoke_tokens', 'convertkit_delete_credentials', 10, 1 );
902 -
903 -// Delete credentials if the API class uses a invalid access token.
904 -// This prevents the Plugin making repetitive API requests that will 401.
905 -add_action( 'convertkit_api_access_token_invalid', 'convertkit_maybe_delete_credentials', 10, 2 );