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/funnel/importer/ajax-handler.php +39 -8 1.7.22.7.0 View file →
@@ -3,8 +3,10 @@
3 3 namespace Sellkit\Admin\Funnel\Importer;
4 4
5 5 defined( 'ABSPATH' ) || die();
6 6
7 +use Sellkit\Global_Checkout\Checkout;
8 +
7 9 /**
8 10 * Class Ajax handler.
9 11 *
10 12 * @SuppressWarnings(PHPMD.NPathComplexity)
@@ -40,8 +42,10 @@
40 42 *
41 43 * @since 1.1.0
42 44 */
43 45 public function import_steps_data() {
46 + check_ajax_referer( 'sellkit', 'nonce' );
47 +
44 48 $nonce = sellkit_htmlspecialchars( INPUT_GET, 'nonce' );
45 49 $step_id = sellkit_htmlspecialchars( INPUT_GET, 'step_id' );
46 50 $funnel_id = sellkit_htmlspecialchars( INPUT_GET, 'funnel_id' );
47 51 $origin_node = filter_input( INPUT_GET, 'origin_node', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
@@ -49,9 +53,11 @@
49 53 $target_index = filter_input( INPUT_GET, 'target_index', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
50 54 $origin_node = isset( $origin_node ) ? $origin_node : 'none';
51 55 $target_node = ! empty( $target_node ) ? $target_node : 'none';
52 56
53 - wp_verify_nonce( $nonce, 'sellkit' );
57 + if ( ! wp_verify_nonce( $nonce, 'sellkit' ) ) {
58 + wp_send_json_error( __( 'Invalid nonce.', 'sellkit' ) );
59 + }
54 60
55 61 $data = $this->step_importer->import_from_api( $step_id );
56 62
57 63 if ( empty( $data ) || is_wp_error( $data ) ) {
@@ -64,9 +70,9 @@
64 70 $this->step_importer->run();
65 71
66 72 sleep( 3 );
67 73
68 - wp_send_json_success( esc_html__( 'The data has been imported successfully.' ) );
74 + wp_send_json_success( esc_html__( 'The data has been imported successfully.', 'sellkit' ) );
69 75 }
70 76
71 77 /**
72 78 * Gets steps.
@@ -73,12 +79,16 @@
73 79 *
74 80 * @since 1.1.0
75 81 */
76 82 public function get_steps() {
83 + check_ajax_referer( 'sellkit', 'nonce' );
84 +
77 85 $nonce = sellkit_htmlspecialchars( INPUT_GET, 'nonce' );
78 86 $type = sellkit_htmlspecialchars( INPUT_GET, 'type' );
79 87
80 - wp_verify_nonce( $nonce, 'sellkit' );
88 + if ( ! wp_verify_nonce( $nonce, 'sellkit' ) ) {
89 + wp_send_json_error( __( 'Invalid nonce.', 'sellkit' ) );
90 + }
81 91
82 92 $response = wp_remote_get( "https://templates.getsellkit.com/wp-json/sellkit/v1/steps/type={$type}", [
83 93 'timeout' => 10,
84 94 ] );
@@ -97,11 +107,15 @@
97 107 *
98 108 * @since 1.1.0
99 109 */
100 110 public function get_funnels() {
111 + check_ajax_referer( 'sellkit', 'nonce' );
112 +
101 113 $nonce = sellkit_htmlspecialchars( INPUT_GET, 'nonce' );
102 114
103 - wp_verify_nonce( $nonce, 'sellkit' );
115 + if ( ! wp_verify_nonce( $nonce, 'sellkit' ) ) {
116 + wp_send_json_error( __( 'Invalid nonce.', 'sellkit' ) );
117 + }
104 118
105 119 $response = wp_remote_get( 'https://templates.getsellkit.com/wp-json/sellkit/v1/funnels', [
106 120 'timeout' => 10,
107 121 ] );
@@ -120,12 +134,16 @@
120 134 *
121 135 * @since 1.1.0
122 136 */
123 137 public function get_funnel_data() {
138 + check_ajax_referer( 'sellkit', 'nonce' );
139 +
124 140 $nonce = sellkit_htmlspecialchars( INPUT_GET, 'nonce' );
125 141 $funnel_id = sellkit_htmlspecialchars( INPUT_GET, 'funnel_id' );
126 142
127 - wp_verify_nonce( $nonce, 'sellkit' );
143 + if ( ! wp_verify_nonce( $nonce, 'sellkit' ) ) {
144 + wp_send_json_error( __( 'Invalid nonce.', 'sellkit' ) );
145 + }
128 146
129 147 $funnel_data = $this->import_funnel_data_from_api( $funnel_id );
130 148
131 149 if ( ! empty( $funnel_data ) ) {
@@ -140,13 +158,22 @@
140 158 *
141 159 * @since 1.1.0
142 160 */
143 161 public function import_funnel() {
162 + check_ajax_referer( 'sellkit', 'nonce' );
163 +
144 164 $nonce = sellkit_htmlspecialchars( INPUT_GET, 'nonce' );
145 165 $funnel_id = sellkit_htmlspecialchars( INPUT_GET, 'funnel_id' );
166 + $page = sellkit_htmlspecialchars( INPUT_GET, 'page' );
146 167
147 - wp_verify_nonce( $nonce, 'sellkit' );
168 + if ( ! wp_verify_nonce( $nonce, 'sellkit' ) ) {
169 + wp_send_json_error( __( 'Invalid nonce.', 'sellkit' ) );
170 + }
148 171
172 + if ( 'checkout' === $page && get_post_status( get_option( Checkout::SELLKIT_GLOBAL_CHECKOUT_OPTION, 0 ) ) ) {
173 + wp_send_json_error( __( 'In order to iport a new global checkout,Please remove previous one.', 'sellkit' ) );
174 + }
175 +
149 176 $funnel_data = $this->import_funnel_data_from_api( $funnel_id );
150 177
151 178 if ( empty( $funnel_data ) ) {
152 179 wp_send_json_error( __( 'something went wrong', 'sellkit' ) );
@@ -153,8 +180,12 @@
153 180 }
154 181
155 182 $new_funnel_id = $this->import_funnel_by_data( $funnel_data );
156 183
184 + if ( 'checkout' === $page ) {
185 + update_option( Checkout::SELLKIT_GLOBAL_CHECKOUT_OPTION, $new_funnel_id );
186 + }
187 +
157 188 wp_send_json_success( [ 'funnelId' => $new_funnel_id ] );
158 189 }
159 190
160 191 /**
@@ -175,9 +206,9 @@
175 206 $step_id = $step->page_id;
176 207 $data = $steps_data->$step_id;
177 208 }
178 209
179 - if ( false === $steps_data ) {
210 + if ( false === $steps_data && property_exists( $step, 'page_id' ) ) {
180 211 $data = $this->step_importer->import_from_api( $step->page_id );
181 212 }
182 213
183 214 if ( is_wp_error( $data ) ) {
@@ -198,9 +229,9 @@
198 229 if ( ! empty( $step->bump[0]->data->products->list ) ) {
199 230 unset( $step->bump[0]->data->products->list );
200 231 }
201 232
202 - $new_step_data[ $key ] = (array) $step;
233 + $new_step_data[ $key ] = json_decode( wp_json_encode( $step ), true );
203 234 }
204 235
205 236 if ( false === $steps_data ) {
206 237 update_post_meta( $new_funnel_id, 'sellkit_steps', $new_step_data );