PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 2.7.0
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v2.7.0
2.7.0 2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 All 43 releases
← All changes | includes/funnel/class.php +89 -11 1.5.82.7.0 View file →
@@ -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,
@@ -217,13 +275,17 @@
217 275 * @SuppressWarnings(PHPMD.NPathComplexity)
218 276 */
219 277 public static function get_page_id() {
220 278 $page_id = sellkit_htmlspecialchars( INPUT_POST, 'sellkit_current_page_id' );
221 - $preview = sellkit_htmlspecialchars( INPUT_GET, 'preview' );
222 279 $structure = get_option( 'permalink_structure' );
280 + $post_data = filter_input( INPUT_POST, 'post_data', FILTER_DEFAULT );
223 281
224 - if ( ! empty( $preview ) ) {
225 - 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 + }
226 288 }
227 289
228 290 if ( is_numeric( $page_id ) ) {
229 291 return $page_id;
@@ -228,8 +290,22 @@
228 290 if ( is_numeric( $page_id ) ) {
229 291 return $page_id;
230 292 }
231 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 +
232 308 $current_url = esc_url_raw( remove_query_arg( 'order-key' ) );
233 309
234 310 if ( ! empty( $structure ) ) {
235 311 $current_url = self::get_base_url( $current_url );
@@ -234,9 +310,9 @@
234 310 if ( ! empty( $structure ) ) {
235 311 $current_url = self::get_base_url( $current_url );
236 312 }
237 313
238 - if ( empty( strpos( $current_url, 'sellkit_step' ) ) ) {
314 + if ( empty( strpos( $current_url, Funnel_Redirect::$step_base ) ) && ! empty( get_option( 'rewrite_rules' ) ) ) {
239 315 return false;
240 316 }
241 317
242 318 if ( empty( $current_url ) ) {
@@ -336,9 +412,10 @@
336 412 $order_number = $parent_order->get_order_number();
337 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' ) );
338 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 ) );
339 415 $parent_order_html .= '</p>';
340 - echo $parent_order_html;
416 +
417 + echo wp_kses_post( $parent_order_html );
341 418 }
342 419
343 420 if ( is_numeric( $upsell_order_id ) ) {
344 421 $upsell_order = wc_get_order( $upsell_order_id );
@@ -345,9 +422,10 @@
345 422 $order_number = $upsell_order->get_order_number();
346 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' ) );
347 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 ) );
348 425 $upsell_order_html .= '</p>';
349 - echo $upsell_order_html;
426 +
427 + echo wp_kses_post( $upsell_order_html );
350 428 }
351 429 }
352 430
353 431 /**