PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 2.3.0
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v2.3.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 1.8.1 All 42 releases
← All changes | includes/admin/class-steps.php +140 -18 1.3.22.3.0 View file →
@@ -5,8 +5,10 @@
5 5 /**
6 6 * Steps class.
7 7 *
8 8 * @since 1.1.0
9 + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
10 + * @SuppressWarnings(PHPMD.CyclomaticComplexity)
9 11 */
10 12 class Sellkit_Admin_Steps {
11 13
12 14 /**
@@ -57,11 +59,31 @@
57 59 add_filter( 'template_include', [ $this, 'load_page_template' ], 10 );
58 60 add_action( 'wp_ajax_sellkit_steps_get_coupons', [ $this, 'get_coupons' ] );
59 61 add_action( 'wp_loaded', [ $this, 'sellkit_steps_flush_rules' ] );
60 62 add_action( 'sellkit_after_toggle_status_sellkit-funnels', [ $this, 'update_steps_post_status' ], 10, 2 );
63 + add_action( 'sellkit_funnels_after_delete_posts_sellkit-funnels', [ $this, 'remove_steps_pages' ], 10, 1 );
61 64 }
62 65
63 66 /**
67 + * Removes steps pages.
68 + *
69 + * @since 1.5.4
70 + * @return void
71 + * @param array $post Posts.
72 + */
73 + public function remove_steps_pages( $post ) {
74 + $nodes = get_post_meta( $post['ID'], 'nodes' );
75 +
76 + if ( empty( $nodes[0] ) ) {
77 + return;
78 + }
79 +
80 + foreach ( $nodes[0] as $node ) {
81 + wp_delete_post( $node['page_id'] );
82 + }
83 + }
84 +
85 + /**
64 86 * Get default funnels.
65 87 *
66 88 * @since 1.1.0
67 89 */
@@ -69,9 +91,13 @@
69 91 return [
70 92 'sales-page' => esc_html__( 'Sales Page', 'sellkit' ),
71 93 'checkout' => esc_html__( 'Checkout', 'sellkit' ),
72 94 'thankyou' => esc_html__( 'Thank You', 'sellkit' ),
95 + 'decision' => esc_html__( 'Condition', 'sellkit' ),
73 96 'upsell' => esc_html__( 'Upsell', 'sellkit' ),
97 + 'downsell' => esc_html__( 'Downsell', 'sellkit' ),
98 + 'optin-confirmation' => esc_html__( 'Opt-in Confirmation' ),
99 + 'optin' => esc_html__( 'Opt-in', 'sellkit' ),
74 100 ];
75 101 }
76 102
77 103 /**
@@ -85,9 +111,11 @@
85 111 foreach ( $steps as $step_number => $step ) {
86 112 $step['funnel_id'] = $funnel_id;
87 113 $step['number'] = $step_number;
88 114
89 - update_post_meta( $step['page_id'], 'step_data', $step );
115 + if ( array_key_exists( 'page_id', $step ) ) {
116 + update_post_meta( $step['page_id'], 'step_data', $step );
117 + }
90 118 }
91 119 }
92 120
93 121 /**
@@ -196,12 +224,17 @@
196 224 foreach ( $products_id as $product_id ) {
197 225 $product = wc_get_product( $product_id );
198 226
199 227 if ( empty( $product ) ) {
200 - wp_send_json_error( __( 'Product does not exist', 'sellkit' ) );
201 228 continue;
202 229 }
203 230
231 + $data = $product->get_data();
232 +
233 + if ( 'trash' === $data['status'] ) {
234 + continue;
235 + }
236 +
204 237 $attributes = $product->get_attributes();
205 238 $label = $product->get_title();
206 239
207 240 if ( $product->get_type() === 'variation' ) {
@@ -226,37 +259,118 @@
226 259 * Filter step data before saving.
227 260 *
228 261 * @since 1.1.0
229 262 * @param string $post_id Post id.
263 + * @SuppressWarnings(PHPMD.NPathComplexity)
230 264 */
231 265 public function after_create_step_callback( $post_id ) {
232 - $steps = get_post_meta( $post_id, 'sellkit_steps', true );
233 - $last_step = end( $steps );
266 + $sub_action_data = sellkit_post( 'sub_action_data' );
267 + $origin_node = isset( $sub_action_data['origin_node'] ) ? $sub_action_data['origin_node'] : '';
268 + $target_node = ! empty( $sub_action_data['target_node'] ) ? $sub_action_data['target_node'] : null;
269 + $target_index = isset( $sub_action_data['target_index'] ) ? $sub_action_data['target_index'] : 0;
270 + $nodes = get_post_meta( $post_id, 'nodes', true );
271 + $last_node = end( $nodes );
234 272
235 - array_pop( $steps );
273 + array_pop( $nodes );
236 274
237 - $new_step_id = wp_insert_post( [
275 + $new_node_id = wp_insert_post( [
238 276 'post_type' => self::SELLKIT_STEP_POST_TYPE,
239 - 'post_title' => $last_step['title'],
240 - 'post_name' => sanitize_title( $last_step['title'] ),
277 + 'post_title' => $last_node['title'],
278 + 'post_name' => sanitize_title( $last_node['title'] ),
241 279 'post_status' => 'publish',
242 280 ] );
243 281
244 - $last_step['page_id'] = $new_step_id;
245 - $last_step['slug'] = get_post_field( 'post_name', $new_step_id );
282 + $current_target = [ 'nodeId' => $target_node ];
283 + $last_node['page_id'] = $new_node_id;
284 + $last_node['slug'] = get_post_field( 'post_name', $new_node_id );
285 + $last_node['targets'] = ! is_null( $target_node ) ? [ $current_target ] : [];
246 286
247 - $step_data = $last_step;
248 - $step_data['funnel_id'] = $post_id;
249 - $step_data['number'] = count( $steps );
287 + if (
288 + 'decision' === $last_node['type']['key'] && ! is_null( $target_node ) ||
289 + 'upsell' === $last_node['type']['key'] && ! is_null( $target_node ) ||
290 + 'downsell' === $last_node['type']['key'] && ! is_null( $target_node )
291 + ) {
292 + $last_node['targets'] = [
293 + $current_target,
294 + $current_target
295 + ];
296 + }
250 297
251 - update_post_meta( $new_step_id, 'step_data', $step_data );
298 + // Adding current target info the the step.
299 + $last_node['current_target_index'] = $target_index;
252 300
253 - $new_steps = array_merge( $steps, [ $last_step ] );
301 + if ( 'last-node' === $origin_node ) {
302 + $first_end_path_node_key = self::get_first_end_path_node_key( $nodes );
303 + $last_node['origin_node'] = 'last-node';
254 304
255 - update_post_meta( $post_id, 'sellkit_steps', $new_steps );
305 + if ( $first_end_path_node_key ) {
306 + unset( $nodes[ $first_end_path_node_key ]['origin_node'] );
307 + }
308 + }
309 +
310 + $node_data = $last_node;
311 + $node_data['funnel_id'] = $post_id;
312 + $node_data['number'] = count( $nodes );
313 +
314 + update_post_meta( $new_node_id, 'step_data', $node_data );// it should be updated.
315 +
316 + $old_node_keys = array_keys( $nodes );
317 + $nodes[ end( $old_node_keys ) + 1 ] = $last_node;
318 + $keys = array_keys( $nodes );
319 +
320 + if (
321 + 'last-node' !== $origin_node &&
322 + 'decision' !== $nodes[ $origin_node ]['type']['key'] &&
323 + 'upsell' !== $nodes[ $origin_node ]['type']['key'] &&
324 + 'downsell' !== $nodes[ $origin_node ]['type']['key']
325 + ) {
326 + $nodes[ $origin_node ]['targets'] = [ [ 'nodeId' => strval( end( $keys ) ) ] ];
327 + }
328 +
329 + if (
330 + 'last-node' !== $origin_node &&
331 + (
332 + 'decision' === $nodes[ $origin_node ]['type']['key'] ||
333 + 'upsell' === $nodes[ $origin_node ]['type']['key'] ||
334 + 'downsell' === $nodes[ $origin_node ]['type']['key']
335 + )
336 + ) {
337 + if ( is_array( $nodes[ $origin_node ]['targets'] ) && empty( $nodes[ $origin_node ]['targets'][0] ) ) {
338 + $nodes[ $origin_node ]['targets'][0] = ! empty( $target_node ) ? [ 'nodeId' => $target_node ] : null;
339 + }
340 +
341 + if ( is_array( $nodes[ $origin_node ]['targets'] ) && empty( $nodes[ $origin_node ]['targets'][1] ) ) {
342 + $nodes[ $origin_node ]['targets'][1] = ! empty( $target_node ) ? [ 'nodeId' => $target_node ] : null;
343 + }
344 +
345 + $nodes[ $origin_node ]['targets'][ (int) $target_index ] = [ 'nodeId' => strval( end( $old_node_keys ) + 1 ) ];
346 + }
347 +
348 + if ( '' === $origin_node && null === $target_node ) {
349 + update_post_meta( $post_id, 'nodes', [ 1 => $last_node ] );
350 + return;
351 + }
352 +
353 + update_post_meta( $post_id, 'nodes', $nodes );
256 354 }
257 355
258 356 /**
357 + * Gets last node origin node
358 + *
359 + * @param array $nodes Nodes.
360 + * @since 1.5.0
361 + */
362 + public static function get_first_end_path_node_key( $nodes ) {
363 + foreach ( $nodes as $key => $node ) {
364 + if ( ! empty( $node['origin_node'] ) && 'last-node' === $node['origin_node'] ) {
365 + return $key;
366 + }
367 + }
368 +
369 + return false;
370 + }
371 +
372 + /**
259 373 * Loading page templates.
260 374 *
261 375 * @since 1.1.0
262 376 * @param string $template Template name.
@@ -268,8 +382,12 @@
268 382 if ( 'string' !== gettype( $template ) || ! is_object( $post ) || self::SELLKIT_STEP_POST_TYPE !== $post->post_type ) {
269 383 return $template;
270 384 }
271 385
386 + if ( has_blocks( $post ) ) {
387 + return $template;
388 + }
389 +
272 390 remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );
273 391 add_filter( 'next_post_rel_link', '__return_empty_string' );
274 392 add_filter( 'previous_post_rel_link', '__return_empty_string' );
275 393
@@ -349,12 +467,12 @@
349 467 if ( get_post_field( 'post_name', $page_id ) === $slug ) {
350 468 return;
351 469 }
352 470
353 - $post_data = get_post_meta( $funnel_id, 'sellkit_steps', true );
471 + $post_data = get_post_meta( $funnel_id, 'nodes', true );
354 472 $post_data[ $selected_step ]['slug'] = get_post_field( 'post_name', $page_id );
355 473
356 - update_post_meta( $funnel_id, 'sellkit_steps', $post_data );
474 + update_post_meta( $funnel_id, 'nodes', $post_data );
357 475 }
358 476
359 477 /**
360 478 * Delete step page id.
@@ -392,8 +510,12 @@
392 510 * @param string $new_status Status.
393 511 */
394 512 public function update_steps_post_status( $funnel_id, $new_status ) {
395 513 $steps = get_post_meta( $funnel_id, 'sellkit_steps', true );
514 +
515 + if ( ! is_array( $steps ) ) {
516 + return;
517 + }
396 518
397 519 foreach ( $steps as $step ) {
398 520 if ( $step['page_id'] === $funnel_id ) {
399 521 continue;