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