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/admin/class-global-checkout.php +32 -9 1.7.52.7.0 View file →
@@ -38,28 +38,51 @@
38 38 wp_send_json_success( $global_checkout_id );
39 39 }
40 40
41 41 /**
42 - * Toggle global checkout funnel status.
42 + * Set global checkout funnel post status (activate / deactivate).
43 43 *
44 + * Expects POST `status` as the target status: `publish` or `draft`.
45 + *
44 46 * @since 1.7.4
45 47 */
46 48 public function change_status() {
47 49 check_ajax_referer( 'sellkit', 'nonce' );
48 50
49 - $status = filter_input( INPUT_POST, 'status', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
50 - $id = filter_input( INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT );
51 - $post = get_post( $id );
51 + $target_status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
52 + $post_id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : 0;
52 53
53 - $post->post_status = 'draft';
54 + if ( ! in_array( $target_status, [ 'publish', 'draft' ], true ) || ! $post_id ) {
55 + wp_send_json_error( [ 'message' => __( 'Invalid request.', 'sellkit' ) ] );
56 + }
54 57
55 - if ( 'publish' !== $status ) {
56 - $post->post_status = 'publish';
58 + $post = get_post( $post_id );
59 +
60 + if ( ! $post || 'sellkit-funnels' !== $post->post_type ) {
61 + wp_send_json_error( [ 'message' => __( 'Invalid funnel.', 'sellkit' ) ] );
57 62 }
58 63
59 - $id = wp_update_post( $post );
64 + $global_checkout_id = (int) get_option( Checkout::SELLKIT_GLOBAL_CHECKOUT_OPTION, 0 );
60 65
61 - wp_send_json_success( $post->post_status );
66 + if ( $global_checkout_id !== $post_id ) {
67 + wp_send_json_error( [ 'message' => __( 'Not the Global Checkout funnel.', 'sellkit' ) ] );
68 + }
69 +
70 + $updated = wp_update_post(
71 + [
72 + 'ID' => $post_id,
73 + 'post_status' => $target_status,
74 + ],
75 + true
76 + );
77 +
78 + if ( is_wp_error( $updated ) || ! $updated ) {
79 + wp_send_json_error( [ 'message' => __( 'Could not update status.', 'sellkit' ) ] );
80 + }
81 +
82 + $saved_status = get_post_status( $post_id );
83 +
84 + wp_send_json_success( $saved_status ? $saved_status : $target_status );
62 85 }
63 86 }
64 87
65 88 new Sellkit_Global_Checkout();