芝麻web文件管理V1.00
编辑当前文件:/home/felaukpo/public_html/wp-content/plugins/cartflows/classes/class-cartflows-frontend.php
logger->log( 'Start-' . __CLASS__ . '::' . __FUNCTION__ ); wcf()->logger->log( 'Only for thank you page' ); if ( wcf()->flow->is_thankyou_page_exists( $order ) ) { if ( _is_wcf_doing_checkout_ajax() ) { $checkout_id = wcf()->utils->get_checkout_id_from_post_data(); if ( ! $checkout_id ) { $checkout_id = wcf()->utils->get_checkout_id_from_order( $order ); } } else { $checkout_id = wcf()->utils->get_checkout_id_from_order( $order ); } wcf()->logger->log( 'Checkout ID : ' . $checkout_id ); if ( $checkout_id ) { $thankyou_step_id = wcf()->flow->get_thankyou_page_id( $order ); $thankyou_step_id = apply_filters( 'cartflows_checkout_next_step_id', $thankyou_step_id, $order, $checkout_id ); if ( $thankyou_step_id ) { $query_param = wcf()->utils->may_be_append_query_string( // Default query string args. array( 'wcf-key' => $order->get_order_key(), 'wcf-order' => $order->get_id(), ) ); $order_receive_url = add_query_arg( $query_param, get_permalink( $thankyou_step_id ) ); } } } wcf()->logger->log( 'End-' . __CLASS__ . '::' . __FUNCTION__ ); return $order_receive_url; } /** * Cancel and redirect to checkout * * @param string $return_url url. * @since 1.0.0 */ public function redirect_to_checkout_on_cancel( $return_url ) { if ( _is_wcf_doing_checkout_ajax() ) { $checkout_id = wcf()->utils->get_checkout_id_from_post_data(); if ( ! $checkout_id ) { $checkout_id = wcf()->utils->get_checkout_id_from_order( $order ); } } else { $checkout_id = wcf()->utils->get_checkout_id_from_order( $order ); } if ( $checkout_id ) { $return_url = add_query_arg( array( 'cancel_order' => 'true', '_wpnonce' => wp_create_nonce( 'woocommerce-cancel_order' ), ), get_permalink( $checkout_id ) ); } return $return_url; } /** * Remove theme styles. * * @since 1.0.0 */ public function remove_theme_styles() { if ( Cartflows_Compatibility::get_instance()->is_compatibility_theme_enabled() ) { return; } $page_template = Cartflows_Helper::get_current_page_template(); if ( ! _wcf_supported_template( $page_template ) ) { return; } // get all styles data. global $wp_styles; global $wp_scripts; $get_stylesheet = 'themes/' . get_stylesheet() . '/'; $get_template = 'themes/' . get_template() . '/'; $remove_styles = apply_filters( 'cartflows_remove_theme_styles', true ); if ( $remove_styles ) { // loop over all of the registered scripts.. foreach ( $wp_styles->registered as $handle => $data ) { if ( ! empty( $data->src ) && ( strpos( $data->src, $get_template ) !== false || strpos( $data->src, $get_stylesheet ) !== false ) ) { // remove it. wp_deregister_style( $handle ); wp_dequeue_style( $handle ); } } } $remove_scripts = apply_filters( 'cartflows_remove_theme_scripts', true ); if ( $remove_scripts ) { // loop over all of the registered scripts. foreach ( $wp_scripts->registered as $handle => $data ) { if ( ! empty( $data->src ) && ( strpos( $data->src, $get_template ) !== false || strpos( $data->src, $get_stylesheet ) !== false ) ) { // remove it. wp_deregister_script( $handle ); wp_dequeue_script( $handle ); } } } } /** * Update main order data in transient. * * @param array $woo_styles new styles array. * @since 1.0.0 * @return array. */ public function woo_default_css( $woo_styles ) { $woo_styles = array( 'woocommerce-layout' => array( 'src' => plugins_url( 'assets/css/woocommerce-layout.css', WC_PLUGIN_FILE ), 'deps' => '', 'version' => WC_VERSION, 'media' => 'all', 'has_rtl' => true, ), 'woocommerce-smallscreen' => array( 'src' => plugins_url( 'assets/css/woocommerce-smallscreen.css', WC_PLUGIN_FILE ), 'deps' => 'woocommerce-layout', 'version' => WC_VERSION, 'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', '768px' ) . ')', 'has_rtl' => true, ), 'woocommerce-general' => array( 'src' => plugins_url( 'assets/css/woocommerce.css', WC_PLUGIN_FILE ), 'deps' => '', 'version' => WC_VERSION, 'media' => 'all', 'has_rtl' => true, ), ); return $woo_styles; } /** * Init Actions. * * @since 1.0.0 */ public function init_actions() { if ( wcf()->utils->is_step_post_type() ) { global $post; $GLOBALS['wcf_step'] = wcf_get_step( $post->ID ); do_action( 'cartflows_wp', $post->ID ); $this->set_flow_session(); $this->delete_checkout_cookies(); } } /** * Set flow session. * * @since 1.0.0 */ public function set_flow_session() { global $wp; add_action( 'wp_head', array( $this, 'noindex_flow' ) ); wcf()->utils->do_not_cache(); if ( _is_wcf_thankyou_type() ) { /* Set key to support pixel */ //phpcs:disable WordPress.Security.NonceVerification if ( isset( $_GET['wcf-key'] ) ) { $wcf_key = sanitize_text_field( wp_unslash( $_GET['wcf-key'] ) ); $_GET['key'] = $wcf_key; $_REQUEST['key'] = $wcf_key; } if ( isset( $_GET['wcf-order'] ) ) { $wcf_order = intval( wp_unslash( $_GET['wcf-order'] ) ); //phpcs:enable WordPress.Security.NonceVerification $_GET['order'] = $wcf_order; $_REQUEST['order'] = $wcf_order; $_GET['order-received'] = $wcf_order; $_REQUEST['order-received'] = $wcf_order; $wp->set_query_var( 'order-received', $wcf_order ); } } } /** * Delete checkout cookies. * * @since 1.0.0 */ public function delete_checkout_cookies() { if ( _is_wcf_thankyou_type() ) { if ( ! wcf()->is_woo_active || ! isset( WC()->session ) ) { return; } $user_key = WC()->session->get_customer_id(); if ( isset( $_COOKIE[ CARTFLOWS_ACTIVE_CHECKOUT ] ) ) { delete_transient( 'wcf_user_' . $user_key . '_checkout_' . sanitize_text_field( wp_unslash( $_COOKIE[ CARTFLOWS_ACTIVE_CHECKOUT ] ) ) ); //phpcs:ignore WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___COOKIE unset( $_COOKIE[ CARTFLOWS_ACTIVE_CHECKOUT ] ); //phpcs:ignore WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___COOKIE setcookie( CARTFLOWS_ACTIVE_CHECKOUT, '', time() - 3600, '/', COOKIE_DOMAIN, CARTFLOWS_HTTPS, true ); //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.cookies_setcookie } } } /** * Add noindex, nofollow. * * @since 1.0.0 */ public function noindex_flow() { $common = Cartflows_Helper::get_common_settings(); global $post; $flow_id = wcf()->utils->get_flow_id_from_step_id( $post->ID ); $flow_indexing = get_post_meta( $flow_id, 'wcf-flow-indexing', true ); $allow_indexing = ( ( '' === $flow_indexing && 'enable' === $common['disallow_indexing'] ) || 'disallow' === $flow_indexing ); if ( apply_filters( 'cartflows_step_add_noindex_meta', $allow_indexing, $flow_id ) ) { echo '
'; } } /** * WP Actions. * * @since 1.0.0 */ public function wp_actions() { if ( wcf()->utils->is_step_post_type() ) { if ( ! wcf()->is_woo_active && wcf()->utils->check_is_woo_required_page() ) { wp_die( ' This page requires WooCommerce plugin installed and activated!', 'WooCommerce Required' ); } /* CSS Compatibility for All theme */ add_filter( 'woocommerce_enqueue_styles', array( $this, 'woo_default_css' ), 9999 ); add_action( 'wp_enqueue_scripts', array( $this, 'remove_theme_styles' ), 9999 ); add_action( 'wp_enqueue_scripts', array( $this, 'global_flow_scripts' ), 20 ); /* Load woo templates from plugin */ add_filter( 'woocommerce_locate_template', array( $this, 'override_woo_template' ), 20, 3 ); /* Add version class to body in frontend. */ add_filter( 'body_class', array( $this, 'add_cartflows_lite_version_to_body' ) ); /* Custom Script Option */ add_action( 'wp_head', array( $this, 'custom_script_option' ) ); /* Remove the action applied by the Flatsome theme */ if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) { $this->remove_flatsome_action(); } } } /** * Debug Data Setting Actions. * * @since 1.1.14 */ public function debug_data_setting_actions() { add_filter( 'cartflows_load_min_assets', array( $this, 'allow_load_minify' ) ); } /** * Get/Set the allow minify option. * * @since 1.1.14 */ public function allow_load_minify() { $debug_data = Cartflows_Helper::get_debug_settings(); $allow_minified = $debug_data['allow_minified_files']; $allow_minify = false; if ( 'enable' === $allow_minified ) { $allow_minify = true; } return $allow_minify; } /** * Global flow scripts. * * @since 1.0.0 */ public function global_flow_scripts() { global $post, $wcf_step; $flow = $wcf_step->get_flow_id(); $current_step = $wcf_step->get_current_step(); $control_step = $wcf_step->get_control_step(); $next_step_link = ''; $compatibility = Cartflows_Compatibility::get_instance(); $is_checkout = _is_wcf_checkout_type(); $is_optin = _is_wcf_optin_type(); if ( _is_wcf_landing_type() ) { $next_step_id = $wcf_step->get_direct_next_step_id(); $next_step_link = get_permalink( $next_step_id ); } $page_template = get_post_meta( $current_step, '_wp_page_template', true ); $fb_tracking_settings = Cartflows_Helper::get_facebook_settings(); $ga_tracking_settings = Cartflows_Helper::get_google_analytics_settings(); $tik_pixel_settings = Cartflows_Helper::get_tiktok_settings(); $pinterest_settings = Cartflows_Helper::get_pinterest_settings(); $gads_settings = Cartflows_Helper::get_google_ads_settings(); $snapchat_settings = Cartflows_Helper::get_snapchat_settings(); $localize = array( 'ajax_url' => admin_url( 'admin-ajax.php', 'relative' ), 'is_pb_preview' => $compatibility->is_page_builder_preview(), 'current_theme' => $compatibility->get_current_theme(), 'current_flow' => $flow, 'current_step' => $current_step, 'control_step' => $control_step, 'next_step' => $next_step_link, 'page_template' => $page_template, 'default_page_builder' => \Cartflows_Helper::get_common_setting( 'default_page_builder' ), 'is_checkout_page' => $is_checkout, 'fb_setting' => $fb_tracking_settings, 'ga_setting' => $ga_tracking_settings, 'tik_setting' => $tik_pixel_settings, 'pin_settings' => $pinterest_settings, 'gads_setting' => $gads_settings, 'snap_settings' => $snapchat_settings, 'active_checkout_cookie' => CARTFLOWS_ACTIVE_CHECKOUT, 'is_optin' => $is_optin, ); if ( $is_checkout ) { $localize['ajax_url'] = add_query_arg( array( 'wcf_checkout_id' => $current_step, ), $localize['ajax_url'] ); } $localize = apply_filters( 'global_cartflows_js_localize', $localize ); $localize_script = ''; $localize_script .= ''; echo $localize_script; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ( _wcf_supported_template( $page_template ) ) { $page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' ); if ( ! ( 'bricks-builder' === $page_builder && function_exists( 'bricks_is_builder' ) && bricks_is_builder() ) ) { wp_enqueue_style( 'wcf-normalize-frontend-global', wcf()->utils->get_css_url( 'cartflows-normalize' ), array(), CARTFLOWS_VER ); } } if ( ! wcf()->is_woo_active ) { wp_register_script( 'jquery-cookie', CARTFLOWS_URL . 'assets/js/lib/jquery-cookie/jquery.cookie.min.js', array( 'jquery' ), CARTFLOWS_VER, false ); } wp_enqueue_style( 'wcf-frontend-global', wcf()->utils->get_css_url( 'frontend' ), array(), CARTFLOWS_VER ); wp_enqueue_script( 'wcf-frontend-global', wcf()->utils->get_js_url( 'frontend' ), array( 'jquery', 'jquery-cookie' ), CARTFLOWS_VER, false ); } /** * Custom Script in head. * * @since 1.0.0 */ public function custom_script_option() { // Check if migration to separate JS/CSS fields is completed. $migration_completed = 'completed' === Cartflows_Helper::get_script_migration_status(); $global_css = trim( $this->get_global_custom_css() ); $global_js = trim( $this->get_global_custom_js() ); $flow_css = ''; $flow_js = ''; $step_css = ''; $step_js = ''; // Old combined script values (used only if migration not completed). $script = ''; $flow_script = ''; if ( $migration_completed ) { // Migration completed: load from new separate JS and CSS meta keys. $flow_css = trim( $this->get_flow_custom_css() ); $flow_js = trim( $this->get_flow_custom_js() ); $step_css = trim( $this->get_step_custom_css() ); $step_js = trim( $this->get_step_custom_js() ); } else { // Migration not completed: load from old combined script meta keys. $script = $this->get_custom_script(); $flow_script = $this->get_flow_custom_script(); } // ------------------------- // CSS Output (Global → Flow → Step) // Step CSS takes priority due to later output. // ------------------------- if ( '' !== $global_css || '' !== $flow_css || '' !== $step_css ) { echo ''; echo ''; echo ''; echo PHP_EOL; } // ------------------------- // JS Output (Global → Flow → Step) // Step JS takes priority due to later execution. // ------------------------- echo ''; echo '', '<\/script>', html_entity_decode( $global_js ) ) . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } // Flow JS (new or old format). if ( $migration_completed && '' !== $flow_js ) { // New format: already pure JS, just escape closing tags. echo str_replace( '', '<\/script>', html_entity_decode( $flow_js ) ) . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } elseif ( ! $migration_completed && '' !== $flow_script ) { // Old format: strip any existing script/style tags and output raw JS. $flow_script_output = $this->strip_script_style_tags( $flow_script ); echo str_replace( '', '<\/script>', html_entity_decode( $flow_script_output ) ) . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } // Step JS (new or old format). if ( $migration_completed && '' !== $step_js ) { // New format: already pure JS, just escape closing tags. echo str_replace( '', '<\/script>', html_entity_decode( $step_js ) ) . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } elseif ( ! $migration_completed && '' !== $script ) { // Old format: strip any existing script/style tags and output raw JS. $step_script_output = $this->strip_script_style_tags( $script ); echo str_replace( '', '<\/script>', html_entity_decode( $step_script_output ) ) . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } echo ''; echo ''; echo PHP_EOL; } /** * Strip tags but keep inner content. $content = preg_replace( '/