Perfect Brands for WooCommerce - Version 1.8.1

Version Description

  • Enhancement: Update documentation link
Download this release

Release Info

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

Code changes from version 1.8.0 to 1.8.1

classes/admin/class-pwb-admin-tab.php CHANGED
@@ -2,9 +2,10 @@
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
- use WC_Admin_Settings, WC_Settings_Page;
 
6
 
7
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
8
 
9
  function pwb_admin_tab() {
10
 
@@ -12,277 +13,263 @@ function pwb_admin_tab() {
12
 
13
  public function __construct() {
14
 
15
- $this->id = 'pwb_admin_tab';
16
- $this->label = __( 'Brands', 'perfect-woocommerce-brands' );
17
 
18
- add_filter( 'woocommerce_settings_tabs_array', [ $this, 'add_settings_page' ], 20 );
19
- add_action( 'woocommerce_settings_' . $this->id, [ $this, 'output' ] );
20
- add_action( 'woocommerce_sections_' . $this->id, [ $this, 'output_sections' ] );
21
- add_action( 'woocommerce_settings_save_' . $this->id, [ $this, 'save' ] );
22
  }
23
 
24
  public function get_sections() {
25
 
26
  $sections = array(
27
- '' => __( 'General', 'perfect-woocommerce-brands' ),
28
- 'brand-pages' => __( 'Brand pages & loop', 'perfect-woocommerce-brands' ),
29
- 'single-product' => __( 'Single product', 'perfect-woocommerce-brands' ),
30
- 'tools' => __( 'Developer tools', 'perfect-woocommerce-brands' ),
31
  );
32
 
33
- return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
34
  }
35
 
36
- public function get_settings( $current_section = '' ) {
37
 
38
  $available_image_sizes_adapted = array();
39
  $available_image_sizes = get_intermediate_image_sizes();
40
- foreach( $available_image_sizes as $image_size ) $available_image_sizes_adapted[$image_size] = $image_size;
 
41
  $available_image_sizes_adapted['full'] = 'full';
42
 
43
- $pages_select_adapted = array( '-' => '-' );
44
  $pages_select = get_pages();
45
- foreach( $pages_select as $page ) $pages_select_adapted[$page->ID] = $page->post_title;
 
46
 
47
- if ( 'single-product' == $current_section ) {
48
 
49
- $settings = apply_filters( 'wc_pwb_admin_tab_settings', array(
50
-
51
- 'section_title' => array(
52
- 'name' => __( 'Single product', 'perfect-woocommerce-brands' ),
53
- 'type' => 'title',
54
- 'desc' => '',
55
- 'id' => 'wc_pwb_admin_tab_section_title'
56
- ),
57
- 'brand_single_product_tab' => array(
58
- 'name' => __( 'Single product tab', 'perfect-woocommerce-brands' ),
59
- 'type' => 'checkbox',
60
- 'default' => 'yes',
61
- 'desc' => __( 'Show brand tab in single product page', 'perfect-woocommerce-brands' ),
62
- 'id' => 'wc_pwb_admin_tab_brand_single_product_tab'
63
- ),
64
- 'show_brand_in_single' => array(
65
- 'name' => __( 'Show brands in single product', 'perfect-woocommerce-brands' ),
66
- 'type' => 'select',
67
- 'class' => 'pwb-admin-tab-field',
68
- 'desc' => __( 'Show brand logo (or name) in single product', 'perfect-woocommerce-brands' ),
69
- 'default' => 'brand_image',
70
- 'id' => 'wc_pwb_admin_tab_brands_in_single',
71
- 'options' => array(
72
- 'no' => __( 'No', 'perfect-woocommerce-brands' ),
73
- 'brand_link' => __( 'Show brand link', 'perfect-woocommerce-brands' ),
74
- 'brand_image' => __( 'Show brand image (if is set)', 'perfect-woocommerce-brands' )
75
- )
76
- ),
77
- 'brand_single_position' => array(
78
- 'name' => __( 'Brand position', 'perfect-woocommerce-brands' ),
79
- 'type' => 'select',
80
- 'class' => 'pwb-admin-tab-field',
81
- 'desc' => __( 'For single product', 'perfect-woocommerce-brands' ),
82
- 'id' => 'wc_pwb_admin_tab_brand_single_position',
83
- 'options' => array(
84
- 'before_title' => __( 'Before title', 'perfect-woocommerce-brands' ),
85
- 'after_title' => __( 'After title', 'perfect-woocommerce-brands' ),
86
- 'after_price' => __( 'After price', 'perfect-woocommerce-brands' ),
87
- 'after_excerpt' => __( 'After excerpt', 'perfect-woocommerce-brands' ),
88
- 'after_add_to_cart' => __( 'After add to cart', 'perfect-woocommerce-brands' ),
89
- 'meta' => __( 'In meta', 'perfect-woocommerce-brands' ),
90
- 'after_meta' => __( 'After meta', 'perfect-woocommerce-brands' ),
91
- 'after_sharing' => __( 'After sharing', 'perfect-woocommerce-brands' )
92
- )
93
- ),
94
- 'section_end' => array(
95
- 'type' => 'sectionend',
96
- 'id' => 'wc_pwb_admin_tab_section_end'
97
- )
98
-
99
- ) );
100
-
101
- } elseif ( 'brand-pages' == $current_section ) {
102
-
103
- $settings = apply_filters( 'wc_pwb_admin_tab_brand_pages_settings', array(
104
-
105
- 'section_title' => array(
106
- 'name' => __( 'Brand pages & loop', 'perfect-woocommerce-brands' ),
107
- 'type' => 'title',
108
- 'desc' => '',
109
- 'id' => 'wc_pwb_admin_tab_section_title'
110
- ),
111
- 'brand_description' => array(
112
- 'name' => __( 'Show brand description', 'perfect-woocommerce-brands' ),
113
- 'type' => 'select',
114
- 'class' => 'pwb-admin-tab-field',
115
- 'default' => 'yes',
116
- 'desc' => __( 'Show brand description (if is set) on brand archive page', 'perfect-woocommerce-brands' ),
117
- 'id' => 'wc_pwb_admin_tab_brand_desc',
118
- 'options' => array(
119
- 'yes' => __( 'Yes, before product loop', 'perfect-woocommerce-brands' ),
120
- 'yes_after_loop' => __( 'Yes, after product loop', 'perfect-woocommerce-brands' ),
121
- 'no' => __( 'No, hide description', 'perfect-woocommerce-brands' )
122
- )
123
- ),
124
- 'brand_banner' => array(
125
- 'name' => __( 'Show brand banner', 'perfect-woocommerce-brands' ),
126
- 'type' => 'select',
127
- 'class' => 'pwb-admin-tab-field',
128
- 'default' => 'yes',
129
- 'desc' => __( 'Show brand banner (if is set) on brand archive page', 'perfect-woocommerce-brands' ),
130
- 'id' => 'wc_pwb_admin_tab_brand_banner',
131
- 'options' => array(
132
- 'yes' => __( 'Yes, before product loop', 'perfect-woocommerce-brands' ),
133
- 'yes_after_loop' => __( 'Yes, after product loop', 'perfect-woocommerce-brands' ),
134
- 'no' => __( 'No, hide banner', 'perfect-woocommerce-brands' )
135
- )
136
- ),
137
- 'show_brand_on_loop' => array(
138
- 'name' => __( 'Show brands in loop', 'perfect-woocommerce-brands' ),
139
- 'type' => 'select',
140
- 'class' => 'pwb-admin-tab-field',
141
- 'desc' => __( 'Show brand logo (or name) in product loop', 'perfect-woocommerce-brands' ),
142
- 'id' => 'wc_pwb_admin_tab_brands_in_loop',
143
- 'options' => array(
144
- 'no' => __( 'No', 'perfect-woocommerce-brands' ),
145
- 'brand_link' => __( 'Show brand link', 'perfect-woocommerce-brands' ),
146
- 'brand_image' => __( 'Show brand image (if is set)', 'perfect-woocommerce-brands' )
147
  )
148
- ),
149
- 'section_end' => array(
150
- 'type' => 'sectionend',
151
- 'id' => 'wc_pwb_admin_tab_section_end'
152
- )
153
-
154
- ) );
155
-
156
- } elseif ( 'tools' == $current_section ) {
157
-
158
- $settings = apply_filters( 'wc_pwb_admin_tab_tools_settings', array(
159
-
160
- 'section_title' => array(
161
- 'name' => __( 'Developer tools', 'perfect-woocommerce-brands' ),
162
- 'type' => 'title',
163
- 'desc' => '',
164
- 'id' => 'wc_pwb_admin_tab_section_tools_title'
165
- ),
166
- 'brand_import' => array(
167
- 'name' => __( 'Import brands', 'perfect-woocommerce-brands' ),
168
- 'type' => 'select',
169
- 'class' => 'pwb-admin-tab-field',
170
- 'desc' => sprintf(
171
- __( 'Import brands from other brand plugin. <a href="%s" target="_blank">Click here for more details</a>', 'perfect-woocommerce-brands' ),
172
- 'https://github.com/titodevera/perfect-woocommerce-brands/wiki/How-to-import-brands-from-other-brands-plugin'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  ),
174
- 'id' => 'wc_pwb_admin_tab_tools_migrate',
175
- 'options' => array(
176
- '-' => __( '-', 'perfect-woocommerce-brands' ),
177
- 'yith' => __( 'YITH WooCommerce Brands Add-On', 'perfect-woocommerce-brands' ),
178
- 'ultimate' => __( 'Ultimate WooCommerce Brands', 'perfect-woocommerce-brands' ),
179
- 'woobrands' => __( 'Offical WooCommerce Brands', 'perfect-woocommerce-brands' )
180
  )
181
- ),
182
- 'brand_dummy_data' => array(
183
- 'name' => __( 'Dummy data', 'perfect-woocommerce-brands' ),
184
- 'type' => 'select',
185
- 'class' => 'pwb-admin-tab-field',
186
- 'desc' => __( 'Import generic brands and assign it to products randomly', 'perfect-woocommerce-brands' ),
187
- 'id' => 'wc_pwb_admin_tab_tools_dummy_data',
188
- 'options' => array(
189
- '-' => __( '-', 'perfect-woocommerce-brands' ),
190
- 'start_import' => __( 'Start import', 'perfect-woocommerce-brands' )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  )
192
- ),
193
- 'brands_system_status' => array(
194
- 'name' => __( 'System status', 'perfect-woocommerce-brands' ),
195
- 'type' => 'textarea',
196
- 'desc' => __( 'Show system status', 'perfect-woocommerce-brands' ),
197
- 'id' => 'wc_pwb_admin_tab_tools_system_status'
198
- ),
199
- 'section_end' => array(
200
- 'type' => 'sectionend',
201
- 'id' => 'wc_pwb_admin_tab_section_tools_end'
202
- )
203
-
204
- ) );
205
 
206
- } else {
207
 
208
- $brands_url = get_option( 'wc_pwb_admin_tab_slug', __( 'brands', 'perfect-woocommerce-brands' ) ) . '/' . __( 'brand-name', 'perfect-woocommerce-brands' ) . '/';
209
-
210
- $settings = apply_filters( 'wc_pwb_admin_tab_product_settings', array(
211
-
212
- 'section_title' => array(
213
- 'name' => __( 'General', 'perfect-woocommerce-brands' ),
214
- 'type' => 'title',
215
- 'desc' => '',
216
- 'id' => 'wc_pwb_admin_tab_section_title'
217
- ),
218
- 'slug' => array(
219
- 'name' => __( 'Slug', 'perfect-woocommerce-brands' ),
220
- 'type' => 'text',
221
- 'class' => 'pwb-admin-tab-field',
222
- 'desc' => __( 'Brands taxonomy slug', 'perfect-woocommerce-brands' ),
223
- 'desc_tip' => sprintf(
224
- __( 'Your brands URLs will look like "%s"', 'perfect-woocommerce-brands' ),
225
- 'https://site.com/' . $brands_url
226
  ),
227
- 'id' => 'wc_pwb_admin_tab_slug',
228
- 'placeholder' => get_taxonomy('pwb-brand')->rewrite['slug']
229
- ),
230
- 'brand_logo_size' => array(
231
- 'name' => __( 'Brand logo size', 'perfect-woocommerce-brands' ),
232
- 'type' => 'select',
233
- 'class' => 'pwb-admin-tab-field',
234
- 'desc' => __( 'Select the size for the brand logo image around the site', 'perfect-woocommerce-brands' ),
235
- 'desc_tip'=> __( 'The default image sizes can be configured under "Settings > Media". You can also define your own image sizes', 'perfect-woocommerce-brands' ),
236
- 'id' => 'wc_pwb_admin_tab_brand_logo_size',
237
- 'options' => $available_image_sizes_adapted
238
- ),
239
- 'brands_page_id' => array(
240
- 'name' => __( 'Brands page', 'perfect-woocommerce-brands' ),
241
- 'type' => 'select',
242
- 'class' => 'pwb-admin-tab-field pwb-admin-selectwoo',
243
- 'desc' => __( 'For linking breadcrumbs', 'perfect-woocommerce-brands' ),
244
- 'desc_tip' => __( 'Select your "Brands" page (if you have one), it will be linked in the breadcrumbs.', 'perfect-woocommerce-brands' ),
245
- 'id' => 'wc_pwb_admin_tab_brands_page_id',
246
- 'options' => $pages_select_adapted
247
- ),
248
- 'section_end' => array(
249
- 'type' => 'sectionend',
250
- 'id' => 'wc_pwb_admin_tab_section_end'
251
- )
252
-
253
- ) );
254
-
255
- }
256
-
257
- return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
 
 
 
 
258
 
259
- }
 
260
 
261
- public function output() {
262
 
263
- global $current_section;
264
 
265
- $settings = $this->get_settings( $current_section );
266
- WC_Admin_Settings::output_fields( $settings );
267
- }
268
 
269
  public function save() {
270
 
271
- update_option( 'old_wc_pwb_admin_tab_slug', get_taxonomy('pwb-brand')->rewrite['slug'] );
272
- if( isset( $_POST['wc_pwb_admin_tab_slug'] ) ) {
273
- $_POST['wc_pwb_admin_tab_slug'] = sanitize_title( $_POST['wc_pwb_admin_tab_slug'] );
274
  }
275
 
276
- global $current_section;
277
 
278
- $settings = $this->get_settings( $current_section );
279
- WC_Admin_Settings::save_fields( $settings );
280
- }
281
 
282
  }
283
 
284
  return new Pwb_Admin_Tab();
285
-
286
  }
