| @@ -106,13 +106,32 @@ | ||
| 106 | 106 | * @return array Post Types |
| 107 | 107 | */ |
| 108 | 108 | function convertkit_get_supported_post_types() { |
| 109 | 109 | |
| 110 | + // Define supported Post Types. | |
| 110 | 111 | $post_types = array( |
| 111 | 112 | 'page', |
| 112 | 113 | 'post', |
| 113 | 114 | ); |
| 114 | 115 | |
| 116 | + // If public Custom Post Types can be fetched, include them now. | |
| 117 | + if ( function_exists( 'get_post_types' ) ) { | |
| 118 | + // Get public Custom Post Types. | |
| 119 | + $custom_post_types = (array) get_post_types( | |
| 120 | + array( | |
| 121 | + 'public' => true, | |
| 122 | + | |
| 123 | + // Don't include WordPress' built in Post Types, such as attachment, revisino and nav_menu_item. | |
| 124 | + '_builtin' => false, | |
| 125 | + ) | |
| 126 | + ); | |
| 127 | + | |
| 128 | + $post_types = array_merge( | |
| 129 | + $post_types, | |
| 130 | + array_keys( $custom_post_types ) | |
| 131 | + ); | |
| 132 | + } | |
| 133 | + | |
| 115 | 134 | /** |
| 116 | 135 | * Defines the Post Types that support ConvertKit Forms. |
| 117 | 136 | * |
| 118 | 137 | * @since 1.9.6 |
| @@ -129,27 +148,16 @@ | ||
| 129 | 148 | * Helper method to get supported Post Types for Restricted Content (Member's Content) |
| 130 | 149 | * |
| 131 | 150 | * @since 2.1.0 |
| 132 | 151 | * |
| 152 | + * @deprecated 2.4.3 No longer used by internal code and not recommended. Use `convertkit_get_supported_post_types` instead. | |
| 153 | + * | |
| 133 | 154 | * @return array Post Types |
| 134 | 155 | */ |
| 135 | 156 | function convertkit_get_supported_restrict_content_post_types() { |
| 136 | 157 | |
| 137 | - $post_types = array( | |
| 138 | - 'page', | |
| 139 | - ); | |
| 158 | + return convertkit_get_supported_post_types(); | |
| 140 | 159 | |
| 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 | 160 | } |
| 153 | 161 | |
| 154 | 162 | /** |
| 155 | 163 | * Helper method to get registered Shortcodes. |
| @@ -223,8 +231,32 @@ | ||
| 223 | 231 | |
| 224 | 232 | } |
| 225 | 233 | |
| 226 | 234 | /** |
| 235 | + * Helper method to get registered pre-publish actions. | |
| 236 | + * | |
| 237 | + * @since 2.4.0 | |
| 238 | + * | |
| 239 | + * @return array Pre-publish actions | |
| 240 | + */ | |
| 241 | +function convertkit_get_pre_publish_actions() { | |
| 242 | + | |
| 243 | + $pre_publish_actions = array(); | |
| 244 | + | |
| 245 | + /** | |
| 246 | + * Registers pre-publish actions for the ConvertKit Plugin. | |
| 247 | + * | |
| 248 | + * @since 2.4.0 | |
| 249 | + * | |
| 250 | + * @param array $pre_publish_panels Pre-publish actions. | |
| 251 | + */ | |
| 252 | + $pre_publish_actions = apply_filters( 'convertkit_get_pre_publish_actions', $pre_publish_actions ); | |
| 253 | + | |
| 254 | + return $pre_publish_actions; | |
| 255 | + | |
| 256 | +} | |
| 257 | + | |
| 258 | +/** | |
| 227 | 259 | * Helper method to return the Plugin Settings Link |
| 228 | 260 | * |
| 229 | 261 | * @since 1.9.6 |
| 230 | 262 | * |
| @@ -260,9 +292,9 @@ | ||
| 260 | 292 | 'page' => 'convertkit-setup', |
| 261 | 293 | ) |
| 262 | 294 | ); |
| 263 | 295 | |
| 264 | - return add_query_arg( $query_args, admin_url( 'index.php' ) ); | |
| 296 | + return add_query_arg( $query_args, admin_url( 'options.php' ) ); | |
| 265 | 297 | |
| 266 | 298 | } |
| 267 | 299 | |
| 268 | 300 | /** |
| @@ -279,9 +311,9 @@ | ||
| 279 | 311 | 'utm_source' => 'wordpress', |
| 280 | 312 | 'utm_term' => get_locale(), |
| 281 | 313 | 'utm_content' => 'convertkit', |
| 282 | 314 | ), |
| 283 | - 'https://app.convertkit.com/users/signup' | |
| 315 | + 'https://app.kit.com/users/signup' | |
| 284 | 316 | ); |
| 285 | 317 | |
| 286 | 318 | } |
| 287 | 319 | |
| @@ -299,9 +331,9 @@ | ||
| 299 | 331 | 'utm_source' => 'wordpress', |
| 300 | 332 | 'utm_term' => get_locale(), |
| 301 | 333 | 'utm_content' => 'convertkit', |
| 302 | 334 | ), |
| 303 | - 'https://app.convertkit.com/' | |
| 335 | + 'https://app.kit.com/' | |
| 304 | 336 | ); |
| 305 | 337 | |
| 306 | 338 | } |
| 307 | 339 | |
| @@ -319,21 +351,21 @@ | ||
| 319 | 351 | 'utm_source' => 'wordpress', |
| 320 | 352 | 'utm_term' => get_locale(), |
| 321 | 353 | 'utm_content' => 'convertkit', |
| 322 | 354 | ), |
| 323 | - 'https://app.convertkit.com/account_settings/billing/' | |
| 355 | + 'https://app.kit.com/account_settings/billing/' | |
| 324 | 356 | ); |
| 325 | 357 | |
| 326 | 358 | } |
| 327 | 359 | |
| 328 | 360 | /** |
| 329 | - * Helper method to return the URL the user needs to visit on the ConvertKit app to obtain their API Key and Secret. | |
| 361 | + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Form or Landing Page. | |
| 330 | 362 | * |
| 331 | - * @since 1.9.6.1 | |
| 363 | + * @since 2.2.3 | |
| 332 | 364 | * |
| 333 | - * @return string ConvertKit App URL. | |
| 365 | + * @return string ConvertKit App URL | |
| 334 | 366 | */ |
| 335 | -function convertkit_get_api_key_url() { | |
| 367 | +function convertkit_get_new_form_url() { | |
| 336 | 368 | |
| 337 | 369 | return add_query_arg( |
| 338 | 370 | array( |
| 339 | 371 | 'utm_source' => 'wordpress', |
| @@ -339,21 +371,41 @@ | ||
| 339 | 371 | 'utm_source' => 'wordpress', |
| 340 | 372 | 'utm_term' => get_locale(), |
| 341 | 373 | 'utm_content' => 'convertkit', |
| 342 | 374 | ), |
| 343 | - 'https://app.convertkit.com/account_settings/advanced_settings/' | |
| 375 | + 'https://app.kit.com/forms/new/' | |
| 344 | 376 | ); |
| 345 | 377 | |
| 346 | 378 | } |
| 347 | 379 | |
| 348 | 380 | /** |
| 349 | - * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Form or Landing Page. | |
| 381 | + * Helper method to return the URL the user needs to visit to edit ConvertKit forms. | |
| 350 | 382 | * |
| 351 | 383 | * @since 2.2.3 |
| 352 | 384 | * |
| 385 | + * @return string ConvertKit Form Editor URL. | |
| 386 | + */ | |
| 387 | +function convertkit_get_form_editor_url() { | |
| 388 | + | |
| 389 | + return add_query_arg( | |
| 390 | + array( | |
| 391 | + 'utm_source' => 'wordpress', | |
| 392 | + 'utm_term' => get_locale(), | |
| 393 | + 'utm_content' => 'convertkit', | |
| 394 | + ), | |
| 395 | + 'https://app.kit.com/forms' | |
| 396 | + ); | |
| 397 | + | |
| 398 | +} | |
| 399 | + | |
| 400 | +/** | |
| 401 | + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Landing Page. | |
| 402 | + * | |
| 403 | + * @since 2.5.5 | |
| 404 | + * | |
| 353 | 405 | * @return string ConvertKit App URL |
| 354 | 406 | */ |
| 355 | -function convertkit_get_new_form_url() { | |
| 407 | +function convertkit_get_new_landing_page_url() { | |
| 356 | 408 | |
| 357 | 409 | return add_query_arg( |
| 358 | 410 | array( |
| 359 | 411 | 'utm_source' => 'wordpress', |
| @@ -359,21 +411,21 @@ | ||
| 359 | 411 | 'utm_source' => 'wordpress', |
| 360 | 412 | 'utm_term' => get_locale(), |
| 361 | 413 | 'utm_content' => 'convertkit', |
| 362 | 414 | ), |
| 363 | - 'https://app.convertkit.com/forms/new/' | |
| 415 | + 'https://app.kit.com/pages/new/' | |
| 364 | 416 | ); |
| 365 | 417 | |
| 366 | 418 | } |
| 367 | 419 | |
| 368 | 420 | /** |
| 369 | - * Helper method to return the URL the user needs to visit to edit ConvertKit forms. | |
| 421 | + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Tag. | |
| 370 | 422 | * |
| 371 | - * @since 2.2.3 | |
| 423 | + * @since 2.3.3 | |
| 372 | 424 | * |
| 373 | - * @return string ConvertKit Form Editor URL. | |
| 425 | + * @return string ConvertKit App URL. | |
| 374 | 426 | */ |
| 375 | -function convertkit_get_form_editor_url() { | |
| 427 | +function convertkit_get_new_tag_url() { | |
| 376 | 428 | |
| 377 | 429 | return add_query_arg( |
| 378 | 430 | array( |
| 379 | 431 | 'utm_source' => 'wordpress', |
| @@ -379,9 +431,9 @@ | ||
| 379 | 431 | 'utm_source' => 'wordpress', |
| 380 | 432 | 'utm_term' => get_locale(), |
| 381 | 433 | 'utm_content' => 'convertkit', |
| 382 | 434 | ), |
| 383 | - 'https://app.convertkit.com/forms' | |
| 435 | + 'https://app.kit.com/subscribers/' | |
| 384 | 436 | ); |
| 385 | 437 | |
| 386 | 438 | } |
| 387 | 439 | |
| @@ -399,14 +451,38 @@ | ||
| 399 | 451 | 'utm_source' => 'wordpress', |
| 400 | 452 | 'utm_term' => get_locale(), |
| 401 | 453 | 'utm_content' => 'convertkit', |
| 402 | 454 | ), |
| 403 | - 'https://app.convertkit.com/campaigns/' | |
| 455 | + 'https://app.kit.com/campaigns/' | |
| 404 | 456 | ); |
| 405 | 457 | |
| 406 | 458 | } |
| 407 | 459 | |
| 408 | 460 | /** |
| 461 | + * Helper method to return the URL the user needs to visit on the ConvertKit app to edit a draft Broadcast. | |
| 462 | + * | |
| 463 | + * @since 2.4.0 | |
| 464 | + * | |
| 465 | + * @param int $broadcast_id ConvertKit Broadcast ID. | |
| 466 | + * @return string ConvertKit App URL. | |
| 467 | + */ | |
| 468 | +function convertkit_get_edit_broadcast_url( $broadcast_id ) { | |
| 469 | + | |
| 470 | + return add_query_arg( | |
| 471 | + array( | |
| 472 | + 'utm_source' => 'wordpress', | |
| 473 | + 'utm_term' => get_locale(), | |
| 474 | + 'utm_content' => 'convertkit', | |
| 475 | + ), | |
| 476 | + sprintf( | |
| 477 | + 'https://app.kit.com/campaigns/%s/draft', | |
| 478 | + $broadcast_id | |
| 479 | + ) | |
| 480 | + ); | |
| 481 | + | |
| 482 | +} | |
| 483 | + | |
| 484 | +/** | |
| 409 | 485 | * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Product. |
| 410 | 486 | * |
| 411 | 487 | * @since 2.2.3 |
| 412 | 488 | * |
| @@ -419,9 +495,9 @@ | ||
| 419 | 495 | 'utm_source' => 'wordpress', |
| 420 | 496 | 'utm_term' => get_locale(), |
| 421 | 497 | 'utm_content' => 'convertkit', |
| 422 | 498 | ), |
| 423 | - 'https://app.convertkit.com/products/new/' | |
| 499 | + 'https://app.kit.com/products/new/' | |
| 424 | 500 | ); |
| 425 | 501 | |
| 426 | 502 | } |
| 427 | 503 | |
| @@ -458,22 +534,106 @@ | ||
| 458 | 534 | * @return string File contents. |
| 459 | 535 | */ |
| 460 | 536 | function convertkit_get_file_contents( $local_file ) { |
| 461 | 537 | |
| 462 | - // Call globals. | |
| 463 | - global $wp_filesystem; | |
| 538 | + // Bail if the file doesn't exist. | |
| 539 | + if ( ! file_exists( $local_file ) ) { | |
| 540 | + return ''; | |
| 541 | + } | |
| 464 | 542 | |
| 465 | - // Load filesystem class. | |
| 466 | - require_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 543 | + // Read file. | |
| 544 | + $contents = file_get_contents( $local_file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents | |
| 467 | 545 | |
| 468 | - // Initiate. | |
| 469 | - WP_Filesystem(); | |
| 470 | - | |
| 471 | - // Bail if the file doesn't exist. | |
| 472 | - if ( ! $wp_filesystem->exists( $local_file ) ) { | |
| 546 | + // Return an empty string if the contents of the file could not be read. | |
| 547 | + if ( ! $contents ) { | |
| 473 | 548 | return ''; |
| 474 | 549 | } |
| 475 | 550 | |
| 476 | 551 | // Return file's contents. |
| 477 | - return $wp_filesystem->get_contents( $local_file ); | |
| 552 | + return $contents; | |
| 553 | + | |
| 554 | +} | |
| 555 | + | |
| 556 | +/** | |
| 557 | + * Returns a dropdown field commonly used for settings, comprising of: | |
| 558 | + * - Do not subscribe | |
| 559 | + * - Subscribe | |
| 560 | + * - Subscribe to Form | |
| 561 | + * | |
| 562 | + * @since 2.5.2 | |
| 563 | + * | |
| 564 | + * @param string $name Field name. | |
| 565 | + * @param string $value Field value. | |
| 566 | + * @param string $id Field ID attribute. | |
| 567 | + * @param string $css_class Field CSS class(es). | |
| 568 | + * @param string $context Resource context. | |
| 569 | + * @param bool|array $additional_options Additional <option> key/value pairs. | |
| 570 | + */ | |
| 571 | +function convertkit_get_subscription_dropdown_field( $name, $value, $id, $css_class = '', $context = '', $additional_options = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter | |
| 572 | + | |
| 573 | + // Load resource classes. | |
| 574 | + $forms = new ConvertKit_Resource_Forms( $context ); | |
| 575 | + $tags = new ConvertKit_Resource_Tags( $context ); | |
| 576 | + $sequences = new ConvertKit_Resource_Sequences( $context ); | |
| 577 | + | |
| 578 | + ob_start(); | |
| 579 | + include CONVERTKIT_PLUGIN_PATH . '/views/backend/subscription-dropdown-field.php'; | |
| 580 | + $output = trim( ob_get_clean() ); | |
| 581 | + | |
| 582 | + // Return output. | |
| 583 | + return $output; | |
| 584 | + | |
| 585 | +} | |
| 586 | + | |
| 587 | +/** | |
| 588 | + * Helper method to safely call get_current_screen(), returning false | |
| 589 | + * if the function is not available or returns null. | |
| 590 | + * | |
| 591 | + * Otherwise returns the given WP_Screen property. | |
| 592 | + * | |
| 593 | + * @since 2.5.9 | |
| 594 | + * | |
| 595 | + * @param string $property WP_Screen property to return. | |
| 596 | + * @return bool|string | |
| 597 | + */ | |
| 598 | +function convertkit_get_current_screen( $property ) { | |
| 599 | + | |
| 600 | + // Bail if we cannot determine the screen. | |
| 601 | + if ( ! function_exists( 'get_current_screen' ) ) { | |
| 602 | + return false; | |
| 603 | + } | |
| 604 | + | |
| 605 | + // Get screen. | |
| 606 | + $screen = get_current_screen(); | |
| 607 | + | |
| 608 | + // Bail if the screen couldn't be determined. | |
| 609 | + if ( is_null( $screen ) ) { | |
| 610 | + return false; | |
| 611 | + } | |
| 612 | + | |
| 613 | + // Return property. | |
| 614 | + return $screen->$property; | |
| 615 | + | |
| 616 | +} | |
| 617 | + | |
| 618 | +/** | |
| 619 | + * Outputs the Intercom help widget script. | |
| 620 | + * | |
| 621 | + * @since 2.7.2 | |
| 622 | + */ | |
| 623 | +function convertkit_output_intercom_messenger() { | |
| 624 | + | |
| 625 | + ?> | |
| 626 | + <script> | |
| 627 | + const KIT_INTERCOM_APP_ID = 'e4n3xtxz'; | |
| 628 | + window.intercomSettings = { | |
| 629 | + api_base: 'https://api-iam.intercom.io', | |
| 630 | + app_id: KIT_INTERCOM_APP_ID | |
| 631 | + }; | |
| 632 | + </script> | |
| 633 | + | |
| 634 | + <script> | |
| 635 | + (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);}}})(); | |
| 636 | + </script> | |
| 637 | + <?php | |
| 478 | 638 | |
| 479 | 639 | } |