| @@ -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. |
| @@ -224,8 +234,32 @@ | ||
| 224 | 234 | |
| 225 | 235 | } |
| 226 | 236 | |
| 227 | 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 | +/** | |
| 228 | 262 | * Helper method to return the Plugin Settings Link |
| 229 | 263 | * |
| 230 | 264 | * @since 1.9.6 |
| 231 | 265 | * |
| @@ -280,9 +314,9 @@ | ||
| 280 | 314 | 'utm_source' => 'wordpress', |
| 281 | 315 | 'utm_term' => get_locale(), |
| 282 | 316 | 'utm_content' => 'convertkit', |
| 283 | 317 | ), |
| 284 | - 'https://app.convertkit.com/users/signup' | |
| 318 | + 'https://app.kit.com/users/signup' | |
| 285 | 319 | ); |
| 286 | 320 | |
| 287 | 321 | } |
| 288 | 322 | |
| @@ -300,9 +334,9 @@ | ||
| 300 | 334 | 'utm_source' => 'wordpress', |
| 301 | 335 | 'utm_term' => get_locale(), |
| 302 | 336 | 'utm_content' => 'convertkit', |
| 303 | 337 | ), |
| 304 | - 'https://app.convertkit.com/' | |
| 338 | + 'https://app.kit.com/' | |
| 305 | 339 | ); |
| 306 | 340 | |
| 307 | 341 | } |
| 308 | 342 | |
| @@ -320,21 +354,21 @@ | ||
| 320 | 354 | 'utm_source' => 'wordpress', |
| 321 | 355 | 'utm_term' => get_locale(), |
| 322 | 356 | 'utm_content' => 'convertkit', |
| 323 | 357 | ), |
| 324 | - 'https://app.convertkit.com/account_settings/billing/' | |
| 358 | + 'https://app.kit.com/account_settings/billing/' | |
| 325 | 359 | ); |
| 326 | 360 | |
| 327 | 361 | } |
| 328 | 362 | |
| 329 | 363 | /** |
| 330 | - * Helper method to return the URL the user needs to visit on the ConvertKit app to obtain their API Key and Secret. | |
| 364 | + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Form or Landing Page. | |
| 331 | 365 | * |
| 332 | - * @since 1.9.6.1 | |
| 366 | + * @since 2.2.3 | |
| 333 | 367 | * |
| 334 | - * @return string ConvertKit App URL. | |
| 368 | + * @return string ConvertKit App URL | |
| 335 | 369 | */ |
| 336 | -function convertkit_get_api_key_url() { | |
| 370 | +function convertkit_get_new_form_url() { | |
| 337 | 371 | |
| 338 | 372 | return add_query_arg( |
| 339 | 373 | array( |
| 340 | 374 | 'utm_source' => 'wordpress', |
| @@ -340,21 +374,41 @@ | ||
| 340 | 374 | 'utm_source' => 'wordpress', |
| 341 | 375 | 'utm_term' => get_locale(), |
| 342 | 376 | 'utm_content' => 'convertkit', |
| 343 | 377 | ), |
| 344 | - 'https://app.convertkit.com/account_settings/advanced_settings/' | |
| 378 | + 'https://app.kit.com/forms/new/' | |
| 345 | 379 | ); |
| 346 | 380 | |
| 347 | 381 | } |
| 348 | 382 | |
| 349 | 383 | /** |
| 350 | - * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Form or Landing Page. | |
| 384 | + * Helper method to return the URL the user needs to visit to edit ConvertKit forms. | |
| 351 | 385 | * |
| 352 | 386 | * @since 2.2.3 |
| 353 | 387 | * |
| 388 | + * @return string ConvertKit Form Editor URL. | |
| 389 | + */ | |
| 390 | +function convertkit_get_form_editor_url() { | |
| 391 | + | |
| 392 | + return add_query_arg( | |
| 393 | + array( | |
| 394 | + 'utm_source' => 'wordpress', | |
| 395 | + 'utm_term' => get_locale(), | |
| 396 | + 'utm_content' => 'convertkit', | |
| 397 | + ), | |
| 398 | + 'https://app.kit.com/forms' | |
| 399 | + ); | |
| 400 | + | |
| 401 | +} | |
| 402 | + | |
| 403 | +/** | |
| 404 | + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Landing Page. | |
| 405 | + * | |
| 406 | + * @since 2.5.5 | |
| 407 | + * | |
| 354 | 408 | * @return string ConvertKit App URL |
| 355 | 409 | */ |
| 356 | -function convertkit_get_new_form_url() { | |
| 410 | +function convertkit_get_new_landing_page_url() { | |
| 357 | 411 | |
| 358 | 412 | return add_query_arg( |
| 359 | 413 | array( |
| 360 | 414 | 'utm_source' => 'wordpress', |
| @@ -360,21 +414,21 @@ | ||
| 360 | 414 | 'utm_source' => 'wordpress', |
| 361 | 415 | 'utm_term' => get_locale(), |
| 362 | 416 | 'utm_content' => 'convertkit', |
| 363 | 417 | ), |
| 364 | - 'https://app.convertkit.com/forms/new/' | |
| 418 | + 'https://app.kit.com/pages/new/' | |
| 365 | 419 | ); |
| 366 | 420 | |
| 367 | 421 | } |
| 368 | 422 | |
| 369 | 423 | /** |
| 370 | - * Helper method to return the URL the user needs to visit to edit ConvertKit forms. | |
| 424 | + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Tag. | |
| 371 | 425 | * |
| 372 | - * @since 2.2.3 | |
| 426 | + * @since 2.3.3 | |
| 373 | 427 | * |
| 374 | - * @return string ConvertKit Form Editor URL. | |
| 428 | + * @return string ConvertKit App URL. | |
| 375 | 429 | */ |
| 376 | -function convertkit_get_form_editor_url() { | |
| 430 | +function convertkit_get_new_tag_url() { | |
| 377 | 431 | |
| 378 | 432 | return add_query_arg( |
| 379 | 433 | array( |
| 380 | 434 | 'utm_source' => 'wordpress', |
| @@ -380,9 +434,9 @@ | ||
| 380 | 434 | 'utm_source' => 'wordpress', |
| 381 | 435 | 'utm_term' => get_locale(), |
| 382 | 436 | 'utm_content' => 'convertkit', |
| 383 | 437 | ), |
| 384 | - 'https://app.convertkit.com/forms' | |
| 438 | + 'https://app.kit.com/subscribers/' | |
| 385 | 439 | ); |
| 386 | 440 | |
| 387 | 441 | } |
| 388 | 442 | |
| @@ -400,14 +454,38 @@ | ||
| 400 | 454 | 'utm_source' => 'wordpress', |
| 401 | 455 | 'utm_term' => get_locale(), |
| 402 | 456 | 'utm_content' => 'convertkit', |
| 403 | 457 | ), |
| 404 | - 'https://app.convertkit.com/campaigns/' | |
| 458 | + 'https://app.kit.com/campaigns/' | |
| 405 | 459 | ); |
| 406 | 460 | |
| 407 | 461 | } |
| 408 | 462 | |
| 409 | 463 | /** |
| 464 | + * Helper method to return the URL the user needs to visit on the ConvertKit app to edit a draft Broadcast. | |
| 465 | + * | |
| 466 | + * @since 2.4.0 | |
| 467 | + * | |
| 468 | + * @param int $broadcast_id ConvertKit Broadcast ID. | |
| 469 | + * @return string ConvertKit App URL. | |
| 470 | + */ | |
| 471 | +function convertkit_get_edit_broadcast_url( $broadcast_id ) { | |
| 472 | + | |
| 473 | + return add_query_arg( | |
| 474 | + array( | |
| 475 | + 'utm_source' => 'wordpress', | |
| 476 | + 'utm_term' => get_locale(), | |
| 477 | + 'utm_content' => 'convertkit', | |
| 478 | + ), | |
| 479 | + sprintf( | |
| 480 | + 'https://app.kit.com/campaigns/%s/draft', | |
| 481 | + $broadcast_id | |
| 482 | + ) | |
| 483 | + ); | |
| 484 | + | |
| 485 | +} | |
| 486 | + | |
| 487 | +/** | |
| 410 | 488 | * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Product. |
| 411 | 489 | * |
| 412 | 490 | * @since 2.2.3 |
| 413 | 491 | * |
| @@ -420,9 +498,9 @@ | ||
| 420 | 498 | 'utm_source' => 'wordpress', |
| 421 | 499 | 'utm_term' => get_locale(), |
| 422 | 500 | 'utm_content' => 'convertkit', |
| 423 | 501 | ), |
| 424 | - 'https://app.convertkit.com/products/new/' | |
| 502 | + 'https://app.kit.com/products/new/' | |
| 425 | 503 | ); |
| 426 | 504 | |
| 427 | 505 | } |
| 428 | 506 | |
| @@ -474,6 +552,141 @@ | ||
| 474 | 552 | } |
| 475 | 553 | |
| 476 | 554 | // Return file's contents. |
| 477 | 555 | return $contents; |
| 556 | + | |
| 557 | +} | |
| 558 | + | |
| 559 | +/** | |
| 560 | + * Returns a dropdown field commonly used for settings, comprising of: | |
| 561 | + * - Do not subscribe | |
| 562 | + * - Subscribe | |
| 563 | + * - Subscribe to Form | |
| 564 | + * | |
| 565 | + * @since 2.5.2 | |
| 566 | + * | |
| 567 | + * @param string $name Field name. | |
| 568 | + * @param string $value Field value. | |
| 569 | + * @param string $id Field ID attribute. | |
| 570 | + * @param string $css_class Field CSS class(es). | |
| 571 | + * @param string $context Resource context. | |
| 572 | + * @param bool|array $additional_options Additional <option> key/value pairs. | |
| 573 | + */ | |
| 574 | +function convertkit_get_subscription_dropdown_field( $name, $value, $id, $css_class = '', $context = '', $additional_options = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter | |
| 575 | + | |
| 576 | + // Load resource classes. | |
| 577 | + $forms = new ConvertKit_Resource_Forms( $context ); | |
| 578 | + $tags = new ConvertKit_Resource_Tags( $context ); | |
| 579 | + $sequences = new ConvertKit_Resource_Sequences( $context ); | |
| 580 | + | |
| 581 | + ob_start(); | |
| 582 | + include CONVERTKIT_PLUGIN_PATH . '/views/backend/subscription-dropdown-field.php'; | |
| 583 | + $output = trim( ob_get_clean() ); | |
| 584 | + | |
| 585 | + // Return output. | |
| 586 | + return $output; | |
| 587 | + | |
| 588 | +} | |
| 589 | + | |
| 590 | +/** | |
| 591 | + * Helper method to safely call get_current_screen(), returning false | |
| 592 | + * if the function is not available or returns null. | |
| 593 | + * | |
| 594 | + * Otherwise returns the given WP_Screen property. | |
| 595 | + * | |
| 596 | + * @since 2.5.9 | |
| 597 | + * | |
| 598 | + * @param string $property WP_Screen property to return. | |
| 599 | + * @return bool|string | |
| 600 | + */ | |
| 601 | +function convertkit_get_current_screen( $property ) { | |
| 602 | + | |
| 603 | + // Bail if we cannot determine the screen. | |
| 604 | + if ( ! function_exists( 'get_current_screen' ) ) { | |
| 605 | + return false; | |
| 606 | + } | |
| 607 | + | |
| 608 | + // Get screen. | |
| 609 | + $screen = get_current_screen(); | |
| 610 | + | |
| 611 | + // Bail if the screen couldn't be determined. | |
| 612 | + if ( is_null( $screen ) ) { | |
| 613 | + return false; | |
| 614 | + } | |
| 615 | + | |
| 616 | + // Return property. | |
| 617 | + return $screen->$property; | |
| 618 | + | |
| 619 | +} | |
| 620 | + | |
| 621 | +/** | |
| 622 | + * Outputs the Intercom help widget script. | |
| 623 | + * | |
| 624 | + * @since 2.7.2 | |
| 625 | + */ | |
| 626 | +function convertkit_output_intercom_messenger() { | |
| 627 | + | |
| 628 | + ?> | |
| 629 | + <script> | |
| 630 | + const KIT_INTERCOM_APP_ID = 'e4n3xtxz'; | |
| 631 | + window.intercomSettings = { | |
| 632 | + api_base: 'https://api-iam.intercom.io', | |
| 633 | + app_id: KIT_INTERCOM_APP_ID | |
| 634 | + }; | |
| 635 | + </script> | |
| 636 | + | |
| 637 | + <script> | |
| 638 | + (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);}}})(); | |
| 639 | + </script> | |
| 640 | + <?php | |
| 641 | + | |
| 642 | +} | |
| 643 | + | |
| 644 | +/** | |
| 645 | + * Returns permitted HTML output when using wp_kses( ..., convertkit_kses_allowed_html()). | |
| 646 | + * | |
| 647 | + * @since 2.8.5 | |
| 648 | + */ | |
| 649 | +function convertkit_kses_allowed_html() { | |
| 650 | + | |
| 651 | + // Get WordPress' permitted HTML elements. | |
| 652 | + $elements = wp_kses_allowed_html( 'post' ); | |
| 653 | + | |
| 654 | + // Add form elements. | |
| 655 | + $form_elements = array( | |
| 656 | + 'input' => array( | |
| 657 | + 'type' => true, | |
| 658 | + 'id' => true, | |
| 659 | + 'name' => true, | |
| 660 | + 'class' => true, | |
| 661 | + 'value' => true, | |
| 662 | + 'checked' => true, | |
| 663 | + 'min' => true, | |
| 664 | + 'max' => true, | |
| 665 | + 'step' => true, | |
| 666 | + 'data-*' => true, | |
| 667 | + ), | |
| 668 | + 'select' => array( | |
| 669 | + 'id' => true, | |
| 670 | + 'name' => true, | |
| 671 | + 'class' => true, | |
| 672 | + 'size' => true, | |
| 673 | + 'multiple' => true, | |
| 674 | + 'data-*' => true, | |
| 675 | + ), | |
| 676 | + 'option' => array( | |
| 677 | + 'value' => true, | |
| 678 | + 'selected' => true, | |
| 679 | + 'data-*' => true, | |
| 680 | + ), | |
| 681 | + 'optgroup' => array( | |
| 682 | + 'label' => true, | |
| 683 | + 'data-*' => true, | |
| 684 | + ), | |
| 685 | + 'label' => array( | |
| 686 | + 'for' => true, | |
| 687 | + ), | |
| 688 | + ); | |
| 689 | + | |
| 690 | + return array_merge( $elements, $form_elements ); | |
| 478 | 691 | |
| 479 | 692 | } |