287
 
288
- add_filter( 'woocommerce_get_settings_pages', 'Perfect_Woocommerce_Brands\Admin\pwb_admin_tab', 15 );
2
 
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
 
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' => __('Brand pages & loop', 'perfect-woocommerce-brands'),
30
+ 'single-product' => __('Single product', 'perfect-woocommerce-brands'),
31
+ 'tools' => __('Developer tools', 'perfect-woocommerce-brands'),
32
  );
33
 
34
+ return apply_filters('woocommerce_get_sections_' . $this->id, $sections);
35
  }
36
 
37
+ public function get_settings($current_section = '') {
38
 
39
  $available_image_sizes_adapted = array();
40
  $available_image_sizes = get_intermediate_image_sizes();
41
+ foreach ($available_image_sizes as $image_size)
42
+ $available_image_sizes_adapted[$image_size] = $image_size;
43
  $available_image_sizes_adapted['full'] = 'full';
44
 
45
+ $pages_select_adapted = array('-' => '-');
46
  $pages_select = get_pages();
47
+ foreach ($pages_select as $page)
48
+ $pages_select_adapted[$page->ID] = $page->post_title;
49
 
50
+ if ('single-product' == $current_section) {
51
 
52
+ $settings = apply_filters('wc_pwb_admin_tab_settings', array(
53
+ 'section_title' => array(
54
+ 'name' => __('Single product', 'perfect-woocommerce-brands'),
55
+ 'type' => 'title',
56
+ 'desc' => '',
57
+ 'id' => 'wc_pwb_admin_tab_section_title'
58
+ ),
59
+ 'brand_single_product_tab' => array(
60
+ 'name' => __('Single product tab', 'perfect-woocommerce-brands'),
61
+ 'type' => 'checkbox',
62
+ 'default' => 'yes',
63
+ 'desc' => __('Show brand tab in single product page', 'perfect-woocommerce-brands'),
64
+ 'id' => 'wc_pwb_admin_tab_brand_single_product_tab'
65
+ ),
66
+ 'show_brand_in_single' => array(
67
+ 'name' => __('Show brands in single product', 'perfect-woocommerce-brands'),
68
+ 'type' => 'select',
69
+ 'class' => 'pwb-admin-tab-field',
70
+ 'desc' => __('Show brand logo (or name) in single product', 'perfect-woocommerce-brands'),
71
+ 'default' => 'brand_image',
72
+ 'id' => 'wc_pwb_admin_tab_brands_in_single',
73
+ 'options' => array(
74
+ 'no' => __('No', 'perfect-woocommerce-brands'),
75
+ 'brand_link' => __('Show brand link', 'perfect-woocommerce-brands'),
76
+ 'brand_image' => __('Show brand image (if is set)', 'perfect-woocommerce-brands')
77
+ )
78
+ ),
79
+ 'brand_single_position' => array(
80
+ 'name' => __('Brand position', 'perfect-woocommerce-brands'),
81
+ 'type' => 'select',
82
+ 'class' => 'pwb-admin-tab-field',
83
+ 'desc' => __('For single product', 'perfect-woocommerce-brands'),
84
+ 'id' => 'wc_pwb_admin_tab_brand_single_position',
85
+ 'options' => array(
86
+ 'before_title' => __('Before title', 'perfect-woocommerce-brands'),
87
+ 'after_title' => __('After title', 'perfect-woocommerce-brands'),
88
+ 'after_price' => __('After price', 'perfect-woocommerce-brands'),
89
+ 'after_excerpt' => __('After excerpt', 'perfect-woocommerce-brands'),
90
+ 'after_add_to_cart' => __('After add to cart', 'perfect-woocommerce-brands'),
91
+ 'meta' => __('In meta', 'perfect-woocommerce-brands'),
92
+ 'after_meta' => __('After meta', 'perfect-woocommerce-brands'),
93
+ 'after_sharing' => __('After sharing', 'perfect-woocommerce-brands')
94
+ )
95
+ ),
96
+ 'section_end' => array(
97
+ 'type' => 'sectionend',
98
+ 'id' => 'wc_pwb_admin_tab_section_end'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  )
100
+ ));
101
+ } elseif ('brand-pages' == $current_section) {
102
+
103
+ $settings = apply_filters('wc_pwb_admin_tab_brand_pages_settings', array(
104
+ 'section_title' => array(
105
+ 'name' => __('Brand pages & loop', 'perfect-woocommerce-brands'),
106
+ 'type' => 'title',
107
+ 'desc' => '',
108
+ 'id' => 'wc_pwb_admin_tab_section_title'
109
+ ),
110
+ 'brand_description' => array(
111
+ 'name' => __('Show brand description', 'perfect-woocommerce-brands'),
112
+ 'type' => 'select',
113
+ 'class' => 'pwb-admin-tab-field',
114
+ 'default' => 'yes',
115
+ 'desc' => __('Show brand description (if is set) on brand archive page', 'perfect-woocommerce-brands'),
116
+ 'id' => 'wc_pwb_admin_tab_brand_desc',
117
+ 'options' => array(
118
+ 'yes' => __('Yes, before product loop', 'perfect-woocommerce-brands'),
119
+ 'yes_after_loop' => __('Yes, after product loop', 'perfect-woocommerce-brands'),
120
+ 'no' => __('No, hide description', 'perfect-woocommerce-brands')
121
+ )
122
+ ),
123
+ 'brand_banner' => array(
124
+ 'name' => __('Show brand banner', 'perfect-woocommerce-brands'),
125
+ 'type' => 'select',
126
+ 'class' => 'pwb-admin-tab-field',
127
+ 'default' => 'yes',
128
+ 'desc' => __('Show brand banner (if is set) on brand archive page', 'perfect-woocommerce-brands'),
129
+ 'id' => 'wc_pwb_admin_tab_brand_banner',
130
+ 'options' => array(
131
+ 'yes' => __('Yes, before product loop', 'perfect-woocommerce-brands'),
132
+ 'yes_after_loop' => __('Yes, after product loop', 'perfect-woocommerce-brands'),
133
+ 'no' => __('No, hide banner', 'perfect-woocommerce-brands')
134
+ )
135
+ ),
136
+ 'show_brand_on_loop' => array(
137
+ 'name' => __('Show brands in loop', 'perfect-woocommerce-brands'),
138
+ 'type' => 'select',
139
+ 'class' => 'pwb-admin-tab-field',
140
+ 'desc' => __('Show brand logo (or name) in product loop', 'perfect-woocommerce-brands'),
141
+ 'id' => 'wc_pwb_admin_tab_brands_in_loop',
142
+ 'options' => array(
143
+ 'no' => __('No', 'perfect-woocommerce-brands'),
144
+ 'brand_link' => __('Show brand link', 'perfect-woocommerce-brands'),
145
+ 'brand_image' => __('Show brand image (if is set)', 'perfect-woocommerce-brands')
146
+ )
147
  ),
148
+ 'section_end' => array(
149
+ 'type' => 'sectionend',
150
+ 'id' => 'wc_pwb_admin_tab_section_end'
 
 
 
151
  )
152
+ ));
153
+ } elseif ('tools' == $current_section) {
154
+
155
+ $settings = apply_filters('wc_pwb_admin_tab_tools_settings', array(
156
+ 'section_title' => array(
157
+ 'name' => __('Developer tools', 'perfect-woocommerce-brands'),
158
+ 'type' => 'title',
159
+ 'desc' => '',
160
+ 'id' => 'wc_pwb_admin_tab_section_tools_title'
161
+ ),
162
+ 'brand_import' => array(
163
+ 'name' => __('Import brands', 'perfect-woocommerce-brands'),
164
+ 'type' => 'select',
165
+ 'class' => 'pwb-admin-tab-field',
166
+ 'desc' => sprintf(
167
+ __('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)
168
+ ),
169
+ 'id' => 'wc_pwb_admin_tab_tools_migrate',
170
+ 'options' => array(
171
+ '-' => __('-', 'perfect-woocommerce-brands'),
172
+ 'yith' => __('YITH WooCommerce Brands Add-On', 'perfect-woocommerce-brands'),
173
+ 'ultimate' => __('Ultimate WooCommerce Brands', 'perfect-woocommerce-brands'),
174
+ 'woobrands' => __('Offical WooCommerce Brands', 'perfect-woocommerce-brands')
175
+ )
176
+ ),
177
+ 'brand_dummy_data' => array(
178
+ 'name' => __('Dummy data', 'perfect-woocommerce-brands'),
179
+ 'type' => 'select',
180
+ 'class' => 'pwb-admin-tab-field',
181
+ 'desc' => __('Import generic brands and assign it to products randomly', 'perfect-woocommerce-brands'),
182
+ 'id' => 'wc_pwb_admin_tab_tools_dummy_data',
183
+ 'options' => array(
184
+ '-' => __('-', 'perfect-woocommerce-brands'),
185
+ 'start_import' => __('Start import', 'perfect-woocommerce-brands')
186
+ )
187
+ ),
188
+ 'brands_system_status' => array(
189
+ 'name' => __('System status', 'perfect-woocommerce-brands'),
190
+ 'type' => 'textarea',
191
+ 'desc' => __('Show system status', 'perfect-woocommerce-brands'),
192
+ 'id' => 'wc_pwb_admin_tab_tools_system_status'
193
+ ),
194
+ 'section_end' => array(
195
+ 'type' => 'sectionend',
196
+ 'id' => 'wc_pwb_admin_tab_section_tools_end'
197
  )
198
+ ));
199
+ } else {
 
 
 
 
 
 
 
 
 
 
 
200
 
201
+ $brands_url = get_option('wc_pwb_admin_tab_slug', __('brands', 'perfect-woocommerce-brands')) . '/' . __('brand-name', 'perfect-woocommerce-brands') . '/';
202
 
203
+ $settings = apply_filters('wc_pwb_admin_tab_product_settings', array(
204
+ 'section_title' => array(
205
+ 'name' => __('General', 'perfect-woocommerce-brands'),
206
+ 'type' => 'title',
207
+ 'desc' => '',
208
+ 'id' => 'wc_pwb_admin_tab_section_title'
 
 
 
 
 
 
 
 
 
 
 
 
209
  ),
210
+ 'slug' => array(
211
+ 'name' => __('Slug', 'perfect-woocommerce-brands'),
212
+ 'type' => 'text',
213
+ 'class' => 'pwb-admin-tab-field',
214
+ 'desc' => __('Brands taxonomy slug', 'perfect-woocommerce-brands'),
215
+ 'desc_tip' => sprintf(
216
+ __('Your brands URLs will look like "%s"', 'perfect-woocommerce-brands'), 'https://site.com/' . $brands_url
217
+ ),
218
+ 'id' => 'wc_pwb_admin_tab_slug',
219
+ 'placeholder' => get_taxonomy('pwb-brand')->rewrite['slug']
220
+ ),
221
+ 'brand_logo_size' => array(
222
+ 'name' => __('Brand logo size', 'perfect-woocommerce-brands'),
223
+ 'type' => 'select',
224
+ 'class' => 'pwb-admin-tab-field',
225
+ 'desc' => __('Select the size for the brand logo image around the site', 'perfect-woocommerce-brands'),
226
+ 'desc_tip' => __('The default image sizes can be configured under "Settings > Media". You can also define your own image sizes', 'perfect-woocommerce-brands'),
227
+ 'id' => 'wc_pwb_admin_tab_brand_logo_size',
228
+ 'options' => $available_image_sizes_adapted
229
+ ),
230
+ 'brands_page_id' => array(
231
+ 'name' => __('Brands page', 'perfect-woocommerce-brands'),
232
+ 'type' => 'select',
233
+ 'class' => 'pwb-admin-tab-field pwb-admin-selectwoo',
234
+ 'desc' => __('For linking breadcrumbs', 'perfect-woocommerce-brands'),
235
+ 'desc_tip' => __('Select your "Brands" page (if you have one), it will be linked in the breadcrumbs.', 'perfect-woocommerce-brands'),
236
+ 'id' => 'wc_pwb_admin_tab_brands_page_id',
237
+ 'options' => $pages_select_adapted
238
+ ),
239
+ 'section_end' => array(
240
+ 'type' => 'sectionend',
241
+ 'id' => 'wc_pwb_admin_tab_section_end'
242
+ )
243
+ ));
244
+ }
245
 
246
+ return apply_filters('woocommerce_get_settings_' . $this->id, $settings, $current_section);
247
+ }
248
 
249
+ public function output() {
250
 
251
+ global $current_section;
252
 
253
+ $settings = $this->get_settings($current_section);
254
+ WC_Admin_Settings::output_fields($settings);
255
+ }
256
 
257
  public function save() {
258
 
259
+ update_option('old_wc_pwb_admin_tab_slug', get_taxonomy('pwb-brand')->rewrite['slug']);
260
+ if (isset($_POST['wc_pwb_admin_tab_slug'])) {
261
+ $_POST['wc_pwb_admin_tab_slug'] = sanitize_title($_POST['wc_pwb_admin_tab_slug']);
262
  }
263
 
264
+ global $current_section;
265
 
266
+ $settings = $this->get_settings($current_section);
267
+ WC_Admin_Settings::save_fields($settings);
268
+ }
269
 
270
  }
