| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | use Elementor\Utils as ElementorUtils; |
| 4 | +use Sellkit\Global_Checkout\Checkout as Global_Checkout; | |
| 4 | 5 | |
| 5 | 6 | defined( 'ABSPATH' ) || die(); |
| 6 | 7 | |
| 7 | 8 | /** |
| @@ -74,9 +75,13 @@ | ||
| 74 | 75 | $page_id = self::get_page_id(); |
| 75 | 76 | } |
| 76 | 77 | |
| 77 | 78 | if ( empty( $page_id ) ) { |
| 78 | - return; | |
| 79 | + $page_id = $this->get_funnel_step_homepage_id(); | |
| 80 | + | |
| 81 | + if ( empty( $page_id ) ) { | |
| 82 | + return; | |
| 83 | + } | |
| 79 | 84 | } |
| 80 | 85 | |
| 81 | 86 | $this->set_funnel_data( $page_id ); |
| 82 | 87 | |
| @@ -87,8 +92,57 @@ | ||
| 87 | 92 | add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_funnel_frontend_script' ] ); |
| 88 | 93 | } |
| 89 | 94 | |
| 90 | 95 | /** |
| 96 | + * Gets funnel step homepage id. | |
| 97 | + * | |
| 98 | + * @since 1.9.6 | |
| 99 | + * @return int|bool | |
| 100 | + */ | |
| 101 | + private function get_funnel_step_homepage_id() { | |
| 102 | + if ( is_admin() ) { | |
| 103 | + return false; | |
| 104 | + } | |
| 105 | + | |
| 106 | + $front_page_id = get_option( 'page_on_front', 0 ); | |
| 107 | + | |
| 108 | + if ( empty( $front_page_id ) ) { | |
| 109 | + return false; | |
| 110 | + } | |
| 111 | + | |
| 112 | + $scheme = ( ! empty( $_SERVER['HTTPS'] ) && 'off' !== $_SERVER['HTTPS'] ) ? 'https' : 'http'; | |
| 113 | + | |
| 114 | + $host = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ); // phpcs:ignore | |
| 115 | + $request_uri = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ); // phpcs:ignore | |
| 116 | + | |
| 117 | + $url = esc_url( "$scheme://$host$request_uri" ); | |
| 118 | + $home_url = get_home_url() . '/'; | |
| 119 | + | |
| 120 | + if ( '/' !== substr( $url, -1 ) ) { | |
| 121 | + $home_url = get_home_url(); | |
| 122 | + } | |
| 123 | + | |
| 124 | + if ( $home_url !== $url ) { | |
| 125 | + return false; | |
| 126 | + } | |
| 127 | + | |
| 128 | + $post_id = url_to_postid( $url ); | |
| 129 | + | |
| 130 | + if ( empty( $post_id ) ) { | |
| 131 | + return false; | |
| 132 | + } | |
| 133 | + | |
| 134 | + $post_type = get_post_type( $post_id ); | |
| 135 | + $status = Funnel_Homepage::check_funnel_step_status( $post_id, $post_type ); | |
| 136 | + | |
| 137 | + if ( $status && intval( $post_id ) === intval( $front_page_id ) ) { | |
| 138 | + return $front_page_id; | |
| 139 | + } | |
| 140 | + | |
| 141 | + return false; | |
| 142 | + } | |
| 143 | + | |
| 144 | + /** | |
| 91 | 145 | * Class Instance. |
| 92 | 146 | * |
| 93 | 147 | * @since 1.1.0 |
| 94 | 148 | * @return Sellkit_Funnel|null |
| @@ -194,12 +248,16 @@ | ||
| 194 | 248 | * @return array |
| 195 | 249 | */ |
| 196 | 250 | public function get_localize_data() { |
| 197 | 251 | if ( ! empty( $this->next_step_data['page_id'] ) ) { |
| 198 | - $next_step_link = add_query_arg( [ | |
| 199 | - 'post_type' => Sellkit_Admin_Steps::SELLKIT_STEP_POST_TYPE, | |
| 200 | - 'p' => $this->next_step_data['page_id'], | |
| 201 | - ], site_url() ); | |
| 252 | + $next_step_link = ! empty( $this->next_step_data['page_id'] ) ? get_the_permalink( $this->next_step_data['page_id'] ) : ''; | |
| 253 | + | |
| 254 | + if ( empty( $next_step_link ) ) { | |
| 255 | + $next_step_link = add_query_arg( [ | |
| 256 | + 'post_type' => Sellkit_Admin_Steps::SELLKIT_STEP_POST_TYPE, | |
| 257 | + 'p' => $this->next_step_data['page_id'], | |
| 258 | + ], site_url() ); | |
| 259 | + } | |
| 202 | 260 | } |
| 203 | 261 | |
| 204 | 262 | return [ |
| 205 | 263 | 'currentStep' => $this->current_step_data, |
| @@ -216,13 +274,18 @@ | ||
| 216 | 274 | * @return false|int |
| 217 | 275 | * @SuppressWarnings(PHPMD.NPathComplexity) |
| 218 | 276 | */ |
| 219 | 277 | public static function get_page_id() { |
| 220 | - $page_id = sellkit_htmlspecialchars( INPUT_POST, 'sellkit_current_page_id' ); | |
| 221 | - $preview = sellkit_htmlspecialchars( INPUT_GET, 'preview' ); | |
| 278 | + $page_id = sellkit_htmlspecialchars( INPUT_POST, 'sellkit_current_page_id' ); | |
| 279 | + $structure = get_option( 'permalink_structure' ); | |
| 280 | + $post_data = filter_input( INPUT_POST, 'post_data', FILTER_DEFAULT ); | |
| 222 | 281 | |
| 223 | - if ( ! empty( $preview ) ) { | |
| 224 | - return false; | |
| 282 | + if ( ! empty( $post_data ) ) { | |
| 283 | + parse_str( $post_data, $post_data ); | |
| 284 | + | |
| 285 | + if ( ! empty( $post_data['sellkit_current_page_id'] ) ) { | |
| 286 | + return (int) $post_data['sellkit_current_page_id']; | |
| 287 | + } | |
| 225 | 288 | } |
| 226 | 289 | |
| 227 | 290 | if ( is_numeric( $page_id ) ) { |
| 228 | 291 | return $page_id; |
| @@ -227,11 +290,29 @@ | ||
| 227 | 290 | if ( is_numeric( $page_id ) ) { |
| 228 | 291 | return $page_id; |
| 229 | 292 | } |
| 230 | 293 | |
| 294 | + // Stripe Express Checkout (and similar express flows) POST to wc-ajax=checkout | |
| 295 | + // without SellKit's hidden fields. Fall back to the checkout step id stored in | |
| 296 | + // the WC session when the user first landed on the funnel checkout page so we | |
| 297 | + // can still resolve the funnel context on the server side. The stored value is | |
| 298 | + // only trusted when recent, to avoid reusing stale ids from older visits. | |
| 299 | + if ( wp_doing_ajax() && function_exists( 'WC' ) && is_object( WC()->session ) ) { | |
| 300 | + $session_page_id = (int) WC()->session->get( 'sellkit_current_page_id' ); | |
| 301 | + $session_time = (int) WC()->session->get( 'sellkit_current_page_id_time' ); | |
| 302 | + | |
| 303 | + if ( $session_page_id > 0 && ( time() - $session_time ) < HOUR_IN_SECONDS ) { | |
| 304 | + return $session_page_id; | |
| 305 | + } | |
| 306 | + } | |
| 307 | + | |
| 231 | 308 | $current_url = esc_url_raw( remove_query_arg( 'order-key' ) ); |
| 232 | 309 | |
| 233 | - if ( empty( strpos( $current_url, 'sellkit_step' ) ) ) { | |
| 310 | + if ( ! empty( $structure ) ) { | |
| 311 | + $current_url = self::get_base_url( $current_url ); | |
| 312 | + } | |
| 313 | + | |
| 314 | + if ( empty( strpos( $current_url, Funnel_Redirect::$step_base ) ) && ! empty( get_option( 'rewrite_rules' ) ) ) { | |
| 234 | 315 | return false; |
| 235 | 316 | } |
| 236 | 317 | |
| 237 | 318 | if ( empty( $current_url ) ) { |
| @@ -261,8 +342,25 @@ | ||
| 261 | 342 | return $page->ID; |
| 262 | 343 | } |
| 263 | 344 | |
| 264 | 345 | /** |
| 346 | + * Gets main url. | |
| 347 | + * | |
| 348 | + * @since 1.5.4 | |
| 349 | + * @param string $url Url. | |
| 350 | + * @return string | |
| 351 | + */ | |
| 352 | + private static function get_base_url( $url ) { | |
| 353 | + $parsed = wp_parse_url( $url ); | |
| 354 | + | |
| 355 | + if ( empty( $parsed['query'] ) ) { | |
| 356 | + return $url; | |
| 357 | + } | |
| 358 | + | |
| 359 | + return explode( '?', $url )[0]; | |
| 360 | + } | |
| 361 | + | |
| 362 | + /** | |
| 265 | 363 | * Customization order pages in admin area. |
| 266 | 364 | * |
| 267 | 365 | * @since 1.1.0 |
| 268 | 366 | */ |
| @@ -314,9 +412,10 @@ | ||
| 314 | 412 | $order_number = $parent_order->get_order_number(); |
| 315 | 413 | $parent_order_html = sprintf( '<p class="form-field form-field-wide" style= "margin-top: 20px;"><strong>%s: </strong>', esc_html__( 'SellKit Parent Order', 'sellkit' ) ); |
| 316 | 414 | $parent_order_html .= sprintf( '<span style= "display: block;"><a href="%1s"><strong>#%2s</strong></a></span>', get_edit_post_link( $main_order_id ), esc_attr( $order_number ) ); |
| 317 | 415 | $parent_order_html .= '</p>'; |
| 318 | - echo $parent_order_html; | |
| 416 | + | |
| 417 | + echo wp_kses_post( $parent_order_html ); | |
| 319 | 418 | } |
| 320 | 419 | |
| 321 | 420 | if ( is_numeric( $upsell_order_id ) ) { |
| 322 | 421 | $upsell_order = wc_get_order( $upsell_order_id ); |
| @@ -323,9 +422,10 @@ | ||
| 323 | 422 | $order_number = $upsell_order->get_order_number(); |
| 324 | 423 | $upsell_order_html = sprintf( '<p class="form-field form-field-wide" style= "margin-top: 20px;"><strong>%s: </strong>', esc_html__( 'SellKit Upsell Order', 'sellkit' ) ); |
| 325 | 424 | $upsell_order_html .= sprintf( '<span style= "display: block;"><a href="%1s"><strong>#%2s</strong></a></span>', get_edit_post_link( $upsell_order_id ), esc_attr( $order_number ) ); |
| 326 | 425 | $upsell_order_html .= '</p>'; |
| 327 | - echo $upsell_order_html; | |
| 426 | + | |
| 427 | + echo wp_kses_post( $upsell_order_html ); | |
| 328 | 428 | } |
| 329 | 429 | } |
| 330 | 430 | |
| 331 | 431 | /** |