Version Description
- Fix: Security fix
Download this release
Release Info
Developer | quadlayers |
Plugin | Perfect Brands for WooCommerce |
Version | 2.0.3 |
Comparing to | |
See all releases |
Code changes from version 2.0.2 to 2.0.3
- assets/js/functions-admin.js +354 -348
- assets/js/functions-admin.min.js +1 -1
- classes/admin/class-brands-exporter.php +91 -86
- classes/class-perfect-woocommerce-brands.php +5 -1
- perfect-woocommerce-brands.php +2 -2
- readme.txt +3 -1
assets/js/functions-admin.js
CHANGED
@@ -1,352 +1,358 @@
|
|
1 |
(function ($) {
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
351 |
|
352 |
})(jQuery)
|
1 |
(function ($) {
|
2 |
+
"use strict";
|
3 |
+
|
4 |
+
var media_uploader = null;
|
5 |
+
|
6 |
+
function open_media_uploader_image(event, imageSelectorButton) {
|
7 |
+
|
8 |
+
var $imageSelectorScope = imageSelectorButton.parent();
|
9 |
+
|
10 |
+
media_uploader = wp.media({
|
11 |
+
frame: "post",
|
12 |
+
state: "insert",
|
13 |
+
multiple: false
|
14 |
+
});
|
15 |
+
|
16 |
+
media_uploader.on("insert", function () {
|
17 |
+
var json = media_uploader.state().get("selection").first().toJSON();
|
18 |
+
var image_id = json.id;
|
19 |
+
var image_url = json.url;
|
20 |
+
var image_html = '<img src="' + image_url + '" width="90" height="90">';
|
21 |
+
|
22 |
+
var current_selector = '';
|
23 |
+
switch (event.target.id) {
|
24 |
+
case 'pwb_brand_image_select':
|
25 |
+
current_selector = '.taxonomy-pwb-brand #pwb_brand_' + 'image';
|
26 |
+
break;
|
27 |
+
case 'pwb_brand_banner_select':
|
28 |
+
current_selector = '.taxonomy-pwb-brand #pwb_brand_' + 'banner';
|
29 |
+
break;
|
30 |
+
}
|
31 |
+
|
32 |
+
$(current_selector).val(image_id);
|
33 |
+
$(current_selector + '_result').remove();
|
34 |
+
|
35 |
+
if ($('.pwb_brand_image_selected', $imageSelectorScope).length) {
|
36 |
+
$('.pwb_brand_image_selected span', $imageSelectorScope).html(image_html);
|
37 |
+
} else {
|
38 |
+
$imageSelectorScope.append('<div class="pwb_brand_image_selected"><span>' + image_html + '</span></div>');
|
39 |
+
}
|
40 |
+
add_delete_link($imageSelectorScope);
|
41 |
+
|
42 |
+
});
|
43 |
+
|
44 |
+
media_uploader.open();
|
45 |
+
}
|
46 |
+
|
47 |
+
|
48 |
+
$('.taxonomy-pwb-brand #pwb_brand_image_select, .taxonomy-pwb-brand #pwb_brand_banner_select').on('click', function (event) {
|
49 |
+
open_media_uploader_image(event, $(this));
|
50 |
+
});
|
51 |
+
|
52 |
+
//bind remove image event for edit page
|
53 |
+
$('.taxonomy-pwb-brand #pwb_brand_image_select, .taxonomy-pwb-brand #pwb_brand_banner_select').each(function () {
|
54 |
+
add_delete_link($(this).parent());
|
55 |
+
});
|
56 |
+
|
57 |
+
//clear custom fields when brand is added
|
58 |
+
if ($('body').hasClass('edit-tags-php') && $('body').hasClass('taxonomy-pwb-brand')) {
|
59 |
+
$(document).ajaxSuccess(function (event, xhr, settings) {
|
60 |
+
//Check ajax action of request that succeeded
|
61 |
+
if (typeof settings != "undefined" && settings.data && ~settings.data.indexOf("action=add-tag") && ~settings.data.indexOf("taxonomy=pwb-brand")) {
|
62 |
+
$('#pwb_brand_image').val('');
|
63 |
+
$('#pwb_brand_banner').val('');
|
64 |
+
$('.pwb_brand_image_selected').remove();
|
65 |
+
}
|
66 |
+
});
|
67 |
+
}
|
68 |
+
|
69 |
+
function add_delete_link($imageSelectorScope) {
|
70 |
+
|
71 |
+
$('.pwb_brand_image_selected span', $imageSelectorScope).append('<a href="#" class="pwb_brand_image_selected_remove">X</a>');
|
72 |
|
73 |
+
$('.pwb_brand_image_selected_remove', $imageSelectorScope).on('click', function (event) {
|
74 |
+
|
75 |
+
event.preventDefault();
|
76 |
+
$(this).closest('.pwb_brand_image_selected').remove();
|
77 |
+
|
78 |
+
//remove the img
|
79 |
+
$('#pwb_brand_image', $imageSelectorScope).val('');
|
80 |
+
$('#pwb_brand_banner', $imageSelectorScope).val('');
|
81 |
+
|
82 |
+
});
|
83 |
+
|
84 |
+
}
|
85 |
+
|
86 |
+
/* ····························· Edit brands page ····························· */
|
87 |
+
$('.taxonomy-pwb-brand table .column-featured > span').not('pwb-blocked').on('click', function (e) {
|
88 |
+
e.preventDefault();
|
89 |
+
var $currentStar = $(this);
|
90 |
+
$currentStar.addClass('pwb-blocked');
|
91 |
+
if ($currentStar.hasClass('dashicons-star-filled')) {
|
92 |
+
$currentStar.removeClass('dashicons-star-filled');
|
93 |
+
$currentStar.addClass('dashicons-star-empty');
|
94 |
+
} else {
|
95 |
+
$currentStar.removeClass('dashicons-star-empty');
|
96 |
+
$currentStar.addClass('dashicons-star-filled');
|
97 |
+
}
|
98 |
+
var data = { 'action': 'pwb_admin_set_featured_brand', 'brand': $currentStar.data('brand-id') };
|
99 |
+
$.post(pwb_ajax_object_admin.ajax_url, data, function (response) {
|
100 |
+
$currentStar.removeClass('pwb-blocked');
|
101 |
+
if (response.success) {
|
102 |
+
var $featuredCount = $('.taxonomy-pwb-brand .pwb-featured-count > span');
|
103 |
+
if (response.data.direction == 'up') {
|
104 |
+
$featuredCount.html(parseInt($featuredCount.text()) + 1);
|
105 |
+
} else {
|
106 |
+
$featuredCount.html(parseInt($featuredCount.text()) - 1);
|
107 |
+
}
|
108 |
+
} else {
|
109 |
+
alert(response.data.error_msg);
|
110 |
+
}
|
111 |
+
});
|
112 |
+
});
|
113 |
+
|
114 |
+
$('.taxonomy-pwb-brand #pwb-first-featured-brands').on('change', function (e) {
|
115 |
+
e.preventDefault();
|
116 |
+
$('#screen-options-apply').replaceWith('<img src="' + pwb_ajax_object_admin.site_url + '/wp-admin/images/loading.gif">');
|
117 |
+
var data = { 'action': 'pwb_admin_save_screen_settings', 'new_val': $(this).is(':checked') };
|
118 |
+
$.post(pwb_ajax_object_admin.ajax_url, data, function (response) { location.reload(); });
|
119 |
+
});
|
120 |
+
|
121 |
+
$('.pwb-edit-brands-bottom > span').on('click', function (e) {
|
122 |
+
e.preventDefault();
|
123 |
+
$('.taxonomy-pwb-brand #col-left').toggleClass('pwb-force-full-width');
|
124 |
+
$('.taxonomy-pwb-brand #col-right').toggleClass('pwb-force-full-width');
|
125 |
+
});
|
126 |
+
/* ····························· /Edit brands page ····························· */
|
127 |
+
|
128 |
+
/* ····························· Settings tab ····························· */
|
129 |
+
|
130 |
+
if ($('.pwb-admin-selectwoo').length) {
|
131 |
+
$('.pwb-admin-selectwoo').selectWoo();
|
132 |
+
}
|
133 |
+
|
134 |
+
// migrate brands
|
135 |
+
$('#wc_pwb_admin_tab_tools_migrate').on('change', function () {
|
136 |
+
|
137 |
+
if ($(this).val() != '-') {
|
138 |
+
|
139 |
+
if (confirm(pwb_ajax_object_admin.translations.migrate_notice)) {
|
140 |
+
|
141 |
+
$('html').append('<div class="pwb-modal"><div class="pwb-modal-inner"></div></div>');
|
142 |
+
$('.pwb-modal-inner').html('<p>' + pwb_ajax_object_admin.translations.migrating + '</p>');
|
143 |
+
|
144 |
+
var data = {
|
145 |
+
'action': 'pwb_admin_migrate_brands',
|
146 |
+
'from': $(this).val()
|
147 |
+
};
|
148 |
+
$.post(pwb_ajax_object_admin.ajax_url, data, function (response) {
|
149 |
+
|
150 |
+
setTimeout(function () {
|
151 |
+
location.href = pwb_ajax_object_admin.brands_url;
|
152 |
+
}, 1000);
|
153 |
+
|
154 |
+
});
|
155 |
+
|
156 |
+
} else {
|
157 |
+
|
158 |
+
}
|
159 |
+
|
160 |
+
}
|
161 |
+
|
162 |
+
$(this).val('-');//reset to default value
|
163 |
+
|
164 |
+
});
|
165 |
+
|
166 |
+
// dummy data
|
167 |
+
$('#wc_pwb_admin_tab_tools_dummy_data').on('change', function () {
|
168 |
+
|
169 |
+
if ($(this).val() != '-') {
|
170 |
+
|
171 |
+
if (confirm(pwb_ajax_object_admin.translations.dummy_data_notice)) {
|
172 |
+
|
173 |
+
$('html').append('<div class="pwb-modal"><div class="pwb-modal-inner"></div></div>');
|
174 |
+
$('.pwb-modal-inner').html('<p>' + pwb_ajax_object_admin.translations.dummy_data + '</p>');
|
175 |
+
|
176 |
+
var data = {
|
177 |
+
'action': 'pwb_admin_dummy_data',
|
178 |
+
'from': $(this).val()
|
179 |
+
};
|
180 |
+
$.post(pwb_ajax_object_admin.ajax_url, data, function (response) {
|
181 |
+
|
182 |
+
setTimeout(function () {
|
183 |
+
location.href = pwb_ajax_object_admin.brands_url;
|
184 |
+
}, 1000);
|
185 |
+
|
186 |
+
});
|
187 |
+
|
188 |
+
} else {
|
189 |
+
|
190 |
+
}
|
191 |
+
|
192 |
+
}
|
193 |
+
|
194 |
+
$(this).val('-');//reset to default value
|
195 |
+
|
196 |
+
});
|
197 |
+
|
198 |
+
var $systemStatusBtn = $('#wc_pwb_admin_tab_tools_system_status').siblings('p');
|
199 |
+
$systemStatusBtn.addClass('button wc_pwb_admin_tab_status_btn');
|
200 |
+
$('.wc_pwb_admin_tab_status_btn').on('click', function (e) {
|
201 |
+
e.preventDefault();
|
202 |
+
if (!$('#wc_pwb_admin_status_result').length) {
|
203 |
+
var $systemStatusTextarea = $('#wc_pwb_admin_tab_tools_system_status');
|
204 |
+
$('<pre id="wc_pwb_admin_status_result"></pre>').insertAfter($systemStatusTextarea);
|
205 |
+
$('#wc_pwb_admin_status_result').click(function (e) {
|
206 |
+
e.preventDefault();
|
207 |
+
var refNode = $(this)[0];
|
208 |
+
if ($.browser.msie) {
|
209 |
+
var range = document.body.createTextRange();
|
210 |
+
range.moveToElementText(refNode);
|
211 |
+
range.select();
|
212 |
+
} else if ($.browser.mozilla || $.browser.opera) {
|
213 |
+
var selection = window.getSelection();
|
214 |
+
var range = document.createRange();
|
215 |
+
range.selectNodeContents(refNode);
|
216 |
+
selection.removeAllRanges();
|
217 |
+
selection.addRange(range);
|
218 |
+
} else if ($.browser.safari) {
|
219 |
+
var selection = window.getSelection();
|
220 |
+
selection.setBaseAndExtent(refNode, 0, refNode, 1);
|
221 |
+
}
|
222 |
+
});
|
223 |
+
}
|
224 |
+
$('#wc_pwb_admin_status_result').html('<img src="' + pwb_ajax_object_admin.site_url + '/wp-admin/images/spinner.gif' + '" alt="Loading" height="20" width="20">');
|
225 |
+
$('#wc_pwb_admin_status_result').show();
|
226 |
+
var data = {
|
227 |
+
'action': 'pwb_system_status'
|
228 |
+
};
|
229 |
+
$.post(ajaxurl, data, function (response) {
|
230 |
+
$('#wc_pwb_admin_status_result').html(response);
|
231 |
+
$('#wc_pwb_admin_status_result').trigger('click');
|
232 |
+
});
|
233 |
+
|
234 |
+
});
|
235 |
+
|
236 |
+
/* ····························· /Settings tab ····························· */
|
237 |
+
|
238 |
+
/* ····························· Admin notices ····························· */
|
239 |
+
$(document).on('click', '.pwb-notice-dismissible .notice-dismiss', function (e) {
|
240 |
+
|
241 |
+
e.preventDefault();
|
242 |
+
|
243 |
+
var noticeName = $(this).closest('.pwb-notice-dismissible').data('notice');
|
244 |
+
|
245 |
+
var data = {
|
246 |
+
'action': 'dismiss_pwb_notice',
|
247 |
+
'notice_name': noticeName
|
248 |
+
};
|
249 |
+
$.post(ajaxurl, data, function (response) {
|
250 |
+
//callback
|
251 |
+
});
|
252 |
+
|
253 |
+
});
|
254 |
+
/* ····························· /Admin notices ····························· */
|
255 |
+
|
256 |
+
/* ····························· Widgets ····························· */
|
257 |
+
pwbBindEventsToWigets();
|
258 |
+
//Fires when a widget is added to a sidebar
|
259 |
+
$(document).bind('widget-added', function (e, widget) {
|
260 |
+
pwbBindEventsToWigets(widget);
|
261 |
+
});
|
262 |
+
//Fires on widget save
|
263 |
+
$(document).on('widget-updated', function (e, widget) {
|
264 |
+
pwbBindEventsToWigets(widget);
|
265 |
+
});
|
266 |
+
function pwbBindEventsToWigets(widget) {
|
267 |
+
|
268 |
+
var $currentWidget = $(".pwb-select-display-as");
|
269 |
+
|
270 |
+
if (widget != undefined) {
|
271 |
+
$currentWidget = $(".pwb-select-display-as", widget);
|
272 |
+
}
|
273 |
+
$currentWidget.on("change", function () {
|
274 |
+
if ($(this).val() == "brand_logo") {
|
275 |
+
$(this).parent().siblings(".pwb-display-as-logo").addClass("show");
|
276 |
+
} else {
|
277 |
+
$(this).parent().siblings(".pwb-display-as-logo").removeClass("show");
|
278 |
+
}
|
279 |
+
});
|
280 |
+
}
|
281 |
+
/* ····························· /Widgets ····························· */
|
282 |
+
|
283 |
+
/* ····························· Brands exporter ····························· */
|
284 |
+
$('button.pwb-brands-export').on('click', function (e) {
|
285 |
+
e.preventDefault();
|
286 |
+
|
287 |
+
var $clickedBtn = $(this);
|
288 |
+
$clickedBtn.addClass('pwb-loading-overlay');
|
289 |
+
$clickedBtn.prop("disabled", true);
|
290 |
+
|
291 |
+
var data = {
|
292 |
+
'action': 'pwb_brands_export',
|
293 |
+
'nonce': pwb_ajax_object_admin.nonce.export
|
294 |
+
};
|
295 |
+
|
296 |
+
|
297 |
+
$.post(pwb_ajax_object_admin.ajax_url, data, function (response) {
|
298 |
+
|
299 |
+
if (response.success) {
|
300 |
+
$clickedBtn.removeClass('pwb-loading-overlay');
|
301 |
+
$clickedBtn.prop("disabled", false);
|
302 |
+
|
303 |
+
//download export file
|
304 |
+
$('#pwb-download-export-file').remove();
|
305 |
+
var link = document.createElement("a");
|
306 |
+
link.download = 'brands.json';
|
307 |
+
link.id = 'pwb-download-export-file';
|
308 |
+
link.href = response.data.export_file_url;
|
309 |
+
$('body').append(link);
|
310 |
+
link.click();
|
311 |
+
}
|
312 |
+
|
313 |
+
});
|
314 |
+
|
315 |
+
})
|
316 |
+
|
317 |
+
$('button.pwb-brands-import').on('click', function (e) {
|
318 |
+
e.preventDefault();
|
319 |
+
$('input.pwb-brands-import-file').trigger('click');
|
320 |
+
});
|
321 |
+
|
322 |
+
$('input.pwb-brands-import-file').on('change', function (e) {
|
323 |
+
e.preventDefault();
|
324 |
+
|
325 |
+
var $clickedBtn = $('button.pwb-brands-import');
|
326 |
+
$clickedBtn.addClass('pwb-loading-overlay');
|
327 |
+
$clickedBtn.prop("disabled", true);
|
328 |
+
|
329 |
+
var file = $(this)[0].files[0];
|
330 |
+
|
331 |
+
var reqData = new FormData();
|
332 |
+
reqData.append('action', 'pwb_brands_import');
|
333 |
+
reqData.append('file', file);
|
334 |
+
reqData.append('nonce', pwb_ajax_object_admin.nonce.import);
|
335 |
+
|
336 |
+
$.ajax({
|
337 |
+
url: pwb_ajax_object_admin.ajax_url,
|
338 |
+
type: 'post',
|
339 |
+
cache: false,
|
340 |
+
dataType: 'json',
|
341 |
+
contentType: false,
|
342 |
+
processData: false,
|
343 |
+
data: reqData,
|
344 |
+
success: function (resp) {
|
345 |
+
if (resp.success) {
|
346 |
+
$clickedBtn.removeClass('pwb-loading-overlay');
|
347 |
+
location.reload();
|
348 |
+
} else {
|
349 |
+
alert('Importer error');
|
350 |
+
}
|
351 |
+
}
|
352 |
+
});
|
353 |
+
|
354 |
+
})
|
355 |
+
|
356 |
+
/* ····························· /Brands exporter ····························· */
|
357 |
|
358 |
})(jQuery)
|
assets/js/functions-admin.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
!function($){"use strict";var media_uploader=null,$systemStatusBtn;function open_media_uploader_image(event,imageSelectorButton){var $imageSelectorScope=imageSelectorButton.parent();(media_uploader=wp.media({frame:"post",state:"insert",multiple:!1})).on("insert",(function(){var json=media_uploader.state().get("selection").first().toJSON(),image_id=json.id,image_url,image_html='<img src="'+json.url+'" width="90" height="90">',current_selector="";switch(event.target.id){case"pwb_brand_image_select":current_selector=".taxonomy-pwb-brand #pwb_brand_image";break;case"pwb_brand_banner_select":current_selector=".taxonomy-pwb-brand #pwb_brand_banner"}$(current_selector).val(image_id),$(current_selector+"_result").remove(),$(".pwb_brand_image_selected",$imageSelectorScope).length?$(".pwb_brand_image_selected span",$imageSelectorScope).html(image_html):$imageSelectorScope.append('<div class="pwb_brand_image_selected"><span>'+image_html+"</span></div>"),add_delete_link($imageSelectorScope)})),media_uploader.open()}function add_delete_link($imageSelectorScope){$(".pwb_brand_image_selected span",$imageSelectorScope).append('<a href="#" class="pwb_brand_image_selected_remove">X</a>'),$(".pwb_brand_image_selected_remove",$imageSelectorScope).on("click",(function(event){event.preventDefault(),$(this).closest(".pwb_brand_image_selected").remove(),$("#pwb_brand_image",$imageSelectorScope).val(""),$("#pwb_brand_banner",$imageSelectorScope).val("")}))}function pwbBindEventsToWigets(widget){var $currentWidget=$(".pwb-select-display-as");null!=widget&&($currentWidget=$(".pwb-select-display-as",widget)),$currentWidget.on("change",(function(){"brand_logo"==$(this).val()?$(this).parent().siblings(".pwb-display-as-logo").addClass("show"):$(this).parent().siblings(".pwb-display-as-logo").removeClass("show")}))}$(".taxonomy-pwb-brand #pwb_brand_image_select, .taxonomy-pwb-brand #pwb_brand_banner_select").on("click",(function(event){open_media_uploader_image(event,$(this))})),$(".taxonomy-pwb-brand #pwb_brand_image_select, .taxonomy-pwb-brand #pwb_brand_banner_select").each((function(){add_delete_link($(this).parent())})),$("body").hasClass("edit-tags-php")&&$("body").hasClass("taxonomy-pwb-brand")&&$(document).ajaxSuccess((function(event,xhr,settings){void 0!==settings&&settings.data&&~settings.data.indexOf("action=add-tag")&&~settings.data.indexOf("taxonomy=pwb-brand")&&($("#pwb_brand_image").val(""),$("#pwb_brand_banner").val(""),$(".pwb_brand_image_selected").remove())})),$(".taxonomy-pwb-brand table .column-featured > span").not("pwb-blocked").on("click",(function(e){e.preventDefault();var $currentStar=$(this);$currentStar.addClass("pwb-blocked"),$currentStar.hasClass("dashicons-star-filled")?($currentStar.removeClass("dashicons-star-filled"),$currentStar.addClass("dashicons-star-empty")):($currentStar.removeClass("dashicons-star-empty"),$currentStar.addClass("dashicons-star-filled"));var data={action:"pwb_admin_set_featured_brand",brand:$currentStar.data("brand-id")};$.post(pwb_ajax_object_admin.ajax_url,data,(function(response){if($currentStar.removeClass("pwb-blocked"),response.success){var $featuredCount=$(".taxonomy-pwb-brand .pwb-featured-count > span");"up"==response.data.direction?$featuredCount.html(parseInt($featuredCount.text())+1):$featuredCount.html(parseInt($featuredCount.text())-1)}else alert(response.data.error_msg)}))})),$(".taxonomy-pwb-brand #pwb-first-featured-brands").on("change",(function(e){e.preventDefault(),$("#screen-options-apply").replaceWith('<img src="'+pwb_ajax_object_admin.site_url+'/wp-admin/images/loading.gif">');var data={action:"pwb_admin_save_screen_settings",new_val:$(this).is(":checked")};$.post(pwb_ajax_object_admin.ajax_url,data,(function(response){location.reload()}))})),$(".pwb-edit-brands-bottom > span").on("click",(function(e){e.preventDefault(),$(".taxonomy-pwb-brand #col-left").toggleClass("pwb-force-full-width"),$(".taxonomy-pwb-brand #col-right").toggleClass("pwb-force-full-width")})),$(".pwb-admin-selectwoo").length&&$(".pwb-admin-selectwoo").selectWoo(),$("#wc_pwb_admin_tab_tools_migrate").on("change",(function(){if("-"!=$(this).val()&&confirm(pwb_ajax_object_admin.translations.migrate_notice)){$("html").append('<div class="pwb-modal"><div class="pwb-modal-inner"></div></div>'),$(".pwb-modal-inner").html("<p>"+pwb_ajax_object_admin.translations.migrating+"</p>");var data={action:"pwb_admin_migrate_brands",from:$(this).val()};$.post(pwb_ajax_object_admin.ajax_url,data,(function(response){setTimeout((function(){location.href=pwb_ajax_object_admin.brands_url}),1e3)}))}$(this).val("-")})),$("#wc_pwb_admin_tab_tools_dummy_data").on("change",(function(){if("-"!=$(this).val()&&confirm(pwb_ajax_object_admin.translations.dummy_data_notice)){$("html").append('<div class="pwb-modal"><div class="pwb-modal-inner"></div></div>'),$(".pwb-modal-inner").html("<p>"+pwb_ajax_object_admin.translations.dummy_data+"</p>");var data={action:"pwb_admin_dummy_data",from:$(this).val()};$.post(pwb_ajax_object_admin.ajax_url,data,(function(response){setTimeout((function(){location.href=pwb_ajax_object_admin.brands_url}),1e3)}))}$(this).val("-")})),$("#wc_pwb_admin_tab_tools_system_status").siblings("p").addClass("button wc_pwb_admin_tab_status_btn"),$(".wc_pwb_admin_tab_status_btn").on("click",(function(e){if(e.preventDefault(),!$("#wc_pwb_admin_status_result").length){var $systemStatusTextarea=$("#wc_pwb_admin_tab_tools_system_status");$('<pre id="wc_pwb_admin_status_result"></pre>').insertAfter($systemStatusTextarea),$("#wc_pwb_admin_status_result").click((function(e){e.preventDefault();var refNode=$(this)[0],range;if($.browser.msie)(range=document.body.createTextRange()).moveToElementText(refNode),range.select();else if($.browser.mozilla||$.browser.opera){var selection=window.getSelection(),range;(range=document.createRange()).selectNodeContents(refNode),selection.removeAllRanges(),selection.addRange(range)}else if($.browser.safari){var selection;(selection=window.getSelection()).setBaseAndExtent(refNode,0,refNode,1)}}))}$("#wc_pwb_admin_status_result").html('<img src="'+pwb_ajax_object_admin.site_url+'/wp-admin/images/spinner.gif" alt="Loading" height="20" width="20">'),$("#wc_pwb_admin_status_result").show();var data={action:"pwb_system_status"};$.post(ajaxurl,data,(function(response){$("#wc_pwb_admin_status_result").html(response),$("#wc_pwb_admin_status_result").trigger("click")}))})),$(document).on("click",".pwb-notice-dismissible .notice-dismiss",(function(e){e.preventDefault();var noticeName,data={action:"dismiss_pwb_notice",notice_name:$(this).closest(".pwb-notice-dismissible").data("notice")};$.post(ajaxurl,data,(function(response){}))})),pwbBindEventsToWigets(),$(document).bind("widget-added",(function(e,widget){pwbBindEventsToWigets(widget)})),$(document).on("widget-updated",(function(e,widget){pwbBindEventsToWigets(widget)})),$("button.pwb-brands-export").on("click",(function(e){e.preventDefault();var $clickedBtn=$(this);$clickedBtn.addClass("pwb-loading-overlay"),$clickedBtn.prop("disabled",!0);var data={action:"pwb_brands_export"};$.post(pwb_ajax_object_admin.ajax_url,data,(function(response){if(response.success){$clickedBtn.removeClass("pwb-loading-overlay"),$clickedBtn.prop("disabled",!1),$("#pwb-download-export-file").remove();var link=document.createElement("a");link.download="brands.json",link.id="pwb-download-export-file",link.href=response.data.export_file_url,$("body").append(link),link.click()}}))})),$("button.pwb-brands-import").on("click",(function(e){e.preventDefault(),$("input.pwb-brands-import-file").trigger("click")})),$("input.pwb-brands-import-file").on("change",(function(e){e.preventDefault();var $clickedBtn=$("button.pwb-brands-import");$clickedBtn.addClass("pwb-loading-overlay"),$clickedBtn.prop("disabled",!0);var file=$(this)[0].files[0],reqData=new FormData;reqData.append("action","pwb_brands_import"),reqData.append("file",file),$.ajax({url:pwb_ajax_object_admin.ajax_url,type:"post",cache:!1,dataType:"json",contentType:!1,processData:!1,data:reqData,success:function(resp){resp.success?($clickedBtn.removeClass("pwb-loading-overlay"),location.reload()):alert("Importer error")}})}))}(jQuery);
|
1 |
+
!function($){"use strict";var media_uploader=null,$systemStatusBtn;function open_media_uploader_image(event,imageSelectorButton){var $imageSelectorScope=imageSelectorButton.parent();(media_uploader=wp.media({frame:"post",state:"insert",multiple:!1})).on("insert",(function(){var json=media_uploader.state().get("selection").first().toJSON(),image_id=json.id,image_url,image_html='<img src="'+json.url+'" width="90" height="90">',current_selector="";switch(event.target.id){case"pwb_brand_image_select":current_selector=".taxonomy-pwb-brand #pwb_brand_image";break;case"pwb_brand_banner_select":current_selector=".taxonomy-pwb-brand #pwb_brand_banner"}$(current_selector).val(image_id),$(current_selector+"_result").remove(),$(".pwb_brand_image_selected",$imageSelectorScope).length?$(".pwb_brand_image_selected span",$imageSelectorScope).html(image_html):$imageSelectorScope.append('<div class="pwb_brand_image_selected"><span>'+image_html+"</span></div>"),add_delete_link($imageSelectorScope)})),media_uploader.open()}function add_delete_link($imageSelectorScope){$(".pwb_brand_image_selected span",$imageSelectorScope).append('<a href="#" class="pwb_brand_image_selected_remove">X</a>'),$(".pwb_brand_image_selected_remove",$imageSelectorScope).on("click",(function(event){event.preventDefault(),$(this).closest(".pwb_brand_image_selected").remove(),$("#pwb_brand_image",$imageSelectorScope).val(""),$("#pwb_brand_banner",$imageSelectorScope).val("")}))}function pwbBindEventsToWigets(widget){var $currentWidget=$(".pwb-select-display-as");null!=widget&&($currentWidget=$(".pwb-select-display-as",widget)),$currentWidget.on("change",(function(){"brand_logo"==$(this).val()?$(this).parent().siblings(".pwb-display-as-logo").addClass("show"):$(this).parent().siblings(".pwb-display-as-logo").removeClass("show")}))}$(".taxonomy-pwb-brand #pwb_brand_image_select, .taxonomy-pwb-brand #pwb_brand_banner_select").on("click",(function(event){open_media_uploader_image(event,$(this))})),$(".taxonomy-pwb-brand #pwb_brand_image_select, .taxonomy-pwb-brand #pwb_brand_banner_select").each((function(){add_delete_link($(this).parent())})),$("body").hasClass("edit-tags-php")&&$("body").hasClass("taxonomy-pwb-brand")&&$(document).ajaxSuccess((function(event,xhr,settings){void 0!==settings&&settings.data&&~settings.data.indexOf("action=add-tag")&&~settings.data.indexOf("taxonomy=pwb-brand")&&($("#pwb_brand_image").val(""),$("#pwb_brand_banner").val(""),$(".pwb_brand_image_selected").remove())})),$(".taxonomy-pwb-brand table .column-featured > span").not("pwb-blocked").on("click",(function(e){e.preventDefault();var $currentStar=$(this);$currentStar.addClass("pwb-blocked"),$currentStar.hasClass("dashicons-star-filled")?($currentStar.removeClass("dashicons-star-filled"),$currentStar.addClass("dashicons-star-empty")):($currentStar.removeClass("dashicons-star-empty"),$currentStar.addClass("dashicons-star-filled"));var data={action:"pwb_admin_set_featured_brand",brand:$currentStar.data("brand-id")};$.post(pwb_ajax_object_admin.ajax_url,data,(function(response){if($currentStar.removeClass("pwb-blocked"),response.success){var $featuredCount=$(".taxonomy-pwb-brand .pwb-featured-count > span");"up"==response.data.direction?$featuredCount.html(parseInt($featuredCount.text())+1):$featuredCount.html(parseInt($featuredCount.text())-1)}else alert(response.data.error_msg)}))})),$(".taxonomy-pwb-brand #pwb-first-featured-brands").on("change",(function(e){e.preventDefault(),$("#screen-options-apply").replaceWith('<img src="'+pwb_ajax_object_admin.site_url+'/wp-admin/images/loading.gif">');var data={action:"pwb_admin_save_screen_settings",new_val:$(this).is(":checked")};$.post(pwb_ajax_object_admin.ajax_url,data,(function(response){location.reload()}))})),$(".pwb-edit-brands-bottom > span").on("click",(function(e){e.preventDefault(),$(".taxonomy-pwb-brand #col-left").toggleClass("pwb-force-full-width"),$(".taxonomy-pwb-brand #col-right").toggleClass("pwb-force-full-width")})),$(".pwb-admin-selectwoo").length&&$(".pwb-admin-selectwoo").selectWoo(),$("#wc_pwb_admin_tab_tools_migrate").on("change",(function(){if("-"!=$(this).val()&&confirm(pwb_ajax_object_admin.translations.migrate_notice)){$("html").append('<div class="pwb-modal"><div class="pwb-modal-inner"></div></div>'),$(".pwb-modal-inner").html("<p>"+pwb_ajax_object_admin.translations.migrating+"</p>");var data={action:"pwb_admin_migrate_brands",from:$(this).val()};$.post(pwb_ajax_object_admin.ajax_url,data,(function(response){setTimeout((function(){location.href=pwb_ajax_object_admin.brands_url}),1e3)}))}$(this).val("-")})),$("#wc_pwb_admin_tab_tools_dummy_data").on("change",(function(){if("-"!=$(this).val()&&confirm(pwb_ajax_object_admin.translations.dummy_data_notice)){$("html").append('<div class="pwb-modal"><div class="pwb-modal-inner"></div></div>'),$(".pwb-modal-inner").html("<p>"+pwb_ajax_object_admin.translations.dummy_data+"</p>");var data={action:"pwb_admin_dummy_data",from:$(this).val()};$.post(pwb_ajax_object_admin.ajax_url,data,(function(response){setTimeout((function(){location.href=pwb_ajax_object_admin.brands_url}),1e3)}))}$(this).val("-")})),$("#wc_pwb_admin_tab_tools_system_status").siblings("p").addClass("button wc_pwb_admin_tab_status_btn"),$(".wc_pwb_admin_tab_status_btn").on("click",(function(e){if(e.preventDefault(),!$("#wc_pwb_admin_status_result").length){var $systemStatusTextarea=$("#wc_pwb_admin_tab_tools_system_status");$('<pre id="wc_pwb_admin_status_result"></pre>').insertAfter($systemStatusTextarea),$("#wc_pwb_admin_status_result").click((function(e){e.preventDefault();var refNode=$(this)[0],range;if($.browser.msie)(range=document.body.createTextRange()).moveToElementText(refNode),range.select();else if($.browser.mozilla||$.browser.opera){var selection=window.getSelection(),range;(range=document.createRange()).selectNodeContents(refNode),selection.removeAllRanges(),selection.addRange(range)}else if($.browser.safari){var selection;(selection=window.getSelection()).setBaseAndExtent(refNode,0,refNode,1)}}))}$("#wc_pwb_admin_status_result").html('<img src="'+pwb_ajax_object_admin.site_url+'/wp-admin/images/spinner.gif" alt="Loading" height="20" width="20">'),$("#wc_pwb_admin_status_result").show();var data={action:"pwb_system_status"};$.post(ajaxurl,data,(function(response){$("#wc_pwb_admin_status_result").html(response),$("#wc_pwb_admin_status_result").trigger("click")}))})),$(document).on("click",".pwb-notice-dismissible .notice-dismiss",(function(e){e.preventDefault();var noticeName,data={action:"dismiss_pwb_notice",notice_name:$(this).closest(".pwb-notice-dismissible").data("notice")};$.post(ajaxurl,data,(function(response){}))})),pwbBindEventsToWigets(),$(document).bind("widget-added",(function(e,widget){pwbBindEventsToWigets(widget)})),$(document).on("widget-updated",(function(e,widget){pwbBindEventsToWigets(widget)})),$("button.pwb-brands-export").on("click",(function(e){e.preventDefault();var $clickedBtn=$(this);$clickedBtn.addClass("pwb-loading-overlay"),$clickedBtn.prop("disabled",!0);var data={action:"pwb_brands_export",nonce:pwb_ajax_object_admin.nonce.export};$.post(pwb_ajax_object_admin.ajax_url,data,(function(response){if(response.success){$clickedBtn.removeClass("pwb-loading-overlay"),$clickedBtn.prop("disabled",!1),$("#pwb-download-export-file").remove();var link=document.createElement("a");link.download="brands.json",link.id="pwb-download-export-file",link.href=response.data.export_file_url,$("body").append(link),link.click()}}))})),$("button.pwb-brands-import").on("click",(function(e){e.preventDefault(),$("input.pwb-brands-import-file").trigger("click")})),$("input.pwb-brands-import-file").on("change",(function(e){e.preventDefault();var $clickedBtn=$("button.pwb-brands-import");$clickedBtn.addClass("pwb-loading-overlay"),$clickedBtn.prop("disabled",!0);var file=$(this)[0].files[0],reqData=new FormData;reqData.append("action","pwb_brands_import"),reqData.append("file",file),reqData.append("nonce",pwb_ajax_object_admin.nonce.import),$.ajax({url:pwb_ajax_object_admin.ajax_url,type:"post",cache:!1,dataType:"json",contentType:!1,processData:!1,data:reqData,success:function(resp){resp.success?($clickedBtn.removeClass("pwb-loading-overlay"),location.reload()):alert("Importer error")}})}))}(jQuery);
|
classes/admin/class-brands-exporter.php
CHANGED
@@ -1,128 +1,133 @@
|
|
1 |
<?php
|
2 |
-
namespace Perfect_Woocommerce_Brands\Admin;
|
3 |
|
4 |
-
|
5 |
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
add_action( 'wp_ajax_pwb_brands_export', array( $this, 'export_brands' ) );
|
11 |
-
add_action( 'wp_ajax_pwb_brands_import', array( $this, 'import_brands' ) );
|
12 |
-
}
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
|
|
|
|
21 |
$this->get_brands();
|
22 |
-
|
|
|
23 |
}
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
$brands_data = array();
|
28 |
-
|
29 |
-
$brands = get_terms( 'pwb-brand',array( 'hide_empty' => false ) );
|
30 |
-
foreach( $brands as $brand ){
|
31 |
-
|
32 |
-
$current_brand = array(
|
33 |
-
'slug' => $brand->slug,
|
34 |
-
'name' => $brand->name,
|
35 |
-
'banner_link' => get_term_meta( $brand->term_id, 'pwb_brand_banner_link', true ),
|
36 |
-
'desc' => htmlentities( $brand->description )
|
37 |
-
);
|
38 |
-
|
39 |
-
$image = get_term_meta( $brand->term_id, 'pwb_brand_image', true );
|
40 |
-
$image = wp_get_attachment_image_src( $image, 'full' );
|
41 |
-
if( $image ) $current_brand['image'] = $image[0];
|
42 |
-
|
43 |
-
$banner = get_term_meta( $brand->term_id, 'pwb_brand_banner', true );
|
44 |
-
$banner = wp_get_attachment_image_src( $banner, 'full' );
|
45 |
-
if( $banner ) $current_brand['banner'] = $banner[0];
|
46 |
|
47 |
-
|
48 |
|
49 |
-
|
|
|
50 |
|
51 |
-
$
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
54 |
|
55 |
-
$
|
|
|
|
|
56 |
|
57 |
-
|
|
|
|
|
58 |
|
|
|
59 |
}
|
60 |
|
61 |
-
|
|
|
|
|
62 |
|
63 |
-
|
64 |
-
$file = $_FILES['file'];
|
65 |
|
66 |
-
|
|
|
67 |
|
68 |
-
|
|
|
69 |
|
70 |
-
|
71 |
|
72 |
-
|
73 |
-
'slug' => $brand['slug'],
|
74 |
-
'description' => html_entity_decode( $brand['desc'] )
|
75 |
-
));
|
76 |
|
77 |
-
|
78 |
|
79 |
-
|
80 |
-
$this->upload_remote_image_and_attach( $brand['image'], $new_brand['term_id'], 'pwb_brand_image' );
|
81 |
-
if( !empty( $brand['banner'] ) )
|
82 |
-
$this->upload_remote_image_and_attach( $brand['banner'], $new_brand['term_id'], 'pwb_brand_banner' );
|
83 |
-
if( !empty( $brand['banner_link'] ) )
|
84 |
-
update_term_meta( $new_brand['term_id'], 'pwb_brand_banner_link', $brand['banner_link'], true );
|
85 |
|
86 |
-
|
87 |
|
88 |
-
|
|
|
|
|
|
|
89 |
|
90 |
-
|
91 |
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
94 |
}
|
95 |
|
96 |
-
|
97 |
-
|
98 |
-
}else{
|
99 |
wp_send_json_error();
|
100 |
}
|
101 |
-
|
102 |
-
|
103 |
}
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
$get = wp_remote_get( $image_url );
|
108 |
-
$type = wp_remote_retrieve_header( $get, 'content-type' );
|
109 |
|
110 |
-
|
|
|
111 |
|
112 |
-
|
|
|
113 |
|
114 |
-
|
115 |
-
'post_title' => basename( $image_url ),
|
116 |
-
'post_mime_type' => $type
|
117 |
-
);
|
118 |
|
119 |
-
|
120 |
-
require_once ABSPATH . 'wp-admin/includes/image.php';
|
121 |
-
$attach_data = wp_generate_attachment_metadata( $attach_id, $mirror['file'] );
|
122 |
-
wp_update_attachment_metadata( $attach_id, $attach_data );
|
123 |
|
124 |
-
|
|
|
|
|
|
|
125 |
|
126 |
-
|
|
|
|
|
|
|
127 |
|
|
|
128 |
}
|
|
1 |
<?php
|
|
|
2 |
|
3 |
+
namespace Perfect_Woocommerce_Brands\Admin;
|
4 |
|
5 |
+
defined('ABSPATH') or die('No script kiddies please!');
|
6 |
|
7 |
+
class Brands_Exporter
|
8 |
+
{
|
|
|
|
|
|
|
9 |
|
10 |
+
function __construct()
|
11 |
+
{
|
12 |
+
add_action('after-pwb-brand-table', array($this, 'exporter_button'));
|
13 |
+
add_action('wp_ajax_pwb_brands_export', array($this, 'export_brands'));
|
14 |
+
add_action('wp_ajax_pwb_brands_import', array($this, 'import_brands'));
|
15 |
+
}
|
16 |
+
|
17 |
+
public function exporter_button()
|
18 |
+
{
|
19 |
+
echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
|
20 |
+
'brands-exporter',
|
21 |
+
'admin',
|
22 |
+
array('ok' => 'va')
|
23 |
+
);
|
24 |
+
}
|
25 |
|
26 |
+
public function export_brands()
|
27 |
+
{
|
28 |
+
if (isset($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'pwb_brands_export')) {
|
29 |
$this->get_brands();
|
30 |
+
} else {
|
31 |
+
wp_send_json_error();
|
32 |
}
|
33 |
+
wp_die();
|
34 |
+
}
|
35 |
|
36 |
+
private function get_brands()
|
37 |
+
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
$brands_data = array();
|
40 |
|
41 |
+
$brands = get_terms('pwb-brand', array('hide_empty' => false));
|
42 |
+
foreach ($brands as $brand) {
|
43 |
|
44 |
+
$current_brand = array(
|
45 |
+
'slug' => $brand->slug,
|
46 |
+
'name' => $brand->name,
|
47 |
+
'banner_link' => get_term_meta($brand->term_id, 'pwb_brand_banner_link', true),
|
48 |
+
'desc' => htmlentities($brand->description)
|
49 |
+
);
|
50 |
|
51 |
+
$image = get_term_meta($brand->term_id, 'pwb_brand_image', true);
|
52 |
+
$image = wp_get_attachment_image_src($image, 'full');
|
53 |
+
if ($image) $current_brand['image'] = $image[0];
|
54 |
|
55 |
+
$banner = get_term_meta($brand->term_id, 'pwb_brand_banner', true);
|
56 |
+
$banner = wp_get_attachment_image_src($banner, 'full');
|
57 |
+
if ($banner) $current_brand['banner'] = $banner[0];
|
58 |
|
59 |
+
$brands_data[] = $current_brand;
|
60 |
}
|
61 |
|
62 |
+
$export_file = fopen(WP_CONTENT_DIR . '/uploads/pwb-export.json', 'w');
|
63 |
+
fwrite($export_file, json_encode($brands_data));
|
64 |
+
fclose($export_file);
|
65 |
|
66 |
+
$result = array('export_file_url' => WP_CONTENT_URL . '/uploads/pwb-export.json');
|
|
|
67 |
|
68 |
+
wp_send_json_success($result);
|
69 |
+
}
|
70 |
|
71 |
+
public function import_brands()
|
72 |
+
{
|
73 |
|
74 |
+
if (isset($_FILES['file']) && isset($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'pwb_brands_import')) {
|
75 |
|
76 |
+
$file = $_FILES['file'];
|
|
|
|
|
|
|
77 |
|
78 |
+
$file_content = json_decode(file_get_contents($file['tmp_name']), true);
|
79 |
|
80 |
+
if (is_array($file_content)) {
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
+
foreach ($file_content as $brand) {
|
83 |
|
84 |
+
$new_brand = wp_insert_term($brand['name'], 'pwb-brand', array(
|
85 |
+
'slug' => $brand['slug'],
|
86 |
+
'description' => html_entity_decode($brand['desc'])
|
87 |
+
));
|
88 |
|
89 |
+
if (!is_wp_error($new_brand)) {
|
90 |
|
91 |
+
if (!empty($brand['image']))
|
92 |
+
$this->upload_remote_image_and_attach($brand['image'], $new_brand['term_id'], 'pwb_brand_image');
|
93 |
+
if (!empty($brand['banner']))
|
94 |
+
$this->upload_remote_image_and_attach($brand['banner'], $new_brand['term_id'], 'pwb_brand_banner');
|
95 |
+
if (!empty($brand['banner_link']))
|
96 |
+
update_term_meta($new_brand['term_id'], 'pwb_brand_banner_link', $brand['banner_link'], true);
|
97 |
+
}
|
98 |
}
|
99 |
|
100 |
+
wp_send_json_success();
|
101 |
+
} else {
|
|
|
102 |
wp_send_json_error();
|
103 |
}
|
104 |
+
} else {
|
105 |
+
wp_send_json_error();
|
106 |
}
|
107 |
|
108 |
+
wp_die();
|
109 |
+
}
|
|
|
|
|
110 |
|
111 |
+
private function upload_remote_image_and_attach($image_url, $term_id, $meta_key)
|
112 |
+
{
|
113 |
|
114 |
+
$get = wp_remote_get($image_url);
|
115 |
+
$type = wp_remote_retrieve_header($get, 'content-type');
|
116 |
|
117 |
+
if (!$type) return false;
|
|
|
|
|
|
|
118 |
|
119 |
+
$mirror = wp_upload_bits(basename($image_url), '', wp_remote_retrieve_body($get));
|
|
|
|
|
|
|
120 |
|
121 |
+
$attachment = array(
|
122 |
+
'post_title' => basename($image_url),
|
123 |
+
'post_mime_type' => $type
|
124 |
+
);
|
125 |
|
126 |
+
$attach_id = wp_insert_attachment($attachment, $mirror['file']);
|
127 |
+
require_once ABSPATH . 'wp-admin/includes/image.php';
|
128 |
+
$attach_data = wp_generate_attachment_metadata($attach_id, $mirror['file']);
|
129 |
+
wp_update_attachment_metadata($attach_id, $attach_data);
|
130 |
|
131 |
+
update_term_meta($term_id, $meta_key, $attach_id, true);
|
132 |
}
|
133 |
+
}
|
classes/class-perfect-woocommerce-brands.php
CHANGED
@@ -746,7 +746,11 @@ class Perfect_Woocommerce_Brands
|
|
746 |
'migrating' => esc_html__('We are migrating the product brands. ¡Don´t close this window until the process is finished!', 'perfect-woocommerce-brands'),
|
747 |
'dummy_data_notice' => esc_html__('¿Start loading dummy data?', 'perfect-woocommerce-brands'),
|
748 |
'dummy_data' => esc_html__('We are importing the dummy data. ¡Don´t close this window until the process is finished!', 'perfect-woocommerce-brands')
|
749 |
-
)
|
|
|
|
|
|
|
|
|
750 |
));
|
751 |
wp_enqueue_script('pwb-functions-admin');
|
752 |
}
|
746 |
'migrating' => esc_html__('We are migrating the product brands. ¡Don´t close this window until the process is finished!', 'perfect-woocommerce-brands'),
|
747 |
'dummy_data_notice' => esc_html__('¿Start loading dummy data?', 'perfect-woocommerce-brands'),
|
748 |
'dummy_data' => esc_html__('We are importing the dummy data. ¡Don´t close this window until the process is finished!', 'perfect-woocommerce-brands')
|
749 |
+
),
|
750 |
+
'nonce' => [
|
751 |
+
'import' => wp_create_nonce('pwb_brands_import'),
|
752 |
+
'export' => wp_create_nonce('pwb_brands_export'),
|
753 |
+
]
|
754 |
));
|
755 |
wp_enqueue_script('pwb-functions-admin');
|
756 |
}
|
perfect-woocommerce-brands.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Plugin Name: Perfect Brands for WooCommerce
|
5 |
* Plugin URI: https://quadlayers.com/portfolio/perfect-woocommerce-brands/
|
6 |
* Description: Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store.
|
7 |
-
* Version: 2.0.
|
8 |
* Author: QuadLayers
|
9 |
* Author URI: https://quadlayers.com
|
10 |
* Text Domain: perfect-woocommerce-brands
|
@@ -36,7 +36,7 @@ define('PWB_PLUGIN_FILE', __FILE__);
|
|
36 |
define('PWB_PLUGIN_URL', plugins_url('', __FILE__));
|
37 |
define('PWB_PLUGIN_DIR', __DIR__ . DIRECTORY_SEPARATOR);
|
38 |
define('PWB_PLUGIN_BASENAME', plugin_basename(__FILE__));
|
39 |
-
define('PWB_PLUGIN_VERSION', '2.0.
|
40 |
define('PWB_PLUGIN_NAME', 'Perfect WooCommerce Brands');
|
41 |
define('PWB_PREFIX', 'pwb');
|
42 |
define('PWB_REVIEW_URL', 'https://wordpress.org/support/plugin/perfect-woocommerce-brands/reviews/?filter=5#new-post');
|
4 |
* Plugin Name: Perfect Brands for WooCommerce
|
5 |
* Plugin URI: https://quadlayers.com/portfolio/perfect-woocommerce-brands/
|
6 |
* Description: Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store.
|
7 |
+
* Version: 2.0.3
|
8 |
* Author: QuadLayers
|
9 |
* Author URI: https://quadlayers.com
|
10 |
* Text Domain: perfect-woocommerce-brands
|
36 |
define('PWB_PLUGIN_URL', plugins_url('', __FILE__));
|
37 |
define('PWB_PLUGIN_DIR', __DIR__ . DIRECTORY_SEPARATOR);
|
38 |
define('PWB_PLUGIN_BASENAME', plugin_basename(__FILE__));
|
39 |
+
define('PWB_PLUGIN_VERSION', '2.0.3');
|
40 |
define('PWB_PLUGIN_NAME', 'Perfect WooCommerce Brands');
|
41 |
define('PWB_PREFIX', 'pwb');
|
42 |
define('PWB_REVIEW_URL', 'https://wordpress.org/support/plugin/perfect-woocommerce-brands/reviews/?filter=5#new-post');
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Tags: woocommerce, woocommerce brands, woocommerce product, woocommerce manufact
|
|
5 |
Requires at least: 4.7
|
6 |
Tested up to: 5.8
|
7 |
Requires PHP: 5.6
|
8 |
-
Stable tag: 2.0.
|
9 |
WC requires at least: 3.0
|
10 |
WC tested up to: 6.0
|
11 |
License: GPLv3
|
@@ -90,6 +90,8 @@ You can also contribute [translating the plugin](https://translate.wordpress.org
|
|
90 |
|
91 |
|
92 |
== Changelog ==
|
|
|
|
|
93 |
= 2.0.2 =
|
94 |
* Fix: WooCommerce compatibility
|
95 |
= 2.0.1 =
|
5 |
Requires at least: 4.7
|
6 |
Tested up to: 5.8
|
7 |
Requires PHP: 5.6
|
8 |
+
Stable tag: 2.0.3
|
9 |
WC requires at least: 3.0
|
10 |
WC tested up to: 6.0
|
11 |
License: GPLv3
|
90 |
|
91 |
|
92 |
== Changelog ==
|
93 |
+
= 2.0.3 =
|
94 |
+
* Fix: Security fix
|
95 |
= 2.0.2 =
|
96 |
* Fix: WooCommerce compatibility
|
97 |
= 2.0.1 =
|