271
 
272
  return new Pwb_Admin_Tab();
 
273
  }
274
 
275
+ add_filter('woocommerce_get_settings_pages', 'Perfect_Woocommerce_Brands\Admin\pwb_admin_tab', 15);
classes/class-perfect-woocommerce-brands.php CHANGED
@@ -1,144 +1,150 @@
1
  <?php
 
2
  namespace Perfect_Woocommerce_Brands;
3
 
4
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
5
 
6
- class Perfect_Woocommerce_Brands{
7
 
8
- function __construct(){
9
- add_action( 'plugin_row_meta', array( '\Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands', 'plugin_row_meta' ), 10, 2 );
10
- add_action( 'woocommerce_init', array( $this, 'register_brands_taxonomy' ), 10, 0 );
11
- add_action( 'init', array( $this, 'add_brands_metafields' ) );
12
- add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
13
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
14
  $this->brand_logo_position();
15
- add_action( 'wp', array( $this, 'brand_desc_position' ) );
16
- add_action( 'woocommerce_after_shop_loop_item_title', array( $this, 'show_brands_in_loop' ) );
17
  $this->add_shortcodes();
18
- if( is_plugin_active('js_composer/js_composer.php') || is_plugin_active('visual_composer/js_composer.php') ){
19
- add_action( 'vc_before_init', array( $this,'vc_map_shortcodes' ) );
20
  }
21
- add_action( 'widgets_init', array( $this, 'register_widgets' ) );
22
- add_filter( 'woocommerce_structured_data_product', array( $this, 'product_microdata' ), 10, 2 );
23
- add_action( 'pre_get_posts', array( $this, 'pwb_brand_filter' ) );
24
- add_action( 'wp_ajax_dismiss_pwb_notice', array( $this, 'dismiss_pwb_notice' ) );
25
- add_action( 'admin_notices', array( $this, 'review_notice' ) );
26
-
27
- add_action( 'wp', function(){
28
- if( is_tax('pwb-brand') )
29
- remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
30
  });
31
- add_action( 'woocommerce_product_duplicate', array( $this, 'product_duplicate_save' ), 10, 2 );
32
 
33
- add_filter( 'woocommerce_get_breadcrumb', array( $this, 'breadcrumbs' ) );
34
 
35
- add_filter( 'shortcode_atts_products', array( $this, 'extend_products_shortcode_atts' ), 10, 4 );
36
- add_filter( 'woocommerce_shortcode_products_query', array( $this, 'extend_products_shortcode' ), 10, 2 );
37
 
38
- add_filter( 'manage_edit-product_sortable_columns', array( $this, 'brands_column_sortable' ), 90 );
39
- add_action( 'posts_clauses', array( $this, 'brands_column_sortable_posts' ), 10, 2 );
40
- add_filter( 'post_type_link', array( $this, 'brand_name_in_url' ), 10, 2 );
41
- add_action( 'pre_get_posts', array( $this, 'search_by_brand_name' ) );
42
 
43
  //clean caches
44
- add_action( 'edited_terms', array( $this, 'clean_caches' ), 10, 2 );
45
- add_action( 'created_term', array( $this, 'clean_caches_after_edit_brand' ), 10, 3 );
46
- add_action( 'delete_term', array( $this, 'clean_caches_after_edit_brand' ), 10, 3 );
47
  }
48
 
49
- public function clean_caches( $term_id, $taxonomy ) {
50
- if ( $taxonomy != 'pwb-brand' ) return;
 
51
  delete_transient('pwb_az_listing_cache');
52
  }
53
 
54
- public function clean_caches_after_edit_brand( $term_id, $tt_id, $taxonomy ) {
55
- if ( $taxonomy != 'pwb-brand' ) return;
 
56
  delete_transient('pwb_az_listing_cache');
57
  }
58
 
59
  /**
60
- * Show row meta on the plugin screen.
61
- *
62
- * @param mixed $links Plugin Row Meta.
63
- * @param mixed $file Plugin Base file.
64
- *
65
- * @return array
66
- */
67
- public static function plugin_row_meta( $links, $file ) {
68
- if( PWB_PLUGIN_BASENAME === $file ){
69
  $row_meta = array(
70
- 'docs' => '<a target="_blank" rel="noopener noferrer" href="https://github.com/titodevera/perfect-woocommerce-brands/wiki">' . esc_html__( 'Developer docs', 'perfect-woocommerce-brands' ) . '</a>',
71
  );
72
- return array_merge( $links, $row_meta );
73
  }
74
- return (array)$links;
75
  }
76
 
77
- public function brand_name_in_url( $permalink, $post ){
78
- if( $post->post_type == 'product' && strpos( $permalink, '%pwb-brand%' ) !== false ) {
79
- $term = 'product';
80
- $brands = wp_get_post_terms( $post->ID, 'pwb-brand' );
81
- if( ! empty( $brands ) && ! is_wp_error( $brands ) ) $term = current( $brands )->slug;
82
- $permalink = str_replace( '%pwb-brand%', $term, $permalink );
 
83
  }
84
  return $permalink;
85
  }
86
 
87
- public function brands_column_sortable_posts( $clauses, $wp_query ) {
88
  global $wpdb;
89
 
90
- if ( isset( $wp_query->query['orderby'] ) && 'taxonomy-pwb-brand' == $wp_query->query['orderby'] ) {
91
 
92
  $clauses['join'] .= "
93
  LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
94
  LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
95
  LEFT OUTER JOIN {$wpdb->terms} USING (term_id)";
96
 
97
- $clauses['where'] .= " AND (taxonomy = 'pwb-brand' OR taxonomy IS NULL)";
98
- $clauses['groupby'] = "object_id";
99
- $clauses['orderby'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) ";
100
- $clauses['orderby'] .= ( 'ASC' == strtoupper( $wp_query->get('order') ) ) ? 'ASC' : 'DESC';
101
  }
102
 
103
  return $clauses;
104
  }
105
 
106
- public function brands_column_sortable( $columns ){
107
  $columns['taxonomy-pwb-brand'] = 'taxonomy-pwb-brand';
108
  return $columns;
109
  }
110
 
111
- public function extend_products_shortcode_atts( $out, $pairs, $atts, $shortcode ){
112
- if( !empty( $atts['brands'] ) ) $out['brands'] = explode( ',', $atts['brands'] );
 
113
  return $out;
114
  }
115
 
116
- public function extend_products_shortcode( $query_args, $atts ){
117
 
118
- if( !empty( $atts['brands'] ) ){
119
  global $wpdb;
120
 
121
- $terms = $atts['brands'];
122
- $terms_count = count( $atts['brands'] );
123
  $terms_adapted = '';
124
 
125
  $terms_i = 0;
126
- foreach( $terms as $brand ){
127
- $terms_adapted .= '"'.$brand.'"';
128
  $terms_i++;
129
- if( $terms_i < $terms_count ) $terms_adapted .= ',';
 
130
  }
131
 
132
- $ids = $wpdb->get_col( "
133
  SELECT DISTINCT tr.object_id
134
  FROM {$wpdb->prefix}term_relationships as tr
135
  INNER JOIN {$wpdb->prefix}term_taxonomy as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
136
  INNER JOIN {$wpdb->prefix}terms as t ON tt.term_id = t.term_id
137
  WHERE tt.taxonomy LIKE 'pwb_brand' AND t.slug IN ($terms_adapted)
138
- " );
139
 
140
- if ( ! empty( $ids ) ) {
141
- if ( 1 === count( $ids ) ) {
142
  $query_args['p'] = $ids[0];
143
  } else {
144
  $query_args['post__in'] = $ids;
@@ -149,166 +155,161 @@ class Perfect_Woocommerce_Brands{
149
  return $query_args;
150
  }
151
 
152
- public function review_notice(){
153
  $show_notice = get_option('wc_pwb_notice_plugin_review', true);
154
  $activate_on = get_option('pwb_activate_on', time());
155
  $now = time();
156
  $one_week = 604800;
157
  $date_diff = $now - $activate_on;
158
 
159
- if ( $show_notice && $date_diff > $one_week ) {
160
- ?>
161
  <div class="notice notice-info pwb-notice-dismissible is-dismissible" data-notice="wc_pwb_notice_plugin_review">
162
- <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>
163
  <p>
164
- <?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' ); ?>
165
- <?php _e( '<a href="https://translate.wordpress.org/projects/wp-plugins/perfect-woocommerce-brands" target="_blank">Translate the plugin</a>', 'perfect-woocommerce-brands' ); ?>
166
- <?php _e( '<a href="https://github.com/titodevera/perfect-woocommerce-brands" target="_blank">View on GitHub</a>', 'perfect-woocommerce-brands' ); ?>
167
  </p>
168
  </div>
169
- <?php
170
  }
171
  }
172
 
173
- public function dismiss_pwb_notice(){
174
- $notice_name_whitelist = array( 'wc_pwb_notice_plugin_review' );
175
- if( isset( $_POST['notice_name'] ) && in_array( $_POST['notice_name'], $notice_name_whitelist ) ){
176
- update_option( $_POST['notice_name'], 0 );
177
  echo 'ok';
178
- }else{
179
  echo 'error';
180
  }
181
  wp_die();
182
  }
183
 
184
- public function pwb_brand_filter( $query ){
185
 
186
- if( !empty( $_GET['pwb-brand-filter'] ) ){
187
 
188
- $terms_array = explode( ',', $_GET['pwb-brand-filter'] );
189
 
190
  //remove invalid terms (security)
191
- for($i=0; $i < count($terms_array); $i++) {
192
- if( !term_exists( $terms_array[$i], 'pwb-brand' ) ) unset($terms_array[$i]);
 
193
  }
194
 
195
  $filterable_product = false;
196
- if( is_product_taxonomy() || is_post_type_archive( 'product' ) )
197
  $filterable_product = true;
198
 
199
- if( $filterable_product && $query->is_main_query() ) {
200
 
201
  $query->set('tax_query', array(
202
- array (
203
- 'taxonomy' => 'pwb-brand',
204
- 'field' => 'slug',
205
- 'terms' => $terms_array
206
- )
207
  ));
208
-
209
  }
210
-
211
  }
212
-
213
  }
214
 
215
  /*
216
- * Adds microdata (brands) to single products
217
- */
218
- public function product_microdata( $markup, $product ){
 
219
 
220
  $new_markup = array();
221
- $brands = wp_get_post_terms( $product->get_id(), 'pwb-brand');
222
  foreach ($brands as $brand) {
223
  $new_markup['brand'][] = $brand->name;
224
  }
225
 
226
- return array_merge( $markup, $new_markup );
227
-
228
  }
229
 
230
- public function add_shortcodes(){
231
- add_shortcode( 'pwb-carousel', array(
232
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Carousel_Shortcode',
233
- 'carousel_shortcode'
234
- ) );
235
- add_shortcode( 'pwb-product-carousel', array(
236
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Product_Carousel_Shortcode',
237
- 'product_carousel_shortcode'
238
- ) );
239
- add_shortcode( 'pwb-all-brands', array(
240
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_All_Brands_Shortcode',
241
- 'all_brands_shortcode'
242
- ) );
243
- add_shortcode( 'pwb-az-listing', array(
244
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_AZ_Listing_Shortcode',
245
- 'shortcode'
246
- ) );
247
- add_shortcode( 'pwb-brand', array(
248
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Brand_Shortcode',
249
- 'brand_shortcode'
250
- ) );
251
  }
252
 
253
- public function register_widgets(){
254
- register_widget( '\Perfect_Woocommerce_Brands\Widgets\PWB_List_Widget' );
255
- register_widget( '\Perfect_Woocommerce_Brands\Widgets\PWB_Dropdown_Widget' );
256
- register_widget( '\Perfect_Woocommerce_Brands\Widgets\PWB_Filter_By_Brand_Widget' );
257
  }
258
 
259
- public function show_brands_in_loop(){
260
 
261
  $brands_in_loop = get_option('wc_pwb_admin_tab_brands_in_loop');
262
  $image_size_selected = get_option('wc_pwb_admin_tab_brand_logo_size', 'thumbnail');
263
 
264
- if( $brands_in_loop == 'brand_link' || $brands_in_loop == 'brand_image' ){
265
 
266
  global $product;
267
  $product_id = $product->get_id();
268
- $product_brands = wp_get_post_terms($product_id, 'pwb-brand');
269
- if(!empty($product_brands)){
270
  echo '<div class="pwb-brands-in-loop">';
271
  foreach ($product_brands as $brand) {
272
 
273
  echo '<span>';
274
- $brand_link = get_term_link ( $brand->term_id, 'pwb-brand' );
275
- $attachment_id = get_term_meta( $brand->term_id, 'pwb_brand_image', 1 );
276
-
277
- $attachment_html = wp_get_attachment_image( $attachment_id, $image_size_selected );
278
- if( !empty($attachment_html) && $brands_in_loop == 'brand_image' ){
279
- echo '<a href="'.$brand_link.'">'.$attachment_html.'</a>';
280
- }else{
281
- echo '<a href="'.$brand_link.'">'.$brand->name.'</a>';
282
- }
283
  echo '</span>';
284
-
285
  }
286
  echo '</div>';
287
  }
288
-
289
  }
290
-
291
  }
292
 
293
  /**
294
- * woocommerce_single_product_summary hook.
295
- *
296
- * @hooked woocommerce_template_single_title - 5
297
- * @hooked woocommerce_template_single_rating - 10
298
- * @hooked woocommerce_template_single_price - 10
299
- * @hooked woocommerce_template_single_excerpt - 20
300
- * @hooked woocommerce_template_single_add_to_cart - 30
301
- * @hooked woocommerce_template_single_meta - 40
302
- * @hooked woocommerce_template_single_sharing - 50
303
- */
304
- private function brand_logo_position(){
305
  $position = 41;
306
  $position_selected = get_option('wc_pwb_admin_tab_brand_single_position');
307
- if ( ! $position_selected ) {
308
- update_option( 'wc_pwb_admin_tab_brand_single_position', 'after_meta' );
309
  }
310
 
311
- switch ( $position_selected ) {
312
  case 'before_title':
313
  $position = 4;
314
  break;
@@ -332,48 +333,42 @@ class Perfect_Woocommerce_Brands{
332
  break;
333
  }
334
 
335
- if ( $position_selected == 'meta' ) {
336
- add_action( 'woocommerce_product_meta_end', [ $this, 'action_woocommerce_single_product_summary' ] );
337
  } else {
338
- add_action( 'woocommerce_single_product_summary', [ $this, 'action_woocommerce_single_product_summary' ], $position );
339
  }
340
-
341
  }
342
 
343
- public function brand_desc_position(){
344
 
345
- if( is_tax('pwb-brand') && !is_paged() ){
346
 
347
  $show_banner = get_option('wc_pwb_admin_tab_brand_banner');
348
- $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
349
 
350
- if( (!$show_banner || $show_banner == 'yes') && (!$show_desc || $show_desc == 'yes') ){
351
  //show banner and description before loop
352
- add_action( 'woocommerce_archive_description', array( $this, 'print_brand_banner_and_desc' ), 15);
353
-
354
- }elseif( $show_banner == 'yes_after_loop' && $show_desc == 'yes_after_loop' ){
355
  //show banner and description after loop
356
- add_action( 'woocommerce_after_main_content', array( $this, 'print_brand_banner_and_desc' ), 9);
357
-
358
- }else{
359
  //show banner and description independently
360
 
361
- if( !$show_banner || $show_banner == 'yes' ){
362
- add_action( 'woocommerce_archive_description', array( $this, 'print_brand_banner' ), 15);
363
- }elseif( $show_banner == 'yes_after_loop' ){
364
- add_action( 'woocommerce_after_main_content', array( $this, 'print_brand_banner' ), 9);
365
  }
366
 
367
- if( !$show_desc || $show_desc == 'yes' ){
368
- add_action( 'woocommerce_archive_description', array( $this, 'print_brand_desc' ), 15);
369
- }elseif( $show_desc == 'yes_after_loop' ){
370
- add_action( 'woocommerce_after_main_content', array( $this, 'print_brand_desc' ), 9);
371
  }
372
-
373
  }
374
-
375
  }
376
-
377
  }
378
 
379
  /*
@@ -383,530 +378,501 @@ class Perfect_Woocommerce_Brands{
383
  * @link https://vc.wpbakery.com/
384
  * @return mixed
385
  */
386
- public function vc_map_shortcodes(){
387
- $available_image_sizes_adapted = array();
388
- $available_image_sizes = get_intermediate_image_sizes();
389
 
390
- foreach($available_image_sizes as $image_size){
391
- $available_image_sizes_adapted[$image_size] = $image_size;
392
- }
 
 
 
 
393
 
394
- vc_map(array(
395
- "name" => __( "PWB Product carousel", "perfect-woocommerce-brands" ),
396
- "description" => __( "Product carousel by brand or by category", "perfect-woocommerce-brands" ),
397
- "base" => "pwb-product-carousel",
398
- "class" => "",
399
- "icon" => PWB_PLUGIN_URL .'/assets/img/icon_pwb.jpg',
400
- "category" => "WooCommerce",
401
- "params" => array(
402
- array(
403
- "type" => "dropdown",
404
- "heading" => __( "Brand", "perfect-woocommerce-brands" ),
405
- "param_name" => "brand",
406
- "admin_label" => true,
407
- "value" => self::get_brands_array( true )
408
- ),
409
- array(
410
- "type" => "textfield",
411
- "holder" => "div",
412
- "heading" => __( "Products", "perfect-woocommerce-brands" ),
413
- "param_name" => "products",
414
- "value" => "10",
415
- "description" => __( "Number of products to load", "perfect-woocommerce-brands" )
416
- ),
417
- array(
418
- "type" => "textfield",
419
- "holder" => "div",
420
- "heading" => __( "Products to show", "perfect-woocommerce-brands" ),
421
- "param_name" => "products_to_show",
422
- "value" => "5",
423
- "description" => __( "Number of products to show", "perfect-woocommerce-brands" )
424
- ),
425
- array(
426
- "type" => "textfield",
427
- "holder" => "div",
428
- "heading" => __( "Products to scroll", "perfect-woocommerce-brands" ),
429
- "param_name" => "products_to_scroll",
430
- "value" => "1",
431
- "description" => __( "Number of products to scroll", "perfect-woocommerce-brands" )
432
- ),
433
- array(
434
- "type" => "checkbox",
435
- "holder" => "div",
436
- "heading" => __( "Autoplay", "perfect-woocommerce-brands" ),
437
- "param_name" => "autoplay",
438
- "description" => __( "Autoplay carousel", "perfect-woocommerce-brands" )
439
- ),
440
- array(
441
- "type" => "checkbox",
442
- "holder" => "div",
443
- "heading" => __( "Arrows", "perfect-woocommerce-brands" ),
444
- "param_name" => "arrows",
445
- "description" => __( "Display prev and next arrows", "perfect-woocommerce-brands" )
446
- )
447
- )
448
- ));
449
-
450
- vc_map(array(
451
- "name" => __( "PWB Brands carousel", "perfect-woocommerce-brands" ),
452
- "description" => __( "Brands carousel", "perfect-woocommerce-brands" ),
453
- "base" => "pwb-carousel",
454
- "class" => "",
455
- "icon" => PWB_PLUGIN_URL .'/assets/img/icon_pwb.jpg',
456
- "category" => "WooCommerce",
457
- "params" => array(
458
- array(
459
- "type" => "textfield",
460
- "holder" => "div",
461
- "heading" => __( "Items", "perfect-woocommerce-brands" ),
462
- "param_name" => "items",
463
- "value" => "10",
464
- "description" => __( "Number of items to load (or 'featured')", "perfect-woocommerce-brands" )
465
- ),
466
- array(
467
- "type" => "textfield",
468
- "holder" => "div",
469
- "heading" => __( "Items to show", "perfect-woocommerce-brands" ),
470
- "param_name" => "items_to_show",
471
- "value" => "5",
472
- "description" => __( "Number of items to show", "perfect-woocommerce-brands" )
473
- ),
474
- array(
475
- "type" => "textfield",
476
- "holder" => "div",
477
- "heading" => __( "Items to scroll", "perfect-woocommerce-brands" ),
478
- "param_name" => "items_to_scroll",
479
- "value" => "1",
480
- "description" => __( "Number of items to scroll", "perfect-woocommerce-brands" )
481
- ),
482
- array(
483
- "type" => "checkbox",
484
- "holder" => "div",
485
- "heading" => __( "Autoplay", "perfect-woocommerce-brands" ),
486
- "param_name" => "autoplay",
487
- "description" => __( "Autoplay carousel", "perfect-woocommerce-brands" )
488
- ),
489
- array(
490
- "type" => "checkbox",
491
- "holder" => "div",
492
- "heading" => __( "Arrows", "perfect-woocommerce-brands" ),
493
- "param_name" => "arrows",
494
- "description" => __( "Display prev and next arrows", "perfect-woocommerce-brands" )
495
- ),
496
- array(
497
- "type" => "dropdown",
498
- "heading" => __( "Brand logo size", "perfect-woocommerce-brands" ),
499
- "param_name" => "image_size",
500
- "admin_label" => true,
501
- "value" => $available_image_sizes_adapted
502
- )
503
- )
504
-
505
-
506
- ));
507
-
508
- vc_map(array(
509
- "name" => __( "PWB All brands", "perfect-woocommerce-brands" ),
510
- "description" => __( "Show all brands", "perfect-woocommerce-brands" ),
511
- "base" => "pwb-all-brands",
512
- "class" => "",
513
- "icon" => PWB_PLUGIN_URL .'/assets/img/icon_pwb.jpg',
514
- "category" => "WooCommerce",
515
- "params" => array(
516
- array(
517
- "type" => "textfield",
518
- "holder" => "div",
519
- "heading" => __( "Brands per page", "perfect-woocommerce-brands" ),
520
- "param_name" => "per_page",
521
- "value" => "10",
522
- "description" => __( "Show x brands per page", "perfect-woocommerce-brands" )
523
- ),
524
- array(
525
- "type" => "dropdown",
526
- "heading" => __( "Brand logo size", "perfect-woocommerce-brands" ),
527
- "param_name" => "image_size",
528
- "admin_label" => true,
529
- "value" => $available_image_sizes_adapted
530
- ),
531
- array(
532
- "type" => "dropdown",
533
- "heading" => __( "Order by", "perfect-woocommerce-brands" ),
534
- "param_name" => "order_by",
535
- "admin_label" => true,
536
- "value" => array(
537
- 'name' => 'name',
538
- 'slug' => 'slug',
539
- 'term_id' => 'term_id',
540
- 'id' => 'id',
541
  'description' => 'description',
542
- 'rand' => 'rand'
543
- )
544
- ),
545
- array(
546
- "type" => "dropdown",
547
- "heading" => __( "Order", "perfect-woocommerce-brands" ),
548
- "param_name" => "order",
549
- "admin_label" => true,
550
- "value" => array(
551
  'ASC' => 'ASC',
552
  'DSC' => 'DSC'
553
- )
554
- ),
555
- array(
556
- "type" => "dropdown",
557
- "heading" => __( "Title position", "perfect-woocommerce-brands" ),
558
- "param_name" => "title_position",
559
- "admin_label" => true,
560
- "value" => array(
561
- __( "Before image", "perfect-woocommerce-brands" ) => 'before',
562
- __( "After image", "perfect-woocommerce-brands" ) => 'after',
563
- __( "Hide", "perfect-woocommerce-brands" ) => 'none'
564
- )
565
- ),
566
- array(
567
- "type" => "checkbox",
568
- "holder" => "div",
569
- "heading" => __( "Hide empty", "perfect-woocommerce-brands" ),
570
- "param_name" => "hide_empty",
571
- "description" => __( "Hide brands that have not been assigned to any product", "perfect-woocommerce-brands" )
572
- )
573
- )
574
-
575
-
576
- ));
577
-
578
- vc_map(array(
579
- "name" => __( "PWB AZ Listing", "perfect-woocommerce-brands" ),
580
- "description" => __( "AZ Listing for brands", "perfect-woocommerce-brands" ),
581
- "base" => "pwb-az-listing",
582
- "class" => "",
583
- "icon" => PWB_PLUGIN_URL .'/assets/img/icon_pwb.jpg',
584
- "category" => "WooCommerce",
585
  "params" => array(
586
- array(
587
- "type" => "dropdown",
588
- "heading" => __( "Only parent brands", "perfect-woocommerce-brands" ),
589
- "param_name" => "only_parents",
590
- "admin_label" => true,
591
- "value" => array( __('No') => 'no', __('Yes') => 'yes' ),
592
- )
593
  )
594
- ));
595
-
596
- vc_map(array(
597
- "name" => __( "PWB brand", "perfect-woocommerce-brands" ),
598
- "description" => __( "Show brand for a specific product", "perfect-woocommerce-brands" ),
599
- "base" => "pwb-brand",
600
- "class" => "",
601
- "icon" => PWB_PLUGIN_URL .'/assets/img/icon_pwb.jpg',
602
- "category" => "WooCommerce",
603
-
604
- "params" => array(
605
- array(
606
- "type" => "textfield",
607
- "holder" => "div",
608
- "heading" => __( "Product id", "perfect-woocommerce-brands" ),
609
- "param_name" => "product_id",
610
- "value" => null,
611
- "description" => __( "Product id (post id)", "perfect-woocommerce-brands" )
612
- ),
613
- array(
614
- "type" => "dropdown",
615
- "heading" => __( "Brand logo size", "perfect-woocommerce-brands" ),
616
- "param_name" => "image_size",
617
- "admin_label" => true,
618
- "value" => $available_image_sizes_adapted
619
- )
620
-
621
- )
622
-
623
-
624
- ));
625
  }
626
 
627
  public function action_woocommerce_single_product_summary() {
628
- $brands = wp_get_post_terms( get_the_ID(), 'pwb-brand');
629
-
630
- if( !is_wp_error( $brands ) ){
631
 
632
- if( sizeof( $brands ) > 0 ){
633
 
634
- $show_as = get_option( 'wc_pwb_admin_tab_brands_in_single' );
635
 
636
- if( $show_as!='no' ){
637
 
638
- do_action( 'pwb_before_single_product_brands', $brands );
639
 
640
- echo '<div class="pwb-single-product-brands pwb-clearfix">';
641
 
642
- if ( $show_as == 'brand_link' ) {
643
- $before_brands_links = '<span class="pwb-text-before-brands-links">';
644
- $before_brands_links.= apply_filters( 'pwb_text_before_brands_links', __('Brands', 'perfect-woocommerce-brands') );
645
- $before_brands_links.= ':</span>';
646
- echo apply_filters( 'pwb_html_before_brands_links', $before_brands_links );
647
- }
648
 
649
- foreach( $brands as $brand ){
650
- $brand_link = get_term_link ( $brand->term_id, 'pwb-brand' );
651
- $attachment_id = get_term_meta( $brand->term_id, 'pwb_brand_image', 1 );
652
-
653
- $image_size = 'thumbnail';
654
- $image_size_selected = get_option('wc_pwb_admin_tab_brand_logo_size', 'thumbnail');
655
- if($image_size_selected!=false){
656
- $image_size = $image_size_selected;
657
- }
658
 
659
- $attachment_html = wp_get_attachment_image($attachment_id,$image_size);
 
 
660
 
661
- if( !empty($attachment_html) && $show_as=='brand_image' || !empty($attachment_html) && !$show_as ){
662
- echo '<a href="'.$brand_link.'" title="'.$brand->name.'">'.$attachment_html.'</a>';
663
- }else{
664
- echo '<a href="'.$brand_link.'" title="'.__( 'View brand', 'perfect-woocommerce-brands' ).'">'.$brand->name.'</a>';
665
- }
666
- }
667
- echo '</div>';
668
 
669
- do_action( 'pwb_after_single_product_brands', $brands );
670
 
 
 
 
 
671
  }
672
-
673
  }
 
674
 
 
 
675
  }
676
-
677
  }
678
 
679
- public function enqueue_scripts(){
680
 
681
- wp_register_script(
682
- 'pwb-lib-slick',
683
- PWB_PLUGIN_URL . '/assets/lib/slick/slick.min.js',
684
- array('jquery'),
685
- '1.8.0',
686
- true
687
- );
688
 
689
- wp_register_style(
690
- 'pwb-lib-slick',
691
- PWB_PLUGIN_URL . '/assets/lib/slick/slick.css',
692
- array(),
693
- '1.8.0',
694
- 'all'
695
- );
696
 
697
- wp_enqueue_style(
698
- 'pwb-styles-frontend',
699
- PWB_PLUGIN_URL . '/assets/css/styles-frontend.min.css',
700
- array(),
701
- PWB_PLUGIN_VERSION,
702
- 'all'
703
- );
704
-
705
- wp_register_script(
706
- 'pwb-functions-frontend',
707
- PWB_PLUGIN_URL . '/assets/js/functions-frontend.min.js',
708
- array('jquery'),
709
- PWB_PLUGIN_VERSION,
710
- true
711
- );
712
 
713
- wp_localize_script( 'pwb-functions-frontend', 'pwb_ajax_object', array(
714
- 'carousel_prev' => apply_filters('pwb_carousel_prev','&lt;'),
715
- 'carousel_next' => apply_filters('pwb_carousel_next','&gt;')
716
- ) );
717
 
718
- wp_enqueue_script('pwb-functions-frontend');
 
 
 
719
 
 
720
  }
721
 
722
- public function admin_enqueue_scripts( $hook ){
723
- $screen = get_current_screen();
724
- if($hook == 'edit-tags.php' && $screen->taxonomy == 'pwb-brand' || $hook == 'term.php' && $screen->taxonomy == 'pwb-brand') {
725
- wp_enqueue_media();
726
- }
727
 
728
- wp_enqueue_style('pwb-styles-admin', PWB_PLUGIN_URL . '/assets/css/styles-admin.min.css', array(), PWB_PLUGIN_VERSION);
729
 
730
- wp_register_script('pwb-functions-admin', PWB_PLUGIN_URL . '/assets/js/functions-admin.min.js', array('jquery'), PWB_PLUGIN_VERSION, true);
731
- wp_localize_script( 'pwb-functions-admin', 'pwb_ajax_object_admin', array(
732
- 'ajax_url' => admin_url( 'admin-ajax.php' ),
733
- 'site_url' => site_url(),
734
- 'brands_url' => admin_url( 'edit-tags.php?taxonomy=pwb-brand&post_type=product' ),
735
  'translations' => array(
736
- 'migrate_notice' => __('¿Start migration?','perfect-woocommerce-brands'),
737
- 'migrating' => __('We are migrating the product brands. ¡Don´t close this window until the process is finished!','perfect-woocommerce-brands'),
738
- 'dummy_data_notice' => __('¿Start loading dummy data?','perfect-woocommerce-brands'),
739
- 'dummy_data' => __('We are importing the dummy data. ¡Don´t close this window until the process is finished!','perfect-woocommerce-brands')
740
  )
741
- ) );
742
- wp_enqueue_script( 'pwb-functions-admin' );
743
-
744
- }
745
-
746
- public function register_brands_taxonomy(){
747
- $labels = array(
748
- 'name' => __( 'Brands', 'perfect-woocommerce-brands' ),
749
- 'singular_name' => __( 'Brand', 'perfect-woocommerce-brands' ),
750
- 'menu_name' => __( 'Brands', 'perfect-woocommerce-brands' ),
751
- 'all_items' => __( 'All Brands', 'perfect-woocommerce-brands' ),
752
- 'edit_item' => __( 'Edit Brand', 'perfect-woocommerce-brands' ),
753
- 'view_item' => __( 'View Brand', 'perfect-woocommerce-brands' ),
754
- 'update_item' => __( 'Update Brand', 'perfect-woocommerce-brands' ),
755
- 'add_new_item' => __( 'Add New Brand', 'perfect-woocommerce-brands' ),
756
- 'new_item_name' => __( 'New Brand Name', 'perfect-woocommerce-brands' ),
757
- 'parent_item' => __( 'Parent Brand', 'perfect-woocommerce-brands' ),
758
- 'parent_item_colon' => __( 'Parent Brand:', 'perfect-woocommerce-brands' ),
759
- 'search_items' => __( 'Search Brands', 'perfect-woocommerce-brands' ),
760
- 'popular_items' => __( 'Popular Brands', 'perfect-woocommerce-brands' ),
761
- 'separate_items_with_commas' => __( 'Separate brands with commas', 'perfect-woocommerce-brands' ),
762
- 'add_or_remove_items' => __( 'Add or remove brands', 'perfect-woocommerce-brands' ),
763
- 'choose_from_most_used' => __( 'Choose from the most used brands', 'perfect-woocommerce-brands' ),
764
- 'not_found' => __( 'No brands found', 'perfect-woocommerce-brands' )
765
- );
766
-
767
- $new_slug = get_option('wc_pwb_admin_tab_slug');
768
- $old_slug = get_option('old_wc_pwb_admin_tab_slug');
769
-
770
- $new_slug = ($new_slug!=false) ? $new_slug : 'brand';
771
- $old_slug = ($old_slug!=false) ? $old_slug : 'null';
772
-
773
- $args = array(
774
- 'hierarchical' => true,
775
- 'labels' => $labels,
776
- 'show_ui' => true,
777
- 'query_var' => true,
778
- 'public' => true,
779
- 'show_admin_column' => true,
780
- 'rewrite' => array(
781
- 'slug' => apply_filters( 'pwb_taxonomy_rewrite', $new_slug ),
782
- 'hierarchical'=> true,
783
- 'with_front' => apply_filters( 'pwb_taxonomy_with_front', true ),
784
- 'ep_mask' => EP_PERMALINK
785
- )
786
- );
787
-
788
- register_taxonomy( 'pwb-brand', array( 'product' ), $args );
789
 
790
- if($new_slug != false && $old_slug!= false && $new_slug != $old_slug){
791
- flush_rewrite_rules();
792
- update_option( 'old_wc_pwb_admin_tab_slug', $new_slug );
793
- }
794
 
 
 
 
 
795
  }
796
 
797
- public function add_brands_metafields(){
798
- register_meta( 'term', 'pwb_brand_image', array($this,'add_brands_metafields_sanitize') );
799
  }
800
 
801
- public function add_brands_metafields_sanitize($brand_img){
802
- return $brand_img;
803
  }
804
 
805
- public static function get_brands( $hide_empty = false, $order_by = 'name', $order = 'ASC', $only_featured = false, $pwb_term = false, $only_parents = false ){
806
- $result = array();
807
 
808
- $brands_args = array( 'hide_empty' => $hide_empty, 'orderby' => $order_by, 'order' => $order );
809
- if( $only_featured ) $brands_args['meta_query'] = array( array( 'key' => 'pwb_featured_brand', 'value' => true ) );
810
- if( $only_parents ) $brands_args['parent'] = 0;
 
 
811
 
812
- $brands = get_terms('pwb-brand', $brands_args);
813
 
814
- foreach( $brands as $key => $brand ){
815
-
816
- if( $pwb_term ){
817
- $brands[$key] = new PWB_Term( $brand );
818
- }else{
819
- $brand_image_id = get_term_meta($brand->term_id, 'pwb_brand_image', true);
820
- $brand_banner_id = get_term_meta($brand->term_id, 'pwb_brand_banner', true);
821
- $brand->brand_image = wp_get_attachment_image_src($brand_image_id);
822
- $brand->brand_banner = wp_get_attachment_image_src($brand_banner_id);
823
- }
824
 
 
 
 
 
 
 
 
825
  }
 
826
 
827
- if( is_array($brands) && count($brands)>0 ) $result = $brands;
 
828
 
829
- return $result;
830
  }
831
 
832
- public static function get_brands_array( $is_select = false ){
833
- $result = array();
834
 
835
- //if is for select input adds default value
836
- if( $is_select )
837
- $result[0] = __( 'All', 'perfect-woocommerce-brands' );
838
 
839
- $brands = get_terms('pwb-brand',array(
840
- 'hide_empty' => false
841
- ));
842
-
843
- foreach ($brands as $brand) {
844
- $result[$brand->term_id] = $brand->slug;
845
- }
846
 
847
- return $result;
 
 
848
 
 
849
  }
850
 
851
- public function print_brand_banner(){
852
- $queried_object = get_queried_object();
853
- $brand_banner = get_term_meta( $queried_object->term_id, 'pwb_brand_banner', true );
854
- $brand_banner_link = get_term_meta( $queried_object->term_id, 'pwb_brand_banner_link', true );
855
- $show_banner = get_option('wc_pwb_admin_tab_brand_banner');
856
- $show_banner = get_option('wc_pwb_admin_tab_brand_banner');
857
- $show_banner_class = ( !$show_banner || $show_banner == 'yes' ) ? 'pwb-before-loop' : 'pwb-after-loop';
858
-
859
- if( $brand_banner!='' ){
860
- echo '<div class="pwb-brand-banner pwb-clearfix '.$show_banner_class.'">';
861
- if( $brand_banner_link!='' ){
862
- echo '<a href="'.site_url($brand_banner_link).'">'.wp_get_attachment_image ( $brand_banner, 'full', false ).'</a>';
863
- }else{
864
- echo wp_get_attachment_image ( $brand_banner, 'full', false );
865
  }
866
  echo '</div>';
867
  }
868
  }
869
 
870
- public function print_brand_desc(){
871
- $queried_object = get_queried_object();
872
- $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
873
- $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
874
- $show_desc_class = ( !$show_desc || $show_desc == 'yes' ) ? 'pwb-before-loop' : 'pwb-after-loop';
875
 
876
- if( $queried_object->description != '' && $show_desc !== 'no' ){
877
- echo '<div class="pwb-brand-description '.$show_desc_class.'">';
878
- echo do_shortcode( wpautop( $queried_object->description ) );
879
  echo '</div>';
880
  }
881
  }
882
 
883
- public function print_brand_banner_and_desc(){
884
  $queried_object = get_queried_object();
885
 
886
  $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
887
- $show_desc_class = ( !$show_desc || $show_desc == 'yes' ) ? 'pwb-before-loop' : 'pwb-after-loop';
888
 
889
- $brand_banner = get_term_meta( $queried_object->term_id, 'pwb_brand_banner', true );
890
- $brand_banner_link = get_term_meta( $queried_object->term_id, 'pwb_brand_banner_link', true );
891
 
892
- if( $brand_banner!='' || $queried_object->description != '' && $show_desc !== 'no' ){
893
- echo '<div class="pwb-brand-banner-cont '.$show_desc_class.'">';
894
- $this->print_brand_banner();
895
- $this->print_brand_desc();
896
  echo '</div>';
897
  }
898
-
899
  }
900
 
901
- public static function render_template( $name, $folder = '', $data, $private = true ){
902
  //default template
903
- if( $folder ) $folder = $folder . '/';
904
- $template_file = dirname( __DIR__ ) . '/templates/' . $folder . $name . '.php';
 
905
 
906
  //theme overrides
907
- if( !$private ){
908
  $theme_template_path = get_stylesheet_directory() . '/perfect-woocommerce-brands/';
909
- if( file_exists( $theme_template_path . $folder . $name . '.php' ) )
910
  $template_file = $theme_template_path . $folder . $name . '.php';
911
  }
912
 
@@ -917,30 +883,29 @@ class Perfect_Woocommerce_Brands{
917
  return ob_get_clean();
918
  }
919
 
920
- public function product_duplicate_save( $duplicate, $product ){
921
- $product_brands = wp_get_object_terms( $product->get_id(), 'pwb-brand', array( 'fields' => 'ids' ) );
922
- wp_set_object_terms( $duplicate->get_id(), $product_brands, 'pwb-brand' );
923
  }
924
 
925
- public function breadcrumbs( $crumbs ) {
926
 
927
- if ( is_tax('pwb-brand') ) {
928
 
929
  $brands_page_id = get_option('wc_pwb_admin_tab_brands_page_id');
930
 
931
- if ( ! empty( $brands_page_id ) && $brands_page_id != '-' ) {
932
 
933
  $cur_brand = get_queried_object();
934
- $brand_ancestors = get_ancestors( $cur_brand->term_id, 'pwb-brand', 'taxonomy' );
935
-
936
- $brand_page_pos = count( $crumbs ) - ( count( $brand_ancestors ) + 2 );
937
- if ( is_paged() ) $brand_page_pos -= 1;
938
 
939
- if ( isset( $crumbs[$brand_page_pos][1] ) )
940
- $crumbs[$brand_page_pos][1] = get_page_link( $brands_page_id );
 
941
 
 
 
942
  }
943
-
944
  }
945
 
946
  return $crumbs;
@@ -950,23 +915,21 @@ class Perfect_Woocommerce_Brands{
950
  * Redirect if the search matchs with a brands name
951
  * Better search experience
952
  */
953
- public function search_by_brand_name( $query ) {
954
 
955
- if ( wp_doing_ajax() ) return;
 
956
 
957
- if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
958
 
959
- $brands = get_terms( array( 'taxonomy' => 'pwb-brand', 'fields' => 'id=>name' ) );
960
 
961
- if ( $match = array_search( strtolower( trim( $query->get('s') ) ), array_map('strtolower', $brands ) ) ) {
962
 
963
- wp_redirect( get_term_link( $match ) );
964
  exit;
965
-
966
  }
967
-
968
  }
969
-
970
  }
971
 
972
  }
1
  <?php
2
+
3
  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'));
13
+ add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
14
+ add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
15
  $this->brand_logo_position();
16
+ add_action('wp', array($this, 'brand_desc_position'));
17
+ add_action('woocommerce_after_shop_loop_item_title', array($this, 'show_brands_in_loop'));
18
  $this->add_shortcodes();
19
+ if (is_plugin_active('js_composer/js_composer.php') || is_plugin_active('visual_composer/js_composer.php')) {
20
+ add_action('vc_before_init', array($this, 'vc_map_shortcodes'));
21
  }
22
+ add_action('widgets_init', array($this, 'register_widgets'));
23
+ add_filter('woocommerce_structured_data_product', array($this, 'product_microdata'), 10, 2);
24
+ add_action('pre_get_posts', array($this, 'pwb_brand_filter'));
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
  });
32
+ add_action('woocommerce_product_duplicate', array($this, 'product_duplicate_save'), 10, 2);
33
 
34
+ add_filter('woocommerce_get_breadcrumb', array($this, 'breadcrumbs'));
35
 
36
+ add_filter('shortcode_atts_products', array($this, 'extend_products_shortcode_atts'), 10, 4);
37
+ add_filter('woocommerce_shortcode_products_query', array($this, 'extend_products_shortcode'), 10, 2);
38
 
39
+ add_filter('manage_edit-product_sortable_columns', array($this, 'brands_column_sortable'), 90);
40
+ add_action('posts_clauses', array($this, 'brands_column_sortable_posts'), 10, 2);
41
+ add_filter('post_type_link', array($this, 'brand_name_in_url'), 10, 2);
42
+ add_action('pre_get_posts', array($this, 'search_by_brand_name'));
43
 
44
  //clean caches
45
+ add_action('edited_terms', array($this, 'clean_caches'), 10, 2);
46
+ add_action('created_term', array($this, 'clean_caches_after_edit_brand'), 10, 3);
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');
60
  }
61
 
62
  /**
63
+ * Show row meta on the plugin screen.
64
+ *
65
+ * @param mixed $links Plugin Row Meta.
66
+ * @param mixed $file Plugin Base file.
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__('Developer docs', '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');
84
+ if (!empty($brands) && !is_wp_error($brands))
85
+ $term = current($brands)->slug;
86
+ $permalink = str_replace('%pwb-brand%', $term, $permalink);
87
  }
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']) {
95
 
96
  $clauses['join'] .= "
97
  LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
98
  LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
99
  LEFT OUTER JOIN {$wpdb->terms} USING (term_id)";
100
 
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;
125
 
126
+ $terms = $atts['brands'];
127
+ $terms_count = count($atts['brands']);
128
  $terms_adapted = '';
129
 
130
  $terms_i = 0;
131
+ foreach ($terms as $brand) {
132
+ $terms_adapted .= '"' . $brand . '"';
133
  $terms_i++;
134
+ if ($terms_i < $terms_count)
135
+ $terms_adapted .= ',';
136
  }
137
 
138
+ $ids = $wpdb->get_col("
139
  SELECT DISTINCT tr.object_id
140
  FROM {$wpdb->prefix}term_relationships as tr
141
  INNER JOIN {$wpdb->prefix}term_taxonomy as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
142
  INNER JOIN {$wpdb->prefix}terms as t ON tt.term_id = t.term_id
143
  WHERE tt.taxonomy LIKE 'pwb_brand' AND t.slug IN ($terms_adapted)
144
+ ");
145
 
146
+ if (!empty($ids)) {
147
+ if (1 === count($ids)) {
148
  $query_args['p'] = $ids[0];
149
  } else {
150
  $query_args['post__in'] = $ids;
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();
162
  $one_week = 604800;
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);
183
  echo 'ok';
184
+ } else {
185
  echo 'error';
186
  }
187
  wp_die();
188
  }
189
 
190
+ public function pwb_brand_filter($query) {
191
 
192
+ if (!empty($_GET['pwb-brand-filter'])) {
193
 
194
+ $terms_array = explode(',', $_GET['pwb-brand-filter']);
195
 
196
  //remove invalid terms (security)
197
+ for ($i = 0; $i < count($terms_array); $i++) {
198
+ if (!term_exists($terms_array[$i], 'pwb-brand'))
199
+ unset($terms_array[$i]);
200
  }
201
 
202
  $filterable_product = false;
203
+ if (is_product_taxonomy() || is_post_type_archive('product'))
204
  $filterable_product = true;
205
 
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
  }
 
217
  }
218
 
219
  /*
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');
227
  foreach ($brands as $brand) {
228
  $new_markup['brand'][] = $brand->name;
229
  }
230
 
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');
267
 
268
+ if ($brands_in_loop == 'brand_link' || $brands_in_loop == 'brand_image') {
269
 
270
  global $product;
271
  $product_id = $product->get_id();
272
+ $product_brands = wp_get_post_terms($product_id, 'pwb-brand');
273
+ if (!empty($product_brands)) {
274
  echo '<div class="pwb-brands-in-loop">';
275
  foreach ($product_brands as $brand) {
276
 
277
  echo '<span>';
278
+ $brand_link = get_term_link($brand->term_id, 'pwb-brand');
279
+ $attachment_id = get_term_meta($brand->term_id, 'pwb_brand_image', 1);
280
+
281
+ $attachment_html = wp_get_attachment_image($attachment_id, $image_size_selected);
282
+ if (!empty($attachment_html) && $brands_in_loop == 'brand_image') {
283
+ echo '<a href="' . $brand_link . '">' . $attachment_html . '</a>';
284
+ } else {
285
+ echo '<a href="' . $brand_link . '">' . $brand->name . '</a>';
286
+ }
287
  echo '</span>';
 
288
  }
289
  echo '</div>';
290
  }
 
291
  }
 
292
  }
293
 
294
  /**
295
+ * woocommerce_single_product_summary hook.
296
+ *
297
+ * @hooked woocommerce_template_single_title - 5
298
+ * @hooked woocommerce_template_single_rating - 10
299
+ * @hooked woocommerce_template_single_price - 10
300
+ * @hooked woocommerce_template_single_excerpt - 20
301
+ * @hooked woocommerce_template_single_add_to_cart - 30
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) {
309
+ update_option('wc_pwb_admin_tab_brand_single_position', 'after_meta');
310
  }
311
 
312
+ switch ($position_selected) {
313
  case 'before_title':
314
  $position = 4;
315
  break;
333
  break;
334
  }
335
 
336
+ if ($position_selected == 'meta') {
337
+ add_action('woocommerce_product_meta_end', [$this, 'action_woocommerce_single_product_summary']);
338
  } else {
339
+ add_action('woocommerce_single_product_summary', [$this, 'action_woocommerce_single_product_summary'], $position);
340
  }
 
341
  }
342
 
343
+ public function brand_desc_position() {
344
 
345
+ if (is_tax('pwb-brand') && !is_paged()) {
346
 
347
  $show_banner = get_option('wc_pwb_admin_tab_brand_banner');
348
+ $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
349
 
350
+ if ((!$show_banner || $show_banner == 'yes') && (!$show_desc || $show_desc == 'yes')) {
351
  //show banner and description before loop
352
+ add_action('woocommerce_archive_description', array($this, 'print_brand_banner_and_desc'), 15);
353
+ } elseif ($show_banner == 'yes_after_loop' && $show_desc == 'yes_after_loop') {
 
354
  //show banner and description after loop
355
+ add_action('woocommerce_after_main_content', array($this, 'print_brand_banner_and_desc'), 9);
356
+ } else {
 
357
  //show banner and description independently
358
 
359
+ if (!$show_banner || $show_banner == 'yes') {
360
+ add_action('woocommerce_archive_description', array($this, 'print_brand_banner'), 15);
361
+ } elseif ($show_banner == 'yes_after_loop') {
362
+ add_action('woocommerce_after_main_content', array($this, 'print_brand_banner'), 9);
363
  }
364
 
365
+ if (!$show_desc || $show_desc == 'yes') {
366
+ add_action('woocommerce_archive_description', array($this, 'print_brand_desc'), 15);
367
+ } elseif ($show_desc == 'yes_after_loop') {
368
+ add_action('woocommerce_after_main_content', array($this, 'print_brand_desc'), 9);
369
  }
 
370
  }
 
371
  }
 
372
  }
373
 
374
  /*
378
  * @link https://vc.wpbakery.com/
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
+
386
+ foreach ($available_image_sizes as $image_size) {
387
+ $available_image_sizes_adapted[$image_size] = $image_size;
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)) {
619
 
620
+ if (sizeof($brands) > 0) {
621
 
622
+ $show_as = get_option('wc_pwb_admin_tab_brands_in_single');
623
 
624
+ if ($show_as != 'no') {
625
 
626
+ do_action('pwb_before_single_product_brands', $brands);
627
 
628
+ echo '<div class="pwb-single-product-brands pwb-clearfix">';
 
 
 
 
 
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
+ }
 
 
 
636
 
637
+ foreach ($brands as $brand) {
638
+ $brand_link = get_term_link($brand->term_id, 'pwb-brand');
639
+ $attachment_id = get_term_meta($brand->term_id, 'pwb_brand_image', 1);
640
 
641
+ $image_size = 'thumbnail';
642
+ $image_size_selected = get_option('wc_pwb_admin_tab_brand_logo_size', 'thumbnail');
643
+ if ($image_size_selected != false) {
644
+ $image_size = $image_size_selected;
645
+ }
 
 
646
 
647
+ $attachment_html = wp_get_attachment_image($attachment_id, $image_size);
648
 
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>';
656
 
657
+ do_action('pwb_after_single_product_brands', $brands);
658
+ }
659
  }
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();
693
+ }
694
 
695
+ wp_enqueue_style('pwb-styles-admin', PWB_PLUGIN_URL . '/assets/css/styles-admin.min.css', array(), PWB_PLUGIN_VERSION);
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');
734
+ $old_slug = get_option('old_wc_pwb_admin_tab_slug');
735
+
736
+ $new_slug = ($new_slug != false) ? $new_slug : 'brand';
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);
 
 
 
755
 
756
+ if ($new_slug != false && $old_slug != false && $new_slug != $old_slug) {
757
+ flush_rewrite_rules();
758
+ update_option('old_wc_pwb_admin_tab_slug', $new_slug);
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);
774
+ if ($only_featured)
775
+ $brands_args['meta_query'] = array(array('key' => 'pwb_featured_brand', 'value' => true));
776
+ if ($only_parents)
777
+ $brands_args['parent'] = 0;
778
 
779
+ $brands = get_terms('pwb-brand', $brands_args);
780
 
781
+ foreach ($brands as $key => $brand) {
 
 
 
 
 
 
 
 
 
782
 
783
+ if ($pwb_term) {
784
+ $brands[$key] = new PWB_Term($brand);
785
+ } else {
786
+ $brand_image_id = get_term_meta($brand->term_id, 'pwb_brand_image', true);
787
+ $brand_banner_id = get_term_meta($brand->term_id, 'pwb_brand_banner', true);
788
+ $brand->brand_image = wp_get_attachment_image_src($brand_image_id);
789
+ $brand->brand_banner = wp_get_attachment_image_src($brand_banner_id);
790
  }
791
+ }
792
 
793
+ if (is_array($brands) && count($brands) > 0)
794
+ $result = $brands;
795
 
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) {
811
+ $result[$brand->term_id] = $brand->slug;
812
+ }
813
 
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 . '">';
827
+ if ($brand_banner_link != '') {
828
+ echo '<a href="' . site_url($brand_banner_link) . '">' . wp_get_attachment_image($brand_banner, 'full', false) . '</a>';
829
+ } else {
830
+ echo wp_get_attachment_image($brand_banner, 'full', false);
831
  }
832
  echo '</div>';
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 . '">';
844
+ echo do_shortcode(wpautop($queried_object->description));
845
  echo '</div>';
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);
857
 
858
+ if ($brand_banner != '' || $queried_object->description != '' && $show_desc !== 'no') {
859
+ echo '<div class="pwb-brand-banner-cont ' . $show_desc_class . '">';
860
+ $this->print_brand_banner();
861
+ $this->print_brand_desc();
862
  echo '</div>';
863
  }
 
864
  }
865
 
866
+ public static function render_template($name, $folder = '', $data, $private = true) {
867
  //default template
868
+ if ($folder)
869
+ $folder = $folder . '/';
870
+ $template_file = dirname(__DIR__) . '/templates/' . $folder . $name . '.php';
871
 
872
  //theme overrides
873
+ if (!$private) {
874
  $theme_template_path = get_stylesheet_directory() . '/perfect-woocommerce-brands/';
875
+ if (file_exists($theme_template_path . $folder . $name . '.php'))
876
  $template_file = $theme_template_path . $folder . $name . '.php';
877
  }
878
 
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
 
895
  $brands_page_id = get_option('wc_pwb_admin_tab_brands_page_id');
896
 
897
+ if (!empty($brands_page_id) && $brands_page_id != '-') {
898
 
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
 
906
+ if (isset($crumbs[$brand_page_pos][1]))
907
+ $crumbs[$brand_page_pos][1] = get_page_link($brands_page_id);
908
  }
 
909
  }
910
 
911
  return $crumbs;
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;
922
 
923
+ if (!is_admin() && $query->is_main_query() && $query->is_search()) {
924
 
925
+ $brands = get_terms(array('taxonomy' => 'pwb-brand', 'fields' => 'id=>name'));
926
 
927
+ if ($match = array_search(strtolower(trim($query->get('s'))), array_map('strtolower', $brands))) {
928
 
929
+ wp_redirect(get_term_link($match));
930
  exit;
 
931
  }
 
932
  }
 
933
  }
934
 
935
  }
perfect-woocommerce-brands.php CHANGED
@@ -4,13 +4,13 @@
4
  * Plugin Name: Perfect WooCommerce Brands
5
  * Plugin URI: https://wordpress.org/plugins/perfect-woocommerce-brands/
6
  * Description: Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store.
7
- * Version: 1.8.0
8
  * Author: QuadLayers
9
  * Author URI: https://quadlayers.com
10
  * Text Domain: perfect-woocommerce-brands
11
  * Domain Path: /lang
12
  * License: GPL3
13
- * Perfect WooCommerce Brands version 1.8.0, 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
@@ -35,13 +35,14 @@ defined('ABSPATH') or die('No script kiddies please!');
35
  define('PWB_PLUGIN_URL', plugins_url('', __FILE__));
36
  define('PWB_PLUGIN_DIR', __DIR__ . DIRECTORY_SEPARATOR);
37
  define('PWB_PLUGIN_BASENAME', plugin_basename(__FILE__));
38
- define('PWB_PLUGIN_VERSION', '1.8.0');
39
  define('PWB_PLUGIN_NAME', 'Perfect WooCommerce Brands');
40
  define('PWB_REVIEW_URL', 'https://wordpress.org/support/plugin/perfect-woocommerce-brands/reviews/?filter=5#new-post');
41
  define('PWB_DEMO_URL', 'https://quadlayers.com/portfolio/perfect-woocommerce-brands/?utm_source=pwb_admin');
42
  define('PWB_PURCHASE_URL', PWB_DEMO_URL);
43
  define('PWB_SUPPORT_URL', 'https://quadlayers.com/account/support/?utm_source=pwb_admin');
44
- define('PWB_DOCUMENTATION_URL', 'https://github.com/titodevera/perfect-woocommerce-brands/wiki');
 
45
  define('PWB_GROUP_URL', 'https://www.facebook.com/groups/quadlayers');
46
 
47
  register_activation_hook(__FILE__, function() {
4
  * Plugin Name: Perfect WooCommerce Brands
5
  * Plugin URI: https://wordpress.org/plugins/perfect-woocommerce-brands/
6
  * Description: Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store.
7
+ * Version: 1.8.1
8
  * Author: QuadLayers
9
  * Author URI: https://quadlayers.com
10
  * Text Domain: perfect-woocommerce-brands
11
  * Domain Path: /lang
12
  * License: GPL3
13
+ * Perfect WooCommerce Brands version 1.8.1, 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
35
  define('PWB_PLUGIN_URL', plugins_url('', __FILE__));
36
  define('PWB_PLUGIN_DIR', __DIR__ . DIRECTORY_SEPARATOR);
37
  define('PWB_PLUGIN_BASENAME', plugin_basename(__FILE__));
38
+ define('PWB_PLUGIN_VERSION', '1.8.1');
39
  define('PWB_PLUGIN_NAME', 'Perfect WooCommerce Brands');
40
  define('PWB_REVIEW_URL', 'https://wordpress.org/support/plugin/perfect-woocommerce-brands/reviews/?filter=5#new-post');
41
  define('PWB_DEMO_URL', 'https://quadlayers.com/portfolio/perfect-woocommerce-brands/?utm_source=pwb_admin');
42
  define('PWB_PURCHASE_URL', PWB_DEMO_URL);
43
  define('PWB_SUPPORT_URL', 'https://quadlayers.com/account/support/?utm_source=pwb_admin');
44
+ define('PWB_DOCUMENTATION_URL', 'https://quadlayers.com/documentation/perfect-woocommerce-brands/?utm_source=pwb_admin');
45
+ define('PWB_GITHUB_URL', 'https://github.com/quadlayers/perfect-woocommerce-brands/');
46
  define('PWB_GROUP_URL', 'https://www.facebook.com/groups/quadlayers');
47
 
48
  register_activation_hook(__FILE__, function() {
readme.txt CHANGED
@@ -1,11 +1,11 @@
1
- === Perfect WooCommerce Brands ===
2
  Contributors: titodevera
3
  Donate link: https://quadlayers.com
4
  Tags: woocommerce, woocommerce brands, woocommerce product, woocommerce manufacturer, woocommerce supplier, e-commerce
5
  Requires at least: 4.7
6
- Tested up to: 5.3.2
7
  Requires PHP: 5.6
8
- Stable tag: 1.8.0
9
  License: GPL3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.en.html
11
 
@@ -13,7 +13,11 @@ Perfect WooCommerce Brands allows you to show product brands in your WooCommerce
13
 
14
  == Description ==
15
 
16
- [About Us](https://quadlayers.com/) | [Community](https://www.facebook.com/groups/quadlayers/)
 
 
 
 
17
 
18
  Whether we like to admit it or not, we are all influenced by brands. Brands are a guarantee for quality, they assure product recognition in customers.
19
  Is essential to work with product brands for increase sales and generate reliability on your e-commerce site.
@@ -73,7 +77,7 @@ Yes you can! Join in on our [GitHub repository](https://github.com/quadlayers/pe
73
  You can also contribute [translating the plugin](https://translate.wordpress.org/projects/wp-plugins/perfect-woocommerce-brands/)
74
 
75
  = Developer Documentation =
76
- [Click here](https://github.com/titodevera/perfect-woocommerce-brands/wiki)
77
 
78
  == Screenshots ==
79
  1. Brands carousel
@@ -84,6 +88,8 @@ You can also contribute [translating the plugin](https://translate.wordpress.org
84
 
85
 
86
  == Changelog ==
 
 
87
  = 1.8.0 =
88
  * Enhancement: Main file renamed according to WordPress standards
89
  * Enhancement: "Show only first level brands" option added for the filter by brand widget
1
+ === Perfect WooCommerce Brands ===
2
  Contributors: titodevera
3
  Donate link: https://quadlayers.com
4
  Tags: woocommerce, woocommerce brands, woocommerce product, woocommerce manufacturer, woocommerce supplier, e-commerce
5
  Requires at least: 4.7
6
+ Tested up to: 5.4.0
7
  Requires PHP: 5.6
8
+ Stable tag: 1.8.1
9
  License: GPL3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.en.html
11
 
13
 
14
  == Description ==
15
 
16
+ Perfect WooCommerce Brands is a perfect tool to organize your site, highlight the brands you have, and also helps as a filter for your customers at UX exploration. PWB extendes the product's description and presentation at your e-commerce site.
17
+
18
+ == PRESENTATION ==
19
+
20
+ [About Us](https://quadlayers.com/) | [Community](https://www.facebook.com/groups/quadlayers/) | [Documentation](https://quadlayers.com/documentation/perfect-woocommerce-brands/)
21
 
22
  Whether we like to admit it or not, we are all influenced by brands. Brands are a guarantee for quality, they assure product recognition in customers.
23
  Is essential to work with product brands for increase sales and generate reliability on your e-commerce site.
77
  You can also contribute [translating the plugin](https://translate.wordpress.org/projects/wp-plugins/perfect-woocommerce-brands/)
78
 
79
  = Developer Documentation =
80
+ [Click here](https://github.com/quadlayers/perfect-woocommerce-brands/wiki)
81
 
82
  == Screenshots ==
83
  1. Brands carousel
88
 
89
 
90
  == Changelog ==
91
+ = 1.8.1 =
92
+ * Enhancement: Update documentation link
93
  = 1.8.0 =
94
  * Enhancement: Main file renamed according to WordPress standards
95
  * Enhancement: "Show only first level brands" option added for the filter by brand widget