Perfect Brands for WooCommerce - Version 1.8.4

Version Description

  • Enhancement: dynamic data escaped
Download this release

Release Info

Developer quadlayers
Plugin Icon 128x128 Perfect Brands for WooCommerce
Version 1.8.4
Comparing to
See all releases

Code changes from version 1.8.3 to 1.8.4

assets/js/functions-admin.js CHANGED
@@ -1,42 +1,43 @@
1
- jQuery( function ( $ ) {
 
2
 
3
  var media_uploader = null;
4
 
5
- function open_media_uploader_image( event, imageSelectorButton ){
6
 
7
  var $imageSelectorScope = imageSelectorButton.parent();
8
 
9
  media_uploader = wp.media({
10
- frame: "post",
11
- state: "insert",
12
  multiple: false
13
  });
14
 
15
- media_uploader.on("insert", function(){
16
  var json = media_uploader.state().get("selection").first().toJSON();
17
  var image_id = json.id;
18
  var image_url = json.url;
19
- var image_html = '<img src="'+image_url+'" width="90" height="90">';
20
 
21
  var current_selector = '';
22
  switch (event.target.id) {
23
- case 'pwb_brand_image_select':
24
- current_selector = '.taxonomy-pwb-brand #pwb_brand_'+'image';
25
- break;
26
- case 'pwb_brand_banner_select':
27
- current_selector = '.taxonomy-pwb-brand #pwb_brand_'+'banner';
28
- break;
29
  }
30
 
31
  $(current_selector).val(image_id);
32
- $(current_selector+'_result').remove();
33
 
34
- if( $('.pwb_brand_image_selected',$imageSelectorScope).length ){
35
- $('.pwb_brand_image_selected span', $imageSelectorScope).html(image_html);
36
- }else{
37
- $imageSelectorScope.append('<div class="pwb_brand_image_selected"><span>'+image_html+'</span></div>');
38
  }
39
- add_delete_link( $imageSelectorScope );
40
 
41
  });
42
 
@@ -44,304 +45,308 @@ jQuery( function ( $ ) {
44
  }
45
 
46
 
47
- $('.taxonomy-pwb-brand #pwb_brand_image_select, .taxonomy-pwb-brand #pwb_brand_banner_select').on('click',function(event){
48
- open_media_uploader_image( event, $(this) );
49
  });
50
 
51
  //bind remove image event for edit page
52
- $('.taxonomy-pwb-brand #pwb_brand_image_select, .taxonomy-pwb-brand #pwb_brand_banner_select').each(function(){
53
- add_delete_link( $(this).parent() );
54
  });
55
 
56
  //clear custom fields when brand is added
57
- if( $('body').hasClass('edit-tags-php') && $('body').hasClass('taxonomy-pwb-brand') ){
58
- jQuery( document ).ajaxSuccess(function( event, xhr, settings ) {
59
- //Check ajax action of request that succeeded
60
- if( typeof settings != "undefined" && settings.data && ~settings.data.indexOf("action=add-tag") && ~settings.data.indexOf("taxonomy=pwb-brand") ) {
61
- $('#pwb_brand_image').val('');
62
- $('#pwb_brand_banner').val('');
63
- $('.pwb_brand_image_selected').remove();
64
- }
65
- });
66
  }
67
 
68
- function add_delete_link( $imageSelectorScope ){
69
 
70
- $( '.pwb_brand_image_selected span', $imageSelectorScope ).append('<a href="#" class="pwb_brand_image_selected_remove">X</a>');
71
 
72
- $( '.pwb_brand_image_selected_remove', $imageSelectorScope ).on( 'click', function( event ){
73
 
74
- event.preventDefault();
75
- $(this).closest('.pwb_brand_image_selected').remove();
76
 
77
- //remove the img
78
- $('#pwb_brand_image',$imageSelectorScope).val('');
79
- $('#pwb_brand_banner',$imageSelectorScope).val('');
80
 
81
- });
82
 
83
  }
84
 
85
  /* ····························· Edit brands page ····························· */
86
- $('.taxonomy-pwb-brand table .column-featured > span').not('pwb-blocked').on('click', function(e){
87
- e.preventDefault();
88
- var $currentStar = $(this);
89
- $currentStar.addClass('pwb-blocked');
90
- if( $currentStar.hasClass('dashicons-star-filled') ){
91
- $currentStar.removeClass('dashicons-star-filled');
92
- $currentStar.addClass('dashicons-star-empty');
93
- }else{
94
- $currentStar.removeClass('dashicons-star-empty');
95
- $currentStar.addClass('dashicons-star-filled');
96
- }
97
- var data = { 'action': 'pwb_admin_set_featured_brand', 'brand': $currentStar.data('brand-id') };
98
- $.post(pwb_ajax_object_admin.ajax_url, data, function( response ) {
99
- $currentStar.removeClass('pwb-blocked');
100
- if( response.success ){
101
- var $featuredCount = $('.taxonomy-pwb-brand .pwb-featured-count > span');
102
- if( response.data.direction == 'up' ){
103
- $featuredCount.html( parseInt( $featuredCount.text() ) + 1 );
104
- }else{
105
- $featuredCount.html( parseInt( $featuredCount.text() ) - 1 );
106
- }
107
- }else{
108
- alert( response.data.error_msg );
109
  }
110
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  });
112
 
113
- $('.taxonomy-pwb-brand #pwb-first-featured-brands').on('change', function(e){
114
- e.preventDefault();
115
- $('#screen-options-apply').replaceWith('<img src="'+pwb_ajax_object_admin.site_url+'/wp-admin/images/loading.gif">');
116
- var data = { 'action': 'pwb_admin_save_screen_settings', 'new_val': $(this).is(':checked') };
117
- $.post(pwb_ajax_object_admin.ajax_url, data, function(response) { location.reload(); });
118
  });
119
 
120
- $('.pwb-edit-brands-bottom > span').on('click', function(e){
121
- e.preventDefault();
122
- $('.taxonomy-pwb-brand #col-left').toggleClass('pwb-force-full-width');
123
- $('.taxonomy-pwb-brand #col-right').toggleClass('pwb-force-full-width');
124
  });
125
  /* ····························· /Edit brands page ····························· */
126
 
127
  /* ····························· Settings tab ····························· */
128
 
129
- if( $('.pwb-admin-selectwoo').length ){
130
- $('.pwb-admin-selectwoo').selectWoo();
131
  }
132
 
133
  // migrate brands
134
- $('#wc_pwb_admin_tab_tools_migrate').on( 'change', function(){
135
 
136
- if( $(this).val() != '-' ){
137
 
138
- if( confirm(pwb_ajax_object_admin.translations.migrate_notice) ){
139
 
140
- $('html').append('<div class="pwb-modal"><div class="pwb-modal-inner"></div></div>');
141
- $('.pwb-modal-inner').html('<p>'+pwb_ajax_object_admin.translations.migrating+'</p>');
142
 
143
- var data = {
144
- 'action': 'pwb_admin_migrate_brands',
145
- 'from': $(this).val()
146
- };
147
- $.post(pwb_ajax_object_admin.ajax_url, data, function(response) {
148
 
149
- setTimeout( function(){
150
- location.href = pwb_ajax_object_admin.brands_url;
151
- }, 1000 );
152
 
153
- });
154
 
155
- }else{
156
 
157
- }
158
 
159
- }
160
 
161
- $(this).val('-');//reset to default value
162
 
163
- } );
164
 
165
  // dummy data
166
- $('#wc_pwb_admin_tab_tools_dummy_data').on( 'change', function(){
167
 
168
- if( $(this).val() != '-' ){
169
 
170
- if( confirm(pwb_ajax_object_admin.translations.dummy_data_notice) ){
171
 
172
- $('html').append('<div class="pwb-modal"><div class="pwb-modal-inner"></div></div>');
173
- $('.pwb-modal-inner').html('<p>'+pwb_ajax_object_admin.translations.dummy_data+'</p>');
174
 
175
- var data = {
176
- 'action': 'pwb_admin_dummy_data',
177
- 'from': $(this).val()
178
- };
179
- $.post(pwb_ajax_object_admin.ajax_url, data, function(response) {
180
 
181
- setTimeout( function(){
182
- location.href = pwb_ajax_object_admin.brands_url;
183
- }, 1000 );
184
 
185
- });
186
 
187
- }else{
188
 
189
- }
190
 
191
- }
192
 
193
- $(this).val('-');//reset to default value
194
 
195
- } );
196
 
197
  var $systemStatusBtn = $('#wc_pwb_admin_tab_tools_system_status').siblings('p');
198
  $systemStatusBtn.addClass('button wc_pwb_admin_tab_status_btn');
199
- $('.wc_pwb_admin_tab_status_btn').on( 'click', function(e){
200
- e.preventDefault();
201
- if( !$('#wc_pwb_admin_status_result').length ){
202
- $systemStatusTextarea = $('#wc_pwb_admin_tab_tools_system_status');
203
- $('<pre id="wc_pwb_admin_status_result"></pre>').insertAfter($systemStatusTextarea);
204
- jQuery( '#wc_pwb_admin_status_result' ).click( function(e) {
205
- e.preventDefault();
206
- var refNode = $( this )[0];
207
- if ( $.browser.msie ) {
208
- var range = document.body.createTextRange();
209
- range.moveToElementText( refNode );
210
- range.select();
211
- } else if ( $.browser.mozilla || $.browser.opera ) {
212
- var selection = window.getSelection();
213
- var range = document.createRange();
214
- range.selectNodeContents( refNode );
215
- selection.removeAllRanges();
216
- selection.addRange( range );
217
- } else if ( $.browser.safari ) {
218
- var selection = window.getSelection();
219
- selection.setBaseAndExtent( refNode, 0, refNode, 1 );
220
- }
221
- } );
222
- }
223
- $('#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">');
224
- $('#wc_pwb_admin_status_result').show();
225
- var data = {
226
- 'action': 'pwb_system_status'
227
- };
228
- jQuery.post(ajaxurl, data, function(response) {
229
- $('#wc_pwb_admin_status_result').html(response);
230
- $('#wc_pwb_admin_status_result').trigger('click');
231
- });
232
-
233
- } );
234
 
235
  /* ····························· /Settings tab ····························· */
236
 
237
  /* ····························· Admin notices ····························· */
238
- $( document ).on( 'click', '.pwb-notice-dismissible .notice-dismiss', function(e) {
239
 
240
- e.preventDefault();
241
 
242
- var noticeName = $( this ).closest( '.pwb-notice-dismissible' ).data( 'notice' );
243
 
244
- var data = {
245
- 'action': 'dismiss_pwb_notice',
246
- 'notice_name': noticeName
247
- };
248
- jQuery.post(ajaxurl, data, function(response) {
249
- //callback
250
- });
251
 
252
- } );
253
  /* ····························· /Admin notices ····························· */
254
 
255
  /* ····························· Widgets ····························· */
256
  pwbBindEventsToWigets();
257
  //Fires when a widget is added to a sidebar
258
- jQuery(document).bind('widget-added',function(e, widget){
259
- pwbBindEventsToWigets( widget );
260
  });
261
  //Fires on widget save
262
- jQuery(document).on('widget-updated', function(e, widget){
263
- pwbBindEventsToWigets( widget );
264
  });
265
- function pwbBindEventsToWigets( widget ){
266
- $currentWidget = $(".pwb-select-display-as");
267
- if( widget != undefined ){
268
- $currentWidget = $(".pwb-select-display-as", widget);
269
- }
270
- $currentWidget.on("change",function(){
271
- if( $(this).val()=="brand_logo" ){
272
- $(this).parent().siblings(".pwb-display-as-logo").addClass("show");
273
- }else{
274
- $(this).parent().siblings(".pwb-display-as-logo").removeClass("show");
275
  }
276
- });
 
 
 
 
 
 
277
  }
278
  /* ····························· /Widgets ····························· */
279
 
280
  /* ····························· Brands exporter ····························· */
281
- $('button.pwb-brands-export').on('click', function(e){
282
- e.preventDefault();
283
-
284
- var $clickedBtn = $(this);
285
- $clickedBtn.addClass('pwb-loading-overlay');
286
- $clickedBtn.prop("disabled",true);
287
-
288
- var data = { 'action': 'pwb_brands_export' };
289
- $.post(pwb_ajax_object_admin.ajax_url, data, function(response) {
290
-
291
- if( response.success ){
292
- $clickedBtn.removeClass('pwb-loading-overlay');
293
- $clickedBtn.prop("disabled",false);
294
-
295
- //descarga el archivo json de exportación
296
- $('#pwb-download-export-file').remove();
297
- var link = document.createElement("a");
298
- link.download = 'brands.json';
299
- link.id = 'pwb-download-export-file';
300
- link.href = response.data.export_file_url;
301
- $('body').append( link );
302
- link.click();
303
- }
304
 
305
- });
306
 
307
- });
308
 
309
- $('button.pwb-brands-import').on('click', function(e){
310
- e.preventDefault();
311
- $('input.pwb-brands-import-file').trigger('click');
312
  });
313
- $('input.pwb-brands-import-file').on('change', function(e){
314
- e.preventDefault();
315
-
316
- var $clickedBtn = $('button.pwb-brands-import');
317
- $clickedBtn.addClass('pwb-loading-overlay');
318
- $clickedBtn.prop("disabled",true);
319
-
320
- var file = $(this)[0].files[0];
321
-
322
- var reqData = new FormData();
323
- reqData.append('action', 'pwb_brands_import');
324
- reqData.append('file', file);
325
-
326
- $.ajax({
327
- url: pwb_ajax_object_admin.ajax_url,
328
- type: 'post',
329
- cache: false,
330
- dataType: 'json',
331
- contentType: false,
332
- processData: false,
333
- data: reqData,
334
- success: function( resp ){
335
- if( resp.success ){
336
- $clickedBtn.removeClass('pwb-loading-overlay');
337
- location.reload();
338
- }else{
339
- alert('Importer error');
340
- }
341
- }
342
- });
 
343
 
344
  })
 
345
  /* ····························· /Brands exporter ····························· */
346
 
347
- });
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
 
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 = { 'action': 'pwb_brands_export' };
292
+ $.post(pwb_ajax_object_admin.ajax_url, data, function (response) {
293
+
294
+ if (response.success) {
295
+ $clickedBtn.removeClass('pwb-loading-overlay');
296
+ $clickedBtn.prop("disabled", false);
297
+
298
+ //download export file
299
+ $('#pwb-download-export-file').remove();
300
+ var link = document.createElement("a");
301
+ link.download = 'brands.json';
302
+ link.id = 'pwb-download-export-file';
303
+ link.href = response.data.export_file_url;
304
+ $('body').append(link);
305
+ link.click();
306
+ }
307
 
308
+ });
309
 
310
+ })
311
 
312
+ $('button.pwb-brands-import').on('click', function (e) {
313
+ e.preventDefault();
314
+ $('input.pwb-brands-import-file').trigger('click');
315
  });
316
+
317
+ $('input.pwb-brands-import-file').on('change', function (e) {
318
+ e.preventDefault();
319
+
320
+ var $clickedBtn = $('button.pwb-brands-import');
321
+ $clickedBtn.addClass('pwb-loading-overlay');
322
+ $clickedBtn.prop("disabled", true);
323
+
324
+ var file = $(this)[0].files[0];
325
+
326
+ var reqData = new FormData();
327
+ reqData.append('action', 'pwb_brands_import');
328
+ reqData.append('file', file);
329
+
330
+ $.ajax({
331
+ url: pwb_ajax_object_admin.ajax_url,
332
+ type: 'post',
333
+ cache: false,
334
+ dataType: 'json',
335
+ contentType: false,
336
+ processData: false,
337
+ data: reqData,
338
+ success: function (resp) {
339
+ if (resp.success) {
340
+ $clickedBtn.removeClass('pwb-loading-overlay');
341
+ location.reload();
342
+ } else {
343
+ alert('Importer error');
344
+ }
345
+ }
346
+ });
347
 
348
  })
349
+
350
  /* ····························· /Brands exporter ····························· */
351
 
352
+ })(jQuery)
assets/js/functions-admin.min.js CHANGED
@@ -1 +1 @@
1
- jQuery(function(d){var b=null;function a(h,g){var i=g.parent();b=wp.media({frame:"post",state:"insert",multiple:false});b.on("insert",function(){var l=b.state().get("selection").first().toJSON();var m=l.id;var n=l.url;var k='<img src="'+n+'" width="90" height="90">';var j="";switch(h.target.id){case"pwb_brand_image_select":j=".taxonomy-pwb-brand #pwb_brand_image";break;case"pwb_brand_banner_select":j=".taxonomy-pwb-brand #pwb_brand_banner";break}d(j).val(m);d(j+"_result").remove();if(d(".pwb_brand_image_selected",i).length){d(".pwb_brand_image_selected span",i).html(k)}else{i.append('<div class="pwb_brand_image_selected"><span>'+k+"</span></div>")}c(i)});b.open()}d(".taxonomy-pwb-brand #pwb_brand_image_select, .taxonomy-pwb-brand #pwb_brand_banner_select").on("click",function(g){a(g,d(this))});d(".taxonomy-pwb-brand #pwb_brand_image_select, .taxonomy-pwb-brand #pwb_brand_banner_select").each(function(){c(d(this).parent())});if(d("body").hasClass("edit-tags-php")&&d("body").hasClass("taxonomy-pwb-brand")){jQuery(document).ajaxSuccess(function(h,i,g){if(typeof g!="undefined"&&g.data&&~g.data.indexOf("action=add-tag")&&~g.data.indexOf("taxonomy=pwb-brand")){d("#pwb_brand_image").val("");d("#pwb_brand_banner").val("");d(".pwb_brand_image_selected").remove()}})}function c(g){d(".pwb_brand_image_selected span",g).append('<a href="#" class="pwb_brand_image_selected_remove">X</a>');d(".pwb_brand_image_selected_remove",g).on("click",function(h){h.preventDefault();d(this).closest(".pwb_brand_image_selected").remove();d("#pwb_brand_image",g).val("");d("#pwb_brand_banner",g).val("")})}d(".taxonomy-pwb-brand table .column-featured > span").not("pwb-blocked").on("click",function(h){h.preventDefault();var i=d(this);i.addClass("pwb-blocked");if(i.hasClass("dashicons-star-filled")){i.removeClass("dashicons-star-filled");i.addClass("dashicons-star-empty")}else{i.removeClass("dashicons-star-empty");i.addClass("dashicons-star-filled")}var g={action:"pwb_admin_set_featured_brand",brand:i.data("brand-id")};d.post(pwb_ajax_object_admin.ajax_url,g,function(j){i.removeClass("pwb-blocked");if(j.success){var k=d(".taxonomy-pwb-brand .pwb-featured-count > span");if(j.data.direction=="up"){k.html(parseInt(k.text())+1)}else{k.html(parseInt(k.text())-1)}}else{alert(j.data.error_msg)}})});d(".taxonomy-pwb-brand #pwb-first-featured-brands").on("change",function(h){h.preventDefault();d("#screen-options-apply").replaceWith('<img src="'+pwb_ajax_object_admin.site_url+'/wp-admin/images/loading.gif">');var g={action:"pwb_admin_save_screen_settings",new_val:d(this).is(":checked")};d.post(pwb_ajax_object_admin.ajax_url,g,function(i){location.reload()})});d(".pwb-edit-brands-bottom > span").on("click",function(g){g.preventDefault();d(".taxonomy-pwb-brand #col-left").toggleClass("pwb-force-full-width");d(".taxonomy-pwb-brand #col-right").toggleClass("pwb-force-full-width")});if(d(".pwb-admin-selectwoo").length){d(".pwb-admin-selectwoo").selectWoo()}d("#wc_pwb_admin_tab_tools_migrate").on("change",function(){if(d(this).val()!="-"){if(confirm(pwb_ajax_object_admin.translations.migrate_notice)){d("html").append('<div class="pwb-modal"><div class="pwb-modal-inner"></div></div>');d(".pwb-modal-inner").html("<p>"+pwb_ajax_object_admin.translations.migrating+"</p>");var g={action:"pwb_admin_migrate_brands",from:d(this).val()};d.post(pwb_ajax_object_admin.ajax_url,g,function(h){setTimeout(function(){location.href=pwb_ajax_object_admin.brands_url},1000)})}else{}}d(this).val("-")});d("#wc_pwb_admin_tab_tools_dummy_data").on("change",function(){if(d(this).val()!="-"){if(confirm(pwb_ajax_object_admin.translations.dummy_data_notice)){d("html").append('<div class="pwb-modal"><div class="pwb-modal-inner"></div></div>');d(".pwb-modal-inner").html("<p>"+pwb_ajax_object_admin.translations.dummy_data+"</p>");var g={action:"pwb_admin_dummy_data",from:d(this).val()};d.post(pwb_ajax_object_admin.ajax_url,g,function(h){setTimeout(function(){location.href=pwb_ajax_object_admin.brands_url},1000)})}else{}}d(this).val("-")});var f=d("#wc_pwb_admin_tab_tools_system_status").siblings("p");f.addClass("button wc_pwb_admin_tab_status_btn");d(".wc_pwb_admin_tab_status_btn").on("click",function(h){h.preventDefault();if(!d("#wc_pwb_admin_status_result").length){$systemStatusTextarea=d("#wc_pwb_admin_tab_tools_system_status");d('<pre id="wc_pwb_admin_status_result"></pre>').insertAfter($systemStatusTextarea);jQuery("#wc_pwb_admin_status_result").click(function(l){l.preventDefault();var j=d(this)[0];if(d.browser.msie){var i=document.body.createTextRange();i.moveToElementText(j);i.select()}else{if(d.browser.mozilla||d.browser.opera){var k=window.getSelection();var i=document.createRange();i.selectNodeContents(j);k.removeAllRanges();k.addRange(i)}else{if(d.browser.safari){var k=window.getSelection();k.setBaseAndExtent(j,0,j,1)}}}})}d("#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">');d("#wc_pwb_admin_status_result").show();var g={action:"pwb_system_status"};jQuery.post(ajaxurl,g,function(i){d("#wc_pwb_admin_status_result").html(i);d("#wc_pwb_admin_status_result").trigger("click")})});d(document).on("click",".pwb-notice-dismissible .notice-dismiss",function(i){i.preventDefault();var g=d(this).closest(".pwb-notice-dismissible").data("notice");var h={action:"dismiss_pwb_notice",notice_name:g};jQuery.post(ajaxurl,h,function(j){})});e();jQuery(document).bind("widget-added",function(h,g){e(g)});jQuery(document).on("widget-updated",function(h,g){e(g)});function e(g){$currentWidget=d(".pwb-select-display-as");if(g!=undefined){$currentWidget=d(".pwb-select-display-as",g)}$currentWidget.on("change",function(){if(d(this).val()=="brand_logo"){d(this).parent().siblings(".pwb-display-as-logo").addClass("show")}else{d(this).parent().siblings(".pwb-display-as-logo").removeClass("show")}})}d("button.pwb-brands-export").on("click",function(i){i.preventDefault();var h=d(this);h.addClass("pwb-loading-overlay");h.prop("disabled",true);var g={action:"pwb_brands_export"};d.post(pwb_ajax_object_admin.ajax_url,g,function(j){if(j.success){h.removeClass("pwb-loading-overlay");h.prop("disabled",false);d("#pwb-download-export-file").remove();var k=document.createElement("a");k.download="brands.json";k.id="pwb-download-export-file";k.href=j.data.export_file_url;d("body").append(k);k.click()}})});d("button.pwb-brands-import").on("click",function(g){g.preventDefault();d("input.pwb-brands-import-file").trigger("click")});d("input.pwb-brands-import-file").on("change",function(j){j.preventDefault();var i=d("button.pwb-brands-import");i.addClass("pwb-loading-overlay");i.prop("disabled",true);var h=d(this)[0].files[0];var g=new FormData();g.append("action","pwb_brands_import");g.append("file",h);d.ajax({url:pwb_ajax_object_admin.ajax_url,type:"post",cache:false,dataType:"json",contentType:false,processData:false,data:g,success:function(k){if(k.success){i.removeClass("pwb-loading-overlay");location.reload()}else{alert("Importer error")}}})})});
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);
assets/js/functions-frontend.js CHANGED
@@ -1,140 +1,141 @@
1
- jQuery( function ( $ ) {
 
2
 
3
- $('.pwb-dropdown-widget').on('change',function(){
4
  var href = $(this).find(":selected").val();
5
  location.href = href;
6
  });
7
 
8
- if( typeof $.fn.slick === 'function' ){
9
-
10
- $('.pwb-carousel').slick({
11
- slide: '.pwb-slick-slide',
12
- infinite: true,
13
- draggable: false,
14
- prevArrow: '<div class="slick-prev"><span>'+pwb_ajax_object.carousel_prev+'</span></div>',
15
- nextArrow: '<div class="slick-next"><span>'+pwb_ajax_object.carousel_next+'</span></div>',
16
- speed: 300,
17
- lazyLoad: 'progressive',
18
- responsive: [
19
- {
20
- breakpoint: 1024,
21
- settings: {
22
- slidesToShow: 4,
23
- draggable: true,
24
- arrows: false
25
- }
26
- },
27
- {
28
- breakpoint: 600,
29
- settings: {
30
- slidesToShow: 3,
31
- draggable: true,
32
- arrows: false
33
- }
34
- },
35
- {
36
- breakpoint: 480,
37
- settings: {
38
- slidesToShow: 2,
39
- draggable: true,
40
- arrows: false
41
- }
42
- }
43
- ]
44
- });
45
-
46
- $('.pwb-product-carousel').slick({
47
- slide: '.pwb-slick-slide',
48
- infinite: true,
49
- draggable: false,
50
- prevArrow: '<div class="slick-prev"><span>'+pwb_ajax_object.carousel_prev+'</span></div>',
51
- nextArrow: '<div class="slick-next"><span>'+pwb_ajax_object.carousel_next+'</span></div>',
52
- speed: 300,
53
- lazyLoad: 'progressive',
54
- responsive: [
55
- {
56
- breakpoint: 1024,
57
- settings: {
58
- slidesToShow: 3,
59
- draggable: true,
60
- arrows: false
61
- }
62
- },
63
- {
64
- breakpoint: 600,
65
- settings: {
66
- slidesToShow: 2,
67
- draggable: true,
68
- arrows: false
69
- }
70
- },
71
- {
72
- breakpoint: 480,
73
- settings: {
74
- slidesToShow: 1,
75
- draggable: true,
76
- arrows: false
77
- }
78
- }
79
- ]
80
- });
81
 
82
  }
83
 
84
  /* ··························· Filter by brand widget ··························· */
85
 
86
- var PWBFilterByBrand = function(){
87
 
88
- var baseUrl = [location.protocol, '//', location.host, location.pathname].join('');
89
- var currentUrl = window.location.href;
90
 
91
- var marcas = [];
92
- $('.pwb-filter-products input[type="checkbox"]').each(function(index){
93
- if( $(this).prop('checked') ) marcas.push( $(this).val() );
94
- });
95
- marcas = marcas.join();
96
 
97
- if( marcas ){
98
 
99
- //removes previous "pwb-brand" from url
100
- currentUrl = currentUrl.replace(/&?pwb-brand-filter=([^&]$|[^&]*)/i, "");
101
 
102
- //removes pagination
103
- currentUrl = currentUrl.replace(/\/page\/\d*\//i, "");
104
 
105
- if( currentUrl.indexOf("?") === -1 ){
106
- currentUrl = currentUrl + '?pwb-brand-filter='+marcas;
107
- }else{
108
- currentUrl = currentUrl + '&pwb-brand-filter='+marcas;
109
- }
110
 
111
- }else{
112
- currentUrl = baseUrl;
113
- }
114
 
115
- location.href = currentUrl;
116
 
117
  }
118
 
119
- $('.pwb-filter-products button').on( 'click', function(){ PWBFilterByBrand(); } );
120
- $('.pwb-filter-products.pwb-hide-submit-btn input').on( 'change', function(){ PWBFilterByBrand(); } );
121
 
122
  var brands = PWBgetUrlParameter('pwb-brand-filter');
123
 
124
- if(brands!=null){
125
- var brands_array = brands.split(',');
126
- $('.pwb-filter-products input[type="checkbox"]').prop('checked',false);
127
- for ( var i = 0, l = brands_array.length; i < l; i++ ) {
128
- $('.pwb-filter-products input[type="checkbox"]').each(function(index){
129
- if($(this).val()){
130
- if(brands_array[i]==$(this).val()){
131
- $(this).prop('checked',true);
132
- }
133
- }
134
- });
135
- }
136
- }else{
137
- $('.pwb-filter-products input[type="checkbox"]').prop('checked', false);
138
  }
139
 
140
  /* ··························· /Filter by brand widget ··························· */
1
+ jQuery(function ($) {
2
+ "use strict";
3
 
4
+ $('.pwb-dropdown-widget').on('change', function () {
5
  var href = $(this).find(":selected").val();
6
  location.href = href;
7
  });
8
 
9
+ if (typeof $.fn.slick === 'function') {
10
+
11
+ $('.pwb-carousel').slick({
12
+ slide: '.pwb-slick-slide',
13
+ infinite: true,
14
+ draggable: false,
15
+ prevArrow: '<div class="slick-prev"><span>' + pwb_ajax_object.carousel_prev + '</span></div>',
16
+ nextArrow: '<div class="slick-next"><span>' + pwb_ajax_object.carousel_next + '</span></div>',
17
+ speed: 300,
18
+ lazyLoad: 'progressive',
19
+ responsive: [
20
+ {
21
+ breakpoint: 1024,
22
+ settings: {
23
+ slidesToShow: 4,
24
+ draggable: true,
25
+ arrows: false
26
+ }
27
+ },
28
+ {
29
+ breakpoint: 600,
30
+ settings: {
31
+ slidesToShow: 3,
32
+ draggable: true,
33
+ arrows: false
34
+ }
35
+ },
36
+ {
37
+ breakpoint: 480,
38
+ settings: {
39
+ slidesToShow: 2,
40
+ draggable: true,
41
+ arrows: false
42
+ }
43
+ }
44
+ ]
45
+ });
46
+
47
+ $('.pwb-product-carousel').slick({
48
+ slide: '.pwb-slick-slide',
49
+ infinite: true,
50
+ draggable: false,
51
+ prevArrow: '<div class="slick-prev"><span>' + pwb_ajax_object.carousel_prev + '</span></div>',
52
+ nextArrow: '<div class="slick-next"><span>' + pwb_ajax_object.carousel_next + '</span></div>',
53
+ speed: 300,
54
+ lazyLoad: 'progressive',
55
+ responsive: [
56
+ {
57
+ breakpoint: 1024,
58
+ settings: {
59
+ slidesToShow: 3,
60
+ draggable: true,
61
+ arrows: false
62
+ }
63
+ },
64
+ {
65
+ breakpoint: 600,
66
+ settings: {
67
+ slidesToShow: 2,
68
+ draggable: true,
69
+ arrows: false
70
+ }
71
+ },
72
+ {
73
+ breakpoint: 480,
74
+ settings: {
75
+ slidesToShow: 1,
76
+ draggable: true,
77
+ arrows: false
78
+ }
79
+ }
80
+ ]
81
+ });
82
 
83
  }
84
 
85
  /* ··························· Filter by brand widget ··························· */
86
 
87
+ var PWBFilterByBrand = function () {
88
 
89
+ var baseUrl = [location.protocol, '//', location.host, location.pathname].join('');
90
+ var currentUrl = window.location.href;
91
 
92
+ var marcas = [];
93
+ $('.pwb-filter-products input[type="checkbox"]').each(function (index) {
94
+ if ($(this).prop('checked')) marcas.push($(this).val());
95
+ });
96
+ marcas = marcas.join();
97
 
98
+ if (marcas) {
99
 
100
+ //removes previous "pwb-brand" from url
101
+ currentUrl = currentUrl.replace(/&?pwb-brand-filter=([^&]$|[^&]*)/i, "");
102
 
103
+ //removes pagination
104
+ currentUrl = currentUrl.replace(/\/page\/\d*\//i, "");
105
 
106
+ if (currentUrl.indexOf("?") === -1) {
107
+ currentUrl = currentUrl + '?pwb-brand-filter=' + marcas;
108
+ } else {
109
+ currentUrl = currentUrl + '&pwb-brand-filter=' + marcas;
110
+ }
111
 
112
+ } else {
113
+ currentUrl = baseUrl;
114
+ }
115
 
116
+ location.href = currentUrl;
117
 
118
  }
119
 
120
+ $('.pwb-filter-products button').on('click', function () { PWBFilterByBrand(); });
121
+ $('.pwb-filter-products.pwb-hide-submit-btn input').on('change', function () { PWBFilterByBrand(); });
122
 
123
  var brands = PWBgetUrlParameter('pwb-brand-filter');
124
 
125
+ if (brands != null) {
126
+ var brands_array = brands.split(',');
127
+ $('.pwb-filter-products input[type="checkbox"]').prop('checked', false);
128
+ for (var i = 0, l = brands_array.length; i < l; i++) {
129
+ $('.pwb-filter-products input[type="checkbox"]').each(function (index) {
130
+ if ($(this).val()) {
131
+ if (brands_array[i] == $(this).val()) {
132
+ $(this).prop('checked', true);
133
+ }
134
+ }
135
+ });
136
+ }
137
+ } else {
138
+ $('.pwb-filter-products input[type="checkbox"]').prop('checked', false);
139
  }
140
 
141
  /* ··························· /Filter by brand widget ··························· */
assets/js/functions-frontend.min.js CHANGED
@@ -1 +1 @@
1
- jQuery(function(e){e(".pwb-dropdown-widget").on("change",function(){var g=e(this).find(":selected").val();location.href=g});if(typeof e.fn.slick==="function"){e(".pwb-carousel").slick({slide:".pwb-slick-slide",infinite:true,draggable:false,prevArrow:'<div class="slick-prev"><span>'+pwb_ajax_object.carousel_prev+"</span></div>",nextArrow:'<div class="slick-next"><span>'+pwb_ajax_object.carousel_next+"</span></div>",speed:300,lazyLoad:"progressive",responsive:[{breakpoint:1024,settings:{slidesToShow:4,draggable:true,arrows:false}},{breakpoint:600,settings:{slidesToShow:3,draggable:true,arrows:false}},{breakpoint:480,settings:{slidesToShow:2,draggable:true,arrows:false}}]});e(".pwb-product-carousel").slick({slide:".pwb-slick-slide",infinite:true,draggable:false,prevArrow:'<div class="slick-prev"><span>'+pwb_ajax_object.carousel_prev+"</span></div>",nextArrow:'<div class="slick-next"><span>'+pwb_ajax_object.carousel_next+"</span></div>",speed:300,lazyLoad:"progressive",responsive:[{breakpoint:1024,settings:{slidesToShow:3,draggable:true,arrows:false}},{breakpoint:600,settings:{slidesToShow:2,draggable:true,arrows:false}},{breakpoint:480,settings:{slidesToShow:1,draggable:true,arrows:false}}]})}var f=function(){var h=[location.protocol,"//",location.host,location.pathname].join("");var i=window.location.href;var g=[];e('.pwb-filter-products input[type="checkbox"]').each(function(j){if(e(this).prop("checked")){g.push(e(this).val())}});g=g.join();if(g){i=i.replace(/&?pwb-brand-filter=([^&]$|[^&]*)/i,"");i=i.replace(/\/page\/\d*\//i,"");if(i.indexOf("?")===-1){i=i+"?pwb-brand-filter="+g}else{i=i+"&pwb-brand-filter="+g}}else{i=h}location.href=i};e(".pwb-filter-products button").on("click",function(){f()});e(".pwb-filter-products.pwb-hide-submit-btn input").on("change",function(){f()});var d=PWBgetUrlParameter("pwb-brand-filter");if(d!=null){var b=d.split(",");e('.pwb-filter-products input[type="checkbox"]').prop("checked",false);for(var c=0,a=b.length;c<a;c++){e('.pwb-filter-products input[type="checkbox"]').each(function(g){if(e(this).val()){if(b[c]==e(this).val()){e(this).prop("checked",true)}}})}}else{e('.pwb-filter-products input[type="checkbox"]').prop("checked",false)}});var PWBgetUrlParameter=function PWBgetUrlParameter(a){var d=decodeURIComponent(window.location.search.substring(1)),c=d.split("&"),e,b;for(b=0;b<c.length;b++){e=c[b].split("=");if(e[0]===a){return e[1]===undefined?true:e[1]}}};
1
+ jQuery((function($){"use strict";$(".pwb-dropdown-widget").on("change",(function(){var href=$(this).find(":selected").val();location.href=href})),"function"==typeof $.fn.slick&&($(".pwb-carousel").slick({slide:".pwb-slick-slide",infinite:!0,draggable:!1,prevArrow:'<div class="slick-prev"><span>'+pwb_ajax_object.carousel_prev+"</span></div>",nextArrow:'<div class="slick-next"><span>'+pwb_ajax_object.carousel_next+"</span></div>",speed:300,lazyLoad:"progressive",responsive:[{breakpoint:1024,settings:{slidesToShow:4,draggable:!0,arrows:!1}},{breakpoint:600,settings:{slidesToShow:3,draggable:!0,arrows:!1}},{breakpoint:480,settings:{slidesToShow:2,draggable:!0,arrows:!1}}]}),$(".pwb-product-carousel").slick({slide:".pwb-slick-slide",infinite:!0,draggable:!1,prevArrow:'<div class="slick-prev"><span>'+pwb_ajax_object.carousel_prev+"</span></div>",nextArrow:'<div class="slick-next"><span>'+pwb_ajax_object.carousel_next+"</span></div>",speed:300,lazyLoad:"progressive",responsive:[{breakpoint:1024,settings:{slidesToShow:3,draggable:!0,arrows:!1}},{breakpoint:600,settings:{slidesToShow:2,draggable:!0,arrows:!1}},{breakpoint:480,settings:{slidesToShow:1,draggable:!0,arrows:!1}}]}));var PWBFilterByBrand=function(){var baseUrl=[location.protocol,"//",location.host,location.pathname].join(""),currentUrl=window.location.href,marcas=[];$('.pwb-filter-products input[type="checkbox"]').each((function(index){$(this).prop("checked")&&marcas.push($(this).val())})),currentUrl=(marcas=marcas.join())?-1===(currentUrl=(currentUrl=currentUrl.replace(/&?pwb-brand-filter=([^&]$|[^&]*)/i,"")).replace(/\/page\/\d*\//i,"")).indexOf("?")?currentUrl+"?pwb-brand-filter="+marcas:currentUrl+"&pwb-brand-filter="+marcas:baseUrl,location.href=currentUrl};$(".pwb-filter-products button").on("click",(function(){PWBFilterByBrand()})),$(".pwb-filter-products.pwb-hide-submit-btn input").on("change",(function(){PWBFilterByBrand()}));var brands=PWBgetUrlParameter("pwb-brand-filter");if(null!=brands){var brands_array=brands.split(",");$('.pwb-filter-products input[type="checkbox"]').prop("checked",!1);for(var i=0,l=brands_array.length;i<l;i++)$('.pwb-filter-products input[type="checkbox"]').each((function(index){$(this).val()&&brands_array[i]==$(this).val()&&$(this).prop("checked",!0)}))}else $('.pwb-filter-products input[type="checkbox"]').prop("checked",!1)}));var PWBgetUrlParameter=function PWBgetUrlParameter(sParam){var sPageURL,sURLVariables=decodeURIComponent(window.location.search.substring(1)).split("&"),sParameterName,i;for(i=0;i<sURLVariables.length;i++)if((sParameterName=sURLVariables[i].split("="))[0]===sParam)return void 0===sParameterName[1]||sParameterName[1]};
classes/admin/class-brands-custom-fields.php CHANGED
@@ -1,81 +1,86 @@
1
  <?php
 
2
  namespace Perfect_Woocommerce_Brands\Admin;
3
 
4
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
5
 
6
- class Brands_Custom_Fields {
 
7
 
8
- function __construct(){
9
- add_action( 'pwb-brand_add_form_fields', array( $this, 'add_brands_metafields_form' ) );
10
- add_action( 'pwb-brand_edit_form_fields', array( $this, 'add_brands_metafields_form_edit' ) );
11
- add_action( 'edit_pwb-brand', array( $this, 'add_brands_metafields_save' ) );
12
- add_action( 'create_pwb-brand', array( $this, 'add_brands_metafields_save' ) );
 
13
  }
14
 
15
- public function add_brands_metafields_form(){
 
16
  ob_start();
17
- ?>
18
 
19
  <div class="form-field pwb_brand_cont">
20
- <label for="pwb_brand_desc"><?php _e( 'Description' ); ?></label>
21
- <textarea id="pwb_brand_description_field" name="pwb_brand_description_field" rows="5" cols="40"></textarea>
22
- <p id="brand-description-help-text"><?php _e( 'Brand description for the archive pages. You can include some html markup and shortcodes.', 'perfect-woocommerce-brands' ); ?></p>
23
  </div>
24
 
25
  <div class="form-field pwb_brand_cont">
26
- <label for="pwb_brand_image"><?php _e( 'Brand logo', 'perfect-woocommerce-brands' ); ?></label>
27
- <input type="text" name="pwb_brand_image" id="pwb_brand_image" value="" >
28
- <a href="#" id="pwb_brand_image_select" class="button"><?php _e('Select image','perfect-woocommerce-brands');?></a>
29
  </div>
30
 
31
  <div class="form-field pwb_brand_cont">
32
- <label for="pwb_brand_banner"><?php _e( 'Brand banner', 'perfect-woocommerce-brands' ); ?></label>
33
- <input type="text" name="pwb_brand_banner" id="pwb_brand_banner" value="" >
34
- <a href="#" id="pwb_brand_banner_select" class="button"><?php _e('Select image','perfect-woocommerce-brands');?></a>
35
- <p><?php _e( 'This image will be shown on brand page', 'perfect-woocommerce-brands' ); ?></p>
36
  </div>
37
 
38
  <div class="form-field pwb_brand_cont">
39
- <label for="pwb_brand_banner_link"><?php _e( 'Brand banner link', 'perfect-woocommerce-brands' ); ?></label>
40
- <input type="text" name="pwb_brand_banner_link" id="pwb_brand_banner_link" value="" >
41
- <p><?php _e( 'This link should be relative to site url. Example: product/product-name', 'perfect-woocommerce-brands' ); ?></p>
42
  </div>
43
 
44
- <?php wp_nonce_field( basename( __FILE__ ), 'pwb_nonce' ); ?>
45
 
46
- <?php
47
  echo ob_get_clean();
48
  }
49
 
50
- public function add_brands_metafields_form_edit($term){
51
- $term_value_image = get_term_meta( $term->term_id, 'pwb_brand_image', true );
52
- $term_value_banner = get_term_meta( $term->term_id, 'pwb_brand_banner', true );
53
- $term_value_banner_link = get_term_meta( $term->term_id, 'pwb_brand_banner_link', true );
 
54
  ob_start();
55
- ?>
56
  <table class="form-table pwb_brand_cont">
57
  <tr class="form-field">
58
  <th>
59
- <label for="pwb_brand_desc"><?php _e( 'Description' ); ?></label>
60
  </th>
61
  <td>
62
- <?php wp_editor( html_entity_decode( $term->description ), 'pwb_brand_description_field', array( 'editor_height' => 120 ) ); ?>
63
- <p id="brand-description-help-text"><?php _e( 'Brand description for the archive pages. You can include some html markup and shortcodes.', 'perfect-woocommerce-brands' ); ?></p>
64
  </td>
65
  </tr>
66
  <tr class="form-field">
67
  <th>
68
- <label for="pwb_brand_image"><?php _e( 'Brand logo', 'perfect-woocommerce-brands' ); ?></label>
69
  </th>
70
  <td>
71
- <input type="text" name="pwb_brand_image" id="pwb_brand_image" value="<?php echo $term_value_image;?>" >
72
- <a href="#" id="pwb_brand_image_select" class="button"><?php _e('Select image','perfect-woocommerce-brands');?></a>
73
 
74
- <?php $current_image = wp_get_attachment_image ( $term_value_image, array('90','90'), false ); ?>
75
- <?php if( !empty($current_image) ): ?>
76
  <div class="pwb_brand_image_selected">
77
  <span>
78
- <?php echo $current_image;?>
79
  <a href="#" class="pwb_brand_image_selected_remove">X</a>
80
  </span>
81
  </div>
@@ -85,17 +90,17 @@ class Brands_Custom_Fields {
85
  </tr>
86
  <tr class="form-field">
87
  <th>
88
- <label for="pwb_brand_banner"><?php _e( 'Brand banner', 'perfect-woocommerce-brands' ); ?></label>
89
  </th>
90
  <td>
91
- <input type="text" name="pwb_brand_banner" id="pwb_brand_banner" value="<?php echo $term_value_banner;?>" >
92
- <a href="#" id="pwb_brand_banner_select" class="button"><?php _e('Select image','perfect-woocommerce-brands');?></a>
93
 
94
- <?php $current_image = wp_get_attachment_image ( $term_value_banner, array('90','90'), false ); ?>
95
- <?php if( !empty($current_image) ): ?>
96
  <div class="pwb_brand_image_selected">
97
  <span>
98
- <?php echo $current_image;?>
99
  <a href="#" class="pwb_brand_image_selected_remove">X</a>
100
  </span>
101
  </div>
@@ -105,72 +110,71 @@ class Brands_Custom_Fields {
105
  </tr>
106
  <tr class="form-field">
107
  <th>
108
- <label for="pwb_brand_banner_link"><?php _e( 'Brand banner link', 'perfect-woocommerce-brands' ); ?></label>
109
  </th>
110
  <td>
111
- <input type="text" name="pwb_brand_banner_link" id="pwb_brand_banner_link" value="<?php echo $term_value_banner_link;?>" >
112
- <p class="description"><?php _e( 'This link should be relative to site url. Example: product/product-name', 'perfect-woocommerce-brands' ); ?></p>
113
- <div id="pwb_brand_banner_link_result"><?php echo wp_get_attachment_image ( $term_value_banner_link, array('90','90'), false );?></div>
114
  </td>
115
  </tr>
116
  </table>
117
 
118
- <?php wp_nonce_field( basename( __FILE__ ), 'pwb_nonce' );?>
119
 
120
- <?php
121
  echo ob_get_clean();
122
  }
123
 
124
- public function add_brands_metafields_save( $term_id ){
 
125
 
126
- if ( ! isset( $_POST['pwb_nonce'] ) || ! wp_verify_nonce( $_POST['pwb_nonce'], basename( __FILE__ ) ) )
127
- return;
128
 
129
  /* ·············· Brand image ·············· */
130
- $old_img = get_term_meta( $term_id, 'pwb_brand_image', true );
131
- $new_img = isset( $_POST['pwb_brand_image'] ) ? $_POST['pwb_brand_image'] : '';
132
 
133
- if ( $old_img && '' === $new_img )
134
- delete_term_meta( $term_id, 'pwb_brand_image' );
135
 
136
- else if ( $old_img !== $new_img )
137
- update_term_meta( $term_id, 'pwb_brand_image', $new_img );
138
  /* ·············· /Brand image ·············· */
139
 
140
  /* ·············· Brand banner ·············· */
141
- $old_img = get_term_meta( $term_id, 'pwb_brand_banner', true );
142
- $new_img = isset( $_POST['pwb_brand_banner'] ) ? $_POST['pwb_brand_banner'] : '';
143
 
144
- if ( $old_img && '' === $new_img )
145
- delete_term_meta( $term_id, 'pwb_brand_banner' );
146
 
147
- else if ( $old_img !== $new_img )
148
- update_term_meta( $term_id, 'pwb_brand_banner', $new_img );
149
  /* ·············· /Brand banner ·············· */
150
 
151
  /* ·············· Brand banner link ·············· */
152
- $old_img = get_term_meta( $term_id, 'pwb_brand_banner_link', true );
153
- $new_img = isset( $_POST['pwb_brand_banner_link'] ) ? $_POST['pwb_brand_banner_link'] : '';
154
 
155
- if ( $old_img && '' === $new_img )
156
- delete_term_meta( $term_id, 'pwb_brand_banner_link' );
157
 
158
- else if ( $old_img !== $new_img )
159
- update_term_meta( $term_id, 'pwb_brand_banner_link', $new_img );
160
  /* ·············· /Brand banner link ·············· */
161
 
162
  /* ·············· Brand desc ·············· */
163
- if( isset( $_POST['pwb_brand_description_field'] ) ){
164
  $allowed_tags = apply_filters(
165
  'pwb_description_allowed_tags',
166
  '<p><span><a><ul><ol><li><h1><h2><h3><h4><h5><h6><pre><strong><em><blockquote><del><ins><img><code><hr>'
167
  );
168
- $desc = strip_tags( wp_unslash( $_POST['pwb_brand_description_field'] ), $allowed_tags );
169
  global $wpdb;
170
- $wpdb->update( $wpdb->term_taxonomy, [ 'description' => $desc ], [ 'term_id' => $term_id ] );
171
  }
172
  /* ·············· /Brand desc ·············· */
173
-
174
  }
175
-
176
  }
1
  <?php
2
+
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
+ defined('ABSPATH') or die('No script kiddies please!');
6
 
7
+ class Brands_Custom_Fields
8
+ {
9
 
10
+ function __construct()
11
+ {
12
+ add_action('pwb-brand_add_form_fields', array($this, 'add_brands_metafields_form'));
13
+ add_action('pwb-brand_edit_form_fields', array($this, 'add_brands_metafields_form_edit'));
14
+ add_action('edit_pwb-brand', array($this, 'add_brands_metafields_save'));
15
+ add_action('create_pwb-brand', array($this, 'add_brands_metafields_save'));
16
  }
17
 
18
+ public function add_brands_metafields_form()
19
+ {
20
  ob_start();
21
+ ?>
22
 
23
  <div class="form-field pwb_brand_cont">
24
+ <label for="pwb_brand_desc"><?php _e('Description'); ?></label>
25
+ <textarea id="pwb_brand_description_field" name="pwb_brand_description_field" rows="5" cols="40"></textarea>
26
+ <p id="brand-description-help-text"><?php _e('Brand description for the archive pages. You can include some html markup and shortcodes.', 'perfect-woocommerce-brands'); ?></p>
27
  </div>
28
 
29
  <div class="form-field pwb_brand_cont">
30
+ <label for="pwb_brand_image"><?php _e('Brand logo', 'perfect-woocommerce-brands'); ?></label>
31
+ <input type="text" name="pwb_brand_image" id="pwb_brand_image" value="">
32
+ <a href="#" id="pwb_brand_image_select" class="button"><?php esc_html_e('Select image', 'perfect-woocommerce-brands'); ?></a>
33
  </div>
34
 
35
  <div class="form-field pwb_brand_cont">
36
+ <label for="pwb_brand_banner"><?php _e('Brand banner', 'perfect-woocommerce-brands'); ?></label>
37
+ <input type="text" name="pwb_brand_banner" id="pwb_brand_banner" value="">
38
+ <a href="#" id="pwb_brand_banner_select" class="button"><?php esc_html_e('Select image', 'perfect-woocommerce-brands'); ?></a>
39
+ <p><?php _e('This image will be shown on brand page', 'perfect-woocommerce-brands'); ?></p>
40
  </div>
41
 
42
  <div class="form-field pwb_brand_cont">
43
+ <label for="pwb_brand_banner_link"><?php _e('Brand banner link', 'perfect-woocommerce-brands'); ?></label>
44
+ <input type="text" name="pwb_brand_banner_link" id="pwb_brand_banner_link" value="">
45
+ <p><?php _e('This link should be relative to site url. Example: product/product-name', 'perfect-woocommerce-brands'); ?></p>
46
  </div>
47
 
48
+ <?php wp_nonce_field(basename(__FILE__), 'pwb_nonce'); ?>
49
 
50
+ <?php
51
  echo ob_get_clean();
52
  }
53
 
54
+ public function add_brands_metafields_form_edit($term)
55
+ {
56
+ $term_value_image = get_term_meta($term->term_id, 'pwb_brand_image', true);
57
+ $term_value_banner = get_term_meta($term->term_id, 'pwb_brand_banner', true);
58
+ $term_value_banner_link = get_term_meta($term->term_id, 'pwb_brand_banner_link', true);
59
  ob_start();
60
+ ?>
61
  <table class="form-table pwb_brand_cont">
62
  <tr class="form-field">
63
  <th>
64
+ <label for="pwb_brand_desc"><?php _e('Description'); ?></label>
65
  </th>
66
  <td>
67
+ <?php wp_editor(html_entity_decode($term->description), 'pwb_brand_description_field', array('editor_height' => 120)); ?>
68
+ <p id="brand-description-help-text"><?php _e('Brand description for the archive pages. You can include some html markup and shortcodes.', 'perfect-woocommerce-brands'); ?></p>
69
  </td>
70
  </tr>
71
  <tr class="form-field">
72
  <th>
73
+ <label for="pwb_brand_image"><?php _e('Brand logo', 'perfect-woocommerce-brands'); ?></label>
74
  </th>
75
  <td>
76
+ <input type="text" name="pwb_brand_image" id="pwb_brand_image" value="<?php echo esc_attr($term_value_image); ?>">
77
+ <a href="#" id="pwb_brand_image_select" class="button"><?php esc_html_e('Select image', 'perfect-woocommerce-brands'); ?></a>
78
 
79
+ <?php $current_image = wp_get_attachment_image($term_value_image, array('90', '90'), false); ?>
80
+ <?php if (!empty($current_image)) : ?>
81
  <div class="pwb_brand_image_selected">
82
  <span>
83
+ <?php echo wp_kses_post($current_image); ?>
84
  <a href="#" class="pwb_brand_image_selected_remove">X</a>
85
  </span>
86
  </div>
90
  </tr>
91
  <tr class="form-field">
92
  <th>
93
+ <label for="pwb_brand_banner"><?php _e('Brand banner', 'perfect-woocommerce-brands'); ?></label>
94
  </th>
95
  <td>
96
+ <input type="text" name="pwb_brand_banner" id="pwb_brand_banner" value="<?php echo esc_html($term_value_banner); ?>">
97
+ <a href="#" id="pwb_brand_banner_select" class="button"><?php esc_html_e('Select image', 'perfect-woocommerce-brands'); ?></a>
98
 
99
+ <?php $current_image = wp_get_attachment_image($term_value_banner, array('90', '90'), false); ?>
100
+ <?php if (!empty($current_image)) : ?>
101
  <div class="pwb_brand_image_selected">
102
  <span>
103
+ <?php echo wp_kses_post($current_image); ?>
104
  <a href="#" class="pwb_brand_image_selected_remove">X</a>
105
  </span>
106
  </div>
110
  </tr>
111
  <tr class="form-field">
112
  <th>
113
+ <label for="pwb_brand_banner_link"><?php _e('Brand banner link', 'perfect-woocommerce-brands'); ?></label>
114
  </th>
115
  <td>
116
+ <input type="text" name="pwb_brand_banner_link" id="pwb_brand_banner_link" value="<?php echo esc_html($term_value_banner_link); ?>">
117
+ <p class="description"><?php _e('This link should be relative to site url. Example: product/product-name', 'perfect-woocommerce-brands'); ?></p>
118
+ <div id="pwb_brand_banner_link_result"><?php echo wp_get_attachment_image($term_value_banner_link, array('90', '90'), false); ?></div>
119
  </td>
120
  </tr>
121
  </table>
122
 
123
+ <?php wp_nonce_field(basename(__FILE__), 'pwb_nonce'); ?>
124
 
125
+ <?php
126
  echo ob_get_clean();
127
  }
128
 
129
+ public function add_brands_metafields_save($term_id)
130
+ {
131
 
132
+ if (!isset($_POST['pwb_nonce']) || !wp_verify_nonce($_POST['pwb_nonce'], basename(__FILE__)))
133
+ return;
134
 
135
  /* ·············· Brand image ·············· */
136
+ $old_img = get_term_meta($term_id, 'pwb_brand_image', true);
137
+ $new_img = isset($_POST['pwb_brand_image']) ? $_POST['pwb_brand_image'] : '';
138
 
139
+ if ($old_img && '' === $new_img)
140
+ delete_term_meta($term_id, 'pwb_brand_image');
141
 
142
+ else if ($old_img !== $new_img)
143
+ update_term_meta($term_id, 'pwb_brand_image', $new_img);
144
  /* ·············· /Brand image ·············· */
145
 
146
  /* ·············· Brand banner ·············· */
147
+ $old_img = get_term_meta($term_id, 'pwb_brand_banner', true);
148
+ $new_img = isset($_POST['pwb_brand_banner']) ? $_POST['pwb_brand_banner'] : '';
149
 
150
+ if ($old_img && '' === $new_img)
151
+ delete_term_meta($term_id, 'pwb_brand_banner');
152
 
153
+ else if ($old_img !== $new_img)
154
+ update_term_meta($term_id, 'pwb_brand_banner', $new_img);
155
  /* ·············· /Brand banner ·············· */
156
 
157
  /* ·············· Brand banner link ·············· */
158
+ $old_img = get_term_meta($term_id, 'pwb_brand_banner_link', true);
159
+ $new_img = isset($_POST['pwb_brand_banner_link']) ? $_POST['pwb_brand_banner_link'] : '';
160
 
161
+ if ($old_img && '' === $new_img)
162
+ delete_term_meta($term_id, 'pwb_brand_banner_link');
163
 
164
+ else if ($old_img !== $new_img)
165
+ update_term_meta($term_id, 'pwb_brand_banner_link', $new_img);
166
  /* ·············· /Brand banner link ·············· */
167
 
168
  /* ·············· Brand desc ·············· */
169
+ if (isset($_POST['pwb_brand_description_field'])) {
170
  $allowed_tags = apply_filters(
171
  'pwb_description_allowed_tags',
172
  '<p><span><a><ul><ol><li><h1><h2><h3><h4><h5><h6><pre><strong><em><blockquote><del><ins><img><code><hr>'
173
  );
174
+ $desc = strip_tags(wp_unslash($_POST['pwb_brand_description_field']), $allowed_tags);
175
  global $wpdb;
176
+ $wpdb->update($wpdb->term_taxonomy, ['description' => $desc], ['term_id' => $term_id]);
177
  }
178
  /* ·············· /Brand desc ·············· */
 
179
  }
 
180
  }
classes/admin/class-edit-brands-page.php CHANGED
@@ -36,7 +36,7 @@ class Edit_Brands_Page {
36
  echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
37
  'edit-brands-bottom',
38
  'admin',
39
- array( 'featured_count' => count( $brands_featured ), 'text_featured' => __('featured', 'perfect-woocommerce-brands') )
40
  );
41
 
42
  }
@@ -90,7 +90,7 @@ class Edit_Brands_Page {
90
  $featured_class = ( $this->is_featured_brand( $term_id ) ) ? 'dashicons-star-filled' : 'dashicons-star-empty';
91
  printf(
92
  '<span class="dashicons %1$s" title="%2$s" data-brand-id="%3$s"></span>',
93
- $featured_class, __('Set as featured', 'perfect-woocommerce-brands'), $term_id
94
  );
95
  break;
96
  }
@@ -122,10 +122,10 @@ class Edit_Brands_Page {
122
  $featured = get_user_option( 'pwb-first-featured-brands', self::$current_user->ID );
123
  ob_start();
124
  ?>
125
- <legend><?php _e('Brands','perfect-woocommerce-brands');?></legend>
126
  <label>
127
  <input id="pwb-first-featured-brands" type="checkbox" <?php checked($featured,true);?>>
128
- <?php _e('Show featured brands first','perfect-woocommerce-brands');?>
129
  </label>
130
  <?php
131
  return ob_get_clean();
36
  echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
37
  'edit-brands-bottom',
38
  'admin',
39
+ array( 'featured_count' => count( $brands_featured ), 'text_featured' => esc_html__('featured', 'perfect-woocommerce-brands') )
40
  );
41
 
42
  }
90
  $featured_class = ( $this->is_featured_brand( $term_id ) ) ? 'dashicons-star-filled' : 'dashicons-star-empty';
91
  printf(
92
  '<span class="dashicons %1$s" title="%2$s" data-brand-id="%3$s"></span>',
93
+ $featured_class, esc_html__('Set as featured', 'perfect-woocommerce-brands'), $term_id
94
  );
95
  break;
96
  }
122
  $featured = get_user_option( 'pwb-first-featured-brands', self::$current_user->ID );
123
  ob_start();
124
  ?>
125
+ <legend><?php esc_html_e('Brands','perfect-woocommerce-brands');?></legend>
126
  <label>
127
  <input id="pwb-first-featured-brands" type="checkbox" <?php checked($featured,true);?>>
128
+ <?php esc_html_e('Show featured brands first','perfect-woocommerce-brands');?>
129
  </label>
130
  <?php
131
  return ob_get_clean();
classes/admin/class-pwb-admin-tab.php CHANGED
@@ -3,297 +3,308 @@
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
  use WC_Admin_Settings,
6
- WC_Settings_Page;
7
 
8
  defined('ABSPATH') or die('No script kiddies please!');
9
 
10
- function pwb_admin_tab() {
 
11
 
12
- class Pwb_Admin_Tab extends WC_Settings_Page {
 
13
 
14
- public function __construct() {
 
15
 
16
- $this->id = 'pwb_admin_tab';
17
- $this->label = __('Brands', 'perfect-woocommerce-brands');
18
-
19
- add_filter('woocommerce_settings_tabs_array', [$this, 'add_settings_page'], 20);
20
- add_action('woocommerce_settings_' . $this->id, [$this, 'output']);
21
- add_action('woocommerce_sections_' . $this->id, [$this, 'output_sections']);
22
- add_action('woocommerce_settings_save_' . $this->id, [$this, 'save']);
23
- }
24
 
25
- public function get_sections() {
 
26
 
27
- $sections = array(
28
- '' => __('General', 'perfect-woocommerce-brands'),
29
- 'brand-pages' => __('Archives', 'perfect-woocommerce-brands'),
30
- 'single-product' => __('Products', 'perfect-woocommerce-brands'),
31
- 'tools' => __('Tools', 'perfect-woocommerce-brands'),
32
- );
33
 
34
- return apply_filters('woocommerce_get_sections_' . $this->id, $sections);
35
- }
36
 
37
- public function output_sections() {
38
- global $current_section;
39
 
40
- $sections = $this->get_sections();
 
 
 
 
 
41
 
42
- if (empty($sections) || 1 === sizeof($sections)) {
43
- return;
44
- }
45
 
46
- echo '<ul class="subsubsub">';
 
 
47
 
48
- $array_keys = array_keys($sections);
49
 
50
- foreach ($sections as $id => $label) {
51
- echo '<li><a href="' . admin_url('admin.php?page=wc-settings&tab=' . $this->id . '&section=' . sanitize_title($id)) . '" class="' . ( $current_section == $id ? 'current' : '' ) . '">' . $label . '</a> ' . ( end($array_keys) == $id ? '' : '|' ) . ' </li>';
52
- }
53
 
54
- echo ' | <li><a target="_blank" href="' . admin_url('edit-tags.php?taxonomy=pwb-brand&post_type=product') . '">' . __('Brands', 'perfect-woocommerce-brands') . '</a></li>';
55
- echo ' | <li><a target="_blank" href="' . admin_url('admin.php?page=pwb_suggestions') . '">' . __('Suggestions', 'perfect-woocommerce-brands') . '</a></li>';
56
- echo ' | <li><a target="_blank" href="' . PWB_DOCUMENTATION_URL . '">' . __('Documentation', 'perfect-woocommerce-brands') . '</a></li>';
57
 
58
- echo '</ul><br class="clear" />';
59
- }
60
 
61
- public function get_settings($current_section = '') {
62
-
63
- $available_image_sizes_adapted = array();
64
- $available_image_sizes = get_intermediate_image_sizes();
65
- foreach ($available_image_sizes as $image_size)
66
- $available_image_sizes_adapted[$image_size] = $image_size;
67
- $available_image_sizes_adapted['full'] = 'full';
68
-
69
- $pages_select_adapted = array('-' => '-');
70
- $pages_select = get_pages();
71
- foreach ($pages_select as $page)
72
- $pages_select_adapted[$page->ID] = $page->post_title;
73
-
74
- if ('single-product' == $current_section) {
75
-
76
- $settings = apply_filters('wc_pwb_admin_tab_settings', array(
77
- 'section_title' => array(
78
- 'name' => __('Products', 'perfect-woocommerce-brands'),
79
- 'type' => 'title',
80
- 'desc' => '',
81
- 'id' => 'wc_pwb_admin_tab_section_title'
82
- ),
83
- 'brand_single_product_tab' => array(
84
- 'name' => __('Products tab', 'perfect-woocommerce-brands'),
85
- 'type' => 'checkbox',
86
- 'default' => 'yes',
87
- 'desc' => __('Show brand tab in single product page', 'perfect-woocommerce-brands'),
88
- 'id' => 'wc_pwb_admin_tab_brand_single_product_tab'
89
- ),
90
- 'show_brand_in_single' => array(
91
- 'name' => __('Show brands in single product', 'perfect-woocommerce-brands'),
92
- 'type' => 'select',
93
- 'class' => 'pwb-admin-tab-field',
94
- 'desc' => __('Show brand logo (or name) in single product', 'perfect-woocommerce-brands'),
95
- 'default' => 'brand_image',
96
- 'id' => 'wc_pwb_admin_tab_brands_in_single',
97
- 'options' => array(
98
- 'no' => __('No', 'perfect-woocommerce-brands'),
99
- 'brand_link' => __('Show brand link', 'perfect-woocommerce-brands'),
100
- 'brand_image' => __('Show brand image (if is set)', 'perfect-woocommerce-brands')
101
- )
102
- ),
103
- 'brand_single_position' => array(
104
- 'name' => __('Brand position', 'perfect-woocommerce-brands'),
105
- 'type' => 'select',
106
- 'class' => 'pwb-admin-tab-field',
107
- 'desc' => __('For single product', 'perfect-woocommerce-brands'),
108
- 'id' => 'wc_pwb_admin_tab_brand_single_position',
109
- 'options' => array(
110
- 'before_title' => __('Before title', 'perfect-woocommerce-brands'),
111
- 'after_title' => __('After title', 'perfect-woocommerce-brands'),
112
- 'after_price' => __('After price', 'perfect-woocommerce-brands'),
113
- 'after_excerpt' => __('After excerpt', 'perfect-woocommerce-brands'),
114
- 'after_add_to_cart' => __('After add to cart', 'perfect-woocommerce-brands'),
115
- 'meta' => __('In meta', 'perfect-woocommerce-brands'),
116
- 'after_meta' => __('After meta', 'perfect-woocommerce-brands'),
117
- 'after_sharing' => __('After sharing', 'perfect-woocommerce-brands')
118
- )
119
- ),
120
- 'section_end' => array(
121
- 'type' => 'sectionend',
122
- 'id' => 'wc_pwb_admin_tab_section_end'
123
- )
124
- ));
125
- } elseif ('brand-pages' == $current_section) {
126
-
127
- $settings = apply_filters('wc_pwb_admin_tab_brand_pages_settings', array(
128
- 'section_title' => array(
129
- 'name' => __('Archives', 'perfect-woocommerce-brands'),
130
- 'type' => 'title',
131
- 'desc' => '',
132
- 'id' => 'wc_pwb_admin_tab_section_title'
133
- ),
134
- 'brand_description' => array(
135
- 'name' => __('Show brand description', 'perfect-woocommerce-brands'),
136
- 'type' => 'select',
137
- 'class' => 'pwb-admin-tab-field',
138
- 'default' => 'yes',
139
- 'desc' => __('Show brand description (if is set) on brand archive page', 'perfect-woocommerce-brands'),
140
- 'id' => 'wc_pwb_admin_tab_brand_desc',
141
- 'options' => array(
142
- 'yes' => __('Yes, before product loop', 'perfect-woocommerce-brands'),
143
- 'yes_after_loop' => __('Yes, after product loop', 'perfect-woocommerce-brands'),
144
- 'no' => __('No, hide description', 'perfect-woocommerce-brands')
145
- )
146
- ),
147
- 'brand_banner' => array(
148
- 'name' => __('Show brand banner', 'perfect-woocommerce-brands'),
149
- 'type' => 'select',
150
- 'class' => 'pwb-admin-tab-field',
151
- 'default' => 'yes',
152
- 'desc' => __('Show brand banner (if is set) on brand archive page', 'perfect-woocommerce-brands'),
153
- 'id' => 'wc_pwb_admin_tab_brand_banner',
154
- 'options' => array(
155
- 'yes' => __('Yes, before product loop', 'perfect-woocommerce-brands'),
156
- 'yes_after_loop' => __('Yes, after product loop', 'perfect-woocommerce-brands'),
157
- 'no' => __('No, hide banner', 'perfect-woocommerce-brands')
158
- )
159
- ),
160
- 'show_brand_on_loop' => array(
161
- 'name' => __('Show brands in loop', 'perfect-woocommerce-brands'),
162
- 'type' => 'select',
163
- 'class' => 'pwb-admin-tab-field',
164
- 'desc' => __('Show brand logo (or name) in product loop', 'perfect-woocommerce-brands'),
165
- 'id' => 'wc_pwb_admin_tab_brands_in_loop',
166
- 'options' => array(
167
- 'no' => __('No', 'perfect-woocommerce-brands'),
168
- 'brand_link' => __('Show brand link', 'perfect-woocommerce-brands'),
169
- 'brand_image' => __('Show brand image (if is set)', 'perfect-woocommerce-brands')
170
- )
171
- ),
172
- 'section_end' => array(
173
- 'type' => 'sectionend',
174
- 'id' => 'wc_pwb_admin_tab_section_end'
175
- )
176
- ));
177
- } elseif ('tools' == $current_section) {
178
-
179
- $settings = apply_filters('wc_pwb_admin_tab_tools_settings', array(
180
- 'section_title' => array(
181
- 'name' => __('Tools', 'perfect-woocommerce-brands'),
182
- 'type' => 'title',
183
- 'desc' => '',
184
- 'id' => 'wc_pwb_admin_tab_section_tools_title'
185
- ),
186
- 'brand_import' => array(
187
- 'name' => __('Import brands', 'perfect-woocommerce-brands'),
188
- 'type' => 'select',
189
- 'class' => 'pwb-admin-tab-field',
190
- 'desc' => sprintf(
191
- __('Import brands from other brand plugin. <a href="%s" target="_blank">Click here for more details</a>', 'perfect-woocommerce-brands'), str_replace('/?', '/brands/?', PWB_DOCUMENTATION_URL)
192
- ),
193
- 'id' => 'wc_pwb_admin_tab_tools_migrate',
194
- 'options' => array(
195
- '-' => __('-', 'perfect-woocommerce-brands'),
196
- 'yith' => __('YITH WooCommerce Brands Add-On', 'perfect-woocommerce-brands'),
197
- 'ultimate' => __('Ultimate WooCommerce Brands', 'perfect-woocommerce-brands'),
198
- 'woobrands' => __('Offical WooCommerce Brands', 'perfect-woocommerce-brands')
199
- )
200
- ),
201
- 'brand_dummy_data' => array(
202
- 'name' => __('Dummy data', 'perfect-woocommerce-brands'),
203
- 'type' => 'select',
204
- 'class' => 'pwb-admin-tab-field',
205
- 'desc' => __('Import generic brands and assign it to products randomly', 'perfect-woocommerce-brands'),
206
- 'id' => 'wc_pwb_admin_tab_tools_dummy_data',
207
- 'options' => array(
208
- '-' => __('-', 'perfect-woocommerce-brands'),
209
- 'start_import' => __('Start import', 'perfect-woocommerce-brands')
210
- )
211
- ),
212
- 'brands_system_status' => array(
213
- 'name' => __('System status', 'perfect-woocommerce-brands'),
214
- 'type' => 'textarea',
215
- 'desc' => __('Show system status', 'perfect-woocommerce-brands'),
216
- 'id' => 'wc_pwb_admin_tab_tools_system_status'
217
- ),
218
- 'section_end' => array(
219
- 'type' => 'sectionend',
220
- 'id' => 'wc_pwb_admin_tab_section_tools_end'
221
- )
222
- ));
223
- } else {
224
-
225
- $brands_url = get_option('wc_pwb_admin_tab_slug', __('brands', 'perfect-woocommerce-brands')) . '/' . __('brand-name', 'perfect-woocommerce-brands') . '/';
226
-
227
- $settings = apply_filters('wc_pwb_admin_tab_product_settings', array(
228
- 'section_title' => array(
229
- 'name' => __('General', 'perfect-woocommerce-brands'),
230
- 'type' => 'title',
231
- 'desc' => '',
232
- 'id' => 'wc_pwb_admin_tab_section_title'
233
- ),
234
- 'slug' => array(
235
- 'name' => __('Slug', 'perfect-woocommerce-brands'),
236
- 'type' => 'text',
237
- 'class' => 'pwb-admin-tab-field',
238
- 'desc' => __('Brands taxonomy slug', 'perfect-woocommerce-brands'),
239
- 'desc_tip' => sprintf(
240
- __('Your brands URLs will look like "%s"', 'perfect-woocommerce-brands'), 'https://site.com/' . $brands_url
241
- ),
242
- 'id' => 'wc_pwb_admin_tab_slug',
243
- 'placeholder' => get_taxonomy('pwb-brand')->rewrite['slug']
244
- ),
245
- 'brand_logo_size' => array(
246
- 'name' => __('Brand logo size', 'perfect-woocommerce-brands'),
247
- 'type' => 'select',
248
- 'class' => 'pwb-admin-tab-field',
249
- 'desc' => __('Select the size for the brand logo image around the site', 'perfect-woocommerce-brands'),
250
- 'desc_tip' => __('The default image sizes can be configured under "Settings > Media". You can also define your own image sizes', 'perfect-woocommerce-brands'),
251
- 'id' => 'wc_pwb_admin_tab_brand_logo_size',
252
- 'options' => $available_image_sizes_adapted
253
- ),
254
- 'brands_page_id' => array(
255
- 'name' => __('Brands page', 'perfect-woocommerce-brands'),
256
- 'type' => 'select',
257
- 'class' => 'pwb-admin-tab-field pwb-admin-selectwoo',
258
- 'desc' => __('For linking breadcrumbs', 'perfect-woocommerce-brands'),
259
- 'desc_tip' => __('Select your "Brands" page (if you have one), it will be linked in the breadcrumbs.', 'perfect-woocommerce-brands'),
260
- 'id' => 'wc_pwb_admin_tab_brands_page_id',
261
- 'options' => $pages_select_adapted
262
- ),
263
- 'section_end' => array(
264
- 'type' => 'sectionend',
265
- 'id' => 'wc_pwb_admin_tab_section_end'
266
- )
267
- ));
268
- }
269
-
270
- return apply_filters('woocommerce_get_settings_' . $this->id, $settings, $current_section);
271
  }
272
 
273
- public function output() {
 
 
274
 
275
- global $current_section;
 
276
 
277
- $settings = $this->get_settings($current_section);
278
- WC_Admin_Settings::output_fields($settings);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  }
280
 
281
- public function save() {
 
 
 
 
282
 
283
- update_option('old_wc_pwb_admin_tab_slug', get_taxonomy('pwb-brand')->rewrite['slug']);
284
- if (isset($_POST['wc_pwb_admin_tab_slug'])) {
285
- $_POST['wc_pwb_admin_tab_slug'] = sanitize_title($_POST['wc_pwb_admin_tab_slug']);
286
- }
287
 
288
- global $current_section;
 
 
289
 
290
- $settings = $this->get_settings($current_section);
291
- WC_Admin_Settings::save_fields($settings);
 
 
 
 
292
  }
293
 
294
- }
295
 
296
- return new Pwb_Admin_Tab();
 
 
297
  }
298
 
299
- add_filter('woocommerce_get_settings_pages', 'Perfect_Woocommerce_Brands\Admin\pwb_admin_tab', 15);
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
  use WC_Admin_Settings,
6
+ WC_Settings_Page;
7
 
8
  defined('ABSPATH') or die('No script kiddies please!');
9
 
10
+ class Pwb_Admin_Tab
11
+ {
12
 
13
+ public function __construct()
14
+ {
15
 
16
+ $this->id = 'pwb_admin_tab';
17
+ $this->label = __('Brands', 'perfect-woocommerce-brands');
18
 
19
+ add_filter('woocommerce_settings_tabs_array', [$this, 'add_tab'], 200);
20
+ add_action('woocommerce_settings_' . $this->id, [$this, 'output']);
21
+ add_action('woocommerce_sections_' . $this->id, [$this, 'output_sections']);
22
+ add_action('woocommerce_settings_save_' . $this->id, [$this, 'save']);
23
+ }
 
 
 
24
 
25
+ public function add_tab($settings_tabs)
26
+ {
27
 
28
+ $settings_tabs[$this->id] = $this->label;
 
 
 
 
 
29
 
30
+ return $settings_tabs;
31
+ }
32
 
33
+ public function get_sections()
34
+ {
35
 
36
+ $sections = array(
37
+ '' => __('General', 'perfect-woocommerce-brands'),
38
+ 'brand-pages' => __('Archives', 'perfect-woocommerce-brands'),
39
+ 'single-product' => __('Products', 'perfect-woocommerce-brands'),
40
+ 'tools' => __('Tools', 'perfect-woocommerce-brands'),
41
+ );
42
 
43
+ return apply_filters('woocommerce_get_sections_' . $this->id, $sections);
44
+ }
 
45
 
46
+ public function output_sections()
47
+ {
48
+ global $current_section;
49
 
50
+ $sections = $this->get_sections();
51
 
52
+ if (empty($sections) || 1 === sizeof($sections)) {
53
+ return;
54
+ }
55
 
56
+ echo '<ul class="subsubsub">';
 
 
57
 
58
+ $array_keys = array_keys($sections);
 
59
 
60
+ foreach ($sections as $id => $label) {
61
+ echo '<li><a href="' . admin_url('admin.php?page=wc-settings&tab=' . $this->id . '&section=' . sanitize_title($id)) . '" class="' . ($current_section == $id ? 'current' : '') . '">' . $label . '</a> ' . (end($array_keys) == $id ? '' : '|') . ' </li>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  }
63
 
64
+ echo ' | <li><a target="_blank" href="' . admin_url('edit-tags.php?taxonomy=pwb-brand&post_type=product') . '">' . __('Brands', 'perfect-woocommerce-brands') . '</a></li>';
65
+ echo ' | <li><a target="_blank" href="' . admin_url('admin.php?page=pwb_suggestions') . '">' . __('Suggestions', 'perfect-woocommerce-brands') . '</a></li>';
66
+ echo ' | <li><a target="_blank" href="' . PWB_DOCUMENTATION_URL . '">' . __('Documentation', 'perfect-woocommerce-brands') . '</a></li>';
67
 
68
+ echo '</ul><br class="clear" />';
69
+ }
70
 
71
+ public function get_settings($current_section = '')
72
+ {
73
+
74
+ $available_image_sizes_adapted = array();
75
+ $available_image_sizes = get_intermediate_image_sizes();
76
+ foreach ($available_image_sizes as $image_size)
77
+ $available_image_sizes_adapted[$image_size] = $image_size;
78
+ $available_image_sizes_adapted['full'] = 'full';
79
+
80
+ $pages_select_adapted = array('-' => '-');
81
+ $pages_select = get_pages();
82
+ foreach ($pages_select as $page)
83
+ $pages_select_adapted[$page->ID] = $page->post_title;
84
+
85
+ if ('single-product' == $current_section) {
86
+
87
+ $settings = apply_filters('wc_pwb_admin_tab_settings', array(
88
+ 'section_title' => array(
89
+ 'name' => __('Products', 'perfect-woocommerce-brands'),
90
+ 'type' => 'title',
91
+ 'desc' => '',
92
+ 'id' => 'wc_pwb_admin_tab_section_title'
93
+ ),
94
+ 'brand_single_product_tab' => array(
95
+ 'name' => __('Products tab', 'perfect-woocommerce-brands'),
96
+ 'type' => 'checkbox',
97
+ 'default' => 'yes',
98
+ 'desc' => __('Show brand tab in single product page', 'perfect-woocommerce-brands'),
99
+ 'id' => 'wc_pwb_admin_tab_brand_single_product_tab'
100
+ ),
101
+ 'show_brand_in_single' => array(
102
+ 'name' => __('Show brands in single product', 'perfect-woocommerce-brands'),
103
+ 'type' => 'select',
104
+ 'class' => 'pwb-admin-tab-field',
105
+ 'desc' => __('Show brand logo (or name) in single product', 'perfect-woocommerce-brands'),
106
+ 'default' => 'brand_image',
107
+ 'id' => 'wc_pwb_admin_tab_brands_in_single',
108
+ 'options' => array(
109
+ 'no' => __('No', 'perfect-woocommerce-brands'),
110
+ 'brand_link' => __('Show brand link', 'perfect-woocommerce-brands'),
111
+ 'brand_image' => __('Show brand image (if is set)', 'perfect-woocommerce-brands')
112
+ )
113
+ ),
114
+ 'brand_single_position' => array(
115
+ 'name' => __('Brand position', 'perfect-woocommerce-brands'),
116
+ 'type' => 'select',
117
+ 'class' => 'pwb-admin-tab-field',
118
+ 'desc' => __('For single product', 'perfect-woocommerce-brands'),
119
+ 'id' => 'wc_pwb_admin_tab_brand_single_position',
120
+ 'options' => array(
121
+ 'before_title' => __('Before title', 'perfect-woocommerce-brands'),
122
+ 'after_title' => __('After title', 'perfect-woocommerce-brands'),
123
+ 'after_price' => __('After price', 'perfect-woocommerce-brands'),
124
+ 'after_excerpt' => __('After excerpt', 'perfect-woocommerce-brands'),
125
+ 'after_add_to_cart' => __('After add to cart', 'perfect-woocommerce-brands'),
126
+ 'meta' => __('In meta', 'perfect-woocommerce-brands'),
127
+ 'after_meta' => __('After meta', 'perfect-woocommerce-brands'),
128
+ 'after_sharing' => __('After sharing', 'perfect-woocommerce-brands')
129
+ )
130
+ ),
131
+ 'section_end' => array(
132
+ 'type' => 'sectionend',
133
+ 'id' => 'wc_pwb_admin_tab_section_end'
134
+ )
135
+ ));
136
+ } elseif ('brand-pages' == $current_section) {
137
+
138
+ $settings = apply_filters('wc_pwb_admin_tab_brand_pages_settings', array(
139
+ 'section_title' => array(
140
+ 'name' => __('Archives', 'perfect-woocommerce-brands'),
141
+ 'type' => 'title',
142
+ 'desc' => '',
143
+ 'id' => 'wc_pwb_admin_tab_section_title'
144
+ ),
145
+ 'brand_description' => array(
146
+ 'name' => __('Show brand description', 'perfect-woocommerce-brands'),
147
+ 'type' => 'select',
148
+ 'class' => 'pwb-admin-tab-field',
149
+ 'default' => 'yes',
150
+ 'desc' => __('Show brand description (if is set) on brand archive page', 'perfect-woocommerce-brands'),
151
+ 'id' => 'wc_pwb_admin_tab_brand_desc',
152
+ 'options' => array(
153
+ 'yes' => __('Yes, before product loop', 'perfect-woocommerce-brands'),
154
+ 'yes_after_loop' => __('Yes, after product loop', 'perfect-woocommerce-brands'),
155
+ 'no' => __('No, hide description', 'perfect-woocommerce-brands')
156
+ )
157
+ ),
158
+ 'brand_banner' => array(
159
+ 'name' => __('Show brand banner', 'perfect-woocommerce-brands'),
160
+ 'type' => 'select',
161
+ 'class' => 'pwb-admin-tab-field',
162
+ 'default' => 'yes',
163
+ 'desc' => __('Show brand banner (if is set) on brand archive page', 'perfect-woocommerce-brands'),
164
+ 'id' => 'wc_pwb_admin_tab_brand_banner',
165
+ 'options' => array(
166
+ 'yes' => __('Yes, before product loop', 'perfect-woocommerce-brands'),
167
+ 'yes_after_loop' => __('Yes, after product loop', 'perfect-woocommerce-brands'),
168
+ 'no' => __('No, hide banner', 'perfect-woocommerce-brands')
169
+ )
170
+ ),
171
+ 'show_brand_on_loop' => array(
172
+ 'name' => __('Show brands in loop', 'perfect-woocommerce-brands'),
173
+ 'type' => 'select',
174
+ 'class' => 'pwb-admin-tab-field',
175
+ 'desc' => __('Show brand logo (or name) in product loop', 'perfect-woocommerce-brands'),
176
+ 'id' => 'wc_pwb_admin_tab_brands_in_loop',
177
+ 'options' => array(
178
+ 'no' => __('No', 'perfect-woocommerce-brands'),
179
+ 'brand_link' => __('Show brand link', 'perfect-woocommerce-brands'),
180
+ 'brand_image' => __('Show brand image (if is set)', 'perfect-woocommerce-brands')
181
+ )
182
+ ),
183
+ 'section_end' => array(
184
+ 'type' => 'sectionend',
185
+ 'id' => 'wc_pwb_admin_tab_section_end'
186
+ )
187
+ ));
188
+ } elseif ('tools' == $current_section) {
189
+
190
+ $settings = apply_filters('wc_pwb_admin_tab_tools_settings', array(
191
+ 'section_title' => array(
192
+ 'name' => __('Tools', 'perfect-woocommerce-brands'),
193
+ 'type' => 'title',
194
+ 'desc' => '',
195
+ 'id' => 'wc_pwb_admin_tab_section_tools_title'
196
+ ),
197
+ 'brand_import' => array(
198
+ 'name' => __('Import brands', 'perfect-woocommerce-brands'),
199
+ 'type' => 'select',
200
+ 'class' => 'pwb-admin-tab-field',
201
+ 'desc' => sprintf(
202
+ __('Import brands from other brand plugin. <a href="%s" target="_blank">Click here for more details</a>', 'perfect-woocommerce-brands'),
203
+ str_replace('/?', '/brands/?', PWB_DOCUMENTATION_URL)
204
+ ),
205
+ 'id' => 'wc_pwb_admin_tab_tools_migrate',
206
+ 'options' => array(
207
+ '-' => __('-', 'perfect-woocommerce-brands'),
208
+ 'yith' => __('YITH WooCommerce Brands Add-On', 'perfect-woocommerce-brands'),
209
+ 'ultimate' => __('Ultimate WooCommerce Brands', 'perfect-woocommerce-brands'),
210
+ 'woobrands' => __('Offical WooCommerce Brands', 'perfect-woocommerce-brands')
211
+ )
212
+ ),
213
+ 'brand_dummy_data' => array(
214
+ 'name' => __('Dummy data', 'perfect-woocommerce-brands'),
215
+ 'type' => 'select',
216
+ 'class' => 'pwb-admin-tab-field',
217
+ 'desc' => __('Import generic brands and assign it to products randomly', 'perfect-woocommerce-brands'),
218
+ 'id' => 'wc_pwb_admin_tab_tools_dummy_data',
219
+ 'options' => array(
220
+ '-' => __('-', 'perfect-woocommerce-brands'),
221
+ 'start_import' => __('Start import', 'perfect-woocommerce-brands')
222
+ )
223
+ ),
224
+ 'brands_system_status' => array(
225
+ 'name' => __('System status', 'perfect-woocommerce-brands'),
226
+ 'type' => 'textarea',
227
+ 'desc' => __('Show system status', 'perfect-woocommerce-brands'),
228
+ 'id' => 'wc_pwb_admin_tab_tools_system_status'
229
+ ),
230
+ 'section_end' => array(
231
+ 'type' => 'sectionend',
232
+ 'id' => 'wc_pwb_admin_tab_section_tools_end'
233
+ )
234
+ ));
235
+ } else {
236
+
237
+ $brands_url = get_option('wc_pwb_admin_tab_slug', __('brands', 'perfect-woocommerce-brands')) . '/' . __('brand-name', 'perfect-woocommerce-brands') . '/';
238
+
239
+ $settings = apply_filters('wc_pwb_admin_tab_product_settings', array(
240
+ 'section_title' => array(
241
+ 'name' => __('General', 'perfect-woocommerce-brands'),
242
+ 'type' => 'title',
243
+ 'desc' => '',
244
+ 'id' => 'wc_pwb_admin_tab_section_title'
245
+ ),
246
+ 'slug' => array(
247
+ 'name' => __('Slug', 'perfect-woocommerce-brands'),
248
+ 'type' => 'text',
249
+ 'class' => 'pwb-admin-tab-field',
250
+ 'desc' => __('Brands taxonomy slug', 'perfect-woocommerce-brands'),
251
+ 'desc_tip' => sprintf(
252
+ __('Your brands URLs will look like "%s"', 'perfect-woocommerce-brands'),
253
+ 'https://site.com/' . $brands_url
254
+ ),
255
+ 'id' => 'wc_pwb_admin_tab_slug',
256
+ 'placeholder' => get_taxonomy('pwb-brand')->rewrite['slug']
257
+ ),
258
+ 'brand_logo_size' => array(
259
+ 'name' => __('Brand logo size', 'perfect-woocommerce-brands'),
260
+ 'type' => 'select',
261
+ 'class' => 'pwb-admin-tab-field',
262
+ 'desc' => __('Select the size for the brand logo image around the site', 'perfect-woocommerce-brands'),
263
+ 'desc_tip' => __('The default image sizes can be configured under "Settings > Media". You can also define your own image sizes', 'perfect-woocommerce-brands'),
264
+ 'id' => 'wc_pwb_admin_tab_brand_logo_size',
265
+ 'options' => $available_image_sizes_adapted
266
+ ),
267
+ 'brands_page_id' => array(
268
+ 'name' => __('Brands page', 'perfect-woocommerce-brands'),
269
+ 'type' => 'select',
270
+ 'class' => 'pwb-admin-tab-field pwb-admin-selectwoo',
271
+ 'desc' => __('For linking breadcrumbs', 'perfect-woocommerce-brands'),
272
+ 'desc_tip' => __('Select your "Brands" page (if you have one), it will be linked in the breadcrumbs.', 'perfect-woocommerce-brands'),
273
+ 'id' => 'wc_pwb_admin_tab_brands_page_id',
274
+ 'options' => $pages_select_adapted
275
+ ),
276
+ 'section_end' => array(
277
+ 'type' => 'sectionend',
278
+ 'id' => 'wc_pwb_admin_tab_section_end'
279
+ )
280
+ ));
281
  }
282
 
283
+ return apply_filters('woocommerce_get_settings_' . $this->id, $settings, $current_section);
284
+ }
285
+
286
+ public function output()
287
+ {
288
 
289
+ global $current_section;
 
 
 
290
 
291
+ $settings = $this->get_settings($current_section);
292
+ WC_Admin_Settings::output_fields($settings);
293
+ }
294
 
295
+ public function save()
296
+ {
297
+
298
+ update_option('old_wc_pwb_admin_tab_slug', get_taxonomy('pwb-brand')->rewrite['slug']);
299
+ if (isset($_POST['wc_pwb_admin_tab_slug'])) {
300
+ $_POST['wc_pwb_admin_tab_slug'] = sanitize_title($_POST['wc_pwb_admin_tab_slug']);
301
  }
302
 
303
+ global $current_section;
304
 
305
+ $settings = $this->get_settings($current_section);
306
+ WC_Admin_Settings::save_fields($settings);
307
+ }
308
  }
309
 
310
+ return new Pwb_Admin_Tab();
classes/admin/class-pwb-exporter-support.php CHANGED
@@ -19,7 +19,7 @@ class PWB_Exporter_Support{
19
  * @return array $columns
20
  */
21
  public function add_export_column( $columns ) {
22
- $columns['pwb-brand'] = __('Brand', 'perfect-woocommerce-brands');
23
  return $columns;
24
  }
25
 
19
  * @return array $columns
20
  */
21
  public function add_export_column( $columns ) {
22
+ $columns['pwb-brand'] = esc_html__('Brand', 'perfect-woocommerce-brands');
23
  return $columns;
24
  }
25
 
classes/admin/class-pwb-importer-support.php CHANGED
@@ -19,7 +19,7 @@ class PWB_Importer_Support{
19
  * @return array $options
20
  */
21
  public function add_column_to_importer( $options ) {
22
- $options['pwb-brand'] = __('Brand', 'perfect-woocommerce-brands');
23
  return $options;
24
  }
25
 
@@ -30,7 +30,7 @@ class PWB_Importer_Support{
30
  * @return array $columns
31
  */
32
  public function add_column_to_mapping_screen( $columns ) {
33
- $columns[__('Brand', 'perfect-woocommerce-brands')] = 'pwb-brand';
34
  return $columns;
35
  }
36
 
19
  * @return array $options
20
  */
21
  public function add_column_to_importer( $options ) {
22
+ $options['pwb-brand'] = esc_html__('Brand', 'perfect-woocommerce-brands');
23
  return $options;
24
  }
25
 
30
  * @return array $columns
31
  */
32
  public function add_column_to_mapping_screen( $columns ) {
33
+ $columns[esc_html__('Brand', 'perfect-woocommerce-brands')] = 'pwb-brand';
34
  return $columns;
35
  }
36
 
classes/admin/class-pwb-suggestions.php CHANGED
@@ -63,7 +63,7 @@ class PWB_Suggestions {
63
 
64
  public function add_menu() {
65
  add_menu_page(PWB_PLUGIN_NAME, PWB_PLUGIN_NAME, 'manage_woocommerce', PWB_PREFIX, array($this, 'add_page'));
66
- add_submenu_page(PWB_PREFIX, __('Suggestions', 'perfect-woocommerce-brands'), __('Suggestions', 'perfect-woocommerce-brands'), 'manage_woocommerce', PWB_PREFIX . '_suggestions', array($this, 'add_page'));
67
  }
68
 
69
  // fix for activateUrl on install now button
63
 
64
  public function add_menu() {
65
  add_menu_page(PWB_PLUGIN_NAME, PWB_PLUGIN_NAME, 'manage_woocommerce', PWB_PREFIX, array($this, 'add_page'));
66
+ add_submenu_page(PWB_PREFIX, esc_html__('Suggestions', 'perfect-woocommerce-brands'), esc_html__('Suggestions', 'perfect-woocommerce-brands'), 'manage_woocommerce', PWB_PREFIX . '_suggestions', array($this, 'add_page'));
67
  }
68
 
69
  // fix for activateUrl on install now button
classes/class-perfect-woocommerce-brands.php CHANGED
@@ -4,9 +4,11 @@ namespace Perfect_Woocommerce_Brands;
4
 
5
  defined('ABSPATH') or die('No script kiddies please!');
6
 
7
- class Perfect_Woocommerce_Brands {
 
8
 
9
- function __construct() {
 
10
  add_action('plugin_row_meta', array('\Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands', 'plugin_row_meta'), 10, 2);
11
  add_action('woocommerce_init', array($this, 'register_brands_taxonomy'), 10, 0);
12
  add_action('init', array($this, 'add_brands_metafields'));
@@ -25,7 +27,7 @@ class Perfect_Woocommerce_Brands {
25
  add_action('wp_ajax_dismiss_pwb_notice', array($this, 'dismiss_pwb_notice'));
26
  add_action('admin_notices', array($this, 'review_notice'));
27
 
28
- add_action('wp', function() {
29
  if (is_tax('pwb-brand'))
30
  remove_action('woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10);
31
  });
@@ -47,13 +49,15 @@ class Perfect_Woocommerce_Brands {
47
  add_action('delete_term', array($this, 'clean_caches_after_edit_brand'), 10, 3);
48
  }
49
 
50
- public function clean_caches($term_id, $taxonomy) {
 
51
  if ($taxonomy != 'pwb-brand')
52
  return;
53
  delete_transient('pwb_az_listing_cache');
54
  }
55
 
56
- public function clean_caches_after_edit_brand($term_id, $tt_id, $taxonomy) {
 
57
  if ($taxonomy != 'pwb-brand')
58
  return;
59
  delete_transient('pwb_az_listing_cache');
@@ -67,17 +71,19 @@ class Perfect_Woocommerce_Brands {
67
  *
68
  * @return array
69
  */
70
- public static function plugin_row_meta($links, $file) {
 
71
  if (PWB_PLUGIN_BASENAME === $file) {
72
  $row_meta = array(
73
- 'docs' => '<a target="_blank" rel="noopener noferrer" href="' . PWB_DOCUMENTATION_URL . '">' . esc_html__('Documentation', 'perfect-woocommerce-brands') . '</a>',
74
  );
75
  return array_merge($links, $row_meta);
76
  }
77
  return (array) $links;
78
  }
79
 
80
- public function brand_name_in_url($permalink, $post) {
 
81
  if ($post->post_type == 'product' && strpos($permalink, '%pwb-brand%') !== false) {
82
  $term = 'product';
83
  $brands = wp_get_post_terms($post->ID, 'pwb-brand');
@@ -88,7 +94,8 @@ class Perfect_Woocommerce_Brands {
88
  return $permalink;
89
  }
90
 
91
- public function brands_column_sortable_posts($clauses, $wp_query) {
 
92
  global $wpdb;
93
 
94
  if (isset($wp_query->query['orderby']) && 'taxonomy-pwb-brand' == $wp_query->query['orderby']) {
@@ -101,24 +108,27 @@ class Perfect_Woocommerce_Brands {
101
  $clauses['where'] .= " AND (taxonomy = 'pwb-brand' OR taxonomy IS NULL)";
102
  $clauses['groupby'] = "object_id";
103
  $clauses['orderby'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) ";
104
- $clauses['orderby'] .= ( 'ASC' == strtoupper($wp_query->get('order')) ) ? 'ASC' : 'DESC';
105
  }
106
 
107
  return $clauses;
108
  }
109
 
110
- public function brands_column_sortable($columns) {
 
111
  $columns['taxonomy-pwb-brand'] = 'taxonomy-pwb-brand';
112
  return $columns;
113
  }
114
 
115
- public function extend_products_shortcode_atts($out, $pairs, $atts, $shortcode) {
 
116
  if (!empty($atts['brands']))
117
  $out['brands'] = explode(',', $atts['brands']);
118
  return $out;
119
  }
120
 
121
- public function extend_products_shortcode($query_args, $atts) {
 
122
 
123
  if (!empty($atts['brands'])) {
124
  global $wpdb;
@@ -155,7 +165,8 @@ class Perfect_Woocommerce_Brands {
155
  return $query_args;
156
  }
157
 
158
- public function review_notice() {
 
159
  $show_notice = get_option('wc_pwb_notice_plugin_review', true);
160
  $activate_on = get_option('pwb_activate_on', time());
161
  $now = time();
@@ -163,20 +174,21 @@ class Perfect_Woocommerce_Brands {
163
  $date_diff = $now - $activate_on;
164
 
165
  if ($show_notice && $date_diff > $one_week) {
166
- ?>
167
  <div class="notice notice-info pwb-notice-dismissible is-dismissible" data-notice="wc_pwb_notice_plugin_review">
168
- <p><?php echo __('We know that you´re in love with Perfect WooCommerce Brands, you can help us making it a bit better. Thanks a lot!', 'perfect-woocommerce-brands'); ?><span class="dashicons dashicons-heart"></span></p>
169
  <p>
170
- <?php _e('<a href="https://wordpress.org/support/plugin/perfect-woocommerce-brands/reviews/?rate=5#new-post" target="_blank">Leave a review</a>', 'perfect-woocommerce-brands'); ?>
171
- <?php _e('<a href="https://translate.wordpress.org/projects/wp-plugins/perfect-woocommerce-brands" target="_blank">Translate the plugin</a>', 'perfect-woocommerce-brands'); ?>
172
- <?php _e('<a href="' . PWB_GITHUB_URL . '" target="_blank">View on GitHub</a>', 'perfect-woocommerce-brands'); ?>
173
  </p>
174
  </div>
175
- <?php
176
  }
177
  }
178
 
179
- public function dismiss_pwb_notice() {
 
180
  $notice_name_whitelist = array('wc_pwb_notice_plugin_review');
181
  if (isset($_POST['notice_name']) && in_array($_POST['notice_name'], $notice_name_whitelist)) {
182
  update_option($_POST['notice_name'], 0);
@@ -187,7 +199,8 @@ class Perfect_Woocommerce_Brands {
187
  wp_die();
188
  }
189
 
190
- public function pwb_brand_filter($query) {
 
191
 
192
  if (!empty($_GET['pwb-brand-filter'])) {
193
 
@@ -206,11 +219,11 @@ class Perfect_Woocommerce_Brands {
206
  if ($filterable_product && $query->is_main_query()) {
207
 
208
  $query->set('tax_query', array(
209
- array(
210
- 'taxonomy' => 'pwb-brand',
211
- 'field' => 'slug',
212
- 'terms' => $terms_array
213
- )
214
  ));
215
  }
216
  }
@@ -220,7 +233,8 @@ class Perfect_Woocommerce_Brands {
220
  * Adds microdata (brands) to single products
221
  */
222
 
223
- public function product_microdata($markup, $product) {
 
224
 
225
  $new_markup = array();
226
  $brands = wp_get_post_terms($product->get_id(), 'pwb-brand');
@@ -231,36 +245,39 @@ class Perfect_Woocommerce_Brands {
231
  return array_merge($markup, $new_markup);
232
  }
233
 
234
- public function add_shortcodes() {
 
235
  add_shortcode('pwb-carousel', array(
236
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Carousel_Shortcode',
237
- 'carousel_shortcode'
238
  ));
239
  add_shortcode('pwb-product-carousel', array(
240
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Product_Carousel_Shortcode',
241
- 'product_carousel_shortcode'
242
  ));
243
  add_shortcode('pwb-all-brands', array(
244
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_All_Brands_Shortcode',
245
- 'all_brands_shortcode'
246
  ));
247
  add_shortcode('pwb-az-listing', array(
248
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_AZ_Listing_Shortcode',
249
- 'shortcode'
250
  ));
251
  add_shortcode('pwb-brand', array(
252
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Brand_Shortcode',
253
- 'brand_shortcode'
254
  ));
255
  }
256
 
257
- public function register_widgets() {
 
258
  register_widget('\Perfect_Woocommerce_Brands\Widgets\PWB_List_Widget');
259
  register_widget('\Perfect_Woocommerce_Brands\Widgets\PWB_Dropdown_Widget');
260
  register_widget('\Perfect_Woocommerce_Brands\Widgets\PWB_Filter_By_Brand_Widget');
261
  }
262
 
263
- public function show_brands_in_loop() {
 
264
 
265
  $brands_in_loop = get_option('wc_pwb_admin_tab_brands_in_loop');
266
  $image_size_selected = get_option('wc_pwb_admin_tab_brand_logo_size', 'thumbnail');
@@ -302,7 +319,8 @@ class Perfect_Woocommerce_Brands {
302
  * @hooked woocommerce_template_single_meta - 40
303
  * @hooked woocommerce_template_single_sharing - 50
304
  */
305
- private function brand_logo_position() {
 
306
  $position = 41;
307
  $position_selected = get_option('wc_pwb_admin_tab_brand_single_position');
308
  if (!$position_selected) {
@@ -340,7 +358,8 @@ class Perfect_Woocommerce_Brands {
340
  }
341
  }
342
 
343
- public function brand_desc_position() {
 
344
 
345
  if (is_tax('pwb-brand') && !is_paged()) {
346
 
@@ -379,7 +398,8 @@ class Perfect_Woocommerce_Brands {
379
  * @return mixed
380
  */
381
 
382
- public function vc_map_shortcodes() {
 
383
  $available_image_sizes_adapted = array();
384
  $available_image_sizes = get_intermediate_image_sizes();
385
 
@@ -388,231 +408,232 @@ class Perfect_Woocommerce_Brands {
388
  }
389
 
390
  vc_map(array(
391
- "name" => __("PWB Product carousel", "perfect-woocommerce-brands"),
392
- "description" => __("Product carousel by brand or by category", "perfect-woocommerce-brands"),
393
- "base" => "pwb-product-carousel",
394
- "class" => "",
395
- "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
396
- "category" => "WooCommerce",
397
- "params" => array(
398
- array(
399
- "type" => "dropdown",
400
- "heading" => __("Brand", "perfect-woocommerce-brands"),
401
- "param_name" => "brand",
402
- "admin_label" => true,
403
- "value" => self::get_brands_array(true)
404
- ),
405
- array(
406
- "type" => "textfield",
407
- "holder" => "div",
408
- "heading" => __("Products", "perfect-woocommerce-brands"),
409
- "param_name" => "products",
410
- "value" => "10",
411
- "description" => __("Number of products to load", "perfect-woocommerce-brands")
412
- ),
413
- array(
414
- "type" => "textfield",
415
- "holder" => "div",
416
- "heading" => __("Products to show", "perfect-woocommerce-brands"),
417
- "param_name" => "products_to_show",
418
- "value" => "5",
419
- "description" => __("Number of products to show", "perfect-woocommerce-brands")
420
- ),
421
- array(
422
- "type" => "textfield",
423
- "holder" => "div",
424
- "heading" => __("Products to scroll", "perfect-woocommerce-brands"),
425
- "param_name" => "products_to_scroll",
426
- "value" => "1",
427
- "description" => __("Number of products to scroll", "perfect-woocommerce-brands")
428
- ),
429
- array(
430
- "type" => "checkbox",
431
- "holder" => "div",
432
- "heading" => __("Autoplay", "perfect-woocommerce-brands"),
433
- "param_name" => "autoplay",
434
- "description" => __("Autoplay carousel", "perfect-woocommerce-brands")
435
- ),
436
- array(
437
- "type" => "checkbox",
438
- "holder" => "div",
439
- "heading" => __("Arrows", "perfect-woocommerce-brands"),
440
- "param_name" => "arrows",
441
- "description" => __("Display prev and next arrows", "perfect-woocommerce-brands")
442
- )
443
  )
 
444
  ));
445
 
446
  vc_map(array(
447
- "name" => __("PWB Brands carousel", "perfect-woocommerce-brands"),
448
- "description" => __("Brands carousel", "perfect-woocommerce-brands"),
449
- "base" => "pwb-carousel",
450
- "class" => "",
451
- "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
452
- "category" => "WooCommerce",
453
- "params" => array(
454
- array(
455
- "type" => "textfield",
456
- "holder" => "div",
457
- "heading" => __("Items", "perfect-woocommerce-brands"),
458
- "param_name" => "items",
459
- "value" => "10",
460
- "description" => __("Number of items to load (or 'featured')", "perfect-woocommerce-brands")
461
- ),
462
- array(
463
- "type" => "textfield",
464
- "holder" => "div",
465
- "heading" => __("Items to show", "perfect-woocommerce-brands"),
466
- "param_name" => "items_to_show",
467
- "value" => "5",
468
- "description" => __("Number of items to show", "perfect-woocommerce-brands")
469
- ),
470
- array(
471
- "type" => "textfield",
472
- "holder" => "div",
473
- "heading" => __("Items to scroll", "perfect-woocommerce-brands"),
474
- "param_name" => "items_to_scroll",
475
- "value" => "1",
476
- "description" => __("Number of items to scroll", "perfect-woocommerce-brands")
477
- ),
478
- array(
479
- "type" => "checkbox",
480
- "holder" => "div",
481
- "heading" => __("Autoplay", "perfect-woocommerce-brands"),
482
- "param_name" => "autoplay",
483
- "description" => __("Autoplay carousel", "perfect-woocommerce-brands")
484
- ),
485
- array(
486
- "type" => "checkbox",
487
- "holder" => "div",
488
- "heading" => __("Arrows", "perfect-woocommerce-brands"),
489
- "param_name" => "arrows",
490
- "description" => __("Display prev and next arrows", "perfect-woocommerce-brands")
491
- ),
492
- array(
493
- "type" => "dropdown",
494
- "heading" => __("Brand logo size", "perfect-woocommerce-brands"),
495
- "param_name" => "image_size",
496
- "admin_label" => true,
497
- "value" => $available_image_sizes_adapted
498
- )
499
  )
 
500
  ));
501
 
502
  vc_map(array(
503
- "name" => __("PWB All brands", "perfect-woocommerce-brands"),
504
- "description" => __("Show all brands", "perfect-woocommerce-brands"),
505
- "base" => "pwb-all-brands",
506
- "class" => "",
507
- "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
508
- "category" => "WooCommerce",
509
- "params" => array(
510
- array(
511
- "type" => "textfield",
512
- "holder" => "div",
513
- "heading" => __("Brands per page", "perfect-woocommerce-brands"),
514
- "param_name" => "per_page",
515
- "value" => "10",
516
- "description" => __("Show x brands per page", "perfect-woocommerce-brands")
517
- ),
518
- array(
519
- "type" => "dropdown",
520
- "heading" => __("Brand logo size", "perfect-woocommerce-brands"),
521
- "param_name" => "image_size",
522
- "admin_label" => true,
523
- "value" => $available_image_sizes_adapted
524
- ),
525
- array(
526
- "type" => "dropdown",
527
- "heading" => __("Order by", "perfect-woocommerce-brands"),
528
- "param_name" => "order_by",
529
- "admin_label" => true,
530
- "value" => array(
531
- 'name' => 'name',
532
- 'slug' => 'slug',
533
- 'term_id' => 'term_id',
534
- 'id' => 'id',
535
- 'description' => 'description',
536
- 'rand' => 'rand'
537
- )
538
- ),
539
- array(
540
- "type" => "dropdown",
541
- "heading" => __("Order", "perfect-woocommerce-brands"),
542
- "param_name" => "order",
543
- "admin_label" => true,
544
- "value" => array(
545
- 'ASC' => 'ASC',
546
- 'DSC' => 'DSC'
547
- )
548
- ),
549
- array(
550
- "type" => "dropdown",
551
- "heading" => __("Title position", "perfect-woocommerce-brands"),
552
- "param_name" => "title_position",
553
- "admin_label" => true,
554
- "value" => array(
555
- __("Before image", "perfect-woocommerce-brands") => 'before',
556
- __("After image", "perfect-woocommerce-brands") => 'after',
557
- __("Hide", "perfect-woocommerce-brands") => 'none'
558
- )
559
- ),
560
- array(
561
- "type" => "checkbox",
562
- "holder" => "div",
563
- "heading" => __("Hide empty", "perfect-woocommerce-brands"),
564
- "param_name" => "hide_empty",
565
- "description" => __("Hide brands that have not been assigned to any product", "perfect-woocommerce-brands")
566
- )
567
  )
 
568
  ));
569
 
570
  vc_map(array(
571
- "name" => __("PWB AZ Listing", "perfect-woocommerce-brands"),
572
- "description" => __("AZ Listing for brands", "perfect-woocommerce-brands"),
573
- "base" => "pwb-az-listing",
574
- "class" => "",
575
- "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
576
- "category" => "WooCommerce",
577
- "params" => array(
578
- array(
579
- "type" => "dropdown",
580
- "heading" => __("Only parent brands", "perfect-woocommerce-brands"),
581
- "param_name" => "only_parents",
582
- "admin_label" => true,
583
- "value" => array(__('No') => 'no', __('Yes') => 'yes'),
584
- )
585
  )
 
586
  ));
587
 
588
  vc_map(array(
589
- "name" => __("PWB brand", "perfect-woocommerce-brands"),
590
- "description" => __("Show brand for a specific product", "perfect-woocommerce-brands"),
591
- "base" => "pwb-brand",
592
- "class" => "",
593
- "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
594
- "category" => "WooCommerce",
595
- "params" => array(
596
- array(
597
- "type" => "textfield",
598
- "holder" => "div",
599
- "heading" => __("Product id", "perfect-woocommerce-brands"),
600
- "param_name" => "product_id",
601
- "value" => null,
602
- "description" => __("Product id (post id)", "perfect-woocommerce-brands")
603
- ),
604
- array(
605
- "type" => "dropdown",
606
- "heading" => __("Brand logo size", "perfect-woocommerce-brands"),
607
- "param_name" => "image_size",
608
- "admin_label" => true,
609
- "value" => $available_image_sizes_adapted
610
- )
611
  )
 
612
  ));
613
  }
614
 
615
- public function action_woocommerce_single_product_summary() {
 
616
  $brands = wp_get_post_terms(get_the_ID(), 'pwb-brand');
617
 
618
  if (!is_wp_error($brands)) {
@@ -629,7 +650,7 @@ class Perfect_Woocommerce_Brands {
629
 
630
  if ($show_as == 'brand_link') {
631
  $before_brands_links = '<span class="pwb-text-before-brands-links">';
632
- $before_brands_links .= apply_filters('pwb_text_before_brands_links', __('Brands', 'perfect-woocommerce-brands'));
633
  $before_brands_links .= ':</span>';
634
  echo apply_filters('pwb_html_before_brands_links', $before_brands_links);
635
  }
@@ -649,7 +670,7 @@ class Perfect_Woocommerce_Brands {
649
  if (!empty($attachment_html) && $show_as == 'brand_image' || !empty($attachment_html) && !$show_as) {
650
  echo '<a href="' . $brand_link . '" title="' . $brand->name . '">' . $attachment_html . '</a>';
651
  } else {
652
- echo '<a href="' . $brand_link . '" title="' . __('View brand', 'perfect-woocommerce-brands') . '">' . $brand->name . '</a>';
653
  }
654
  }
655
  echo '</div>';
@@ -660,33 +681,51 @@ class Perfect_Woocommerce_Brands {
660
  }
661
  }
662
 
663
- public function enqueue_scripts() {
 
664
 
665
  wp_register_script(
666
- 'pwb-lib-slick', PWB_PLUGIN_URL . '/assets/lib/slick/slick.min.js', array('jquery'), '1.8.0', true
 
 
 
 
667
  );
668
 
669
  wp_register_style(
670
- 'pwb-lib-slick', PWB_PLUGIN_URL . '/assets/lib/slick/slick.css', array(), '1.8.0', 'all'
 
 
 
 
671
  );
672
 
673
  wp_enqueue_style(
674
- 'pwb-styles-frontend', PWB_PLUGIN_URL . '/assets/css/styles-frontend.min.css', array(), PWB_PLUGIN_VERSION, 'all'
 
 
 
 
675
  );
676
 
677
  wp_register_script(
678
- 'pwb-functions-frontend', PWB_PLUGIN_URL . '/assets/js/functions-frontend.min.js', array('jquery'), PWB_PLUGIN_VERSION, true
 
 
 
 
679
  );
680
 
681
  wp_localize_script('pwb-functions-frontend', 'pwb_ajax_object', array(
682
- 'carousel_prev' => apply_filters('pwb_carousel_prev', '&lt;'),
683
- 'carousel_next' => apply_filters('pwb_carousel_next', '&gt;')
684
  ));
685
 
686
  wp_enqueue_script('pwb-functions-frontend');
687
  }
688
 
689
- public function admin_enqueue_scripts($hook) {
 
690
  $screen = get_current_screen();
691
  if ($hook == 'edit-tags.php' && $screen->taxonomy == 'pwb-brand' || $hook == 'term.php' && $screen->taxonomy == 'pwb-brand') {
692
  wp_enqueue_media();
@@ -696,38 +735,39 @@ class Perfect_Woocommerce_Brands {
696
 
697
  wp_register_script('pwb-functions-admin', PWB_PLUGIN_URL . '/assets/js/functions-admin.min.js', array('jquery'), PWB_PLUGIN_VERSION, true);
698
  wp_localize_script('pwb-functions-admin', 'pwb_ajax_object_admin', array(
699
- 'ajax_url' => admin_url('admin-ajax.php'),
700
- 'site_url' => site_url(),
701
- 'brands_url' => admin_url('edit-tags.php?taxonomy=pwb-brand&post_type=product'),
702
- 'translations' => array(
703
- 'migrate_notice' => __('¿Start migration?', 'perfect-woocommerce-brands'),
704
- 'migrating' => __('We are migrating the product brands. ¡Don´t close this window until the process is finished!', 'perfect-woocommerce-brands'),
705
- 'dummy_data_notice' => __('¿Start loading dummy data?', 'perfect-woocommerce-brands'),
706
- 'dummy_data' => __('We are importing the dummy data. ¡Don´t close this window until the process is finished!', 'perfect-woocommerce-brands')
707
- )
708
  ));
709
  wp_enqueue_script('pwb-functions-admin');
710
  }
711
 
712
- public function register_brands_taxonomy() {
 
713
  $labels = array(
714
- 'name' => __('Brands', 'perfect-woocommerce-brands'),
715
- 'singular_name' => __('Brand', 'perfect-woocommerce-brands'),
716
- 'menu_name' => __('Brands', 'perfect-woocommerce-brands'),
717
- 'all_items' => __('All Brands', 'perfect-woocommerce-brands'),
718
- 'edit_item' => __('Edit Brand', 'perfect-woocommerce-brands'),
719
- 'view_item' => __('View Brand', 'perfect-woocommerce-brands'),
720
- 'update_item' => __('Update Brand', 'perfect-woocommerce-brands'),
721
- 'add_new_item' => __('Add New Brand', 'perfect-woocommerce-brands'),
722
- 'new_item_name' => __('New Brand Name', 'perfect-woocommerce-brands'),
723
- 'parent_item' => __('Parent Brand', 'perfect-woocommerce-brands'),
724
- 'parent_item_colon' => __('Parent Brand:', 'perfect-woocommerce-brands'),
725
- 'search_items' => __('Search Brands', 'perfect-woocommerce-brands'),
726
- 'popular_items' => __('Popular Brands', 'perfect-woocommerce-brands'),
727
- 'separate_items_with_commas' => __('Separate brands with commas', 'perfect-woocommerce-brands'),
728
- 'add_or_remove_items' => __('Add or remove brands', 'perfect-woocommerce-brands'),
729
- 'choose_from_most_used' => __('Choose from the most used brands', 'perfect-woocommerce-brands'),
730
- 'not_found' => __('No brands found', 'perfect-woocommerce-brands')
731
  );
732
 
733
  $new_slug = get_option('wc_pwb_admin_tab_slug');
@@ -737,18 +777,18 @@ class Perfect_Woocommerce_Brands {
737
  $old_slug = ($old_slug != false) ? $old_slug : 'null';
738
 
739
  $args = array(
 
 
 
 
 
 
 
 
740
  'hierarchical' => true,
741
- 'labels' => $labels,
742
- 'show_ui' => true,
743
- 'query_var' => true,
744
- 'public' => true,
745
- 'show_admin_column' => true,
746
- 'rewrite' => array(
747
- 'slug' => apply_filters('pwb_taxonomy_rewrite', $new_slug),
748
- 'hierarchical' => true,
749
- 'with_front' => apply_filters('pwb_taxonomy_with_front', true),
750
- 'ep_mask' => EP_PERMALINK
751
- )
752
  );
753
 
754
  register_taxonomy('pwb-brand', array('product'), $args);
@@ -759,15 +799,18 @@ class Perfect_Woocommerce_Brands {
759
  }
760
  }
761
 
762
- public function add_brands_metafields() {
 
763
  register_meta('term', 'pwb_brand_image', array($this, 'add_brands_metafields_sanitize'));
764
  }
765
 
766
- public function add_brands_metafields_sanitize($brand_img) {
 
767
  return $brand_img;
768
  }
769
 
770
- public static function get_brands($hide_empty = false, $order_by = 'name', $order = 'ASC', $only_featured = false, $pwb_term = false, $only_parents = false) {
 
771
  $result = array();
772
 
773
  $brands_args = array('hide_empty' => $hide_empty, 'orderby' => $order_by, 'order' => $order);
@@ -796,15 +839,16 @@ class Perfect_Woocommerce_Brands {
796
  return $result;
797
  }
798
 
799
- public static function get_brands_array($is_select = false) {
 
800
  $result = array();
801
 
802
  //if is for select input adds default value
803
  if ($is_select)
804
- $result[0] = __('All', 'perfect-woocommerce-brands');
805
 
806
  $brands = get_terms('pwb-brand', array(
807
- 'hide_empty' => false
808
  ));
809
 
810
  foreach ($brands as $brand) {
@@ -814,13 +858,14 @@ class Perfect_Woocommerce_Brands {
814
  return $result;
815
  }
816
 
817
- public function print_brand_banner() {
 
818
  $queried_object = get_queried_object();
819
  $brand_banner = get_term_meta($queried_object->term_id, 'pwb_brand_banner', true);
820
  $brand_banner_link = get_term_meta($queried_object->term_id, 'pwb_brand_banner_link', true);
821
  $show_banner = get_option('wc_pwb_admin_tab_brand_banner');
822
  $show_banner = get_option('wc_pwb_admin_tab_brand_banner');
823
- $show_banner_class = (!$show_banner || $show_banner == 'yes' ) ? 'pwb-before-loop' : 'pwb-after-loop';
824
 
825
  if ($brand_banner != '') {
826
  echo '<div class="pwb-brand-banner pwb-clearfix ' . $show_banner_class . '">';
@@ -833,11 +878,12 @@ class Perfect_Woocommerce_Brands {
833
  }
834
  }
835
 
836
- public function print_brand_desc() {
 
837
  $queried_object = get_queried_object();
838
  $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
839
  $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
840
- $show_desc_class = (!$show_desc || $show_desc == 'yes' ) ? 'pwb-before-loop' : 'pwb-after-loop';
841
 
842
  if ($queried_object->description != '' && $show_desc !== 'no') {
843
  echo '<div class="pwb-brand-description ' . $show_desc_class . '">';
@@ -846,11 +892,12 @@ class Perfect_Woocommerce_Brands {
846
  }
847
  }
848
 
849
- public function print_brand_banner_and_desc() {
 
850
  $queried_object = get_queried_object();
851
 
852
  $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
853
- $show_desc_class = (!$show_desc || $show_desc == 'yes' ) ? 'pwb-before-loop' : 'pwb-after-loop';
854
 
855
  $brand_banner = get_term_meta($queried_object->term_id, 'pwb_brand_banner', true);
856
  $brand_banner_link = get_term_meta($queried_object->term_id, 'pwb_brand_banner_link', true);
@@ -863,7 +910,8 @@ class Perfect_Woocommerce_Brands {
863
  }
864
  }
865
 
866
- public static function render_template($name, $folder = '', $data, $private = true) {
 
867
  //default template
868
  if ($folder)
869
  $folder = $folder . '/';
@@ -883,12 +931,14 @@ class Perfect_Woocommerce_Brands {
883
  return ob_get_clean();
884
  }
885
 
886
- public function product_duplicate_save($duplicate, $product) {
 
887
  $product_brands = wp_get_object_terms($product->get_id(), 'pwb-brand', array('fields' => 'ids'));
888
  wp_set_object_terms($duplicate->get_id(), $product_brands, 'pwb-brand');
889
  }
890
 
891
- public function breadcrumbs($crumbs) {
 
892
 
893
  if (is_tax('pwb-brand')) {
894
 
@@ -899,7 +949,7 @@ class Perfect_Woocommerce_Brands {
899
  $cur_brand = get_queried_object();
900
  $brand_ancestors = get_ancestors($cur_brand->term_id, 'pwb-brand', 'taxonomy');
901
 
902
- $brand_page_pos = count($crumbs) - ( count($brand_ancestors) + 2 );
903
  if (is_paged())
904
  $brand_page_pos -= 1;
905
 
@@ -915,7 +965,8 @@ class Perfect_Woocommerce_Brands {
915
  * Redirect if the search matchs with a brands name
916
  * Better search experience
917
  */
918
- public function search_by_brand_name($query) {
 
919
 
920
  if (wp_doing_ajax())
921
  return;
@@ -931,5 +982,4 @@ class Perfect_Woocommerce_Brands {
931
  }
932
  }
933
  }
934
-
935
  }
4
 
5
  defined('ABSPATH') or die('No script kiddies please!');
6
 
7
+ class Perfect_Woocommerce_Brands
8
+ {
9
 
10
+ function __construct()
11
+ {
12
  add_action('plugin_row_meta', array('\Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands', 'plugin_row_meta'), 10, 2);
13
  add_action('woocommerce_init', array($this, 'register_brands_taxonomy'), 10, 0);
14
  add_action('init', array($this, 'add_brands_metafields'));
27
  add_action('wp_ajax_dismiss_pwb_notice', array($this, 'dismiss_pwb_notice'));
28
  add_action('admin_notices', array($this, 'review_notice'));
29
 
30
+ add_action('wp', function () {
31
  if (is_tax('pwb-brand'))
32
  remove_action('woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10);
33
  });
49
  add_action('delete_term', array($this, 'clean_caches_after_edit_brand'), 10, 3);
50
  }
51
 
52
+ public function clean_caches($term_id, $taxonomy)
53
+ {
54
  if ($taxonomy != 'pwb-brand')
55
  return;
56
  delete_transient('pwb_az_listing_cache');
57
  }
58
 
59
+ public function clean_caches_after_edit_brand($term_id, $tt_id, $taxonomy)
60
+ {
61
  if ($taxonomy != 'pwb-brand')
62
  return;
63
  delete_transient('pwb_az_listing_cache');
71
  *
72
  * @return array
73
  */
74
+ public static function plugin_row_meta($links, $file)
75
+ {
76
  if (PWB_PLUGIN_BASENAME === $file) {
77
  $row_meta = array(
78
+ 'docs' => '<a target="_blank" rel="noopener noferrer" href="' . PWB_DOCUMENTATION_URL . '">' . esc_html__('Documentation', 'perfect-woocommerce-brands') . '</a>',
79
  );
80
  return array_merge($links, $row_meta);
81
  }
82
  return (array) $links;
83
  }
84
 
85
+ public function brand_name_in_url($permalink, $post)
86
+ {
87
  if ($post->post_type == 'product' && strpos($permalink, '%pwb-brand%') !== false) {
88
  $term = 'product';
89
  $brands = wp_get_post_terms($post->ID, 'pwb-brand');
94
  return $permalink;
95
  }
96
 
97
+ public function brands_column_sortable_posts($clauses, $wp_query)
98
+ {
99
  global $wpdb;
100
 
101
  if (isset($wp_query->query['orderby']) && 'taxonomy-pwb-brand' == $wp_query->query['orderby']) {
108
  $clauses['where'] .= " AND (taxonomy = 'pwb-brand' OR taxonomy IS NULL)";
109
  $clauses['groupby'] = "object_id";
110
  $clauses['orderby'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) ";
111
+ $clauses['orderby'] .= ('ASC' == strtoupper($wp_query->get('order'))) ? 'ASC' : 'DESC';
112
  }
113
 
114
  return $clauses;
115
  }
116
 
117
+ public function brands_column_sortable($columns)
118
+ {
119
  $columns['taxonomy-pwb-brand'] = 'taxonomy-pwb-brand';
120
  return $columns;
121
  }
122
 
123
+ public function extend_products_shortcode_atts($out, $pairs, $atts, $shortcode)
124
+ {
125
  if (!empty($atts['brands']))
126
  $out['brands'] = explode(',', $atts['brands']);
127
  return $out;
128
  }
129
 
130
+ public function extend_products_shortcode($query_args, $atts)
131
+ {
132
 
133
  if (!empty($atts['brands'])) {
134
  global $wpdb;
165
  return $query_args;
166
  }
167
 
168
+ public function review_notice()
169
+ {
170
  $show_notice = get_option('wc_pwb_notice_plugin_review', true);
171
  $activate_on = get_option('pwb_activate_on', time());
172
  $now = time();
174
  $date_diff = $now - $activate_on;
175
 
176
  if ($show_notice && $date_diff > $one_week) {
177
+ ?>
178
  <div class="notice notice-info pwb-notice-dismissible is-dismissible" data-notice="wc_pwb_notice_plugin_review">
179
+ <p><?php echo esc_html__('We know that you´re in love with Perfect WooCommerce Brands, you can help us making it a bit better. Thanks a lot!', 'perfect-woocommerce-brands'); ?><span class="dashicons dashicons-heart"></span></p>
180
  <p>
181
+ <a href="https://wordpress.org/support/plugin/perfect-woocommerce-brands/reviews/?rate=5#new-post" target="_blank"><?php esc_html_e('Leave a review', 'perfect-woocommerce-brands'); ?></a>
182
+ <a href="https://translate.wordpress.org/projects/wp-plugins/perfect-woocommerce-brands" target="_blank"><?php esc_html_e('Translate the plugin', 'perfect-woocommerce-brands'); ?></a>
183
+ <a href="<?php echo esc_url(PWB_GITHUB_URL); ?>" target="_blank"><?php esc_html_e('View on GitHub', 'perfect-woocommerce-brands'); ?></a>
184
  </p>
185
  </div>
186
+ <?php
187
  }
188
  }
189
 
190
+ public function dismiss_pwb_notice()
191
+ {
192
  $notice_name_whitelist = array('wc_pwb_notice_plugin_review');
193
  if (isset($_POST['notice_name']) && in_array($_POST['notice_name'], $notice_name_whitelist)) {
194
  update_option($_POST['notice_name'], 0);
199
  wp_die();
200
  }
201
 
202
+ public function pwb_brand_filter($query)
203
+ {
204
 
205
  if (!empty($_GET['pwb-brand-filter'])) {
206
 
219
  if ($filterable_product && $query->is_main_query()) {
220
 
221
  $query->set('tax_query', array(
222
+ array(
223
+ 'taxonomy' => 'pwb-brand',
224
+ 'field' => 'slug',
225
+ 'terms' => $terms_array
226
+ )
227
  ));
228
  }
229
  }
233
  * Adds microdata (brands) to single products
234
  */
235
 
236
+ public function product_microdata($markup, $product)
237
+ {
238
 
239
  $new_markup = array();
240
  $brands = wp_get_post_terms($product->get_id(), 'pwb-brand');
245
  return array_merge($markup, $new_markup);
246
  }
247
 
248
+ public function add_shortcodes()
249
+ {
250
  add_shortcode('pwb-carousel', array(
251
+ '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Carousel_Shortcode',
252
+ 'carousel_shortcode'
253
  ));
254
  add_shortcode('pwb-product-carousel', array(
255
+ '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Product_Carousel_Shortcode',
256
+ 'product_carousel_shortcode'
257
  ));
258
  add_shortcode('pwb-all-brands', array(
259
+ '\Perfect_Woocommerce_Brands\Shortcodes\PWB_All_Brands_Shortcode',
260
+ 'all_brands_shortcode'
261
  ));
262
  add_shortcode('pwb-az-listing', array(
263
+ '\Perfect_Woocommerce_Brands\Shortcodes\PWB_AZ_Listing_Shortcode',
264
+ 'shortcode'
265
  ));
266
  add_shortcode('pwb-brand', array(
267
+ '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Brand_Shortcode',
268
+ 'brand_shortcode'
269
  ));
270
  }
271
 
272
+ public function register_widgets()
273
+ {
274
  register_widget('\Perfect_Woocommerce_Brands\Widgets\PWB_List_Widget');
275
  register_widget('\Perfect_Woocommerce_Brands\Widgets\PWB_Dropdown_Widget');
276
  register_widget('\Perfect_Woocommerce_Brands\Widgets\PWB_Filter_By_Brand_Widget');
277
  }
278
 
279
+ public function show_brands_in_loop()
280
+ {
281
 
282
  $brands_in_loop = get_option('wc_pwb_admin_tab_brands_in_loop');
283
  $image_size_selected = get_option('wc_pwb_admin_tab_brand_logo_size', 'thumbnail');
319
  * @hooked woocommerce_template_single_meta - 40
320
  * @hooked woocommerce_template_single_sharing - 50
321
  */
322
+ private function brand_logo_position()
323
+ {
324
  $position = 41;
325
  $position_selected = get_option('wc_pwb_admin_tab_brand_single_position');
326
  if (!$position_selected) {
358
  }
359
  }
360
 
361
+ public function brand_desc_position()
362
+ {
363
 
364
  if (is_tax('pwb-brand') && !is_paged()) {
365
 
398
  * @return mixed
399
  */
400
 
401
+ public function vc_map_shortcodes()
402
+ {
403
  $available_image_sizes_adapted = array();
404
  $available_image_sizes = get_intermediate_image_sizes();
405
 
408
  }
409
 
410
  vc_map(array(
411
+ "name" => __("PWB Product carousel", "perfect-woocommerce-brands"),
412
+ "description" => __("Product carousel by brand or by category", "perfect-woocommerce-brands"),
413
+ "base" => "pwb-product-carousel",
414
+ "class" => "",
415
+ "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
416
+ "category" => "WooCommerce",
417
+ "params" => array(
418
+ array(
419
+ "type" => "dropdown",
420
+ "heading" => __("Brand", "perfect-woocommerce-brands"),
421
+ "param_name" => "brand",
422
+ "admin_label" => true,
423
+ "value" => self::get_brands_array(true)
424
+ ),
425
+ array(
426
+ "type" => "textfield",
427
+ "holder" => "div",
428
+ "heading" => __("Products", "perfect-woocommerce-brands"),
429
+ "param_name" => "products",
430
+ "value" => "10",
431
+ "description" => __("Number of products to load", "perfect-woocommerce-brands")
432
+ ),
433
+ array(
434
+ "type" => "textfield",
435
+ "holder" => "div",
436
+ "heading" => __("Products to show", "perfect-woocommerce-brands"),
437
+ "param_name" => "products_to_show",
438
+ "value" => "5",
439
+ "description" => __("Number of products to show", "perfect-woocommerce-brands")
440
+ ),
441
+ array(
442
+ "type" => "textfield",
443
+ "holder" => "div",
444
+ "heading" => __("Products to scroll", "perfect-woocommerce-brands"),
445
+ "param_name" => "products_to_scroll",
446
+ "value" => "1",
447
+ "description" => __("Number of products to scroll", "perfect-woocommerce-brands")
448
+ ),
449
+ array(
450
+ "type" => "checkbox",
451
+ "holder" => "div",
452
+ "heading" => __("Autoplay", "perfect-woocommerce-brands"),
453
+ "param_name" => "autoplay",
454
+ "description" => __("Autoplay carousel", "perfect-woocommerce-brands")
455
+ ),
456
+ array(
457
+ "type" => "checkbox",
458
+ "holder" => "div",
459
+ "heading" => __("Arrows", "perfect-woocommerce-brands"),
460
+ "param_name" => "arrows",
461
+ "description" => __("Display prev and next arrows", "perfect-woocommerce-brands")
 
462
  )
463
+ )
464
  ));
465
 
466
  vc_map(array(
467
+ "name" => __("PWB Brands carousel", "perfect-woocommerce-brands"),
468
+ "description" => __("Brands carousel", "perfect-woocommerce-brands"),
469
+ "base" => "pwb-carousel",
470
+ "class" => "",
471
+ "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
472
+ "category" => "WooCommerce",
473
+ "params" => array(
474
+ array(
475
+ "type" => "textfield",
476
+ "holder" => "div",
477
+ "heading" => __("Items", "perfect-woocommerce-brands"),
478
+ "param_name" => "items",
479
+ "value" => "10",
480
+ "description" => __("Number of items to load (or 'featured')", "perfect-woocommerce-brands")
481
+ ),
482
+ array(
483
+ "type" => "textfield",
484
+ "holder" => "div",
485
+ "heading" => __("Items to show", "perfect-woocommerce-brands"),
486
+ "param_name" => "items_to_show",
487
+ "value" => "5",
488
+ "description" => __("Number of items to show", "perfect-woocommerce-brands")
489
+ ),
490
+ array(
491
+ "type" => "textfield",
492
+ "holder" => "div",
493
+ "heading" => __("Items to scroll", "perfect-woocommerce-brands"),
494
+ "param_name" => "items_to_scroll",
495
+ "value" => "1",
496
+ "description" => __("Number of items to scroll", "perfect-woocommerce-brands")
497
+ ),
498
+ array(
499
+ "type" => "checkbox",
500
+ "holder" => "div",
501
+ "heading" => __("Autoplay", "perfect-woocommerce-brands"),
502
+ "param_name" => "autoplay",
503
+ "description" => __("Autoplay carousel", "perfect-woocommerce-brands")
504
+ ),
505
+ array(
506
+ "type" => "checkbox",
507
+ "holder" => "div",
508
+ "heading" => __("Arrows", "perfect-woocommerce-brands"),
509
+ "param_name" => "arrows",
510
+ "description" => __("Display prev and next arrows", "perfect-woocommerce-brands")
511
+ ),
512
+ array(
513
+ "type" => "dropdown",
514
+ "heading" => __("Brand logo size", "perfect-woocommerce-brands"),
515
+ "param_name" => "image_size",
516
+ "admin_label" => true,
517
+ "value" => $available_image_sizes_adapted
 
518
  )
519
+ )
520
  ));
521
 
522
  vc_map(array(
523
+ "name" => __("PWB All brands", "perfect-woocommerce-brands"),
524
+ "description" => __("Show all brands", "perfect-woocommerce-brands"),
525
+ "base" => "pwb-all-brands",
526
+ "class" => "",
527
+ "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
528
+ "category" => "WooCommerce",
529
+ "params" => array(
530
+ array(
531
+ "type" => "textfield",
532
+ "holder" => "div",
533
+ "heading" => __("Brands per page", "perfect-woocommerce-brands"),
534
+ "param_name" => "per_page",
535
+ "value" => "10",
536
+ "description" => __("Show x brands per page", "perfect-woocommerce-brands")
537
+ ),
538
+ array(
539
+ "type" => "dropdown",
540
+ "heading" => __("Brand logo size", "perfect-woocommerce-brands"),
541
+ "param_name" => "image_size",
542
+ "admin_label" => true,
543
+ "value" => $available_image_sizes_adapted
544
+ ),
545
+ array(
546
+ "type" => "dropdown",
547
+ "heading" => __("Order by", "perfect-woocommerce-brands"),
548
+ "param_name" => "order_by",
549
+ "admin_label" => true,
550
+ "value" => array(
551
+ 'name' => 'name',
552
+ 'slug' => 'slug',
553
+ 'term_id' => 'term_id',
554
+ 'id' => 'id',
555
+ 'description' => 'description',
556
+ 'rand' => 'rand'
557
+ )
558
+ ),
559
+ array(
560
+ "type" => "dropdown",
561
+ "heading" => __("Order", "perfect-woocommerce-brands"),
562
+ "param_name" => "order",
563
+ "admin_label" => true,
564
+ "value" => array(
565
+ 'ASC' => 'ASC',
566
+ 'DSC' => 'DSC'
567
+ )
568
+ ),
569
+ array(
570
+ "type" => "dropdown",
571
+ "heading" => __("Title position", "perfect-woocommerce-brands"),
572
+ "param_name" => "title_position",
573
+ "admin_label" => true,
574
+ "value" => array(
575
+ __("Before image", "perfect-woocommerce-brands") => 'before',
576
+ __("After image", "perfect-woocommerce-brands") => 'after',
577
+ __("Hide", "perfect-woocommerce-brands") => 'none'
578
+ )
579
+ ),
580
+ array(
581
+ "type" => "checkbox",
582
+ "holder" => "div",
583
+ "heading" => __("Hide empty", "perfect-woocommerce-brands"),
584
+ "param_name" => "hide_empty",
585
+ "description" => __("Hide brands that have not been assigned to any product", "perfect-woocommerce-brands")
 
586
  )
587
+ )
588
  ));
589
 
590
  vc_map(array(
591
+ "name" => __("PWB AZ Listing", "perfect-woocommerce-brands"),
592
+ "description" => __("AZ Listing for brands", "perfect-woocommerce-brands"),
593
+ "base" => "pwb-az-listing",
594
+ "class" => "",
595
+ "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
596
+ "category" => "WooCommerce",
597
+ "params" => array(
598
+ array(
599
+ "type" => "dropdown",
600
+ "heading" => __("Only parent brands", "perfect-woocommerce-brands"),
601
+ "param_name" => "only_parents",
602
+ "admin_label" => true,
603
+ "value" => array(esc_html__('No') => 'no', esc_html__('Yes') => 'yes'),
 
604
  )
605
+ )
606
  ));
607
 
608
  vc_map(array(
609
+ "name" => __("PWB brand", "perfect-woocommerce-brands"),
610
+ "description" => __("Show brand for a specific product", "perfect-woocommerce-brands"),
611
+ "base" => "pwb-brand",
612
+ "class" => "",
613
+ "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
614
+ "category" => "WooCommerce",
615
+ "params" => array(
616
+ array(
617
+ "type" => "textfield",
618
+ "holder" => "div",
619
+ "heading" => __("Product id", "perfect-woocommerce-brands"),
620
+ "param_name" => "product_id",
621
+ "value" => null,
622
+ "description" => __("Product id (post id)", "perfect-woocommerce-brands")
623
+ ),
624
+ array(
625
+ "type" => "dropdown",
626
+ "heading" => __("Brand logo size", "perfect-woocommerce-brands"),
627
+ "param_name" => "image_size",
628
+ "admin_label" => true,
629
+ "value" => $available_image_sizes_adapted
 
630
  )
631
+ )
632
  ));
633
  }
634
 
635
+ public function action_woocommerce_single_product_summary()
636
+ {
637
  $brands = wp_get_post_terms(get_the_ID(), 'pwb-brand');
638
 
639
  if (!is_wp_error($brands)) {
650
 
651
  if ($show_as == 'brand_link') {
652
  $before_brands_links = '<span class="pwb-text-before-brands-links">';
653
+ $before_brands_links .= apply_filters('pwb_text_before_brands_links', esc_html__('Brands', 'perfect-woocommerce-brands'));
654
  $before_brands_links .= ':</span>';
655
  echo apply_filters('pwb_html_before_brands_links', $before_brands_links);
656
  }
670
  if (!empty($attachment_html) && $show_as == 'brand_image' || !empty($attachment_html) && !$show_as) {
671
  echo '<a href="' . $brand_link . '" title="' . $brand->name . '">' . $attachment_html . '</a>';
672
  } else {
673
+ echo '<a href="' . $brand_link . '" title="' . esc_html__('View brand', 'perfect-woocommerce-brands') . '">' . $brand->name . '</a>';
674
  }
675
  }
676
  echo '</div>';
681
  }
682
  }
683
 
684
+ public function enqueue_scripts()
685
+ {
686
 
687
  wp_register_script(
688
+ 'pwb-lib-slick',
689
+ PWB_PLUGIN_URL . '/assets/lib/slick/slick.min.js',
690
+ array('jquery'),
691
+ '1.8.0',
692
+ false
693
  );
694
 
695
  wp_register_style(
696
+ 'pwb-lib-slick',
697
+ PWB_PLUGIN_URL . '/assets/lib/slick/slick.css',
698
+ array(),
699
+ '1.8.0',
700
+ 'all'
701
  );
702
 
703
  wp_enqueue_style(
704
+ 'pwb-styles-frontend',
705
+ PWB_PLUGIN_URL . '/assets/css/styles-frontend.min.css',
706
+ array(),
707
+ PWB_PLUGIN_VERSION,
708
+ 'all'
709
  );
710
 
711
  wp_register_script(
712
+ 'pwb-functions-frontend',
713
+ PWB_PLUGIN_URL . '/assets/js/functions-frontend.min.js',
714
+ array('jquery'),
715
+ PWB_PLUGIN_VERSION,
716
+ true
717
  );
718
 
719
  wp_localize_script('pwb-functions-frontend', 'pwb_ajax_object', array(
720
+ 'carousel_prev' => apply_filters('pwb_carousel_prev', '&lt;'),
721
+ 'carousel_next' => apply_filters('pwb_carousel_next', '&gt;')
722
  ));
723
 
724
  wp_enqueue_script('pwb-functions-frontend');
725
  }
726
 
727
+ public function admin_enqueue_scripts($hook)
728
+ {
729
  $screen = get_current_screen();
730
  if ($hook == 'edit-tags.php' && $screen->taxonomy == 'pwb-brand' || $hook == 'term.php' && $screen->taxonomy == 'pwb-brand') {
731
  wp_enqueue_media();
735
 
736
  wp_register_script('pwb-functions-admin', PWB_PLUGIN_URL . '/assets/js/functions-admin.min.js', array('jquery'), PWB_PLUGIN_VERSION, true);
737
  wp_localize_script('pwb-functions-admin', 'pwb_ajax_object_admin', array(
738
+ 'ajax_url' => admin_url('admin-ajax.php'),
739
+ 'site_url' => site_url(),
740
+ 'brands_url' => admin_url('edit-tags.php?taxonomy=pwb-brand&post_type=product'),
741
+ 'translations' => array(
742
+ 'migrate_notice' => esc_html__('¿Start migration?', 'perfect-woocommerce-brands'),
743
+ 'migrating' => esc_html__('We are migrating the product brands. ¡Don´t close this window until the process is finished!', 'perfect-woocommerce-brands'),
744
+ 'dummy_data_notice' => esc_html__('¿Start loading dummy data?', 'perfect-woocommerce-brands'),
745
+ 'dummy_data' => esc_html__('We are importing the dummy data. ¡Don´t close this window until the process is finished!', 'perfect-woocommerce-brands')
746
+ )
747
  ));
748
  wp_enqueue_script('pwb-functions-admin');
749
  }
750
 
751
+ public function register_brands_taxonomy()
752
+ {
753
  $labels = array(
754
+ 'name' => esc_html__('Brands', 'perfect-woocommerce-brands'),
755
+ 'singular_name' => esc_html__('Brand', 'perfect-woocommerce-brands'),
756
+ 'menu_name' => esc_html__('Brands', 'perfect-woocommerce-brands'),
757
+ 'all_items' => esc_html__('All Brands', 'perfect-woocommerce-brands'),
758
+ 'edit_item' => esc_html__('Edit Brand', 'perfect-woocommerce-brands'),
759
+ 'view_item' => esc_html__('View Brand', 'perfect-woocommerce-brands'),
760
+ 'update_item' => esc_html__('Update Brand', 'perfect-woocommerce-brands'),
761
+ 'add_new_item' => esc_html__('Add New Brand', 'perfect-woocommerce-brands'),
762
+ 'new_item_name' => esc_html__('New Brand Name', 'perfect-woocommerce-brands'),
763
+ 'parent_item' => esc_html__('Parent Brand', 'perfect-woocommerce-brands'),
764
+ 'parent_item_colon' => esc_html__('Parent Brand:', 'perfect-woocommerce-brands'),
765
+ 'search_items' => esc_html__('Search Brands', 'perfect-woocommerce-brands'),
766
+ 'popular_items' => esc_html__('Popular Brands', 'perfect-woocommerce-brands'),
767
+ 'separate_items_with_commas' => esc_html__('Separate brands with commas', 'perfect-woocommerce-brands'),
768
+ 'add_or_remove_items' => esc_html__('Add or remove brands', 'perfect-woocommerce-brands'),
769
+ 'choose_from_most_used' => esc_html__('Choose from the most used brands', 'perfect-woocommerce-brands'),
770
+ 'not_found' => esc_html__('No brands found', 'perfect-woocommerce-brands')
771
  );
772
 
773
  $new_slug = get_option('wc_pwb_admin_tab_slug');
777
  $old_slug = ($old_slug != false) ? $old_slug : 'null';
778
 
779
  $args = array(
780
+ 'hierarchical' => true,
781
+ 'labels' => $labels,
782
+ 'show_ui' => true,
783
+ 'query_var' => true,
784
+ 'public' => true,
785
+ 'show_admin_column' => true,
786
+ 'rewrite' => array(
787
+ 'slug' => apply_filters('pwb_taxonomy_rewrite', $new_slug),
788
  'hierarchical' => true,
789
+ 'with_front' => apply_filters('pwb_taxonomy_with_front', true),
790
+ 'ep_mask' => EP_PERMALINK
791
+ )
 
 
 
 
 
 
 
 
792
  );
793
 
794
  register_taxonomy('pwb-brand', array('product'), $args);
799
  }
800
  }
801
 
802
+ public function add_brands_metafields()
803
+ {
804
  register_meta('term', 'pwb_brand_image', array($this, 'add_brands_metafields_sanitize'));
805
  }
806
 
807
+ public function add_brands_metafields_sanitize($brand_img)
808
+ {
809
  return $brand_img;
810
  }
811
 
812
+ public static function get_brands($hide_empty = false, $order_by = 'name', $order = 'ASC', $only_featured = false, $pwb_term = false, $only_parents = false)
813
+ {
814
  $result = array();
815
 
816
  $brands_args = array('hide_empty' => $hide_empty, 'orderby' => $order_by, 'order' => $order);
839
  return $result;
840
  }
841
 
842
+ public static function get_brands_array($is_select = false)
843
+ {
844
  $result = array();
845
 
846
  //if is for select input adds default value
847
  if ($is_select)
848
+ $result[0] = esc_html__('All', 'perfect-woocommerce-brands');
849
 
850
  $brands = get_terms('pwb-brand', array(
851
+ 'hide_empty' => false
852
  ));
853
 
854
  foreach ($brands as $brand) {
858
  return $result;
859
  }
860
 
861
+ public function print_brand_banner()
862
+ {
863
  $queried_object = get_queried_object();
864
  $brand_banner = get_term_meta($queried_object->term_id, 'pwb_brand_banner', true);
865
  $brand_banner_link = get_term_meta($queried_object->term_id, 'pwb_brand_banner_link', true);
866
  $show_banner = get_option('wc_pwb_admin_tab_brand_banner');
867
  $show_banner = get_option('wc_pwb_admin_tab_brand_banner');
868
+ $show_banner_class = (!$show_banner || $show_banner == 'yes') ? 'pwb-before-loop' : 'pwb-after-loop';
869
 
870
  if ($brand_banner != '') {
871
  echo '<div class="pwb-brand-banner pwb-clearfix ' . $show_banner_class . '">';
878
  }
879
  }
880
 
881
+ public function print_brand_desc()
882
+ {
883
  $queried_object = get_queried_object();
884
  $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
885
  $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
886
+ $show_desc_class = (!$show_desc || $show_desc == 'yes') ? 'pwb-before-loop' : 'pwb-after-loop';
887
 
888
  if ($queried_object->description != '' && $show_desc !== 'no') {
889
  echo '<div class="pwb-brand-description ' . $show_desc_class . '">';
892
  }
893
  }
894
 
895
+ public function print_brand_banner_and_desc()
896
+ {
897
  $queried_object = get_queried_object();
898
 
899
  $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
900
+ $show_desc_class = (!$show_desc || $show_desc == 'yes') ? 'pwb-before-loop' : 'pwb-after-loop';
901
 
902
  $brand_banner = get_term_meta($queried_object->term_id, 'pwb_brand_banner', true);
903
  $brand_banner_link = get_term_meta($queried_object->term_id, 'pwb_brand_banner_link', true);
910
  }
911
  }
912
 
913
+ public static function render_template($name, $folder = '', $data, $private = true)
914
+ {
915
  //default template
916
  if ($folder)
917
  $folder = $folder . '/';
931
  return ob_get_clean();
932
  }
933
 
934
+ public function product_duplicate_save($duplicate, $product)
935
+ {
936
  $product_brands = wp_get_object_terms($product->get_id(), 'pwb-brand', array('fields' => 'ids'));
937
  wp_set_object_terms($duplicate->get_id(), $product_brands, 'pwb-brand');
938
  }
939
 
940
+ public function breadcrumbs($crumbs)
941
+ {
942
 
943
  if (is_tax('pwb-brand')) {
944
 
949
  $cur_brand = get_queried_object();
950
  $brand_ancestors = get_ancestors($cur_brand->term_id, 'pwb-brand', 'taxonomy');
951
 
952
+ $brand_page_pos = count($crumbs) - (count($brand_ancestors) + 2);
953
  if (is_paged())
954
  $brand_page_pos -= 1;
955
 
965
  * Redirect if the search matchs with a brands name
966
  * Better search experience
967
  */
968
+ public function search_by_brand_name($query)
969
+ {
970
 
971
  if (wp_doing_ajax())
972
  return;
982
  }
983
  }
984
  }
 
985
  }
classes/class-pwb-product-tab.php CHANGED
@@ -2,65 +2,66 @@
2
 
3
  namespace Perfect_Woocommerce_Brands;
4
 
5
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
6
 
7
- class PWB_Product_Tab{
 
8
 
9
- function __construct(){
10
- add_filter( 'woocommerce_product_tabs', array( $this, 'product_tab' ) );
 
11
  }
12
 
13
- public function product_tab( $tabs ){
 
14
 
15
  global $product;
16
 
17
- if( isset( $product ) ){
18
- $brands = wp_get_object_terms( $product->get_id(), 'pwb-brand' );
19
 
20
- if( !empty( $brands ) ){
21
- $show_brand_tab = get_option( 'wc_pwb_admin_tab_brand_single_product_tab' );
22
- if( $show_brand_tab == 'yes' || !$show_brand_tab ){
23
  $tabs['pwb_tab'] = array(
24
- 'title' => __( 'Brand', 'perfect-woocommerce-brands' ),
25
- 'priority' => 20,
26
- 'callback' => array( $this, 'product_tab_content' )
27
  );
28
  }
29
  }
30
  }
31
 
32
- return $tabs;
33
-
34
  }
35
 
36
- public function product_tab_content(){
 
37
 
38
  global $product;
39
- $brands = wp_get_object_terms( $product->get_id(), 'pwb-brand' );
40
 
41
  ob_start();
42
- ?>
43
 
44
- <h2><?php echo apply_filters( 'woocommerce_product_brand_heading', __('Brand', 'perfect-woocommerce-brands') ); ?></h2>
45
- <?php foreach( $brands as $brand ): ?>
46
 
47
  <?php
48
  $image_size = get_option('wc_pwb_admin_tab_brand_logo_size', 'thumbnail');
49
- $brand_logo = get_term_meta( $brand->term_id, 'pwb_brand_image', true );
50
- $brand_logo = wp_get_attachment_image( $brand_logo, apply_filters( 'pwb_product_tab_brand_logo_size', $image_size ) );
51
  ?>
52
 
53
  <div id="tab-pwb_tab-content">
54
- <h3><?php echo $brand->name;?></h3>
55
- <?php if( !empty($brand->description) ) echo '<div>'.do_shortcode($brand->description).'</div>';?>
56
- <?php if( !empty($brand_logo) ) echo '<span>'.$brand_logo.'</span>';?>
57
  </div>
58
 
59
  <?php endforeach; ?>
60
 
61
- <?php
62
  echo ob_get_clean();
63
-
64
  }
65
-
66
  }
2
 
3
  namespace Perfect_Woocommerce_Brands;
4
 
5
+ defined('ABSPATH') or die('No script kiddies please!');
6
 
7
+ class PWB_Product_Tab
8
+ {
9
 
10
+ function __construct()
11
+ {
12
+ add_filter('woocommerce_product_tabs', array($this, 'product_tab'));
13
  }
14
 
15
+ public function product_tab($tabs)
16
+ {
17
 
18
  global $product;
19
 
20
+ if (isset($product)) {
21
+ $brands = wp_get_object_terms($product->get_id(), 'pwb-brand');
22
 
23
+ if (!empty($brands)) {
24
+ $show_brand_tab = get_option('wc_pwb_admin_tab_brand_single_product_tab');
25
+ if ($show_brand_tab == 'yes' || !$show_brand_tab) {
26
  $tabs['pwb_tab'] = array(
27
+ 'title' => __('Brand', 'perfect-woocommerce-brands'),
28
+ 'priority' => 20,
29
+ 'callback' => array($this, 'product_tab_content')
30
  );
31
  }
32
  }
33
  }
34
 
35
+ return $tabs;
 
36
  }
37
 
38
+ public function product_tab_content()
39
+ {
40
 
41
  global $product;
42
+ $brands = wp_get_object_terms($product->get_id(), 'pwb-brand');
43
 
44
  ob_start();
45
+ ?>
46
 
47
+ <h2><?php echo apply_filters('woocommerce_product_brand_heading', esc_html__('Brand', 'perfect-woocommerce-brands')); ?></h2>
48
+ <?php foreach ($brands as $brand) : ?>
49
 
50
  <?php
51
  $image_size = get_option('wc_pwb_admin_tab_brand_logo_size', 'thumbnail');
52
+ $brand_logo = get_term_meta($brand->term_id, 'pwb_brand_image', true);
53
+ $brand_logo = wp_get_attachment_image($brand_logo, apply_filters('pwb_product_tab_brand_logo_size', $image_size));
54
  ?>
55
 
56
  <div id="tab-pwb_tab-content">
57
+ <h3><?php echo esc_html($brand->name); ?></h3>
58
+ <?php if (!empty($brand->description)) echo '<div>' . do_shortcode($brand->description) . '</div>'; ?>
59
+ <?php if (!empty($brand_logo)) echo '<span>' . $brand_logo . '</span>'; ?>
60
  </div>
61
 
62
  <?php endforeach; ?>
63
 
64
+ <?php
65
  echo ob_get_clean();
 
66
  }
 
67
  }
classes/class-pwb-suggestions-list.php CHANGED
@@ -110,7 +110,7 @@ class PWB_Suggestions_List_Table extends \WP_Plugin_Install_List_Table {
110
  $tabs = array();
111
 
112
  if ('search' === $tab) {
113
- $tabs['search'] = __('Search Results');
114
  }
115
  if ($tab === 'beta' || false !== strpos(get_bloginfo('version'), '-')) {
116
  $tabs['beta'] = _x('Beta Testing', 'Plugin Installer');
110
  $tabs = array();
111
 
112
  if ('search' === $tab) {
113
+ $tabs['search'] = esc_html__('Search Results');
114
  }
115
  if ($tab === 'beta' || false !== strpos(get_bloginfo('version'), '-')) {
116
  $tabs['beta'] = _x('Beta Testing', 'Plugin Installer');
classes/class-pwb-term.php CHANGED
@@ -17,7 +17,7 @@ class PWB_Term{
17
  if( is_a( $this->term_obj, 'WP_Term' ) ){
18
  $this->build_pwb_term( $this->term_obj );
19
  }else{
20
- throw new Exception( __('Only WP_Term objects are allowed', 'perfect-woocommerce-brands') );
21
  }
22
  }
23
 
17
  if( is_a( $this->term_obj, 'WP_Term' ) ){
18
  $this->build_pwb_term( $this->term_obj );
19
  }else{
20
+ throw new Exception( esc_html__('Only WP_Term objects are allowed', 'perfect-woocommerce-brands') );
21
  }
22
  }
23
 
classes/shortcodes/class-pwb-all-brands.php CHANGED
@@ -1,49 +1,51 @@
1
  <?php
 
2
  namespace Perfect_Woocommerce_Brands\Shortcodes;
3
 
4
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
5
 
6
- class PWB_All_Brands_Shortcode{
 
7
 
8
- public static function all_brands_shortcode( $atts ) {
 
9
 
10
- $atts = shortcode_atts( array(
11
  'per_page' => "10",
12
  'image_size' => "thumbnail",
13
  'hide_empty' => false,
14
  'order_by' => 'name',
15
  'order' => 'ASC',
16
  'title_position' => 'before'
17
- ), $atts, 'pwb-all-brands' );
18
 
19
- $hide_empty = ( $atts['hide_empty'] != 'true' ) ? false : true;
20
 
21
  ob_start();
22
 
23
  $brands = array();
24
- if( $atts['order_by'] == 'rand' ){
25
- $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands( $hide_empty );
26
- shuffle( $brands );
27
- }else{
28
- $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands( $hide_empty, $atts['order_by'], $atts['order'] );
29
  }
30
 
31
  //remove residual empty brands
32
- foreach ( $brands as $key => $brand ) {
33
 
34
- $count = self::count_visible_products( $brand->term_id );
35
 
36
- if ( ! $count && $hide_empty ){
37
- unset( $brands[$key] );
38
  } else {
39
  $brands[$key]->count_pwb = $count;
40
  }
41
-
42
  }
43
 
44
- ?>
45
  <div class="pwb-all-brands">
46
- <?php static::pagination( $brands, $atts['per_page'], $atts['image_size'], $atts['title_position'] );?>
47
  </div>
48
  <?php
49
 
@@ -54,7 +56,8 @@ class PWB_All_Brands_Shortcode{
54
  * WP_Term->count property don´t care about hidden products
55
  * Counts the products in a specific brand
56
  */
57
- public static function count_visible_products( $brand_id ) {
 
58
 
59
  $args = array(
60
  'posts_per_page' => -1,
@@ -76,13 +79,13 @@ class PWB_All_Brands_Shortcode{
76
  $wc_query = new \WP_Query($args);
77
 
78
  return $wc_query->found_posts;
79
-
80
  }
81
 
82
- public static function pagination( $display_array, $show_per_page, $image_size, $title_position ) {
 
83
  $page = 1;
84
 
85
- if( isset( $_GET['pwb-page'] ) && filter_var( $_GET['pwb-page'], FILTER_VALIDATE_INT ) == true ){
86
  $page = $_GET['pwb-page'];
87
  }
88
 
@@ -99,72 +102,76 @@ class PWB_All_Brands_Shortcode{
99
  $total_elements = count($display_array);
100
  $pages = ((int)$total_elements / (int)$show_per_page);
101
  $pages = ceil($pages);
102
- if($pages>=1 && $page <= $pages){
103
 
104
- ?>
105
  <div class="pwb-brands-cols-outer">
106
  <?php
107
- foreach( $outArray as $brand ) {
108
 
109
  $brand_id = $brand->term_id;
110
  $brand_name = $brand->name;
111
  $brand_link = get_term_link($brand_id);
112
 
113
- $attachment_id = get_term_meta( $brand_id, 'pwb_brand_image', 1 );
114
  $attachment_html = $brand_name;
115
- if($attachment_id!=''){
116
- $attachment_html = wp_get_attachment_image( $attachment_id, $image_size );
117
  }
118
 
119
- ?>
120
  <div class="pwb-brands-col3">
121
 
122
- <?php if( $title_position != 'none' && $title_position != 'after' ): ?>
123
  <p>
124
- <a href="<?php echo $brand_link;?>"><?php echo $brand_name;?></a>
125
- <small>(<?php echo $brand->count_pwb;?>)</small>
 
 
126
  </p>
127
  <?php endif; ?>
128
 
129
  <div>
130
- <a href="<?php echo $brand_link;?>" title="<?php echo $brand_name;?>"><?php echo $attachment_html;?></a>
 
 
131
  </div>
132
 
133
- <?php if( $title_position != 'none' && $title_position == 'after' ): ?>
134
  <p>
135
- <a href="<?php echo $brand_link;?>"><?php echo $brand_name;?></a>
136
- <small>(<?php echo $brand->count_pwb;?>)</small>
 
 
137
  </p>
138
  <?php endif; ?>
139
 
140
  </div>
141
- <?php
142
  }
143
  ?>
144
  </div>
145
- <?php
146
  $next = $page + 1;
147
  $prev = $page - 1;
148
 
149
  echo '<div class="pwb-pagination-wrapper">';
150
- if($prev>1){
151
- echo '<a href="'.get_the_permalink().'" class="pwb-pagination prev" title="'.__('First page','perfect-woocommerce-brands').'">&laquo;</a>';
152
  }
153
- if($prev>0){
154
- echo '<a href="'.get_the_permalink().'?pwb-page='.$prev.'" class="pwb-pagination last" title="'.__('Previous page','perfect-woocommerce-brands').'">&lsaquo;</a>';
155
  }
156
 
157
- if($next<=$pages){
158
- echo '<a href="'.get_the_permalink().'?pwb-page='.$next.'" class="pwb-pagination first" title="'.__('Next page','perfect-woocommerce-brands').'">&rsaquo;</a>';
159
  }
160
- if($next<$pages){
161
- echo '<a href="'.get_the_permalink().'?pwb-page='.$pages.'" class="pwb-pagination next" title="'.__('Last page','perfect-woocommerce-brands').'">&raquo;</a>';
162
  }
163
  echo '</div>';
164
-
165
- }else{
166
- echo __('No results','perfect-woocommerce-brands');
167
  }
168
-
169
  }
170
  }
1
  <?php
2
+
3
  namespace Perfect_Woocommerce_Brands\Shortcodes;
4
 
5
+ defined('ABSPATH') or die('No script kiddies please!');
6
 
7
+ class PWB_All_Brands_Shortcode
8
+ {
9
 
10
+ public static function all_brands_shortcode($atts)
11
+ {
12
 
13
+ $atts = shortcode_atts(array(
14
  'per_page' => "10",
15
  'image_size' => "thumbnail",
16
  'hide_empty' => false,
17
  'order_by' => 'name',
18
  'order' => 'ASC',
19
  'title_position' => 'before'
20
+ ), $atts, 'pwb-all-brands');
21
 
22
+ $hide_empty = ($atts['hide_empty'] != 'true') ? false : true;
23
 
24
  ob_start();
25
 
26
  $brands = array();
27
+ if ($atts['order_by'] == 'rand') {
28
+ $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands($hide_empty);
29
+ shuffle($brands);
30
+ } else {
31
+ $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands($hide_empty, $atts['order_by'], $atts['order']);
32
  }
33
 
34
  //remove residual empty brands
35
+ foreach ($brands as $key => $brand) {
36
 
37
+ $count = self::count_visible_products($brand->term_id);
38
 
39
+ if (!$count && $hide_empty) {
40
+ unset($brands[$key]);
41
  } else {
42
  $brands[$key]->count_pwb = $count;
43
  }
 
44
  }
45
 
46
+ ?>
47
  <div class="pwb-all-brands">
48
+ <?php static::pagination($brands, $atts['per_page'], $atts['image_size'], $atts['title_position']); ?>
49
  </div>
50
  <?php
51
 
56
  * WP_Term->count property don´t care about hidden products
57
  * Counts the products in a specific brand
58
  */
59
+ public static function count_visible_products($brand_id)
60
+ {
61
 
62
  $args = array(
63
  'posts_per_page' => -1,
79
  $wc_query = new \WP_Query($args);
80
 
81
  return $wc_query->found_posts;
 
82
  }
83
 
84
+ public static function pagination($display_array, $show_per_page, $image_size, $title_position)
85
+ {
86
  $page = 1;
87
 
88
+ if (isset($_GET['pwb-page']) && filter_var($_GET['pwb-page'], FILTER_VALIDATE_INT) == true) {
89
  $page = $_GET['pwb-page'];
90
  }
91
 
102
  $total_elements = count($display_array);
103
  $pages = ((int)$total_elements / (int)$show_per_page);
104
  $pages = ceil($pages);
105
+ if ($pages >= 1 && $page <= $pages) {
106
 
107
+ ?>
108
  <div class="pwb-brands-cols-outer">
109
  <?php
110
+ foreach ($outArray as $brand) {
111
 
112
  $brand_id = $brand->term_id;
113
  $brand_name = $brand->name;
114
  $brand_link = get_term_link($brand_id);
115
 
116
+ $attachment_id = get_term_meta($brand_id, 'pwb_brand_image', 1);
117
  $attachment_html = $brand_name;
118
+ if ($attachment_id != '') {
119
+ $attachment_html = wp_get_attachment_image($attachment_id, $image_size);
120
  }
121
 
122
+ ?>
123
  <div class="pwb-brands-col3">
124
 
125
+ <?php if ($title_position != 'none' && $title_position != 'after') : ?>
126
  <p>
127
+ <a href="<?php echo esc_url($brand_link); ?>">
128
+ <?php echo esc_html($brand_name); ?>
129
+ </a>
130
+ <small>(<?php echo esc_html($brand->count_pwb); ?>)</small>
131
  </p>
132
  <?php endif; ?>
133
 
134
  <div>
135
+ <a href="<?php echo esc_url($brand_link); ?>" title="<?php echo esc_html($brand_name); ?>">
136
+ <?php echo wp_kses_post($attachment_html); ?>
137
+ </a>
138
  </div>
139
 
140
+ <?php if ($title_position != 'none' && $title_position == 'after') : ?>
141
  <p>
142
+ <a href="<?php echo esc_html($brand_link); ?>">
143
+ <?php echo wp_kses_post($brand_name); ?>
144
+ </a>
145
+ <small>(<?php echo esc_html($brand->count_pwb); ?>)</small>
146
  </p>
147
  <?php endif; ?>
148
 
149
  </div>
150
+ <?php
151
  }
152
  ?>
153
  </div>
154
+ <?php
155
  $next = $page + 1;
156
  $prev = $page - 1;
157
 
158
  echo '<div class="pwb-pagination-wrapper">';
159
+ if ($prev > 1) {
160
+ echo '<a href="' . get_the_permalink() . '" class="pwb-pagination prev" title="' . esc_html__('First page', 'perfect-woocommerce-brands') . '">&laquo;</a>';
161
  }
162
+ if ($prev > 0) {
163
+ echo '<a href="' . get_the_permalink() . '?pwb-page=' . $prev . '" class="pwb-pagination last" title="' . esc_html__('Previous page', 'perfect-woocommerce-brands') . '">&lsaquo;</a>';
164
  }
165
 
166
+ if ($next <= $pages) {
167
+ echo '<a href="' . get_the_permalink() . '?pwb-page=' . $next . '" class="pwb-pagination first" title="' . esc_html__('Next page', 'perfect-woocommerce-brands') . '">&rsaquo;</a>';
168
  }
169
+ if ($next < $pages) {
170
+ echo '<a href="' . get_the_permalink() . '?pwb-page=' . $pages . '" class="pwb-pagination next" title="' . esc_html__('Last page', 'perfect-woocommerce-brands') . '">&raquo;</a>';
171
  }
172
  echo '</div>';
173
+ } else {
174
+ echo esc_html__('No results', 'perfect-woocommerce-brands');
 
175
  }
 
176
  }
177
  }
classes/shortcodes/class-pwb-product-carousel.php CHANGED
@@ -1,50 +1,57 @@
1
  <?php
 
2
  namespace Perfect_Woocommerce_Brands\Shortcodes;
3
 
4
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
5
 
6
- class PWB_Product_Carousel_Shortcode{
 
7
 
8
  private static $atts;
9
 
10
- public static function product_carousel_shortcode( $atts ) {
 
11
 
12
- self::$atts = shortcode_atts( array(
13
- 'brand' => "all",
14
- 'category' => "all",
15
- 'products' => "10",
16
- 'products_to_show' => "5",
17
- 'products_to_scroll' => "1",
18
- 'autoplay' => "false",
19
- 'arrows' => "false"
20
- ), $atts, 'pwb-product-carousel' );
21
 
22
  //enqueue deps
23
- if( !wp_style_is('pwb-lib-slick') ) wp_enqueue_style('pwb-lib-slick');
24
- if( !wp_script_is('pwb-lib-slick') ) wp_enqueue_script('pwb-lib-slick');
 
 
 
25
 
26
  return \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
27
  'product-carousel',
28
  'shortcodes',
29
- array( 'slick_settings' => self::slick_settings(), 'products' => self::products_data() ),
30
  false
31
  );
32
-
33
  }
34
 
35
- private static function slick_settings(){
 
36
 
37
  $slick_settings = array(
38
  'slidesToShow' => (int)self::$atts['products_to_show'],
39
  'slidesToScroll' => (int)self::$atts['products_to_scroll'],
40
- 'autoplay' => ( self::$atts['autoplay'] === 'true' ) ? true: false,
41
- 'arrows' => ( self::$atts['arrows'] === 'true' ) ? true: false
42
  );
43
- return htmlspecialchars( json_encode( $slick_settings ), ENT_QUOTES, 'UTF-8' );
44
 
 
45
  }
46
 
47
- private static function products_data(){
 
48
 
49
  $products = array();
50
 
@@ -54,7 +61,7 @@ class PWB_Product_Carousel_Shortcode{
54
  'paged' => false
55
  );
56
 
57
- if( self::$atts['brand'] != 'all' ){
58
  $args['tax_query'] = array(
59
  array(
60
  'taxonomy' => 'pwb-brand',
@@ -63,23 +70,23 @@ class PWB_Product_Carousel_Shortcode{
63
  )
64
  );
65
  }
66
- if( self::$atts['category'] != 'all'){
67
- $woo_category_query = array(
68
- 'taxonomy' => 'product_cat',
69
- 'field' => 'slug',
70
- 'terms' => self::$atts['category']
71
- );
72
- if(isset($args['tax_query']) && is_array($args['tax_query'])) {
73
- $args['tax_query'][] = $woo_category_query;
74
- } else {
75
- $args['tax_query'] = array($woo_category_query);
76
- }
77
  }
78
 
79
- $loop = new \WP_Query( $args );
80
- if( $loop->have_posts() ) {
81
- while ( $loop->have_posts() ) : $loop->the_post();
82
- $product = wc_get_product( get_the_ID() );
83
 
84
  $products[] = array(
85
  'id' => get_the_ID(),
@@ -87,12 +94,10 @@ class PWB_Product_Carousel_Shortcode{
87
  'thumbnail' => woocommerce_get_product_thumbnail(),
88
  'title' => $product->get_title()
89
  );
90
- endwhile;
91
- }
92
- wp_reset_postdata();
93
 
94
  return $products;
95
-
96
  }
97
-
98
  }
1
  <?php
2
+
3
  namespace Perfect_Woocommerce_Brands\Shortcodes;
4
 
5
+ defined('ABSPATH') or die('No script kiddies please!');
6
 
7
+ class PWB_Product_Carousel_Shortcode
8
+ {
9
 
10
  private static $atts;
11
 
12
+ public static function product_carousel_shortcode($atts)
13
+ {
14
 
15
+ self::$atts = shortcode_atts(array(
16
+ 'brand' => "all",
17
+ 'category' => "all",
18
+ 'products' => "10",
19
+ 'products_to_show' => "5",
20
+ 'products_to_scroll' => "1",
21
+ 'autoplay' => "false",
22
+ 'arrows' => "false"
23
+ ), $atts, 'pwb-product-carousel');
24
 
25
  //enqueue deps
26
+ if (!wp_style_is('pwb-lib-slick'))
27
+ wp_enqueue_style('pwb-lib-slick');
28
+
29
+ if (!wp_script_is('pwb-lib-slick'))
30
+ wp_enqueue_script('pwb-lib-slick');
31
 
32
  return \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
33
  'product-carousel',
34
  'shortcodes',
35
+ array('slick_settings' => self::slick_settings(), 'products' => self::products_data()),
36
  false
37
  );
 
38
  }
39
 
40
+ private static function slick_settings()
41
+ {
42
 
43
  $slick_settings = array(
44
  'slidesToShow' => (int)self::$atts['products_to_show'],
45
  'slidesToScroll' => (int)self::$atts['products_to_scroll'],
46
+ 'autoplay' => (self::$atts['autoplay'] === 'true') ? true : false,
47
+ 'arrows' => (self::$atts['arrows'] === 'true') ? true : false
48
  );
 
49
 
50
+ return htmlspecialchars(json_encode($slick_settings), ENT_QUOTES, 'UTF-8');
51
  }
52
 
53
+ private static function products_data()
54
+ {
55
 
56
  $products = array();
57
 
61
  'paged' => false
62
  );
63
 
64
+ if (self::$atts['brand'] != 'all') {
65
  $args['tax_query'] = array(
66
  array(
67
  'taxonomy' => 'pwb-brand',
70
  )
71
  );
72
  }
73
+ if (self::$atts['category'] != 'all') {
74
+ $woo_category_query = array(
75
+ 'taxonomy' => 'product_cat',
76
+ 'field' => 'slug',
77
+ 'terms' => self::$atts['category']
78
+ );
79
+ if (isset($args['tax_query']) && is_array($args['tax_query'])) {
80
+ $args['tax_query'][] = $woo_category_query;
81
+ } else {
82
+ $args['tax_query'] = array($woo_category_query);
83
+ }
84
  }
85
 
86
+ $loop = new \WP_Query($args);
87
+ if ($loop->have_posts()) {
88
+ while ($loop->have_posts()) : $loop->the_post();
89
+ $product = wc_get_product(get_the_ID());
90
 
91
  $products[] = array(
92
  'id' => get_the_ID(),
94
  'thumbnail' => woocommerce_get_product_thumbnail(),
95
  'title' => $product->get_title()
96
  );
97
+ endwhile;
98
+ }
99
+ wp_reset_postdata();
100
 
101
  return $products;
 
102
  }
 
103
  }
classes/widgets/class-pwb-dropdown.php CHANGED
@@ -16,7 +16,7 @@ class PWB_Dropdown_Widget extends \WP_Widget {
16
  public function form($instance){
17
  extract($instance);
18
 
19
- $title = ( isset( $instance[ 'title' ] ) ) ? $instance[ 'title' ] : __('Brands', 'perfect-woocommerce-brands');
20
  $hide_empty = ( isset( $hide_empty ) && $hide_empty == 'on' ) ? true : false;
21
  $only_featured = ( isset( $only_featured ) && $only_featured == 'on' ) ? true : false;
22
  ?>
16
  public function form($instance){
17
  extract($instance);
18
 
19
+ $title = ( isset( $instance[ 'title' ] ) ) ? $instance[ 'title' ] : esc_html__('Brands', 'perfect-woocommerce-brands');
20
  $hide_empty = ( isset( $hide_empty ) && $hide_empty == 'on' ) ? true : false;
21
  $only_featured = ( isset( $only_featured ) && $only_featured == 'on' ) ? true : false;
22
  ?>
classes/widgets/class-pwb-filter-by-brand.php CHANGED
@@ -1,207 +1,201 @@
1
  <?php
 
2
  namespace Perfect_Woocommerce_Brands\Widgets;
 
3
  use WP_Query;
4
 
5
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
6
 
7
- class PWB_Filter_By_Brand_Widget extends \WP_Widget {
 
8
 
9
- function __construct() {
10
- $params = array(
11
- 'description' => __( 'Recommended for product categories or shop page', 'perfect-woocommerce-brands' ),
12
- 'name' => __( 'Filter products by brand', 'perfect-woocommerce-brands' )
13
- );
14
- parent::__construct('PWB_Filter_By_Brand_Widget', '', $params);
 
15
  }
16
 
17
- public function form( $instance ) {
18
- extract($instance);
 
19
 
20
- $title = ( isset( $instance[ 'title' ] ) ) ? $instance[ 'title' ] : __('Brands', 'perfect-woocommerce-brands');
21
- $limit = ( isset( $instance[ 'limit' ] ) ) ? $instance[ 'limit' ] : 20;
22
- $hide_submit_btn = ( isset( $hide_submit_btn ) && $hide_submit_btn == 'on' ) ? true : false;
23
- $only_first_level_brands = ( isset( $only_first_level_brands ) && $only_first_level_brands == 'on' ) ? true : false;
24
- ?>
25
 
26
  <p>
27
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
28
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
29
- </p>
30
 
31
  <p>
32
- <label for="<?php echo $this->get_field_id( 'limit' ); ?>">
33
- <?php echo __( 'Max number of brands', 'perfect-woocommerce-brands' );?>
34
- </label>
35
- <input class="widefat" id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" />
36
- </p>
37
 
38
  <p>
39
- <input
40
- type="checkbox"
41
- id="<?php echo esc_attr( $this->get_field_id('hide_submit_btn') ); ?>"
42
- name="<?php echo esc_attr( $this->get_field_name('hide_submit_btn') ); ?>"
43
- <?php checked( $hide_submit_btn ); ?>>
44
- <label for="<?php echo esc_attr( $this->get_field_id('hide_submit_btn') ); ?>">
45
- <?php echo __( 'Hide filter button', 'perfect-woocommerce-brands' );?>
46
- </label>
47
- </p>
48
 
49
  <p>
50
- <input
51
- type="checkbox"
52
- id="<?php echo esc_attr( $this->get_field_id('only_first_level_brands') ); ?>"
53
- name="<?php echo esc_attr( $this->get_field_name('only_first_level_brands') ); ?>"
54
- <?php checked( $only_first_level_brands ); ?>>
55
- <label for="<?php echo esc_attr( $this->get_field_id('only_first_level_brands') ); ?>">
56
- <?php echo __( 'Show only first level brands', 'perfect-woocommerce-brands' );?>
57
- </label>
58
  </p>
59
 
60
- <?php
61
- }
62
-
63
- public function update( $new_instance, $old_instance ) {
64
- $limit = trim( strip_tags( $new_instance['limit'] ) );
65
- $limit = filter_var( $limit, FILTER_VALIDATE_INT, [ 'options' => [ 'min_range' => 1 ] ] );
66
-
67
- $instance = array();
68
- $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : '';
69
- $instance['limit'] = ( $limit != false ) ? $limit : $old_instance['limit'];
70
- $instance['hide_submit_btn'] = ( isset( $new_instance['hide_submit_btn'] ) ) ? $new_instance['hide_submit_btn'] : '';
71
- $instance['only_first_level_brands'] = ( isset( $new_instance['only_first_level_brands'] ) ) ? $new_instance['only_first_level_brands'] : '';
72
- return $instance;
73
- }
74
-
75
- public function widget( $args, $instance ) {
76
- extract( $args );
77
- extract( $instance );
78
 
79
- if( !is_tax('pwb-brand') && !is_product() ){
 
 
 
 
 
 
 
 
 
 
 
80
 
81
- $hide_submit_btn = ( isset( $hide_submit_btn ) && $hide_submit_btn == 'on' ) ? true : false;
82
- $only_first_level_brands = ( isset( $only_first_level_brands ) && $only_first_level_brands == 'on' ) ? true : false;
 
 
83
 
84
- $show_widget = true;
85
- $current_products = false;
86
- if( is_product_taxonomy() || is_shop() ){
87
- $current_products = $this->current_products_query();
88
- if( empty( $current_products ) ) $show_widget = false;
89
- }
90
 
91
- if( $show_widget ){
 
92
 
93
- $title = ( isset( $instance[ 'title' ] ) ) ? $instance[ 'title' ] : __('Brands', 'perfect-woocommerce-brands');
94
- $title = apply_filters( 'widget_title', $title );
95
- $limit = ( isset( $instance[ 'limit' ] ) ) ? $instance[ 'limit' ] : 20;
 
 
 
96
 
97
- echo $args['before_widget'];
98
- if ( ! empty( $title ) ) echo $args['before_title'] . $title . $args['after_title'];
99
- $this->render_widget( $current_products, $limit, $hide_submit_btn, $only_first_level_brands );
100
- echo $args['after_widget'];
101
- }
102
 
103
- }
 
 
104
 
 
 
 
 
 
 
105
  }
106
 
107
- public function render_widget( $current_products, $limit, $hide_submit_btn, $only_first_level_brands ) {
 
108
 
109
  $result_brands = array();
110
 
111
- if ( is_product_taxonomy() || is_shop() ) {
112
-
113
- //obtains brands ids
114
- if ( ! empty( $current_products ) ) $result_brands = $this->get_products_brands( $current_products );
115
-
116
- //excludes the child brands if needed
117
- if ( $only_first_level_brands ) {
118
- $result_brands = $this->exclude_child_brands( $result_brands );
119
- }
120
 
121
- if( is_shop() ){
122
- $cate_url = get_permalink( wc_get_page_id( 'shop' ) );
123
- }else{
124
- $cate = get_queried_object();
125
- $cateID = $cate->term_id;
126
- $cate_url = get_term_link($cateID);
127
- }
128
 
129
- }else{
130
- //no product category
131
- $cate_url = get_permalink( wc_get_page_id( 'shop' ) );
132
- $result_brands = get_terms( 'pwb-brand', array( 'hide_empty' => true, 'fields' => 'ids' ) );
133
  }
134
 
135
- if( $limit > 0 ) $result_brands = array_slice( $result_brands, 0, $limit );
136
-
137
- global $wp;
138
- $current_url = home_url(add_query_arg(array(),$wp->request));
 
 
 
 
 
 
 
 
139
 
140
- if ( ! empty( $result_brands ) ) {
141
 
142
- $result_brands_ordered = array();
143
- foreach ( $result_brands as $brand ) {
144
- $brand = get_term($brand);
145
- $result_brands_ordered[$brand->name] = $brand;
146
- }
147
- ksort($result_brands_ordered);
148
 
149
- $result_brands_ordered = apply_filters( 'pwb_widget_brand_filter', $result_brands_ordered );
150
 
151
- echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
152
- 'filter-by-brand',
153
- 'widgets',
154
- array( 'cate_url' => $cate_url, 'brands' => $result_brands_ordered, 'hide_submit_btn' => $hide_submit_btn ),
155
- false
156
- );
157
 
158
- }
159
 
160
- }
 
 
 
 
 
 
 
161
 
162
- private function exclude_child_brands( $brands ) {
 
163
 
164
  //gets parent for all brands
165
- foreach ( $brands as $brand_key => $brand ) {
166
 
167
- $brand_o = get_term( $brand, 'pwb-brand' );
168
 
169
- if ( $brand_o->parent ) {
170
 
171
  //exclude this child brand and include the parent
172
- unset( $brands[$brand_key] );
173
- if ( ! in_array( $brand_o->parent, $brands ) ) $brands[$brand_key] = $brand_o->parent;
174
-
175
  }
176
-
177
  }
178
 
179
  //reset keys
180
- $brands = array_values( $brands );
181
 
182
 
183
  return $brands;
184
-
185
  }
186
 
187
- private function current_products_query() {
 
188
 
189
- $args = array(
190
- 'posts_per_page' => -1,
191
- 'post_type' => 'product',
192
- 'tax_query' => array(
193
- array(
194
- 'taxonomy' => 'pwb-brand',
195
  'operator' => 'EXISTS'
196
- )
197
- ),
198
  'fields' => 'ids',
199
- );
200
 
201
  $cat = get_queried_object();
202
- if( is_a( $cat, 'WP_Term' ) ){
203
  $cat_id = $cat->term_id;
204
- $cat_id_array = get_term_children( $cat_id, $cat->taxonomy );
205
  $cat_id_array[] = $cat_id;
206
  $args['tax_query'][] = array(
207
  'taxonomy' => $cat->taxonomy,
@@ -210,30 +204,30 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
210
  );
211
  }
212
 
213
- if( get_option('woocommerce_hide_out_of_stock_items') === 'yes' ){
214
  $args['meta_query'] = array(
215
  array(
216
- 'key' => '_stock_status',
217
- 'value' => 'outofstock',
218
- 'compare' => 'NOT IN'
219
- )
220
  );
221
  }
222
 
223
- $wp_query = new WP_Query($args);
224
  wp_reset_postdata();
225
 
226
  return $wp_query->posts;
 
227
 
228
- }
229
-
230
- private function get_products_brands( $product_ids ) {
231
 
232
- $product_ids = implode(',', array_map('intval', $product_ids) );
233
 
234
  global $wpdb;
235
 
236
- $brand_ids = $wpdb->get_col( "SELECT DISTINCT t.term_id
237
  FROM {$wpdb->prefix}terms AS t
238
  INNER JOIN {$wpdb->prefix}term_taxonomy AS tt
239
  ON t.term_id = tt.term_id
@@ -241,10 +235,8 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
241
  ON tr.term_taxonomy_id = tt.term_taxonomy_id
242
  WHERE tt.taxonomy = 'pwb-brand'
243
  AND tr.object_id IN ($product_ids)
244
- " );
245
-
246
- return ( $brand_ids ) ? $brand_ids : false;
247
 
 
248
  }
249
-
250
  }
1
  <?php
2
+
3
  namespace Perfect_Woocommerce_Brands\Widgets;
4
+
5
  use WP_Query;
6
 
7
+ defined('ABSPATH') or die('No script kiddies please!');
8
 
9
+ class PWB_Filter_By_Brand_Widget extends \WP_Widget
10
+ {
11
 
12
+ function __construct()
13
+ {
14
+ $params = array(
15
+ 'description' => __('Recommended for product categories or shop page', 'perfect-woocommerce-brands'),
16
+ 'name' => __('Filter products by brand', 'perfect-woocommerce-brands')
17
+ );
18
+ parent::__construct('PWB_Filter_By_Brand_Widget', '', $params);
19
  }
20
 
21
+ public function form($instance)
22
+ {
23
+ extract($instance);
24
 
25
+ $title = (isset($instance['title'])) ? $instance['title'] : esc_html__('Brands', 'perfect-woocommerce-brands');
26
+ $limit = (isset($instance['limit'])) ? $instance['limit'] : 20;
27
+ $hide_submit_btn = (isset($hide_submit_btn) && $hide_submit_btn == 'on') ? true : false;
28
+ $only_first_level_brands = (isset($only_first_level_brands) && $only_first_level_brands == 'on') ? true : false;
29
+ ?>
30
 
31
  <p>
32
+ <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php _e('Title:'); ?></label>
33
+ <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_html($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
34
+ </p>
35
 
36
  <p>
37
+ <label for="<?php echo esc_attr($this->get_field_id('limit')); ?>">
38
+ <?php echo __('Max number of brands', 'perfect-woocommerce-brands'); ?>
39
+ </label>
40
+ <input class="widefat" id="<?php echo esc_attr($this->get_field_id('limit')); ?>" name="<?php echo esc_html($this->get_field_name('limit')); ?>" type="text" value="<?php echo esc_attr($limit); ?>" />
41
+ </p>
42
 
43
  <p>
44
+ <input type="checkbox" id="<?php echo esc_attr($this->get_field_id('hide_submit_btn')); ?>" name="<?php echo esc_attr($this->get_field_name('hide_submit_btn')); ?>" <?php checked($hide_submit_btn); ?>>
45
+ <label for="<?php echo esc_attr($this->get_field_id('hide_submit_btn')); ?>">
46
+ <?php echo __('Hide filter button', 'perfect-woocommerce-brands'); ?>
47
+ </label>
48
+ </p>
 
 
 
 
49
 
50
  <p>
51
+ <input type="checkbox" id="<?php echo esc_attr($this->get_field_id('only_first_level_brands')); ?>" name="<?php echo esc_attr($this->get_field_name('only_first_level_brands')); ?>" <?php checked($only_first_level_brands); ?>>
52
+ <label for="<?php echo esc_attr($this->get_field_id('only_first_level_brands')); ?>">
53
+ <?php echo __('Show only first level brands', 'perfect-woocommerce-brands'); ?>
54
+ </label>
 
 
 
 
55
  </p>
56
 
57
+ <?php
58
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
+ public function update($new_instance, $old_instance)
61
+ {
62
+ $limit = trim(strip_tags($new_instance['limit']));
63
+ $limit = filter_var($limit, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
64
+
65
+ $instance = array();
66
+ $instance['title'] = (!empty($new_instance['title'])) ? sanitize_text_field($new_instance['title']) : '';
67
+ $instance['limit'] = ($limit != false) ? $limit : $old_instance['limit'];
68
+ $instance['hide_submit_btn'] = (isset($new_instance['hide_submit_btn'])) ? $new_instance['hide_submit_btn'] : '';
69
+ $instance['only_first_level_brands'] = (isset($new_instance['only_first_level_brands'])) ? $new_instance['only_first_level_brands'] : '';
70
+ return $instance;
71
+ }
72
 
73
+ public function widget($args, $instance)
74
+ {
75
+ extract($args);
76
+ extract($instance);
77
 
78
+ if (!is_tax('pwb-brand') && !is_product()) {
 
 
 
 
 
79
 
80
+ $hide_submit_btn = (isset($hide_submit_btn) && $hide_submit_btn == 'on') ? true : false;
81
+ $only_first_level_brands = (isset($only_first_level_brands) && $only_first_level_brands == 'on') ? true : false;
82
 
83
+ $show_widget = true;
84
+ $current_products = false;
85
+ if (is_product_taxonomy() || is_shop()) {
86
+ $current_products = $this->current_products_query();
87
+ if (empty($current_products)) $show_widget = false;
88
+ }
89
 
90
+ if ($show_widget) {
 
 
 
 
91
 
92
+ $title = (isset($instance['title'])) ? $instance['title'] : esc_html__('Brands', 'perfect-woocommerce-brands');
93
+ $title = apply_filters('widget_title', $title);
94
+ $limit = (isset($instance['limit'])) ? $instance['limit'] : 20;
95
 
96
+ echo $args['before_widget'];
97
+ if (!empty($title)) echo $args['before_title'] . $title . $args['after_title'];
98
+ $this->render_widget($current_products, $limit, $hide_submit_btn, $only_first_level_brands);
99
+ echo $args['after_widget'];
100
+ }
101
+ }
102
  }
103
 
104
+ public function render_widget($current_products, $limit, $hide_submit_btn, $only_first_level_brands)
105
+ {
106
 
107
  $result_brands = array();
108
 
109
+ if (is_product_taxonomy() || is_shop()) {
 
 
 
 
 
 
 
 
110
 
111
+ //obtains brands ids
112
+ if (!empty($current_products)) $result_brands = $this->get_products_brands($current_products);
 
 
 
 
 
113
 
114
+ //excludes the child brands if needed
115
+ if ($only_first_level_brands) {
116
+ $result_brands = $this->exclude_child_brands($result_brands);
 
117
  }
118
 
119
+ if (is_shop()) {
120
+ $cate_url = get_permalink(wc_get_page_id('shop'));
121
+ } else {
122
+ $cate = get_queried_object();
123
+ $cateID = $cate->term_id;
124
+ $cate_url = get_term_link($cateID);
125
+ }
126
+ } else {
127
+ //no product category
128
+ $cate_url = get_permalink(wc_get_page_id('shop'));
129
+ $result_brands = get_terms('pwb-brand', array('hide_empty' => true, 'fields' => 'ids'));
130
+ }
131
 
132
+ if ($limit > 0) $result_brands = array_slice($result_brands, 0, $limit);
133
 
134
+ global $wp;
135
+ $current_url = home_url(add_query_arg(array(), $wp->request));
 
 
 
 
136
 
137
+ if (!empty($result_brands)) {
138
 
139
+ $result_brands_ordered = array();
140
+ foreach ($result_brands as $brand) {
141
+ $brand = get_term($brand);
142
+ $result_brands_ordered[$brand->name] = $brand;
143
+ }
144
+ ksort($result_brands_ordered);
145
 
146
+ $result_brands_ordered = apply_filters('pwb_widget_brand_filter', $result_brands_ordered);
147
 
148
+ echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
149
+ 'filter-by-brand',
150
+ 'widgets',
151
+ array('cate_url' => $cate_url, 'brands' => $result_brands_ordered, 'hide_submit_btn' => $hide_submit_btn),
152
+ false
153
+ );
154
+ }
155
+ }
156
 
157
+ private function exclude_child_brands($brands)
158
+ {
159
 
160
  //gets parent for all brands
161
+ foreach ($brands as $brand_key => $brand) {
162
 
163
+ $brand_o = get_term($brand, 'pwb-brand');
164
 
165
+ if ($brand_o->parent) {
166
 
167
  //exclude this child brand and include the parent
168
+ unset($brands[$brand_key]);
169
+ if (!in_array($brand_o->parent, $brands)) $brands[$brand_key] = $brand_o->parent;
 
170
  }
 
171
  }
172
 
173
  //reset keys
174
+ $brands = array_values($brands);
175
 
176
 
177
  return $brands;
 
178
  }
179
 
180
+ private function current_products_query()
181
+ {
182
 
183
+ $args = array(
184
+ 'posts_per_page' => -1,
185
+ 'post_type' => 'product',
186
+ 'tax_query' => array(
187
+ array(
188
+ 'taxonomy' => 'pwb-brand',
189
  'operator' => 'EXISTS'
190
+ )
191
+ ),
192
  'fields' => 'ids',
193
+ );
194
 
195
  $cat = get_queried_object();
196
+ if (is_a($cat, 'WP_Term')) {
197
  $cat_id = $cat->term_id;
198
+ $cat_id_array = get_term_children($cat_id, $cat->taxonomy);
199
  $cat_id_array[] = $cat_id;
200
  $args['tax_query'][] = array(
201
  'taxonomy' => $cat->taxonomy,
204
  );
205
  }
206
 
207
+ if (get_option('woocommerce_hide_out_of_stock_items') === 'yes') {
208
  $args['meta_query'] = array(
209
  array(
210
+ 'key' => '_stock_status',
211
+ 'value' => 'outofstock',
212
+ 'compare' => 'NOT IN'
213
+ )
214
  );
215
  }
216
 
217
+ $wp_query = new WP_Query($args);
218
  wp_reset_postdata();
219
 
220
  return $wp_query->posts;
221
+ }
222
 
223
+ private function get_products_brands($product_ids)
224
+ {
 
225
 
226
+ $product_ids = implode(',', array_map('intval', $product_ids));
227
 
228
  global $wpdb;
229
 
230
+ $brand_ids = $wpdb->get_col("SELECT DISTINCT t.term_id
231
  FROM {$wpdb->prefix}terms AS t
232
  INNER JOIN {$wpdb->prefix}term_taxonomy AS tt
233
  ON t.term_id = tt.term_id
235
  ON tr.term_taxonomy_id = tt.term_taxonomy_id
236
  WHERE tt.taxonomy = 'pwb-brand'
237
  AND tr.object_id IN ($product_ids)
238
+ ");
 
 
239
 
240
+ return ($brand_ids) ? $brand_ids : false;
241
  }
 
242
  }
classes/widgets/class-pwb-list.php CHANGED
@@ -16,7 +16,7 @@ class PWB_List_Widget extends \WP_Widget {
16
  public function form($instance){
17
  extract($instance);
18
 
19
- $title = ( isset( $instance[ 'title' ] ) ) ? $instance[ 'title' ] : __('Brands', 'perfect-woocommerce-brands');
20
  if( !isset( $display_as ) ) $display_as = 'brand_logo';
21
  if( !isset( $columns ) ) $columns = '2';
22
  $hide_empty = ( isset( $hide_empty ) && $hide_empty == 'on' ) ? true : false;
16
  public function form($instance){
17
  extract($instance);
18
 
19
+ $title = ( isset( $instance[ 'title' ] ) ) ? $instance[ 'title' ] : esc_html__('Brands', 'perfect-woocommerce-brands');
20
  if( !isset( $display_as ) ) $display_as = 'brand_logo';
21
  if( !isset( $columns ) ) $columns = '2';
22
  $hide_empty = ( isset( $hide_empty ) && $hide_empty == 'on' ) ? true : false;
perfect-woocommerce-brands.php CHANGED
@@ -4,13 +4,13 @@
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: 1.8.3
8
  * Author: QuadLayers
9
  * Author URI: https://quadlayers.com
10
  * Text Domain: perfect-woocommerce-brands
11
  * Domain Path: /lang
12
  * License: GPLv3
13
- * Perfect WooCommerce Brands version 1.8.3, Copyright (C) 2019 QuadLayers
14
  * Perfect WooCommerce Brands is free software: you can redistribute it and/or modify
15
  * it under the terms of the GNU General Public License as published by
16
  * the Free Software Foundation, either version 3 of the License, or
@@ -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', '1.8.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');
@@ -110,7 +110,7 @@ if (is_plugin_active('woocommerce/woocommerce.php')) {
110
  } elseif (is_admin()) {
111
 
112
  add_action('admin_notices', function() {
113
- $message = __('Perfect WooCommerce Brands needs WooCommerce to run. Please, install and active WooCommerce plugin.', 'perfect-woocommerce-brands');
114
  printf('<div class="%1$s"><p>%2$s</p></div>', 'notice notice-error', $message);
115
  });
116
  }
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: 1.8.4
8
  * Author: QuadLayers
9
  * Author URI: https://quadlayers.com
10
  * Text Domain: perfect-woocommerce-brands
11
  * Domain Path: /lang
12
  * License: GPLv3
13
+ * Perfect WooCommerce Brands version 1.8.4, Copyright (C) 2019 QuadLayers
14
  * Perfect WooCommerce Brands is free software: you can redistribute it and/or modify
15
  * it under the terms of the GNU General Public License as published by
16
  * the Free Software Foundation, either version 3 of the License, or
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', '1.8.4');
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');
110
  } elseif (is_admin()) {
111
 
112
  add_action('admin_notices', function() {
113
+ $message = esc_html__('Perfect WooCommerce Brands needs WooCommerce to run. Please, install and active WooCommerce plugin.', 'perfect-woocommerce-brands');
114
  printf('<div class="%1$s"><p>%2$s</p></div>', 'notice notice-error', $message);
115
  });
116
  }
readme.txt CHANGED
@@ -5,9 +5,9 @@ Tags: woocommerce, woocommerce brands, woocommerce product, woocommerce manufact
5
  Requires at least: 4.7
6
  Tested up to: 5.4.2
7
  Requires PHP: 5.6
8
- Stable tag: 1.8.3
9
  WC requires at least: 3.0
10
- WC tested up to: 4.1.1
11
  License: GPLv3
12
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
13
 
@@ -90,6 +90,8 @@ You can also contribute [translating the plugin](https://translate.wordpress.org
90
 
91
 
92
  == Changelog ==
 
 
93
  = 1.8.3 =
94
  * Enhancement: Update suggestions
95
  = 1.8.2 =
5
  Requires at least: 4.7
6
  Tested up to: 5.4.2
7
  Requires PHP: 5.6
8
+ Stable tag: 1.8.4
9
  WC requires at least: 3.0
10
+ WC tested up to: 4.2.0
11
  License: GPLv3
12
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
13
 
90
 
91
 
92
  == Changelog ==
93
+ = 1.8.4 =
94
+ * Enhancement: dynamic data escaped
95
  = 1.8.3 =
96
  * Enhancement: Update suggestions
97
  = 1.8.2 =
templates/admin/brands-exporter.php CHANGED
@@ -8,8 +8,8 @@
8
  ?>
9
 
10
  <div class="pwb-brands-exporter pwb-clearfix">
11
- <button class="button pwb-brands-export"><?php _e('Export brands', 'perfect-woocommerce-brands');?></button>
12
- <button class="button pwb-brands-import"><?php _e('Import brands', 'perfect-woocommerce-brands');?></button>
13
  <input type="file" class="pwb-brands-import-file" accept="application/json">
14
  <p><?php _e( 'This tool allows you to export and import the brands between different sites using PWB.', 'perfect-woocommerce-brands' );?></p>
15
  </div>
8
  ?>
9
 
10
  <div class="pwb-brands-exporter pwb-clearfix">
11
+ <button class="button pwb-brands-export"><?php esc_html_e('Export brands', 'perfect-woocommerce-brands');?></button>
12
+ <button class="button pwb-brands-import"><?php esc_html_e('Import brands', 'perfect-woocommerce-brands');?></button>
13
  <input type="file" class="pwb-brands-import-file" accept="application/json">
14
  <p><?php _e( 'This tool allows you to export and import the brands between different sites using PWB.', 'perfect-woocommerce-brands' );?></p>
15
  </div>
templates/admin/edit-brands-bottom.php CHANGED
@@ -1,15 +1,16 @@
1
  <?php
 
2
  /**
3
  * The template for displaying the edit-tags.php table footer
4
  * @version 1.0.0
5
  */
6
 
7
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
8
  ?>
9
 
10
  <div class="pwb-edit-brands-bottom pwb-clearfix">
11
  <span class="dashicons dashicons-admin-collapse"></span>
12
  <p class="pwb-featured-count">
13
- <span><?php echo $data['featured_count'];?></span> <?php echo $data['text_featured'];?>
14
  </p>
15
- </div>
1
  <?php
2
+
3
  /**
4
  * The template for displaying the edit-tags.php table footer
5
  * @version 1.0.0
6
  */
7
 
8
+ defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
  <div class="pwb-edit-brands-bottom pwb-clearfix">
12
  <span class="dashicons dashicons-admin-collapse"></span>
13
  <p class="pwb-featured-count">
14
+ <span><?php echo esc_html($data['featured_count']); ?></span> <?php echo esc_html($data['text_featured']); ?>
15
  </p>
16
+ </div>
templates/shortcodes/az-listing.php CHANGED
@@ -1,13 +1,14 @@
1
  <?php
 
2
  /**
3
  * The template for displaying the a-z Listing
4
  * @version 1.0.1
5
  */
6
 
7
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
8
  ?>
9
 
10
- <?php if( !empty( $grouped_brands ) ): ?>
11
 
12
  <div class="pwb-az-listing">
13
 
@@ -15,8 +16,8 @@
15
 
16
  <ul class="pwb-clearfix">
17
 
18
- <?php foreach( $grouped_brands as $letter => $brand_group ): ?>
19
- <li><a href="#pwb-az-listing-<?php echo $letter;?>"><?php echo $letter;?></a></li>
20
  <?php endforeach; ?>
21
 
22
  </ul>
@@ -25,17 +26,17 @@
25
 
26
  <div class="pwb-az-listing-content">
27
 
28
- <?php foreach( $grouped_brands as $letter => $brand_group ): ?>
29
 
30
- <div id="pwb-az-listing-<?php echo $letter;?>" class="pwb-az-listing-row pwb-clearfix">
31
- <p class="pwb-az-listing-title"><?php echo $letter;?></p>
32
  <div class="pwb-az-listing-row-in">
33
 
34
- <?php foreach( $brand_group as $brand ): ?>
35
 
36
  <div class="pwb-az-listing-col">
37
- <a href="<?php echo get_term_link($brand['brand_term']->term_id);?>">
38
- <?php echo $brand['brand_term']->name;?>
39
  </a>
40
  </div>
41
 
@@ -50,4 +51,4 @@
50
 
51
  </div>
52
 
53
- <?php endif; ?>
1
  <?php
2
+
3
  /**
4
  * The template for displaying the a-z Listing
5
  * @version 1.0.1
6
  */
7
 
8
+ defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
+ <?php if (!empty($grouped_brands)) : ?>
12
 
13
  <div class="pwb-az-listing">
14
 
16
 
17
  <ul class="pwb-clearfix">
18
 
19
+ <?php foreach ($grouped_brands as $letter => $brand_group) : ?>
20
+ <li><a href="#pwb-az-listing-<?php echo esc_attr($letter); ?>"><?php echo esc_html($letter); ?></a></li>
21
  <?php endforeach; ?>
22
 
23
  </ul>
26
 
27
  <div class="pwb-az-listing-content">
28
 
29
+ <?php foreach ($grouped_brands as $letter => $brand_group) : ?>
30
 
31
+ <div id="pwb-az-listing-<?php echo esc_attr($letter); ?>" class="pwb-az-listing-row pwb-clearfix">
32
+ <p class="pwb-az-listing-title"><?php echo esc_attr($letter); ?></p>
33
  <div class="pwb-az-listing-row-in">
34
 
35
+ <?php foreach ($brand_group as $brand) : ?>
36
 
37
  <div class="pwb-az-listing-col">
38
+ <a href="<?php echo get_term_link($brand['brand_term']->term_id); ?>">
39
+ <?php echo esc_html($brand['brand_term']->name); ?>
40
  </a>
41
  </div>
42
 
51
 
52
  </div>
53
 
54
+ <?php endif; ?>
templates/shortcodes/brand.php CHANGED
@@ -1,27 +1,28 @@
1
  <?php
 
2
  /**
3
  * The template for displaying the "pwb-brand" shortcode
4
  * @version 1.0.0
5
  */
6
 
7
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
8
  ?>
9
 
10
- <?php if( !empty( $brands ) ): ?>
11
 
12
  <div class="pwb-brand-shortcode">
13
 
14
- <?php foreach( $brands as $brand ): ?>
15
 
16
- <a href="<?php echo $brand->term_link;?>" title="<?php _e( 'View brand', 'perfect-woocommerce-brands' );?>">
17
 
18
- <?php if( !$as_link && !empty( $brand->image ) ): ?>
19
 
20
- <?php echo $brand->image;?>
21
 
22
- <?php else: ?>
23
 
24
- <?php echo $brand->name;?>
25
 
26
  <?php endif; ?>
27
 
@@ -31,4 +32,4 @@
31
 
32
  </div>
33
 
34
- <?php endif; ?>
1
  <?php
2
+
3
  /**
4
  * The template for displaying the "pwb-brand" shortcode
5
  * @version 1.0.0
6
  */
7
 
8
+ defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
+ <?php if (!empty($brands)) : ?>
12
 
13
  <div class="pwb-brand-shortcode">
14
 
15
+ <?php foreach ($brands as $brand) : ?>
16
 
17
+ <a href="<?php echo esc_url($brand->term_link); ?>" title="<?php _e('View brand', 'perfect-woocommerce-brands'); ?>">
18
 
19
+ <?php if (!$as_link && !empty($brand->image)) : ?>
20
 
21
+ <?php echo wp_kses_post($brand->image); ?>
22
 
23
+ <?php else : ?>
24
 
25
+ <?php echo esc_html($brand->name); ?>
26
 
27
  <?php endif; ?>
28
 
32
 
33
  </div>
34
 
35
+ <?php endif; ?>
templates/shortcodes/carousel.php CHANGED
@@ -1,22 +1,23 @@
1
  <?php
 
2
  /**
3
  * The template for displaying the carousels
4
  * @version 1.0.0
5
  */
6
 
7
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
8
  ?>
9
 
10
  <div class="pwb-carousel" data-slick="<?php echo $slick_settings; ?>">
11
 
12
- <?php foreach( $brands as $brand ): ?>
13
  <div class="pwb-slick-slide">
14
- <a href="<?php echo $brand['link'];?>" title="<?php echo $brand['name']; ?>">
15
- <?php echo $brand['attachment_html'];?>
16
  </a>
17
  </div>
18
  <?php endforeach; ?>
19
 
20
- <div class="pwb-carousel-loader"><?php _e('Loading','perfect-woocommerce-brands');?>...</div>
21
 
22
- </div>
1
  <?php
2
+
3
  /**
4
  * The template for displaying the carousels
5
  * @version 1.0.0
6
  */
7
 
8
+ defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
  <div class="pwb-carousel" data-slick="<?php echo $slick_settings; ?>">
12
 
13
+ <?php foreach ($brands as $brand) : ?>
14
  <div class="pwb-slick-slide">
15
+ <a href="<?php echo esc_url($brand['link']); ?>" title="<?php echo esc_html($brand['name']); ?>">
16
+ <?php echo wp_kses_post($brand['attachment_html']); ?>
17
  </a>
18
  </div>
19
  <?php endforeach; ?>
20
 
21
+ <div class="pwb-carousel-loader"><?php esc_html_e('Loading', 'perfect-woocommerce-brands'); ?>...</div>
22
 
23
+ </div>
templates/shortcodes/product-carousel.php CHANGED
@@ -1,32 +1,33 @@
1
  <?php
 
2
  /**
3
  * The template for displaying the product carousels
4
  * @version 1.0.0
5
  */
6
 
7
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
8
  ?>
9
 
10
- <?php if( !empty( $products ) ): ?>
11
 
12
  <div class="pwb-product-carousel" data-slick="<?php echo $slick_settings; ?>">
13
 
14
- <?php foreach( $products as $product ): ?>
15
  <div class="pwb-slick-slide">
16
- <a href="<?php echo $product['permalink']; ?>">
17
- <?php echo $product['thumbnail']; ?>
18
- <h3><?php echo $product['title']; ?></h3>
19
- <?php echo do_shortcode('[add_to_cart id="'.$product['id'].'" style=""]'); ?>
20
  </a>
21
  </div>
22
  <?php endforeach; ?>
23
 
24
- <div class="pwb-carousel-loader"><?php _e('Loading','perfect-woocommerce-brands');?>...</div>
25
 
26
  </div>
27
 
28
- <?php else: ?>
29
 
30
- <div><?php _e('Nothing found');?></div>
31
 
32
- <?php endif; ?>
1
  <?php
2
+
3
  /**
4
  * The template for displaying the product carousels
5
  * @version 1.0.0
6
  */
7
 
8
+ defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
+ <?php if (!empty($products)) : ?>
12
 
13
  <div class="pwb-product-carousel" data-slick="<?php echo $slick_settings; ?>">
14
 
15
+ <?php foreach ($products as $product) : ?>
16
  <div class="pwb-slick-slide">
17
+ <a href="<?php echo esc_url($product['permalink']); ?>">
18
+ <?php echo wp_kses_post($product['thumbnail']); ?>
19
+ <h3><?php echo esc_html($product['title']); ?></h3>
20
+ <?php echo do_shortcode('[add_to_cart id="' . esc_attr($product['id']) . '" style=""]'); ?>
21
  </a>
22
  </div>
23
  <?php endforeach; ?>
24
 
25
+ <div class="pwb-carousel-loader"><?php esc_html_e('Loading', 'perfect-woocommerce-brands'); ?>...</div>
26
 
27
  </div>
28
 
29
+ <?php else : ?>
30
 
31
+ <div><?php esc_html_e('Nothing found'); ?></div>
32
 
33
+ <?php endif; ?>
templates/widgets/dropdown.php CHANGED
@@ -1,19 +1,20 @@
1
  <?php
 
2
  /**
3
  * The template for displaying the dropdown widget
4
  * @version 1.0.0
5
  */
6
 
7
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
8
  ?>
9
 
10
  <select class="pwb-dropdown-widget">
11
  <option selected="true" disabled="disabled">
12
- <?php echo apply_filters( 'pwb_dropdown_placeholder', __( 'Brands', 'perfect-woocommerce-brands' ) ); ?>
13
  </option>
14
- <?php foreach( $brands as $brand ): ?>
15
- <option value="<?php echo $brand->get('link');?>" <?php selected( $data['selected'], $brand->get('id') );?>>
16
- <?php echo $brand->get('name');?>
17
  </option>
18
  <?php endforeach; ?>
19
- </select>
1
  <?php
2
+
3
  /**
4
  * The template for displaying the dropdown widget
5
  * @version 1.0.0
6
  */
7
 
8
+ defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
  <select class="pwb-dropdown-widget">
12
  <option selected="true" disabled="disabled">
13
+ <?php echo apply_filters('pwb_dropdown_placeholder', __('Brands', 'perfect-woocommerce-brands')); ?>
14
  </option>
15
+ <?php foreach ($brands as $brand) : ?>
16
+ <option value="<?php echo esc_url($brand->get('link')); ?>" <?php selected($data['selected'], $brand->get('id')); ?>>
17
+ <?php echo esc_html($brand->get('name')); ?>
18
  </option>
19
  <?php endforeach; ?>
20
+ </select>
templates/widgets/filter-by-brand.php CHANGED
@@ -1,23 +1,24 @@
1
  <?php
 
2
  /**
3
  * The template for displaying filter by brand widget
4
  * @version 1.0.0
5
  */
6
 
7
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
8
  ?>
9
 
10
- <div class="pwb-filter-products<?php if( $hide_submit_btn ) echo ' pwb-hide-submit-btn'; ?>" data-cat-url="<?php echo $cate_url;?>">
11
  <ul>
12
- <?php foreach( $brands as $brand ): ?>
13
  <li>
14
  <label>
15
- <input type="checkbox" data-brand="<?php echo $brand->term_id;?>" value="<?php echo $brand->slug;?>"><?php echo $brand->name; ?>
16
  </label>
17
  </li>
18
  <?php endforeach; ?>
19
  </ul>
20
- <?php if( !$hide_submit_btn ): ?>
21
- <button><?php _e('Apply filter','perfect-woocommerce-brands') ?></button>
22
- <?php endif;?>
23
- </div>
1
  <?php
2
+
3
  /**
4
  * The template for displaying filter by brand widget
5
  * @version 1.0.0
6
  */
7
 
8
+ defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
+ <div class="pwb-filter-products<?php if ($hide_submit_btn) echo ' pwb-hide-submit-btn'; ?>" data-cat-url="<?php echo esc_url($cate_url); ?>">
12
  <ul>
13
+ <?php foreach ($brands as $brand) : ?>
14
  <li>
15
  <label>
16
+ <input type="checkbox" data-brand="<?php echo esc_attr($brand->term_id); ?>" value="<?php echo esc_html($brand->slug); ?>"><?php echo esc_html($brand->name); ?>
17
  </label>
18
  </li>
19
  <?php endforeach; ?>
20
  </ul>
21
+ <?php if (!$hide_submit_btn) : ?>
22
+ <button><?php esc_html_e('Apply filter', 'perfect-woocommerce-brands') ?></button>
23
+ <?php endif; ?>
24
+ </div>
templates/widgets/list-logo.php CHANGED
@@ -1,22 +1,23 @@
1
  <?php
 
2
  /**
3
- * The template for displaying the list logo widget
4
- * @version 1.0.0
5
- */
6
 
7
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
8
  ?>
9
 
10
  <ul class="pwb-row">
11
 
12
- <?php foreach( $data['brands'] as $brand ): ?>
13
 
14
- <li class="<?php echo $data['li_class'];?>">
15
 
16
- <a href="<?php echo $brand->get('link');?>" title="<?php echo $data['title_prefix'] . ' ' . $brand->get('name'); ?>">
17
 
18
- <?php if( !empty( html_entity_decode( $brand->get('image') ) ) ): ?>
19
- <?php echo html_entity_decode( $brand->get('image') ); ?>
20
  <?php endif; ?>
21
 
22
  </a>
@@ -25,4 +26,4 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
25
 
26
  <?php endforeach; ?>
27
 
28
- </ul>
1
  <?php
2
+
3
  /**
4
+ * The template for displaying the list logo widget
5
+ * @version 1.0.0
6
+ */
7
 
8
+ defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
  <ul class="pwb-row">
12
 
13
+ <?php foreach ($data['brands'] as $brand) : ?>
14
 
15
+ <li class="<?php echo esc_attr($data['li_class']); ?>">
16
 
17
+ <a href="<?php echo esc_url($brand->get('link')); ?>" title="<?php echo esc_html($data['title_prefix'] . ' ' . $brand->get('name')); ?>">
18
 
19
+ <?php if (!empty(html_entity_decode($brand->get('image')))) : ?>
20
+ <?php echo html_entity_decode($brand->get('image')); ?>
21
  <?php endif; ?>
22
 
23
  </a>
26
 
27
  <?php endforeach; ?>
28
 
29
+ </ul>
templates/widgets/list.php CHANGED
@@ -1,22 +1,23 @@
1
  <?php
 
2
  /**
3
- * The template for displaying the list widget
4
- * @version 1.0.0
5
- */
6
 
7
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
8
  ?>
9
 
10
  <ul class="pwb-row">
11
 
12
- <?php foreach( $data['brands'] as $brand ): ?>
13
 
14
  <li>
15
- <a href="<?php echo $brand->get('link');?>" title="<?php echo $data['title_prefix'] . ' ' . $brand->get('name'); ?>">
16
- <?php echo $brand->get('name'); ?>
17
  </a>
18
  </li>
19
 
20
  <?php endforeach; ?>
21
 
22
- </ul>
1
  <?php
2
+
3
  /**
4
+ * The template for displaying the list widget
5
+ * @version 1.0.0
6
+ */
7
 
8
+ defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
  <ul class="pwb-row">
12
 
13
+ <?php foreach ($data['brands'] as $brand) : ?>
14
 
15
  <li>
16
+ <a href="<?php echo esc_html($brand->get('link')); ?>" title="<?php echo esc_html($data['title_prefix'] . ' ' . $brand->get('name')); ?>">
17
+ <?php echo esc_html($brand->get('name')); ?>
18
  </a>
19
  </li>
20
 
21
  <?php endforeach; ?>
22
 
23
+ </ul>
uninstall.php CHANGED
@@ -12,7 +12,7 @@
12
  delete_option('wc_pwb_admin_tab_section_end');
13
  delete_option('wc_pwb_notice_plugin_review');
14
 
15
- //elimina el archivo de marcas exportadas si existe
16
  unlink( WP_CONTENT_DIR . '/uploads/pwb-export.json' );
17
 
18
  //update permalinks and clean cache
12
  delete_option('wc_pwb_admin_tab_section_end');
13
  delete_option('wc_pwb_notice_plugin_review');
14
 
15
+ //remove exported brands if exists
16
  unlink( WP_CONTENT_DIR . '/uploads/pwb-export.json' );
17
 
18
  //update permalinks and clean cache