Skip to content

Commit d92480a

Browse files
authored
Merge pull request #363 from Ecwid/dev
Dev
2 parents afcf9d0 + 79bf18d commit d92480a

File tree

4 files changed

+66
-31
lines changed

4 files changed

+66
-31
lines changed

ecwid-shopping-cart.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,14 @@ function ecwid_get_clear_all_cache_action() {
18291829

18301830
function ecwid_clear_all_cache()
18311831
{
1832-
if ( array_key_exists( ecwid_get_clear_all_cache_action(), $_GET ) ) {
1832+
$key = ecwid_get_clear_all_cache_action();
1833+
1834+
if ( array_key_exists( $key, $_GET ) ) {
1835+
1836+
if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), $key ) ) {
1837+
return;
1838+
}
1839+
18331840
ecwid_full_cache_reset();
18341841

18351842
if ( array_key_exists( 'redirect_back', $_GET ) ) {
@@ -1896,7 +1903,8 @@ function ecwid_register_admin_styles($hook_suffix) {
18961903
wp_enqueue_script('ecwid-welcome-page-js', ECWID_PLUGIN_URL . 'js/welcome-page.js', array(), get_option('ecwid_plugin_version'));
18971904
wp_localize_script('ecwid-welcome-page-js', 'ecwidParams', array(
18981905
'registerLink' => ecwid_get_register_link(),
1899-
'isWL' => Ecwid_Config::is_wl()
1906+
'isWL' => Ecwid_Config::is_wl(),
1907+
'_ajax_nonce' => wp_create_nonce( 'ec-create-store' ),
19001908
)
19011909
);
19021910

@@ -2111,6 +2119,14 @@ function ecwid_create_store( $params = array() ) {
21112119
}
21122120

21132121
function ecwid_ajax_create_store() {
2122+
if ( ! check_ajax_referer( 'ec-create-store' ) ) {
2123+
die();
2124+
}
2125+
2126+
if ( ! current_user_can( 'manage_options' ) ) {
2127+
die();
2128+
}
2129+
21142130
$result = ecwid_create_store();
21152131
$is_store_created = is_array( $result ) && $result['response']['code'] == 200;
21162132

includes/shortcodes/class-ecwid-shortcode-product.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,21 @@ public function render_placeholder() {
6666

6767
$product = Ecwid_Product::get_without_loading( $this->_params['id'], (object) array( 'name' => '' ) );
6868

69+
if ( ! empty ( $product->price ) ) {
70+
$price = $product->price;
71+
} else {
72+
$price = 0;
73+
}
74+
6975
if ( is_array( $items ) && count( $items ) > 0 ) {
7076
foreach ( $items as $item ) {
7177
if ( array_key_exists( $item, $display_items ) ) {
7278
if ( $item == 'title' ) {
7379
$display_items[ $item ] = str_replace( '$name', $product->name, $display_items[ $item ] );
7480
}
7581

76-
if ( $item == 'price' && ! empty( $product->price ) ) {
77-
$display_items[ $item ] = str_replace( '$price', $product->price, $display_items[ $item ] );
82+
if ( $item == 'price' ) {
83+
$display_items[ $item ] = str_replace( '$price', $price, $display_items[ $item ] );
7884
}
7985

8086
if ( $this->_params['link'] == 'yes' && in_array( $item, array( 'title', 'picture' ) ) ) {

js/welcome-page.js

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
1-
jQuery(document).ready(function(){
1+
jQuery(document).ready(function () {
22

3-
jQuery('.ec-create-store-button').on('click', function() {
4-
5-
if (ecwidParams.isWL) {
6-
location.href = ecwidParams.registerLink;
7-
return;
3+
jQuery('.ec-create-store-button').on('click', function () {
4+
5+
if (ecwidParams.isWL) {
6+
location.href = ecwidParams.registerLink;
7+
return;
88
}
99

1010
jQuery('.ec-create-store-button').addClass('btn--loading');
1111
jQuery('.ec-connect-store').addClass('disabled');
1212

13-
jQuery.ajax(ajaxurl + '?action=ecwid_create_store',
14-
{
15-
success: function(result) {
16-
jQuery('.ec-create-store-note').hide();
17-
jQuery('.ec-create-store-success-note').show();
18-
19-
setTimeout(function() {
20-
location.href="admin.php?page=ec-store&ec-store-page=complete-registration";
21-
}, 1000);
22-
},
23-
error: function(error) {
24-
if( error.status == '409' ) {
25-
location.href = 'admin-post.php?action=ec_connect';
26-
} else {
27-
location.href = ecwidParams.registerLink;
28-
}
29-
}
30-
}
31-
);
32-
});
13+
var data = {
14+
action: 'ecwid_create_store',
15+
_ajax_nonce: ecwidParams._ajax_nonce
16+
};
17+
18+
jQuery.ajax({
19+
'url': ajaxurl,
20+
'data': data,
21+
'success': function (result) {
22+
jQuery('.ec-create-store-note').hide();
23+
jQuery('.ec-create-store-success-note').show();
24+
25+
setTimeout(function () {
26+
location.href = "admin.php?page=ec-store&ec-store-page=complete-registration";
27+
}, 1000);
28+
},
29+
'error': function (error) {
30+
if (error.status == '409') {
31+
location.href = 'admin-post.php?action=ec_connect';
32+
} else {
33+
location.href = ecwidParams.registerLink;
34+
}
35+
}
36+
});
37+
});
3338

3439
});

templates/admin-params.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,12 @@
6767

6868
<br />
6969
<h2>Clear plugin cache</h2>
70-
<a href="?<?php echo esc_attr( ecwid_get_clear_all_cache_action() ); ?>&redirect_back">Clear all caches</a>
70+
<?php
71+
$ec_store_clear_cache_url = add_query_arg( array(
72+
'page' => 'ec-params',
73+
ecwid_get_clear_all_cache_action() => 1,
74+
'_wpnonce' => wp_create_nonce( ecwid_get_clear_all_cache_action() ),
75+
'redirect_back' => 1,
76+
) );
77+
?>
78+
<a href="<?php echo esc_attr( $ec_store_clear_cache_url ); ?>">Clear all caches</a>

0 commit comments

Comments
 (0)