| @@ -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. |
| @@ -147,28 +147,8 @@ | ||
| 147 | 147 | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
| 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 | 151 | * Helper method to get supported Post Types for Restricted Content (Member's Content) |
| 172 | 152 | * |
| 173 | 153 | * @since 2.1.0 |
| 174 | 154 | * |
| @@ -254,32 +234,8 @@ | ||
| 254 | 234 | |
| 255 | 235 | } |
| 256 | 236 | |
| 257 | 237 | /** |
| 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 | 238 | * Helper method to get registered pre-publish actions. |
| 283 | 239 | * |
| 284 | 240 | * @since 2.4.0 |
| 285 | 241 | * |
| @@ -302,57 +258,8 @@ | ||
| 302 | 258 | |
| 303 | 259 | } |
| 304 | 260 | |
| 305 | 261 | /** |
| 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 | - * Helper method to get registered abilities. | |
| 332 | - * | |
| 333 | - * @since 3.4.0 | |
| 334 | - * | |
| 335 | - * @return array Abilities. | |
| 336 | - */ | |
| 337 | -function convertkit_get_abilities() { | |
| 338 | - | |
| 339 | - $abilities = array(); | |
| 340 | - | |
| 341 | - /** | |
| 342 | - * Registers abilities for the Kit Plugin. | |
| 343 | - * | |
| 344 | - * @since 3.4.0 | |
| 345 | - * | |
| 346 | - * @param array $abilities Abilities. | |
| 347 | - */ | |
| 348 | - $abilities = apply_filters( 'convertkit_abilities', $abilities ); | |
| 349 | - | |
| 350 | - return $abilities; | |
| 351 | - | |
| 352 | -} | |
| 353 | - | |
| 354 | -/** | |
| 355 | 262 | * Helper method to return the Plugin Settings Link |
| 356 | 263 | * |
| 357 | 264 | * @since 1.9.6 |
| 358 | 265 | * |
| @@ -407,9 +314,9 @@ | ||
| 407 | 314 | 'utm_source' => 'wordpress', |
| 408 | 315 | 'utm_term' => get_locale(), |
| 409 | 316 | 'utm_content' => 'convertkit', |
| 410 | 317 | ), |
| 411 | - 'https://app.kit.com/users/signup' | |
| 318 | + 'https://app.convertkit.com/users/signup' | |
| 412 | 319 | ); |
| 413 | 320 | |
| 414 | 321 | } |
| 415 | 322 | |
| @@ -427,9 +334,9 @@ | ||
| 427 | 334 | 'utm_source' => 'wordpress', |
| 428 | 335 | 'utm_term' => get_locale(), |
| 429 | 336 | 'utm_content' => 'convertkit', |
| 430 | 337 | ), |
| 431 | - 'https://app.kit.com/' | |
| 338 | + 'https://app.convertkit.com/' | |
| 432 | 339 | ); |
| 433 | 340 | |
| 434 | 341 | } |
| 435 | 342 | |
| @@ -447,9 +354,9 @@ | ||
| 447 | 354 | 'utm_source' => 'wordpress', |
| 448 | 355 | 'utm_term' => get_locale(), |
| 449 | 356 | 'utm_content' => 'convertkit', |
| 450 | 357 | ), |
| 451 | - 'https://app.kit.com/account_settings/billing/' | |
| 358 | + 'https://app.convertkit.com/account_settings/billing/' | |
| 452 | 359 | ); |
| 453 | 360 | |
| 454 | 361 | } |
| 455 | 362 | |
| @@ -467,9 +374,9 @@ | ||
| 467 | 374 | 'utm_source' => 'wordpress', |
| 468 | 375 | 'utm_term' => get_locale(), |
| 469 | 376 | 'utm_content' => 'convertkit', |
| 470 | 377 | ), |
| 471 | - 'https://app.kit.com/forms/new/' | |
| 378 | + 'https://app.convertkit.com/forms/new/' | |
| 472 | 379 | ); |
| 473 | 380 | |
| 474 | 381 | } |
| 475 | 382 | |
| @@ -487,9 +394,9 @@ | ||
| 487 | 394 | 'utm_source' => 'wordpress', |
| 488 | 395 | 'utm_term' => get_locale(), |
| 489 | 396 | 'utm_content' => 'convertkit', |
| 490 | 397 | ), |
| 491 | - 'https://app.kit.com/forms' | |
| 398 | + 'https://app.convertkit.com/forms' | |
| 492 | 399 | ); |
| 493 | 400 | |
| 494 | 401 | } |
| 495 | 402 | |
| @@ -507,9 +414,9 @@ | ||
| 507 | 414 | 'utm_source' => 'wordpress', |
| 508 | 415 | 'utm_term' => get_locale(), |
| 509 | 416 | 'utm_content' => 'convertkit', |
| 510 | 417 | ), |
| 511 | - 'https://app.kit.com/pages/new/' | |
| 418 | + 'https://app.convertkit.com/pages/new/' | |
| 512 | 419 | ); |
| 513 | 420 | |
| 514 | 421 | } |
| 515 | 422 | |
| @@ -527,9 +434,9 @@ | ||
| 527 | 434 | 'utm_source' => 'wordpress', |
| 528 | 435 | 'utm_term' => get_locale(), |
| 529 | 436 | 'utm_content' => 'convertkit', |
| 530 | 437 | ), |
| 531 | - 'https://app.kit.com/subscribers/' | |
| 438 | + 'https://app.convertkit.com/subscribers/' | |
| 532 | 439 | ); |
| 533 | 440 | |
| 534 | 441 | } |
| 535 | 442 | |
| @@ -547,9 +454,9 @@ | ||
| 547 | 454 | 'utm_source' => 'wordpress', |
| 548 | 455 | 'utm_term' => get_locale(), |
| 549 | 456 | 'utm_content' => 'convertkit', |
| 550 | 457 | ), |
| 551 | - 'https://app.kit.com/campaigns/' | |
| 458 | + 'https://app.convertkit.com/campaigns/' | |
| 552 | 459 | ); |
| 553 | 460 | |
| 554 | 461 | } |
| 555 | 462 | |
| @@ -569,9 +476,9 @@ | ||
| 569 | 476 | 'utm_term' => get_locale(), |
| 570 | 477 | 'utm_content' => 'convertkit', |
| 571 | 478 | ), |
| 572 | 479 | sprintf( |
| 573 | - 'https://app.kit.com/campaigns/%s/draft', | |
| 480 | + 'https://app.convertkit.com/campaigns/%s/draft', | |
| 574 | 481 | $broadcast_id |
| 575 | 482 | ) |
| 576 | 483 | ); |
| 577 | 484 | |
| @@ -591,42 +498,14 @@ | ||
| 591 | 498 | 'utm_source' => 'wordpress', |
| 592 | 499 | 'utm_term' => get_locale(), |
| 593 | 500 | 'utm_content' => 'convertkit', |
| 594 | 501 | ), |
| 595 | - 'https://app.kit.com/products/new/' | |
| 502 | + 'https://app.convertkit.com/products/new/' | |
| 596 | 503 | ); |
| 597 | 504 | |
| 598 | 505 | } |
| 599 | 506 | |
| 600 | 507 | /** |
| 601 | - * Helper method to enqueue the frontend CSS file. | |
| 602 | - * | |
| 603 | - * @since 3.2.0 | |
| 604 | - */ | |
| 605 | -function convertkit_enqueue_frontend_css() { | |
| 606 | - | |
| 607 | - wp_enqueue_style( 'convertkit-frontend', CONVERTKIT_PLUGIN_URL . 'resources/frontend/css/frontend.css', array(), CONVERTKIT_PLUGIN_VERSION ); | |
| 608 | - | |
| 609 | -} | |
| 610 | - | |
| 611 | -/** | |
| 612 | - * Helper method to enqueue the frontend JS file. | |
| 613 | - * | |
| 614 | - * @since 3.2.0 | |
| 615 | - */ | |
| 616 | -function convertkit_enqueue_frontend_js() { | |
| 617 | - | |
| 618 | - wp_enqueue_script( | |
| 619 | - 'convertkit-js', | |
| 620 | - CONVERTKIT_PLUGIN_URL . 'resources/frontend/js/dist/frontend.min.js', | |
| 621 | - array(), | |
| 622 | - CONVERTKIT_PLUGIN_VERSION, | |
| 623 | - true | |
| 624 | - ); | |
| 625 | - | |
| 626 | -} | |
| 627 | - | |
| 628 | -/** | |
| 629 | 508 | * Helper method to enqueue Select2 scripts for use within the ConvertKit Plugin. |
| 630 | 509 | * |
| 631 | 510 | * @since 1.9.6.4 |
| 632 | 511 | */ |
| @@ -737,193 +616,4 @@ | ||
| 737 | 616 | // Return property. |
| 738 | 617 | return $screen->$property; |
| 739 | 618 | |
| 740 | 619 | } |
| 741 | - | |
| 742 | -/** | |
| 743 | - * Outputs the Intercom help widget script. | |
| 744 | - * | |
| 745 | - * @since 2.7.2 | |
| 746 | - */ | |
| 747 | -function convertkit_output_intercom_messenger() { | |
| 748 | - | |
| 749 | - ?> | |
| 750 | - <script> | |
| 751 | - const KIT_INTERCOM_APP_ID = 'e4n3xtxz'; | |
| 752 | - window.intercomSettings = { | |
| 753 | - api_base: 'https://api-iam.intercom.io', | |
| 754 | - app_id: KIT_INTERCOM_APP_ID | |
| 755 | - }; | |
| 756 | - </script> | |
| 757 | - | |
| 758 | - <script> | |
| 759 | - (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);}}})(); | |
| 760 | - </script> | |
| 761 | - <?php | |
| 762 | - | |
| 763 | -} | |
| 764 | - | |
| 765 | -/** | |
| 766 | - * Checks if the given Theme is active. | |
| 767 | - * | |
| 768 | - * @since 3.1.4 | |
| 769 | - * | |
| 770 | - * @param string $theme_name Theme name. | |
| 771 | - * @return bool | |
| 772 | - */ | |
| 773 | -function convertkit_is_theme_active( $theme_name ) { | |
| 774 | - | |
| 775 | - // Assume Theme isn't active if we can't detect it. | |
| 776 | - if ( ! function_exists( 'wp_get_theme' ) ) { | |
| 777 | - return false; | |
| 778 | - } | |
| 779 | - | |
| 780 | - // Check the Parent Theme if we're on a Child Theme. | |
| 781 | - if ( wp_get_theme()->parent() ) { | |
| 782 | - $theme = wp_get_theme()->parent(); | |
| 783 | - } else { | |
| 784 | - $theme = wp_get_theme(); | |
| 785 | - } | |
| 786 | - | |
| 787 | - return strtolower( $theme->get( 'Name' ) ) === strtolower( $theme_name ); | |
| 788 | - | |
| 789 | -} | |
| 790 | - | |
| 791 | -/** | |
| 792 | - * Returns permitted HTML output when using wp_kses( ..., convertkit_kses_allowed_html()). | |
| 793 | - * | |
| 794 | - * @since 2.8.5 | |
| 795 | - */ | |
| 796 | -function convertkit_kses_allowed_html() { | |
| 797 | - | |
| 798 | - // Get WordPress' permitted HTML elements. | |
| 799 | - $elements = wp_kses_allowed_html( 'post' ); | |
| 800 | - | |
| 801 | - // Add form elements. | |
| 802 | - $form_elements = array( | |
| 803 | - 'input' => array( | |
| 804 | - 'type' => true, | |
| 805 | - 'id' => true, | |
| 806 | - 'name' => true, | |
| 807 | - 'class' => true, | |
| 808 | - 'value' => true, | |
| 809 | - 'checked' => true, | |
| 810 | - 'min' => true, | |
| 811 | - 'max' => true, | |
| 812 | - 'step' => true, | |
| 813 | - 'data-*' => true, | |
| 814 | - ), | |
| 815 | - 'select' => array( | |
| 816 | - 'id' => true, | |
| 817 | - 'name' => true, | |
| 818 | - 'class' => true, | |
| 819 | - 'size' => true, | |
| 820 | - 'multiple' => true, | |
| 821 | - 'data-*' => true, | |
| 822 | - ), | |
| 823 | - 'option' => array( | |
| 824 | - 'value' => true, | |
| 825 | - 'selected' => true, | |
| 826 | - 'data-*' => true, | |
| 827 | - ), | |
| 828 | - 'optgroup' => array( | |
| 829 | - 'label' => true, | |
| 830 | - 'data-*' => true, | |
| 831 | - ), | |
| 832 | - 'label' => array( | |
| 833 | - 'for' => true, | |
| 834 | - ), | |
| 835 | - ); | |
| 836 | - | |
| 837 | - return array_merge( $elements, $form_elements ); | |
| 838 | - | |
| 839 | -} | |
| 840 | - | |
| 841 | -/** | |
| 842 | - * Saves the new access token, refresh token and its expiry, and schedules | |
| 843 | - * a WordPress Cron event to refresh the token on expiry. | |
| 844 | - * | |
| 845 | - * @since 3.1.1 | |
| 846 | - * | |
| 847 | - * @param array $result New Access Token, Refresh Token and Expiry. | |
| 848 | - * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens. | |
| 849 | - */ | |
| 850 | -function convertkit_maybe_update_credentials( $result, $client_id ) { | |
| 851 | - | |
| 852 | - // Don't save these credentials if they're not for this Client ID. | |
| 853 | - // They're for another Kit Plugin that uses OAuth. | |
| 854 | - if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) { | |
| 855 | - return; | |
| 856 | - } | |
| 857 | - | |
| 858 | - $settings = new ConvertKit_Settings(); | |
| 859 | - $settings->update_credentials( $result ); | |
| 860 | - | |
| 861 | -} | |
| 862 | - | |
| 863 | -/** | |
| 864 | - * Deletes the stored access token, refresh token and its expiry from the Plugin settings, | |
| 865 | - * and clears any existing scheduled WordPress Cron event to refresh the token on expiry, | |
| 866 | - * when the user revokes the access token. | |
| 867 | - * | |
| 868 | - * @since 3.2.4 | |
| 869 | - * | |
| 870 | - * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens. | |
| 871 | - */ | |
| 872 | -function convertkit_delete_credentials( $client_id ) { | |
| 873 | - | |
| 874 | - // Don't delete these credentials if they're not for this Client ID. | |
| 875 | - // They're for another Kit Plugin that uses OAuth. | |
| 876 | - if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) { | |
| 877 | - return; | |
| 878 | - } | |
| 879 | - | |
| 880 | - // Delete Access and Refresh Tokens. | |
| 881 | - $settings = new ConvertKit_Settings(); | |
| 882 | - $settings->delete_credentials(); | |
| 883 | - | |
| 884 | -} | |
| 885 | - | |
| 886 | -/** | |
| 887 | - * Deletes the stored access token, refresh token and its expiry from the Plugin settings, | |
| 888 | - * and clears any existing scheduled WordPress Cron event to refresh the token on expiry, | |
| 889 | - * when either: | |
| 890 | - * - The access token is invalid | |
| 891 | - * - The access token expired, and refreshing failed | |
| 892 | - * | |
| 893 | - * @since 3.1.1 | |
| 894 | - * | |
| 895 | - * @param WP_Error $result Error result. | |
| 896 | - * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens. | |
| 897 | - */ | |
| 898 | -function convertkit_maybe_delete_credentials( $result, $client_id ) { | |
| 899 | - | |
| 900 | - // Don't save these credentials if they're not for this Client ID. | |
| 901 | - // They're for another Kit Plugin that uses OAuth. | |
| 902 | - if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) { | |
| 903 | - return; | |
| 904 | - } | |
| 905 | - | |
| 906 | - // If the error isn't a 401, don't delete credentials. | |
| 907 | - // This could be e.g. a temporary network error, rate limit or similar. | |
| 908 | - if ( $result->get_error_data( 'convertkit_api_error' ) !== 401 ) { | |
| 909 | - return; | |
| 910 | - } | |
| 911 | - | |
| 912 | - // Persist an error notice in the WordPress Administration until the user fixes the problem. | |
| 913 | - WP_ConvertKit()->get_class( 'admin_notices' )->add( 'authorization_failed' ); | |
| 914 | - | |
| 915 | - $settings = new ConvertKit_Settings(); | |
| 916 | - $settings->delete_credentials(); | |
| 917 | - | |
| 918 | -} | |
| 919 | - | |
| 920 | -// Update Access Token when refreshed by the API class. | |
| 921 | -add_action( 'convertkit_api_get_access_token', 'convertkit_maybe_update_credentials', 10, 2 ); | |
| 922 | -add_action( 'convertkit_api_refresh_token', 'convertkit_maybe_update_credentials', 10, 2 ); | |
| 923 | - | |
| 924 | -// Delete credentials when the user revokes the access and refresh tokens. | |
| 925 | -add_action( 'convertkit_api_revoke_tokens', 'convertkit_delete_credentials', 10, 1 ); | |
| 926 | - | |
| 927 | -// Delete credentials if the API class uses a invalid access token. | |
| 928 | -// This prevents the Plugin making repetitive API requests that will 401. | |
| 929 | -add_action( 'convertkit_api_access_token_invalid', 'convertkit_maybe_delete_credentials', 10, 2 ); | |