Version Description
- Jul 10, 2022 =
- Improved security of handling storefront settings. Ecwid ecommerce shopping cart plugin update is recommended.
- Farmin theme improved compatibility. Even though Ecwid is compatible with every WordPress theme by design, some slight fixes and improvements are sometimes needed to make storefront look better. Thats why we are always monitoring how Ecwid pages look and behave in WordPress ecommerce themes.
Download this release
Release Info
Developer | Ecwid |
Plugin | Ecwid Ecommerce Shopping Cart |
Version | 6.10.23 |
Comparing to | |
See all releases |
Code changes from version 6.10.22 to 6.10.23
- ecwid-shopping-cart.php +8 -1
- includes/class-ecwid-admin-storefront-page.php +24 -0
- includes/class-ecwid-nav-menus.php +234 -205
- includes/importer/class-ecwid-import-page.php +92 -96
- readme.txt +6 -2
ecwid-shopping-cart.php
CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.ecwid.com?partner=wporg
|
|
5 |
Description: Ecwid is a free full-featured shopping cart. It can be easily integrated with any Wordpress blog and takes less than 5 minutes to set up.
|
6 |
Text Domain: ecwid-shopping-cart
|
7 |
Author: Ecwid Ecommerce
|
8 |
-
Version: 6.10.
|
9 |
Author URI: https://ecwid.to/ecwid-site
|
10 |
License: GPLv2 or later
|
11 |
*/
|
@@ -1223,6 +1223,10 @@ function ecwid_trim_description($description)
|
|
1223 |
add_action( 'wp_ajax_ecwid_deactivate_feedback', 'ecwid_ajax_deactivate_feedback' );
|
1224 |
function ecwid_ajax_deactivate_feedback()
|
1225 |
{
|
|
|
|
|
|
|
|
|
1226 |
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-popup-deactivate.php';
|
1227 |
$popup = new Ecwid_Popup_Deactivate();
|
1228 |
$popup->ajax_deactivate_feedback();
|
@@ -2629,6 +2633,9 @@ function get_ecwid_store_id() {
|
|
2629 |
}
|
2630 |
|
2631 |
function ecwid_sync_products() {
|
|
|
|
|
|
|
2632 |
|
2633 |
set_time_limit(3600);
|
2634 |
if (!defined('DOING_AJAX')) {
|
5 |
Description: Ecwid is a free full-featured shopping cart. It can be easily integrated with any Wordpress blog and takes less than 5 minutes to set up.
|
6 |
Text Domain: ecwid-shopping-cart
|
7 |
Author: Ecwid Ecommerce
|
8 |
+
Version: 6.10.23
|
9 |
Author URI: https://ecwid.to/ecwid-site
|
10 |
License: GPLv2 or later
|
11 |
*/
|
1223 |
add_action( 'wp_ajax_ecwid_deactivate_feedback', 'ecwid_ajax_deactivate_feedback' );
|
1224 |
function ecwid_ajax_deactivate_feedback()
|
1225 |
{
|
1226 |
+
if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
|
1227 |
+
die();
|
1228 |
+
}
|
1229 |
+
|
1230 |
require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-popup-deactivate.php';
|
1231 |
$popup = new Ecwid_Popup_Deactivate();
|
1232 |
$popup->ajax_deactivate_feedback();
|
2633 |
}
|
2634 |
|
2635 |
function ecwid_sync_products() {
|
2636 |
+
if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
|
2637 |
+
die();
|
2638 |
+
}
|
2639 |
|
2640 |
set_time_limit(3600);
|
2641 |
if (!defined('DOING_AJAX')) {
|
includes/class-ecwid-admin-storefront-page.php
CHANGED
@@ -117,6 +117,10 @@ class Ecwid_Admin_Storefront_Page {
|
|
117 |
}
|
118 |
|
119 |
public function ajax_set_status() {
|
|
|
|
|
|
|
|
|
120 |
$page_statuses = array(
|
121 |
0 => 'draft',
|
122 |
1 => 'publish',
|
@@ -151,6 +155,10 @@ class Ecwid_Admin_Storefront_Page {
|
|
151 |
}
|
152 |
|
153 |
public function ajax_set_store_on_front() {
|
|
|
|
|
|
|
|
|
154 |
$status = isset( $_GET['status'] ) ? intval( $_GET['status'] ) : false;
|
155 |
|
156 |
$store_page_id = get_option( Ecwid_Store_Page::OPTION_MAIN_STORE_PAGE_ID );
|
@@ -178,6 +186,10 @@ class Ecwid_Admin_Storefront_Page {
|
|
178 |
}
|
179 |
|
180 |
public function ajax_set_mainpage() {
|
|
|
|
|
|
|
|
|
181 |
if ( ! isset( $_GET['page'] ) ) {
|
182 |
return;
|
183 |
}
|
@@ -207,6 +219,10 @@ class Ecwid_Admin_Storefront_Page {
|
|
207 |
}
|
208 |
|
209 |
public function ajax_set_display_cart_icon() {
|
|
|
|
|
|
|
|
|
210 |
$status = isset( $_GET['status'] ) ? intval( $_GET['status'] ) : false;
|
211 |
|
212 |
if ( $status ) {
|
@@ -220,6 +236,10 @@ class Ecwid_Admin_Storefront_Page {
|
|
220 |
}
|
221 |
|
222 |
public function ajax_set_page_slug() {
|
|
|
|
|
|
|
|
|
223 |
if ( ! isset( $_GET['slug'] ) ) {
|
224 |
return;
|
225 |
}
|
@@ -262,6 +282,10 @@ class Ecwid_Admin_Storefront_Page {
|
|
262 |
}
|
263 |
|
264 |
public function ajax_create_page() {
|
|
|
|
|
|
|
|
|
265 |
if ( ! isset( $_GET['type'] ) ) {
|
266 |
return;
|
267 |
}
|
117 |
}
|
118 |
|
119 |
public function ajax_set_status() {
|
120 |
+
if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
|
121 |
+
die();
|
122 |
+
}
|
123 |
+
|
124 |
$page_statuses = array(
|
125 |
0 => 'draft',
|
126 |
1 => 'publish',
|
155 |
}
|
156 |
|
157 |
public function ajax_set_store_on_front() {
|
158 |
+
if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
|
159 |
+
die();
|
160 |
+
}
|
161 |
+
|
162 |
$status = isset( $_GET['status'] ) ? intval( $_GET['status'] ) : false;
|
163 |
|
164 |
$store_page_id = get_option( Ecwid_Store_Page::OPTION_MAIN_STORE_PAGE_ID );
|
186 |
}
|
187 |
|
188 |
public function ajax_set_mainpage() {
|
189 |
+
if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
|
190 |
+
die();
|
191 |
+
}
|
192 |
+
|
193 |
if ( ! isset( $_GET['page'] ) ) {
|
194 |
return;
|
195 |
}
|
219 |
}
|
220 |
|
221 |
public function ajax_set_display_cart_icon() {
|
222 |
+
if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
|
223 |
+
die();
|
224 |
+
}
|
225 |
+
|
226 |
$status = isset( $_GET['status'] ) ? intval( $_GET['status'] ) : false;
|
227 |
|
228 |
if ( $status ) {
|
236 |
}
|
237 |
|
238 |
public function ajax_set_page_slug() {
|
239 |
+
if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
|
240 |
+
die();
|
241 |
+
}
|
242 |
+
|
243 |
if ( ! isset( $_GET['slug'] ) ) {
|
244 |
return;
|
245 |
}
|
282 |
}
|
283 |
|
284 |
public function ajax_create_page() {
|
285 |
+
if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
|
286 |
+
die();
|
287 |
+
}
|
288 |
+
|
289 |
if ( ! isset( $_GET['type'] ) ) {
|
290 |
return;
|
291 |
}
|
includes/class-ecwid-nav-menus.php
CHANGED
@@ -2,125 +2,142 @@
|
|
2 |
|
3 |
class Ecwid_Nav_Menus {
|
4 |
|
5 |
-
|
6 |
-
|
7 |
const OPTVAL_USE_JS_API_FOR_CATS_MENU_FALSE = 'off';
|
8 |
-
const OPTVAL_USE_JS_API_FOR_CATS_MENU_AUTO
|
9 |
-
const FILTER_USE_JS_API_FOR_CATS_MENU
|
10 |
|
11 |
protected $item_types;
|
12 |
|
13 |
public function __construct() {
|
14 |
-
add_action('init', array( $this, 'init' ));
|
15 |
|
16 |
-
add_filter('wp_get_nav_menu_items', array( $this, 'process_menu_items' ));
|
17 |
|
18 |
if ( is_admin() ) {
|
19 |
-
add_filter('admin_init', array( $this, 'add_meta_box' ));
|
20 |
|
21 |
-
add_action('admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
|
22 |
} else {
|
23 |
-
add_action('wp_enqueue_scripts', array( $this, 'enqueue_frontend_assets' ) );
|
24 |
add_filter( 'nav_menu_link_attributes', array( $this, 'nav_menu_link_attributes' ), 10, 2 );
|
25 |
}
|
26 |
}
|
27 |
|
28 |
public function init() {
|
29 |
-
register_post_type(
|
|
|
30 |
array(
|
31 |
-
'labels'
|
32 |
'name' => __( 'Ecwid Menu Item', 'ecwid-shopping-cart' ),
|
33 |
),
|
34 |
-
'supports'
|
35 |
-
|
36 |
-
'public' =>
|
37 |
-
'exclude_from_search' =>
|
38 |
-
'publicly_queryable' =>
|
39 |
-
'show_ui' =>
|
40 |
-
'show_in_menu' =>
|
41 |
-
'show_in_nav_menus' =>
|
42 |
-
'show_in_admin_bar' =>
|
43 |
-
'has_archive' =>
|
44 |
)
|
45 |
);
|
46 |
}
|
47 |
|
48 |
-
public static function should_use_js_api_for_categories_menu()
|
49 |
-
{
|
50 |
$value = get_option( self::OPTION_USE_JS_API_FOR_CATS_MENU );
|
51 |
-
|
52 |
if ( $value == self::OPTVAL_USE_JS_API_FOR_CATS_MENU_TRUE ) {
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
return $value == self::OPTVAL_USE_JS_API_FOR_CATS_MENU_TRUE;
|
62 |
-
|
63 |
-
|
64 |
-
static
|
65 |
|
66 |
$locations = get_nav_menu_locations();
|
67 |
|
68 |
-
if (empty($locations))
|
|
|
|
|
69 |
|
70 |
-
foreach ($locations as $name => $menu_id) {
|
71 |
-
if ($menu_id > 0) {
|
72 |
break;
|
73 |
}
|
74 |
}
|
75 |
-
if ($menu_id == 0)
|
|
|
|
|
76 |
|
77 |
-
$existing = self::_find_existing_store_page_menu($menu_id);
|
78 |
-
if ($existing)
|
|
|
|
|
79 |
|
80 |
-
$items = wp_get_nav_menu_items($menu_id);
|
81 |
|
82 |
-
wp_update_nav_menu_item(
|
83 |
-
|
|
|
|
|
|
|
84 |
'menu-item-object' => 'ecwid-store-with-categories',
|
85 |
-
'menu-item-type'
|
86 |
-
'menu-item-status' => 'publish'
|
|
|
87 |
);
|
88 |
}
|
89 |
|
90 |
-
static
|
91 |
|
92 |
-
$options
|
93 |
$autofill = $options['auto_add'];
|
94 |
-
if (empty($autofill)) {
|
95 |
return false;
|
96 |
}
|
97 |
|
98 |
-
$store_page_id = get_option('ecwid_store_page_id');
|
99 |
-
foreach ($autofill as $menu_id) {
|
100 |
-
$items = wp_get_nav_menu_items($menu_id);
|
101 |
-
foreach ($items as $item) {
|
102 |
-
if ( $item->object == 'page' && $item->object_id == $store_page_id && time() - strtotime($item->post_date_gmt) < 60 ) {
|
103 |
-
$result = wp_update_nav_menu_item(
|
104 |
-
|
|
|
|
|
|
|
105 |
'menu-item-status' => $item->status,
|
106 |
'menu-item-object' => 'ecwid-store-with-categories',
|
107 |
-
'menu-item-type'
|
|
|
108 |
);
|
109 |
}
|
110 |
}
|
111 |
}
|
112 |
}
|
113 |
|
114 |
-
static
|
115 |
-
$items = wp_get_nav_menu_items($menu_id);
|
116 |
|
117 |
-
if (empty($items))
|
|
|
|
|
118 |
|
119 |
-
foreach ($items as $item) {
|
120 |
-
if ( $item->object == 'page' && $item->object_id == Ecwid_Store_Page::get_current_store_page_id() )
|
121 |
return $item;
|
|
|
122 |
|
123 |
-
if ($item->object == 'ecwid-store-with-categories' || $item->object == 'ecwid-store') {
|
124 |
return $item;
|
125 |
}
|
126 |
}
|
@@ -129,52 +146,61 @@ class Ecwid_Nav_Menus {
|
|
129 |
}
|
130 |
|
131 |
public function add_meta_box() {
|
132 |
-
add_meta_box('ecwid_nav_links', __('Store', 'ecwid-shopping-cart'), array( $this, 'create_menu_items'), 'nav-menus', 'side');
|
133 |
}
|
134 |
|
135 |
public function enqueue_frontend_assets() {
|
136 |
-
|
137 |
-
if ( Ecwid_Store_Page::get_current_store_page_id() != get_the_ID() && !Ecwid_Ajax_Defer_Renderer::is_enabled() ) {
|
138 |
return;
|
139 |
}
|
140 |
|
141 |
-
wp_enqueue_script( 'ecwid-menu', ECWID_PLUGIN_URL . 'js/nav-menu-frontend.js', array( 'jquery' ), get_option('ecwid_plugin_version') );
|
142 |
-
wp_localize_script(
|
143 |
-
'
|
144 |
-
|
|
|
|
|
|
|
|
|
145 |
}
|
146 |
|
147 |
public function enqueue_admin_assets() {
|
148 |
$screen = get_current_screen();
|
149 |
|
150 |
-
if ($screen->base != 'nav-menus')
|
|
|
|
|
151 |
|
152 |
-
wp_enqueue_style('ecwid-nav-menu',
|
153 |
|
154 |
-
EcwidPlatform::set('nav-menus-opened-once', null);
|
155 |
|
156 |
$first_run = false;
|
157 |
// It opens the page twice on the very first run of that page
|
158 |
-
if (EcwidPlatform::get('nav-menus-opened-once', false) < 2) {
|
159 |
-
EcwidPlatform::set('nav-menus-opened-once', EcwidPlatform::get('nav-menus-opened-once') + 1);
|
160 |
-
$first_run = EcwidPlatform::get('nav-menus-opened-once') <= 2;
|
161 |
}
|
162 |
|
163 |
-
wp_enqueue_script('ecwid-admin-menu-js', ECWID_PLUGIN_URL . 'js/nav-menu.js', array(), get_option('ecwid_plugin_version'));
|
164 |
-
wp_localize_script(
|
165 |
-
'
|
166 |
-
'
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
|
|
|
|
|
|
|
|
173 |
}
|
174 |
-
|
175 |
-
public function process_menu_items($items)
|
176 |
-
|
177 |
-
if ( is_admin() || empty($items) ) {
|
178 |
return $items;
|
179 |
}
|
180 |
|
@@ -182,83 +208,88 @@ class Ecwid_Nav_Menus {
|
|
182 |
|
183 |
$counter = 0;
|
184 |
|
185 |
-
for ( $i = 0; $i < count($items); $i++ ) {
|
186 |
-
|
187 |
-
if (!isset($items[$i])) {
|
188 |
continue;
|
189 |
}
|
190 |
-
|
191 |
-
$item = $items[$i];
|
192 |
-
$items[$i]->menu_order = $i + 1;
|
193 |
|
194 |
-
$
|
|
|
|
|
|
|
195 |
|
196 |
if ( $ecwid_menu_type && isset( $ecwid_menu_type['ecwid-page'] ) ) {
|
197 |
-
$item->url
|
198 |
$item->ecwid_page_type = $ecwid_menu_type['ecwid-page'];
|
199 |
}
|
200 |
|
201 |
-
if ($item->object == 'ecwid-store-with-categories' || $item->object == 'ecwid-store') {
|
202 |
$item->url = Ecwid_Store_Page::get_store_url();
|
203 |
}
|
204 |
-
|
205 |
-
if ($item->object == 'ecwid-store-with-categories') {
|
206 |
|
207 |
$cache_key = apply_filters( 'ecwid_nav_categories_posts_cache_key', 'nav_categories_posts' );
|
208 |
|
209 |
$posts = EcwidPlatform::cache_get( $cache_key );
|
210 |
-
|
211 |
-
if (
|
212 |
-
$posts
|
213 |
-
$api
|
214 |
$result = $api->get_categories( array( 'parent' => 0 ) );
|
215 |
-
|
216 |
if ( $result && $result->count > 0 ) {
|
217 |
-
|
218 |
-
$categories = $result->items;
|
219 |
-
usort( $categories, Ecwid_Category::usort_callback() );
|
220 |
-
|
221 |
-
foreach ($categories as $category) {
|
222 |
-
$category = Ecwid_Category::get_by_id( $category->id );
|
223 |
-
$post = new stdClass;
|
224 |
-
$post->ID = -1;
|
225 |
-
$post->post_author = '';
|
226 |
-
$post->post_date = '';
|
227 |
-
$post->post_date_gmt = '';
|
228 |
-
$post->post_password = '';
|
229 |
-
$post->post_name = '';
|
230 |
-
$post->post_type = $item->post_type;
|
231 |
-
$post->post_status = 'publish';
|
232 |
-
$post->to_ping = '';
|
233 |
-
$post->pinged = '';
|
234 |
-
$post->post_parent = 0;
|
235 |
-
$post->url = $category->get_link( Ecwid_Store_Page::get_store_url() );
|
236 |
-
$post->classes = '';
|
237 |
-
$post->type = 'post';
|
238 |
-
$post->db_id = 0;
|
239 |
-
$post->title = $category->name;
|
240 |
-
$post->target = '';
|
241 |
-
$post->object = '';
|
242 |
-
$post->attr_title = '';
|
243 |
-
$post->description = '';
|
244 |
-
$post->xfn = '';
|
245 |
-
$post->object_id = 0;
|
246 |
-
$post->ecwid_page_type = 'category';
|
247 |
-
$post->ecwid_category_id = $category->id;
|
248 |
-
|
249 |
-
$post->ecwid_name_translated = array();
|
250 |
-
if( isset($category->nameTranslated) ) {
|
251 |
-
$post->ecwid_name_translated = $category->nameTranslated;
|
252 |
-
}
|
253 |
-
|
254 |
-
$posts[] = $post;
|
255 |
-
}
|
256 |
-
|
257 |
-
EcwidPlatform::cache_set( $cache_key, $posts, DAY_IN_SECONDS );
|
258 |
-
}
|
259 |
-
}
|
260 |
|
261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
|
263 |
foreach ( $posts as $post ) {
|
264 |
$counter++;
|
@@ -266,36 +297,34 @@ class Ecwid_Nav_Menus {
|
|
266 |
array_splice( $items, $i + $counter, 0, array( $post ) );
|
267 |
}
|
268 |
$counter++;
|
269 |
-
|
270 |
-
}
|
271 |
-
|
272 |
return $items;
|
273 |
}
|
274 |
|
275 |
-
public function nav_menu_link_attributes( $attributes, $item )
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
}
|
280 |
|
281 |
if ( in_array( $item->ecwid_page_type, array( 'cart', 'account/orders' ) ) ) {
|
282 |
$attributes['rel'] = 'nofollow';
|
283 |
}
|
284 |
|
285 |
if ( Ecwid_Store_Page::get_current_store_page_id() != get_the_ID() ) {
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
$attributes['data-ecwid-page'] = $item->ecwid_page_type;
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
public function create_menu_items() {
|
300 |
$menu_links = $this->get_nav_menu_items();
|
301 |
?>
|
@@ -304,16 +333,16 @@ class Ecwid_Nav_Menus {
|
|
304 |
<ul id="ecwid-links-checklist" class="categorychecklist form-no-clear">
|
305 |
<?php
|
306 |
$i = -1;
|
307 |
-
foreach ($menu_links as $key => $value) {
|
308 |
?>
|
309 |
<li>
|
310 |
<label class="menu-item-title">
|
311 |
-
<input type="checkbox" class="menu-item-checkbox" name="menu-item[<?php echo esc_attr($i); ?>][menu-item-object-id]" value="<?php echo esc_attr($i); ?>" /> <?php echo $value['list-name']; ?>
|
312 |
</label>
|
313 |
-
<input type="hidden" class="menu-item-object" name="menu-item[<?php echo esc_attr($i); ?>][menu-item-object]" value="<?php echo $value['classes']; ?>" />
|
314 |
-
<input type="hidden" class="menu-item-type" name="menu-item[<?php echo esc_attr($i); ?>][menu-item-type]" value="ecwid_menu_item" />
|
315 |
-
<input type="hidden" class="menu-item-title" name="menu-item[<?php echo esc_attr($i); ?>][menu-item-title]" value="<?php echo esc_html($value['label'] ); ?>" />
|
316 |
-
<input type="hidden" class="menu-item-url" name="menu-item[<?php echo esc_attr($i); ?>][menu-item-url]" value="<?php echo esc_url(Ecwid_Store_Page::get_store_url() . '#!/~/' . $value['url']); ?>" />
|
317 |
</li>
|
318 |
<?php
|
319 |
$i--;
|
@@ -323,10 +352,10 @@ class Ecwid_Nav_Menus {
|
|
323 |
</div>
|
324 |
<p class="button-controls">
|
325 |
<span class="list-controls">
|
326 |
-
<a href="<?php echo admin_url('nav-menus.php?page-tab=all&selectall=1#posttype-ecwid-links'); ?>" class="select-all"><?php _e('Select All'); ?></a>
|
327 |
</span>
|
328 |
<span class="add-to-menu">
|
329 |
-
<input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-post-type-menu-item" id="submit-posttype-ecwid-links">
|
330 |
<span class="spinner"></span>
|
331 |
</span>
|
332 |
</p>
|
@@ -336,56 +365,56 @@ class Ecwid_Nav_Menus {
|
|
336 |
}
|
337 |
|
338 |
protected function get_nav_menu_items() {
|
339 |
-
if ($this->item_types != null) {
|
340 |
return $this->item_types;
|
341 |
}
|
342 |
|
343 |
$this->item_types = array(
|
344 |
-
'ecwid-cart'
|
345 |
-
'list-name' => __('Cart', 'ecwid-shopping-cart'),
|
346 |
'classes' => 'ecwid-cart',
|
347 |
'url' => 'cart',
|
348 |
-
'label' => __('Shopping Cart', 'ecwid-shopping-cart'),
|
349 |
-
'name'
|
350 |
'ecwid-page' => 'cart',
|
351 |
-
'nofollow' => true
|
352 |
),
|
353 |
-
'ecwid-product-search'
|
354 |
-
'list-name' => __('Product Search', 'ecwid-shopping-cart'),
|
355 |
'classes' => 'ecwid-product-search',
|
356 |
'url' => 'search',
|
357 |
-
'label' => __('Product Search', 'ecwid-shopping-cart'),
|
358 |
-
'name'
|
359 |
-
|
360 |
),
|
361 |
-
'ecwid-my-account'
|
362 |
-
'list-name' => __('My Account', 'ecwid-shopping-cart'),
|
363 |
'classes' => 'ecwid-my-account',
|
364 |
'url' => 'accountSettings',
|
365 |
-
'label' => __('My Account', 'ecwid-shopping-cart'),
|
366 |
-
'name'
|
367 |
'ecwid-page' => 'account/orders',
|
368 |
-
|
369 |
),
|
370 |
-
'ecwid-store'
|
371 |
-
'list-name' => __('Store', 'ecwid-shopping-cart'),
|
372 |
'classes' => 'ecwid-store',
|
373 |
'url' => '',
|
374 |
-
'label' => __('Store', 'ecwid-shopping-cart'),
|
375 |
-
'name'
|
376 |
-
'ecwid-page' => '/'
|
377 |
),
|
378 |
'ecwid-store-with-categories' => array(
|
379 |
-
'list-name' => __('Store with Categories Menu', 'ecwid-shopping-cart'),
|
380 |
'classes' => 'ecwid-store-with-categories',
|
381 |
'url' => '',
|
382 |
-
'label' => __('Store', 'ecwid-shopping-cart'),
|
383 |
-
'name'
|
384 |
-
|
385 |
-
)
|
386 |
);
|
387 |
|
388 |
return $this->item_types;
|
389 |
}
|
390 |
}
|
391 |
-
$ecwid_menus = new Ecwid_Nav_Menus();
|
2 |
|
3 |
class Ecwid_Nav_Menus {
|
4 |
|
5 |
+
const OPTION_USE_JS_API_FOR_CATS_MENU = 'ecwid_use_js_api_to_open_store_categories_pages';
|
6 |
+
const OPTVAL_USE_JS_API_FOR_CATS_MENU_TRUE = 'on';
|
7 |
const OPTVAL_USE_JS_API_FOR_CATS_MENU_FALSE = 'off';
|
8 |
+
const OPTVAL_USE_JS_API_FOR_CATS_MENU_AUTO = 'auto';
|
9 |
+
const FILTER_USE_JS_API_FOR_CATS_MENU = 'ecwid_use_js_api_for_categories_menu';
|
10 |
|
11 |
protected $item_types;
|
12 |
|
13 |
public function __construct() {
|
14 |
+
add_action( 'init', array( $this, 'init' ) );
|
15 |
|
16 |
+
add_filter( 'wp_get_nav_menu_items', array( $this, 'process_menu_items' ) );
|
17 |
|
18 |
if ( is_admin() ) {
|
19 |
+
add_filter( 'admin_init', array( $this, 'add_meta_box' ) );
|
20 |
|
21 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
|
22 |
} else {
|
23 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_assets' ) );
|
24 |
add_filter( 'nav_menu_link_attributes', array( $this, 'nav_menu_link_attributes' ), 10, 2 );
|
25 |
}
|
26 |
}
|
27 |
|
28 |
public function init() {
|
29 |
+
register_post_type(
|
30 |
+
'ecwid_menu_item',
|
31 |
array(
|
32 |
+
'labels' => array(
|
33 |
'name' => __( 'Ecwid Menu Item', 'ecwid-shopping-cart' ),
|
34 |
),
|
35 |
+
'supports' => array( 'title' ),
|
36 |
+
|
37 |
+
'public' => false,
|
38 |
+
'exclude_from_search' => true,
|
39 |
+
'publicly_queryable' => false,
|
40 |
+
'show_ui' => false,
|
41 |
+
'show_in_menu' => false,
|
42 |
+
'show_in_nav_menus' => false,
|
43 |
+
'show_in_admin_bar' => false,
|
44 |
+
'has_archive' => false,
|
45 |
)
|
46 |
);
|
47 |
}
|
48 |
|
49 |
+
public static function should_use_js_api_for_categories_menu() {
|
|
|
50 |
$value = get_option( self::OPTION_USE_JS_API_FOR_CATS_MENU );
|
51 |
+
|
52 |
if ( $value == self::OPTVAL_USE_JS_API_FOR_CATS_MENU_TRUE ) {
|
53 |
+
return true;
|
54 |
+
}
|
55 |
+
if ( $value == self::OPTVAL_USE_JS_API_FOR_CATS_MENU_FALSE ) {
|
56 |
+
return false;
|
57 |
+
}
|
58 |
+
|
59 |
+
$value = apply_filters( self::FILTER_USE_JS_API_FOR_CATS_MENU, $value );
|
60 |
+
|
61 |
return $value == self::OPTVAL_USE_JS_API_FOR_CATS_MENU_TRUE;
|
62 |
+
}
|
63 |
+
|
64 |
+
public static function add_menu_on_activate() {
|
65 |
|
66 |
$locations = get_nav_menu_locations();
|
67 |
|
68 |
+
if ( empty( $locations ) ) {
|
69 |
+
return;
|
70 |
+
}
|
71 |
|
72 |
+
foreach ( $locations as $name => $menu_id ) {
|
73 |
+
if ( $menu_id > 0 ) {
|
74 |
break;
|
75 |
}
|
76 |
}
|
77 |
+
if ( $menu_id == 0 ) {
|
78 |
+
return;
|
79 |
+
}
|
80 |
|
81 |
+
$existing = self::_find_existing_store_page_menu( $menu_id );
|
82 |
+
if ( $existing ) {
|
83 |
+
return;
|
84 |
+
}
|
85 |
|
86 |
+
$items = wp_get_nav_menu_items( $menu_id );
|
87 |
|
88 |
+
wp_update_nav_menu_item(
|
89 |
+
$menu_id,
|
90 |
+
0,
|
91 |
+
array(
|
92 |
+
'menu-item-title' => 'Store',
|
93 |
'menu-item-object' => 'ecwid-store-with-categories',
|
94 |
+
'menu-item-type' => 'ecwid_menu_item',
|
95 |
+
'menu-item-status' => 'publish',
|
96 |
+
)
|
97 |
);
|
98 |
}
|
99 |
|
100 |
+
public static function replace_auto_added_menu() {
|
101 |
|
102 |
+
$options = get_option( 'nav_menu_options' );
|
103 |
$autofill = $options['auto_add'];
|
104 |
+
if ( empty( $autofill ) ) {
|
105 |
return false;
|
106 |
}
|
107 |
|
108 |
+
$store_page_id = get_option( 'ecwid_store_page_id' );
|
109 |
+
foreach ( $autofill as $menu_id ) {
|
110 |
+
$items = wp_get_nav_menu_items( $menu_id );
|
111 |
+
foreach ( $items as $item ) {
|
112 |
+
if ( $item->object == 'page' && $item->object_id == $store_page_id && time() - strtotime( $item->post_date_gmt ) < 60 ) {
|
113 |
+
$result = wp_update_nav_menu_item(
|
114 |
+
$menu_id,
|
115 |
+
$item->db_id,
|
116 |
+
array(
|
117 |
+
'menu-item-title' => $item->title,
|
118 |
'menu-item-status' => $item->status,
|
119 |
'menu-item-object' => 'ecwid-store-with-categories',
|
120 |
+
'menu-item-type' => 'ecwid_menu_item',
|
121 |
+
)
|
122 |
);
|
123 |
}
|
124 |
}
|
125 |
}
|
126 |
}
|
127 |
|
128 |
+
protected static function _find_existing_store_page_menu( $menu_id ) {
|
129 |
+
$items = wp_get_nav_menu_items( $menu_id );
|
130 |
|
131 |
+
if ( empty( $items ) ) {
|
132 |
+
return null;
|
133 |
+
}
|
134 |
|
135 |
+
foreach ( $items as $item ) {
|
136 |
+
if ( $item->object == 'page' && $item->object_id == Ecwid_Store_Page::get_current_store_page_id() ) {
|
137 |
return $item;
|
138 |
+
}
|
139 |
|
140 |
+
if ( $item->object == 'ecwid-store-with-categories' || $item->object == 'ecwid-store' ) {
|
141 |
return $item;
|
142 |
}
|
143 |
}
|
146 |
}
|
147 |
|
148 |
public function add_meta_box() {
|
149 |
+
add_meta_box( 'ecwid_nav_links', __( 'Store', 'ecwid-shopping-cart' ), array( $this, 'create_menu_items' ), 'nav-menus', 'side' );
|
150 |
}
|
151 |
|
152 |
public function enqueue_frontend_assets() {
|
153 |
+
|
154 |
+
if ( Ecwid_Store_Page::get_current_store_page_id() != get_the_ID() && ! Ecwid_Ajax_Defer_Renderer::is_enabled() ) {
|
155 |
return;
|
156 |
}
|
157 |
|
158 |
+
wp_enqueue_script( 'ecwid-menu', ECWID_PLUGIN_URL . 'js/nav-menu-frontend.js', array( 'jquery' ), get_option( 'ecwid_plugin_version' ) );
|
159 |
+
wp_localize_script(
|
160 |
+
'ecwid-menu',
|
161 |
+
'ecwid_menu_data',
|
162 |
+
array(
|
163 |
+
'items' => $this->get_nav_menu_items(),
|
164 |
+
)
|
165 |
+
);
|
166 |
}
|
167 |
|
168 |
public function enqueue_admin_assets() {
|
169 |
$screen = get_current_screen();
|
170 |
|
171 |
+
if ( $screen->base != 'nav-menus' ) {
|
172 |
+
return;
|
173 |
+
}
|
174 |
|
175 |
+
wp_enqueue_style( 'ecwid-nav-menu', ECWID_PLUGIN_URL . 'css/nav-menu.css', array(), get_option( 'ecwid_plugin_version' ) );
|
176 |
|
177 |
+
EcwidPlatform::set( 'nav-menus-opened-once', null );
|
178 |
|
179 |
$first_run = false;
|
180 |
// It opens the page twice on the very first run of that page
|
181 |
+
if ( EcwidPlatform::get( 'nav-menus-opened-once', false ) < 2 ) {
|
182 |
+
EcwidPlatform::set( 'nav-menus-opened-once', EcwidPlatform::get( 'nav-menus-opened-once' ) + 1 );
|
183 |
+
$first_run = EcwidPlatform::get( 'nav-menus-opened-once' ) <= 2;
|
184 |
}
|
185 |
|
186 |
+
wp_enqueue_script( 'ecwid-admin-menu-js', ECWID_PLUGIN_URL . 'js/nav-menu.js', array(), get_option( 'ecwid_plugin_version' ) );
|
187 |
+
wp_localize_script(
|
188 |
+
'ecwid-admin-menu-js',
|
189 |
+
'ecwid_nav_menu_params',
|
190 |
+
array(
|
191 |
+
'store_page' => __( 'Store Page', 'ecwid-shopping-cart' ),
|
192 |
+
'reset_cats_cache' => __( 'Refresh categories list', 'ecwid-shopping-cart' ),
|
193 |
+
'cache_updated' => __( 'Done', 'ecwid-shopping-cart' ),
|
194 |
+
'reset_cache_message' => __( 'The store top-level categories are automatically added to this drop-down menu', 'ecwid-shopping-cart' ),
|
195 |
+
'first_run' => $first_run,
|
196 |
+
'register_link' => ecwid_get_register_link(),
|
197 |
+
'items' => $this->get_nav_menu_items(),
|
198 |
+
)
|
199 |
+
);
|
200 |
}
|
201 |
+
|
202 |
+
public function process_menu_items( $items ) {
|
203 |
+
if ( is_admin() || empty( $items ) ) {
|
|
|
204 |
return $items;
|
205 |
}
|
206 |
|
208 |
|
209 |
$counter = 0;
|
210 |
|
211 |
+
for ( $i = 0; $i < count( $items ); $i++ ) {
|
212 |
+
|
213 |
+
if ( ! isset( $items[ $i ] ) ) {
|
214 |
continue;
|
215 |
}
|
|
|
|
|
|
|
216 |
|
217 |
+
$item = $items[ $i ];
|
218 |
+
$items[ $i ]->menu_order = $i + 1;
|
219 |
+
|
220 |
+
$ecwid_menu_type = isset( $types[ $item->object ] ) ? $types[ $item->object ] : null;
|
221 |
|
222 |
if ( $ecwid_menu_type && isset( $ecwid_menu_type['ecwid-page'] ) ) {
|
223 |
+
$item->url = Ecwid_Store_Page::get_menu_item_url( $ecwid_menu_type );
|
224 |
$item->ecwid_page_type = $ecwid_menu_type['ecwid-page'];
|
225 |
}
|
226 |
|
227 |
+
if ( $item->object == 'ecwid-store-with-categories' || $item->object == 'ecwid-store' ) {
|
228 |
$item->url = Ecwid_Store_Page::get_store_url();
|
229 |
}
|
230 |
+
|
231 |
+
if ( $item->object == 'ecwid-store-with-categories' ) {
|
232 |
|
233 |
$cache_key = apply_filters( 'ecwid_nav_categories_posts_cache_key', 'nav_categories_posts' );
|
234 |
|
235 |
$posts = EcwidPlatform::cache_get( $cache_key );
|
236 |
+
|
237 |
+
if ( ! $posts ) {
|
238 |
+
$posts = array();
|
239 |
+
$api = new Ecwid_Api_V3();
|
240 |
$result = $api->get_categories( array( 'parent' => 0 ) );
|
241 |
+
|
242 |
if ( $result && $result->count > 0 ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
|
244 |
+
$categories = $result->items;
|
245 |
+
usort( $categories, Ecwid_Category::usort_callback() );
|
246 |
+
|
247 |
+
foreach ( $categories as $category ) {
|
248 |
+
$category = Ecwid_Category::get_by_id( $category->id );
|
249 |
+
|
250 |
+
$post = new stdClass();
|
251 |
+
$post->ID = -1;
|
252 |
+
$post->post_author = '';
|
253 |
+
$post->post_date = '';
|
254 |
+
$post->post_date_gmt = '';
|
255 |
+
$post->post_password = '';
|
256 |
+
$post->post_name = '';
|
257 |
+
$post->post_type = $item->post_type;
|
258 |
+
$post->post_status = 'publish';
|
259 |
+
$post->to_ping = '';
|
260 |
+
$post->pinged = '';
|
261 |
+
$post->post_parent = 0;
|
262 |
+
$post->url = $category->get_link( Ecwid_Store_Page::get_store_url() );
|
263 |
+
$post->classes = '';
|
264 |
+
$post->type = 'post';
|
265 |
+
$post->db_id = 0;
|
266 |
+
$post->title = $category->name;
|
267 |
+
$post->target = '';
|
268 |
+
$post->object = '';
|
269 |
+
$post->attr_title = '';
|
270 |
+
$post->description = '';
|
271 |
+
$post->xfn = '';
|
272 |
+
$post->object_id = 0;
|
273 |
+
$post->filter = 'raw';
|
274 |
+
$post->ecwid_page_type = 'category';
|
275 |
+
$post->ecwid_category_id = $category->id;
|
276 |
+
|
277 |
+
$post->ecwid_name_translated = array();
|
278 |
+
if ( isset( $category->nameTranslated ) ) {
|
279 |
+
$post->ecwid_name_translated = $category->nameTranslated;
|
280 |
+
}
|
281 |
+
|
282 |
+
$post = new WP_Post( $post );
|
283 |
+
wp_cache_add( $post->ID, $post, 'posts' );
|
284 |
+
|
285 |
+
$posts[] = $post;
|
286 |
+
}//end foreach
|
287 |
+
|
288 |
+
EcwidPlatform::cache_set( $cache_key, $posts, DAY_IN_SECONDS );
|
289 |
+
}//end if
|
290 |
+
}//end if
|
291 |
+
|
292 |
+
$posts = apply_filters( 'ecwid_nav_categories_posts', $posts );
|
293 |
|
294 |
foreach ( $posts as $post ) {
|
295 |
$counter++;
|
297 |
array_splice( $items, $i + $counter, 0, array( $post ) );
|
298 |
}
|
299 |
$counter++;
|
300 |
+
}//end if
|
301 |
+
}//end for
|
302 |
+
|
303 |
return $items;
|
304 |
}
|
305 |
|
306 |
+
public function nav_menu_link_attributes( $attributes, $item ) {
|
307 |
+
if ( ! isset( $item->ecwid_page_type ) ) {
|
308 |
+
return $attributes;
|
309 |
+
}
|
|
|
310 |
|
311 |
if ( in_array( $item->ecwid_page_type, array( 'cart', 'account/orders' ) ) ) {
|
312 |
$attributes['rel'] = 'nofollow';
|
313 |
}
|
314 |
|
315 |
if ( Ecwid_Store_Page::get_current_store_page_id() != get_the_ID() ) {
|
316 |
+
return $attributes;
|
317 |
+
}
|
318 |
+
|
319 |
$attributes['data-ecwid-page'] = $item->ecwid_page_type;
|
320 |
+
|
321 |
+
if ( $item->ecwid_page_type == 'category' ) {
|
322 |
+
$attributes['data-ecwid-category-id'] = $item->ecwid_category_id;
|
323 |
+
}
|
324 |
+
|
325 |
+
return $attributes;
|
326 |
+
}
|
327 |
+
|
|
|
328 |
public function create_menu_items() {
|
329 |
$menu_links = $this->get_nav_menu_items();
|
330 |
?>
|
333 |
<ul id="ecwid-links-checklist" class="categorychecklist form-no-clear">
|
334 |
<?php
|
335 |
$i = -1;
|
336 |
+
foreach ( $menu_links as $key => $value ) {
|
337 |
?>
|
338 |
<li>
|
339 |
<label class="menu-item-title">
|
340 |
+
<input type="checkbox" class="menu-item-checkbox" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-object-id]" value="<?php echo esc_attr( $i ); ?>" /> <?php echo $value['list-name']; ?>
|
341 |
</label>
|
342 |
+
<input type="hidden" class="menu-item-object" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-object]" value="<?php echo $value['classes']; ?>" />
|
343 |
+
<input type="hidden" class="menu-item-type" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-type]" value="ecwid_menu_item" />
|
344 |
+
<input type="hidden" class="menu-item-title" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-title]" value="<?php echo esc_html( $value['label'] ); ?>" />
|
345 |
+
<input type="hidden" class="menu-item-url" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-url]" value="<?php echo esc_url( Ecwid_Store_Page::get_store_url() . '#!/~/' . $value['url'] ); ?>" />
|
346 |
</li>
|
347 |
<?php
|
348 |
$i--;
|
352 |
</div>
|
353 |
<p class="button-controls">
|
354 |
<span class="list-controls">
|
355 |
+
<a href="<?php echo admin_url( 'nav-menus.php?page-tab=all&selectall=1#posttype-ecwid-links' ); ?>" class="select-all"><?php _e( 'Select All' ); ?></a>
|
356 |
</span>
|
357 |
<span class="add-to-menu">
|
358 |
+
<input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-post-type-menu-item" id="submit-posttype-ecwid-links">
|
359 |
<span class="spinner"></span>
|
360 |
</span>
|
361 |
</p>
|
365 |
}
|
366 |
|
367 |
protected function get_nav_menu_items() {
|
368 |
+
if ( $this->item_types != null ) {
|
369 |
return $this->item_types;
|
370 |
}
|
371 |
|
372 |
$this->item_types = array(
|
373 |
+
'ecwid-cart' => array(
|
374 |
+
'list-name' => __( 'Cart', 'ecwid-shopping-cart' ),
|
375 |
'classes' => 'ecwid-cart',
|
376 |
'url' => 'cart',
|
377 |
+
'label' => __( 'Shopping Cart', 'ecwid-shopping-cart' ),
|
378 |
+
'name' => 'cart',
|
379 |
'ecwid-page' => 'cart',
|
380 |
+
'nofollow' => true,
|
381 |
),
|
382 |
+
'ecwid-product-search' => array(
|
383 |
+
'list-name' => __( 'Product Search', 'ecwid-shopping-cart' ),
|
384 |
'classes' => 'ecwid-product-search',
|
385 |
'url' => 'search',
|
386 |
+
'label' => __( 'Product Search', 'ecwid-shopping-cart' ),
|
387 |
+
'name' => 'search',
|
388 |
+
'ecwid-page' => 'search',
|
389 |
),
|
390 |
+
'ecwid-my-account' => array(
|
391 |
+
'list-name' => __( 'My Account', 'ecwid-shopping-cart' ),
|
392 |
'classes' => 'ecwid-my-account',
|
393 |
'url' => 'accountSettings',
|
394 |
+
'label' => __( 'My Account', 'ecwid-shopping-cart' ),
|
395 |
+
'name' => 'account',
|
396 |
'ecwid-page' => 'account/orders',
|
397 |
+
'nofollow' => true,
|
398 |
),
|
399 |
+
'ecwid-store' => array(
|
400 |
+
'list-name' => __( 'Store', 'ecwid-shopping-cart' ),
|
401 |
'classes' => 'ecwid-store',
|
402 |
'url' => '',
|
403 |
+
'label' => __( 'Store', 'ecwid-shopping-cart' ),
|
404 |
+
'name' => 'store',
|
405 |
+
'ecwid-page' => '/',
|
406 |
),
|
407 |
'ecwid-store-with-categories' => array(
|
408 |
+
'list-name' => __( 'Store with Categories Menu', 'ecwid-shopping-cart' ),
|
409 |
'classes' => 'ecwid-store-with-categories',
|
410 |
'url' => '',
|
411 |
+
'label' => __( 'Store', 'ecwid-shopping-cart' ),
|
412 |
+
'name' => 'store-with-categories',
|
413 |
+
'ecwid-page' => '/',
|
414 |
+
),
|
415 |
);
|
416 |
|
417 |
return $this->item_types;
|
418 |
}
|
419 |
}
|
420 |
+
$ecwid_menus = new Ecwid_Nav_Menus();
|
includes/importer/class-ecwid-import-page.php
CHANGED
@@ -2,41 +2,38 @@
|
|
2 |
|
3 |
require_once __DIR__ . '/class-ecwid-importer.php';
|
4 |
|
5 |
-
class Ecwid_Import_Page
|
6 |
-
|
7 |
-
const PAGE_SLUG
|
8 |
const PAGE_SLUG_WOO = 'ec-store-import-woocommerce';
|
9 |
-
|
10 |
-
const AJAX_ACTION_CHECK_IMPORT
|
11 |
const AJAX_ACTION_DO_WOO_IMPORT = 'ec-store-do-woo-import';
|
12 |
const ACTION_GET_WOO_IMPORT_LOG = 'ec-store-get-woo-import-log';
|
13 |
-
|
14 |
const PARAM_FROM_IMPORT_ONBOARDING = 'from-woo-import-message';
|
15 |
-
|
16 |
-
public function init_actions()
|
17 |
-
{
|
18 |
add_action( 'admin_menu', array( $this, 'build_menu' ) );
|
19 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
20 |
add_action( 'current_screen', array( $this, 'process_woo_onboarding_redirect' ) );
|
21 |
-
add_action( 'wp_ajax_' . self::AJAX_ACTION_CHECK_IMPORT, array( $this, 'check_import') );
|
22 |
-
add_action( 'wp_ajax_' . self::AJAX_ACTION_DO_WOO_IMPORT, array( $this, 'do_woo_import') );
|
23 |
-
add_action( 'current_screen', array( $this, 'do_reconnect') );
|
24 |
-
add_action( 'admin_post_' . self::ACTION_GET_WOO_IMPORT_LOG, array( $this, 'get_woo_import_log') );
|
25 |
-
}
|
26 |
-
|
27 |
-
public function process_woo_onboarding_redirect()
|
28 |
-
|
29 |
-
if ( strrpos( strrev( get_current_screen()->base), strrev( self::PAGE_SLUG_WOO) ) !== 0 ) {
|
30 |
return;
|
31 |
}
|
32 |
|
33 |
-
if ( isset($_GET[self::PARAM_FROM_IMPORT_ONBOARDING]) ) {
|
34 |
Ecwid_Message_Manager::disable_message( Ecwid_Message_Manager::MSG_WOO_IMPORT_ONBOARDING );
|
35 |
}
|
36 |
}
|
37 |
-
|
38 |
-
public function build_menu()
|
39 |
-
{
|
40 |
add_submenu_page(
|
41 |
'',
|
42 |
__( 'Import', 'ecwid-shopping-cart' ),
|
@@ -45,8 +42,8 @@ class Ecwid_Import_Page
|
|
45 |
self::PAGE_SLUG,
|
46 |
array( $this, 'do_page' )
|
47 |
);
|
48 |
-
|
49 |
-
if ( $this->_need_to_show_woo() ) {
|
50 |
add_submenu_page(
|
51 |
self::PAGE_SLUG,
|
52 |
sprintf( __( 'Import your products from WooCommerce to %s', 'ecwid-shopping-cart' ), Ecwid_Config::get_brand() ),
|
@@ -57,126 +54,125 @@ class Ecwid_Import_Page
|
|
57 |
);
|
58 |
}
|
59 |
}
|
60 |
-
|
61 |
-
public function enqueue_scripts()
|
62 |
-
|
63 |
-
wp_enqueue_style( 'ecwid-importer', ECWID_PLUGIN_URL . 'css/importer.css' );
|
64 |
wp_enqueue_script( 'ecwid-importer', ECWID_PLUGIN_URL . 'js/importer.js' );
|
65 |
-
wp_localize_script(
|
66 |
-
'
|
67 |
-
'
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
74 |
return;
|
75 |
}
|
76 |
-
|
77 |
-
$data
|
78 |
$token_ok = $this->_is_token_ok();
|
79 |
-
if (
|
80 |
$data['has_good_token'] = false;
|
81 |
} else {
|
82 |
$data['has_good_token'] = true;
|
83 |
-
$data
|
84 |
}
|
85 |
-
|
86 |
echo json_encode( $data );
|
87 |
-
|
88 |
die();
|
89 |
}
|
90 |
-
|
91 |
// Returns url for the page that should be displayed on clicking the "Import from woo" button in woo import onboarding message
|
92 |
public static function get_woo_page_url_from_message() {
|
93 |
return 'admin.php?page=' . self::PAGE_SLUG_WOO . '&' . self::PARAM_FROM_IMPORT_ONBOARDING . '=1';
|
94 |
}
|
95 |
-
|
96 |
-
protected function _is_token_ok()
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
return $oauth->has_scope( 'create_catalog' ) && $oauth->has_scope( 'update_catalog' );
|
101 |
}
|
102 |
-
|
103 |
-
public function do_woo_import()
|
104 |
-
|
|
|
|
|
|
|
105 |
$importer = new Ecwid_Importer();
|
106 |
-
|
107 |
-
if (
|
108 |
-
$settings = isset($_REQUEST['settings']) ? map_deep( wp_unslash( $_REQUEST['settings'] ), 'sanitize_text_field' ) : array();
|
109 |
$importer->initiate( $settings );
|
110 |
}
|
111 |
-
|
112 |
$result = $importer->proceed();
|
113 |
-
|
114 |
echo json_encode( $result );
|
115 |
-
|
116 |
die();
|
117 |
}
|
118 |
-
|
119 |
protected function _get_billing_page_url() {
|
120 |
return 'admin.php?page=' . Ecwid_Admin::ADMIN_SLUG . '&ec-page=billing';
|
121 |
}
|
122 |
-
|
123 |
-
public function do_reconnect()
|
124 |
-
|
125 |
-
if ( strrpos( strrev( get_current_screen()->base), strrev( self::PAGE_SLUG_WOO) ) !== 0 ) {
|
126 |
return;
|
127 |
}
|
128 |
-
|
129 |
-
if ( !isset( $_GET['action'] ) || $_GET['action'] != 'reconnect' ) {
|
130 |
return;
|
131 |
}
|
132 |
-
|
133 |
$url = $this->_get_woo_url() . '#start';
|
134 |
-
|
135 |
$params = array(
|
136 |
'delete-demo',
|
137 |
-
'update-by-sku'
|
138 |
);
|
139 |
-
|
140 |
foreach ( $params as $param ) {
|
141 |
-
if ( isset( $_GET[$param] ) ) {
|
142 |
$url .= '&' . $param . '=true';
|
143 |
}
|
144 |
}
|
145 |
|
146 |
wp_safe_redirect(
|
147 |
-
'admin.php?page=' .
|
148 |
. '&reconnect&return-url=' . rawurlencode( $url )
|
149 |
. '&scope=create_catalog+update_catalog&do_reconnect=1'
|
150 |
);
|
151 |
}
|
152 |
-
|
153 |
-
protected function _get_woo_url()
|
154 |
-
|
155 |
-
return 'admin.php?page=' . self::PAGE_SLUG_WOO;
|
156 |
}
|
157 |
|
158 |
-
protected function _need_to_show_woo()
|
159 |
-
{
|
160 |
return is_plugin_active( 'woocommerce/woocommerce.php' ) && wp_count_posts( 'product' )->publish > 0;
|
161 |
}
|
162 |
-
|
163 |
-
public function do_page()
|
164 |
-
|
165 |
-
require_once ECWID_IMPORTER_TEMPLATES_DIR . '/landing.tpl.php';
|
166 |
}
|
167 |
-
|
168 |
-
public function do_woo_page()
|
169 |
-
|
170 |
-
$import_data = Ecwid_Import::gather_import_data();
|
171 |
echo Ecwid_Admin_UI_Framework::print_fix_js();
|
172 |
-
|
173 |
require_once ECWID_IMPORTER_TEMPLATES_DIR . '/woo-main.tpl.php';
|
174 |
}
|
175 |
-
|
176 |
protected function _get_products_categories_message( $products, $categories ) {
|
177 |
if ( ecwid_is_paid_account() ) {
|
178 |
-
return sprintf(
|
179 |
-
__( '%s products and %s categories', 'ecwid-shopping-cart' ),
|
180 |
$products,
|
181 |
$categories
|
182 |
);
|
@@ -189,25 +185,25 @@ class Ecwid_Import_Page
|
|
189 |
}
|
190 |
|
191 |
public function get_woo_import_log() {
|
192 |
-
if (!current_user_can('manage_options')) {
|
193 |
return;
|
194 |
}
|
195 |
|
196 |
-
header(
|
197 |
|
198 |
$error_log = get_option( Ecwid_Importer::OPTION_ERROR_LOG, false );
|
199 |
|
200 |
-
if(
|
201 |
die();
|
202 |
}
|
203 |
|
204 |
-
foreach ($error_log as $type => $messages) {
|
205 |
echo sprintf( "ERROR TYPE: %s\r\n", $type );
|
206 |
|
207 |
-
foreach ($messages as $message => $data) {
|
208 |
echo "*** \r\n";
|
209 |
echo $message . "\r\n";
|
210 |
-
echo 'Data: ' . var_export($data, true) . "\r\n";
|
211 |
}
|
212 |
|
213 |
echo "\r\n";
|
@@ -215,4 +211,4 @@ class Ecwid_Import_Page
|
|
215 |
|
216 |
die();
|
217 |
}
|
218 |
-
}
|
2 |
|
3 |
require_once __DIR__ . '/class-ecwid-importer.php';
|
4 |
|
5 |
+
class Ecwid_Import_Page {
|
6 |
+
|
7 |
+
const PAGE_SLUG = 'ec-store-import';
|
8 |
const PAGE_SLUG_WOO = 'ec-store-import-woocommerce';
|
9 |
+
|
10 |
+
const AJAX_ACTION_CHECK_IMPORT = 'ec-store-check-import';
|
11 |
const AJAX_ACTION_DO_WOO_IMPORT = 'ec-store-do-woo-import';
|
12 |
const ACTION_GET_WOO_IMPORT_LOG = 'ec-store-get-woo-import-log';
|
13 |
+
|
14 |
const PARAM_FROM_IMPORT_ONBOARDING = 'from-woo-import-message';
|
15 |
+
|
16 |
+
public function init_actions() {
|
|
|
17 |
add_action( 'admin_menu', array( $this, 'build_menu' ) );
|
18 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
19 |
add_action( 'current_screen', array( $this, 'process_woo_onboarding_redirect' ) );
|
20 |
+
add_action( 'wp_ajax_' . self::AJAX_ACTION_CHECK_IMPORT, array( $this, 'check_import' ) );
|
21 |
+
add_action( 'wp_ajax_' . self::AJAX_ACTION_DO_WOO_IMPORT, array( $this, 'do_woo_import' ) );
|
22 |
+
add_action( 'current_screen', array( $this, 'do_reconnect' ) );
|
23 |
+
add_action( 'admin_post_' . self::ACTION_GET_WOO_IMPORT_LOG, array( $this, 'get_woo_import_log' ) );
|
24 |
+
}
|
25 |
+
|
26 |
+
public function process_woo_onboarding_redirect() {
|
27 |
+
if ( strrpos( strrev( get_current_screen()->base ), strrev( self::PAGE_SLUG_WOO ) ) !== 0 ) {
|
|
|
28 |
return;
|
29 |
}
|
30 |
|
31 |
+
if ( isset( $_GET[ self::PARAM_FROM_IMPORT_ONBOARDING ] ) ) {
|
32 |
Ecwid_Message_Manager::disable_message( Ecwid_Message_Manager::MSG_WOO_IMPORT_ONBOARDING );
|
33 |
}
|
34 |
}
|
35 |
+
|
36 |
+
public function build_menu() {
|
|
|
37 |
add_submenu_page(
|
38 |
'',
|
39 |
__( 'Import', 'ecwid-shopping-cart' ),
|
42 |
self::PAGE_SLUG,
|
43 |
array( $this, 'do_page' )
|
44 |
);
|
45 |
+
|
46 |
+
if ( $this->_need_to_show_woo() ) {
|
47 |
add_submenu_page(
|
48 |
self::PAGE_SLUG,
|
49 |
sprintf( __( 'Import your products from WooCommerce to %s', 'ecwid-shopping-cart' ), Ecwid_Config::get_brand() ),
|
54 |
);
|
55 |
}
|
56 |
}
|
57 |
+
|
58 |
+
public function enqueue_scripts() {
|
59 |
+
wp_enqueue_style( 'ecwid-importer', ECWID_PLUGIN_URL . 'css/importer.css' );
|
|
|
60 |
wp_enqueue_script( 'ecwid-importer', ECWID_PLUGIN_URL . 'js/importer.js' );
|
61 |
+
wp_localize_script(
|
62 |
+
'ecwid-importer',
|
63 |
+
'ecwid_importer',
|
64 |
+
array(
|
65 |
+
'check_token_action' => self::AJAX_ACTION_CHECK_IMPORT,
|
66 |
+
'do_woo_import_action' => self::AJAX_ACTION_DO_WOO_IMPORT,
|
67 |
+
)
|
68 |
+
);
|
69 |
+
}
|
70 |
+
|
71 |
+
public function check_import() {
|
72 |
+
if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
|
73 |
return;
|
74 |
}
|
75 |
+
|
76 |
+
$data = array();
|
77 |
$token_ok = $this->_is_token_ok();
|
78 |
+
if ( ! $token_ok ) {
|
79 |
$data['has_good_token'] = false;
|
80 |
} else {
|
81 |
$data['has_good_token'] = true;
|
82 |
+
$data = Ecwid_Import::gather_import_data();
|
83 |
}
|
84 |
+
|
85 |
echo json_encode( $data );
|
86 |
+
|
87 |
die();
|
88 |
}
|
89 |
+
|
90 |
// Returns url for the page that should be displayed on clicking the "Import from woo" button in woo import onboarding message
|
91 |
public static function get_woo_page_url_from_message() {
|
92 |
return 'admin.php?page=' . self::PAGE_SLUG_WOO . '&' . self::PARAM_FROM_IMPORT_ONBOARDING . '=1';
|
93 |
}
|
94 |
+
|
95 |
+
protected function _is_token_ok() {
|
96 |
+
$oauth = new Ecwid_OAuth();
|
97 |
+
|
|
|
98 |
return $oauth->has_scope( 'create_catalog' ) && $oauth->has_scope( 'update_catalog' );
|
99 |
}
|
100 |
+
|
101 |
+
public function do_woo_import() {
|
102 |
+
if ( ! current_user_can( Ecwid_Admin::get_capability() ) ) {
|
103 |
+
return;
|
104 |
+
}
|
105 |
+
|
106 |
$importer = new Ecwid_Importer();
|
107 |
+
|
108 |
+
if ( ! $importer->has_begun() || isset( $_REQUEST['reset'] ) ) {
|
109 |
+
$settings = isset( $_REQUEST['settings'] ) ? map_deep( wp_unslash( $_REQUEST['settings'] ), 'sanitize_text_field' ) : array();
|
110 |
$importer->initiate( $settings );
|
111 |
}
|
112 |
+
|
113 |
$result = $importer->proceed();
|
114 |
+
|
115 |
echo json_encode( $result );
|
116 |
+
|
117 |
die();
|
118 |
}
|
119 |
+
|
120 |
protected function _get_billing_page_url() {
|
121 |
return 'admin.php?page=' . Ecwid_Admin::ADMIN_SLUG . '&ec-page=billing';
|
122 |
}
|
123 |
+
|
124 |
+
public function do_reconnect() {
|
125 |
+
if ( strrpos( strrev( get_current_screen()->base ), strrev( self::PAGE_SLUG_WOO ) ) !== 0 ) {
|
|
|
126 |
return;
|
127 |
}
|
128 |
+
|
129 |
+
if ( ! isset( $_GET['action'] ) || $_GET['action'] != 'reconnect' ) {
|
130 |
return;
|
131 |
}
|
132 |
+
|
133 |
$url = $this->_get_woo_url() . '#start';
|
134 |
+
|
135 |
$params = array(
|
136 |
'delete-demo',
|
137 |
+
'update-by-sku',
|
138 |
);
|
139 |
+
|
140 |
foreach ( $params as $param ) {
|
141 |
+
if ( isset( $_GET[ $param ] ) ) {
|
142 |
$url .= '&' . $param . '=true';
|
143 |
}
|
144 |
}
|
145 |
|
146 |
wp_safe_redirect(
|
147 |
+
'admin.php?page=' . Ecwid_Admin::ADMIN_SLUG
|
148 |
. '&reconnect&return-url=' . rawurlencode( $url )
|
149 |
. '&scope=create_catalog+update_catalog&do_reconnect=1'
|
150 |
);
|
151 |
}
|
152 |
+
|
153 |
+
protected function _get_woo_url() {
|
154 |
+
return 'admin.php?page=' . self::PAGE_SLUG_WOO;
|
|
|
155 |
}
|
156 |
|
157 |
+
protected function _need_to_show_woo() {
|
|
|
158 |
return is_plugin_active( 'woocommerce/woocommerce.php' ) && wp_count_posts( 'product' )->publish > 0;
|
159 |
}
|
160 |
+
|
161 |
+
public function do_page() {
|
162 |
+
require_once ECWID_IMPORTER_TEMPLATES_DIR . '/landing.tpl.php';
|
|
|
163 |
}
|
164 |
+
|
165 |
+
public function do_woo_page() {
|
166 |
+
$import_data = Ecwid_Import::gather_import_data();
|
|
|
167 |
echo Ecwid_Admin_UI_Framework::print_fix_js();
|
168 |
+
|
169 |
require_once ECWID_IMPORTER_TEMPLATES_DIR . '/woo-main.tpl.php';
|
170 |
}
|
171 |
+
|
172 |
protected function _get_products_categories_message( $products, $categories ) {
|
173 |
if ( ecwid_is_paid_account() ) {
|
174 |
+
return sprintf(
|
175 |
+
__( '%1$s products and %2$s categories', 'ecwid-shopping-cart' ),
|
176 |
$products,
|
177 |
$categories
|
178 |
);
|
185 |
}
|
186 |
|
187 |
public function get_woo_import_log() {
|
188 |
+
if ( ! current_user_can( 'manage_options' ) ) {
|
189 |
return;
|
190 |
}
|
191 |
|
192 |
+
header( 'Content-Disposition: attachment; filename=ec-woo-import-log.txt' );
|
193 |
|
194 |
$error_log = get_option( Ecwid_Importer::OPTION_ERROR_LOG, false );
|
195 |
|
196 |
+
if ( ! $error_log ) {
|
197 |
die();
|
198 |
}
|
199 |
|
200 |
+
foreach ( $error_log as $type => $messages ) {
|
201 |
echo sprintf( "ERROR TYPE: %s\r\n", $type );
|
202 |
|
203 |
+
foreach ( $messages as $message => $data ) {
|
204 |
echo "*** \r\n";
|
205 |
echo $message . "\r\n";
|
206 |
+
echo 'Data: ' . var_export( $data, true ) . "\r\n";
|
207 |
}
|
208 |
|
209 |
echo "\r\n";
|
211 |
|
212 |
die();
|
213 |
}
|
214 |
+
}
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
-
=== Ecwid Ecommerce Shopping Cart ===
|
2 |
Contributors: Ecwid
|
3 |
Tags: ecommerce, e-commerce, storefront, shopping cart, online store
|
4 |
Requires at least: 4.4
|
5 |
Tested up to: 6.0
|
6 |
-
Stable tag: 6.10.
|
7 |
|
8 |
Powerful, easy to use ecommerce shopping cart for WordPress. Sell on Facebook and Instagram. iPhone & Android apps. Superb support. Free plan available.
|
9 |
|
@@ -152,6 +152,10 @@ You can use Ecwid’s built-in import tools to copy your store products from any
|
|
152 |
|
153 |
== Changelog ==
|
154 |
|
|
|
|
|
|
|
|
|
155 |
= 6.10.22 - June 08, 2022 =
|
156 |
- Improvements for the integration with the All in One SEO plugin. There was a minor SEO issue with duplicates of the canonical tag on ecommerce store pages. There was sitemaps issue generated by plugin did not work well with those generated by All in One SEO. These issues has been fixed and everything should work fine now.
|
157 |
- Minor fixes for Gutenberg ecommerce blocks.
|
1 |
+
=== Ecwid Ecommerce Shopping Cart ===
|
2 |
Contributors: Ecwid
|
3 |
Tags: ecommerce, e-commerce, storefront, shopping cart, online store
|
4 |
Requires at least: 4.4
|
5 |
Tested up to: 6.0
|
6 |
+
Stable tag: 6.10.23
|
7 |
|
8 |
Powerful, easy to use ecommerce shopping cart for WordPress. Sell on Facebook and Instagram. iPhone & Android apps. Superb support. Free plan available.
|
9 |
|
152 |
|
153 |
== Changelog ==
|
154 |
|
155 |
+
= 6.10.23 - Jul 10, 2022 =
|
156 |
+
- **Improved security of handling storefront settings. Ecwid ecommerce shopping cart plugin update is recommended.**
|
157 |
+
- Farmin theme improved compatibility. Even though Ecwid is compatible with every WordPress theme by design, some slight fixes and improvements are sometimes needed to make storefront look better. That’s why we are always monitoring how Ecwid pages look and behave in WordPress ecommerce themes.
|
158 |
+
|
159 |
= 6.10.22 - June 08, 2022 =
|
160 |
- Improvements for the integration with the All in One SEO plugin. There was a minor SEO issue with duplicates of the canonical tag on ecommerce store pages. There was sitemaps issue generated by plugin did not work well with those generated by All in One SEO. These issues has been fixed and everything should work fine now.
|
161 |
- Minor fixes for Gutenberg ecommerce blocks.
|