| @@ -9,8 +9,24 @@ | ||
| 9 | 9 | exit; // Exit if accessed directly. |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | + * Fatal error mb_strpos fallback. | |
| 14 | + * | |
| 15 | + * @param string $string string where to find. | |
| 16 | + * @param string $search string to search. | |
| 17 | + * @since 1.0.0 | |
| 18 | + */ | |
| 19 | +function wcf_mb_strpos( $string, $search ) { | |
| 20 | + | |
| 21 | + if ( function_exists( 'mb_strpos' ) ) { | |
| 22 | + return mb_strpos( $string, $search, 0, 'utf-8' ); | |
| 23 | + } else { | |
| 24 | + return strpos( $string, $search ); | |
| 25 | + } | |
| 26 | +} | |
| 27 | + | |
| 28 | +/** | |
| 13 | 29 | * Check if cartflows pro activated. |
| 14 | 30 | * |
| 15 | 31 | * @since 1.0.0 |
| 16 | 32 | */ |
| @@ -20,12 +36,40 @@ | ||
| 20 | 36 | return true; |
| 21 | 37 | } |
| 22 | 38 | |
| 23 | 39 | return false; |
| 40 | +} | |
| 24 | 41 | |
| 42 | +/** | |
| 43 | + * Check if cartflows pro's license is been activated. | |
| 44 | + * | |
| 45 | + * @since 1.11.8 | |
| 46 | + */ | |
| 47 | +function _is_cartflows_pro_license_activated() { | |
| 48 | + | |
| 49 | + if ( _is_cartflows_pro() && class_exists( 'CartFlows_Pro_Licence' ) ) { | |
| 50 | + return CartFlows_Pro_Licence::get_instance()->activate_status; | |
| 51 | + } | |
| 52 | + | |
| 53 | + return false; | |
| 25 | 54 | } |
| 26 | 55 | |
| 27 | 56 | /** |
| 57 | + * Returns pro version number. | |
| 58 | + * | |
| 59 | + * @param int $version version number. | |
| 60 | + * @since 1.0.0 | |
| 61 | + */ | |
| 62 | +function _is_cartflows_pro_ver_less_than( $version ) { | |
| 63 | + | |
| 64 | + if ( defined( 'CARTFLOWS_PRO_VER' ) && version_compare( CARTFLOWS_PRO_VER, $version, '<' ) ) { | |
| 65 | + return true; | |
| 66 | + } | |
| 67 | + | |
| 68 | + return false; | |
| 69 | +} | |
| 70 | + | |
| 71 | +/** | |
| 28 | 72 | * Returns step id. |
| 29 | 73 | * |
| 30 | 74 | * @since 1.0.0 |
| 31 | 75 | */ |
| @@ -140,22 +184,43 @@ | ||
| 140 | 184 | * @return bool |
| 141 | 185 | */ |
| 142 | 186 | function _is_wcf_doing_checkout_ajax() { |
| 143 | 187 | |
| 144 | - if ( wp_doing_ajax() ) { | |
| 188 | + //phpcs:disable WordPress.Security.NonceVerification | |
| 189 | + if ( wp_doing_ajax() || isset( $_GET['wc-ajax'] ) ) { | |
| 145 | 190 | |
| 191 | + if ( ( isset( $_GET['wc-ajax'] ) && isset( $_POST['_wcf_checkout_id'] ) ) || isset( $_GET['wcf_checkout_id'] ) | |
| 192 | + ) { | |
| 193 | + return true; | |
| 194 | + } | |
| 195 | + } | |
| 196 | + //phpcs:enable WordPress.Security.NonceVerification | |
| 197 | + | |
| 198 | + return false; | |
| 199 | +} | |
| 200 | + | |
| 201 | +/** | |
| 202 | + * Check if optin AJAX call is in progress. | |
| 203 | + * | |
| 204 | + * @since 1.0.0 | |
| 205 | + * @return bool | |
| 206 | + */ | |
| 207 | +function _is_wcf_doing_optin_ajax() { | |
| 208 | + | |
| 209 | + //phpcs:disable WordPress.Security.NonceVerification | |
| 210 | + if ( wp_doing_ajax() || isset( $_GET['wc-ajax'] ) ) { | |
| 211 | + | |
| 146 | 212 | if ( isset( $_GET['wc-ajax'] ) && |
| 147 | - 'checkout' === $_GET['wc-ajax'] && | |
| 148 | - isset( $_POST['_wcf_checkout_id'] ) | |
| 213 | + isset( $_POST['_wcf_optin_id'] ) | |
| 149 | 214 | ) { |
| 150 | 215 | return true; |
| 151 | 216 | } |
| 152 | 217 | } |
| 218 | + //phpcs:enable WordPress.Security.NonceVerification | |
| 153 | 219 | |
| 154 | 220 | return false; |
| 155 | 221 | } |
| 156 | 222 | |
| 157 | - | |
| 158 | 223 | /** |
| 159 | 224 | * Returns checkout ID. |
| 160 | 225 | * |
| 161 | 226 | * @since 1.0.0 |
| @@ -352,8 +417,10 @@ | ||
| 352 | 417 | * @return bool |
| 353 | 418 | */ |
| 354 | 419 | function _is_wcf_base_offer_type() { |
| 355 | 420 | |
| 421 | + $result = false; | |
| 422 | + | |
| 356 | 423 | if ( wcf()->utils->is_step_post_type() ) { |
| 357 | 424 | |
| 358 | 425 | global $post; |
| 359 | 426 | |
| @@ -360,13 +427,13 @@ | ||
| 360 | 427 | $step_type = get_post_meta( $post->ID, 'wcf-step-type', true ); |
| 361 | 428 | |
| 362 | 429 | if ( 'upsell' === $step_type || 'downsell' === $step_type ) { |
| 363 | 430 | |
| 364 | - return true; | |
| 431 | + $result = true; | |
| 365 | 432 | } |
| 366 | 433 | } |
| 367 | 434 | |
| 368 | - return false; | |
| 435 | + return apply_filters( 'cartflows_is_offer_type', $result ); | |
| 369 | 436 | } |
| 370 | 437 | |
| 371 | 438 | /** |
| 372 | 439 | * Returns upsell ID. |
| @@ -383,5 +450,316 @@ | ||
| 383 | 450 | return $post->ID; |
| 384 | 451 | } |
| 385 | 452 | |
| 386 | 453 | return false; |
| 454 | +} | |
| 455 | + | |
| 456 | +/** | |
| 457 | + * Check if page is of optin type. | |
| 458 | + * | |
| 459 | + * @since 1.0.0 | |
| 460 | + * @return int/bool | |
| 461 | + */ | |
| 462 | +function _is_wcf_optin_type() { | |
| 463 | + | |
| 464 | + if ( wcf()->utils->is_step_post_type() ) { | |
| 465 | + | |
| 466 | + global $post; | |
| 467 | + | |
| 468 | + if ( 'optin' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) { | |
| 469 | + | |
| 470 | + return true; | |
| 471 | + } | |
| 472 | + } | |
| 473 | + | |
| 474 | + return false; | |
| 475 | +} | |
| 476 | + | |
| 477 | +/** | |
| 478 | + * Get optin page ID. | |
| 479 | + * | |
| 480 | + * @since 1.0.0 | |
| 481 | + * @return int/bool | |
| 482 | + */ | |
| 483 | +function _get_wcf_optin_id() { | |
| 484 | + | |
| 485 | + if ( _is_wcf_optin_type() ) { | |
| 486 | + | |
| 487 | + global $post; | |
| 488 | + | |
| 489 | + return $post->ID; | |
| 490 | + } | |
| 491 | + | |
| 492 | + return false; | |
| 493 | +} | |
| 494 | + | |
| 495 | +/** | |
| 496 | + * Define a constant if it is not already defined. | |
| 497 | + * | |
| 498 | + * @since 3.0.0 | |
| 499 | + * @param string $name Constant name. | |
| 500 | + * @param mixed $value Value. | |
| 501 | + */ | |
| 502 | +function wcf_maybe_define_constant( $name, $value ) { | |
| 503 | + if ( ! defined( $name ) ) { | |
| 504 | + define( $name, $value ); | |
| 505 | + } | |
| 506 | +} | |
| 507 | + | |
| 508 | + | |
| 509 | +if ( ! function_exists( 'wp_body_open' ) ) { | |
| 510 | + /** | |
| 511 | + * Fire the wp_body_open action. | |
| 512 | + * | |
| 513 | + * Added for backwards compatibility to support WordPress versions prior to 5.2.0. | |
| 514 | + */ | |
| 515 | + function wp_body_open() { | |
| 516 | + /** | |
| 517 | + * Triggered after the opening <body> tag. | |
| 518 | + */ | |
| 519 | + do_action( 'wp_body_open' ); | |
| 520 | + } | |
| 521 | +} | |
| 522 | + | |
| 523 | +/** | |
| 524 | + * Check if type is optin by id. | |
| 525 | + * | |
| 526 | + * @param int $post_id post id. | |
| 527 | + * | |
| 528 | + * @return int/bool | |
| 529 | + * @since 1.0.0 | |
| 530 | + */ | |
| 531 | +function _wcf_check_is_optin_by_id( $post_id ) { | |
| 532 | + | |
| 533 | + if ( 'optin' === get_post_meta( $post_id, 'wcf-step-type', true ) ) { | |
| 534 | + | |
| 535 | + return true; | |
| 536 | + } | |
| 537 | + | |
| 538 | + return false; | |
| 539 | +} | |
| 540 | + | |
| 541 | +/** | |
| 542 | + * Supported Page Template | |
| 543 | + * | |
| 544 | + * @param string $page_template current page template. | |
| 545 | + * | |
| 546 | + * @return int/bool | |
| 547 | + * @since 1.5.7 | |
| 548 | + */ | |
| 549 | +function _wcf_supported_template( $page_template ) { | |
| 550 | + | |
| 551 | + if ( in_array( $page_template, array( 'cartflows-default', 'cartflows-canvas', 'instant-checkout' ), true ) ) { | |
| 552 | + | |
| 553 | + return true; | |
| 554 | + } | |
| 555 | + | |
| 556 | + return false; | |
| 557 | +} | |
| 558 | + | |
| 559 | +/** | |
| 560 | + * Display design Metabox Notice. | |
| 561 | + * | |
| 562 | + * @return string | |
| 563 | + * @since 1.6.15 | |
| 564 | + */ | |
| 565 | +function wcf_get_page_builder_notice() { | |
| 566 | + | |
| 567 | + $notice = ''; | |
| 568 | + $page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' ); | |
| 569 | + | |
| 570 | + $supported_page_builders = array( 'elementor', 'beaver-builder' ); | |
| 571 | + | |
| 572 | + $page_builder_data = array( | |
| 573 | + 'elementor' => array( | |
| 574 | + 'name' => 'Elementor', | |
| 575 | + 'doc' => Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/elementor-widgets-of-cartflows/' ), | |
| 576 | + ), | |
| 577 | + 'beaver-builder' => array( | |
| 578 | + 'name' => 'Beaver Builder', | |
| 579 | + 'doc' => Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/beaver-builder-modules-of-cartflows/' ), | |
| 580 | + ), | |
| 581 | + 'gutenberg' => array( | |
| 582 | + 'name' => 'Gutenebrg', | |
| 583 | + 'doc' => Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/cartflows-gutenberg-blocks/' ), | |
| 584 | + ), | |
| 585 | + ); | |
| 586 | + | |
| 587 | + if ( isset( $page_builder_data[ $page_builder ] ) ) { | |
| 588 | + | |
| 589 | + $page_builder_name = $page_builder_data[ $page_builder ]['name']; | |
| 590 | + $doc_link = $page_builder_data[ $page_builder ]['doc']; | |
| 591 | + | |
| 592 | + $notice = '<div class="wcf-metabox-notice-wrap"><p class="wcf-metabox-notice wcf-pb-modules-notice">'; | |
| 593 | + $notice .= '<span class="dashicons dashicons-info"></span> '; | |
| 594 | + /* translators: %1$s page builder name "string" */ | |
| 595 | + $notice .= sprintf( __( 'We have introduced %1$1s widgets for CartFlows shortcodes. Now, you can add/change/update design settings directly from the page builder as well.', 'cartflows' ), $page_builder_name ); | |
| 596 | + $notice .= ' <a href="' . $doc_link . '" target="_blank">' . __( 'Learn More »', 'cartflows' ) . '</span></a>'; | |
| 597 | + $notice .= '</p></div>'; | |
| 598 | + } | |
| 599 | + | |
| 600 | + return $notice; | |
| 601 | +} | |
| 602 | + | |
| 603 | +/** | |
| 604 | + * Get step type. | |
| 605 | + * | |
| 606 | + * @param int $post_id post id. | |
| 607 | + * | |
| 608 | + * @return bool|string | |
| 609 | + * @since 1.0.0 | |
| 610 | + */ | |
| 611 | +function wcf_get_step_type( $post_id ) { | |
| 612 | + | |
| 613 | + return get_post_meta( $post_id, 'wcf-step-type', true ); | |
| 614 | +} | |
| 615 | + | |
| 616 | +/** | |
| 617 | + * Get get step object. | |
| 618 | + * | |
| 619 | + * @param int $step_id current step ID. | |
| 620 | + * @since 1.5.9 | |
| 621 | + */ | |
| 622 | +function wcf_get_step( $step_id ) { | |
| 623 | + | |
| 624 | + if ( ! isset( wcf()->wcf_step_objs[ $step_id ] ) ) { | |
| 625 | + | |
| 626 | + wcf()->wcf_step_objs[ $step_id ] = new Cartflows_Step_Factory( $step_id ); | |
| 627 | + } | |
| 628 | + | |
| 629 | + return wcf()->wcf_step_objs[ $step_id ]; | |
| 630 | +} | |
| 631 | + | |
| 632 | +/** | |
| 633 | + * Check auto-prefill checkout fields feature is enabled or not. | |
| 634 | + * | |
| 635 | + * @return boolean | |
| 636 | + */ | |
| 637 | +function is_auto_prefill_checkout_fields_enabled() { | |
| 638 | + return apply_filters( 'cartflows_auto_prefill_checkout_fields', true ); | |
| 639 | +} | |
| 640 | + | |
| 641 | +/** | |
| 642 | + * Is starter plan. | |
| 643 | + * | |
| 644 | + * @return boolean | |
| 645 | + */ | |
| 646 | +function is_wcf_starter_plan() { | |
| 647 | + return defined( 'CARTFLOWS_PRO_PLUGIN_TYPE' ) && CARTFLOWS_PRO_PLUGIN_TYPE === 'starter'; | |
| 648 | +} | |
| 649 | + | |
| 650 | +/** | |
| 651 | + * Is PRO plan. | |
| 652 | + * | |
| 653 | + * @return boolean | |
| 654 | + */ | |
| 655 | +function is_wcf_pro_plan() { | |
| 656 | + return defined( 'CARTFLOWS_PRO_PLUGIN_TYPE' ) && CARTFLOWS_PRO_PLUGIN_TYPE === 'pro'; | |
| 657 | +} | |
| 658 | + | |
| 659 | +/** | |
| 660 | + * Show notice. | |
| 661 | + * | |
| 662 | + * @param string $title title. | |
| 663 | + * @param string $message description. | |
| 664 | + * @param string $classes classes. | |
| 665 | + */ | |
| 666 | +function wcf_feature_notice( $title, $message, $classes ) { | |
| 667 | + | |
| 668 | + $image_path = esc_url( CARTFLOWS_URL . 'assets/images/cartflows-logo-small.jpg' ); | |
| 669 | + | |
| 670 | + $output = '<div class="wcf-notice wcf-dismissible-notice notice notice-info is-dismissible ' . $classes . '">'; | |
| 671 | + $output .= '<div class="wcf-notice-container">'; | |
| 672 | + $output .= '<img src=' . $image_path . ' class="wcf-notice-custom-logo" alt="CartFlows Icon" itemprop="logo">'; | |
| 673 | + $output .= '<div class="wcf-notice-message"><p class="wcf-notice-heading">' . $title . '</p><p class="wcf-notice-description">' . $message . '</p></div>'; | |
| 674 | + $output .= '</div>'; | |
| 675 | + $output .= '</div>'; | |
| 676 | + | |
| 677 | + echo wp_kses_post( $output ); | |
| 678 | +} | |
| 679 | + | |
| 680 | +/** | |
| 681 | + * Get checkout layout type. | |
| 682 | + * | |
| 683 | + * @since 2.1.0 | |
| 684 | + * @return string | |
| 685 | + */ | |
| 686 | +function wcf_get_checkout_layout() { | |
| 687 | + | |
| 688 | + $checkout_id = _is_wcf_checkout_type(); | |
| 689 | + | |
| 690 | + if ( ! $checkout_id ) { | |
| 691 | + $checkout_id = isset( $_GET['wcf_checkout_id'] ) && ! empty( $_GET['wcf_checkout_id'] ) ? intval( wp_unslash( $_GET['wcf_checkout_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification | |
| 692 | + } | |
| 693 | + | |
| 694 | + $checkout_layout = 'modern-checkout'; | |
| 695 | + | |
| 696 | + if ( ! empty( $checkout_id ) ) { | |
| 697 | + // Get checkout layout skin. | |
| 698 | + $checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' ); | |
| 699 | + } | |
| 700 | + | |
| 701 | + return $checkout_layout; | |
| 702 | +} | |
| 703 | + | |
| 704 | +/** Check weather the OttoKit is installed and Connected. | |
| 705 | + * | |
| 706 | + * @return bool | |
| 707 | + */ | |
| 708 | +function _is_suretriggers_connected() { | |
| 709 | + | |
| 710 | + // Check is the plugin installed. | |
| 711 | + if ( ! defined( 'SURE_TRIGGERS_VER' ) ) { | |
| 712 | + return false; | |
| 713 | + } | |
| 714 | + | |
| 715 | + // If installed then check is it connected or not. | |
| 716 | + return apply_filters( 'suretriggers_is_user_connected', '' ); | |
| 717 | +} | |
| 718 | + | |
| 719 | +/** | |
| 720 | + * Check if the current theme is a block theme OR a FSE Theme. | |
| 721 | + * | |
| 722 | + * @since 2.1.1 | |
| 723 | + * @return bool | |
| 724 | + */ | |
| 725 | +function wcf_is_current_theme_is_fse_theme() { | |
| 726 | + | |
| 727 | + if ( function_exists( 'wp_is_block_theme' ) ) { | |
| 728 | + return boolval( wp_is_block_theme() ); | |
| 729 | + } | |
| 730 | + | |
| 731 | + return false; | |
| 732 | +} | |
| 733 | + | |
| 734 | +/** | |
| 735 | + * Checks if deprecated step notes should be shown. | |
| 736 | + * | |
| 737 | + * This function applies a filter to determine if deprecated step notes should be displayed. | |
| 738 | + * | |
| 739 | + * @return bool Returns true if deprecated step notes should be shown, false otherwise. | |
| 740 | + */ | |
| 741 | +function wcf_show_deprecated_step_notes() { | |
| 742 | + return apply_filters( 'cartflows_show_deprecated_step_notes', false ); | |
| 743 | +} | |
| 744 | + | |
| 745 | +/** | |
| 746 | + * Checks if file modifications are disabled in WordPress. | |
| 747 | + * | |
| 748 | + * This function determines whether file modifications (such as updates and installations) | |
| 749 | + * are disabled by checking the DISALLOW_FILE_MODS constant. | |
| 750 | + * | |
| 751 | + * @since 2.2.0 | |
| 752 | + * @return bool True if file modifications are disabled, false otherwise. | |
| 753 | + */ | |
| 754 | +function wcf_file_mod_disabled() { | |
| 755 | + | |
| 756 | + $is_disabled = false; | |
| 757 | + | |
| 758 | + $disallow_file_mods = defined( 'DISALLOW_FILE_MODS' ) ? DISALLOW_FILE_MODS : false; | |
| 759 | + | |
| 760 | + if ( apply_filters( 'cartflows_file_mod_disabled', $disallow_file_mods ) ) { | |
| 761 | + $is_disabled = true; | |
| 762 | + } | |
| 763 | + | |
| 764 | + return $is_disabled; | |
| 387 | 765 | } |