PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.2.3
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.2.3
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 +390 -33 2.2.83.2.3 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,27 +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 - );
161 + return convertkit_get_supported_post_types();
140 162
141 - /**
142 - * Defines the Post Types that support Restricted Content / Members Content functionality.
143 - *
144 - * @since 2.0.0
145 - *
146 - * @param array $post_types Post Types
147 - */
148 - $post_types = apply_filters( 'convertkit_get_supported_restrict_content_post_types', $post_types );
149 -
150 - return $post_types;
151 -
152 163 }
153 164
154 165 /**
155 166 * Helper method to get registered Shortcodes.
@@ -223,8 +234,57 @@
223 234
224 235 }
225 236
226 237 /**
238 + * Helper method to get registered pre-publish actions.
239 + *
240 + * @since 2.4.0
241 + *
242 + * @return array Pre-publish actions
243 + */
244 +function convertkit_get_pre_publish_actions() {
245 +
246 + $pre_publish_actions = array();
247 +
248 + /**
249 + * Registers pre-publish actions for the ConvertKit Plugin.
250 + *
251 + * @since 2.4.0
252 + *
253 + * @param array $pre_publish_panels Pre-publish actions.
254 + */
255 + $pre_publish_actions = apply_filters( 'convertkit_get_pre_publish_actions', $pre_publish_actions );
256 +
257 + return $pre_publish_actions;
258 +
259 +}
260 +
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 +/**
227 287 * Helper method to return the Plugin Settings Link
228 288 *
229 289 * @since 1.9.6
230 290 *
@@ -260,9 +320,9 @@
260 320 'page' => 'convertkit-setup',
261 321 )
262 322 );
263 323
264 - return add_query_arg( $query_args, admin_url( 'index.php' ) );
324 + return add_query_arg( $query_args, admin_url( 'options.php' ) );
265 325
266 326 }
267 327
268 328 /**
@@ -279,9 +339,9 @@
279 339 'utm_source' => 'wordpress',
280 340 'utm_term' => get_locale(),
281 341 'utm_content' => 'convertkit',
282 342 ),
283 - 'https://app.convertkit.com/users/signup'
343 + 'https://app.kit.com/users/signup'
284 344 );
285 345
286 346 }
287 347
@@ -299,9 +359,9 @@
299 359 'utm_source' => 'wordpress',
300 360 'utm_term' => get_locale(),
301 361 'utm_content' => 'convertkit',
302 362 ),
303 - 'https://app.convertkit.com/'
363 + 'https://app.kit.com/'
304 364 );
305 365
306 366 }
307 367
@@ -319,21 +379,21 @@
319 379 'utm_source' => 'wordpress',
320 380 'utm_term' => get_locale(),
321 381 'utm_content' => 'convertkit',
322 382 ),
323 - 'https://app.convertkit.com/account_settings/billing/'
383 + 'https://app.kit.com/account_settings/billing/'
324 384 );
325 385
326 386 }
327 387
328 388 /**
329 - * 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.
330 390 *
331 - * @since 1.9.6.1
391 + * @since 2.2.3
332 392 *
333 - * @return string ConvertKit App URL.
393 + * @return string ConvertKit App URL
334 394 */
335 -function convertkit_get_api_key_url() {
395 +function convertkit_get_new_form_url() {
336 396
337 397 return add_query_arg(
338 398 array(
339 399 'utm_source' => 'wordpress',
@@ -339,21 +399,41 @@
339 399 'utm_source' => 'wordpress',
340 400 'utm_term' => get_locale(),
341 401 'utm_content' => 'convertkit',
342 402 ),
343 - 'https://app.convertkit.com/account_settings/advanced_settings/'
403 + 'https://app.kit.com/forms/new/'
344 404 );
345 405
346 406 }
347 407
348 408 /**
349 - * 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.
350 410 *
351 411 * @since 2.2.3
352 412 *
413 + * @return string ConvertKit Form Editor URL.
414 + */
415 +function convertkit_get_form_editor_url() {
416 +
417 + return add_query_arg(
418 + array(
419 + 'utm_source' => 'wordpress',
420 + 'utm_term' => get_locale(),
421 + 'utm_content' => 'convertkit',
422 + ),
423 + 'https://app.kit.com/forms'
424 + );
425 +
426 +}
427 +
428 +/**
429 + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Landing Page.
430 + *
431 + * @since 2.5.5
432 + *
353 433 * @return string ConvertKit App URL
354 434 */
355 -function convertkit_get_new_form_url() {
435 +function convertkit_get_new_landing_page_url() {
356 436
357 437 return add_query_arg(
358 438 array(
359 439 'utm_source' => 'wordpress',
@@ -359,21 +439,21 @@
359 439 'utm_source' => 'wordpress',
360 440 'utm_term' => get_locale(),
361 441 'utm_content' => 'convertkit',
362 442 ),
363 - 'https://app.convertkit.com/forms/new/'
443 + 'https://app.kit.com/pages/new/'
364 444 );
365 445
366 446 }
367 447
368 448 /**
369 - * Helper method to return the URL the user needs to visit to edit ConvertKit forms.
449 + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Tag.
370 450 *
371 - * @since 2.2.3
451 + * @since 2.3.3
372 452 *
373 - * @return string ConvertKit Form Editor URL.
453 + * @return string ConvertKit App URL.
374 454 */
375 -function convertkit_get_form_editor_url() {
455 +function convertkit_get_new_tag_url() {
376 456
377 457 return add_query_arg(
378 458 array(
379 459 'utm_source' => 'wordpress',
@@ -379,9 +459,9 @@
379 459 'utm_source' => 'wordpress',
380 460 'utm_term' => get_locale(),
381 461 'utm_content' => 'convertkit',
382 462 ),
383 - 'https://app.convertkit.com/forms'
463 + 'https://app.kit.com/subscribers/'
384 464 );
385 465
386 466 }
387 467
@@ -399,14 +479,38 @@
399 479 'utm_source' => 'wordpress',
400 480 'utm_term' => get_locale(),
401 481 'utm_content' => 'convertkit',
402 482 ),
403 - 'https://app.convertkit.com/campaigns/'
483 + 'https://app.kit.com/campaigns/'
404 484 );
405 485
406 486 }
407 487
408 488 /**
489 + * Helper method to return the URL the user needs to visit on the ConvertKit app to edit a draft Broadcast.
490 + *
491 + * @since 2.4.0
492 + *
493 + * @param int $broadcast_id ConvertKit Broadcast ID.
494 + * @return string ConvertKit App URL.
495 + */
496 +function convertkit_get_edit_broadcast_url( $broadcast_id ) {
497 +
498 + return add_query_arg(
499 + array(
500 + 'utm_source' => 'wordpress',
501 + 'utm_term' => get_locale(),
502 + 'utm_content' => 'convertkit',
503 + ),
504 + sprintf(
505 + 'https://app.kit.com/campaigns/%s/draft',
506 + $broadcast_id
507 + )
508 + );
509 +
510 +}
511 +
512 +/**
409 513 * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Product.
410 514 *
411 515 * @since 2.2.3
412 516 *
@@ -419,14 +523,42 @@
419 523 'utm_source' => 'wordpress',
420 524 'utm_term' => get_locale(),
421 525 'utm_content' => 'convertkit',
422 526 ),
423 - 'https://app.convertkit.com/products/new/'
527 + 'https://app.kit.com/products/new/'
424 528 );
425 529
426 530 }
427 531
428 532 /**
533 + * Helper method to enqueue the frontend CSS file.
534 + *
535 + * @since 3.2.0
536 + */
537 +function convertkit_enqueue_frontend_css() {
538 +
539 + wp_enqueue_style( 'convertkit-frontend', CONVERTKIT_PLUGIN_URL . 'resources/frontend/css/frontend.css', array(), CONVERTKIT_PLUGIN_VERSION );
540 +
541 +}
542 +
543 +/**
544 + * Helper method to enqueue the frontend JS file.
545 + *
546 + * @since 3.2.0
547 + */
548 +function convertkit_enqueue_frontend_js() {
549 +
550 + wp_enqueue_script(
551 + 'convertkit-js',
552 + CONVERTKIT_PLUGIN_URL . 'resources/frontend/js/dist/frontend.min.js',
553 + array(),
554 + CONVERTKIT_PLUGIN_VERSION,
555 + true
556 + );
557 +
558 +}
559 +
560 +/**
429 561 * Helper method to enqueue Select2 scripts for use within the ConvertKit Plugin.
430 562 *
431 563 * @since 1.9.6.4
432 564 */
@@ -475,4 +607,229 @@
475 607 // Return file's contents.
476 608 return $contents;
477 609
478 610 }
611 +
612 +/**
613 + * Returns a dropdown field commonly used for settings, comprising of:
614 + * - Do not subscribe
615 + * - Subscribe
616 + * - Subscribe to Form
617 + *
618 + * @since 2.5.2
619 + *
620 + * @param string $name Field name.
621 + * @param string $value Field value.
622 + * @param string $id Field ID attribute.
623 + * @param string $css_class Field CSS class(es).
624 + * @param string $context Resource context.
625 + * @param bool|array $additional_options Additional <option> key/value pairs.
626 + */
627 +function convertkit_get_subscription_dropdown_field( $name, $value, $id, $css_class = '', $context = '', $additional_options = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
628 +
629 + // Load resource classes.
630 + $forms = new ConvertKit_Resource_Forms( $context );
631 + $tags = new ConvertKit_Resource_Tags( $context );
632 + $sequences = new ConvertKit_Resource_Sequences( $context );
633 +
634 + ob_start();
635 + include CONVERTKIT_PLUGIN_PATH . '/views/backend/subscription-dropdown-field.php';
636 + $output = trim( ob_get_clean() );
637 +
638 + // Return output.
639 + return $output;
640 +
641 +}
642 +
643 +/**
644 + * Helper method to safely call get_current_screen(), returning false
645 + * if the function is not available or returns null.
646 + *
647 + * Otherwise returns the given WP_Screen property.
648 + *
649 + * @since 2.5.9
650 + *
651 + * @param string $property WP_Screen property to return.
652 + * @return bool|string
653 + */
654 +function convertkit_get_current_screen( $property ) {
655 +
656 + // Bail if we cannot determine the screen.
657 + if ( ! function_exists( 'get_current_screen' ) ) {
658 + return false;
659 + }
660 +
661 + // Get screen.
662 + $screen = get_current_screen();
663 +
664 + // Bail if the screen couldn't be determined.
665 + if ( is_null( $screen ) ) {
666 + return false;
667 + }
668 +
669 + // Return property.
670 + return $screen->$property;
671 +
672 +}
673 +
674 +/**
675 + * Outputs the Intercom help widget script.
676 + *
677 + * @since 2.7.2
678 + */
679 +function convertkit_output_intercom_messenger() {
680 +
681 + ?>
682 + <script>
683 + const KIT_INTERCOM_APP_ID = 'e4n3xtxz';
684 + window.intercomSettings = {
685 + api_base: 'https://api-iam.intercom.io',
686 + app_id: KIT_INTERCOM_APP_ID
687 + };
688 + </script>
689 +
690 + <script>
691 + (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);}}})();
692 + </script>
693 + <?php
694 +
695 +}
696 +
697 +/**
698 + * Checks if the given Theme is active.
699 + *
700 + * @since 3.1.4
701 + *
702 + * @param string $theme_name Theme name.
703 + * @return bool
704 + */
705 +function convertkit_is_theme_active( $theme_name ) {
706 +
707 + // Assume Theme isn't active if we can't detect it.
708 + if ( ! function_exists( 'wp_get_theme' ) ) {
709 + return false;
710 + }
711 +
712 + // Check the Parent Theme if we're on a Child Theme.
713 + if ( wp_get_theme()->parent() ) {
714 + $theme = wp_get_theme()->parent();
715 + } else {
716 + $theme = wp_get_theme();
717 + }
718 +
719 + return strtolower( $theme->get( 'Name' ) ) === strtolower( $theme_name );
720 +
721 +}
722 +
723 +/**
724 + * Returns permitted HTML output when using wp_kses( ..., convertkit_kses_allowed_html()).
725 + *
726 + * @since 2.8.5
727 + */
728 +function convertkit_kses_allowed_html() {
729 +
730 + // Get WordPress' permitted HTML elements.
731 + $elements = wp_kses_allowed_html( 'post' );
732 +
733 + // Add form elements.
734 + $form_elements = array(
735 + 'input' => array(
736 + 'type' => true,
737 + 'id' => true,
738 + 'name' => true,
739 + 'class' => true,
740 + 'value' => true,
741 + 'checked' => true,
742 + 'min' => true,
743 + 'max' => true,
744 + 'step' => true,
745 + 'data-*' => true,
746 + ),
747 + 'select' => array(
748 + 'id' => true,
749 + 'name' => true,
750 + 'class' => true,
751 + 'size' => true,
752 + 'multiple' => true,
753 + 'data-*' => true,
754 + ),
755 + 'option' => array(
756 + 'value' => true,
757 + 'selected' => true,
758 + 'data-*' => true,
759 + ),
760 + 'optgroup' => array(
761 + 'label' => true,
762 + 'data-*' => true,
763 + ),
764 + 'label' => array(
765 + 'for' => true,
766 + ),
767 + );
768 +
769 + return array_merge( $elements, $form_elements );
770 +
771 +}
772 +
773 +/**
774 + * Saves the new access token, refresh token and its expiry, and schedules
775 + * a WordPress Cron event to refresh the token on expiry.
776 + *
777 + * @since 3.1.1
778 + *
779 + * @param array $result New Access Token, Refresh Token and Expiry.
780 + * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
781 + */
782 +function convertkit_maybe_update_credentials( $result, $client_id ) {
783 +
784 + // Don't save these credentials if they're not for this Client ID.
785 + // They're for another Kit Plugin that uses OAuth.
786 + if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) {
787 + return;
788 + }
789 +
790 + $settings = new ConvertKit_Settings();
791 + $settings->update_credentials( $result );
792 +
793 +}
794 +
795 +/**
796 + * Deletes the stored access token, refresh token and its expiry from the Plugin settings,
797 + * and clears any existing scheduled WordPress Cron event to refresh the token on expiry,
798 + * when either:
799 + * - The access token is invalid
800 + * - The access token expired, and refreshing failed
801 + *
802 + * @since 3.1.1
803 + *
804 + * @param WP_Error $result Error result.
805 + * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
806 + */
807 +function convertkit_maybe_delete_credentials( $result, $client_id ) {
808 +
809 + // Don't save these credentials if they're not for this Client ID.
810 + // They're for another Kit Plugin that uses OAuth.
811 + if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) {
812 + return;
813 + }
814 +
815 + // If the error isn't a 401, don't delete credentials.
816 + // This could be e.g. a temporary network error, rate limit or similar.
817 + if ( $result->get_error_data( 'convertkit_api_error' ) !== 401 ) {
818 + return;
819 + }
820 +
821 + // Persist an error notice in the WordPress Administration until the user fixes the problem.
822 + WP_ConvertKit()->get_class( 'admin_notices' )->add( 'authorization_failed' );
823 +
824 + $settings = new ConvertKit_Settings();
825 + $settings->delete_credentials();
826 +
827 +}
828 +
829 +// Update Access Token when refreshed by the API class.
830 +add_action( 'convertkit_api_get_access_token', 'convertkit_maybe_update_credentials', 10, 2 );
831 +add_action( 'convertkit_api_refresh_token', 'convertkit_maybe_update_credentials', 10, 2 );
832 +
833 +// Delete credentials if the API class uses a invalid access token.
834 +// This prevents the Plugin making repetitive API requests that will 401.
835 +add_action( 'convertkit_api_access_token_invalid', 'convertkit_maybe_delete_credentials', 10, 2 );