| @@ -106,13 +106,35 @@ | ||
| 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 = 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 | + // 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 | + } | |
| 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,32 @@ | ||
| 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 | +/** | |
| 227 | 262 | * Helper method to return the Plugin Settings Link |
| 228 | 263 | * |
| 229 | 264 | * @since 1.9.6 |
| 230 | 265 | * |
| @@ -244,8 +279,29 @@ | ||
| 244 | 279 | |
| 245 | 280 | } |
| 246 | 281 | |
| 247 | 282 | /** |
| 283 | + * Helper method to return the Plugin Settings Link | |
| 284 | + * | |
| 285 | + * @since 2.2.4 | |
| 286 | + * | |
| 287 | + * @param array $query_args Optional Query Args. | |
| 288 | + * @return string Settings Link | |
| 289 | + */ | |
| 290 | +function convertkit_get_setup_wizard_plugin_link( $query_args = array() ) { | |
| 291 | + | |
| 292 | + $query_args = array_merge( | |
| 293 | + $query_args, | |
| 294 | + array( | |
| 295 | + 'page' => 'convertkit-setup', | |
| 296 | + ) | |
| 297 | + ); | |
| 298 | + | |
| 299 | + return add_query_arg( $query_args, admin_url( 'options.php' ) ); | |
| 300 | + | |
| 301 | +} | |
| 302 | + | |
| 303 | +/** | |
| 248 | 304 | * Helper method to return the URL the user needs to visit to register a ConvertKit account. |
| 249 | 305 | * |
| 250 | 306 | * @since 1.9.8.4 |
| 251 | 307 | * |
| @@ -284,8 +340,28 @@ | ||
| 284 | 340 | |
| 285 | 341 | } |
| 286 | 342 | |
| 287 | 343 | /** |
| 344 | + * Helper method to return the URL the user needs to visit to manage thier billing. | |
| 345 | + * | |
| 346 | + * @since 2.2.7 | |
| 347 | + * | |
| 348 | + * @return string ConvertKit Billing URL. | |
| 349 | + */ | |
| 350 | +function convertkit_get_billing_url() { | |
| 351 | + | |
| 352 | + return add_query_arg( | |
| 353 | + array( | |
| 354 | + 'utm_source' => 'wordpress', | |
| 355 | + 'utm_term' => get_locale(), | |
| 356 | + 'utm_content' => 'convertkit', | |
| 357 | + ), | |
| 358 | + 'https://app.convertkit.com/account_settings/billing/' | |
| 359 | + ); | |
| 360 | + | |
| 361 | +} | |
| 362 | + | |
| 363 | +/** | |
| 288 | 364 | * Helper method to return the URL the user needs to visit on the ConvertKit app to obtain their API Key and Secret. |
| 289 | 365 | * |
| 290 | 366 | * @since 1.9.6.1 |
| 291 | 367 | * |
| @@ -304,8 +380,132 @@ | ||
| 304 | 380 | |
| 305 | 381 | } |
| 306 | 382 | |
| 307 | 383 | /** |
| 384 | + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Form or Landing Page. | |
| 385 | + * | |
| 386 | + * @since 2.2.3 | |
| 387 | + * | |
| 388 | + * @return string ConvertKit App URL | |
| 389 | + */ | |
| 390 | +function convertkit_get_new_form_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.convertkit.com/forms/new/' | |
| 399 | + ); | |
| 400 | + | |
| 401 | +} | |
| 402 | + | |
| 403 | +/** | |
| 404 | + * Helper method to return the URL the user needs to visit to edit ConvertKit forms. | |
| 405 | + * | |
| 406 | + * @since 2.2.3 | |
| 407 | + * | |
| 408 | + * @return string ConvertKit Form Editor URL. | |
| 409 | + */ | |
| 410 | +function convertkit_get_form_editor_url() { | |
| 411 | + | |
| 412 | + return add_query_arg( | |
| 413 | + array( | |
| 414 | + 'utm_source' => 'wordpress', | |
| 415 | + 'utm_term' => get_locale(), | |
| 416 | + 'utm_content' => 'convertkit', | |
| 417 | + ), | |
| 418 | + 'https://app.convertkit.com/forms' | |
| 419 | + ); | |
| 420 | + | |
| 421 | +} | |
| 422 | + | |
| 423 | +/** | |
| 424 | + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Tag. | |
| 425 | + * | |
| 426 | + * @since 2.3.3 | |
| 427 | + * | |
| 428 | + * @return string ConvertKit App URL. | |
| 429 | + */ | |
| 430 | +function convertkit_get_new_tag_url() { | |
| 431 | + | |
| 432 | + return add_query_arg( | |
| 433 | + array( | |
| 434 | + 'utm_source' => 'wordpress', | |
| 435 | + 'utm_term' => get_locale(), | |
| 436 | + 'utm_content' => 'convertkit', | |
| 437 | + ), | |
| 438 | + 'https://app.convertkit.com/subscribers/' | |
| 439 | + ); | |
| 440 | + | |
| 441 | +} | |
| 442 | + | |
| 443 | +/** | |
| 444 | + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Broadcast. | |
| 445 | + * | |
| 446 | + * @since 2.2.6 | |
| 447 | + * | |
| 448 | + * @return string ConvertKit App URL. | |
| 449 | + */ | |
| 450 | +function convertkit_get_new_broadcast_url() { | |
| 451 | + | |
| 452 | + return add_query_arg( | |
| 453 | + array( | |
| 454 | + 'utm_source' => 'wordpress', | |
| 455 | + 'utm_term' => get_locale(), | |
| 456 | + 'utm_content' => 'convertkit', | |
| 457 | + ), | |
| 458 | + 'https://app.convertkit.com/campaigns/' | |
| 459 | + ); | |
| 460 | + | |
| 461 | +} | |
| 462 | + | |
| 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.convertkit.com/campaigns/%s/draft', | |
| 481 | + $broadcast_id | |
| 482 | + ) | |
| 483 | + ); | |
| 484 | + | |
| 485 | +} | |
| 486 | + | |
| 487 | +/** | |
| 488 | + * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Product. | |
| 489 | + * | |
| 490 | + * @since 2.2.3 | |
| 491 | + * | |
| 492 | + * @return string ConvertKit App URL. | |
| 493 | + */ | |
| 494 | +function convertkit_get_new_product_url() { | |
| 495 | + | |
| 496 | + return add_query_arg( | |
| 497 | + array( | |
| 498 | + 'utm_source' => 'wordpress', | |
| 499 | + 'utm_term' => get_locale(), | |
| 500 | + 'utm_content' => 'convertkit', | |
| 501 | + ), | |
| 502 | + 'https://app.convertkit.com/products/new/' | |
| 503 | + ); | |
| 504 | + | |
| 505 | +} | |
| 506 | + | |
| 507 | +/** | |
| 308 | 508 | * Helper method to enqueue Select2 scripts for use within the ConvertKit Plugin. |
| 309 | 509 | * |
| 310 | 510 | * @since 1.9.6.4 |
| 311 | 511 | */ |
| @@ -324,6 +524,34 @@ | ||
| 324 | 524 | function convertkit_select2_enqueue_styles() { |
| 325 | 525 | |
| 326 | 526 | wp_enqueue_style( 'convertkit-select2', 'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css', array(), CONVERTKIT_PLUGIN_VERSION ); |
| 327 | 527 | wp_enqueue_style( 'convertkit-admin-select2', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/select2.css', array(), CONVERTKIT_PLUGIN_VERSION ); |
| 528 | + | |
| 529 | +} | |
| 530 | + | |
| 531 | +/** | |
| 532 | + * Return the contents of the given local file. | |
| 533 | + * | |
| 534 | + * @since 2.2.2 | |
| 535 | + * | |
| 536 | + * @param string $local_file Local file, including path. | |
| 537 | + * @return string File contents. | |
| 538 | + */ | |
| 539 | +function convertkit_get_file_contents( $local_file ) { | |
| 540 | + | |
| 541 | + // Bail if the file doesn't exist. | |
| 542 | + if ( ! file_exists( $local_file ) ) { | |
| 543 | + return ''; | |
| 544 | + } | |
| 545 | + | |
| 546 | + // Read file. | |
| 547 | + $contents = file_get_contents( $local_file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents | |
| 548 | + | |
| 549 | + // Return an empty string if the contents of the file could not be read. | |
| 550 | + if ( ! $contents ) { | |
| 551 | + return ''; | |
| 552 | + } | |
| 553 | + | |
| 554 | + // Return file's contents. | |
| 555 | + return $contents; | |
| 328 | 556 | |
| 329 | 557 | } |