Perfect Brands for WooCommerce - Version 2.0.6

Version Description

  • Fix: Output sanitization
Download this release

Release Info

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

Code changes from version 2.0.5 to 2.0.6

Files changed (44) hide show
  1. classes/admin/class-brands-custom-fields.php +173 -177
  2. classes/admin/class-brands-exporter.php +145 -142
  3. classes/admin/class-edit-brands-page.php +185 -167
  4. classes/admin/class-pwb-admin-tab.php +307 -301
  5. classes/admin/class-pwb-coupon.php +76 -59
  6. classes/admin/class-pwb-dummy-data.php +99 -103
  7. classes/admin/class-pwb-exporter-support.php +32 -30
  8. classes/admin/class-pwb-importer-support.php +49 -47
  9. classes/admin/class-pwb-migrate.php +119 -126
  10. classes/admin/class-pwb-notices.php +82 -77
  11. classes/admin/class-pwb-suggestions.php +114 -117
  12. classes/admin/class-pwb-system-status.php +62 -64
  13. classes/class-perfect-woocommerce-brands.php +1033 -998
  14. classes/class-pwb-api-support.php +168 -152
  15. classes/class-pwb-product-tab.php +58 -67
  16. classes/class-pwb-suggestions-list-table.php +140 -0
  17. classes/class-pwb-suggestions-list.php +0 -154
  18. classes/class-pwb-term.php +33 -33
  19. classes/shortcodes/class-pwb-all-brands.php +165 -172
  20. classes/shortcodes/class-pwb-az-listing.php +58 -53
  21. classes/shortcodes/class-pwb-brand.php +38 -28
  22. classes/shortcodes/class-pwb-carousel.php +90 -69
  23. classes/shortcodes/class-pwb-product-carousel.php +102 -98
  24. classes/widgets/class-pwb-dropdown-widget.php +109 -0
  25. classes/widgets/class-pwb-dropdown.php +0 -93
  26. classes/widgets/class-pwb-filter-by-brand-widget.php +250 -0
  27. classes/widgets/class-pwb-filter-by-brand.php +0 -242
  28. classes/widgets/class-pwb-list-widget.php +156 -0
  29. classes/widgets/class-pwb-list.php +0 -129
  30. includes/quadlayers/widget.php +125 -127
  31. main.php +8 -8
  32. perfect-woocommerce-brands.php +93 -78
  33. readme.txt +3 -1
  34. templates/admin/brands-exporter.php +6 -5
  35. templates/admin/edit-brands-bottom.php +7 -8
  36. templates/shortcodes/az-listing.php +29 -45
  37. templates/shortcodes/brand.php +15 -14
  38. templates/shortcodes/carousel.php +12 -14
  39. templates/shortcodes/product-carousel.php +17 -23
  40. templates/widgets/dropdown.php +11 -10
  41. templates/widgets/filter-by-brand.php +24 -18
  42. templates/widgets/list-logo.php +12 -19
  43. templates/widgets/list.php +10 -13
  44. uninstall.php +15 -15
classes/admin/class-brands-custom-fields.php CHANGED
@@ -2,181 +2,177 @@
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
-
7
- class Brands_Custom_Fields
8
- {
9
-
10
- function __construct()
11
- {
12
- add_action('pwb-brand_add_form_fields', array($this, 'add_brands_metafields_form'));
13
- add_action('pwb-brand_edit_form_fields', array($this, 'add_brands_metafields_form_edit'));
14
- add_action('edit_pwb-brand', array($this, 'add_brands_metafields_save'));
15
- add_action('create_pwb-brand', array($this, 'add_brands_metafields_save'));
16
- }
17
-
18
- public function add_brands_metafields_form()
19
- {
20
- ob_start();
21
- ?>
22
-
23
- <div class="form-field pwb_brand_cont">
24
- <label for="pwb_brand_desc"><?php _e('Description'); ?></label>
25
- <textarea id="pwb_brand_description_field" name="pwb_brand_description_field" rows="5" cols="40"></textarea>
26
- <p id="brand-description-help-text"><?php _e('Brand description for the archive pages. You can include some html markup and shortcodes.', 'perfect-woocommerce-brands'); ?></p>
27
- </div>
28
-
29
- <div class="form-field pwb_brand_cont">
30
- <label for="pwb_brand_image"><?php _e('Brand logo', 'perfect-woocommerce-brands'); ?></label>
31
- <input type="text" name="pwb_brand_image" id="pwb_brand_image" value="">
32
- <a href="#" id="pwb_brand_image_select" class="button"><?php esc_html_e('Select image', 'perfect-woocommerce-brands'); ?></a>
33
- </div>
34
-
35
- <div class="form-field pwb_brand_cont">
36
- <label for="pwb_brand_banner"><?php _e('Brand banner', 'perfect-woocommerce-brands'); ?></label>
37
- <input type="text" name="pwb_brand_banner" id="pwb_brand_banner" value="">
38
- <a href="#" id="pwb_brand_banner_select" class="button"><?php esc_html_e('Select image', 'perfect-woocommerce-brands'); ?></a>
39
- <p><?php _e('This image will be shown on brand page', 'perfect-woocommerce-brands'); ?></p>
40
- </div>
41
-
42
- <div class="form-field pwb_brand_cont">
43
- <label for="pwb_brand_banner_link"><?php _e('Brand banner link', 'perfect-woocommerce-brands'); ?></label>
44
- <input type="text" name="pwb_brand_banner_link" id="pwb_brand_banner_link" value="">
45
- <p><?php _e('This link should be relative to site url. Example: product/product-name', 'perfect-woocommerce-brands'); ?></p>
46
- </div>
47
-
48
- <?php wp_nonce_field(basename(__FILE__), 'pwb_nonce'); ?>
49
-
50
- <?php
51
- echo ob_get_clean();
52
- }
53
-
54
- public function add_brands_metafields_form_edit($term)
55
- {
56
- $term_value_image = get_term_meta($term->term_id, 'pwb_brand_image', true);
57
- $term_value_banner = get_term_meta($term->term_id, 'pwb_brand_banner', true);
58
- $term_value_banner_link = get_term_meta($term->term_id, 'pwb_brand_banner_link', true);
59
- ob_start();
60
- $image_size_selected = get_option('wc_pwb_admin_tab_brand_logo_size', 'thumbnail');
61
-
62
- ?>
63
- <table class="form-table pwb_brand_cont">
64
- <tr class="form-field">
65
- <th>
66
- <label for="pwb_brand_desc"><?php _e('Description'); ?></label>
67
- </th>
68
- <td>
69
- <?php wp_editor(html_entity_decode($term->description), 'pwb_brand_description_field', array('editor_height' => 120)); ?>
70
- <p id="brand-description-help-text"><?php _e('Brand description for the archive pages. You can include some html markup and shortcodes.', 'perfect-woocommerce-brands'); ?></p>
71
- </td>
72
- </tr>
73
- <tr class="form-field">
74
- <th>
75
- <label for="pwb_brand_image"><?php _e('Brand logo', 'perfect-woocommerce-brands'); ?></label>
76
- </th>
77
- <td>
78
- <input type="text" name="pwb_brand_image" id="pwb_brand_image" value="<?php echo esc_attr($term_value_image); ?>">
79
- <a href="#" id="pwb_brand_image_select" class="button"><?php esc_html_e('Select image', 'perfect-woocommerce-brands'); ?></a>
80
-
81
- <?php $current_image = wp_get_attachment_image($term_value_image, $image_size_selected, false); ?>
82
- <?php if (!empty($current_image)) : ?>
83
- <div class="pwb_brand_image_selected">
84
- <span>
85
- <?php echo wp_kses_post($current_image); ?>
86
- <a href="#" class="pwb_brand_image_selected_remove">X</a>
87
- </span>
88
- </div>
89
- <?php endif; ?>
90
-
91
- </td>
92
- </tr>
93
- <tr class="form-field">
94
- <th>
95
- <label for="pwb_brand_banner"><?php _e('Brand banner', 'perfect-woocommerce-brands'); ?></label>
96
- </th>
97
- <td>
98
- <input type="text" name="pwb_brand_banner" id="pwb_brand_banner" value="<?php echo esc_html($term_value_banner); ?>">
99
- <a href="#" id="pwb_brand_banner_select" class="button"><?php esc_html_e('Select image', 'perfect-woocommerce-brands'); ?></a>
100
-
101
- <?php $current_image = wp_get_attachment_image($term_value_banner, 'full', false); ?>
102
- <?php if (!empty($current_image)) : ?>
103
- <div class="pwb_brand_image_selected">
104
- <span>
105
- <?php echo wp_kses_post($current_image); ?>
106
- <a href="#" class="pwb_brand_image_selected_remove">X</a>
107
- </span>
108
- </div>
109
- <?php endif; ?>
110
-
111
- </td>
112
- </tr>
113
- <tr class="form-field">
114
- <th>
115
- <label for="pwb_brand_banner_link"><?php _e('Brand banner link', 'perfect-woocommerce-brands'); ?></label>
116
- </th>
117
- <td>
118
- <input type="text" name="pwb_brand_banner_link" id="pwb_brand_banner_link" value="<?php echo esc_html($term_value_banner_link); ?>">
119
- <p class="description"><?php _e('This link should be relative to site url. Example: product/product-name', 'perfect-woocommerce-brands'); ?></p>
120
- <div id="pwb_brand_banner_link_result"><?php echo wp_get_attachment_image($term_value_banner_link, array('90', '90'), false); ?></div>
121
- </td>
122
- </tr>
123
- </table>
124
-
125
- <?php wp_nonce_field(basename(__FILE__), 'pwb_nonce'); ?>
126
-
127
- <?php
128
- echo ob_get_clean();
129
- }
130
-
131
- public function add_brands_metafields_save($term_id)
132
- {
133
-
134
- if (!isset($_POST['pwb_nonce']) || !wp_verify_nonce($_POST['pwb_nonce'], basename(__FILE__)))
135
- return;
136
-
137
- /* ·············· Brand image ·············· */
138
- $old_img = get_term_meta($term_id, 'pwb_brand_image', true);
139
- $new_img = isset($_POST['pwb_brand_image']) ? sanitize_text_field($_POST['pwb_brand_image']) : '';
140
-
141
- if ($old_img && '' === $new_img)
142
- delete_term_meta($term_id, 'pwb_brand_image');
143
-
144
- else if ($old_img !== $new_img)
145
- update_term_meta($term_id, 'pwb_brand_image', $new_img);
146
- /* ·············· /Brand image ·············· */
147
-
148
- /* ·············· Brand banner ·············· */
149
- $old_img = get_term_meta($term_id, 'pwb_brand_banner', true);
150
- $new_img = isset($_POST['pwb_brand_banner']) ? sanitize_text_field($_POST['pwb_brand_banner']) : '';
151
-
152
- if ($old_img && '' === $new_img)
153
- delete_term_meta($term_id, 'pwb_brand_banner');
154
-
155
- else if ($old_img !== $new_img)
156
- update_term_meta($term_id, 'pwb_brand_banner', $new_img);
157
- /* ·············· /Brand banner ·············· */
158
-
159
- /* ·············· Brand banner link ·············· */
160
- $old_img = get_term_meta($term_id, 'pwb_brand_banner_link', true);
161
- $new_img = isset($_POST['pwb_brand_banner_link']) ? esc_url_raw($_POST['pwb_brand_banner_link']) : '';
162
-
163
- if ($old_img && '' === $new_img)
164
- delete_term_meta($term_id, 'pwb_brand_banner_link');
165
-
166
- else if ($old_img !== $new_img)
167
- update_term_meta($term_id, 'pwb_brand_banner_link', $new_img);
168
- /* ·············· /Brand banner link ·············· */
169
-
170
- /* ·············· Brand desc ·············· */
171
- if (isset($_POST['pwb_brand_description_field'])) {
172
- $allowed_tags = apply_filters(
173
- 'pwb_description_allowed_tags',
174
- '<p><span><a><ul><ol><li><h1><h2><h3><h4><h5><h6><pre><strong><em><blockquote><del><ins><img><code><hr>'
175
- );
176
- $desc = strip_tags(wp_unslash($_POST['pwb_brand_description_field']), $allowed_tags);
177
- global $wpdb;
178
- $wpdb->update($wpdb->term_taxonomy, ['description' => $desc], ['term_id' => $term_id]);
179
- }
180
- /* ·············· /Brand desc ·············· */
181
- }
182
  }
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class Brands_Custom_Fields {
8
+
9
+ function __construct() {
10
+ add_action( 'pwb-brand_add_form_fields', array( $this, 'add_brands_metafields_form' ) );
11
+ add_action( 'pwb-brand_edit_form_fields', array( $this, 'add_brands_metafields_form_edit' ) );
12
+ add_action( 'edit_pwb-brand', array( $this, 'add_brands_metafields_save' ) );
13
+ add_action( 'create_pwb-brand', array( $this, 'add_brands_metafields_save' ) );
14
+ }
15
+
16
+ public function add_brands_metafields_form() {
17
+ ob_start();
18
+ ?>
19
+
20
+ <div class="form-field pwb_brand_cont">
21
+ <label for="pwb_brand_desc"><?php esc_html_e( 'Description', 'perfect-woocommerce-brands' ); ?></label>
22
+ <textarea id="pwb_brand_description_field" name="pwb_brand_description_field" rows="5" cols="40"></textarea>
23
+ <p id="brand-description-help-text"><?php esc_html_e( 'Brand description for the archive pages. You can include some html markup and shortcodes.', 'perfect-woocommerce-brands' ); ?></p>
24
+ </div>
25
+
26
+ <div class="form-field pwb_brand_cont">
27
+ <label for="pwb_brand_image"><?php esc_html_e( 'Brand logo', 'perfect-woocommerce-brands' ); ?></label>
28
+ <input type="text" name="pwb_brand_image" id="pwb_brand_image" value="">
29
+ <a href="#" id="pwb_brand_image_select" class="button"><?php esc_html_e( 'Select image', 'perfect-woocommerce-brands' ); ?></a>
30
+ </div>
31
+
32
+ <div class="form-field pwb_brand_cont">
33
+ <label for="pwb_brand_banner"><?php esc_html_e( 'Brand banner', 'perfect-woocommerce-brands' ); ?></label>
34
+ <input type="text" name="pwb_brand_banner" id="pwb_brand_banner" value="">
35
+ <a href="#" id="pwb_brand_banner_select" class="button"><?php esc_html_e( 'Select image', 'perfect-woocommerce-brands' ); ?></a>
36
+ <p><?php esc_html_e( 'This image will be shown on brand page', 'perfect-woocommerce-brands' ); ?></p>
37
+ </div>
38
+
39
+ <div class="form-field pwb_brand_cont">
40
+ <label for="pwb_brand_banner_link"><?php esc_html_e( 'Brand banner link', 'perfect-woocommerce-brands' ); ?></label>
41
+ <input type="text" name="pwb_brand_banner_link" id="pwb_brand_banner_link" value="">
42
+ <p><?php esc_html_e( 'This link should be relative to site url. Example: product/product-name', 'perfect-woocommerce-brands' ); ?></p>
43
+ </div>
44
+
45
+ <?php wp_nonce_field( basename( __FILE__ ), 'pwb_nonce' ); ?>
46
+
47
+ <?php
48
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
49
+ echo ob_get_clean();
50
+ }
51
+
52
+ public function add_brands_metafields_form_edit( $term ) {
53
+ $term_value_image = get_term_meta( $term->term_id, 'pwb_brand_image', true );
54
+ $term_value_banner = get_term_meta( $term->term_id, 'pwb_brand_banner', true );
55
+ $term_value_banner_link = get_term_meta( $term->term_id, 'pwb_brand_banner_link', true );
56
+ ob_start();
57
+ $image_size_selected = get_option( 'wc_pwb_admin_tab_brand_logo_size', 'thumbnail' );
58
+
59
+ ?>
60
+ <table class="form-table pwb_brand_cont">
61
+ <tr class="form-field">
62
+ <th>
63
+ <label for="pwb_brand_desc"><?php esc_html_e( 'Description' ); ?></label>
64
+ </th>
65
+ <td>
66
+ <?php wp_editor( html_entity_decode( $term->description ), 'pwb_brand_description_field', array( 'editor_height' => 120 ) ); ?>
67
+ <p id="brand-description-help-text"><?php esc_html_e( 'Brand description for the archive pages. You can include some html markup and shortcodes.', 'perfect-woocommerce-brands' ); ?></p>
68
+ </td>
69
+ </tr>
70
+ <tr class="form-field">
71
+ <th>
72
+ <label for="pwb_brand_image"><?php esc_html_e( 'Brand logo', 'perfect-woocommerce-brands' ); ?></label>
73
+ </th>
74
+ <td>
75
+ <input type="text" name="pwb_brand_image" id="pwb_brand_image" value="<?php echo esc_attr( $term_value_image ); ?>">
76
+ <a href="#" id="pwb_brand_image_select" class="button"><?php esc_html_e( 'Select image', 'perfect-woocommerce-brands' ); ?></a>
77
+
78
+ <?php $current_image = wp_get_attachment_image( $term_value_image, $image_size_selected, false ); ?>
79
+ <?php if ( ! empty( $current_image ) ) : ?>
80
+ <div class="pwb_brand_image_selected">
81
+ <span>
82
+ <?php echo wp_kses_post( $current_image ); ?>
83
+ <a href="#" class="pwb_brand_image_selected_remove">X</a>
84
+ </span>
85
+ </div>
86
+ <?php endif; ?>
87
+
88
+ </td>
89
+ </tr>
90
+ <tr class="form-field">
91
+ <th>
92
+ <label for="pwb_brand_banner"><?php esc_html_e( 'Brand banner', 'perfect-woocommerce-brands' ); ?></label>
93
+ </th>
94
+ <td>
95
+ <input type="text" name="pwb_brand_banner" id="pwb_brand_banner" value="<?php echo esc_html( $term_value_banner ); ?>">
96
+ <a href="#" id="pwb_brand_banner_select" class="button"><?php esc_html_e( 'Select image', 'perfect-woocommerce-brands' ); ?></a>
97
+
98
+ <?php $current_image = wp_get_attachment_image( $term_value_banner, 'full', false ); ?>
99
+ <?php if ( ! empty( $current_image ) ) : ?>
100
+ <div class="pwb_brand_image_selected">
101
+ <span>
102
+ <?php echo wp_kses_post( $current_image ); ?>
103
+ <a href="#" class="pwb_brand_image_selected_remove">X</a>
104
+ </span>
105
+ </div>
106
+ <?php endif; ?>
107
+
108
+ </td>
109
+ </tr>
110
+ <tr class="form-field">
111
+ <th>
112
+ <label for="pwb_brand_banner_link"><?php esc_html_e( 'Brand banner link', 'perfect-woocommerce-brands' ); ?></label>
113
+ </th>
114
+ <td>
115
+ <input type="text" name="pwb_brand_banner_link" id="pwb_brand_banner_link" value="<?php echo esc_html( $term_value_banner_link ); ?>">
116
+ <p class="description"><?php esc_html_e( 'This link should be relative to site url. Example: product/product-name', 'perfect-woocommerce-brands' ); ?></p>
117
+ <div id="pwb_brand_banner_link_result"><?php echo wp_get_attachment_image( $term_value_banner_link, array( '90', '90' ), false ); ?></div>
118
+ </td>
119
+ </tr>
120
+ </table>
121
+
122
+ <?php wp_nonce_field( basename( __FILE__ ), 'pwb_nonce' ); ?>
123
+
124
+ <?php
125
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
126
+ echo ob_get_clean();
127
+ }
128
+
129
+ public function add_brands_metafields_save( $term_id ) {
130
+ if ( ! isset( $_POST['pwb_nonce'] ) || ! wp_verify_nonce( $_POST['pwb_nonce'], basename( __FILE__ ) ) ) {
131
+ return;
132
+ }
133
+
134
+ /* ·············· Brand image ·············· */
135
+ $old_img = get_term_meta( $term_id, 'pwb_brand_image', true );
136
+ $new_img = isset( $_POST['pwb_brand_image'] ) ? sanitize_text_field( $_POST['pwb_brand_image'] ) : '';
137
+
138
+ if ( $old_img && '' === $new_img ) {
139
+ delete_term_meta( $term_id, 'pwb_brand_image' );
140
+
141
+ } elseif ( $old_img !== $new_img ) {
142
+ update_term_meta( $term_id, 'pwb_brand_image', $new_img );
143
+ }
144
+ /* ·············· /Brand image ·············· */
145
+
146
+ /* ·············· Brand banner ·············· */
147
+ $old_img = get_term_meta( $term_id, 'pwb_brand_banner', true );
148
+ $new_img = isset( $_POST['pwb_brand_banner'] ) ? sanitize_text_field( wp_unslash( $_POST['pwb_brand_banner'] ) ) : '';
149
+
150
+ if ( $old_img && '' === $new_img ) {
151
+ delete_term_meta( $term_id, 'pwb_brand_banner' );
152
+
153
+ } elseif ( $old_img !== $new_img ) {
154
+ update_term_meta( $term_id, 'pwb_brand_banner', $new_img );
155
+ }
156
+ /* ·············· /Brand banner ·············· */
157
+
158
+ /* ·············· Brand banner link ·············· */
159
+ $old_img = get_term_meta( $term_id, 'pwb_brand_banner_link', true );
160
+ $new_img = isset( $_POST['pwb_brand_banner_link'] ) ? esc_url_raw( wp_unslash( $_POST['pwb_brand_banner_link'] ) ) : '';
161
+
162
+ if ( $old_img && '' === $new_img ) {
163
+ delete_term_meta( $term_id, 'pwb_brand_banner_link' );
164
+
165
+ } elseif ( $old_img !== $new_img ) {
166
+ update_term_meta( $term_id, 'pwb_brand_banner_link', $new_img );
167
+ }
168
+ /* ·············· /Brand banner link ·············· */
169
+
170
+ /* ·············· Brand desc ·············· */
171
+ if ( isset( $_POST['pwb_brand_description_field'] ) ) {
172
+ $desc = wp_kses_post( wp_unslash( $_POST['pwb_brand_description_field'] ) );
173
+ global $wpdb;
174
+ $wpdb->update( $wpdb->term_taxonomy, array( 'description' => $desc ), array( 'term_id' => $term_id ) );
175
+ }
176
+ /* ·············· /Brand desc ·············· */
177
+ }
 
 
 
 
178
  }
classes/admin/class-brands-exporter.php CHANGED
@@ -2,146 +2,149 @@
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
-
7
- class Brands_Exporter
8
- {
9
-
10
- function __construct()
11
- {
12
- add_action('after-pwb-brand-table', array($this, 'exporter_button'));
13
- add_action('wp_ajax_pwb_brands_export', array($this, 'brands_export'));
14
- add_action('wp_ajax_pwb_brands_import', array($this, 'brands_import'));
15
- }
16
-
17
- public function exporter_button()
18
- {
19
- echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
20
- 'brands-exporter',
21
- 'admin',
22
- array('ok' => 'va')
23
- );
24
- }
25
-
26
- public function brands_export()
27
- {
28
- if (
29
- isset($_REQUEST['nonce'])
30
- &&
31
- wp_verify_nonce($_REQUEST['nonce'], 'pwb_brands_export')
32
- &&
33
- current_user_can('manage_options')
34
- ) {
35
- $this->get_brands();
36
- } else {
37
- wp_send_json_error();
38
- }
39
- wp_die();
40
- }
41
-
42
- private function get_brands()
43
- {
44
-
45
- $brands_data = array();
46
-
47
- $brands = get_terms('pwb-brand', array('hide_empty' => false));
48
- foreach ($brands as $brand) {
49
-
50
- $current_brand = array(
51
- 'slug' => $brand->slug,
52
- 'name' => $brand->name,
53
- 'banner_link' => get_term_meta($brand->term_id, 'pwb_brand_banner_link', true),
54
- 'desc' => htmlentities($brand->description)
55
- );
56
-
57
- $image = get_term_meta($brand->term_id, 'pwb_brand_image', true);
58
- $image = wp_get_attachment_image_src($image, 'full');
59
- if ($image) $current_brand['image'] = $image[0];
60
-
61
- $banner = get_term_meta($brand->term_id, 'pwb_brand_banner', true);
62
- $banner = wp_get_attachment_image_src($banner, 'full');
63
- if ($banner) $current_brand['banner'] = $banner[0];
64
-
65
- $brands_data[] = $current_brand;
66
- }
67
-
68
- $export_file = fopen(WP_CONTENT_DIR . '/uploads/pwb-export.json', 'w');
69
- fwrite($export_file, json_encode($brands_data));
70
- fclose($export_file);
71
-
72
- $result = array('export_file_url' => WP_CONTENT_URL . '/uploads/pwb-export.json');
73
-
74
- wp_send_json_success($result);
75
- }
76
-
77
- public function brands_import()
78
- {
79
-
80
- if (
81
- isset($_FILES['file'])
82
- &&
83
- isset($_REQUEST['nonce'])
84
- &&
85
- wp_verify_nonce($_REQUEST['nonce'], 'pwb_brands_import')
86
- &&
87
- current_user_can('manage_options')
88
- ) {
89
-
90
- $file = $_FILES['file'];
91
-
92
- $file_content = json_decode(file_get_contents($file['tmp_name']), true);
93
-
94
- if (is_array($file_content)) {
95
-
96
- foreach ($file_content as $brand) {
97
-
98
- $new_brand = wp_insert_term($brand['name'], 'pwb-brand', array(
99
- 'slug' => $brand['slug'],
100
- 'description' => html_entity_decode($brand['desc'])
101
- ));
102
-
103
- if (!is_wp_error($new_brand)) {
104
-
105
- if (!empty($brand['image']))
106
- $this->upload_remote_image_and_attach($brand['image'], $new_brand['term_id'], 'pwb_brand_image');
107
- if (!empty($brand['banner']))
108
- $this->upload_remote_image_and_attach($brand['banner'], $new_brand['term_id'], 'pwb_brand_banner');
109
- if (!empty($brand['banner_link']))
110
- update_term_meta($new_brand['term_id'], 'pwb_brand_banner_link', $brand['banner_link'], true);
111
- }
112
- }
113
-
114
- wp_send_json_success();
115
- } else {
116
- wp_send_json_error();
117
- }
118
- } else {
119
- wp_send_json_error();
120
- }
121
-
122
- wp_die();
123
- }
124
-
125
- private function upload_remote_image_and_attach($image_url, $term_id, $meta_key)
126
- {
127
-
128
- $get = wp_remote_get($image_url);
129
- $type = wp_remote_retrieve_header($get, 'content-type');
130
-
131
- if (!$type) return false;
132
-
133
- $mirror = wp_upload_bits(basename($image_url), '', wp_remote_retrieve_body($get));
134
-
135
- $attachment = array(
136
- 'post_title' => basename($image_url),
137
- 'post_mime_type' => $type
138
- );
139
-
140
- $attach_id = wp_insert_attachment($attachment, $mirror['file']);
141
- require_once ABSPATH . 'wp-admin/includes/image.php';
142
- $attach_data = wp_generate_attachment_metadata($attach_id, $mirror['file']);
143
- wp_update_attachment_metadata($attach_id, $attach_data);
144
-
145
- update_term_meta($term_id, $meta_key, $attach_id, true);
146
- }
 
 
 
147
  }
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class Brands_Exporter {
8
+
9
+ function __construct() {
10
+ add_action( 'after-pwb-brand-table', array( $this, 'exporter_button' ) );
11
+ add_action( 'wp_ajax_pwb_brands_export', array( $this, 'brands_export' ) );
12
+ add_action( 'wp_ajax_pwb_brands_import', array( $this, 'brands_import' ) );
13
+ }
14
+
15
+ public function exporter_button() {
16
+ echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
17
+ 'brands-exporter',
18
+ 'admin',
19
+ array( 'ok' => 'va' )
20
+ );
21
+ }
22
+
23
+ public function brands_export() {
24
+ if (
25
+ isset( $_REQUEST['nonce'] )
26
+ &&
27
+ wp_verify_nonce( $_REQUEST['nonce'], 'pwb_brands_export' )
28
+ &&
29
+ current_user_can( 'manage_options' )
30
+ ) {
31
+ $this->get_brands();
32
+ } else {
33
+ wp_send_json_error();
34
+ }
35
+ wp_die();
36
+ }
37
+
38
+ private function get_brands() {
39
+ $brands_data = array();
40
+
41
+ $brands = get_terms( 'pwb-brand', array( 'hide_empty' => false ) );
42
+ foreach ( $brands as $brand ) {
43
+
44
+ $current_brand = array(
45
+ 'slug' => $brand->slug,
46
+ 'name' => $brand->name,
47
+ 'banner_link' => get_term_meta( $brand->term_id, 'pwb_brand_banner_link', true ),
48
+ 'desc' => htmlentities( $brand->description ),
49
+ );
50
+
51
+ $image = get_term_meta( $brand->term_id, 'pwb_brand_image', true );
52
+ $image = wp_get_attachment_image_src( $image, 'full' );
53
+ if ( $image ) {
54
+ $current_brand['image'] = $image[0];
55
+ }
56
+
57
+ $banner = get_term_meta( $brand->term_id, 'pwb_brand_banner', true );
58
+ $banner = wp_get_attachment_image_src( $banner, 'full' );
59
+ if ( $banner ) {
60
+ $current_brand['banner'] = $banner[0];
61
+ }
62
+
63
+ $brands_data[] = $current_brand;
64
+ }
65
+
66
+ $export_file = fopen( WP_CONTENT_DIR . '/uploads/pwb-export.json', 'w' );
67
+ fwrite( $export_file, json_encode( $brands_data ) );
68
+ fclose( $export_file );
69
+
70
+ $result = array( 'export_file_url' => WP_CONTENT_URL . '/uploads/pwb-export.json' );
71
+
72
+ wp_send_json_success( $result );
73
+ }
74
+
75
+ public function brands_import() {
76
+ if (
77
+ isset( $_FILES['file'] )
78
+ &&
79
+ isset( $_REQUEST['nonce'] )
80
+ &&
81
+ wp_verify_nonce( $_REQUEST['nonce'], 'pwb_brands_import' )
82
+ &&
83
+ current_user_can( 'manage_options' )
84
+ ) {
85
+
86
+ $file = $_FILES['file'];
87
+
88
+ $file_content = json_decode( file_get_contents( $file['tmp_name'] ), true );
89
+
90
+ if ( is_array( $file_content ) ) {
91
+
92
+ foreach ( $file_content as $brand ) {
93
+
94
+ $new_brand = wp_insert_term(
95
+ $brand['name'],
96
+ 'pwb-brand',
97
+ array(
98
+ 'slug' => $brand['slug'],
99
+ 'description' => html_entity_decode( $brand['desc'] ),
100
+ )
101
+ );
102
+
103
+ if ( ! is_wp_error( $new_brand ) ) {
104
+
105
+ if ( ! empty( $brand['image'] ) ) {
106
+ $this->upload_remote_image_and_attach( $brand['image'], $new_brand['term_id'], 'pwb_brand_image' );
107
+ }
108
+ if ( ! empty( $brand['banner'] ) ) {
109
+ $this->upload_remote_image_and_attach( $brand['banner'], $new_brand['term_id'], 'pwb_brand_banner' );
110
+ }
111
+ if ( ! empty( $brand['banner_link'] ) ) {
112
+ update_term_meta( $new_brand['term_id'], 'pwb_brand_banner_link', $brand['banner_link'], true );
113
+ }
114
+ }
115
+ }
116
+
117
+ wp_send_json_success();
118
+ } else {
119
+ wp_send_json_error();
120
+ }
121
+ } else {
122
+ wp_send_json_error();
123
+ }
124
+
125
+ wp_die();
126
+ }
127
+
128
+ private function upload_remote_image_and_attach( $image_url, $term_id, $meta_key ) {
129
+ $get = wp_remote_get( $image_url );
130
+ $type = wp_remote_retrieve_header( $get, 'content-type' );
131
+
132
+ if ( ! $type ) {
133
+ return false;
134
+ }
135
+
136
+ $mirror = wp_upload_bits( basename( $image_url ), '', wp_remote_retrieve_body( $get ) );
137
+
138
+ $attachment = array(
139
+ 'post_title' => basename( $image_url ),
140
+ 'post_mime_type' => $type,
141
+ );
142
+
143
+ $attach_id = wp_insert_attachment( $attachment, $mirror['file'] );
144
+ require_once ABSPATH . 'wp-admin/includes/image.php';
145
+ $attach_data = wp_generate_attachment_metadata( $attach_id, $mirror['file'] );
146
+ wp_update_attachment_metadata( $attach_id, $attach_data );
147
+
148
+ update_term_meta( $term_id, $meta_key, $attach_id, true );
149
+ }
150
  }
classes/admin/class-edit-brands-page.php CHANGED
@@ -2,171 +2,189 @@
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
-
7
- class Edit_Brands_Page
8
- {
9
-
10
- private static $current_user;
11
-
12
- function __construct()
13
- {
14
- add_filter('get_terms', array($this, 'brand_list_admin_filter'), 10, 3);
15
- add_filter('manage_edit-pwb-brand_columns', array($this, 'brand_taxonomy_columns_head'));
16
- add_filter('manage_pwb-brand_custom_column', array($this, 'brand_taxonomy_columns'), 10, 3);
17
- add_action('wp_ajax_pwb_admin_set_featured_brand', array($this, 'admin_set_featured_brand'));
18
- add_filter('screen_settings', array($this, 'add_screen_options'), 10, 2);
19
- add_action('wp_ajax_pwb_admin_save_screen_settings', array($this, 'admin_save_screen_settings'));
20
- add_action('plugins_loaded', function () {
21
- \Perfect_Woocommerce_Brands\Admin\Edit_Brands_Page::$current_user = wp_get_current_user();
22
- });
23
- add_action('after-pwb-brand-table', array($this, 'add_brands_count'));
24
- }
25
-
26
- private static function is_edit_brands_page()
27
- {
28
- global $pagenow;
29
- return ($pagenow == 'edit-tags.php' && isset($_GET['taxonomy']) && $_GET['taxonomy'] == 'pwb-brand') ? true : false;
30
- }
31
-
32
- public function add_brands_count($tax_name)
33
- {
34
- $brands = get_terms(
35
- $tax_name,
36
- array('hide_empty' => false)
37
- );
38
- $brands_featured = get_terms(
39
- $tax_name,
40
- array('hide_empty' => false, 'meta_query' => array(array('key' => 'pwb_featured_brand', 'value' => true)))
41
- );
42
-
43
- echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
44
- 'edit-brands-bottom',
45
- 'admin',
46
- array('featured_count' => count($brands_featured), 'text_featured' => esc_html__('featured', 'perfect-woocommerce-brands'))
47
- );
48
- }
49
-
50
- public function brand_list_admin_filter($brands, $taxonomies, $args)
51
- {
52
-
53
- if (self::is_edit_brands_page() && !empty(self::$current_user->ID)) {
54
- $featured = get_user_option('pwb-first-featured-brands', self::$current_user->ID);
55
- if ($featured) {
56
- $featured_brands = array();
57
- $other_brands = array();
58
- foreach ($brands as $brand) {
59
- if (isset($brand->term_id) && get_term_meta($brand->term_id, 'pwb_featured_brand', true)) {
60
- $featured_brands[] = $brand;
61
- } else {
62
- $other_brands[] = $brand;
63
- }
64
- }
65
- return array_merge($featured_brands, $other_brands);
66
- }
67
- }
68
- return $brands;
69
- }
70
-
71
- public function brand_taxonomy_columns_head($columns)
72
- {
73
- $new_columns = array();
74
-
75
- if (isset($columns['cb'])) {
76
- $new_columns['cb'] = $columns['cb'];
77
- unset($columns['cb']);
78
- }
79
-
80
- if (isset($columns['description'])) unset($columns['description']);
81
-
82
- $new_columns['logo'] = __('Logo', 'perfect-woocommerce-brands');
83
- $columns['featured'] = '<span class="pwb-featured-col-title">' . __('Featured', 'perfect-woocommerce-brands') . '</span>';
84
-
85
- return array_merge($new_columns, $columns);
86
- }
87
-
88
- public function brand_taxonomy_columns($c, $column_name, $term_id)
89
- {
90
- switch ($column_name) {
91
- case 'logo':
92
- $image = wp_get_attachment_image(get_term_meta($term_id, 'pwb_brand_image', 1), array('40', '40'));
93
- return ($image) ? $image : wc_placeholder_img(array('40', '40'));
94
- break;
95
- case 'featured':
96
- $featured_class = ($this->is_featured_brand($term_id)) ? 'dashicons-star-filled' : 'dashicons-star-empty';
97
- printf(
98
- '<span class="dashicons %1$s" title="%2$s" data-brand-id="%3$s"></span>',
99
- $featured_class,
100
- esc_html__('Set as featured', 'perfect-woocommerce-brands'),
101
- $term_id
102
- );
103
- break;
104
- }
105
- }
106
-
107
- private function is_featured_brand($brand_id)
108
- {
109
- return (get_term_meta($brand_id, 'pwb_featured_brand', true));
110
- }
111
-
112
- public function admin_set_featured_brand()
113
- {
114
- if (
115
- isset($_REQUEST['nonce'])
116
- &&
117
- wp_verify_nonce($_REQUEST['nonce'], 'pwb_admin_set_featured_brand')
118
- &&
119
- current_user_can('manage_options')
120
- ) {
121
-
122
- if (isset($_POST['brand'])) {
123
- $direction = 'up';
124
- $brand = intval($_POST['brand']);
125
- if ($this->is_featured_brand($brand)) {
126
- delete_term_meta($brand, 'pwb_featured_brand', true);
127
- $direction = 'down';
128
- } else {
129
- update_term_meta($brand, 'pwb_featured_brand', true);
130
- }
131
- wp_send_json_success(array('success' => true, 'direction' => $direction));
132
- } else {
133
- wp_send_json_error(array('success' => false, 'error_msg' => __('Error!', 'perfect-woocommerce-brands')));
134
- }
135
- }
136
- wp_die();
137
- }
138
-
139
- public function add_screen_options($status, $args)
140
- {
141
- if (self::is_edit_brands_page()) {
142
- $featured = get_user_option('pwb-first-featured-brands', self::$current_user->ID);
143
- ob_start();
144
- ?>
145
- <legend><?php esc_html_e('Brands', 'perfect-woocommerce-brands'); ?></legend>
146
- <label>
147
- <input id="pwb-first-featured-brands" type="checkbox" <?php checked($featured, true); ?>>
148
- <?php esc_html_e('Show featured brands first', 'perfect-woocommerce-brands'); ?>
149
- </label>
150
- <?php
151
- return ob_get_clean();
152
- }
153
- }
154
-
155
- public function admin_save_screen_settings()
156
- {
157
- if (
158
- isset($_REQUEST['nonce'])
159
- &&
160
- wp_verify_nonce($_REQUEST['nonce'], 'pwb_admin_save_screen_settings')
161
- &&
162
- current_user_can('manage_options')
163
- ) {
164
-
165
- if (isset($_POST['new_val'])) {
166
- $new_val = ($_POST['new_val'] == 'true') ? true : false;
167
- update_user_option(self::$current_user->ID, 'pwb-first-featured-brands', $new_val);
168
- }
169
- }
170
- wp_die();
171
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  }
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class Edit_Brands_Page {
8
+
9
+ private static $current_user;
10
+
11
+ function __construct() {
12
+ add_filter( 'get_terms', array( $this, 'brand_list_admin_filter' ), 10, 3 );
13
+ add_filter( 'manage_edit-pwb-brand_columns', array( $this, 'brand_taxonomy_columns_head' ) );
14
+ add_filter( 'manage_pwb-brand_custom_column', array( $this, 'brand_taxonomy_columns' ), 10, 3 );
15
+ add_action( 'wp_ajax_pwb_admin_set_featured_brand', array( $this, 'admin_set_featured_brand' ) );
16
+ add_filter( 'screen_settings', array( $this, 'add_screen_options' ), 10, 2 );
17
+ add_action( 'wp_ajax_pwb_admin_save_screen_settings', array( $this, 'admin_save_screen_settings' ) );
18
+ add_action(
19
+ 'plugins_loaded',
20
+ function () {
21
+ \Perfect_Woocommerce_Brands\Admin\Edit_Brands_Page::$current_user = wp_get_current_user();
22
+ }
23
+ );
24
+ add_action( 'after-pwb-brand-table', array( $this, 'add_brands_count' ) );
25
+ }
26
+
27
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
28
+ private static function is_edit_brands_page() {
29
+ global $pagenow;
30
+ return ( $pagenow == 'edit-tags.php' && isset( $_GET['taxonomy'] ) && $_GET['taxonomy'] == 'pwb-brand' ) ? true : false; // phpcs:ignore WordPress.Security.NonceVerification.Missing
31
+ }
32
+
33
+ public function add_brands_count( $tax_name ) {
34
+ $brands = get_terms(
35
+ $tax_name,
36
+ array( 'hide_empty' => false )
37
+ );
38
+ $brands_featured = get_terms(
39
+ $tax_name,
40
+ array(
41
+ 'hide_empty' => false,
42
+ 'meta_query' => array(
43
+ array(
44
+ 'key' => 'pwb_featured_brand',
45
+ 'value' => true,
46
+ ),
47
+ ),
48
+ )
49
+ );
50
+
51
+ echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
52
+ 'edit-brands-bottom',
53
+ 'admin',
54
+ array(
55
+ 'featured_count' => count( $brands_featured ),
56
+ 'text_featured' => esc_html__( 'featured', 'perfect-woocommerce-brands' ),
57
+ )
58
+ );
59
+ }
60
+
61
+ public function brand_list_admin_filter( $brands, $taxonomies, $args ) {
62
+ if ( self::is_edit_brands_page() && ! empty( self::$current_user->ID ) ) {
63
+ $featured = get_user_option( 'pwb-first-featured-brands', self::$current_user->ID );
64
+ if ( $featured ) {
65
+ $featured_brands = array();
66
+ $other_brands = array();
67
+ foreach ( $brands as $brand ) {
68
+ if ( isset( $brand->term_id ) && get_term_meta( $brand->term_id, 'pwb_featured_brand', true ) ) {
69
+ $featured_brands[] = $brand;
70
+ } else {
71
+ $other_brands[] = $brand;
72
+ }
73
+ }
74
+ return array_merge( $featured_brands, $other_brands );
75
+ }
76
+ }
77
+ return $brands;
78
+ }
79
+
80
+ public function brand_taxonomy_columns_head( $columns ) {
81
+ $new_columns = array();
82
+
83
+ if ( isset( $columns['cb'] ) ) {
84
+ $new_columns['cb'] = $columns['cb'];
85
+ unset( $columns['cb'] );
86
+ }
87
+
88
+ if ( isset( $columns['description'] ) ) {
89
+ unset( $columns['description'] );
90
+ }
91
+
92
+ $new_columns['logo'] = __( 'Logo', 'perfect-woocommerce-brands' );
93
+ $columns['featured'] = '<span class="pwb-featured-col-title">' . __( 'Featured', 'perfect-woocommerce-brands' ) . '</span>';
94
+
95
+ return array_merge( $new_columns, $columns );
96
+ }
97
+
98
+ public function brand_taxonomy_columns( $c, $column_name, $term_id ) {
99
+ switch ( $column_name ) {
100
+ case 'logo':
101
+ $image = wp_get_attachment_image( get_term_meta( $term_id, 'pwb_brand_image', 1 ), array( '40', '40' ) );
102
+ return ( $image ) ? $image : wc_placeholder_img( array( '40', '40' ) );
103
+ break;
104
+ case 'featured':
105
+ $featured_class = $this->is_featured_brand( $term_id ) ? 'dashicons-star-filled' : 'dashicons-star-empty';
106
+ printf(
107
+ '<span class="dashicons %1$s" title="%2$s" data-brand-id="%3$s"></span>',
108
+ esc_attr( $featured_class ),
109
+ esc_html__( 'Set as featured', 'perfect-woocommerce-brands' ),
110
+ esc_attr( $term_id )
111
+ );
112
+ break;
113
+ }
114
+ }
115
+
116
+ private function is_featured_brand( $brand_id ) {
117
+ return ( get_term_meta( $brand_id, 'pwb_featured_brand', true ) );
118
+ }
119
+
120
+ public function admin_set_featured_brand() {
121
+ if (
122
+ isset( $_REQUEST['nonce'] )
123
+ &&
124
+ wp_verify_nonce( $_REQUEST['nonce'], 'pwb_admin_set_featured_brand' )
125
+ &&
126
+ current_user_can( 'manage_options' )
127
+ ) {
128
+
129
+ if ( isset( $_POST['brand'] ) ) {
130
+ $direction = 'up';
131
+ $brand = intval( $_POST['brand'] );
132
+ if ( $this->is_featured_brand( $brand ) ) {
133
+ delete_term_meta( $brand, 'pwb_featured_brand', true );
134
+ $direction = 'down';
135
+ } else {
136
+ update_term_meta( $brand, 'pwb_featured_brand', true );
137
+ }
138
+ wp_send_json_success(
139
+ array(
140
+ 'success' => true,
141
+ 'direction' => $direction,
142
+ )
143
+ );
144
+ } else {
145
+ wp_send_json_error(
146
+ array(
147
+ 'success' => false,
148
+ 'error_msg' => __(
149
+ 'Error!',
150
+ 'perfect-woocommerce-brands'
151
+ ),
152
+ )
153
+ );
154
+ }
155
+ }
156
+ wp_die();
157
+ }
158
+
159
+ public function add_screen_options( $status, $args ) {
160
+ if ( self::is_edit_brands_page() ) {
161
+ $featured = get_user_option( 'pwb-first-featured-brands', self::$current_user->ID );
162
+ ob_start();
163
+ ?>
164
+ <legend><?php esc_html_e( 'Brands', 'perfect-woocommerce-brands' ); ?></legend>
165
+ <label>
166
+ <input id="pwb-first-featured-brands" type="checkbox" <?php checked( $featured, true ); ?>>
167
+ <?php esc_html_e( 'Show featured brands first', 'perfect-woocommerce-brands' ); ?>
168
+ </label>
169
+ <?php
170
+ return ob_get_clean();
171
+ }
172
+ }
173
+
174
+ public function admin_save_screen_settings() {
175
+ if (
176
+ isset( $_REQUEST['nonce'] )
177
+ &&
178
+ wp_verify_nonce( $_REQUEST['nonce'], 'pwb_admin_save_screen_settings' )
179
+ &&
180
+ current_user_can( 'manage_options' )
181
+ ) {
182
+
183
+ if ( isset( $_POST['new_val'] ) ) {
184
+ $new_val = ( $_POST['new_val'] == 'true' ) ? true : false;
185
+ update_user_option( self::$current_user->ID, 'pwb-first-featured-brands', $new_val );
186
+ }
187
+ }
188
+ wp_die();
189
+ }
190
  }
classes/admin/class-pwb-admin-tab.php CHANGED
@@ -2,307 +2,313 @@
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
- class Pwb_Admin_Tab
11
- {
12
-
13
- public function __construct()
14
- {
15
-
16
- $this->id = 'pwb_admin_tab';
17
- $this->label = __('Brands', 'perfect-woocommerce-brands');
18
-
19
- add_filter('woocommerce_settings_tabs_array', [$this, 'add_tab'], 200);
20
- add_action('woocommerce_settings_' . $this->id, [$this, 'output']);
21
- add_action('woocommerce_sections_' . $this->id, [$this, 'output_sections']);
22
- add_action('woocommerce_settings_save_' . $this->id, [$this, 'save']);
23
- }
24
-
25
- public function add_tab($settings_tabs)
26
- {
27
-
28
- $settings_tabs[$this->id] = $this->label;
29
-
30
- return $settings_tabs;
31
- }
32
-
33
- public function get_sections()
34
- {
35
-
36
- $sections = array(
37
- '' => __('General', 'perfect-woocommerce-brands'),
38
- 'brand-pages' => __('Archives', 'perfect-woocommerce-brands'),
39
- 'single-product' => __('Products', 'perfect-woocommerce-brands'),
40
- 'tools' => __('Tools', 'perfect-woocommerce-brands'),
41
- );
42
-
43
- return apply_filters('woocommerce_get_sections_' . $this->id, $sections);
44
- }
45
-
46
- public function output_sections()
47
- {
48
- global $current_section;
49
-
50
- $sections = $this->get_sections();
51
-
52
- if (empty($sections) || 1 === sizeof($sections)) {
53
- return;
54
- }
55
-
56
- ?>
57
- <ul class="subsubsub">
58
- <?php foreach ($sections as $id => $label) : ?>
59
- <li><a href="<?php echo admin_url('admin.php?page=wc-settings&tab=' . $this->id . '&section=' . $id); ?>" class="<?php echo ($current_section == $id ? 'current' : ''); ?>"><?php esc_html_e($label); ?></a></li> |
60
- <?php endforeach; ?>
61
- <li><a target="_blank" href="<?php echo admin_url('edit-tags.php?taxonomy=pwb-brand&post_type=product'); ?>"><?php esc_html_e('Brands', 'perfect-woocommerce-brands'); ?></a></li> |
62
- <li><a target="_blank" href="<?php echo admin_url('admin.php?page=pwb_suggestions'); ?>"><?php esc_attr_e('Suggestions', 'perfect-woocommerce-brands'); ?></a></li> |
63
- <li><a target="_blank" href="<?php echo esc_url(PWB_DOCUMENTATION_URL); ?>"><?php esc_html_e('Documentation', 'perfect-woocommerce-brands'); ?></a></li>
64
- </ul>
65
- <br class="clear" />
66
- <?php
67
- }
68
-
69
- public function get_settings($current_section = '')
70
- {
71
-
72
- $available_image_sizes_adapted = array();
73
- $available_image_sizes = get_intermediate_image_sizes();
74
- foreach ($available_image_sizes as $image_size)
75
- $available_image_sizes_adapted[$image_size] = $image_size;
76
- $available_image_sizes_adapted['full'] = 'full';
77
-
78
- $pages_select_adapted = array('-' => '-');
79
- $pages_select = get_pages();
80
- foreach ($pages_select as $page)
81
- $pages_select_adapted[$page->ID] = $page->post_title;
82
-
83
- if ('single-product' == $current_section) {
84
-
85
- $settings = apply_filters('wc_pwb_admin_tab_settings', array(
86
- 'section_title' => array(
87
- 'name' => __('Products', 'perfect-woocommerce-brands'),
88
- 'type' => 'title',
89
- 'desc' => '',
90
- 'id' => 'wc_pwb_admin_tab_section_title'
91
- ),
92
- 'brand_single_product_tab' => array(
93
- 'name' => __('Products tab', 'perfect-woocommerce-brands'),
94
- 'type' => 'checkbox',
95
- 'default' => 'yes',
96
- 'desc' => __('Show brand tab in single product page', 'perfect-woocommerce-brands'),
97
- 'id' => 'wc_pwb_admin_tab_brand_single_product_tab'
98
- ),
99
- 'show_brand_in_single' => array(
100
- 'name' => __('Show brands in single product', 'perfect-woocommerce-brands'),
101
- 'type' => 'select',
102
- 'class' => 'pwb-admin-tab-field',
103
- 'desc' => __('Show brand logo (or name) in single product', 'perfect-woocommerce-brands'),
104
- 'default' => 'brand_image',
105
- 'id' => 'wc_pwb_admin_tab_brands_in_single',
106
- 'options' => array(
107
- 'no' => __('No', 'perfect-woocommerce-brands'),
108
- 'brand_link' => __('Show brand link', 'perfect-woocommerce-brands'),
109
- 'brand_image' => __('Show brand image (if is set)', 'perfect-woocommerce-brands')
110
- )
111
- ),
112
- 'brand_single_position' => array(
113
- 'name' => __('Brand position', 'perfect-woocommerce-brands'),
114
- 'type' => 'select',
115
- 'class' => 'pwb-admin-tab-field',
116
- 'desc' => __('For single product', 'perfect-woocommerce-brands'),
117
- 'id' => 'wc_pwb_admin_tab_brand_single_position',
118
- 'options' => array(
119
- 'before_title' => __('Before title', 'perfect-woocommerce-brands'),
120
- 'after_title' => __('After title', 'perfect-woocommerce-brands'),
121
- 'after_price' => __('After price', 'perfect-woocommerce-brands'),
122
- 'after_excerpt' => __('After excerpt', 'perfect-woocommerce-brands'),
123
- 'after_add_to_cart' => __('After add to cart', 'perfect-woocommerce-brands'),
124
- 'meta' => __('In meta', 'perfect-woocommerce-brands'),
125
- 'after_meta' => __('After meta', 'perfect-woocommerce-brands'),
126
- 'after_sharing' => __('After sharing', 'perfect-woocommerce-brands')
127
- )
128
- ),
129
- 'section_end' => array(
130
- 'type' => 'sectionend',
131
- 'id' => 'wc_pwb_admin_tab_section_end'
132
- )
133
- ));
134
- } elseif ('brand-pages' == $current_section) {
135
-
136
- $settings = apply_filters('wc_pwb_admin_tab_brand_pages_settings', array(
137
- 'section_title' => array(
138
- 'name' => __('Archives', 'perfect-woocommerce-brands'),
139
- 'type' => 'title',
140
- 'desc' => '',
141
- 'id' => 'wc_pwb_admin_tab_section_title'
142
- ),
143
- 'brand_description' => array(
144
- 'name' => __('Show brand description', 'perfect-woocommerce-brands'),
145
- 'type' => 'select',
146
- 'class' => 'pwb-admin-tab-field',
147
- 'default' => 'yes',
148
- 'desc' => __('Show brand description (if is set) on brand archive page', 'perfect-woocommerce-brands'),
149
- 'id' => 'wc_pwb_admin_tab_brand_desc',
150
- 'options' => array(
151
- 'yes' => __('Yes, before product loop', 'perfect-woocommerce-brands'),
152
- 'yes_after_loop' => __('Yes, after product loop', 'perfect-woocommerce-brands'),
153
- 'no' => __('No, hide description', 'perfect-woocommerce-brands')
154
- )
155
- ),
156
- 'brand_banner' => array(
157
- 'name' => __('Show brand banner', 'perfect-woocommerce-brands'),
158
- 'type' => 'select',
159
- 'class' => 'pwb-admin-tab-field',
160
- 'default' => 'yes',
161
- 'desc' => __('Show brand banner (if is set) on brand archive page', 'perfect-woocommerce-brands'),
162
- 'id' => 'wc_pwb_admin_tab_brand_banner',
163
- 'options' => array(
164
- 'yes' => __('Yes, before product loop', 'perfect-woocommerce-brands'),
165
- 'yes_after_loop' => __('Yes, after product loop', 'perfect-woocommerce-brands'),
166
- 'no' => __('No, hide banner', 'perfect-woocommerce-brands')
167
- )
168
- ),
169
- 'show_brand_on_loop' => array(
170
- 'name' => __('Show brands in loop', 'perfect-woocommerce-brands'),
171
- 'type' => 'select',
172
- 'class' => 'pwb-admin-tab-field',
173
- 'desc' => __('Show brand logo (or name) in product loop', 'perfect-woocommerce-brands'),
174
- 'id' => 'wc_pwb_admin_tab_brands_in_loop',
175
- 'options' => array(
176
- 'no' => __('No', 'perfect-woocommerce-brands'),
177
- 'brand_link' => __('Show brand link', 'perfect-woocommerce-brands'),
178
- 'brand_image' => __('Show brand image (if is set)', 'perfect-woocommerce-brands')
179
- )
180
- ),
181
- 'section_end' => array(
182
- 'type' => 'sectionend',
183
- 'id' => 'wc_pwb_admin_tab_section_end'
184
- )
185
- ));
186
- } elseif ('tools' == $current_section) {
187
-
188
- $settings = apply_filters('wc_pwb_admin_tab_tools_settings', array(
189
- 'section_title' => array(
190
- 'name' => __('Tools', 'perfect-woocommerce-brands'),
191
- 'type' => 'title',
192
- 'desc' => '',
193
- 'id' => 'wc_pwb_admin_tab_section_tools_title'
194
- ),
195
- 'brand_import' => array(
196
- 'name' => __('Import brands', 'perfect-woocommerce-brands'),
197
- 'type' => 'select',
198
- 'class' => 'pwb-admin-tab-field',
199
- 'desc' => sprintf(
200
- __('Import brands from other brand plugin. <a href="%s" target="_blank">Click here for more details</a>', 'perfect-woocommerce-brands'),
201
- str_replace('/?', '/brands/?', PWB_DOCUMENTATION_URL)
202
- ),
203
- 'id' => 'wc_pwb_admin_tab_tools_migrate',
204
- 'options' => array(
205
- '-' => __('-', 'perfect-woocommerce-brands'),
206
- 'yith' => __('YITH WooCommerce Brands Add-On', 'perfect-woocommerce-brands'),
207
- 'ultimate' => __('Ultimate WooCommerce Brands', 'perfect-woocommerce-brands'),
208
- 'woobrands' => __('Offical WooCommerce Brands', 'perfect-woocommerce-brands')
209
- )
210
- ),
211
- 'brand_dummy_data' => array(
212
- 'name' => __('Dummy data', 'perfect-woocommerce-brands'),
213
- 'type' => 'select',
214
- 'class' => 'pwb-admin-tab-field',
215
- 'desc' => __('Import generic brands and assign it to products randomly', 'perfect-woocommerce-brands'),
216
- 'id' => 'wc_pwb_admin_tab_tools_dummy_data',
217
- 'options' => array(
218
- '-' => __('-', 'perfect-woocommerce-brands'),
219
- 'start_import' => __('Start import', 'perfect-woocommerce-brands')
220
- )
221
- ),
222
- 'brands_system_status' => array(
223
- 'name' => __('System status', 'perfect-woocommerce-brands'),
224
- 'type' => 'textarea',
225
- 'desc' => __('Show system status', 'perfect-woocommerce-brands'),
226
- 'id' => 'wc_pwb_admin_tab_tools_system_status'
227
- ),
228
- 'section_end' => array(
229
- 'type' => 'sectionend',
230
- 'id' => 'wc_pwb_admin_tab_section_tools_end'
231
- )
232
- ));
233
- } else {
234
-
235
- $brands_url = get_option('wc_pwb_admin_tab_slug', __('brands', 'perfect-woocommerce-brands')) . '/' . __('brand-name', 'perfect-woocommerce-brands') . '/';
236
-
237
- $settings = apply_filters('wc_pwb_admin_tab_product_settings', array(
238
- 'section_title' => array(
239
- 'name' => __('General', 'perfect-woocommerce-brands'),
240
- 'type' => 'title',
241
- 'desc' => '',
242
- 'id' => 'wc_pwb_admin_tab_section_title'
243
- ),
244
- 'slug' => array(
245
- 'name' => __('Slug', 'perfect-woocommerce-brands'),
246
- 'type' => 'text',
247
- 'class' => 'pwb-admin-tab-field',
248
- 'desc' => __('Brands taxonomy slug', 'perfect-woocommerce-brands'),
249
- 'desc_tip' => sprintf(
250
- __('Your brands URLs will look like "%s"', 'perfect-woocommerce-brands'),
251
- 'https://site.com/' . $brands_url
252
- ),
253
- 'id' => 'wc_pwb_admin_tab_slug',
254
- 'placeholder' => get_taxonomy('pwb-brand')->rewrite['slug']
255
- ),
256
- 'brand_logo_size' => array(
257
- 'name' => __('Brand logo size', 'perfect-woocommerce-brands'),
258
- 'type' => 'select',
259
- 'class' => 'pwb-admin-tab-field',
260
- 'desc' => __('Select the size for the brand logo image around the site', 'perfect-woocommerce-brands'),
261
- 'desc_tip' => __('The default image sizes can be configured under "Settings > Media". You can also define your own image sizes', 'perfect-woocommerce-brands'),
262
- 'id' => 'wc_pwb_admin_tab_brand_logo_size',
263
- 'options' => $available_image_sizes_adapted
264
- ),
265
- 'brands_page_id' => array(
266
- 'name' => __('Brands page', 'perfect-woocommerce-brands'),
267
- 'type' => 'select',
268
- 'class' => 'pwb-admin-tab-field pwb-admin-selectwoo',
269
- 'desc' => __('For linking breadcrumbs', 'perfect-woocommerce-brands'),
270
- 'desc_tip' => __('Select your "Brands" page (if you have one), it will be linked in the breadcrumbs.', 'perfect-woocommerce-brands'),
271
- 'id' => 'wc_pwb_admin_tab_brands_page_id',
272
- 'options' => $pages_select_adapted
273
- ),
274
- 'section_end' => array(
275
- 'type' => 'sectionend',
276
- 'id' => 'wc_pwb_admin_tab_section_end'
277
- )
278
- ));
279
- }
280
-
281
- return apply_filters('woocommerce_get_settings_' . $this->id, $settings, $current_section);
282
- }
283
-
284
- public function output()
285
- {
286
-
287
- global $current_section;
288
-
289
- $settings = $this->get_settings($current_section);
290
- WC_Admin_Settings::output_fields($settings);
291
- }
292
-
293
- public function save()
294
- {
295
-
296
- update_option('old_wc_pwb_admin_tab_slug', get_taxonomy('pwb-brand')->rewrite['slug']);
297
- if (isset($_POST['wc_pwb_admin_tab_slug'])) {
298
- $_POST['wc_pwb_admin_tab_slug'] = sanitize_title($_POST['wc_pwb_admin_tab_slug']);
299
- }
300
-
301
- global $current_section;
302
-
303
- $settings = $this->get_settings($current_section);
304
- WC_Admin_Settings::save_fields($settings);
305
- }
 
 
 
 
 
 
306
  }
307
 
308
  return new Pwb_Admin_Tab();
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
+ use WC_Admin_Settings, WC_Settings_Page;
6
+
7
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
8
+
9
+ class Pwb_Admin_Tab {
10
+
11
+ public function __construct() {
12
+ $this->id = 'pwb_admin_tab';
13
+ $this->label = __( 'Brands', 'perfect-woocommerce-brands' );
14
+
15
+ add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_tab' ), 200 );
16
+ add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
17
+ add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
18
+ add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
19
+ }
20
+
21
+ public function add_tab( $settings_tabs ) {
22
+ $settings_tabs[ $this->id ] = $this->label;
23
+ return $settings_tabs;
24
+ }
25
+
26
+ public function get_sections() {
27
+ $sections = array(
28
+ '' => __( 'General', 'perfect-woocommerce-brands' ),
29
+ 'brand-pages' => __( 'Archives', 'perfect-woocommerce-brands' ),
30
+ 'single-product' => __( 'Products', 'perfect-woocommerce-brands' ),
31
+ 'tools' => __( 'Tools', 'perfect-woocommerce-brands' ),
32
+ );
33
+
34
+ return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
35
+ }
36
+
37
+ public function output_sections() {
38
+ global $current_section;
39
+
40
+ $sections = $this->get_sections();
41
+
42
+ if ( empty( $sections ) || 1 === count( $sections ) ) {
43
+ return;
44
+ }
45
+
46
+ ?>
47
+ <ul class="subsubsub">
48
+ <?php foreach ( $sections as $id => $label ) : ?>
49
+ <li>
50
+ <a
51
+ href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=' . $this->id . '&section=' . $id ) ); ?>"
52
+ class="<?php echo ( $current_section === $id ? 'current' : '' ); ?>"><?php echo esc_html( $label ); ?>
53
+ </a>
54
+ </li> |
55
+ <?php endforeach; ?>
56
+ <li><a target="_blank" href="<?php echo esc_url( admin_url( 'edit-tags.php?taxonomy=pwb-brand&post_type=product' ) ); ?>"><?php esc_html_e( 'Brands', 'perfect-woocommerce-brands' ); ?></a></li> |
57
+ <li><a target="_blank" href="<?php echo esc_url( admin_url( 'admin.php?page=pwb_suggestions' ) ); ?>"><?php esc_attr_e( 'Suggestions', 'perfect-woocommerce-brands' ); ?></a></li> |
58
+ <li><a target="_blank" href="<?php echo esc_url( PWB_DOCUMENTATION_URL ); ?>"><?php esc_html_e( 'Documentation', 'perfect-woocommerce-brands' ); ?></a></li>
59
+ </ul>
60
+ <br class="clear" />
61
+ <?php
62
+ }
63
+
64
+ public function get_settings( $current_section = '' ) {
65
+ $available_image_sizes_adapted = array();
66
+ $available_image_sizes = get_intermediate_image_sizes();
67
+ foreach ( $available_image_sizes as $image_size ) {
68
+ $available_image_sizes_adapted[ $image_size ] = $image_size;
69
+ }
70
+ $available_image_sizes_adapted['full'] = 'full';
71
+
72
+ $pages_select_adapted = array( '-' => '-' );
73
+ $pages_select = get_pages();
74
+ foreach ( $pages_select as $page ) {
75
+ $pages_select_adapted[ $page->ID ] = $page->post_title;
76
+ }
77
+
78
+ if ( 'single-product' == $current_section ) {
79
+
80
+ $settings = apply_filters(
81
+ 'wc_pwb_admin_tab_settings',
82
+ array(
83
+ 'section_title' => array(
84
+ 'name' => __( 'Products', 'perfect-woocommerce-brands' ),
85
+ 'type' => 'title',
86
+ 'desc' => '',
87
+ 'id' => 'wc_pwb_admin_tab_section_title',
88
+ ),
89
+ 'brand_single_product_tab' => array(
90
+ 'name' => __( 'Products tab', 'perfect-woocommerce-brands' ),
91
+ 'type' => 'checkbox',
92
+ 'default' => 'yes',
93
+ 'desc' => __( 'Show brand tab in single product page', 'perfect-woocommerce-brands' ),
94
+ 'id' => 'wc_pwb_admin_tab_brand_single_product_tab',
95
+ ),
96
+ 'show_brand_in_single' => array(
97
+ 'name' => __( 'Show brands in single product', 'perfect-woocommerce-brands' ),
98
+ 'type' => 'select',
99
+ 'class' => 'pwb-admin-tab-field',
100
+ 'desc' => __( 'Show brand logo (or name) in single product', 'perfect-woocommerce-brands' ),
101
+ 'default' => 'brand_image',
102
+ 'id' => 'wc_pwb_admin_tab_brands_in_single',
103
+ 'options' => array(
104
+ 'no' => __( 'No', 'perfect-woocommerce-brands' ),
105
+ 'brand_link' => __( 'Show brand link', 'perfect-woocommerce-brands' ),
106
+ 'brand_image' => __( 'Show brand image (if is set)', 'perfect-woocommerce-brands' ),
107
+ ),
108
+ ),
109
+ 'brand_single_position' => array(
110
+ 'name' => __( 'Brand position', 'perfect-woocommerce-brands' ),
111
+ 'type' => 'select',
112
+ 'class' => 'pwb-admin-tab-field',
113
+ 'desc' => __( 'For single product', 'perfect-woocommerce-brands' ),
114
+ 'id' => 'wc_pwb_admin_tab_brand_single_position',
115
+ 'options' => array(
116
+ 'before_title' => __( 'Before title', 'perfect-woocommerce-brands' ),
117
+ 'after_title' => __( 'After title', 'perfect-woocommerce-brands' ),
118
+ 'after_price' => __( 'After price', 'perfect-woocommerce-brands' ),
119
+ 'after_excerpt' => __( 'After excerpt', 'perfect-woocommerce-brands' ),
120
+ 'after_add_to_cart' => __( 'After add to cart', 'perfect-woocommerce-brands' ),
121
+ 'meta' => __( 'In meta', 'perfect-woocommerce-brands' ),
122
+ 'after_meta' => __( 'After meta', 'perfect-woocommerce-brands' ),
123
+ 'after_sharing' => __( 'After sharing', 'perfect-woocommerce-brands' ),
124
+ ),
125
+ ),
126
+ 'section_end' => array(
127
+ 'type' => 'sectionend',
128
+ 'id' => 'wc_pwb_admin_tab_section_end',
129
+ ),
130
+ )
131
+ );
132
+ } elseif ( 'brand-pages' == $current_section ) {
133
+
134
+ $settings = apply_filters(
135
+ 'wc_pwb_admin_tab_brand_pages_settings',
136
+ array(
137
+ 'section_title' => array(
138
+ 'name' => __( 'Archives', 'perfect-woocommerce-brands' ),
139
+ 'type' => 'title',
140
+ 'desc' => '',
141
+ 'id' => 'wc_pwb_admin_tab_section_title',
142
+ ),
143
+ 'brand_description' => array(
144
+ 'name' => __( 'Show brand description', 'perfect-woocommerce-brands' ),
145
+ 'type' => 'select',
146
+ 'class' => 'pwb-admin-tab-field',
147
+ 'default' => 'yes',
148
+ 'desc' => __( 'Show brand description (if is set) on brand archive page', 'perfect-woocommerce-brands' ),
149
+ 'id' => 'wc_pwb_admin_tab_brand_desc',
150
+ 'options' => array(
151
+ 'yes' => __( 'Yes, before product loop', 'perfect-woocommerce-brands' ),
152
+ 'yes_after_loop' => __( 'Yes, after product loop', 'perfect-woocommerce-brands' ),
153
+ 'no' => __( 'No, hide description', 'perfect-woocommerce-brands' ),
154
+ ),
155
+ ),
156
+ 'brand_banner' => array(
157
+ 'name' => __( 'Show brand banner', 'perfect-woocommerce-brands' ),
158
+ 'type' => 'select',
159
+ 'class' => 'pwb-admin-tab-field',
160
+ 'default' => 'yes',
161
+ 'desc' => __( 'Show brand banner (if is set) on brand archive page', 'perfect-woocommerce-brands' ),
162
+ 'id' => 'wc_pwb_admin_tab_brand_banner',
163
+ 'options' => array(
164
+ 'yes' => __( 'Yes, before product loop', 'perfect-woocommerce-brands' ),
165
+ 'yes_after_loop' => __( 'Yes, after product loop', 'perfect-woocommerce-brands' ),
166
+ 'no' => __( 'No, hide banner', 'perfect-woocommerce-brands' ),
167
+ ),
168
+ ),
169
+ 'show_brand_on_loop' => array(
170
+ 'name' => __( 'Show brands in loop', 'perfect-woocommerce-brands' ),
171
+ 'type' => 'select',
172
+ 'class' => 'pwb-admin-tab-field',
173
+ 'desc' => __( 'Show brand logo (or name) in product loop', 'perfect-woocommerce-brands' ),
174
+ 'id' => 'wc_pwb_admin_tab_brands_in_loop',
175
+ 'options' => array(
176
+ 'no' => __( 'No', 'perfect-woocommerce-brands' ),
177
+ 'brand_link' => __( 'Show brand link', 'perfect-woocommerce-brands' ),
178
+ 'brand_image' => __( 'Show brand image (if is set)', 'perfect-woocommerce-brands' ),
179
+ ),
180
+ ),
181
+ 'section_end' => array(
182
+ 'type' => 'sectionend',
183
+ 'id' => 'wc_pwb_admin_tab_section_end',
184
+ ),
185
+ )
186
+ );
187
+ } elseif ( 'tools' == $current_section ) {
188
+
189
+ $settings = apply_filters(
190
+ 'wc_pwb_admin_tab_tools_settings',
191
+ array(
192
+ 'section_title' => array(
193
+ 'name' => __( 'Tools', 'perfect-woocommerce-brands' ),
194
+ 'type' => 'title',
195
+ 'desc' => '',
196
+ 'id' => 'wc_pwb_admin_tab_section_tools_title',
197
+ ),
198
+ 'brand_import' => array(
199
+ 'name' => __( 'Import brands', 'perfect-woocommerce-brands' ),
200
+ 'type' => 'select',
201
+ 'class' => 'pwb-admin-tab-field',
202
+ 'desc' => sprintf(
203
+ __( 'Import brands from other brand plugin. <a href="%s" target="_blank">Click here for more details</a>', 'perfect-woocommerce-brands' ),
204
+ str_replace( '/?', '/brands/?', PWB_DOCUMENTATION_URL )
205
+ ),
206
+ 'id' => 'wc_pwb_admin_tab_tools_migrate',
207
+ 'options' => array(
208
+ '-' => __( '-', 'perfect-woocommerce-brands' ),
209
+ 'yith' => __( 'YITH WooCommerce Brands Add-On', 'perfect-woocommerce-brands' ),
210
+ 'ultimate' => __( 'Ultimate WooCommerce Brands', 'perfect-woocommerce-brands' ),
211
+ 'woobrands' => __( 'Offical WooCommerce Brands', 'perfect-woocommerce-brands' ),
212
+ ),
213
+ ),
214
+ 'brand_dummy_data' => array(
215
+ 'name' => __( 'Dummy data', 'perfect-woocommerce-brands' ),
216
+ 'type' => 'select',
217
+ 'class' => 'pwb-admin-tab-field',
218
+ 'desc' => __( 'Import generic brands and assign it to products randomly', 'perfect-woocommerce-brands' ),
219
+ 'id' => 'wc_pwb_admin_tab_tools_dummy_data',
220
+ 'options' => array(
221
+ '-' => __( '-', 'perfect-woocommerce-brands' ),
222
+ 'start_import' => __( 'Start import', 'perfect-woocommerce-brands' ),
223
+ ),
224
+ ),
225
+ 'brands_system_status' => array(
226
+ 'name' => __( 'System status', 'perfect-woocommerce-brands' ),
227
+ 'type' => 'textarea',
228
+ 'desc' => __( 'Show system status', 'perfect-woocommerce-brands' ),
229
+ 'id' => 'wc_pwb_admin_tab_tools_system_status',
230
+ ),
231
+ 'section_end' => array(
232
+ 'type' => 'sectionend',
233
+ 'id' => 'wc_pwb_admin_tab_section_tools_end',
234
+ ),
235
+ )
236
+ );
237
+ } else {
238
+
239
+ $brands_url = get_option( 'wc_pwb_admin_tab_slug', __( 'brands', 'perfect-woocommerce-brands' ) ) . '/' . __( 'brand-name', 'perfect-woocommerce-brands' ) . '/';
240
+
241
+ $settings = apply_filters(
242
+ 'wc_pwb_admin_tab_product_settings',
243
+ array(
244
+ 'section_title' => array(
245
+ 'name' => __( 'General', 'perfect-woocommerce-brands' ),
246
+ 'type' => 'title',
247
+ 'desc' => '',
248
+ 'id' => 'wc_pwb_admin_tab_section_title',
249
+ ),
250
+ 'slug' => array(
251
+ 'name' => __( 'Slug', 'perfect-woocommerce-brands' ),
252
+ 'type' => 'text',
253
+ 'class' => 'pwb-admin-tab-field',
254
+ 'desc' => __( 'Brands taxonomy slug', 'perfect-woocommerce-brands' ),
255
+ 'desc_tip' => sprintf(
256
+ __( 'Your brands URLs will look like "%s"', 'perfect-woocommerce-brands' ),
257
+ 'https://site.com/' . $brands_url
258
+ ),
259
+ 'id' => 'wc_pwb_admin_tab_slug',
260
+ 'placeholder' => get_taxonomy( 'pwb-brand' )->rewrite['slug'],
261
+ ),
262
+ 'brand_logo_size' => array(
263
+ 'name' => __( 'Brand logo size', 'perfect-woocommerce-brands' ),
264
+ 'type' => 'select',
265
+ 'class' => 'pwb-admin-tab-field',
266
+ 'desc' => __( 'Select the size for the brand logo image around the site', 'perfect-woocommerce-brands' ),
267
+ 'desc_tip' => __( 'The default image sizes can be configured under "Settings > Media". You can also define your own image sizes', 'perfect-woocommerce-brands' ),
268
+ 'id' => 'wc_pwb_admin_tab_brand_logo_size',
269
+ 'options' => $available_image_sizes_adapted,
270
+ ),
271
+ 'brands_page_id' => array(
272
+ 'name' => __( 'Brands page', 'perfect-woocommerce-brands' ),
273
+ 'type' => 'select',
274
+ 'class' => 'pwb-admin-tab-field pwb-admin-selectwoo',
275
+ 'desc' => __( 'For linking breadcrumbs', 'perfect-woocommerce-brands' ),
276
+ 'desc_tip' => __( 'Select your "Brands" page (if you have one), it will be linked in the breadcrumbs.', 'perfect-woocommerce-brands' ),
277
+ 'id' => 'wc_pwb_admin_tab_brands_page_id',
278
+ 'options' => $pages_select_adapted,
279
+ ),
280
+ 'section_end' => array(
281
+ 'type' => 'sectionend',
282
+ 'id' => 'wc_pwb_admin_tab_section_end',
283
+ ),
284
+ )
285
+ );
286
+ }
287
+
288
+ return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
289
+ }
290
+
291
+ public function output() {
292
+ global $current_section;
293
+
294
+ $settings = $this->get_settings( $current_section );
295
+ WC_Admin_Settings::output_fields( $settings );
296
+ }
297
+
298
+ public function save() {
299
+
300
+ update_option( 'old_wc_pwb_admin_tab_slug', get_taxonomy( 'pwb-brand' )->rewrite['slug'] );
301
+
302
+ if ( isset( $_POST['wc_pwb_admin_tab_slug'] ) ) {
303
+ $_POST['wc_pwb_admin_tab_slug'] = sanitize_title( $_POST['wc_pwb_admin_tab_slug'] );
304
+ }
305
+
306
+ global $current_section;
307
+
308
+ $settings = $this->get_settings( $current_section );
309
+
310
+ WC_Admin_Settings::save_fields( $settings );
311
+ }
312
  }
313
 
314
  return new Pwb_Admin_Tab();
classes/admin/class-pwb-coupon.php CHANGED
@@ -1,77 +1,94 @@
1
  <?php
2
- namespace Perfect_Woocommerce_Brands\Admin;
3
 
4
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
5
 
6
- class PWB_Coupon{
7
 
8
- function __construct(){
9
- add_action( 'woocommerce_coupon_options_usage_restriction', array( $this, 'coupon_restriction' ) );
10
- add_action( 'woocommerce_coupon_options_save', array( $this, 'coupon_save' ) );
11
- add_filter( 'woocommerce_coupon_is_valid', array( $this, 'is_valid_coupon' ), 10, 2 );
12
- add_filter( 'woocommerce_coupon_is_valid_for_product', array( $this, 'is_valid_for_product_brand' ), 10, 4 );
13
- }
14
 
15
- public function coupon_restriction() {
16
- global $thepostid, $post;
17
- $thepostid = empty( $thepostid ) ? $post->get_ID() : $thepostid;
 
 
 
18
 
19
- $selected_brands = get_post_meta( $thepostid, '_pwb_coupon_restriction', true );
20
- if( $selected_brands == '' ) $selected_brands = array();
 
21
 
22
- ob_start();
23
- ?>
24
- <p class="form-field"><label for="_pwb_coupon_restriction"><?php _e( 'Brands restriction', 'perfect-woocommerce-brands' ); ?></label>
 
 
 
 
 
25
  <select id="_pwb_coupon_restriction" name="_pwb_coupon_restriction[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php esc_attr_e( 'Any brand', 'perfect-woocommerce-brands' ); ?>">
26
  <?php
27
- $categories = get_terms( 'pwb-brand', 'orderby=name&hide_empty=0' );
28
- if ( $categories ) {
29
- foreach ( $categories as $cat ) {
30
- echo '<option value="' . esc_attr( $cat->term_id ) . '"' . selected( in_array( $cat->term_id, $selected_brands ), true, false ) . '>' . esc_html( $cat->name ) . '</option>';
31
- }
32
  }
 
33
  ?>
34
- </select> <?php echo wc_help_tip( __( 'Coupon will be valid if there are at least one product of this brands in the cart', 'perfect-woocommerce-brands' ) ); ?></p>
35
- <?php
36
- echo ob_get_clean();
 
 
 
 
 
 
 
 
37
 
38
- }
 
 
 
39
 
40
- public function coupon_save( $post_id ){
41
- $_pwb_coupon_restriction = isset( $_POST['_pwb_coupon_restriction'] ) ? sanitize_text_field($_POST['_pwb_coupon_restriction']) : '';
42
- update_post_meta( $post_id, '_pwb_coupon_restriction', $_pwb_coupon_restriction );
43
- }
44
 
45
- public function is_valid_coupon( $availability, $coupon ){
46
- $selected_brands = get_post_meta( $coupon->get_ID(), '_pwb_coupon_restriction', true );
47
- if( !empty( $selected_brands ) ){
48
- global $woocommerce;
49
- $products = $woocommerce->cart->get_cart();
50
- foreach( $products as $product ) {
51
- $product_brands = wp_get_post_terms( $product['product_id'], 'pwb-brand', array( 'fields' => 'ids' ) );
52
- $valid_brands = array_intersect( $selected_brands, $product_brands );
53
- if( !empty( $valid_brands ) ) return true;
54
- }
55
- return false;
56
- }
57
- return true;
58
- }
 
 
59
 
60
- public function is_valid_for_product_brand( $valid, $product, $coupon, $values ){
61
- if ( !$valid ) return false;
 
 
62
 
63
- $coupon_id = is_callable( array( $coupon, 'get_id' ) ) ? $coupon->get_id() : $coupon->id;
64
- $selected_brands = get_post_meta( $coupon_id, '_pwb_coupon_restriction', true );
65
- if ( empty( $selected_brands ) ) return $valid;
 
 
66
 
67
- if( $product->is_type( 'variation' ) ){
68
- $product_id = $product->get_parent_id();
69
- }else{
70
- $product_id = is_callable( array( $product, 'get_id' ) ) ? $product->get_id() : $product->id;
71
- }
72
- $product_brands = wp_get_post_terms( $product_id, 'pwb-brand', array( 'fields' => 'ids' ) );
73
- $valid_brands = array_intersect( $selected_brands, $product_brands );
74
- return !empty( $valid_brands );
75
- }
76
 
77
- }
1
  <?php
 
2
 
3
+ namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
 
7
+ class PWB_Coupon {
 
 
 
 
 
8
 
9
+ function __construct() {
10
+ add_action( 'woocommerce_coupon_options_usage_restriction', array( $this, 'coupon_restriction' ) );
11
+ add_action( 'woocommerce_coupon_options_save', array( $this, 'coupon_save' ) );
12
+ add_filter( 'woocommerce_coupon_is_valid', array( $this, 'is_valid_coupon' ), 10, 2 );
13
+ add_filter( 'woocommerce_coupon_is_valid_for_product', array( $this, 'is_valid_for_product_brand' ), 10, 4 );
14
+ }
15
 
16
+ public function coupon_restriction() {
17
+ global $thepostid, $post;
18
+ $thepostid = empty( $thepostid ) ? $post->get_ID() : $thepostid;
19
 
20
+ $selected_brands = get_post_meta( $thepostid, '_pwb_coupon_restriction', true );
21
+ if ( $selected_brands == '' ) {
22
+ $selected_brands = array();
23
+ }
24
+
25
+ ob_start();
26
+ ?>
27
+ <p class="form-field"><label for="_pwb_coupon_restriction"><?php esc_html_e( 'Brands restriction', 'perfect-woocommerce-brands' ); ?></label>
28
  <select id="_pwb_coupon_restriction" name="_pwb_coupon_restriction[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php esc_attr_e( 'Any brand', 'perfect-woocommerce-brands' ); ?>">
29
  <?php
30
+ $categories = get_terms( 'pwb-brand', 'orderby=name&hide_empty=0' );
31
+ if ( $categories ) {
32
+ foreach ( $categories as $cat ) {
33
+ echo '<option value="' . esc_attr( $cat->term_id ) . '"' . selected( in_array( $cat->term_id, $selected_brands ), true, false ) . '>' . esc_html( $cat->name ) . '</option>';
 
34
  }
35
+ }
36
  ?>
37
+ </select>
38
+ <?php
39
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
40
+ echo wc_help_tip( esc_html__( 'Coupon will be valid if there are at least one product of this brands in the cart', 'perfect-woocommerce-brands' ) );
41
+ ?>
42
+ </p>
43
+ <?php
44
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
45
+ echo ob_get_clean();
46
+
47
+ }
48
 
49
+ public function coupon_save( $post_id ) {
50
+ // phpcs:ignore WordPress.Security
51
+ $_pwb_coupon_restriction = isset( $_POST['_pwb_coupon_restriction'] ) ? sanitize_text_field( wp_unslash( $_POST['_pwb_coupon_restriction'] ) ) : '';
52
+ update_post_meta( $post_id, '_pwb_coupon_restriction', $_pwb_coupon_restriction );
53
 
54
+ }
 
 
 
55
 
56
+ public function is_valid_coupon( $availability, $coupon ) {
57
+ $selected_brands = get_post_meta( $coupon->get_ID(), '_pwb_coupon_restriction', true );
58
+ if ( ! empty( $selected_brands ) ) {
59
+ global $woocommerce;
60
+ $products = $woocommerce->cart->get_cart();
61
+ foreach ( $products as $product ) {
62
+ $product_brands = wp_get_post_terms( $product['product_id'], 'pwb-brand', array( 'fields' => 'ids' ) );
63
+ $valid_brands = array_intersect( $selected_brands, $product_brands );
64
+ if ( ! empty( $valid_brands ) ) {
65
+ return true;
66
+ }
67
+ }
68
+ return false;
69
+ }
70
+ return true;
71
+ }
72
 
73
+ public function is_valid_for_product_brand( $valid, $product, $coupon, $values ) {
74
+ if ( ! $valid ) {
75
+ return false;
76
+ }
77
 
78
+ $coupon_id = is_callable( array( $coupon, 'get_id' ) ) ? $coupon->get_id() : $coupon->id;
79
+ $selected_brands = get_post_meta( $coupon_id, '_pwb_coupon_restriction', true );
80
+ if ( empty( $selected_brands ) ) {
81
+ return $valid;
82
+ }
83
 
84
+ if ( $product->is_type( 'variation' ) ) {
85
+ $product_id = $product->get_parent_id();
86
+ } else {
87
+ $product_id = is_callable( array( $product, 'get_id' ) ) ? $product->get_id() : $product->id;
88
+ }
89
+ $product_brands = wp_get_post_terms( $product_id, 'pwb-brand', array( 'fields' => 'ids' ) );
90
+ $valid_brands = array_intersect( $selected_brands, $product_brands );
91
+ return ! empty( $valid_brands );
92
+ }
93
 
94
+ }
classes/admin/class-pwb-dummy-data.php CHANGED
@@ -2,107 +2,103 @@
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
-
7
- class PWB_Dummy_Data
8
- {
9
-
10
- function __construct()
11
- {
12
- add_action('wp_ajax_pwb_admin_dummy_data', array($this, 'admin_dummy_data'));
13
- }
14
-
15
- private static function get_attachment_id_from_src($image_src)
16
- {
17
- global $wpdb;
18
- $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'";
19
- $id = $wpdb->get_var($query);
20
- return $id;
21
- }
22
-
23
- private static function retrieve_img_src($img)
24
- {
25
- if (preg_match('/<img(\s+?)([^>]*?)src=(\"|\')([^>\\3]*?)\\3([^>]*?)>/is', $img, $m) && isset($m[4]))
26
- return $m[4];
27
- return false;
28
- }
29
-
30
- private static function upload_image($post_id, $img_url)
31
- {
32
-
33
- require_once ABSPATH . "wp-admin" . '/includes/image.php';
34
- require_once ABSPATH . "wp-admin" . '/includes/file.php';
35
- require_once ABSPATH . "wp-admin" . '/includes/media.php';
36
-
37
- //solves media_sideload_image bug with spaces in filenames
38
- $parsed_file = parse_url($img_url);
39
- $path = $parsed_file['path'];
40
- $file_name = basename($path);
41
- $encoded_file_name = rawurlencode($file_name);
42
- $path = str_replace($file_name, $encoded_file_name, $path);
43
- $img_url = $parsed_file['scheme'] . "://" . $parsed_file['host'] . $path;
44
- $image = '';
45
-
46
- preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $img_url, $file_matches);
47
- if (isset($file_matches[0])) {
48
- $image = media_sideload_image($img_url, $post_id);
49
- }
50
-
51
- //media_sideload_image returns a html image
52
- //extract the src value for get the attachment id
53
- $image_src = self::retrieve_img_src($image);
54
- return self::get_attachment_id_from_src($image_src);
55
- }
56
-
57
- private function build_description()
58
- {
59
- $desc = 'lorem ipsum dolor <strong>sit</strong> amet consectetur adipiscing elit etiam mollis faucibus aliquet';
60
- $desc .= 'sed risus turpis dapibus vel <strong>rhoncus</strong> a vestibulum sed lectus in hac habitasse platea dictumst';
61
- $desc .= 'suspendisse non luctus felis <strong>morbi</strong> id volutpat ligula quisque rutrum arcu at erat lobortis';
62
- $exploded_desc = explode(' ', $desc);
63
- shuffle($exploded_desc);
64
- $desc = implode(' ', $exploded_desc);
65
- return ucfirst($desc);
66
- }
67
-
68
- public function admin_dummy_data()
69
- {
70
-
71
- if (
72
- isset($_REQUEST['nonce'])
73
- &&
74
- wp_verify_nonce($_REQUEST['nonce'], 'pwb_admin_dummy_data')
75
- &&
76
- current_user_can('manage_options')
77
- ) {
78
-
79
- for ($i = 1; $i < 11; $i++) {
80
- $term_desc = $this->build_description();
81
- $brand_name = 'brand' . $i;
82
- $attachment_id = self::upload_image(false, PWB_PLUGIN_URL . '/assets/img/dummy-data/' . $brand_name . '.png');
83
- $inserted_brand = wp_insert_term(ucfirst($brand_name), 'pwb-brand', array("description" => $term_desc));
84
- if (!is_wp_error($inserted_brand) && isset($inserted_brand['term_id'])) {
85
- add_term_meta($inserted_brand['term_id'], 'pwb_brand_image', $attachment_id);
86
- }
87
- }
88
-
89
- $this->set_brands_randomly();
90
- }
91
-
92
- wp_die();
93
- }
94
-
95
- public function set_brands_randomly()
96
- {
97
-
98
- $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands_array();
99
-
100
- $the_query = new \WP_Query(array('posts_per_page' => -1, 'post_type' => 'product'));
101
-
102
- while ($the_query->have_posts()) {
103
- $the_query->the_post();
104
- wp_set_object_terms(get_the_ID(), array_rand($brands), 'pwb-brand');
105
- }
106
- wp_reset_postdata();
107
- }
108
  }
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class PWB_Dummy_Data {
8
+
9
+
10
+ function __construct() {
11
+ add_action( 'wp_ajax_pwb_admin_dummy_data', array( $this, 'admin_dummy_data' ) );
12
+ }
13
+
14
+ private static function get_attachment_id_from_src( $image_src ) {
15
+ global $wpdb;
16
+ $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'";
17
+ $id = $wpdb->get_var( $query );
18
+ return $id;
19
+ }
20
+
21
+ private static function retrieve_img_src( $img ) {
22
+ if ( preg_match( '/<img(\s+?)([^>]*?)src=(\"|\')([^>\\3]*?)\\3([^>]*?)>/is', $img, $m ) && isset( $m[4] ) ) {
23
+ return $m[4];
24
+ }
25
+ return false;
26
+ }
27
+
28
+ private static function upload_image( $post_id, $img_url ) {
29
+ require_once ABSPATH . 'wp-admin' . '/includes/image.php';
30
+ require_once ABSPATH . 'wp-admin' . '/includes/file.php';
31
+ require_once ABSPATH . 'wp-admin' . '/includes/media.php';
32
+
33
+ // solves media_sideload_image bug with spaces in filenames
34
+ $parsed_file = wp_parse_url( $img_url );
35
+ $path = $parsed_file['path'];
36
+ $file_name = basename( $path );
37
+ $encoded_file_name = rawurlencode( $file_name );
38
+ $path = str_replace( $file_name, $encoded_file_name, $path );
39
+ $img_url = $parsed_file['scheme'] . '://' . $parsed_file['host'] . $path;
40
+ $image = '';
41
+
42
+ preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $img_url, $file_matches );
43
+ if ( isset( $file_matches[0] ) ) {
44
+ $image = media_sideload_image( $img_url, $post_id );
45
+ }
46
+
47
+ // media_sideload_image returns a html image
48
+ // extract the src value for get the attachment id
49
+ $image_src = self::retrieve_img_src( $image );
50
+ return self::get_attachment_id_from_src( $image_src );
51
+ }
52
+
53
+ private function build_description() {
54
+ $desc = 'lorem ipsum dolor <strong>sit</strong> amet consectetur adipiscing elit etiam mollis faucibus aliquet';
55
+ $desc .= 'sed risus turpis dapibus vel <strong>rhoncus</strong> a vestibulum sed lectus in hac habitasse platea dictumst';
56
+ $desc .= 'suspendisse non luctus felis <strong>morbi</strong> id volutpat ligula quisque rutrum arcu at erat lobortis';
57
+ $exploded_desc = explode( ' ', $desc );
58
+ shuffle( $exploded_desc );
59
+ $desc = implode( ' ', $exploded_desc );
60
+ return ucfirst( $desc );
61
+ }
62
+
63
+ public function admin_dummy_data() {
64
+ if (
65
+ isset( $_REQUEST['nonce'] )
66
+ &&
67
+ wp_verify_nonce( $_REQUEST['nonce'], 'pwb_admin_dummy_data' )
68
+ &&
69
+ current_user_can( 'manage_options' )
70
+ ) {
71
+
72
+ for ( $i = 1; $i < 11; $i++ ) {
73
+ $term_desc = $this->build_description();
74
+ $brand_name = 'brand' . $i;
75
+ $attachment_id = self::upload_image( false, PWB_PLUGIN_URL . '/assets/img/dummy-data/' . $brand_name . '.png' );
76
+ $inserted_brand = wp_insert_term( ucfirst( $brand_name ), 'pwb-brand', array( 'description' => $term_desc ) );
77
+ if ( ! is_wp_error( $inserted_brand ) && isset( $inserted_brand['term_id'] ) ) {
78
+ add_term_meta( $inserted_brand['term_id'], 'pwb_brand_image', $attachment_id );
79
+ }
80
+ }
81
+
82
+ $this->set_brands_randomly();
83
+ }
84
+
85
+ wp_die();
86
+ }
87
+
88
+ public function set_brands_randomly() {
89
+ $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands_array();
90
+
91
+ $the_query = new \WP_Query(
92
+ array(
93
+ 'posts_per_page' => -1,
94
+ 'post_type' => 'product',
95
+ )
96
+ );
97
+
98
+ while ( $the_query->have_posts() ) {
99
+ $the_query->the_post();
100
+ wp_set_object_terms( get_the_ID(), array_rand( $brands ), 'pwb-brand' );
101
+ }
102
+ wp_reset_postdata();
103
+ }
 
 
 
 
104
  }
classes/admin/class-pwb-exporter-support.php CHANGED
@@ -2,39 +2,41 @@
2
 
3
  namespace Perfect_Woocommerce_Brands;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
 
7
- class PWB_Exporter_Support{
8
 
9
- function __construct(){
10
- add_filter( 'woocommerce_product_export_column_names', array( $this, 'add_export_column' ) );
11
- add_filter( 'woocommerce_product_export_product_default_columns', array( $this, 'add_export_column' ) );
12
- add_filter( 'woocommerce_product_export_product_column_pwb-brand', array( $this, 'add_export_data' ), 10, 2 );
13
- }
14
 
15
- /**
16
- * Add the custom column to the exporter and the exporter column menu.
17
- *
18
- * @param array $columns
19
- * @return array $columns
20
- */
21
- public function add_export_column( $columns ) {
22
- $columns['pwb-brand'] = esc_html__('Brand', 'perfect-woocommerce-brands');
23
- return $columns;
24
- }
25
 
26
- /**
27
- * Provide the data to be exported for one item in the column.
28
- *
29
- * @param mixed $value (default: '')
30
- * @param WC_Product $product
31
- * @return mixed $value - Should be in a format that can be output into a text file (string, numeric, etc).
32
- */
33
- public function add_export_data( $value, $product ) {
34
- $brands = wp_get_post_terms( $product->get_id(), 'pwb-brand' );
35
- $brand_names = array();
36
- foreach( $brands as $brand ) $brand_names[] = $brand->name;
37
- return implode( ',', $brand_names );
38
- }
 
 
39
 
40
  }
2
 
3
  namespace Perfect_Woocommerce_Brands;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
 
7
+ class PWB_Exporter_Support {
8
 
9
+ function __construct() {
10
+ add_filter( 'woocommerce_product_export_column_names', array( $this, 'add_export_column' ) );
11
+ add_filter( 'woocommerce_product_export_product_default_columns', array( $this, 'add_export_column' ) );
12
+ add_filter( 'woocommerce_product_export_product_column_pwb-brand', array( $this, 'add_export_data' ), 10, 2 );
13
+ }
14
 
15
+ /**
16
+ * Add the custom column to the exporter and the exporter column menu.
17
+ *
18
+ * @param array $columns
19
+ * @return array $columns
20
+ */
21
+ public function add_export_column( $columns ) {
22
+ $columns['pwb-brand'] = esc_html__( 'Brand', 'perfect-woocommerce-brands' );
23
+ return $columns;
24
+ }
25
 
26
+ /**
27
+ * Provide the data to be exported for one item in the column.
28
+ *
29
+ * @param mixed $value (default: '')
30
+ * @param WC_Product $product
31
+ * @return mixed $value - Should be in a format that can be output into a text file (string, numeric, etc).
32
+ */
33
+ public function add_export_data( $value, $product ) {
34
+ $brands = wp_get_post_terms( $product->get_id(), 'pwb-brand' );
35
+ $brand_names = array();
36
+ foreach ( $brands as $brand ) {
37
+ $brand_names[] = $brand->name;
38
+ }
39
+ return implode( ',', $brand_names );
40
+ }
41
 
42
  }
classes/admin/class-pwb-importer-support.php CHANGED
@@ -2,52 +2,54 @@
2
 
3
  namespace Perfect_Woocommerce_Brands;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
-
7
- class PWB_Importer_Support{
8
-
9
- function __construct(){
10
- add_filter( 'woocommerce_csv_product_import_mapping_options', array( $this, 'add_column_to_importer' ) );
11
- add_filter( 'woocommerce_csv_product_import_mapping_default_columns', array( $this, 'add_column_to_mapping_screen' ) );
12
- add_action( 'woocommerce_product_import_inserted_product_object', array( $this, 'process_import' ), 10, 2 );
13
- }
14
-
15
- /**
16
- * Register the 'Custom Column' column in the importer.
17
- *
18
- * @param array $options
19
- * @return array $options
20
- */
21
- public function add_column_to_importer( $options ) {
22
- $options['pwb-brand'] = esc_html__('Brand', 'perfect-woocommerce-brands');
23
- return $options;
24
- }
25
-
26
- /**
27
- * Add automatic mapping support for 'Custom Column'.
28
- *
29
- * @param array $columns
30
- * @return array $columns
31
- */
32
- public function add_column_to_mapping_screen( $columns ) {
33
- $columns[esc_html__('Brand', 'perfect-woocommerce-brands')] = 'pwb-brand';
34
- return $columns;
35
- }
36
-
37
- /**
38
- * Process the data read from the CSV file.
39
- *
40
- * @param WC_Product $object - Product being imported or updated.
41
- * @param array $data - CSV data read for the product.
42
- * @return WC_Product $object
43
- */
44
- public function process_import( $object, $data ) {
45
- if( isset( $data['pwb-brand'] ) ){
46
- wp_delete_object_term_relationships( $object->get_id(), 'pwb-brand' );
47
- $brands = explode( ',', $data['pwb-brand'] );
48
- foreach( $brands as $brand ) wp_set_object_terms( $object->get_id(), $brand, 'pwb-brand', true );
49
- }
50
- return $object;
51
- }
 
 
52
 
53
  }
2
 
3
  namespace Perfect_Woocommerce_Brands;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class PWB_Importer_Support {
8
+
9
+ function __construct() {
10
+ add_filter( 'woocommerce_csv_product_import_mapping_options', array( $this, 'add_column_to_importer' ) );
11
+ add_filter( 'woocommerce_csv_product_import_mapping_default_columns', array( $this, 'add_column_to_mapping_screen' ) );
12
+ add_action( 'woocommerce_product_import_inserted_product_object', array( $this, 'process_import' ), 10, 2 );
13
+ }
14
+
15
+ /**
16
+ * Register the 'Custom Column' column in the importer.
17
+ *
18
+ * @param array $options
19
+ * @return array $options
20
+ */
21
+ public function add_column_to_importer( $options ) {
22
+ $options['pwb-brand'] = esc_html__( 'Brand', 'perfect-woocommerce-brands' );
23
+ return $options;
24
+ }
25
+
26
+ /**
27
+ * Add automatic mapping support for 'Custom Column'.
28
+ *
29
+ * @param array $columns
30
+ * @return array $columns
31
+ */
32
+ public function add_column_to_mapping_screen( $columns ) {
33
+ $columns[ esc_html__( 'Brand', 'perfect-woocommerce-brands' ) ] = 'pwb-brand';
34
+ return $columns;
35
+ }
36
+
37
+ /**
38
+ * Process the data read from the CSV file.
39
+ *
40
+ * @param WC_Product $object - Product being imported or updated.
41
+ * @param array $data - CSV data read for the product.
42
+ * @return WC_Product $object
43
+ */
44
+ public function process_import( $object, $data ) {
45
+ if ( isset( $data['pwb-brand'] ) ) {
46
+ wp_delete_object_term_relationships( $object->get_id(), 'pwb-brand' );
47
+ $brands = explode( ',', $data['pwb-brand'] );
48
+ foreach ( $brands as $brand ) {
49
+ wp_set_object_terms( $object->get_id(), $brand, 'pwb-brand', true );
50
+ }
51
+ }
52
+ return $object;
53
+ }
54
 
55
  }
classes/admin/class-pwb-migrate.php CHANGED
@@ -2,130 +2,123 @@
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
-
7
- class PWB_Migrate
8
- {
9
-
10
- function __construct()
11
- {
12
- add_action('wp_ajax_pwb_admin_migrate_brands', array($this, 'admin_migrate_brands'));
13
- }
14
-
15
- public function admin_migrate_brands()
16
- {
17
-
18
- if (
19
- isset($_REQUEST['nonce'])
20
- &&
21
- wp_verify_nonce($_REQUEST['nonce'], 'pwb_admin_migrate_brands')
22
- &&
23
- current_user_can('manage_options')
24
- ) {
25
-
26
- if (isset($_POST['from'])) {
27
-
28
- switch ($_POST['from']) {
29
- case 'yith':
30
- $this->migrate_from_yith();
31
- break;
32
- case 'ultimate':
33
- $this->migrate_from_ultimate();
34
- break;
35
- case 'woobrands':
36
- $this->migrate_from_woobrands();
37
- break;
38
- }
39
- }
40
- }
41
-
42
- wp_die();
43
- }
44
-
45
- public function migrate_from_yith()
46
- {
47
-
48
- global $wpdb;
49
- $terms = $wpdb->get_col('SELECT term_id FROM ' . $wpdb->prefix . 'term_taxonomy WHERE taxonomy LIKE "yith_product_brand"');
50
-
51
- foreach ($terms as $term_id) {
52
-
53
- //change taxonomy
54
- $wpdb->update(
55
- $wpdb->prefix . 'term_taxonomy',
56
- array(
57
- 'taxonomy' => 'pwb-brand'
58
- ),
59
- array(
60
- 'term_id' => $term_id
61
- )
62
- );
63
-
64
- //update term meta
65
- $wpdb->update(
66
- $wpdb->prefix . 'termmeta',
67
- array(
68
- 'meta_key' => 'pwb_brand_image'
69
- ),
70
- array(
71
- 'meta_key' => 'thumbnail_id',
72
- 'term_id' => $term_id
73
- )
74
- );
75
- }
76
- }
77
-
78
- public function migrate_from_ultimate()
79
- {
80
-
81
- global $wpdb;
82
- $terms = $wpdb->get_col('SELECT term_id FROM ' . $wpdb->prefix . 'term_taxonomy WHERE taxonomy LIKE "product_brand"');
83
-
84
- foreach ($terms as $term_id) {
85
-
86
- //change taxonomy
87
- $wpdb->update(
88
- $wpdb->prefix . 'term_taxonomy',
89
- array(
90
- 'taxonomy' => 'pwb-brand'
91
- ),
92
- array(
93
- 'term_id' => $term_id
94
- )
95
- );
96
-
97
- /**
98
- * Ultimate WooCommerce Brands uses tax-meta-class, tax meta are really options
99
- * @link https://github.com/bainternet/Tax-Meta-Class
100
- */
101
- $term_meta = get_option('tax_meta_' . $term_id);
102
- if (isset($term_meta['mgwb_image_brand_thumb']['id']))
103
- add_term_meta($term_id, 'pwb_brand_image', $term_meta['mgwb_image_brand_thumb']['id']);
104
- }
105
- }
106
-
107
- public function migrate_from_woobrands()
108
- {
109
-
110
- global $wpdb;
111
- $terms = $wpdb->get_col('SELECT term_id FROM ' . $wpdb->prefix . 'term_taxonomy WHERE taxonomy LIKE "product_brand"');
112
-
113
- foreach ($terms as $term_id) {
114
-
115
- // change taxonomy
116
- $wpdb->update(
117
- $wpdb->prefix . 'term_taxonomy',
118
- array(
119
- 'taxonomy' => 'pwb-brand'
120
- ),
121
- array(
122
- 'term_id' => $term_id
123
- )
124
- );
125
-
126
- // add the logo id
127
- if ($thumb_id = get_woocommerce_term_meta($term_id, 'thumbnail_id', true))
128
- add_term_meta($term_id, 'pwb_brand_image', $thumb_id);
129
- }
130
- }
131
  }
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class PWB_Migrate {
8
+
9
+ function __construct() {
10
+ add_action( 'wp_ajax_pwb_admin_migrate_brands', array( $this, 'admin_migrate_brands' ) );
11
+ }
12
+
13
+ public function admin_migrate_brands() {
14
+ if (
15
+ isset( $_REQUEST['nonce'] )
16
+ &&
17
+ wp_verify_nonce( $_REQUEST['nonce'], 'pwb_admin_migrate_brands' )
18
+ &&
19
+ current_user_can( 'manage_options' )
20
+ ) {
21
+
22
+ if ( isset( $_POST['from'] ) ) {
23
+
24
+ switch ( $_POST['from'] ) {
25
+ case 'yith':
26
+ $this->migrate_from_yith();
27
+ break;
28
+ case 'ultimate':
29
+ $this->migrate_from_ultimate();
30
+ break;
31
+ case 'woobrands':
32
+ $this->migrate_from_woobrands();
33
+ break;
34
+ }
35
+ }
36
+ }
37
+
38
+ wp_die();
39
+ }
40
+
41
+ public function migrate_from_yith() {
42
+ global $wpdb;
43
+ $terms = $wpdb->get_col( 'SELECT term_id FROM ' . $wpdb->prefix . 'term_taxonomy WHERE taxonomy LIKE "yith_product_brand"' );
44
+
45
+ foreach ( $terms as $term_id ) {
46
+
47
+ // change taxonomy
48
+ $wpdb->update(
49
+ $wpdb->prefix . 'term_taxonomy',
50
+ array(
51
+ 'taxonomy' => 'pwb-brand',
52
+ ),
53
+ array(
54
+ 'term_id' => $term_id,
55
+ )
56
+ );
57
+
58
+ // update term meta
59
+ $wpdb->update(
60
+ $wpdb->prefix . 'termmeta',
61
+ array(
62
+ 'meta_key' => 'pwb_brand_image',
63
+ ),
64
+ array(
65
+ 'meta_key' => 'thumbnail_id',
66
+ 'term_id' => $term_id,
67
+ )
68
+ );
69
+ }
70
+ }
71
+
72
+ public function migrate_from_ultimate() {
73
+ global $wpdb;
74
+ $terms = $wpdb->get_col( 'SELECT term_id FROM ' . $wpdb->prefix . 'term_taxonomy WHERE taxonomy LIKE "product_brand"' );
75
+
76
+ foreach ( $terms as $term_id ) {
77
+
78
+ // change taxonomy
79
+ $wpdb->update(
80
+ $wpdb->prefix . 'term_taxonomy',
81
+ array(
82
+ 'taxonomy' => 'pwb-brand',
83
+ ),
84
+ array(
85
+ 'term_id' => $term_id,
86
+ )
87
+ );
88
+
89
+ /**
90
+ * Ultimate WooCommerce Brands uses tax-meta-class, tax meta are really options
91
+ *
92
+ * @link https://github.com/bainternet/Tax-Meta-Class
93
+ */
94
+ $term_meta = get_option( 'tax_meta_' . $term_id );
95
+ if ( isset( $term_meta['mgwb_image_brand_thumb']['id'] ) ) {
96
+ add_term_meta( $term_id, 'pwb_brand_image', $term_meta['mgwb_image_brand_thumb']['id'] );
97
+ }
98
+ }
99
+ }
100
+
101
+ public function migrate_from_woobrands() {
102
+ global $wpdb;
103
+ $terms = $wpdb->get_col( 'SELECT term_id FROM ' . $wpdb->prefix . 'term_taxonomy WHERE taxonomy LIKE "product_brand"' );
104
+
105
+ foreach ( $terms as $term_id ) {
106
+
107
+ // change taxonomy
108
+ $wpdb->update(
109
+ $wpdb->prefix . 'term_taxonomy',
110
+ array(
111
+ 'taxonomy' => 'pwb-brand',
112
+ ),
113
+ array(
114
+ 'term_id' => $term_id,
115
+ )
116
+ );
117
+
118
+ // add the logo id
119
+ if ( $thumb_id = get_woocommerce_term_meta( $term_id, 'thumbnail_id', true ) ) {
120
+ add_term_meta( $term_id, 'pwb_brand_image', $thumb_id );
121
+ }
122
+ }
123
+ }
 
 
 
 
 
 
 
124
  }
classes/admin/class-pwb-notices.php CHANGED
@@ -2,85 +2,90 @@
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
 
7
  class PWB_Notices {
8
 
9
- protected static $instance;
10
-
11
- function __construct() {
12
- add_filter('plugin_action_links_' . PWB_PLUGIN_BASENAME, array($this, 'add_action_links'));
13
- // add_action('admin_notices', array($this, 'add_notices'));
14
- // add_action('wp_ajax_pwb_dismiss_notice', array($this, 'ajax_dismiss_notice'));
15
- }
16
-
17
- function ajax_dismiss_notice() {
18
-
19
- if (check_admin_referer('pwb_dismiss_notice', 'nonce') && isset($_REQUEST['notice_id'])) {
20
-
21
- $notice_id = sanitize_key($_REQUEST['notice_id']);
22
-
23
- update_user_meta(get_current_user_id(), $notice_id, true);
24
-
25
- wp_send_json($notice_id);
26
- }
27
-
28
- wp_die();
29
- }
30
-
31
- function add_notices() {
32
-
33
- if (!get_transient('pwb-first-rating') && !get_user_meta(get_current_user_id(), 'pwb-user-rating', true)) {
34
- ?>
35
- <div id="pwb-admin-rating" class="pwb-notice notice is-dismissible" data-notice_id="pwb-user-rating">
36
- <div class="notice-container" style="padding-top: 10px; padding-bottom: 10px; display: flex; justify-content: left; align-items: center;">
37
- <div class="notice-image">
38
- <img style="border-radius:50%;max-width: 90px;" src="<?php echo plugins_url('/assets/img/icon_pwb.jpg', PWB_PLUGIN_FILE); ?>" alt="<?php echo esc_html(PWB_PLUGIN_NAME); ?>>">
39
- </div>
40
- <div class="notice-content" style="margin-left: 15px;">
41
- <p>
42
- <?php printf(esc_html__('Hello! Thank you for choosing the %s plugin!', 'perfect-woocommerce-brands'), PWB_PLUGIN_NAME); ?>
43
- <br/>
44
- <?php esc_html_e('Could you please give it a 5-star rating on WordPress? We know its a big favor, but we\'ve worked very much and very hard to release this great product. Your feedback will boost our motivation and help us promote and continue to improve this product.', 'perfect-woocommerce-brands'); ?>
45
- </p>
46
- <a href="<?php echo esc_url(PWB_REVIEW_URL); ?>" class="button-primary" target="_blank">
47
- <?php esc_html_e('Yes, of course!', 'perfect-woocommerce-brands'); ?>
48
- </a>
49
- <a href="<?php echo esc_url(PWB_SUPPORT_URL); ?>" class="button-secondary" target="_blank">
50
- <?php esc_html_e('Report a bug', 'perfect-woocommerce-brands'); ?>
51
- </a>
52
- </div>
53
- </div>
54
- </div>
55
- <script>
56
- (function ($) {
57
- $('.pwb-notice').on('click', '.notice-dismiss', function (e) {
58
- e.preventDefault();
59
- var notice_id = $(e.delegateTarget).data('notice_id');
60
- $.ajax({
61
- type: 'POST',
62
- url: ajaxurl,
63
- data: {
64
- notice_id: notice_id,
65
- action: 'pwb_dismiss_notice',
66
- nonce: '<?php echo wp_create_nonce('pwb_dismiss_notice'); ?>'
67
- },
68
- success: function (response) {
69
- console.log(response);
70
- },
71
- });
72
- });
73
- })(jQuery);
74
- </script>
75
- <?php
76
- }
77
- }
78
-
79
- public function add_action_links($links) {
80
-
81
- $links[] = '<a href="' . esc_url(admin_url('admin.php?page=wc-settings&tab=pwb_admin_tab')) . '">' . esc_html__('Settings', 'perfect-woocommerce-brands') . '</a>';
82
-
83
- return $links;
84
- }
 
 
 
 
 
85
 
86
  }
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
 
7
  class PWB_Notices {
8
 
9
+ protected static $instance;
10
+
11
+ function __construct() {
12
+ add_filter( 'plugin_action_links_' . PWB_PLUGIN_BASENAME, array( $this, 'add_action_links' ) );
13
+ // add_action('admin_notices', array($this, 'add_notices'));
14
+ // add_action('wp_ajax_pwb_dismiss_notice', array($this, 'ajax_dismiss_notice'));
15
+ }
16
+
17
+ function ajax_dismiss_notice() {
18
+
19
+ if ( check_admin_referer( 'pwb_dismiss_notice', 'nonce' ) && isset( $_REQUEST['notice_id'] ) ) {
20
+
21
+ $notice_id = sanitize_key( $_REQUEST['notice_id'] );
22
+
23
+ update_user_meta( get_current_user_id(), $notice_id, true );
24
+
25
+ wp_send_json( $notice_id );
26
+ }
27
+
28
+ wp_die();
29
+ }
30
+
31
+ function add_notices() {
32
+
33
+ if ( ! get_transient( 'pwb-first-rating' ) && ! get_user_meta( get_current_user_id(), 'pwb-user-rating', true ) ) {
34
+ ?>
35
+ <div id="pwb-admin-rating" class="pwb-notice notice is-dismissible" data-notice_id="pwb-user-rating">
36
+ <div class="notice-container" style="padding-top: 10px; padding-bottom: 10px; display: flex; justify-content: left; align-items: center;">
37
+ <div class="notice-image">
38
+ <img style="border-radius:50%;max-width: 90px;" src="<?php echo esc_url( plugins_url( '/assets/img/icon_pwb.jpg', PWB_PLUGIN_FILE ) ); ?>" alt="<?php echo esc_html( PWB_PLUGIN_NAME ); ?>>">
39
+ </div>
40
+ <div class="notice-content" style="margin-left: 15px;">
41
+ <p>
42
+ <?php printf( esc_html__( 'Hello! Thank you for choosing the %s plugin!', 'perfect-woocommerce-brands' ), esc_html( PWB_PLUGIN_NAME ) ); ?>
43
+ <br/>
44
+ <?php esc_html_e( 'Could you please give it a 5-star rating on WordPress? We know its a big favor, but we\'ve worked very much and very hard to release this great product. Your feedback will boost our motivation and help us promote and continue to improve this product.', 'perfect-woocommerce-brands' ); ?>
45
+ </p>
46
+ <a href="<?php echo esc_url( PWB_REVIEW_URL ); ?>" class="button-primary" target="_blank">
47
+ <?php esc_html_e( 'Yes, of course!', 'perfect-woocommerce-brands' ); ?>
48
+ </a>
49
+ <a href="<?php echo esc_url( PWB_SUPPORT_URL ); ?>" class="button-secondary" target="_blank">
50
+ <?php esc_html_e( 'Report a bug', 'perfect-woocommerce-brands' ); ?>
51
+ </a>
52
+ </div>
53
+ </div>
54
+ </div>
55
+ <script>
56
+ (function ($) {
57
+ $('.pwb-notice').on('click', '.notice-dismiss', function (e) {
58
+ e.preventDefault();
59
+ var notice_id = $(e.delegateTarget).data('notice_id');
60
+ $.ajax({
61
+ type: 'POST',
62
+ url: ajaxurl,
63
+ data: {
64
+ notice_id: notice_id,
65
+ action: 'pwb_dismiss_notice',
66
+ nonce: '
67
+ <?php
68
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
69
+ echo wp_create_nonce( 'pwb_dismiss_notice' );
70
+ ?>
71
+ '
72
+ },
73
+ success: function (response) {
74
+ console.log(response);
75
+ },
76
+ });
77
+ });
78
+ })(jQuery);
79
+ </script>
80
+ <?php
81
+ }
82
+ }
83
+
84
+ public function add_action_links( $links ) {
85
+
86
+ $links[] = '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=pwb_admin_tab' ) ) . '">' . esc_html__( 'Settings', 'perfect-woocommerce-brands' ) . '</a>';
87
+
88
+ return $links;
89
+ }
90
 
91
  }
classes/admin/class-pwb-suggestions.php CHANGED
@@ -2,121 +2,118 @@
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
-
7
- class PWB_Suggestions
8
- {
9
-
10
- public function __construct()
11
- {
12
- add_action('admin_menu', array($this, 'add_menu'));
13
- add_action('admin_init', array($this, 'add_redirect'));
14
- add_action('admin_head', array($this, 'remove_menu'));
15
- add_filter('network_admin_url', array($this, 'network_admin_url'), 10, 2);
16
- }
17
-
18
- // Admin
19
- // -------------------------------------------------------------------------
20
-
21
- public function add_page()
22
- {
23
- include_once(PWB_PLUGIN_DIR . 'classes/class-pwb-suggestions-list.php');
24
- ?>
25
- <style>
26
- @media screen and (max-width: 2299px) and (min-width: 1600px) {
27
-
28
- #the-list {
29
- display: flex;
30
- flex-wrap: wrap;
31
- }
32
-
33
- .plugin-card {
34
- margin: 8px !important;
35
- width: calc(50% - 4px - 16px) !important;
36
- }
37
- }
38
- </style>
39
- <div class="wrap about-wrap full-width-layout">
40
-
41
- <h1><?php esc_html_e('Suggestions', 'perfect-woocommerce-brands'); ?></h1>
42
-
43
- <p class="about-text"><?php printf(esc_html__('Thanks for using our product! We recommend these extensions that will add new features to stand out your business and improve your sales.', 'perfect-woocommerce-brands'), PWB_PLUGIN_NAME); ?></p>
44
-
45
- <p class="about-text">
46
- <?php printf('<a href="%s" target="_blank">%s</a>', PWB_PURCHASE_URL, esc_html__('Purchase', 'perfect-woocommerce-brands')); ?></a> |
47
- <?php printf('<a href="%s" target="_blank">%s</a>', PWB_DOCUMENTATION_URL, esc_html__('Documentation', 'perfect-woocommerce-brands')); ?></a>
48
- </p>
49
-
50
- <?php printf('<a href="%s" target="_blank"><div style="
51
- background: #006bff url(%s) no-repeat;
52
- background-position: top center;
53
- background-size: 130px 130px;
54
- color: #fff;
55
- font-size: 14px;
56
- text-align: center;
57
- font-weight: 600;
58
- margin: 5px 0 0;
59
- padding-top: 120px;
60
- height: 40px;
61
- display: inline-block;
62
- width: 140px;
63
- " class="wp-badge">%s</div></a>', 'https://quadlayers.com/?utm_source=pwb_admin', plugins_url('/assets/img/quadlayers.jpg', PWB_PLUGIN_FILE), esc_html__('QuadLayers', 'perfect-woocommerce-brands')); ?>
64
-
65
- </div>
66
- <div class="wrap" style="
67
- position: relative;
68
- margin: 25px 40px 0 20px;
69
- max-width: 1200px;">
70
- <?php
71
- $wp_list_table = new \Perfect_Woocommerce_Brands\PWB_Suggestions_List_Table();
72
- $wp_list_table->prepare_items();
73
- ?>
74
- <form id="plugin-filter" method="post" class="importer-item">
75
- <?php $wp_list_table->display(); ?>
76
- </form>
77
- </div>
78
- <?php
79
- }
80
-
81
- public function add_menu()
82
- {
83
- add_menu_page(PWB_PLUGIN_NAME, PWB_PLUGIN_NAME, 'manage_woocommerce', PWB_PREFIX, array($this, 'add_page'));
84
- add_submenu_page(PWB_PREFIX, esc_html__('Suggestions', 'perfect-woocommerce-brands'), esc_html__('Suggestions', 'perfect-woocommerce-brands'), 'manage_woocommerce', PWB_PREFIX . '_suggestions', array($this, 'add_page'));
85
- }
86
-
87
- // fix for activateUrl on install now button
88
- public function network_admin_url($url, $path)
89
- {
90
-
91
- if (wp_doing_ajax() && !is_network_admin()) {
92
- if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'install-plugin') {
93
- if (strpos($url, 'plugins.php') !== false) {
94
- $url = self_admin_url($path);
95
- }
96
- }
97
- }
98
-
99
- return $url;
100
- }
101
-
102
- public function add_redirect()
103
- {
104
-
105
- if (isset($_REQUEST['activate']) && $_REQUEST['activate'] == 'true') {
106
- if (wp_get_referer() == admin_url('admin.php?page=' . PWB_PREFIX . '_suggestions')) {
107
- wp_redirect(admin_url('admin.php?page=' . PWB_PREFIX . '_suggestions'));
108
- }
109
- }
110
- }
111
-
112
- public function remove_menu()
113
- {
114
- ?>
115
- <style>
116
- li.toplevel_page_<?php echo PWB_PREFIX; ?> {
117
- display: none;
118
- }
119
- </style>
120
- <?php
121
- }
122
  }
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class PWB_Suggestions {
8
+
9
+ public function __construct() {
10
+ add_action( 'admin_menu', array( $this, 'add_menu' ) );
11
+ add_action( 'admin_init', array( $this, 'add_redirect' ) );
12
+ add_action( 'admin_head', array( $this, 'remove_menu' ) );
13
+ add_filter( 'network_admin_url', array( $this, 'network_admin_url' ), 10, 2 );
14
+ }
15
+
16
+ // Admin
17
+ // -------------------------------------------------------------------------
18
+
19
+ public function add_page() {
20
+ include_once PWB_PLUGIN_DIR . 'classes/class-pwb-suggestions-list-table.php';
21
+ ?>
22
+ <style>
23
+ @media screen and (max-width: 2299px) and (min-width: 1600px) {
24
+ #the-list {
25
+ display: flex;
26
+ flex-wrap: wrap;
27
+ }
28
+
29
+ .plugin-card {
30
+ margin: 8px !important;
31
+ width: calc(50% - 4px - 16px) !important;
32
+ }
33
+ }
34
+ </style>
35
+ <div class="wrap about-wrap full-width-layout">
36
+
37
+ <h1><?php esc_html_e( 'Suggestions', 'perfect-woocommerce-brands' ); ?></h1>
38
+
39
+ <p class="about-text"><?php printf( esc_html__( 'Thanks for using our product! We recommend these extensions that will add new features to stand out your business and improve your sales.', 'perfect-woocommerce-brands' ), esc_html( PWB_PLUGIN_NAME ) ); ?></p>
40
+
41
+ <p class="about-text">
42
+ <?php printf( '<a href="%s" target="_blank">%s</a>', esc_html( PWB_PURCHASE_URL ), esc_html__( 'Purchase', 'perfect-woocommerce-brands' ) ); ?></a> |
43
+ <?php printf( '<a href="%s" target="_blank">%s</a>', esc_html( PWB_DOCUMENTATION_URL ), esc_html__( 'Documentation', 'perfect-woocommerce-brands' ) ); ?></a>
44
+ </p>
45
+ <?php
46
+ printf(
47
+ '<a href="%s" target="_blank"><div style="
48
+ background: #006bff url(%s) no-repeat;
49
+ background-position: top center;
50
+ background-size: 130px 130px;
51
+ color: #fff;
52
+ font-size: 14px;
53
+ text-align: center;
54
+ font-weight: 600;
55
+ margin: 5px 0 0;
56
+ padding-top: 120px;
57
+ height: 40px;
58
+ display: inline-block;
59
+ width: 140px;
60
+ " class="wp-badge">%s</div></a>',
61
+ 'https://quadlayers.com/?utm_source=pwb_admin',
62
+ esc_url( plugins_url( '/assets/img/quadlayers.jpg', PWB_PLUGIN_FILE ) ),
63
+ esc_html__( 'QuadLayers', 'perfect-woocommerce-brands' )
64
+ );
65
+ ?>
66
+
67
+ </div>
68
+ <div class="wrap" style="
69
+ position: relative;
70
+ margin: 25px 40px 0 20px;
71
+ max-width: 1200px;">
72
+ <?php
73
+ $wp_list_table = new \Perfect_Woocommerce_Brands\PWB_Suggestions_List_Table();
74
+ $wp_list_table->prepare_items();
75
+ ?>
76
+ <form id="plugin-filter" method="post" class="importer-item">
77
+ <?php $wp_list_table->display(); ?>
78
+ </form>
79
+ </div>
80
+ <?php
81
+ }
82
+
83
+ public function add_menu() {
84
+ add_menu_page( PWB_PLUGIN_NAME, PWB_PLUGIN_NAME, 'manage_woocommerce', PWB_PREFIX, array( $this, 'add_page' ) );
85
+ add_submenu_page( PWB_PREFIX, esc_html__( 'Suggestions', 'perfect-woocommerce-brands' ), esc_html__( 'Suggestions', 'perfect-woocommerce-brands' ), 'manage_woocommerce', PWB_PREFIX . '_suggestions', array( $this, 'add_page' ) );
86
+ }
87
+
88
+ // fix for activateUrl on install now button
89
+ public function network_admin_url( $url, $path ) {
90
+ if ( wp_doing_ajax() && ! is_network_admin() ) {
91
+ if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'install-plugin' ) {
92
+ if ( strpos( $url, 'plugins.php' ) !== false ) {
93
+ $url = self_admin_url( $path );
94
+ }
95
+ }
96
+ }
97
+
98
+ return $url;
99
+ }
100
+
101
+ public function add_redirect() {
102
+ if ( isset( $_REQUEST['activate'] ) && $_REQUEST['activate'] == 'true' ) {
103
+ if ( wp_get_referer() == admin_url( 'admin.php?page=' . PWB_PREFIX . '_suggestions' ) ) {
104
+ wp_safe_redirect( admin_url( 'admin.php?page=' . PWB_PREFIX . '_suggestions' ) );
105
+ exit();
106
+ }
107
+ }
108
+ }
109
+
110
+ public function remove_menu() {
111
+ ?>
112
+ <style>
113
+ li.toplevel_page_<?php echo esc_attr( PWB_PREFIX ); ?> {
114
+ display: none;
115
+ }
116
+ </style>
117
+ <?php
118
+ }
 
 
 
119
  }
classes/admin/class-pwb-system-status.php CHANGED
@@ -2,75 +2,73 @@
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
 
7
- class PWB_System_Status
8
- {
9
 
10
- function __construct()
11
- {
12
- add_action('wp_ajax_pwb_system_status', array($this, 'system_status'));
13
- }
14
 
15
- public function system_status()
16
- {
17
- if (
18
- isset($_REQUEST['nonce'])
19
- &&
20
- wp_verify_nonce($_REQUEST['nonce'], 'pwb_system_status')
21
- &&
22
- current_user_can('manage_options')
23
- ) {
24
 
25
- print_r(array(
26
- 'home_url' => get_option('home'),
27
- 'site_url' => get_option('siteurl'),
28
- 'version' => WC()->version,
29
- 'wp_version' => get_bloginfo('version'),
30
- 'wp_multisite' => is_multisite(),
31
- 'wp_memory_limit' => WP_MEMORY_LIMIT,
32
- 'wp_debug_mode' => (defined('WP_DEBUG') && WP_DEBUG),
33
- 'wp_cron' => !(defined('DISABLE_WP_CRON') && DISABLE_WP_CRON),
34
- 'language' => get_locale(),
35
- 'server_info' => $_SERVER['SERVER_SOFTWARE'],
36
- 'php_version' => phpversion(),
37
- 'php_post_max_size' => ini_get('post_max_size'),
38
- 'php_max_execution_time' => ini_get('max_execution_time'),
39
- 'php_max_input_vars' => ini_get('max_input_vars'),
40
- 'max_upload_size' => wp_max_upload_size(),
41
- 'default_timezone' => date_default_timezone_get(),
42
- 'theme' => $this->theme_info(),
43
- 'active_plugins' => get_option('active_plugins'),
44
- 'pwb_options' => $this->pwb_options()
45
- ));
46
- }
47
 
48
- wp_die();
49
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- private function theme_info()
52
- {
53
- $current_theme = wp_get_theme();
54
- return array(
55
- 'name' => $current_theme->__get('name'),
56
- 'version' => $current_theme->__get('version'),
57
- 'parent_theme' => $current_theme->__get('parent_theme')
58
- );
59
- }
60
 
61
- private function pwb_options()
62
- {
63
- return array(
64
- 'version' => PWB_PLUGIN_VERSION,
65
- 'wc_pwb_admin_tab_brand_single_position' => get_option('wc_pwb_admin_tab_brand_single_position'),
66
- 'old_wc_pwb_admin_tab_slug' => get_option('old_wc_pwb_admin_tab_slug'),
67
- 'wc_pwb_notice_plugin_review' => get_option('wc_pwb_notice_plugin_review'),
68
- 'wc_pwb_admin_tab_slug' => get_option('wc_pwb_admin_tab_slug'),
69
- 'wc_pwb_admin_tab_brand_desc' => get_option('wc_pwb_admin_tab_brand_desc'),
70
- 'wc_pwb_admin_tab_brand_single_product_tab' => get_option('wc_pwb_admin_tab_brand_single_product_tab'),
71
- 'wc_pwb_admin_tab_brands_in_loop' => get_option('wc_pwb_admin_tab_brands_in_loop'),
72
- 'wc_pwb_admin_tab_brands_in_single' => get_option('wc_pwb_admin_tab_brands_in_single'),
73
- 'wc_pwb_admin_tab_brand_logo_size' => get_option('wc_pwb_admin_tab_brand_logo_size')
74
- );
75
- }
 
 
 
 
 
 
 
 
76
  }
2
 
3
  namespace Perfect_Woocommerce_Brands\Admin;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
 
7
+ class PWB_System_Status {
 
8
 
 
 
 
 
9
 
10
+ function __construct() {
11
+ add_action( 'wp_ajax_pwb_system_status', array( $this, 'system_status' ) );
12
+ }
 
 
 
 
 
 
13
 
14
+ public function system_status() {
15
+ if (
16
+ isset( $_REQUEST['nonce'] )
17
+ &&
18
+ wp_verify_nonce( $_REQUEST['nonce'], 'pwb_system_status' )
19
+ &&
20
+ current_user_can( 'manage_options' )
21
+ ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ print_r(
24
+ array(
25
+ 'home_url' => get_option( 'home' ),
26
+ 'site_url' => get_option( 'siteurl' ),
27
+ 'version' => WC()->version,
28
+ 'wp_version' => get_bloginfo( 'version' ),
29
+ 'wp_multisite' => is_multisite(),
30
+ 'wp_memory_limit' => WP_MEMORY_LIMIT,
31
+ 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
32
+ 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),
33
+ 'language' => get_locale(),
34
+ 'server_info' => $_SERVER['SERVER_SOFTWARE'],
35
+ 'php_version' => phpversion(),
36
+ 'php_post_max_size' => ini_get( 'post_max_size' ),
37
+ 'php_max_execution_time' => ini_get( 'max_execution_time' ),
38
+ 'php_max_input_vars' => ini_get( 'max_input_vars' ),
39
+ 'max_upload_size' => wp_max_upload_size(),
40
+ 'default_timezone' => date_default_timezone_get(),
41
+ 'theme' => $this->theme_info(),
42
+ 'active_plugins' => get_option( 'active_plugins' ),
43
+ 'pwb_options' => $this->pwb_options(),
44
+ )
45
+ );
46
+ }
47
 
48
+ wp_die();
49
+ }
 
 
 
 
 
 
 
50
 
51
+ private function theme_info() {
52
+ $current_theme = wp_get_theme();
53
+ return array(
54
+ 'name' => $current_theme->__get( 'name' ),
55
+ 'version' => $current_theme->__get( 'version' ),
56
+ 'parent_theme' => $current_theme->__get( 'parent_theme' ),
57
+ );
58
+ }
59
+
60
+ private function pwb_options() {
61
+ return array(
62
+ 'version' => PWB_PLUGIN_VERSION,
63
+ 'wc_pwb_admin_tab_brand_single_position' => get_option( 'wc_pwb_admin_tab_brand_single_position' ),
64
+ 'old_wc_pwb_admin_tab_slug' => get_option( 'old_wc_pwb_admin_tab_slug' ),
65
+ 'wc_pwb_notice_plugin_review' => get_option( 'wc_pwb_notice_plugin_review' ),
66
+ 'wc_pwb_admin_tab_slug' => get_option( 'wc_pwb_admin_tab_slug' ),
67
+ 'wc_pwb_admin_tab_brand_desc' => get_option( 'wc_pwb_admin_tab_brand_desc' ),
68
+ 'wc_pwb_admin_tab_brand_single_product_tab' => get_option( 'wc_pwb_admin_tab_brand_single_product_tab' ),
69
+ 'wc_pwb_admin_tab_brands_in_loop' => get_option( 'wc_pwb_admin_tab_brands_in_loop' ),
70
+ 'wc_pwb_admin_tab_brands_in_single' => get_option( 'wc_pwb_admin_tab_brands_in_single' ),
71
+ 'wc_pwb_admin_tab_brand_logo_size' => get_option( 'wc_pwb_admin_tab_brand_logo_size' ),
72
+ );
73
+ }
74
  }
classes/class-perfect-woocommerce-brands.php CHANGED
@@ -2,1011 +2,1046 @@
2
 
3
  namespace Perfect_Woocommerce_Brands;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
-
7
- class Perfect_Woocommerce_Brands
8
- {
9
-
10
- function __construct()
11
- {
12
- add_action('plugin_row_meta', array('\Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands', 'plugin_row_meta'), 10, 2);
13
- add_action('woocommerce_init', array($this, 'register_brands_taxonomy'), 10, 0);
14
- add_action('init', array($this, 'add_brands_metafields'));
15
- add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
16
- add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
17
- $this->brand_logo_position();
18
- add_action('wp', array($this, 'brand_desc_position'));
19
- add_action('woocommerce_after_shop_loop_item_title', array($this, 'show_brands_in_loop'));
20
- $this->add_shortcodes();
21
- if (is_plugin_active('js_composer/js_composer.php') || is_plugin_active('visual_composer/js_composer.php')) {
22
- add_action('vc_before_init', array($this, 'vc_map_shortcodes'));
23
- }
24
- add_action('widgets_init', array($this, 'register_widgets'));
25
- add_filter('woocommerce_structured_data_product', array($this, 'product_microdata'), 10, 2);
26
- add_action('pre_get_posts', array($this, 'pwb_brand_filter'));
27
- add_action('wp_ajax_pwb_dismiss_notice', array($this, 'dismiss_notice'));
28
- add_action('admin_notices', array($this, 'review_notice'));
29
-
30
- add_action('wp', function () {
31
- if (is_tax('pwb-brand'))
32
- remove_action('woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10);
33
- });
34
- add_action('woocommerce_product_duplicate', array($this, 'product_duplicate_save'), 10, 2);
35
-
36
- add_filter('woocommerce_get_breadcrumb', array($this, 'breadcrumbs'));
37
-
38
- add_filter('shortcode_atts_products', array($this, 'extend_products_shortcode_atts'), 10, 4);
39
- add_filter('woocommerce_shortcode_products_query', array($this, 'extend_products_shortcode'), 10, 2);
40
-
41
- add_filter('manage_edit-product_sortable_columns', array($this, 'brands_column_sortable'), 90);
42
- add_action('posts_clauses', array($this, 'brands_column_sortable_posts'), 10, 2);
43
- add_filter('post_type_link', array($this, 'brand_name_in_url'), 10, 2);
44
- add_action('pre_get_posts', array($this, 'search_by_brand_name'));
45
-
46
- //clean caches
47
- add_action('edited_terms', array($this, 'clean_caches'), 10, 2);
48
- add_action('created_term', array($this, 'clean_caches_after_edit_brand'), 10, 3);
49
- add_action('delete_term', array($this, 'clean_caches_after_edit_brand'), 10, 3);
50
- }
51
-
52
- public function clean_caches($term_id, $taxonomy)
53
- {
54
- if ($taxonomy != 'pwb-brand')
55
- return;
56
- delete_transient('pwb_az_listing_cache');
57
- }
58
-
59
- public function clean_caches_after_edit_brand($term_id, $tt_id, $taxonomy)
60
- {
61
- if ($taxonomy != 'pwb-brand')
62
- return;
63
- delete_transient('pwb_az_listing_cache');
64
- }
65
-
66
- /**
67
- * Show row meta on the plugin screen.
68
- *
69
- * @param mixed $links Plugin Row Meta.
70
- * @param mixed $file Plugin Base file.
71
- *
72
- * @return array
73
- */
74
- public static function plugin_row_meta($links, $file)
75
- {
76
- if (PWB_PLUGIN_BASENAME === $file) {
77
- $row_meta = array(
78
- 'docs' => '<a target="_blank" rel="noopener noferrer" href="' . PWB_DOCUMENTATION_URL . '">' . esc_html__('Documentation', 'perfect-woocommerce-brands') . '</a>',
79
- );
80
- return array_merge($links, $row_meta);
81
- }
82
- return (array) $links;
83
- }
84
-
85
- public function brand_name_in_url($permalink, $post)
86
- {
87
- if ($post->post_type == 'product' && strpos($permalink, '%pwb-brand%') !== false) {
88
- $term = 'product';
89
- $brands = wp_get_post_terms($post->ID, 'pwb-brand');
90
- if (!empty($brands) && !is_wp_error($brands))
91
- $term = current($brands)->slug;
92
- $permalink = str_replace('%pwb-brand%', $term, $permalink);
93
- }
94
- return $permalink;
95
- }
96
-
97
- public function brands_column_sortable_posts($clauses, $wp_query)
98
- {
99
- global $wpdb;
100
-
101
- if (isset($wp_query->query['orderby']) && 'taxonomy-pwb-brand' == $wp_query->query['orderby']) {
102
-
103
- $clauses['join'] .= "
104
  LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
105
  LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
106
  LEFT OUTER JOIN {$wpdb->terms} USING (term_id)";
107
 
108
- $clauses['where'] .= " AND (taxonomy = 'pwb-brand' OR taxonomy IS NULL)";
109
- $clauses['groupby'] = "object_id";
110
- $clauses['orderby'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) ";
111
- $clauses['orderby'] .= ('ASC' == strtoupper($wp_query->get('order'))) ? 'ASC' : 'DESC';
112
- }
113
-
114
- return $clauses;
115
- }
116
-
117
- public function brands_column_sortable($columns)
118
- {
119
- $columns['taxonomy-pwb-brand'] = 'taxonomy-pwb-brand';
120
- return $columns;
121
- }
122
-
123
- public function extend_products_shortcode_atts($out, $pairs, $atts, $shortcode)
124
- {
125
- if (!empty($atts['brands']))
126
- $out['brands'] = explode(',', $atts['brands']);
127
- return $out;
128
- }
129
-
130
- public function extend_products_shortcode($query_args, $atts)
131
- {
132
-
133
- if (!empty($atts['brands'])) {
134
- global $wpdb;
135
-
136
- $terms = $atts['brands'];
137
- $terms_count = count($atts['brands']);
138
- $terms_adapted = '';
139
-
140
- $terms_i = 0;
141
- foreach ($terms as $brand) {
142
- $terms_adapted .= '"' . $brand . '"';
143
- $terms_i++;
144
- if ($terms_i < $terms_count)
145
- $terms_adapted .= ',';
146
- }
147
-
148
- $ids = $wpdb->get_col("
149
  SELECT DISTINCT tr.object_id
150
  FROM {$wpdb->prefix}term_relationships as tr
151
  INNER JOIN {$wpdb->prefix}term_taxonomy as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
152
  INNER JOIN {$wpdb->prefix}terms as t ON tt.term_id = t.term_id
153
  WHERE tt.taxonomy LIKE 'pwb_brand' AND t.slug IN ($terms_adapted)
154
- ");
155
-
156
- if (!empty($ids)) {
157
- if (1 === count($ids)) {
158
- $query_args['p'] = $ids[0];
159
- } else {
160
- $query_args['post__in'] = $ids;
161
- }
162
- }
163
- }
164
-
165
- return $query_args;
166
- }
167
-
168
- public function review_notice()
169
- {
170
- $show_notice = get_option('wc_pwb_notice_plugin_review', true);
171
- $activate_on = get_option('pwb_activate_on', time());
172
- $now = time();
173
- $one_week = 604800;
174
- $date_diff = $now - $activate_on;
175
-
176
- if ($show_notice && $date_diff > $one_week) {
177
- ?>
178
- <div class="notice notice-info pwb-notice-dismissible is-dismissible" data-notice="wc_pwb_notice_plugin_review">
179
- <p><?php echo esc_html__('We know that you´re in love with Perfect WooCommerce Brands, you can help us making it a bit better. Thanks a lot!', 'perfect-woocommerce-brands'); ?><span class="dashicons dashicons-heart"></span></p>
180
- <p>
181
- <a href="https://wordpress.org/support/plugin/perfect-woocommerce-brands/reviews/?rate=5#new-post" target="_blank"><?php esc_html_e('Leave a review', 'perfect-woocommerce-brands'); ?></a>
182
- <a href="https://translate.wordpress.org/projects/wp-plugins/perfect-woocommerce-brands" target="_blank"><?php esc_html_e('Translate the plugin', 'perfect-woocommerce-brands'); ?></a>
183
- <a href="<?php echo esc_url(PWB_GITHUB_URL); ?>" target="_blank"><?php esc_html_e('View on GitHub', 'perfect-woocommerce-brands'); ?></a>
184
- </p>
185
- </div>
186
- <?php
187
- }
188
- }
189
-
190
- public function dismiss_notice()
191
- {
192
-
193
- if (
194
- isset($_REQUEST['nonce'])
195
- &&
196
- wp_verify_nonce($_REQUEST['nonce'], 'pwb_dismiss_notice')
197
- &&
198
- current_user_can('manage_options')
199
- ) {
200
-
201
- $notice_name_whitelist = array('wc_pwb_notice_plugin_review');
202
-
203
- if (isset($_POST['notice_name']) && in_array($_POST['notice_name'], $notice_name_whitelist)) {
204
-
205
- $notice_key = sanitize_key($_POST['notice_name']);
206
-
207
- update_option($notice_key, 0);
208
- echo 'ok';
209
- } else {
210
- echo 'error';
211
- }
212
- }
213
- wp_die();
214
- }
215
-
216
- public function pwb_brand_filter($query)
217
- {
218
-
219
- if (!empty($_GET['pwb-brand-filter'])) {
220
-
221
- $terms_array = explode(',', sanitize_text_field($_GET['pwb-brand-filter']));
222
-
223
- //remove invalid terms (security)
224
- for ($i = 0; $i < count($terms_array); $i++) {
225
- if (!term_exists($terms_array[$i], 'pwb-brand'))
226
- unset($terms_array[$i]);
227
- }
228
-
229
- $filterable_product = false;
230
- if (is_product_taxonomy() || is_post_type_archive('product'))
231
- $filterable_product = true;
232
-
233
- if ($filterable_product && $query->is_main_query()) {
234
-
235
- $query->set('tax_query', array(
236
- array(
237
- 'taxonomy' => 'pwb-brand',
238
- 'field' => 'slug',
239
- 'terms' => $terms_array
240
- )
241
- ));
242
- }
243
- }
244
- }
245
-
246
- /*
247
- * Adds microdata (brands) to single products
248
- */
249
-
250
- public function product_microdata($markup, $product)
251
- {
252
- $new_markup = array();
253
- $brands = wp_get_post_terms($product->get_id(), 'pwb-brand');
254
- foreach ($brands as $brand) {
255
- $new_markup['brand'][] = [
256
- '@type' => 'Brand',
257
- 'name' => $brand->name
258
- ];
259
- // $new_markup['brand'][] = $brand->name;
260
- }
261
-
262
- return array_merge($markup, $new_markup);
263
- }
264
-
265
- public function add_shortcodes()
266
- {
267
- add_shortcode('pwb-carousel', array(
268
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Carousel_Shortcode',
269
- 'carousel_shortcode'
270
- ));
271
- add_shortcode('pwb-product-carousel', array(
272
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Product_Carousel_Shortcode',
273
- 'product_carousel_shortcode'
274
- ));
275
- add_shortcode('pwb-all-brands', array(
276
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_All_Brands_Shortcode',
277
- 'all_brands_shortcode'
278
- ));
279
- add_shortcode('pwb-az-listing', array(
280
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_AZ_Listing_Shortcode',
281
- 'shortcode'
282
- ));
283
- add_shortcode('pwb-brand', array(
284
- '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Brand_Shortcode',
285
- 'brand_shortcode'
286
- ));
287
- }
288
-
289
- public function register_widgets()
290
- {
291
- register_widget('\Perfect_Woocommerce_Brands\Widgets\PWB_List_Widget');
292
- register_widget('\Perfect_Woocommerce_Brands\Widgets\PWB_Dropdown_Widget');
293
- register_widget('\Perfect_Woocommerce_Brands\Widgets\PWB_Filter_By_Brand_Widget');
294
- }
295
-
296
- public function show_brands_in_loop()
297
- {
298
-
299
- $brands_in_loop = get_option('wc_pwb_admin_tab_brands_in_loop');
300
- $image_size_selected = get_option('wc_pwb_admin_tab_brand_logo_size', 'thumbnail');
301
-
302
- if ($brands_in_loop == 'brand_link' || $brands_in_loop == 'brand_image') {
303
-
304
- global $product;
305
- $product_id = $product->get_id();
306
- $product_brands = wp_get_post_terms($product_id, 'pwb-brand');
307
- if (!empty($product_brands)) {
308
- echo '<div class="pwb-brands-in-loop">';
309
- foreach ($product_brands as $brand) {
310
-
311
- echo '<span>';
312
- $brand_link = get_term_link($brand->term_id, 'pwb-brand');
313
- $attachment_id = get_term_meta($brand->term_id, 'pwb_brand_image', 1);
314
-
315
- $attachment_html = wp_get_attachment_image($attachment_id, $image_size_selected);
316
- if (!empty($attachment_html) && $brands_in_loop == 'brand_image') {
317
- echo '<a href="' . $brand_link . '">' . $attachment_html . '</a>';
318
- } else {
319
- echo '<a href="' . $brand_link . '">' . $brand->name . '</a>';
320
- }
321
- echo '</span>';
322
- }
323
- echo '</div>';
324
- }
325
- }
326
- }
327
-
328
- /**
329
- * woocommerce_single_product_summary hook.
330
- *
331
- * @hooked woocommerce_template_single_title - 5
332
- * @hooked woocommerce_template_single_rating - 10
333
- * @hooked woocommerce_template_single_price - 10
334
- * @hooked woocommerce_template_single_excerpt - 20
335
- * @hooked woocommerce_template_single_add_to_cart - 30
336
- * @hooked woocommerce_template_single_meta - 40
337
- * @hooked woocommerce_template_single_sharing - 50
338
- */
339
- private function brand_logo_position()
340
- {
341
- $position = 41;
342
- $position_selected = get_option('wc_pwb_admin_tab_brand_single_position');
343
- if (!$position_selected) {
344
- update_option('wc_pwb_admin_tab_brand_single_position', 'after_meta');
345
- }
346
-
347
- switch ($position_selected) {
348
- case 'before_title':
349
- $position = 4;
350
- break;
351
- case 'after_title':
352
- $position = 6;
353
- break;
354
- case 'after_price':
355
- $position = 11;
356
- break;
357
- case 'after_excerpt':
358
- $position = 21;
359
- break;
360
- case 'after_add_to_cart':
361
- $position = 31;
362
- break;
363
- case 'after_meta':
364
- $position = 41;
365
- break;
366
- case 'after_sharing':
367
- $position = 51;
368
- break;
369
- }
370
-
371
- if ($position_selected == 'meta') {
372
- add_action('woocommerce_product_meta_end', [$this, 'action_woocommerce_single_product_summary']);
373
- } else {
374
- add_action('woocommerce_single_product_summary', [$this, 'action_woocommerce_single_product_summary'], $position);
375
- }
376
- }
377
-
378
- public function brand_desc_position()
379
- {
380
-
381
- if (is_tax('pwb-brand') && !is_paged()) {
382
-
383
- $show_banner = get_option('wc_pwb_admin_tab_brand_banner');
384
- $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
385
-
386
- if ((!$show_banner || $show_banner == 'yes') && (!$show_desc || $show_desc == 'yes')) {
387
- //show banner and description before loop
388
- add_action('woocommerce_archive_description', array($this, 'print_brand_banner_and_desc'), 15);
389
- } elseif ($show_banner == 'yes_after_loop' && $show_desc == 'yes_after_loop') {
390
- //show banner and description after loop
391
- add_action('woocommerce_after_main_content', array($this, 'print_brand_banner_and_desc'), 9);
392
- } else {
393
- //show banner and description independently
394
-
395
- if (!$show_banner || $show_banner == 'yes') {
396
- add_action('woocommerce_archive_description', array($this, 'print_brand_banner'), 15);
397
- } elseif ($show_banner == 'yes_after_loop') {
398
- add_action('woocommerce_after_main_content', array($this, 'print_brand_banner'), 9);
399
- }
400
-
401
- if (!$show_desc || $show_desc == 'yes') {
402
- add_action('woocommerce_archive_description', array($this, 'print_brand_desc'), 15);
403
- } elseif ($show_desc == 'yes_after_loop') {
404
- add_action('woocommerce_after_main_content', array($this, 'print_brand_desc'), 9);
405
- }
406
- }
407
- }
408
- }
409
-
410
- /*
411
- * Maps shortcode (for visual composer plugin)
412
- *
413
- * @since 1.0
414
- * @link https://vc.wpbakery.com/
415
- * @return mixed
416
- */
417
-
418
- public function vc_map_shortcodes()
419
- {
420
- $available_image_sizes_adapted = array();
421
- $available_image_sizes = get_intermediate_image_sizes();
422
-
423
- foreach ($available_image_sizes as $image_size) {
424
- $available_image_sizes_adapted[$image_size] = $image_size;
425
- }
426
-
427
- vc_map(array(
428
- "name" => __("PWB Product carousel", "perfect-woocommerce-brands"),
429
- "description" => __("Product carousel by brand or by category", "perfect-woocommerce-brands"),
430
- "base" => "pwb-product-carousel",
431
- "class" => "",
432
- "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
433
- "category" => "WooCommerce",
434
- "params" => array(
435
- array(
436
- "type" => "dropdown",
437
- "heading" => __("Brand", "perfect-woocommerce-brands"),
438
- "param_name" => "brand",
439
- "admin_label" => true,
440
- "value" => self::get_brands_array(true)
441
- ),
442
- array(
443
- "type" => "textfield",
444
- "holder" => "div",
445
- "heading" => __("Products", "perfect-woocommerce-brands"),
446
- "param_name" => "products",
447
- "value" => "10",
448
- "description" => __("Number of products to load", "perfect-woocommerce-brands")
449
- ),
450
- array(
451
- "type" => "textfield",
452
- "holder" => "div",
453
- "heading" => __("Products to show", "perfect-woocommerce-brands"),
454
- "param_name" => "products_to_show",
455
- "value" => "5",
456
- "description" => __("Number of products to show", "perfect-woocommerce-brands")
457
- ),
458
- array(
459
- "type" => "textfield",
460
- "holder" => "div",
461
- "heading" => __("Products to scroll", "perfect-woocommerce-brands"),
462
- "param_name" => "products_to_scroll",
463
- "value" => "1",
464
- "description" => __("Number of products to scroll", "perfect-woocommerce-brands")
465
- ),
466
- array(
467
- "type" => "checkbox",
468
- "holder" => "div",
469
- "heading" => __("Autoplay", "perfect-woocommerce-brands"),
470
- "param_name" => "autoplay",
471
- "description" => __("Autoplay carousel", "perfect-woocommerce-brands")
472
- ),
473
- array(
474
- "type" => "checkbox",
475
- "holder" => "div",
476
- "heading" => __("Arrows", "perfect-woocommerce-brands"),
477
- "param_name" => "arrows",
478
- "description" => __("Display prev and next arrows", "perfect-woocommerce-brands")
479
- )
480
- )
481
- ));
482
-
483
- vc_map(array(
484
- "name" => __("PWB Brands carousel", "perfect-woocommerce-brands"),
485
- "description" => __("Brands carousel", "perfect-woocommerce-brands"),
486
- "base" => "pwb-carousel",
487
- "class" => "",
488
- "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
489
- "category" => "WooCommerce",
490
- "params" => array(
491
- array(
492
- "type" => "textfield",
493
- "holder" => "div",
494
- "heading" => __("Items", "perfect-woocommerce-brands"),
495
- "param_name" => "items",
496
- "value" => "10",
497
- "description" => __("Number of items to load (or 'featured')", "perfect-woocommerce-brands")
498
- ),
499
- array(
500
- "type" => "textfield",
501
- "holder" => "div",
502
- "heading" => __("Items to show", "perfect-woocommerce-brands"),
503
- "param_name" => "items_to_show",
504
- "value" => "5",
505
- "description" => __("Number of items to show", "perfect-woocommerce-brands")
506
- ),
507
- array(
508
- "type" => "textfield",
509
- "holder" => "div",
510
- "heading" => __("Items to scroll", "perfect-woocommerce-brands"),
511
- "param_name" => "items_to_scroll",
512
- "value" => "1",
513
- "description" => __("Number of items to scroll", "perfect-woocommerce-brands")
514
- ),
515
- array(
516
- "type" => "checkbox",
517
- "holder" => "div",
518
- "heading" => __("Autoplay", "perfect-woocommerce-brands"),
519
- "param_name" => "autoplay",
520
- "description" => __("Autoplay carousel", "perfect-woocommerce-brands")
521
- ),
522
- array(
523
- "type" => "checkbox",
524
- "holder" => "div",
525
- "heading" => __("Arrows", "perfect-woocommerce-brands"),
526
- "param_name" => "arrows",
527
- "description" => __("Display prev and next arrows", "perfect-woocommerce-brands")
528
- ),
529
- array(
530
- "type" => "dropdown",
531
- "heading" => __("Brand logo size", "perfect-woocommerce-brands"),
532
- "param_name" => "image_size",
533
- "admin_label" => true,
534
- "value" => $available_image_sizes_adapted
535
- )
536
- )
537
- ));
538
-
539
- vc_map(array(
540
- "name" => __("PWB All brands", "perfect-woocommerce-brands"),
541
- "description" => __("Show all brands", "perfect-woocommerce-brands"),
542
- "base" => "pwb-all-brands",
543
- "class" => "",
544
- "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
545
- "category" => "WooCommerce",
546
- "params" => array(
547
- array(
548
- "type" => "textfield",
549
- "holder" => "div",
550
- "heading" => __("Brands per page", "perfect-woocommerce-brands"),
551
- "param_name" => "per_page",
552
- "value" => "10",
553
- "description" => __("Show x brands per page", "perfect-woocommerce-brands")
554
- ),
555
- array(
556
- "type" => "dropdown",
557
- "heading" => __("Brand logo size", "perfect-woocommerce-brands"),
558
- "param_name" => "image_size",
559
- "admin_label" => true,
560
- "value" => $available_image_sizes_adapted
561
- ),
562
- array(
563
- "type" => "dropdown",
564
- "heading" => __("Order by", "perfect-woocommerce-brands"),
565
- "param_name" => "order_by",
566
- "admin_label" => true,
567
- "value" => array(
568
- 'name' => 'name',
569
- 'slug' => 'slug',
570
- 'term_id' => 'term_id',
571
- 'id' => 'id',
572
- 'description' => 'description',
573
- 'rand' => 'rand'
574
- )
575
- ),
576
- array(
577
- "type" => "dropdown",
578
- "heading" => __("Order", "perfect-woocommerce-brands"),
579
- "param_name" => "order",
580
- "admin_label" => true,
581
- "value" => array(
582
- 'ASC' => 'ASC',
583
- 'DSC' => 'DSC'
584
- )
585
- ),
586
- array(
587
- "type" => "dropdown",
588
- "heading" => __("Title position", "perfect-woocommerce-brands"),
589
- "param_name" => "title_position",
590
- "admin_label" => true,
591
- "value" => array(
592
- __("Before image", "perfect-woocommerce-brands") => 'before',
593
- __("After image", "perfect-woocommerce-brands") => 'after',
594
- __("Hide", "perfect-woocommerce-brands") => 'none'
595
- )
596
- ),
597
- array(
598
- "type" => "checkbox",
599
- "holder" => "div",
600
- "heading" => __("Hide empty", "perfect-woocommerce-brands"),
601
- "param_name" => "hide_empty",
602
- "description" => __("Hide brands that have not been assigned to any product", "perfect-woocommerce-brands")
603
- )
604
- )
605
- ));
606
-
607
- vc_map(array(
608
- "name" => __("PWB AZ Listing", "perfect-woocommerce-brands"),
609
- "description" => __("AZ Listing for brands", "perfect-woocommerce-brands"),
610
- "base" => "pwb-az-listing",
611
- "class" => "",
612
- "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
613
- "category" => "WooCommerce",
614
- "params" => array(
615
- array(
616
- "type" => "dropdown",
617
- "heading" => __("Only parent brands", "perfect-woocommerce-brands"),
618
- "param_name" => "only_parents",
619
- "admin_label" => true,
620
- "value" => array(esc_html__('No') => 'no', esc_html__('Yes') => 'yes'),
621
- )
622
- )
623
- ));
624
-
625
- vc_map(array(
626
- "name" => __("PWB brand", "perfect-woocommerce-brands"),
627
- "description" => __("Show brand for a specific product", "perfect-woocommerce-brands"),
628
- "base" => "pwb-brand",
629
- "class" => "",
630
- "icon" => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
631
- "category" => "WooCommerce",
632
- "params" => array(
633
- array(
634
- "type" => "textfield",
635
- "holder" => "div",
636
- "heading" => __("Product id", "perfect-woocommerce-brands"),
637
- "param_name" => "product_id",
638
- "value" => null,
639
- "description" => __("Product id (post id)", "perfect-woocommerce-brands")
640
- ),
641
- array(
642
- "type" => "dropdown",
643
- "heading" => __("Brand logo size", "perfect-woocommerce-brands"),
644
- "param_name" => "image_size",
645
- "admin_label" => true,
646
- "value" => $available_image_sizes_adapted
647
- )
648
- )
649
- ));
650
- }
651
-
652
- public function action_woocommerce_single_product_summary()
653
- {
654
- $brands = wp_get_post_terms(get_the_ID(), 'pwb-brand');
655
-
656
- if (!is_wp_error($brands)) {
657
-
658
- if (sizeof($brands) > 0) {
659
-
660
- $show_as = get_option('wc_pwb_admin_tab_brands_in_single');
661
-
662
- if ($show_as != 'no') {
663
-
664
- do_action('pwb_before_single_product_brands', $brands);
665
-
666
- echo '<div class="pwb-single-product-brands pwb-clearfix">';
667
-
668
- if ($show_as == 'brand_link') {
669
- $before_brands_links = '<span class="pwb-text-before-brands-links">';
670
- $before_brands_links .= apply_filters('pwb_text_before_brands_links', esc_html__('Brands', 'perfect-woocommerce-brands'));
671
- $before_brands_links .= ':</span>';
672
- echo apply_filters('pwb_html_before_brands_links', $before_brands_links);
673
- }
674
-
675
- foreach ($brands as $brand) {
676
- $brand_link = get_term_link($brand->term_id, 'pwb-brand');
677
- $attachment_id = get_term_meta($brand->term_id, 'pwb_brand_image', 1);
678
-
679
- $image_size = 'thumbnail';
680
- $image_size_selected = get_option('wc_pwb_admin_tab_brand_logo_size', 'thumbnail');
681
- if ($image_size_selected != false) {
682
- $image_size = $image_size_selected;
683
- }
684
-
685
- $attachment_html = wp_get_attachment_image($attachment_id, $image_size);
686
-
687
- if (!empty($attachment_html) && $show_as == 'brand_image' || !empty($attachment_html) && !$show_as) {
688
- echo '<a href="' . $brand_link . '" title="' . $brand->name . '">' . $attachment_html . '</a>';
689
- } else {
690
- echo '<a href="' . $brand_link . '" title="' . esc_html__('View brand', 'perfect-woocommerce-brands') . '">' . $brand->name . '</a>';
691
- }
692
- }
693
- echo '</div>';
694
-
695
- do_action('pwb_after_single_product_brands', $brands);
696
- }
697
- }
698
- }
699
- }
700
-
701
- public function enqueue_scripts()
702
- {
703
-
704
- wp_register_script(
705
- 'pwb-lib-slick',
706
- PWB_PLUGIN_URL . '/assets/lib/slick/slick.min.js',
707
- array('jquery'),
708
- '1.8.0',
709
- false
710
- );
711
-
712
- wp_register_style(
713
- 'pwb-lib-slick',
714
- PWB_PLUGIN_URL . '/assets/lib/slick/slick.css',
715
- array(),
716
- '1.8.0',
717
- 'all'
718
- );
719
-
720
- wp_enqueue_style(
721
- 'pwb-styles-frontend',
722
- PWB_PLUGIN_URL . '/assets/css/styles-frontend.min.css',
723
- array(),
724
- PWB_PLUGIN_VERSION,
725
- 'all'
726
- );
727
-
728
- wp_register_script(
729
- 'pwb-functions-frontend',
730
- PWB_PLUGIN_URL . '/assets/js/functions-frontend.min.js',
731
- array('jquery'),
732
- PWB_PLUGIN_VERSION,
733
- true
734
- );
735
-
736
- wp_localize_script('pwb-functions-frontend', 'pwb_ajax_object', array(
737
- 'carousel_prev' => apply_filters('pwb_carousel_prev', '&lt;'),
738
- 'carousel_next' => apply_filters('pwb_carousel_next', '&gt;')
739
- ));
740
-
741
- wp_enqueue_script('pwb-functions-frontend');
742
- }
743
-
744
- public function admin_enqueue_scripts($hook)
745
- {
746
- $screen = get_current_screen();
747
- if ($hook == 'edit-tags.php' && $screen->taxonomy == 'pwb-brand' || $hook == 'term.php' && $screen->taxonomy == 'pwb-brand') {
748
- wp_enqueue_media();
749
- }
750
-
751
- wp_enqueue_style('pwb-styles-admin', PWB_PLUGIN_URL . '/assets/css/styles-admin.min.css', array(), PWB_PLUGIN_VERSION);
752
-
753
- wp_register_script('pwb-functions-admin', PWB_PLUGIN_URL . '/assets/js/functions-admin.min.js', array('jquery'), PWB_PLUGIN_VERSION, true);
754
- wp_localize_script('pwb-functions-admin', 'pwb_ajax_object_admin', array(
755
- 'ajax_url' => admin_url('admin-ajax.php'),
756
- 'site_url' => site_url(),
757
- 'brands_url' => admin_url('edit-tags.php?taxonomy=pwb-brand&post_type=product'),
758
- 'translations' => array(
759
- 'migrate_notice' => esc_html__('¿Start migration?', 'perfect-woocommerce-brands'),
760
- 'migrating' => esc_html__('We are migrating the product brands. ¡Don´t close this window until the process is finished!', 'perfect-woocommerce-brands'),
761
- 'dummy_data_notice' => esc_html__('¿Start loading dummy data?', 'perfect-woocommerce-brands'),
762
- 'dummy_data' => esc_html__('We are importing the dummy data. ¡Don´t close this window until the process is finished!', 'perfect-woocommerce-brands')
763
- ),
764
- 'nonce' => [
765
- 'pwb_brands_export' => wp_create_nonce('pwb_brands_export'), //ok
766
- 'pwb_brands_import' => wp_create_nonce('pwb_brands_import'), //ok
767
- 'pwb_dismiss_notice' => wp_create_nonce('pwb_dismiss_notice'), //ok
768
- 'pwb_admin_set_featured_brand' => wp_create_nonce('pwb_admin_set_featured_brand'), //ok
769
- 'pwb_admin_save_screen_settings' => wp_create_nonce('pwb_admin_save_screen_settings'), //ok
770
- 'pwb_admin_dummy_data' => wp_create_nonce('pwb_admin_dummy_data'), //ok
771
- 'pwb_admin_migrate_brands' => wp_create_nonce('pwb_admin_migrate_brands'),
772
- 'pwb_system_status' => wp_create_nonce('pwb_system_status')
773
- ]
774
- ));
775
- wp_enqueue_script('pwb-functions-admin');
776
- }
777
-
778
- public function register_brands_taxonomy()
779
- {
780
- $labels = array(
781
- 'name' => esc_html__('Brands', 'perfect-woocommerce-brands'),
782
- 'singular_name' => esc_html__('Brand', 'perfect-woocommerce-brands'),
783
- 'menu_name' => esc_html__('Brands', 'perfect-woocommerce-brands'),
784
- 'all_items' => esc_html__('All Brands', 'perfect-woocommerce-brands'),
785
- 'edit_item' => esc_html__('Edit Brand', 'perfect-woocommerce-brands'),
786
- 'view_item' => esc_html__('View Brand', 'perfect-woocommerce-brands'),
787
- 'update_item' => esc_html__('Update Brand', 'perfect-woocommerce-brands'),
788
- 'add_new_item' => esc_html__('Add New Brand', 'perfect-woocommerce-brands'),
789
- 'new_item_name' => esc_html__('New Brand Name', 'perfect-woocommerce-brands'),
790
- 'parent_item' => esc_html__('Parent Brand', 'perfect-woocommerce-brands'),
791
- 'parent_item_colon' => esc_html__('Parent Brand:', 'perfect-woocommerce-brands'),
792
- 'search_items' => esc_html__('Search Brands', 'perfect-woocommerce-brands'),
793
- 'popular_items' => esc_html__('Popular Brands', 'perfect-woocommerce-brands'),
794
- 'separate_items_with_commas' => esc_html__('Separate brands with commas', 'perfect-woocommerce-brands'),
795
- 'add_or_remove_items' => esc_html__('Add or remove brands', 'perfect-woocommerce-brands'),
796
- 'choose_from_most_used' => esc_html__('Choose from the most used brands', 'perfect-woocommerce-brands'),
797
- 'not_found' => esc_html__('No brands found', 'perfect-woocommerce-brands')
798
- );
799
-
800
- $new_slug = get_option('wc_pwb_admin_tab_slug');
801
- $old_slug = get_option('old_wc_pwb_admin_tab_slug');
802
-
803
- $new_slug = ($new_slug != false) ? $new_slug : 'brand';
804
- $old_slug = ($old_slug != false) ? $old_slug : 'null';
805
-
806
- $args = array(
807
- 'hierarchical' => true,
808
- 'labels' => $labels,
809
- 'show_ui' => true,
810
- 'query_var' => true,
811
- 'public' => true,
812
- 'show_admin_column' => true,
813
- 'rewrite' => array(
814
- 'slug' => apply_filters('pwb_taxonomy_rewrite', $new_slug),
815
- 'hierarchical' => true,
816
- 'with_front' => apply_filters('pwb_taxonomy_with_front', true),
817
- 'ep_mask' => EP_PERMALINK
818
- )
819
- );
820
-
821
- register_taxonomy('pwb-brand', array('product'), $args);
822
-
823
- if ($new_slug != false && $old_slug != false && $new_slug != $old_slug) {
824
- flush_rewrite_rules();
825
- update_option('old_wc_pwb_admin_tab_slug', $new_slug);
826
- }
827
- }
828
-
829
- public function add_brands_metafields()
830
- {
831
- register_meta('term', 'pwb_brand_image', array($this, 'add_brands_metafields_sanitize'));
832
- }
833
-
834
- public function add_brands_metafields_sanitize($brand_img)
835
- {
836
- return $brand_img;
837
- }
838
-
839
- public static function get_brands($hide_empty = false, $order_by = 'name', $order = 'ASC', $only_featured = false, $pwb_term = false, $only_parents = false)
840
- {
841
- $result = array();
842
-
843
- $brands_args = array('hide_empty' => $hide_empty, 'orderby' => $order_by, 'order' => $order);
844
- if ($only_featured)
845
- $brands_args['meta_query'] = array(array('key' => 'pwb_featured_brand', 'value' => true));
846
- if ($only_parents)
847
- $brands_args['parent'] = 0;
848
-
849
- $brands = get_terms('pwb-brand', $brands_args);
850
-
851
- foreach ($brands as $key => $brand) {
852
-
853
- if ($pwb_term) {
854
- $brands[$key] = new PWB_Term($brand);
855
- } else {
856
- $brand_image_id = get_term_meta($brand->term_id, 'pwb_brand_image', true);
857
- $brand_banner_id = get_term_meta($brand->term_id, 'pwb_brand_banner', true);
858
- $brand->brand_image = wp_get_attachment_image_src($brand_image_id);
859
- $brand->brand_banner = wp_get_attachment_image_src($brand_banner_id);
860
- }
861
- }
862
-
863
- if (is_array($brands) && count($brands) > 0)
864
- $result = $brands;
865
-
866
- return $result;
867
- }
868
-
869
- public static function get_brands_array($is_select = false)
870
- {
871
- $result = array();
872
-
873
- //if is for select input adds default value
874
- if ($is_select)
875
- $result[0] = esc_html__('All', 'perfect-woocommerce-brands');
876
-
877
- $brands = get_terms('pwb-brand', array(
878
- 'hide_empty' => false
879
- ));
880
-
881
- foreach ($brands as $brand) {
882
- $result[$brand->term_id] = $brand->slug;
883
- }
884
-
885
- return $result;
886
- }
887
-
888
- public function print_brand_banner()
889
- {
890
- $queried_object = get_queried_object();
891
- $brand_banner = get_term_meta($queried_object->term_id, 'pwb_brand_banner', true);
892
- $brand_banner_link = get_term_meta($queried_object->term_id, 'pwb_brand_banner_link', true);
893
- $show_banner = get_option('wc_pwb_admin_tab_brand_banner');
894
- $show_banner = get_option('wc_pwb_admin_tab_brand_banner');
895
- $show_banner_class = (!$show_banner || $show_banner == 'yes') ? 'pwb-before-loop' : 'pwb-after-loop';
896
-
897
- if ($brand_banner != '') {
898
- echo '<div class="pwb-brand-banner pwb-clearfix ' . $show_banner_class . '">';
899
- if ($brand_banner_link != '') {
900
- echo '<a href="' . site_url($brand_banner_link) . '">' . wp_get_attachment_image($brand_banner, 'full', false) . '</a>';
901
- } else {
902
- echo wp_get_attachment_image($brand_banner, 'full', false);
903
- }
904
- echo '</div>';
905
- }
906
- }
907
-
908
- public function print_brand_desc()
909
- {
910
- $queried_object = get_queried_object();
911
- $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
912
- $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
913
- $show_desc_class = (!$show_desc || $show_desc == 'yes') ? 'pwb-before-loop' : 'pwb-after-loop';
914
-
915
- if ($queried_object->description != '' && $show_desc !== 'no') {
916
- echo '<div class="pwb-brand-description ' . $show_desc_class . '">';
917
- echo do_shortcode(wpautop($queried_object->description));
918
- echo '</div>';
919
- }
920
- }
921
-
922
- public function print_brand_banner_and_desc()
923
- {
924
- $queried_object = get_queried_object();
925
-
926
- $show_desc = get_option('wc_pwb_admin_tab_brand_desc');
927
- $show_desc_class = (!$show_desc || $show_desc == 'yes') ? 'pwb-before-loop' : 'pwb-after-loop';
928
-
929
- $brand_banner = get_term_meta($queried_object->term_id, 'pwb_brand_banner', true);
930
- $brand_banner_link = get_term_meta($queried_object->term_id, 'pwb_brand_banner_link', true);
931
-
932
- if ($brand_banner != '' || $queried_object->description != '' && $show_desc !== 'no') {
933
- echo '<div class="pwb-brand-banner-cont ' . $show_desc_class . '">';
934
- $this->print_brand_banner();
935
- $this->print_brand_desc();
936
- echo '</div>';
937
- }
938
- }
939
-
940
- public static function render_template($name = '', $folder = '', $data = array(), $private = true)
941
- {
942
- //default template
943
- if ($folder)
944
- $folder = $folder . '/';
945
- $template_file = dirname(__DIR__) . '/templates/' . $folder . $name . '.php';
946
-
947
- //theme overrides
948
- if (!$private) {
949
- $theme_template_path = get_stylesheet_directory() . '/perfect-woocommerce-brands/';
950
- if (file_exists($theme_template_path . $folder . $name . '.php'))
951
- $template_file = $theme_template_path . $folder . $name . '.php';
952
- }
953
-
954
- extract($data);
955
-
956
- ob_start();
957
- include $template_file;
958
- return ob_get_clean();
959
- }
960
-
961
- public function product_duplicate_save($duplicate, $product)
962
- {
963
- $product_brands = wp_get_object_terms($product->get_id(), 'pwb-brand', array('fields' => 'ids'));
964
- wp_set_object_terms($duplicate->get_id(), $product_brands, 'pwb-brand');
965
- }
966
-
967
- public function breadcrumbs($crumbs)
968
- {
969
-
970
- if (is_tax('pwb-brand')) {
971
-
972
- $brands_page_id = get_option('wc_pwb_admin_tab_brands_page_id');
973
-
974
- if (!empty($brands_page_id) && $brands_page_id != '-') {
975
-
976
- $cur_brand = get_queried_object();
977
- $brand_ancestors = get_ancestors($cur_brand->term_id, 'pwb-brand', 'taxonomy');
978
-
979
- $brand_page_pos = count($crumbs) - (count($brand_ancestors) + 2);
980
- if (is_paged())
981
- $brand_page_pos -= 1;
982
-
983
- if (isset($crumbs[$brand_page_pos][1]))
984
- $crumbs[$brand_page_pos][1] = get_page_link($brands_page_id);
985
- }
986
- }
987
-
988
- return $crumbs;
989
- }
990
-
991
- /**
992
- * Redirect if the search matchs with a brands name
993
- * Better search experience
994
- */
995
- public function search_by_brand_name($query)
996
- {
997
-
998
- if (wp_doing_ajax())
999
- return;
1000
-
1001
- if (!is_admin() && $query->is_main_query() && $query->is_search()) {
1002
-
1003
- $brands = get_terms(array('taxonomy' => 'pwb-brand', 'fields' => 'id=>name'));
1004
-
1005
- if ($match = array_search(strtolower(trim($query->get('s'))), array_map('strtolower', $brands))) {
1006
-
1007
- wp_redirect(get_term_link($match));
1008
- exit;
1009
- }
1010
- }
1011
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1012
  }
2
 
3
  namespace Perfect_Woocommerce_Brands;
4
 
5
+ defined( 'ABSPATH' ) || 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_pwb_dismiss_notice', array( $this, 'dismiss_notice' ) );
26
+ add_action( 'admin_notices', array( $this, 'review_notice' ) );
27
+
28
+ add_action(
29
+ 'wp',
30
+ function () {
31
+ if ( is_tax( 'pwb-brand' ) ) {
32
+ remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
33
+ }
34
+ }
35
+ );
36
+ add_action( 'woocommerce_product_duplicate', array( $this, 'product_duplicate_save' ), 10, 2 );
37
+
38
+ add_filter( 'woocommerce_get_breadcrumb', array( $this, 'breadcrumbs' ) );
39
+
40
+ add_filter( 'shortcode_atts_products', array( $this, 'extend_products_shortcode_atts' ), 10, 4 );
41
+ add_filter( 'woocommerce_shortcode_products_query', array( $this, 'extend_products_shortcode' ), 10, 2 );
42
+
43
+ add_filter( 'manage_edit-product_sortable_columns', array( $this, 'brands_column_sortable' ), 90 );
44
+ add_action( 'posts_clauses', array( $this, 'brands_column_sortable_posts' ), 10, 2 );
45
+ add_filter( 'post_type_link', array( $this, 'brand_name_in_url' ), 10, 2 );
46
+ add_action( 'pre_get_posts', array( $this, 'search_by_brand_name' ) );
47
+
48
+ // clean caches
49
+ add_action( 'edited_terms', array( $this, 'clean_caches' ), 10, 2 );
50
+ add_action( 'created_term', array( $this, 'clean_caches_after_edit_brand' ), 10, 3 );
51
+ add_action( 'delete_term', array( $this, 'clean_caches_after_edit_brand' ), 10, 3 );
52
+ }
53
+
54
+ public function clean_caches( $term_id, $taxonomy ) {
55
+ if ( $taxonomy != 'pwb-brand' ) {
56
+ return;
57
+ }
58
+ delete_transient( 'pwb_az_listing_cache' );
59
+ }
60
+
61
+ public function clean_caches_after_edit_brand( $term_id, $tt_id, $taxonomy ) {
62
+ if ( $taxonomy != 'pwb-brand' ) {
63
+ return;
64
+ }
65
+ delete_transient( 'pwb_az_listing_cache' );
66
+ }
67
+
68
+ /**
69
+ * Show row meta on the plugin screen.
70
+ *
71
+ * @param mixed $links Plugin Row Meta.
72
+ * @param mixed $file Plugin Base file.
73
+ *
74
+ * @return array
75
+ */
76
+ public static function plugin_row_meta( $links, $file ) {
77
+ if ( PWB_PLUGIN_BASENAME === $file ) {
78
+ $row_meta = array(
79
+ 'docs' => '<a target="_blank" rel="noopener noferrer" href="' . PWB_DOCUMENTATION_URL . '">' . esc_html__( 'Documentation', 'perfect-woocommerce-brands' ) . '</a>',
80
+ );
81
+ return array_merge( $links, $row_meta );
82
+ }
83
+ return (array) $links;
84
+ }
85
+
86
+ public function brand_name_in_url( $permalink, $post ) {
87
+ if ( $post->post_type == 'product' && strpos( $permalink, '%pwb-brand%' ) !== false ) {
88
+ $term = 'product';
89
+ $brands = wp_get_post_terms( $post->ID, 'pwb-brand' );
90
+ if ( ! empty( $brands ) && ! is_wp_error( $brands ) ) {
91
+ $term = current( $brands )->slug;
92
+ }
93
+ $permalink = str_replace( '%pwb-brand%', $term, $permalink );
94
+ }
95
+ return $permalink;
96
+ }
97
+
98
+ public function brands_column_sortable_posts( $clauses, $wp_query ) {
99
+ global $wpdb;
100
+
101
+ if ( isset( $wp_query->query['orderby'] ) && 'taxonomy-pwb-brand' == $wp_query->query['orderby'] ) {
102
+
103
+ $clauses['join'] .= "
104
  LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
105
  LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
106
  LEFT OUTER JOIN {$wpdb->terms} USING (term_id)";
107
 
108
+ $clauses['where'] .= " AND (taxonomy = 'pwb-brand' OR taxonomy IS NULL)";
109
+ $clauses['groupby'] = 'object_id';
110
+ $clauses['orderby'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) ";
111
+ $clauses['orderby'] .= ( 'ASC' == strtoupper( $wp_query->get( 'order' ) ) ) ? 'ASC' : 'DESC';
112
+ }
113
+
114
+ return $clauses;
115
+ }
116
+
117
+ public function brands_column_sortable( $columns ) {
118
+ $columns['taxonomy-pwb-brand'] = 'taxonomy-pwb-brand';
119
+ return $columns;
120
+ }
121
+
122
+ public function extend_products_shortcode_atts( $out, $pairs, $atts, $shortcode ) {
123
+ if ( ! empty( $atts['brands'] ) ) {
124
+ $out['brands'] = explode( ',', $atts['brands'] );
125
+ }
126
+ return $out;
127
+ }
128
+
129
+ public function extend_products_shortcode( $query_args, $atts ) {
130
+ if ( ! empty( $atts['brands'] ) ) {
131
+ global $wpdb;
132
+
133
+ $terms = $atts['brands'];
134
+ $terms_count = count( $atts['brands'] );
135
+ $terms_adapted = '';
136
+
137
+ $terms_i = 0;
138
+ foreach ( $terms as $brand ) {
139
+ $terms_adapted .= '"' . $brand . '"';
140
+ $terms_i++;
141
+ if ( $terms_i < $terms_count ) {
142
+ $terms_adapted .= ',';
143
+ }
144
+ }
145
+
146
+ $ids = $wpdb->get_col(
147
+ "
 
148
  SELECT DISTINCT tr.object_id
149
  FROM {$wpdb->prefix}term_relationships as tr
150
  INNER JOIN {$wpdb->prefix}term_taxonomy as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
151
  INNER JOIN {$wpdb->prefix}terms as t ON tt.term_id = t.term_id
152
  WHERE tt.taxonomy LIKE 'pwb_brand' AND t.slug IN ($terms_adapted)
153
+ "
154
+ );
155
+
156
+ if ( ! empty( $ids ) ) {
157
+ if ( 1 === count( $ids ) ) {
158
+ $query_args['p'] = $ids[0];
159
+ } else {
160
+ $query_args['post__in'] = $ids;
161
+ }
162
+ }
163
+ }
164
+
165
+ return $query_args;
166
+ }
167
+
168
+ public function review_notice() {
169
+ $show_notice = get_option( 'wc_pwb_notice_plugin_review', true );
170
+ $activate_on = get_option( 'pwb_activate_on', time() );
171
+ $now = time();
172
+ $one_week = 604800;
173
+ $date_diff = $now - $activate_on;
174
+
175
+ if ( $show_notice && $date_diff > $one_week ) {
176
+ ?>
177
+ <div class="notice notice-info pwb-notice-dismissible is-dismissible" data-notice="wc_pwb_notice_plugin_review">
178
+ <p><?php echo esc_html__( 'We know that you´re in love with Perfect WooCommerce Brands, you can help us making it a bit better. Thanks a lot!', 'perfect-woocommerce-brands' ); ?><span class="dashicons dashicons-heart"></span></p>
179
+ <p>
180
+ <a href="https://wordpress.org/support/plugin/perfect-woocommerce-brands/reviews/?rate=5#new-post" target="_blank"><?php esc_html_e( 'Leave a review', 'perfect-woocommerce-brands' ); ?></a>
181
+ <a href="https://translate.wordpress.org/projects/wp-plugins/perfect-woocommerce-brands" target="_blank"><?php esc_html_e( 'Translate the plugin', 'perfect-woocommerce-brands' ); ?></a>
182
+ <a href="<?php echo esc_url( PWB_GITHUB_URL ); ?>" target="_blank"><?php esc_html_e( 'View on GitHub', 'perfect-woocommerce-brands' ); ?></a>
183
+ </p>
184
+ </div>
185
+ <?php
186
+ }
187
+ }
188
+
189
+ public function dismiss_notice() {
190
+ if (
191
+ isset( $_REQUEST['nonce'] )
192
+ &&
193
+ wp_verify_nonce( $_REQUEST['nonce'], 'pwb_dismiss_notice' )
194
+ &&
195
+ current_user_can( 'manage_options' )
196
+ ) {
197
+
198
+ $notice_name_whitelist = array( 'wc_pwb_notice_plugin_review' );
199
+
200
+ if ( isset( $_POST['notice_name'] ) && in_array( $_POST['notice_name'], $notice_name_whitelist ) ) {
201
+
202
+ $notice_key = sanitize_key( $_POST['notice_name'] );
203
+
204
+ update_option( $notice_key, 0 );
205
+ echo 'ok';
206
+ } else {
207
+ echo 'error';
208
+ }
209
+ }
210
+ wp_die();
211
+ }
212
+
213
+ public function pwb_brand_filter( $query ) {
214
+ if ( ! empty( $_GET['pwb-brand-filter'] ) ) {
215
+
216
+ $terms_array = explode( ',', sanitize_text_field( $_GET['pwb-brand-filter'] ) );
217
+
218
+ // remove invalid terms (security)
219
+ for ( $i = 0; $i < count( $terms_array ); $i++ ) {
220
+ if ( ! term_exists( $terms_array[ $i ], 'pwb-brand' ) ) {
221
+ unset( $terms_array[ $i ] );
222
+ }
223
+ }
224
+
225
+ $filterable_product = false;
226
+ if ( is_product_taxonomy() || is_post_type_archive( 'product' ) ) {
227
+ $filterable_product = true;
228
+ }
229
+
230
+ if ( $filterable_product && $query->is_main_query() ) {
231
+
232
+ $query->set(
233
+ 'tax_query',
234
+ array(
235
+ array(
236
+ 'taxonomy' => 'pwb-brand',
237
+ 'field' => 'slug',
238
+ 'terms' => $terms_array,
239
+ ),
240
+ )
241
+ );
242
+ }
243
+ }
244
+ }
245
+
246
+ /*
247
+ * Adds microdata (brands) to single products
248
+ */
249
+
250
+ public function product_microdata( $markup, $product ) {
251
+ $new_markup = array();
252
+ $brands = wp_get_post_terms( $product->get_id(), 'pwb-brand' );
253
+ foreach ( $brands as $brand ) {
254
+ $new_markup['brand'][] = array(
255
+ '@type' => 'Brand',
256
+ 'name' => $brand->name,
257
+ );
258
+ // $new_markup['brand'][] = $brand->name;
259
+ }
260
+
261
+ return array_merge( $markup, $new_markup );
262
+ }
263
+
264
+ public function add_shortcodes() {
265
+ add_shortcode(
266
+ 'pwb-carousel',
267
+ array(
268
+ '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Carousel_Shortcode',
269
+ 'carousel_shortcode',
270
+ )
271
+ );
272
+ add_shortcode(
273
+ 'pwb-product-carousel',
274
+ array(
275
+ '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Product_Carousel_Shortcode',
276
+ 'product_carousel_shortcode',
277
+ )
278
+ );
279
+ add_shortcode(
280
+ 'pwb-all-brands',
281
+ array(
282
+ '\Perfect_Woocommerce_Brands\Shortcodes\PWB_All_Brands_Shortcode',
283
+ 'all_brands_shortcode',
284
+ )
285
+ );
286
+ add_shortcode(
287
+ 'pwb-az-listing',
288
+ array(
289
+ '\Perfect_Woocommerce_Brands\Shortcodes\PWB_AZ_Listing_Shortcode',
290
+ 'shortcode',
291
+ )
292
+ );
293
+ add_shortcode(
294
+ 'pwb-brand',
295
+ array(
296
+ '\Perfect_Woocommerce_Brands\Shortcodes\PWB_Brand_Shortcode',
297
+ 'brand_shortcode',
298
+ )
299
+ );
300
+ }
301
+
302
+ public function register_widgets() {
303
+ register_widget( '\Perfect_Woocommerce_Brands\Widgets\PWB_List_Widget' );
304
+ register_widget( '\Perfect_Woocommerce_Brands\Widgets\PWB_Dropdown_Widget' );
305
+ register_widget( '\Perfect_Woocommerce_Brands\Widgets\PWB_Filter_By_Brand_Widget' );
306
+ }
307
+
308
+ public function show_brands_in_loop() {
309
+ $brands_in_loop = get_option( 'wc_pwb_admin_tab_brands_in_loop' );
310
+ $image_size_selected = get_option( 'wc_pwb_admin_tab_brand_logo_size', 'thumbnail' );
311
+
312
+ if ( $brands_in_loop == 'brand_link' || $brands_in_loop == 'brand_image' ) {
313
+
314
+ global $product;
315
+ $product_id = $product->get_id();
316
+ $product_brands = wp_get_post_terms( $product_id, 'pwb-brand' );
317
+ if ( ! empty( $product_brands ) ) {
318
+ echo '<div class="pwb-brands-in-loop">';
319
+ foreach ( $product_brands as $brand ) {
320
+
321
+ echo '<span>';
322
+ $brand_link = get_term_link( $brand->term_id, 'pwb-brand' );
323
+ $attachment_id = get_term_meta( $brand->term_id, 'pwb_brand_image', 1 );
324
+
325
+ $attachment_html = wp_get_attachment_image( $attachment_id, $image_size_selected );
326
+ if ( ! empty( $attachment_html ) && $brands_in_loop == 'brand_image' ) {
327
+ echo '<a href="' . esc_url( $brand_link ) . '">' . esc_html( $attachment_html ) . '</a>';
328
+ } else {
329
+ echo '<a href="' . esc_url( $brand_link ) . '">' . esc_html( $brand->name ) . '</a>';
330
+ }
331
+ echo '</span>';
332
+ }
333
+ echo '</div>';
334
+ }
335
+ }
336
+ }
337
+
338
+ /**
339
+ * woocommerce_single_product_summary hook.
340
+ *
341
+ * @hooked woocommerce_template_single_title - 5
342
+ * @hooked woocommerce_template_single_rating - 10
343
+ * @hooked woocommerce_template_single_price - 10
344
+ * @hooked woocommerce_template_single_excerpt - 20
345
+ * @hooked woocommerce_template_single_add_to_cart - 30
346
+ * @hooked woocommerce_template_single_meta - 40
347
+ * @hooked woocommerce_template_single_sharing - 50
348
+ */
349
+ private function brand_logo_position() {
350
+ $position = 41;
351
+ $position_selected = get_option( 'wc_pwb_admin_tab_brand_single_position' );
352
+ if ( ! $position_selected ) {
353
+ update_option( 'wc_pwb_admin_tab_brand_single_position', 'after_meta' );
354
+ }
355
+
356
+ switch ( $position_selected ) {
357
+ case 'before_title':
358
+ $position = 4;
359
+ break;
360
+ case 'after_title':
361
+ $position = 6;
362
+ break;
363
+ case 'after_price':
364
+ $position = 11;
365
+ break;
366
+ case 'after_excerpt':
367
+ $position = 21;
368
+ break;
369
+ case 'after_add_to_cart':
370
+ $position = 31;
371
+ break;
372
+ case 'after_meta':
373
+ $position = 41;
374
+ break;
375
+ case 'after_sharing':
376
+ $position = 51;
377
+ break;
378
+ }
379
+
380
+ if ( $position_selected == 'meta' ) {
381
+ add_action( 'woocommerce_product_meta_end', array( $this, 'action_woocommerce_single_product_summary' ) );
382
+ } else {
383
+ add_action( 'woocommerce_single_product_summary', array( $this, 'action_woocommerce_single_product_summary' ), $position );
384
+ }
385
+ }
386
+
387
+ public function brand_desc_position() {
388
+ if ( is_tax( 'pwb-brand' ) && ! is_paged() ) {
389
+
390
+ $show_banner = get_option( 'wc_pwb_admin_tab_brand_banner' );
391
+ $show_desc = get_option( 'wc_pwb_admin_tab_brand_desc' );
392
+
393
+ if ( ( ! $show_banner || $show_banner == 'yes' ) && ( ! $show_desc || $show_desc == 'yes' ) ) {
394
+ // show banner and description before loop
395
+ add_action( 'woocommerce_archive_description', array( $this, 'print_brand_banner_and_desc' ), 15 );
396
+ } elseif ( $show_banner == 'yes_after_loop' && $show_desc == 'yes_after_loop' ) {
397
+ // show banner and description after loop
398
+ add_action( 'woocommerce_after_main_content', array( $this, 'print_brand_banner_and_desc' ), 9 );
399
+ } else {
400
+ // show banner and description independently
401
+
402
+ if ( ! $show_banner || $show_banner == 'yes' ) {
403
+ add_action( 'woocommerce_archive_description', array( $this, 'print_brand_banner' ), 15 );
404
+ } elseif ( $show_banner == 'yes_after_loop' ) {
405
+ add_action( 'woocommerce_after_main_content', array( $this, 'print_brand_banner' ), 9 );
406
+ }
407
+
408
+ if ( ! $show_desc || $show_desc == 'yes' ) {
409
+ add_action( 'woocommerce_archive_description', array( $this, 'print_brand_desc' ), 15 );
410
+ } elseif ( $show_desc == 'yes_after_loop' ) {
411
+ add_action( 'woocommerce_after_main_content', array( $this, 'print_brand_desc' ), 9 );
412
+ }
413
+ }
414
+ }
415
+ }
416
+
417
+ /*
418
+ * Maps shortcode (for visual composer plugin)
419
+ *
420
+ * @since 1.0
421
+ * @link https://vc.wpbakery.com/
422
+ * @return mixed
423
+ */
424
+
425
+ public function vc_map_shortcodes() {
426
+ $available_image_sizes_adapted = array();
427
+ $available_image_sizes = get_intermediate_image_sizes();
428
+
429
+ foreach ( $available_image_sizes as $image_size ) {
430
+ $available_image_sizes_adapted[ $image_size ] = $image_size;
431
+ }
432
+
433
+ vc_map(
434
+ array(
435
+ 'name' => __( 'PWB Product carousel', 'perfect-woocommerce-brands' ),
436
+ 'description' => __( 'Product carousel by brand or by category', 'perfect-woocommerce-brands' ),
437
+ 'base' => 'pwb-product-carousel',
438
+ 'class' => '',
439
+ 'icon' => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
440
+ 'category' => 'WooCommerce',
441
+ 'params' => array(
442
+ array(
443
+ 'type' => 'dropdown',
444
+ 'heading' => __( 'Brand', 'perfect-woocommerce-brands' ),
445
+ 'param_name' => 'brand',
446
+ 'admin_label' => true,
447
+ 'value' => self::get_brands_array( true ),
448
+ ),
449
+ array(
450
+ 'type' => 'textfield',
451
+ 'holder' => 'div',
452
+ 'heading' => __( 'Products', 'perfect-woocommerce-brands' ),
453
+ 'param_name' => 'products',
454
+ 'value' => '10',
455
+ 'description' => __( 'Number of products to load', 'perfect-woocommerce-brands' ),
456
+ ),
457
+ array(
458
+ 'type' => 'textfield',
459
+ 'holder' => 'div',
460
+ 'heading' => __( 'Products to show', 'perfect-woocommerce-brands' ),
461
+ 'param_name' => 'products_to_show',
462
+ 'value' => '5',
463
+ 'description' => __( 'Number of products to show', 'perfect-woocommerce-brands' ),
464
+ ),
465
+ array(
466
+ 'type' => 'textfield',
467
+ 'holder' => 'div',
468
+ 'heading' => __( 'Products to scroll', 'perfect-woocommerce-brands' ),
469
+ 'param_name' => 'products_to_scroll',
470
+ 'value' => '1',
471
+ 'description' => __( 'Number of products to scroll', 'perfect-woocommerce-brands' ),
472
+ ),
473
+ array(
474
+ 'type' => 'checkbox',
475
+ 'holder' => 'div',
476
+ 'heading' => __( 'Autoplay', 'perfect-woocommerce-brands' ),
477
+ 'param_name' => 'autoplay',
478
+ 'description' => __( 'Autoplay carousel', 'perfect-woocommerce-brands' ),
479
+ ),
480
+ array(
481
+ 'type' => 'checkbox',
482
+ 'holder' => 'div',
483
+ 'heading' => __( 'Arrows', 'perfect-woocommerce-brands' ),
484
+ 'param_name' => 'arrows',
485
+ 'description' => __( 'Display prev and next arrows', 'perfect-woocommerce-brands' ),
486
+ ),
487
+ ),
488
+ )
489
+ );
490
+
491
+ vc_map(
492
+ array(
493
+ 'name' => __( 'PWB Brands carousel', 'perfect-woocommerce-brands' ),
494
+ 'description' => __( 'Brands carousel', 'perfect-woocommerce-brands' ),
495
+ 'base' => 'pwb-carousel',
496
+ 'class' => '',
497
+ 'icon' => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
498
+ 'category' => 'WooCommerce',
499
+ 'params' => array(
500
+ array(
501
+ 'type' => 'textfield',
502
+ 'holder' => 'div',
503
+ 'heading' => __( 'Items', 'perfect-woocommerce-brands' ),
504
+ 'param_name' => 'items',
505
+ 'value' => '10',
506
+ 'description' => __( "Number of items to load (or 'featured')", 'perfect-woocommerce-brands' ),
507
+ ),
508
+ array(
509
+ 'type' => 'textfield',
510
+ 'holder' => 'div',
511
+ 'heading' => __( 'Items to show', 'perfect-woocommerce-brands' ),
512
+ 'param_name' => 'items_to_show',
513
+ 'value' => '5',
514
+ 'description' => __( 'Number of items to show', 'perfect-woocommerce-brands' ),
515
+ ),
516
+ array(
517
+ 'type' => 'textfield',
518
+ 'holder' => 'div',
519
+ 'heading' => __( 'Items to scroll', 'perfect-woocommerce-brands' ),
520
+ 'param_name' => 'items_to_scroll',
521
+ 'value' => '1',
522
+ 'description' => __( 'Number of items to scroll', 'perfect-woocommerce-brands' ),
523
+ ),
524
+ array(
525
+ 'type' => 'checkbox',
526
+ 'holder' => 'div',
527
+ 'heading' => __( 'Autoplay', 'perfect-woocommerce-brands' ),
528
+ 'param_name' => 'autoplay',
529
+ 'description' => __( 'Autoplay carousel', 'perfect-woocommerce-brands' ),
530
+ ),
531
+ array(
532
+ 'type' => 'checkbox',
533
+ 'holder' => 'div',
534
+ 'heading' => __( 'Arrows', 'perfect-woocommerce-brands' ),
535
+ 'param_name' => 'arrows',
536
+ 'description' => __( 'Display prev and next arrows', 'perfect-woocommerce-brands' ),
537
+ ),
538
+ array(
539
+ 'type' => 'dropdown',
540
+ 'heading' => __( 'Brand logo size', 'perfect-woocommerce-brands' ),
541
+ 'param_name' => 'image_size',
542
+ 'admin_label' => true,
543
+ 'value' => $available_image_sizes_adapted,
544
+ ),
545
+ ),
546
+ )
547
+ );
548
+
549
+ vc_map(
550
+ array(
551
+ 'name' => __( 'PWB All brands', 'perfect-woocommerce-brands' ),
552
+ 'description' => __( 'Show all brands', 'perfect-woocommerce-brands' ),
553
+ 'base' => 'pwb-all-brands',
554
+ 'class' => '',
555
+ 'icon' => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
556
+ 'category' => 'WooCommerce',
557
+ 'params' => array(
558
+ array(
559
+ 'type' => 'textfield',
560
+ 'holder' => 'div',
561
+ 'heading' => __( 'Brands per page', 'perfect-woocommerce-brands' ),
562
+ 'param_name' => 'per_page',
563
+ 'value' => '10',
564
+ 'description' => __( 'Show x brands per page', 'perfect-woocommerce-brands' ),
565
+ ),
566
+ array(
567
+ 'type' => 'dropdown',
568
+ 'heading' => __( 'Brand logo size', 'perfect-woocommerce-brands' ),
569
+ 'param_name' => 'image_size',
570
+ 'admin_label' => true,
571
+ 'value' => $available_image_sizes_adapted,
572
+ ),
573
+ array(
574
+ 'type' => 'dropdown',
575
+ 'heading' => __( 'Order by', 'perfect-woocommerce-brands' ),
576
+ 'param_name' => 'order_by',
577
+ 'admin_label' => true,
578
+ 'value' => array(
579
+ 'name' => 'name',
580
+ 'slug' => 'slug',
581
+ 'term_id' => 'term_id',
582
+ 'id' => 'id',
583
+ 'description' => 'description',
584
+ 'rand' => 'rand',
585
+ ),
586
+ ),
587
+ array(
588
+ 'type' => 'dropdown',
589
+ 'heading' => __( 'Order', 'perfect-woocommerce-brands' ),
590
+ 'param_name' => 'order',
591
+ 'admin_label' => true,
592
+ 'value' => array(
593
+ 'ASC' => 'ASC',
594
+ 'DSC' => 'DSC',
595
+ ),
596
+ ),
597
+ array(
598
+ 'type' => 'dropdown',
599
+ 'heading' => __( 'Title position', 'perfect-woocommerce-brands' ),
600
+ 'param_name' => 'title_position',
601
+ 'admin_label' => true,
602
+ 'value' => array(
603
+ __( 'Before image', 'perfect-woocommerce-brands' ) => 'before',
604
+ __( 'After image', 'perfect-woocommerce-brands' ) => 'after',
605
+ __( 'Hide', 'perfect-woocommerce-brands' ) => 'none',
606
+ ),
607
+ ),
608
+ array(
609
+ 'type' => 'checkbox',
610
+ 'holder' => 'div',
611
+ 'heading' => __( 'Hide empty', 'perfect-woocommerce-brands' ),
612
+ 'param_name' => 'hide_empty',
613
+ 'description' => __( 'Hide brands that have not been assigned to any product', 'perfect-woocommerce-brands' ),
614
+ ),
615
+ ),
616
+ )
617
+ );
618
+
619
+ vc_map(
620
+ array(
621
+ 'name' => __( 'PWB AZ Listing', 'perfect-woocommerce-brands' ),
622
+ 'description' => __( 'AZ Listing for brands', 'perfect-woocommerce-brands' ),
623
+ 'base' => 'pwb-az-listing',
624
+ 'class' => '',
625
+ 'icon' => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
626
+ 'category' => 'WooCommerce',
627
+ 'params' => array(
628
+ array(
629
+ 'type' => 'dropdown',
630
+ 'heading' => __( 'Only parent brands', 'perfect-woocommerce-brands' ),
631
+ 'param_name' => 'only_parents',
632
+ 'admin_label' => true,
633
+ 'value' => array(
634
+ esc_html__( 'No' ) => 'no',
635
+ esc_html__( 'Yes' ) => 'yes',
636
+ ),
637
+ ),
638
+ ),
639
+ )
640
+ );
641
+
642
+ vc_map(
643
+ array(
644
+ 'name' => __( 'PWB brand', 'perfect-woocommerce-brands' ),
645
+ 'description' => __( 'Show brand for a specific product', 'perfect-woocommerce-brands' ),
646
+ 'base' => 'pwb-brand',
647
+ 'class' => '',
648
+ 'icon' => PWB_PLUGIN_URL . '/assets/img/icon_pwb.jpg',
649
+ 'category' => 'WooCommerce',
650
+ 'params' => array(
651
+ array(
652
+ 'type' => 'textfield',
653
+ 'holder' => 'div',
654
+ 'heading' => __( 'Product id', 'perfect-woocommerce-brands' ),
655
+ 'param_name' => 'product_id',
656
+ 'value' => null,
657
+ 'description' => __( 'Product id (post id)', 'perfect-woocommerce-brands' ),
658
+ ),
659
+ array(
660
+ 'type' => 'dropdown',
661
+ 'heading' => __( 'Brand logo size', 'perfect-woocommerce-brands' ),
662
+ 'param_name' => 'image_size',
663
+ 'admin_label' => true,
664
+ 'value' => $available_image_sizes_adapted,
665
+ ),
666
+ ),
667
+ )
668
+ );
669
+ }
670
+
671
+ public function action_woocommerce_single_product_summary() {
672
+ $brands = wp_get_post_terms( get_the_ID(), 'pwb-brand' );
673
+
674
+ if ( ! is_wp_error( $brands ) ) {
675
+
676
+ if ( sizeof( $brands ) > 0 ) {
677
+
678
+ $show_as = get_option( 'wc_pwb_admin_tab_brands_in_single' );
679
+
680
+ if ( $show_as != 'no' ) {
681
+
682
+ do_action( 'pwb_before_single_product_brands', $brands );
683
+
684
+ echo '<div class="pwb-single-product-brands pwb-clearfix">';
685
+
686
+ if ( $show_as == 'brand_link' ) {
687
+ $before_brands_links = '<span class="pwb-text-before-brands-links">';
688
+ $before_brands_links .= apply_filters( 'pwb_text_before_brands_links', esc_html__( 'Brands', 'perfect-woocommerce-brands' ) );
689
+ $before_brands_links .= ':</span>';
690
+ echo wp_kses_post( apply_filters( 'pwb_html_before_brands_links', $before_brands_links ) );
691
+ }
692
+
693
+ foreach ( $brands as $brand ) {
694
+ $brand_link = get_term_link( $brand->term_id, 'pwb-brand' );
695
+ $attachment_id = get_term_meta( $brand->term_id, 'pwb_brand_image', 1 );
696
+
697
+ $image_size = 'thumbnail';
698
+ $image_size_selected = get_option( 'wc_pwb_admin_tab_brand_logo_size', 'thumbnail' );
699
+ if ( $image_size_selected != false ) {
700
+ $image_size = $image_size_selected;
701
+ }
702
+
703
+ $attachment_html = wp_get_attachment_image( $attachment_id, $image_size );
704
+
705
+ if ( ! empty( $attachment_html ) && $show_as == 'brand_image' || ! empty( $attachment_html ) && ! $show_as ) {
706
+ echo '<a href="' . esc_url( $brand_link ) . '" title="' . esc_attr( $brand->name ) . '">' . $attachment_html . '</a>';// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
707
+ } else {
708
+ echo '<a href="' . esc_url( $brand_link ) . '" title="' . esc_html__( 'View brand', 'perfect-woocommerce-brands' ) . '">' . esc_html( $brand->name ) . '</a>';
709
+ }
710
+ }
711
+ echo '</div>';
712
+
713
+ do_action( 'pwb_after_single_product_brands', $brands );
714
+ }
715
+ }
716
+ }
717
+ }
718
+
719
+ public function enqueue_scripts() {
720
+ wp_register_script(
721
+ 'pwb-lib-slick',
722
+ PWB_PLUGIN_URL . '/assets/lib/slick/slick.min.js',
723
+ array( 'jquery' ),
724
+ '1.8.0',
725
+ false
726
+ );
727
+
728
+ wp_register_style(
729
+ 'pwb-lib-slick',
730
+ PWB_PLUGIN_URL . '/assets/lib/slick/slick.css',
731
+ array(),
732
+ '1.8.0',
733
+ 'all'
734
+ );
735
+
736
+ wp_enqueue_style(
737
+ 'pwb-styles-frontend',
738
+ PWB_PLUGIN_URL . '/assets/css/styles-frontend.min.css',
739
+ array(),
740
+ PWB_PLUGIN_VERSION,
741
+ 'all'
742
+ );
743
+
744
+ wp_register_script(
745
+ 'pwb-functions-frontend',
746
+ PWB_PLUGIN_URL . '/assets/js/functions-frontend.min.js',
747
+ array( 'jquery' ),
748
+ PWB_PLUGIN_VERSION,
749
+ true
750
+ );
751
+
752
+ wp_localize_script(
753
+ 'pwb-functions-frontend',
754
+ 'pwb_ajax_object',
755
+ array(
756
+ 'carousel_prev' => apply_filters( 'pwb_carousel_prev', '&lt;' ),
757
+ 'carousel_next' => apply_filters( 'pwb_carousel_next', '&gt;' ),
758
+ )
759
+ );
760
+
761
+ wp_enqueue_script( 'pwb-functions-frontend' );
762
+ }
763
+
764
+ public function admin_enqueue_scripts( $hook ) {
765
+ $screen = get_current_screen();
766
+ if ( $hook == 'edit-tags.php' && $screen->taxonomy == 'pwb-brand' || $hook == 'term.php' && $screen->taxonomy == 'pwb-brand' ) {
767
+ wp_enqueue_media();
768
+ }
769
+
770
+ wp_enqueue_style( 'pwb-styles-admin', PWB_PLUGIN_URL . '/assets/css/styles-admin.min.css', array(), PWB_PLUGIN_VERSION );
771
+
772
+ wp_register_script( 'pwb-functions-admin', PWB_PLUGIN_URL . '/assets/js/functions-admin.min.js', array( 'jquery' ), PWB_PLUGIN_VERSION, true );
773
+ wp_localize_script(
774
+ 'pwb-functions-admin',
775
+ 'pwb_ajax_object_admin',
776
+ array(
777
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
778
+ 'site_url' => site_url(),
779
+ 'brands_url' => admin_url( 'edit-tags.php?taxonomy=pwb-brand&post_type=product' ),
780
+ 'translations' => array(
781
+ 'migrate_notice' => esc_html__( '¿Start migration?', 'perfect-woocommerce-brands' ),
782
+ 'migrating' => esc_html__( 'We are migrating the product brands. ¡Don´t close this window until the process is finished!', 'perfect-woocommerce-brands' ),
783
+ 'dummy_data_notice' => esc_html__( '¿Start loading dummy data?', 'perfect-woocommerce-brands' ),
784
+ 'dummy_data' => esc_html__( 'We are importing the dummy data. ¡Don´t close this window until the process is finished!', 'perfect-woocommerce-brands' ),
785
+ ),
786
+ 'nonce' => array(
787
+ 'pwb_brands_export' => wp_create_nonce( 'pwb_brands_export' ), // ok
788
+ 'pwb_brands_import' => wp_create_nonce( 'pwb_brands_import' ), // ok
789
+ 'pwb_dismiss_notice' => wp_create_nonce( 'pwb_dismiss_notice' ), // ok
790
+ 'pwb_admin_set_featured_brand' => wp_create_nonce( 'pwb_admin_set_featured_brand' ), // ok
791
+ 'pwb_admin_save_screen_settings' => wp_create_nonce( 'pwb_admin_save_screen_settings' ), // ok
792
+ 'pwb_admin_dummy_data' => wp_create_nonce( 'pwb_admin_dummy_data' ), // ok
793
+ 'pwb_admin_migrate_brands' => wp_create_nonce( 'pwb_admin_migrate_brands' ),
794
+ 'pwb_system_status' => wp_create_nonce( 'pwb_system_status' ),
795
+ ),
796
+ )
797
+ );
798
+ wp_enqueue_script( 'pwb-functions-admin' );
799
+ }
800
+
801
+ public function register_brands_taxonomy() {
802
+ $labels = array(
803
+ 'name' => esc_html__( 'Brands', 'perfect-woocommerce-brands' ),
804
+ 'singular_name' => esc_html__( 'Brand', 'perfect-woocommerce-brands' ),
805
+ 'menu_name' => esc_html__( 'Brands', 'perfect-woocommerce-brands' ),
806
+ 'all_items' => esc_html__( 'All Brands', 'perfect-woocommerce-brands' ),
807
+ 'edit_item' => esc_html__( 'Edit Brand', 'perfect-woocommerce-brands' ),
808
+ 'view_item' => esc_html__( 'View Brand', 'perfect-woocommerce-brands' ),
809
+ 'update_item' => esc_html__( 'Update Brand', 'perfect-woocommerce-brands' ),
810
+ 'add_new_item' => esc_html__( 'Add New Brand', 'perfect-woocommerce-brands' ),
811
+ 'new_item_name' => esc_html__( 'New Brand Name', 'perfect-woocommerce-brands' ),
812
+ 'parent_item' => esc_html__( 'Parent Brand', 'perfect-woocommerce-brands' ),
813
+ 'parent_item_colon' => esc_html__( 'Parent Brand:', 'perfect-woocommerce-brands' ),
814
+ 'search_items' => esc_html__( 'Search Brands', 'perfect-woocommerce-brands' ),
815
+ 'popular_items' => esc_html__( 'Popular Brands', 'perfect-woocommerce-brands' ),
816
+ 'separate_items_with_commas' => esc_html__( 'Separate brands with commas', 'perfect-woocommerce-brands' ),
817
+ 'add_or_remove_items' => esc_html__( 'Add or remove brands', 'perfect-woocommerce-brands' ),
818
+ 'choose_from_most_used' => esc_html__( 'Choose from the most used brands', 'perfect-woocommerce-brands' ),
819
+ 'not_found' => esc_html__( 'No brands found', 'perfect-woocommerce-brands' ),
820
+ );
821
+
822
+ $new_slug = get_option( 'wc_pwb_admin_tab_slug' );
823
+ $old_slug = get_option( 'old_wc_pwb_admin_tab_slug' );
824
+
825
+ $new_slug = ( $new_slug != false ) ? $new_slug : 'brand';
826
+ $old_slug = ( $old_slug != false ) ? $old_slug : 'null';
827
+
828
+ $args = array(
829
+ 'hierarchical' => true,
830
+ 'labels' => $labels,
831
+ 'show_ui' => true,
832
+ 'query_var' => true,
833
+ 'public' => true,
834
+ 'show_admin_column' => true,
835
+ 'rewrite' => array(
836
+ 'slug' => apply_filters( 'pwb_taxonomy_rewrite', $new_slug ),
837
+ 'hierarchical' => true,
838
+ 'with_front' => apply_filters( 'pwb_taxonomy_with_front', true ),
839
+ 'ep_mask' => EP_PERMALINK,
840
+ ),
841
+ );
842
+
843
+ register_taxonomy( 'pwb-brand', array( 'product' ), $args );
844
+
845
+ if ( $new_slug != false && $old_slug != false && $new_slug != $old_slug ) {
846
+ flush_rewrite_rules();
847
+ update_option( 'old_wc_pwb_admin_tab_slug', $new_slug );
848
+ }
849
+ }
850
+
851
+ public function add_brands_metafields() {
852
+ register_meta( 'term', 'pwb_brand_image', array( $this, 'add_brands_metafields_sanitize' ) );
853
+ }
854
+
855
+ public function add_brands_metafields_sanitize( $brand_img ) {
856
+ return $brand_img;
857
+ }
858
+
859
+ public static function get_brands( $hide_empty = false, $order_by = 'name', $order = 'ASC', $only_featured = false, $pwb_term = false, $only_parents = false ) {
860
+ $result = array();
861
+
862
+ $brands_args = array(
863
+ 'hide_empty' => $hide_empty,
864
+ 'orderby' => $order_by,
865
+ 'order' => $order,
866
+ );
867
+ if ( $only_featured ) {
868
+ $brands_args['meta_query'] = array(
869
+ array(
870
+ 'key' => 'pwb_featured_brand',
871
+ 'value' => true,
872
+ ),
873
+ );
874
+ }
875
+ if ( $only_parents ) {
876
+ $brands_args['parent'] = 0;
877
+ }
878
+
879
+ $brands = get_terms( 'pwb-brand', $brands_args );
880
+
881
+ foreach ( $brands as $key => $brand ) {
882
+
883
+ if ( $pwb_term ) {
884
+ $brands[ $key ] = new PWB_Term( $brand );
885
+ } else {
886
+ $brand_image_id = get_term_meta( $brand->term_id, 'pwb_brand_image', true );
887
+ $brand_banner_id = get_term_meta( $brand->term_id, 'pwb_brand_banner', true );
888
+ $brand->brand_image = wp_get_attachment_image_src( $brand_image_id );
889
+ $brand->brand_banner = wp_get_attachment_image_src( $brand_banner_id );
890
+ }
891
+ }
892
+
893
+ if ( is_array( $brands ) && count( $brands ) > 0 ) {
894
+ $result = $brands;
895
+ }
896
+
897
+ return $result;
898
+ }
899
+
900
+ public static function get_brands_array( $is_select = false ) {
901
+ $result = array();
902
+
903
+ // if is for select input adds default value
904
+ if ( $is_select ) {
905
+ $result[0] = esc_html__( 'All', 'perfect-woocommerce-brands' );
906
+ }
907
+
908
+ $brands = get_terms(
909
+ 'pwb-brand',
910
+ array(
911
+ 'hide_empty' => false,
912
+ )
913
+ );
914
+
915
+ foreach ( $brands as $brand ) {
916
+ $result[ $brand->term_id ] = $brand->slug;
917
+ }
918
+
919
+ return $result;
920
+ }
921
+
922
+ public function print_brand_banner() {
923
+ $queried_object = get_queried_object();
924
+ $brand_banner = get_term_meta( $queried_object->term_id, 'pwb_brand_banner', true );
925
+ $brand_banner_link = get_term_meta( $queried_object->term_id, 'pwb_brand_banner_link', true );
926
+ $show_banner = get_option( 'wc_pwb_admin_tab_brand_banner' );
927
+ $show_banner = get_option( 'wc_pwb_admin_tab_brand_banner' );
928
+ $show_banner_class = ( ! $show_banner || $show_banner == 'yes' ) ? 'pwb-before-loop' : 'pwb-after-loop';
929
+
930
+ if ( $brand_banner != '' ) {
931
+ echo '<div class="pwb-brand-banner pwb-clearfix ' . esc_attr( $show_banner_class ) . '">';
932
+ if ( $brand_banner_link != '' ) {
933
+ echo '<a href="' . esc_url( site_url( $brand_banner_link ) ) . '">' . wp_get_attachment_image( $brand_banner, 'full', false ) . '</a>';
934
+ } else {
935
+ echo wp_get_attachment_image( $brand_banner, 'full', false );
936
+ }
937
+ echo '</div>';
938
+ }
939
+ }
940
+
941
+ public function print_brand_desc() {
942
+ $queried_object = get_queried_object();
943
+ $show_desc = get_option( 'wc_pwb_admin_tab_brand_desc' );
944
+ $show_desc = get_option( 'wc_pwb_admin_tab_brand_desc' );
945
+ $show_desc_class = ( ! $show_desc || $show_desc == 'yes' ) ? 'pwb-before-loop' : 'pwb-after-loop';
946
+
947
+ if ( $queried_object->description != '' && $show_desc !== 'no' ) {
948
+ echo '<div class="pwb-brand-description ' . esc_attr( $show_desc_class ) . '">';
949
+ echo do_shortcode( wpautop( $queried_object->description ) );
950
+ echo '</div>';
951
+ }
952
+ }
953
+
954
+ public function print_brand_banner_and_desc() {
955
+ $queried_object = get_queried_object();
956
+
957
+ $show_desc = get_option( 'wc_pwb_admin_tab_brand_desc' );
958
+ $show_desc_class = ( ! $show_desc || $show_desc == 'yes' ) ? 'pwb-before-loop' : 'pwb-after-loop';
959
+
960
+ $brand_banner = get_term_meta( $queried_object->term_id, 'pwb_brand_banner', true );
961
+ $brand_banner_link = get_term_meta( $queried_object->term_id, 'pwb_brand_banner_link', true );
962
+
963
+ if ( $brand_banner != '' || $queried_object->description != '' && $show_desc !== 'no' ) {
964
+ echo '<div class="pwb-brand-banner-cont ' . esc_attr( $show_desc_class ) . '">';
965
+ $this->print_brand_banner();
966
+ $this->print_brand_desc();
967
+ echo '</div>';
968
+ }
969
+ }
970
+
971
+ public static function render_template( $name = '', $folder = '', $data = array(), $private = true ) {
972
+ // default template
973
+ if ( $folder ) {
974
+ $folder = $folder . '/';
975
+ }
976
+ $template_file = dirname( __DIR__ ) . '/templates/' . $folder . $name . '.php';
977
+
978
+ // theme overrides
979
+ if ( ! $private ) {
980
+ $theme_template_path = get_stylesheet_directory() . '/perfect-woocommerce-brands/';
981
+ if ( file_exists( $theme_template_path . $folder . $name . '.php' ) ) {
982
+ $template_file = $theme_template_path . $folder . $name . '.php';
983
+ }
984
+ }
985
+
986
+ extract( $data );
987
+
988
+ ob_start();
989
+ include $template_file;
990
+ return ob_get_clean();
991
+ }
992
+
993
+ public function product_duplicate_save( $duplicate, $product ) {
994
+ $product_brands = wp_get_object_terms( $product->get_id(), 'pwb-brand', array( 'fields' => 'ids' ) );
995
+ wp_set_object_terms( $duplicate->get_id(), $product_brands, 'pwb-brand' );
996
+ }
997
+
998
+ public function breadcrumbs( $crumbs ) {
999
+ if ( is_tax( 'pwb-brand' ) ) {
1000
+
1001
+ $brands_page_id = get_option( 'wc_pwb_admin_tab_brands_page_id' );
1002
+
1003
+ if ( ! empty( $brands_page_id ) && $brands_page_id != '-' ) {
1004
+
1005
+ $cur_brand = get_queried_object();
1006
+ $brand_ancestors = get_ancestors( $cur_brand->term_id, 'pwb-brand', 'taxonomy' );
1007
+
1008
+ $brand_page_pos = count( $crumbs ) - ( count( $brand_ancestors ) + 2 );
1009
+ if ( is_paged() ) {
1010
+ $brand_page_pos -= 1;
1011
+ }
1012
+
1013
+ if ( isset( $crumbs[ $brand_page_pos ][1] ) ) {
1014
+ $crumbs[ $brand_page_pos ][1] = get_page_link( $brands_page_id );
1015
+ }
1016
+ }
1017
+ }
1018
+
1019
+ return $crumbs;
1020
+ }
1021
+
1022
+ /**
1023
+ * Redirect if the search matchs with a brands name
1024
+ * Better search experience
1025
+ */
1026
+ public function search_by_brand_name( $query ) {
1027
+ if ( wp_doing_ajax() ) {
1028
+ return;
1029
+ }
1030
+
1031
+ if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
1032
+
1033
+ $brands = get_terms(
1034
+ array(
1035
+ 'taxonomy' => 'pwb-brand',
1036
+ 'fields' => 'id=>name',
1037
+ )
1038
+ );
1039
+
1040
+ if ( $match = array_search( strtolower( trim( $query->get( 's' ) ) ), array_map( 'strtolower', $brands ) ) ) {
1041
+
1042
+ wp_redirect( get_term_link( $match ) );
1043
+ exit;
1044
+ }
1045
+ }
1046
+ }
1047
  }
classes/class-pwb-api-support.php CHANGED
@@ -4,156 +4,172 @@ namespace Perfect_Woocommerce_Brands;
4
 
5
  use WP_Error, WP_REST_Server;
6
 
7
- defined('ABSPATH') or die('No script kiddies please!');
8
-
9
- class PWB_API_Support
10
- {
11
-
12
- private $namespaces = array("wc/v1", "wc/v2", "wc/v3");
13
- private $base = 'brands';
14
-
15
- function __construct()
16
- {
17
- add_action('rest_api_init', array($this, 'register_endpoints'));
18
- add_action('rest_api_init', array($this, 'register_fields'));
19
- }
20
-
21
- /**
22
- * Registers the endpoint for all possible $namespaces
23
- */
24
- public function register_endpoints()
25
- {
26
- foreach ($this->namespaces as $namespace) {
27
- register_rest_route($namespace, '/' . $this->base, array(
28
- array(
29
- 'methods' => WP_REST_Server::READABLE,
30
- 'callback' => function () {
31
- return rest_ensure_response(
32
- Perfect_Woocommerce_Brands::get_brands()
33
- );
34
- },
35
- 'permission_callback' => '__return_true'
36
- ),
37
- array(
38
- 'methods' => WP_REST_Server::CREATABLE,
39
- 'callback' => array($this, 'create_brand'),
40
- 'permission_callback' => function () {
41
- return current_user_can('manage_options');
42
- }
43
-
44
- ),
45
- array(
46
- 'methods' => WP_REST_Server::DELETABLE,
47
- 'callback' => array($this, 'delete_brand'),
48
- 'permission_callback' => function () {
49
- return current_user_can('manage_options');
50
- }
51
- )
52
- ));
53
- }
54
- }
55
-
56
- public function delete_brand($request)
57
- {
58
- foreach ($request['brands'] as $brand) {
59
- $delete_result = wp_delete_term($brand, 'pwb-brand');
60
- if (is_wp_error($delete_result)) return $delete_result;
61
- }
62
- return true;
63
- }
64
-
65
- public function create_brand($request)
66
- {
67
- $new_brand = wp_insert_term($request['name'], 'pwb-brand', array('slug' => $request['slug'], 'description' => $request['description']));
68
- if (!is_wp_error($new_brand)) {
69
- return array('id' => $new_brand['term_id'], 'name' => $request['name'], 'slug' => $request['slug'], 'description' => $request['description']);
70
- } else {
71
- return $new_brand;
72
- }
73
- }
74
-
75
- /**
76
- * Entry point for all rest field settings
77
- */
78
- public function register_fields()
79
- {
80
- register_rest_field('product', 'brands', array(
81
- 'get_callback' => array($this, "get_callback"),
82
- 'update_callback' => array($this, "update_callback"),
83
- 'schema' => $this->get_schema(),
84
- ));
85
- }
86
-
87
- /**
88
- * Returns the schema of the "brands" field on the /product route
89
- * To attach a brand to a product just append a "brands" key containing an array of brand id's
90
- * An empty array wil detach all brands.
91
- * @return array
92
- */
93
- public function get_schema()
94
- {
95
- return array(
96
- 'description' => __('Product brands', 'perfect-woocommerce-brands'),
97
- 'type' => 'array',
98
- 'items' => array(
99
- "type" => "integer"
100
- ),
101
- 'context' => array("view", "edit")
102
- );
103
- }
104
-
105
- /**
106
- * Returns all attached brands to a GET request to /products(/id)
107
- * @param $product
108
- * @return array|\WP_Error
109
- */
110
- public function get_callback($product)
111
- {
112
- $brands = wp_get_post_terms($product['id'], 'pwb-brand');
113
-
114
- $result_brands_array = array();
115
- foreach ($brands as $brand) {
116
- $result_brands_array[] = array(
117
- 'id' => $brand->term_id,
118
- 'name' => $brand->name,
119
- 'slug' => $brand->slug
120
- );
121
- }
122
-
123
- return $result_brands_array;
124
- }
125
-
126
- /**
127
- * Entry point for an update call
128
- * @param $brands
129
- * @param $product
130
- */
131
- public function update_callback($brands, $product)
132
- {
133
- $this->remove_brands($product);
134
- $this->add_brands($brands, $product);
135
- }
136
-
137
-
138
- /**
139
- * Detaches all brands from a product
140
- * @param \WC_Product $product
141
- */
142
- private function remove_brands($product)
143
- {
144
- $brands = wp_get_post_terms($product->get_id(), 'pwb-brand');
145
- if (!empty($brands)) {
146
- wp_set_post_terms($product->get_id(), array(), 'pwb-brand');
147
- }
148
- }
149
-
150
- /**
151
- * Attaches the given brands to a product. Earlier attached brands, not in this array, will be removed
152
- * @param array $brands
153
- * @param \WC_Product $product
154
- */
155
- private function add_brands($brands, $product)
156
- {
157
- wp_set_post_terms($product->get_id(), $brands, "pwb-brand");
158
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  }
4
 
5
  use WP_Error, WP_REST_Server;
6
 
7
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
8
+
9
+ class PWB_API_Support {
10
+
11
+ private $namespaces = array( 'wc/v1', 'wc/v2', 'wc/v3' );
12
+ private $base = 'brands';
13
+
14
+ function __construct() {
15
+ add_action( 'rest_api_init', array( $this, 'register_endpoints' ) );
16
+ add_action( 'rest_api_init', array( $this, 'register_fields' ) );
17
+ }
18
+
19
+ /**
20
+ * Registers the endpoint for all possible $namespaces
21
+ */
22
+ public function register_endpoints() {
23
+ foreach ( $this->namespaces as $namespace ) {
24
+ register_rest_route(
25
+ $namespace,
26
+ '/' . $this->base,
27
+ array(
28
+ array(
29
+ 'methods' => WP_REST_Server::READABLE,
30
+ 'callback' => function () {
31
+ return rest_ensure_response(
32
+ Perfect_Woocommerce_Brands::get_brands()
33
+ );
34
+ },
35
+ 'permission_callback' => '__return_true',
36
+ ),
37
+ array(
38
+ 'methods' => WP_REST_Server::CREATABLE,
39
+ 'callback' => array( $this, 'create_brand' ),
40
+ 'permission_callback' => function () {
41
+ return current_user_can( 'manage_options' );
42
+ },
43
+
44
+ ),
45
+ array(
46
+ 'methods' => WP_REST_Server::DELETABLE,
47
+ 'callback' => array( $this, 'delete_brand' ),
48
+ 'permission_callback' => function () {
49
+ return current_user_can( 'manage_options' );
50
+ },
51
+ ),
52
+ )
53
+ );
54
+ }
55
+ }
56
+
57
+ public function delete_brand( $request ) {
58
+ foreach ( $request['brands'] as $brand ) {
59
+ $delete_result = wp_delete_term( $brand, 'pwb-brand' );
60
+ if ( is_wp_error( $delete_result ) ) {
61
+ return $delete_result;
62
+ }
63
+ }
64
+ return true;
65
+ }
66
+
67
+ public function create_brand( $request ) {
68
+ $new_brand = wp_insert_term(
69
+ $request['name'],
70
+ 'pwb-brand',
71
+ array(
72
+ 'slug' => $request['slug'],
73
+ 'description' => $request['description'],
74
+ )
75
+ );
76
+ if ( ! is_wp_error( $new_brand ) ) {
77
+ return array(
78
+ 'id' => $new_brand['term_id'],
79
+ 'name' => $request['name'],
80
+ 'slug' => $request['slug'],
81
+ 'description' => $request['description'],
82
+ );
83
+ } else {
84
+ return $new_brand;
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Entry point for all rest field settings
90
+ */
91
+ public function register_fields() {
92
+ register_rest_field(
93
+ 'product',
94
+ 'brands',
95
+ array(
96
+ 'get_callback' => array( $this, 'get_callback' ),
97
+ 'update_callback' => array( $this, 'update_callback' ),
98
+ 'schema' => $this->get_schema(),
99
+ )
100
+ );
101
+ }
102
+
103
+ /**
104
+ * Returns the schema of the "brands" field on the /product route
105
+ * To attach a brand to a product just append a "brands" key containing an array of brand id's
106
+ * An empty array wil detach all brands.
107
+ *
108
+ * @return array
109
+ */
110
+ public function get_schema() {
111
+ return array(
112
+ 'description' => __( 'Product brands', 'perfect-woocommerce-brands' ),
113
+ 'type' => 'array',
114
+ 'items' => array(
115
+ 'type' => 'integer',
116
+ ),
117
+ 'context' => array( 'view', 'edit' ),
118
+ );
119
+ }
120
+
121
+ /**
122
+ * Returns all attached brands to a GET request to /products(/id)
123
+ *
124
+ * @param $product
125
+ * @return array|\WP_Error
126
+ */
127
+ public function get_callback( $product ) {
128
+ $brands = wp_get_post_terms( $product['id'], 'pwb-brand' );
129
+
130
+ $result_brands_array = array();
131
+ foreach ( $brands as $brand ) {
132
+ $result_brands_array[] = array(
133
+ 'id' => $brand->term_id,
134
+ 'name' => $brand->name,
135
+ 'slug' => $brand->slug,
136
+ );
137
+ }
138
+
139
+ return $result_brands_array;
140
+ }
141
+
142
+ /**
143
+ * Entry point for an update call
144
+ *
145
+ * @param $brands
146
+ * @param $product
147
+ */
148
+ public function update_callback( $brands, $product ) {
149
+ $this->remove_brands( $product );
150
+ $this->add_brands( $brands, $product );
151
+ }
152
+
153
+
154
+ /**
155
+ * Detaches all brands from a product
156
+ *
157
+ * @param \WC_Product $product
158
+ */
159
+ private function remove_brands( $product ) {
160
+ $brands = wp_get_post_terms( $product->get_id(), 'pwb-brand' );
161
+ if ( ! empty( $brands ) ) {
162
+ wp_set_post_terms( $product->get_id(), array(), 'pwb-brand' );
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Attaches the given brands to a product. Earlier attached brands, not in this array, will be removed
168
+ *
169
+ * @param array $brands
170
+ * @param \WC_Product $product
171
+ */
172
+ private function add_brands( $brands, $product ) {
173
+ wp_set_post_terms( $product->get_id(), $brands, 'pwb-brand' );
174
+ }
175
  }
classes/class-pwb-product-tab.php CHANGED
@@ -1,71 +1,62 @@
1
  <?php
2
-
3
  namespace Perfect_Woocommerce_Brands;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
-
7
- class PWB_Product_Tab
8
- {
9
-
10
- function __construct()
11
- {
12
- add_filter('woocommerce_product_tabs', array($this, 'product_tab'));
13
- }
14
-
15
- public function product_tab($tabs)
16
- {
17
-
18
- global $product;
19
-
20
- if (isset($product)) {
21
- $brands = wp_get_object_terms($product->get_id(), 'pwb-brand');
22
-
23
- if (!empty($brands)) {
24
- $show_brand_tab = get_option('wc_pwb_admin_tab_brand_single_product_tab');
25
- if ($show_brand_tab == 'yes' || !$show_brand_tab) {
26
- $tabs['pwb_tab'] = array(
27
- 'title' => __('Brand', 'perfect-woocommerce-brands'),
28
- 'priority' => 20,
29
- 'callback' => array($this, 'product_tab_content')
30
- );
31
- }
32
- }
33
- }
34
-
35
- return $tabs;
36
- }
37
-
38
- public function product_tab_content()
39
- {
40
-
41
- global $product;
42
- $brands = wp_get_object_terms($product->get_id(), 'pwb-brand');
43
-
44
- ob_start();
45
- ?>
46
-
47
- <h2><?php echo apply_filters('woocommerce_product_brand_heading', esc_html__('Brand', 'perfect-woocommerce-brands')); ?></h2>
48
- <?php foreach ($brands as $brand) : ?>
49
-
50
- <?php
51
- $image_size = get_option('wc_pwb_admin_tab_brand_logo_size', 'thumbnail');
52
- $brand_logo = get_term_meta($brand->term_id, 'pwb_brand_image', true);
53
- $brand_logo = wp_get_attachment_image($brand_logo, apply_filters('pwb_product_tab_brand_logo_size', $image_size));
54
- ?>
55
-
56
- <div id="tab-pwb_tab-content">
57
- <h3><?php echo esc_html($brand->name); ?></h3>
58
- <?php if (!empty($brand->description)) : ?>
59
- <div><?php echo do_shortcode($brand->description); ?></div>
60
- <?php endif; ?>
61
- <?php if (!empty($brand_logo)) : ?>
62
- <span><?php echo wp_kses_post($brand_logo); ?></span>
63
- <?php endif; ?>
64
- </div>
65
-
66
- <?php endforeach; ?>
67
-
68
- <?php
69
- echo ob_get_clean();
70
- }
71
  }
1
  <?php
 
2
  namespace Perfect_Woocommerce_Brands;
3
 
4
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
5
+
6
+ class PWB_Product_Tab {
7
+
8
+
9
+ function __construct() {
10
+ add_filter( 'woocommerce_product_tabs', array( $this, 'product_tab' ) );
11
+ }
12
+
13
+ public function product_tab( $tabs ) {
14
+ global $product;
15
+
16
+ if ( isset( $product ) ) {
17
+ $brands = wp_get_object_terms( $product->get_id(), 'pwb-brand' );
18
+
19
+ if ( ! empty( $brands ) ) {
20
+ $show_brand_tab = get_option( 'wc_pwb_admin_tab_brand_single_product_tab' );
21
+ if ( $show_brand_tab == 'yes' || ! $show_brand_tab ) {
22
+ $tabs['pwb_tab'] = array(
23
+ 'title' => __( 'Brand', 'perfect-woocommerce-brands' ),
24
+ 'priority' => 20,
25
+ 'callback' => array( $this, 'product_tab_content' ),
26
+ );
27
+ }
28
+ }
29
+ }
30
+
31
+ return $tabs;
32
+ }
33
+
34
+ public function product_tab_content() {
35
+ global $product;
36
+ $brands = wp_get_object_terms( $product->get_id(), 'pwb-brand' );
37
+
38
+ ob_start();
39
+ ?>
40
+
41
+ <h2><?php echo esc_html( apply_filters( 'woocommerce_product_brand_heading', esc_html__( 'Brand', 'perfect-woocommerce-brands' ) ) ); ?></h2>
42
+ <?php foreach ( $brands as $brand ) : ?>
43
+ <?php
44
+ $image_size = get_option( 'wc_pwb_admin_tab_brand_logo_size', 'thumbnail' );
45
+ $brand_logo = get_term_meta( $brand->term_id, 'pwb_brand_image', true );
46
+ $brand_logo = wp_get_attachment_image( $brand_logo, apply_filters( 'pwb_product_tab_brand_logo_size', $image_size ) );
47
+ ?>
48
+ <div id="tab-pwb_tab-content">
49
+ <h3><?php echo esc_html( $brand->name ); ?></h3>
50
+ <?php if ( ! empty( $brand->description ) ) : ?>
51
+ <div><?php echo do_shortcode( $brand->description ); ?></div>
52
+ <?php endif; ?>
53
+ <?php if ( ! empty( $brand_logo ) ) : ?>
54
+ <span><?php echo wp_kses_post( $brand_logo ); ?></span>
55
+ <?php endif; ?>
56
+ </div>
57
+ <?php endforeach; ?>
58
+ <?php
59
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
60
+ echo ob_get_clean();
61
+ }
 
 
 
 
 
 
 
 
62
  }
classes/class-pwb-suggestions-list-table.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Perfect_Woocommerce_Brands;
4
+
5
+ require_once ABSPATH . 'wp-admin/includes/class-wp-plugin-install-list-table.php';
6
+
7
+ class PWB_Suggestions_List_Table extends \WP_Plugin_Install_List_Table {
8
+
9
+
10
+ public $promote = array(
11
+ 'woocommerce-checkout-manager',
12
+ 'woocommerce-direct-checkout',
13
+ 'wp-whatsapp-chat',
14
+ 'quadlayers-telegram-chat',
15
+ 'wp-tiktok-feed',
16
+ 'insta-gallery',
17
+ 'quadmenu',
18
+ );
19
+
20
+ private function remove_plugins( $plugins ) {
21
+ $promote = array();
22
+
23
+ foreach ( $this->promote as $order => $slug ) {
24
+
25
+ if ( $id = @max( array_keys( array_column( $plugins, 'slug' ), $slug ) ) ) {
26
+
27
+ $promote[] = $plugins[ $id ];
28
+ }
29
+ }
30
+
31
+ return $promote;
32
+ }
33
+
34
+ public function self_admin_url( $url, $path ) {
35
+ if ( strpos( $url, 'tab=plugin-information' ) !== false ) {
36
+ $url = network_admin_url( $path );
37
+ }
38
+
39
+ return $url;
40
+ }
41
+
42
+ public function network_admin_url( $url, $path ) {
43
+ if ( strpos( $url, 'plugins.php' ) !== false ) {
44
+ $url = self_admin_url( $path );
45
+ }
46
+
47
+ return $url;
48
+ }
49
+
50
+ public function display_rows() {
51
+ add_filter( 'self_admin_url', array( $this, 'self_admin_url' ), 10, 2 );
52
+ add_filter( 'network_admin_url', array( $this, 'network_admin_url' ), 10, 2 );
53
+ parent::display_rows();
54
+ }
55
+
56
+ public function is_connected() {
57
+ global $wp_version;
58
+
59
+ $http_args = array(
60
+ 'timeout' => 15,
61
+ 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
62
+ );
63
+
64
+ return is_wp_error( wp_remote_get( 'http://api.wordpress.org/plugins/info/1.2/', $http_args ) );
65
+ }
66
+
67
+ public function get_plugins() {
68
+ $tk = PWB_PREFIX . '_suggestions_plugins';
69
+
70
+ $plugins = get_transient( $tk );
71
+
72
+ if ( $plugins === false ) {
73
+
74
+ $args = array(
75
+ 'per_page' => 36,
76
+ 'author' => 'quadlayers',
77
+ 'locale' => get_user_locale(),
78
+ );
79
+
80
+ $api = plugins_api( 'query_plugins', $args );
81
+
82
+ if ( ! is_wp_error( $api ) ) {
83
+
84
+ $plugins = $this->remove_plugins( $api->plugins );
85
+
86
+ set_transient( $tk, $plugins, 24 * HOUR_IN_SECONDS );
87
+ }
88
+ }
89
+
90
+ return $plugins;
91
+ }
92
+
93
+ public function prepare_items() {
94
+ include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
95
+
96
+ global $tabs, $tab;
97
+
98
+ wp_enqueue_style( 'thickbox' );
99
+ wp_enqueue_script( 'plugin-install' );
100
+ wp_enqueue_script( 'thickbox' );
101
+ wp_enqueue_script( 'updates' );
102
+ // wp_localize_script('updates', 'pagenow', array('plugin-install-network'))
103
+
104
+ wp_reset_vars( array( 'tab' ) );
105
+
106
+ $tabs = array();
107
+
108
+ if ( 'search' === $tab ) {
109
+ $tabs['search'] = esc_html__( 'Search Results' );
110
+ }
111
+ if ( $tab === 'beta' || false !== strpos( get_bloginfo( 'version' ), '-' ) ) {
112
+ $tabs['beta'] = _x( 'Beta Testing', 'Plugin Installer' );
113
+ }
114
+ $tabs['featured'] = _x( 'Featured', 'Plugin Installer' );
115
+ $tabs['popular'] = _x( 'Popular', 'Plugin Installer' );
116
+ $tabs['recommended'] = _x( 'Recommended', 'Plugin Installer' );
117
+ $tabs['favorites'] = _x( 'Favorites', 'Plugin Installer' );
118
+
119
+ $nonmenu_tabs = array( 'plugin-information' ); // Valid actions to perform which do not have a Menu item.
120
+
121
+ $tabs = apply_filters( 'install_plugins_tabs', $tabs );
122
+
123
+ $nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
124
+
125
+ // If a non-valid menu tab has been selected, And it's not a non-menu action.
126
+ if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) ) {
127
+ $tab = key( $tabs );
128
+ }
129
+
130
+ $this->items = $this->get_plugins();
131
+
132
+ wp_localize_script(
133
+ 'updates',
134
+ '_wpUpdatesItemCounts',
135
+ array(
136
+ 'totals' => wp_get_update_data(),
137
+ )
138
+ );
139
+ }
140
+ }
classes/class-pwb-suggestions-list.php DELETED
@@ -1,154 +0,0 @@
1
- <?php
2
-
3
- namespace Perfect_Woocommerce_Brands;
4
-
5
- require_once(ABSPATH . 'wp-admin/includes/class-wp-plugin-install-list-table.php');
6
-
7
- class PWB_Suggestions_List_Table extends \WP_Plugin_Install_List_Table
8
- {
9
-
10
- public $promote = array(
11
- 'woocommerce-checkout-manager',
12
- 'woocommerce-direct-checkout',
13
- 'wp-whatsapp-chat',
14
- 'quadlayers-telegram-chat',
15
- 'wp-tiktok-feed',
16
- 'insta-gallery',
17
- 'quadmenu',
18
- );
19
-
20
- private function remove_plugins($plugins)
21
- {
22
-
23
- $promote = array();
24
-
25
- foreach ($this->promote as $order => $slug) {
26
-
27
- if ($id = @max(array_keys(array_column($plugins, 'slug'), $slug))) {
28
-
29
- $promote[] = $plugins[$id];
30
- }
31
- }
32
-
33
- return $promote;
34
- }
35
-
36
- public function self_admin_url($url, $path)
37
- {
38
-
39
- if (strpos($url, 'tab=plugin-information') !== false) {
40
- $url = network_admin_url($path);
41
- }
42
-
43
- return $url;
44
- }
45
-
46
- public function network_admin_url($url, $path)
47
- {
48
-
49
- if (strpos($url, 'plugins.php') !== false) {
50
- $url = self_admin_url($path);
51
- }
52
-
53
- return $url;
54
- }
55
-
56
- public function display_rows()
57
- {
58
- add_filter('self_admin_url', array($this, 'self_admin_url'), 10, 2);
59
- add_filter('network_admin_url', array($this, 'network_admin_url'), 10, 2);
60
- parent::display_rows();
61
- }
62
-
63
- public function is_connected()
64
- {
65
-
66
- global $wp_version;
67
-
68
- $http_args = array(
69
- 'timeout' => 15,
70
- 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url('/'),
71
- );
72
-
73
- return is_wp_error(wp_remote_get('http://api.wordpress.org/plugins/info/1.2/', $http_args));
74
- }
75
-
76
- public function get_plugins()
77
- {
78
-
79
- $tk = PWB_PREFIX . '_suggestions_plugins';
80
-
81
- $plugins = get_transient($tk);
82
-
83
- if ($plugins === false) {
84
-
85
- $args = array(
86
- 'per_page' => 36,
87
- 'author' => 'quadlayers',
88
- 'locale' => get_user_locale(),
89
- );
90
-
91
- $api = plugins_api('query_plugins', $args);
92
-
93
- if (!is_wp_error($api)) {
94
-
95
- $plugins = $this->remove_plugins($api->plugins);
96
-
97
- set_transient($tk, $plugins, 24 * HOUR_IN_SECONDS);
98
- }
99
- }
100
-
101
- return $plugins;
102
- }
103
-
104
- public function prepare_items()
105
- {
106
-
107
- include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
108
-
109
- global $tabs, $tab;
110
-
111
- wp_enqueue_style('thickbox');
112
- wp_enqueue_script('plugin-install');
113
- wp_enqueue_script('thickbox');
114
- wp_enqueue_script('updates');
115
- // wp_localize_script('updates', 'pagenow', array('plugin-install-network'))
116
-
117
- wp_reset_vars(array('tab'));
118
-
119
- $tabs = array();
120
-
121
- if ('search' === $tab) {
122
- $tabs['search'] = esc_html__('Search Results');
123
- }
124
- if ($tab === 'beta' || false !== strpos(get_bloginfo('version'), '-')) {
125
- $tabs['beta'] = _x('Beta Testing', 'Plugin Installer');
126
- }
127
- $tabs['featured'] = _x('Featured', 'Plugin Installer');
128
- $tabs['popular'] = _x('Popular', 'Plugin Installer');
129
- $tabs['recommended'] = _x('Recommended', 'Plugin Installer');
130
- $tabs['favorites'] = _x('Favorites', 'Plugin Installer');
131
-
132
- $nonmenu_tabs = array('plugin-information'); // Valid actions to perform which do not have a Menu item.
133
-
134
- $tabs = apply_filters('install_plugins_tabs', $tabs);
135
-
136
- $nonmenu_tabs = apply_filters('install_plugins_nonmenu_tabs', $nonmenu_tabs);
137
-
138
- // If a non-valid menu tab has been selected, And it's not a non-menu action.
139
- if (empty($tab) || (!isset($tabs[$tab]) && !in_array($tab, (array) $nonmenu_tabs))) {
140
- $tab = key($tabs);
141
- }
142
-
143
- $this->items = $this->get_plugins();
144
-
145
-
146
- wp_localize_script(
147
- 'updates',
148
- '_wpUpdatesItemCounts',
149
- array(
150
- 'totals' => wp_get_update_data()
151
- )
152
- );
153
- }
154
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-pwb-term.php CHANGED
@@ -2,38 +2,38 @@
2
 
3
  namespace Perfect_Woocommerce_Brands;
4
 
5
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
6
-
7
- class PWB_Term{
8
-
9
- protected $term_obj, $id, $name, $link, $image, $banner, $banner_link, $desc, $slug;
10
-
11
- function __construct( $term_obj ){
12
- $this->term_obj = $term_obj;
13
- $this->is_wp_term();
14
- }
15
-
16
- private function is_wp_term(){
17
- if( is_a( $this->term_obj, 'WP_Term' ) ){
18
- $this->build_pwb_term( $this->term_obj );
19
- }else{
20
- throw new Exception( esc_html__('Only WP_Term objects are allowed', 'perfect-woocommerce-brands') );
21
- }
22
- }
23
-
24
- protected function build_pwb_term(){
25
- $this->id = $this->term_obj->term_id;
26
- $this->name = $this->term_obj->name;
27
- $this->slug = $this->term_obj->slug;
28
- $this->desc = get_term_meta( $this->id, 'pwb_brand_banner_description', true );
29
- $this->link = get_term_link( $this->term_obj->term_id );
30
- $this->image = htmlentities( wp_get_attachment_image( get_term_meta( $this->id, 'pwb_brand_image', true ), 'full' ) );
31
- $this->banner = htmlentities( wp_get_attachment_image( get_term_meta( $this->id, 'pwb_brand_banner', true ), 'full' ) );
32
- $this->banner_link = get_term_meta( $this->id, 'pwb_brand_banner_link', true) ;
33
- }
34
-
35
- public function get( $key = 'id' ){
36
- return ( isset( $this->$key ) ) ? $this->$key : false;
37
- }
38
 
39
  }
2
 
3
  namespace Perfect_Woocommerce_Brands;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class PWB_Term {
8
+
9
+ protected $term_obj, $id, $name, $link, $image, $banner, $banner_link, $desc, $slug;
10
+
11
+ function __construct( $term_obj ) {
12
+ $this->term_obj = $term_obj;
13
+ $this->is_wp_term();
14
+ }
15
+
16
+ private function is_wp_term() {
17
+ if ( is_a( $this->term_obj, 'WP_Term' ) ) {
18
+ $this->build_pwb_term( $this->term_obj );
19
+ } else {
20
+ throw new Exception( esc_html__( 'Only WP_Term objects are allowed', 'perfect-woocommerce-brands' ) );
21
+ }
22
+ }
23
+
24
+ protected function build_pwb_term() {
25
+ $this->id = $this->term_obj->term_id;
26
+ $this->name = $this->term_obj->name;
27
+ $this->slug = $this->term_obj->slug;
28
+ $this->desc = get_term_meta( $this->id, 'pwb_brand_banner_description', true );
29
+ $this->link = get_term_link( $this->term_obj->term_id );
30
+ $this->image = htmlentities( wp_get_attachment_image( get_term_meta( $this->id, 'pwb_brand_image', true ), 'full' ) );
31
+ $this->banner = htmlentities( wp_get_attachment_image( get_term_meta( $this->id, 'pwb_brand_banner', true ), 'full' ) );
32
+ $this->banner_link = get_term_meta( $this->id, 'pwb_brand_banner_link', true );
33
+ }
34
+
35
+ public function get( $key = 'id' ) {
36
+ return ( isset( $this->$key ) ) ? $this->$key : false;
37
+ }
38
 
39
  }
classes/shortcodes/class-pwb-all-brands.php CHANGED
@@ -2,176 +2,169 @@
2
 
3
  namespace Perfect_Woocommerce_Brands\Shortcodes;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
-
7
- class PWB_All_Brands_Shortcode
8
- {
9
-
10
- public static function all_brands_shortcode($atts)
11
- {
12
-
13
- $atts = shortcode_atts(array(
14
- 'per_page' => "10",
15
- 'image_size' => "thumbnail",
16
- 'hide_empty' => false,
17
- 'order_by' => 'name',
18
- 'order' => 'ASC',
19
- 'title_position' => 'before'
20
- ), $atts, 'pwb-all-brands');
21
-
22
- $hide_empty = ($atts['hide_empty'] != 'true') ? false : true;
23
-
24
- ob_start();
25
-
26
- $brands = array();
27
- if ($atts['order_by'] == 'rand') {
28
- $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands($hide_empty);
29
- shuffle($brands);
30
- } else {
31
- $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands($hide_empty, $atts['order_by'], $atts['order']);
32
- }
33
-
34
- //remove residual empty brands
35
- foreach ($brands as $key => $brand) {
36
-
37
- $count = self::count_visible_products($brand->term_id);
38
-
39
- if (!$count && $hide_empty) {
40
- unset($brands[$key]);
41
- } else {
42
- $brands[$key]->count_pwb = $count;
43
- }
44
- }
45
-
46
- ?>
47
- <div class="pwb-all-brands">
48
- <?php static::pagination($brands, $atts['per_page'], $atts['image_size'], $atts['title_position']); ?>
49
- </div>
50
- <?php
51
-
52
- return ob_get_clean();
53
- }
54
-
55
- /**
56
- * WP_Term->count property don´t care about hidden products
57
- * Counts the products in a specific brand
58
- */
59
- public static function count_visible_products($brand_id)
60
- {
61
-
62
- $args = array(
63
- 'posts_per_page' => -1,
64
- 'post_type' => 'product',
65
- 'tax_query' => array(
66
- array(
67
- 'taxonomy' => 'pwb-brand',
68
- 'field' => 'term_id',
69
- 'terms' => $brand_id
70
- ),
71
- array(
72
- 'taxonomy' => 'product_visibility',
73
- 'field' => 'name',
74
- 'terms' => 'exclude-from-catalog',
75
- 'operator' => 'NOT IN',
76
- )
77
- )
78
- );
79
- $wc_query = new \WP_Query($args);
80
-
81
- return $wc_query->found_posts;
82
- }
83
-
84
- public static function pagination($display_array, $show_per_page, $image_size, $title_position)
85
- {
86
- $page = 1;
87
-
88
- if (isset($_GET['pwb-page']) && filter_var($_GET['pwb-page'], FILTER_VALIDATE_INT) == true) {
89
- $page = intval($_GET['pwb-page']);
90
- }
91
-
92
- $page = $page < 1 ? 1 : $page;
93
-
94
- // start position in the $display_array
95
- // +1 is to account for total values.
96
- $start = ($page - 1) * ($show_per_page);
97
- $offset = $show_per_page;
98
-
99
- $outArray = array_slice($display_array, $start, $offset);
100
-
101
- //pagination links
102
- $total_elements = count($display_array);
103
- $pages = ((int)$total_elements / (int)$show_per_page);
104
- $pages = ceil($pages);
105
- if ($pages >= 1 && $page <= $pages) {
106
-
107
- ?>
108
- <div class="pwb-brands-cols-outer">
109
- <?php
110
- foreach ($outArray as $brand) {
111
-
112
- $brand_id = $brand->term_id;
113
- $brand_name = $brand->name;
114
- $brand_link = get_term_link($brand_id);
115
-
116
- $attachment_id = get_term_meta($brand_id, 'pwb_brand_image', 1);
117
- $attachment_html = $brand_name;
118
- if ($attachment_id != '') {
119
- $attachment_html = wp_get_attachment_image($attachment_id, $image_size);
120
- }
121
-
122
- ?>
123
- <div class="pwb-brands-col3">
124
-
125
- <?php if ($title_position != 'none' && $title_position != 'after') : ?>
126
- <p>
127
- <a href="<?php echo esc_url($brand_link); ?>">
128
- <?php echo esc_html($brand_name); ?>
129
- </a>
130
- <small>(<?php echo esc_html($brand->count_pwb); ?>)</small>
131
- </p>
132
- <?php endif; ?>
133
-
134
- <div>
135
- <a href="<?php echo esc_url($brand_link); ?>" title="<?php echo esc_html($brand_name); ?>">
136
- <?php echo wp_kses_post($attachment_html); ?>
137
- </a>
138
- </div>
139
-
140
- <?php if ($title_position != 'none' && $title_position == 'after') : ?>
141
- <p>
142
- <a href="<?php echo esc_html($brand_link); ?>">
143
- <?php echo wp_kses_post($brand_name); ?>
144
- </a>
145
- <small>(<?php echo esc_html($brand->count_pwb); ?>)</small>
146
- </p>
147
- <?php endif; ?>
148
-
149
- </div>
150
- <?php
151
- }
152
- ?>
153
- </div>
154
- <?php
155
- $next = $page + 1;
156
- $prev = $page - 1;
157
-
158
- echo '<div class="pwb-pagination-wrapper">';
159
- if ($prev > 1) {
160
- echo '<a href="' . get_the_permalink() . '" class="pwb-pagination prev" title="' . esc_html__('First page', 'perfect-woocommerce-brands') . '">&laquo;</a>';
161
- }
162
- if ($prev > 0) {
163
- echo '<a href="' . get_the_permalink() . '?pwb-page=' . esc_attr($prev) . '" class="pwb-pagination last" title="' . esc_html__('Previous page', 'perfect-woocommerce-brands') . '">&lsaquo;</a>';
164
- }
165
-
166
- if ($next <= $pages) {
167
- echo '<a href="' . get_the_permalink() . '?pwb-page=' . esc_attr($next) . '" class="pwb-pagination first" title="' . esc_html__('Next page', 'perfect-woocommerce-brands') . '">&rsaquo;</a>';
168
- }
169
- if ($next < $pages) {
170
- echo '<a href="' . get_the_permalink() . '?pwb-page=' . esc_attr($pages) . '" class="pwb-pagination next" title="' . esc_html__('Last page', 'perfect-woocommerce-brands') . '">&raquo;</a>';
171
- }
172
- echo '</div>';
173
- } else {
174
- echo esc_html__('No results', 'perfect-woocommerce-brands');
175
- }
176
- }
177
  }
2
 
3
  namespace Perfect_Woocommerce_Brands\Shortcodes;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class PWB_All_Brands_Shortcode {
8
+
9
+ public static function all_brands_shortcode( $atts ) {
10
+ $atts = shortcode_atts(
11
+ array(
12
+ 'per_page' => '10',
13
+ 'image_size' => 'thumbnail',
14
+ 'hide_empty' => false,
15
+ 'order_by' => 'name',
16
+ 'order' => 'ASC',
17
+ 'title_position' => 'before',
18
+ ),
19
+ $atts,
20
+ 'pwb-all-brands'
21
+ );
22
+
23
+ $hide_empty = ( $atts['hide_empty'] != 'true' ) ? false : true;
24
+
25
+ ob_start();
26
+
27
+ $brands = array();
28
+ if ( $atts['order_by'] == 'rand' ) {
29
+ $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands( $hide_empty );
30
+ shuffle( $brands );
31
+ } else {
32
+ $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands( $hide_empty, $atts['order_by'], $atts['order'] );
33
+ }
34
+
35
+ // remove residual empty brands
36
+ foreach ( $brands as $key => $brand ) {
37
+
38
+ $count = self::count_visible_products( $brand->term_id );
39
+
40
+ if ( ! $count && $hide_empty ) {
41
+ unset( $brands[ $key ] );
42
+ } else {
43
+ $brands[ $key ]->count_pwb = $count;
44
+ }
45
+ }
46
+
47
+ ?>
48
+ <div class="pwb-all-brands">
49
+ <?php static::pagination( $brands, $atts['per_page'], $atts['image_size'], $atts['title_position'] ); ?>
50
+ </div>
51
+ <?php
52
+
53
+ return ob_get_clean();
54
+ }
55
+
56
+ /**
57
+ * WP_Term->count property don´t care about hidden products
58
+ * Counts the products in a specific brand
59
+ */
60
+
61
+ public static function count_visible_products( $brand_id ) {
62
+ $args = array(
63
+ 'posts_per_page' => -1,
64
+ 'post_type' => 'product',
65
+ 'tax_query' => array(
66
+ array(
67
+ 'taxonomy' => 'pwb-brand',
68
+ 'field' => 'term_id',
69
+ 'terms' => $brand_id,
70
+ ),
71
+ array(
72
+ 'taxonomy' => 'product_visibility',
73
+ 'field' => 'name',
74
+ 'terms' => 'exclude-from-catalog',
75
+ 'operator' => 'NOT IN',
76
+ ),
77
+ ),
78
+ );
79
+ $wc_query = new \WP_Query( $args );
80
+
81
+ return $wc_query->found_posts;
82
+ }
83
+
84
+ public static function pagination( $display_array, $show_per_page, $image_size, $title_position ) {
85
+
86
+ $page = 1;
87
+
88
+ if ( isset( $_GET['pwb-page'] ) && filter_var( $_GET['pwb-page'], FILTER_VALIDATE_INT ) == true ) {
89
+ $page = intval( $_GET['pwb-page'] );
90
+ }
91
+
92
+ $page = $page < 1 ? 1 : $page;
93
+
94
+ // start position in the $display_array
95
+ // +1 is to account for total values.
96
+ $start = ( $page - 1 ) * ( $show_per_page );
97
+ $offset = $show_per_page;
98
+
99
+ $out_array = array_slice( $display_array, $start, $offset );
100
+
101
+ // pagination links
102
+ $total_elements = count( $display_array );
103
+ $pages = ( (int) $total_elements / (int) $show_per_page );
104
+ $pages = ceil( $pages );
105
+
106
+ if ( $pages >= 1 && $page <= $pages ) {
107
+ ?>
108
+ <div class="pwb-brands-cols-outer">
109
+ <?php
110
+ foreach ( $out_array as $brand ) :
111
+
112
+ $brand_id = $brand->term_id;
113
+ $brand_name = $brand->name;
114
+ $brand_link = get_term_link( $brand_id );
115
+
116
+ $attachment_id = get_term_meta( $brand_id, 'pwb_brand_image', 1 );
117
+ $attachment_html = $brand_name;
118
+ if ( $attachment_id != '' ) {
119
+ $attachment_html = wp_get_attachment_image( $attachment_id, $image_size );
120
+ }
121
+
122
+ ?>
123
+ <div class="pwb-brands-col3">
124
+ <?php if ( $title_position != 'none' && $title_position != 'after' ) : ?>
125
+ <p>
126
+ <a href="<?php echo esc_url( $brand_link ); ?>">
127
+ <?php echo esc_html( $brand_name ); ?>
128
+ </a>
129
+ <small>(<?php echo esc_html( $brand->count_pwb ); ?>)</small>
130
+ </p>
131
+ <?php endif; ?>
132
+ <div>
133
+ <a href="<?php echo esc_url( $brand_link ); ?>" title="<?php echo esc_html( $brand_name ); ?>">
134
+ <?php echo wp_kses_post( $attachment_html ); ?>
135
+ </a>
136
+ </div>
137
+ <?php if ( $title_position != 'none' && $title_position == 'after' ) : ?>
138
+ <p>
139
+ <a href="<?php echo esc_html( $brand_link ); ?>">
140
+ <?php echo wp_kses_post( $brand_name ); ?>
141
+ </a>
142
+ <small>(<?php echo esc_html( $brand->count_pwb ); ?>)</small>
143
+ </p>
144
+ <?php endif; ?>
145
+ </div>
146
+ <?php endforeach; ?>
147
+ </div>
148
+ <?php
149
+ $next = $page + 1;
150
+ $prev = $page - 1;
151
+ echo '<div class="pwb-pagination-wrapper">';
152
+ if ( $prev > 1 ) {
153
+ echo '<a href="' . esc_url( get_the_permalink() ) . '" class="pwb-pagination prev" title="' . esc_html__( 'First page', 'perfect-woocommerce-brands' ) . '">&laquo;</a>';
154
+ }
155
+ if ( $prev > 0 ) {
156
+ echo '<a href="' . esc_url( get_the_permalink() ) . '?pwb-page=' . esc_attr( $prev ) . '" class="pwb-pagination last" title="' . esc_html__( 'Previous page', 'perfect-woocommerce-brands' ) . '">&lsaquo;</a>';
157
+ }
158
+
159
+ if ( $next <= $pages ) {
160
+ echo '<a href="' . esc_url( get_the_permalink() ) . '?pwb-page=' . esc_attr( $next ) . '" class="pwb-pagination first" title="' . esc_html__( 'Next page', 'perfect-woocommerce-brands' ) . '">&rsaquo;</a>';
161
+ }
162
+ if ( $next < $pages ) {
163
+ echo '<a href="' . esc_url( get_the_permalink() ) . '?pwb-page=' . esc_attr( $pages ) . '" class="pwb-pagination next" title="' . esc_html__( 'Last page', 'perfect-woocommerce-brands' ) . '">&raquo;</a>';
164
+ }
165
+ echo '</div>';
166
+ } else {
167
+ echo esc_html__( 'No results', 'perfect-woocommerce-brands' );
168
+ }
169
+ }
 
 
 
 
 
 
 
170
  }
classes/shortcodes/class-pwb-az-listing.php CHANGED
@@ -1,80 +1,85 @@
1
  <?php
 
2
  namespace Perfect_Woocommerce_Brands\Shortcodes;
 
3
  use WP_Query;
4
 
5
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
6
 
7
  class PWB_AZ_Listing_Shortcode {
8
 
9
- public static function shortcode( $atts ) {
10
-
11
- $grouped_brands = get_transient('pwb_az_listing_cache');
12
 
13
- if ( ! $grouped_brands ) {
14
 
15
- $atts = shortcode_atts( array(
16
- 'only_parents' => false,
17
- ), $atts, 'pwb-az-listing' );
18
 
19
- $only_parents = filter_var( $atts['only_parents'], FILTER_VALIDATE_BOOLEAN );
 
 
 
 
 
 
20
 
21
- $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands( true, 'name', 'ASC', false, false, $only_parents );
22
- $grouped_brands = array();
23
 
24
- foreach ( $brands as $brand ) {
 
25
 
26
- if ( self::has_products( $brand->term_id ) ) {
27
 
28
- $letter = mb_substr( htmlspecialchars_decode( $brand->name ), 0, 1 );
29
- $letter = strtolower( $letter );
30
- $grouped_brands[$letter][] = [ 'brand_term' => $brand ];
31
 
32
- }
 
 
33
 
34
- }
 
35
 
36
- set_transient( 'pwb_az_listing_cache', $grouped_brands, 43200 );//12 hours
37
 
38
- }
39
 
40
- return \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
41
- 'az-listing',
42
- 'shortcodes',
43
- array( 'grouped_brands' => $grouped_brands ),
44
- false
45
- );
46
 
47
- }
48
 
49
- private static function has_products( $brand_id ){
50
 
51
- $args = array(
52
- 'posts_per_page' => -1,
53
- 'post_type' => 'product',
54
- 'tax_query' => array(
55
- array(
56
- 'taxonomy' => 'pwb-brand',
57
- 'field' => 'term_id',
58
- 'terms' => array( $brand_id )
59
- )
60
- ),
61
- 'fields' => 'ids'
62
- );
63
 
64
- if( get_option('woocommerce_hide_out_of_stock_items') === 'yes' ){
65
- $args['meta_query'] = array(
66
- array(
67
- 'key' => '_stock_status',
68
- 'value' => 'outofstock',
69
- 'compare' => 'NOT IN'
70
- )
71
- );
72
- }
73
 
74
- $wp_query = new WP_Query($args);
75
- wp_reset_postdata();
76
- return $wp_query->posts;
77
 
78
- }
79
 
80
  }
1
  <?php
2
+
3
  namespace Perfect_Woocommerce_Brands\Shortcodes;
4
+
5
  use WP_Query;
6
 
7
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
8
 
9
  class PWB_AZ_Listing_Shortcode {
10
 
11
+ public static function shortcode( $atts ) {
 
 
12
 
13
+ $grouped_brands = get_transient( 'pwb_az_listing_cache' );
14
 
15
+ if ( ! $grouped_brands ) {
 
 
16
 
17
+ $atts = shortcode_atts(
18
+ array(
19
+ 'only_parents' => false,
20
+ ),
21
+ $atts,
22
+ 'pwb-az-listing'
23
+ );
24
 
25
+ $only_parents = filter_var( $atts['only_parents'], FILTER_VALIDATE_BOOLEAN );
 
26
 
27
+ $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands( true, 'name', 'ASC', false, false, $only_parents );
28
+ $grouped_brands = array();
29
 
30
+ foreach ( $brands as $brand ) {
31
 
32
+ if ( self::has_products( $brand->term_id ) ) {
 
 
33
 
34
+ $letter = mb_substr( htmlspecialchars_decode( $brand->name ), 0, 1 );
35
+ $letter = strtolower( $letter );
36
+ $grouped_brands[ $letter ][] = array( 'brand_term' => $brand );
37
 
38
+ }
39
+ }
40
 
41
+ set_transient( 'pwb_az_listing_cache', $grouped_brands, 43200 );// 12 hours
42
 
43
+ }
44
 
45
+ return \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
46
+ 'az-listing',
47
+ 'shortcodes',
48
+ array( 'grouped_brands' => $grouped_brands ),
49
+ false
50
+ );
51
 
52
+ }
53
 
54
+ private static function has_products( $brand_id ) {
55
 
56
+ $args = array(
57
+ 'posts_per_page' => -1,
58
+ 'post_type' => 'product',
59
+ 'tax_query' => array(
60
+ array(
61
+ 'taxonomy' => 'pwb-brand',
62
+ 'field' => 'term_id',
63
+ 'terms' => array( $brand_id ),
64
+ ),
65
+ ),
66
+ 'fields' => 'ids',
67
+ );
68
 
69
+ if ( get_option( 'woocommerce_hide_out_of_stock_items' ) === 'yes' ) {
70
+ $args['meta_query'] = array(
71
+ array(
72
+ 'key' => '_stock_status',
73
+ 'value' => 'outofstock',
74
+ 'compare' => 'NOT IN',
75
+ ),
76
+ );
77
+ }
78
 
79
+ $wp_query = new WP_Query( $args );
80
+ wp_reset_postdata();
81
+ return $wp_query->posts;
82
 
83
+ }
84
 
85
  }
classes/shortcodes/class-pwb-brand.php CHANGED
@@ -1,33 +1,43 @@
1
  <?php
2
- namespace Perfect_Woocommerce_Brands\Shortcodes;
3
-
4
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
5
-
6
- class PWB_Brand_Shortcode{
7
-
8
- public static function brand_shortcode( $atts ) {
9
- $atts = shortcode_atts( array(
10
- 'product_id' => null,
11
- 'as_link' => false,
12
- 'image_size' => 'thumbnail',
13
- ), $atts, 'pwb-brand' );
14
 
15
- if( !$atts['product_id'] && is_singular('product') ) $atts['product_id'] = get_the_ID();
16
-
17
- $brands = wp_get_post_terms( $atts['product_id'], 'pwb-brand');
18
-
19
- foreach( $brands as $key => $brand ){
20
- $brands[$key]->term_link = get_term_link ( $brand->term_id, 'pwb-brand' );
21
- $brands[$key]->image = wp_get_attachment_image( get_term_meta( $brand->term_id, 'pwb_brand_image', 1 ), $atts['image_size'] );
22
- }
23
-
24
- return \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
25
- 'brand',
26
- 'shortcodes',
27
- array( 'brands' => $brands, 'as_link' => $atts['as_link'] ),
28
- false
29
- );
30
 
31
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  }
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ namespace Perfect_Woocommerce_Brands\Shortcodes;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class PWB_Brand_Shortcode {
8
+
9
+ public static function brand_shortcode( $atts ) {
10
+ $atts = shortcode_atts(
11
+ array(
12
+ 'product_id' => null,
13
+ 'as_link' => false,
14
+ 'image_size' => 'thumbnail',
15
+ ),
16
+ $atts,
17
+ 'pwb-brand'
18
+ );
19
+
20
+ if ( ! $atts['product_id'] && is_singular( 'product' ) ) {
21
+ $atts['product_id'] = get_the_ID();
22
+ }
23
+
24
+ $brands = wp_get_post_terms( $atts['product_id'], 'pwb-brand' );
25
+
26
+ foreach ( $brands as $key => $brand ) {
27
+ $brands[ $key ]->term_link = get_term_link( $brand->term_id, 'pwb-brand' );
28
+ $brands[ $key ]->image = wp_get_attachment_image( get_term_meta( $brand->term_id, 'pwb_brand_image', 1 ), $atts['image_size'] );
29
+ }
30
+
31
+ return \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
32
+ 'brand',
33
+ 'shortcodes',
34
+ array(
35
+ 'brands' => $brands,
36
+ 'as_link' => $atts['as_link'],
37
+ ),
38
+ false
39
+ );
40
+
41
+ }
42
 
43
  }
classes/shortcodes/class-pwb-carousel.php CHANGED
@@ -1,74 +1,95 @@
1
  <?php
2
- namespace Perfect_Woocommerce_Brands\Shortcodes;
3
-
4
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
5
-
6
- class PWB_Carousel_Shortcode{
7
-
8
- private static $atts;
9
-
10
- public static function carousel_shortcode( $atts ) {
11
-
12
- self::$atts = shortcode_atts( array(
13
- 'items' => "10",
14
- 'items_to_show' => "5",
15
- 'items_to_scroll' => "1",
16
- 'image_size' => "thumbnail",
17
- 'autoplay' => "false",
18
- 'arrows' => "false",
19
- 'hide_empty' => false
20
- ), $atts, 'pwb-carousel' );
21
-
22
- //enqueue deps
23
- if( !wp_style_is('pwb-lib-slick') ) wp_enqueue_style('pwb-lib-slick');
24
- if( !wp_script_is('pwb-lib-slick') ) wp_enqueue_script('pwb-lib-slick');
25
-
26
- return \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
27
- 'carousel',
28
- 'shortcodes',
29
- array( 'slick_settings' => self::slick_settings(), 'brands' => self::brands_data() ),
30
- false
31
- );
32
-
33
- }
34
 
35
- private static function slick_settings(){
36
-
37
- $slick_settings = array(
38
- 'slidesToShow' => (int)self::$atts['items_to_show'],
39
- 'slidesToScroll' => (int)self::$atts['items_to_scroll'],
40
- 'autoplay' => ( self::$atts['autoplay'] === 'true' ) ? true: false,
41
- 'arrows' => ( self::$atts['arrows'] === 'true' ) ? true: false
42
- );
43
- return htmlspecialchars( json_encode( $slick_settings ), ENT_QUOTES, 'UTF-8' );
44
-
45
- }
46
-
47
- private static function brands_data(){
48
-
49
- $brands = array();
50
- $foreach_i = 0;
51
- if( self::$atts['items'] == 'featured' ){
52
- $brands_array = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands( self::$atts['items'], 'name', 'ASC', true );
53
- }else{
54
- $brands_array = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands( self::$atts['items'] );
55
- }
56
- foreach( $brands_array as $brand ){
57
- if( self::$atts['items'] != 'featured' && $foreach_i >= (int)self::$atts['items'] ) break;
58
-
59
- $brand_id = $brand->term_id;
60
- $brand_link = get_term_link($brand_id);
61
- $attachment_id = get_term_meta( $brand_id, 'pwb_brand_image', 1 );
62
- $attachment_html = $brand->name;
63
- if($attachment_id!='') $attachment_html = wp_get_attachment_image( $attachment_id, self::$atts['image_size'] );
64
-
65
- $brands[] = array( 'link' => $brand_link, 'attachment_html' => $attachment_html, 'name' => $brand->name );
66
-
67
- $foreach_i++;
68
- }
69
-
70
- return $brands;
71
 
72
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  }
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ namespace Perfect_Woocommerce_Brands\Shortcodes;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class PWB_Carousel_Shortcode {
8
+
9
+ private static $atts;
10
+
11
+ public static function carousel_shortcode( $atts ) {
12
+
13
+ self::$atts = shortcode_atts(
14
+ array(
15
+ 'items' => '10',
16
+ 'items_to_show' => '5',
17
+ 'items_to_scroll' => '1',
18
+ 'image_size' => 'thumbnail',
19
+ 'autoplay' => 'false',
20
+ 'arrows' => 'false',
21
+ 'hide_empty' => false,
22
+ ),
23
+ $atts,
24
+ 'pwb-carousel'
25
+ );
26
+
27
+ // enqueue deps
28
+ if ( ! wp_style_is( 'pwb-lib-slick' ) ) {
29
+ wp_enqueue_style( 'pwb-lib-slick' );
30
+ }
31
+ if ( ! wp_script_is( 'pwb-lib-slick' ) ) {
32
+ wp_enqueue_script( 'pwb-lib-slick' );
33
+ }
34
+
35
+ return \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
36
+ 'carousel',
37
+ 'shortcodes',
38
+ array(
39
+ 'slick_settings' => self::slick_settings(),
40
+ 'brands' => self::brands_data(),
41
+ ),
42
+ false
43
+ );
44
+
45
+ }
46
+
47
+ private static function slick_settings() {
48
+
49
+ $slick_settings = array(
50
+ 'slidesToShow' => (int) self::$atts['items_to_show'],
51
+ 'slidesToScroll' => (int) self::$atts['items_to_scroll'],
52
+ 'autoplay' => ( self::$atts['autoplay'] === 'true' ) ? true : false,
53
+ 'arrows' => ( self::$atts['arrows'] === 'true' ) ? true : false,
54
+ );
55
+
56
+ return htmlspecialchars( json_encode( $slick_settings ), ENT_QUOTES, 'UTF-8' );
57
+
58
+ }
59
+
60
+ private static function brands_data() {
61
+
62
+ $brands = array();
63
+ $foreach_i = 0;
64
+ if ( self::$atts['items'] == 'featured' ) {
65
+ $brands_array = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands( self::$atts['items'], 'name', 'ASC', true );
66
+ } else {
67
+ $brands_array = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands( self::$atts['items'] );
68
+ }
69
+ foreach ( $brands_array as $brand ) {
70
+ if ( self::$atts['items'] != 'featured' && $foreach_i >= (int) self::$atts['items'] ) {
71
+ break;
72
+ }
73
+
74
+ $brand_id = $brand->term_id;
75
+ $brand_link = get_term_link( $brand_id );
76
+ $attachment_id = get_term_meta( $brand_id, 'pwb_brand_image', 1 );
77
+ $attachment_html = $brand->name;
78
+ if ( $attachment_id != '' ) {
79
+ $attachment_html = wp_get_attachment_image( $attachment_id, self::$atts['image_size'] );
80
+ }
81
+
82
+ $brands[] = array(
83
+ 'link' => $brand_link,
84
+ 'attachment_html' => $attachment_html,
85
+ 'name' => $brand->name,
86
+ );
87
+
88
+ $foreach_i++;
89
+ }
90
+
91
+ return $brands;
92
+
93
+ }
94
 
95
  }
classes/shortcodes/class-pwb-product-carousel.php CHANGED
@@ -2,102 +2,106 @@
2
 
3
  namespace Perfect_Woocommerce_Brands\Shortcodes;
4
 
5
- defined('ABSPATH') or die('No script kiddies please!');
6
-
7
- class PWB_Product_Carousel_Shortcode
8
- {
9
-
10
- private static $atts;
11
-
12
- public static function product_carousel_shortcode($atts)
13
- {
14
-
15
- self::$atts = shortcode_atts(array(
16
- 'brand' => "all",
17
- 'category' => "all",
18
- 'products' => "10",
19
- 'products_to_show' => "5",
20
- 'products_to_scroll' => "1",
21
- 'autoplay' => "false",
22
- 'arrows' => "false"
23
- ), $atts, 'pwb-product-carousel');
24
-
25
- //enqueue deps
26
- if (!wp_style_is('pwb-lib-slick'))
27
- wp_enqueue_style('pwb-lib-slick');
28
-
29
- if (!wp_script_is('pwb-lib-slick'))
30
- wp_enqueue_script('pwb-lib-slick');
31
-
32
- return \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
33
- 'product-carousel',
34
- 'shortcodes',
35
- array('slick_settings' => self::slick_settings(), 'products' => self::products_data()),
36
- false
37
- );
38
- }
39
-
40
- private static function slick_settings()
41
- {
42
-
43
- $slick_settings = array(
44
- 'slidesToShow' => (int)self::$atts['products_to_show'],
45
- 'slidesToScroll' => (int)self::$atts['products_to_scroll'],
46
- 'autoplay' => (self::$atts['autoplay'] === 'true') ? true : false,
47
- 'arrows' => (self::$atts['arrows'] === 'true') ? true : false
48
- );
49
-
50
- return htmlspecialchars(json_encode($slick_settings), ENT_QUOTES, 'UTF-8');
51
- }
52
-
53
- private static function products_data()
54
- {
55
-
56
- $products = array();
57
-
58
- $args = array(
59
- 'post_type' => 'product',
60
- 'posts_per_page' => (int)self::$atts['products'],
61
- 'paged' => false
62
- );
63
-
64
- if (self::$atts['brand'] != 'all') {
65
- $args['tax_query'] = array(
66
- array(
67
- 'taxonomy' => 'pwb-brand',
68
- 'field' => 'slug',
69
- 'terms' => self::$atts['brand']
70
- )
71
- );
72
- }
73
- if (self::$atts['category'] != 'all') {
74
- $woo_category_query = array(
75
- 'taxonomy' => 'product_cat',
76
- 'field' => 'slug',
77
- 'terms' => self::$atts['category']
78
- );
79
- if (isset($args['tax_query']) && is_array($args['tax_query'])) {
80
- $args['tax_query'][] = $woo_category_query;
81
- } else {
82
- $args['tax_query'] = array($woo_category_query);
83
- }
84
- }
85
-
86
- $loop = new \WP_Query($args);
87
- if ($loop->have_posts()) {
88
- while ($loop->have_posts()) : $loop->the_post();
89
- $product = wc_get_product(get_the_ID());
90
-
91
- $products[] = array(
92
- 'id' => get_the_ID(),
93
- 'permalink' => get_the_permalink(),
94
- 'thumbnail' => woocommerce_get_product_thumbnail(),
95
- 'title' => $product->get_title()
96
- );
97
- endwhile;
98
- }
99
- wp_reset_postdata();
100
-
101
- return $products;
102
- }
 
 
 
 
103
  }
2
 
3
  namespace Perfect_Woocommerce_Brands\Shortcodes;
4
 
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class PWB_Product_Carousel_Shortcode {
8
+
9
+
10
+ private static $atts;
11
+
12
+ public static function product_carousel_shortcode( $atts ) {
13
+ self::$atts = shortcode_atts(
14
+ array(
15
+ 'brand' => 'all',
16
+ 'category' => 'all',
17
+ 'products' => '10',
18
+ 'products_to_show' => '5',
19
+ 'products_to_scroll' => '1',
20
+ 'autoplay' => 'false',
21
+ 'arrows' => 'false',
22
+ ),
23
+ $atts,
24
+ 'pwb-product-carousel'
25
+ );
26
+
27
+ // enqueue deps
28
+ if ( ! wp_style_is( 'pwb-lib-slick' ) ) {
29
+ wp_enqueue_style( 'pwb-lib-slick' );
30
+ }
31
+
32
+ if ( ! wp_script_is( 'pwb-lib-slick' ) ) {
33
+ wp_enqueue_script( 'pwb-lib-slick' );
34
+ }
35
+
36
+ return \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
37
+ 'product-carousel',
38
+ 'shortcodes',
39
+ array(
40
+ 'slick_settings' => self::slick_settings(),
41
+ 'products' => self::products_data(),
42
+ ),
43
+ false
44
+ );
45
+ }
46
+
47
+ private static function slick_settings() {
48
+ $slick_settings = array(
49
+ 'slidesToShow' => (int) self::$atts['products_to_show'],
50
+ 'slidesToScroll' => (int) self::$atts['products_to_scroll'],
51
+ 'autoplay' => ( self::$atts['autoplay'] === 'true' ) ? true : false,
52
+ 'arrows' => ( self::$atts['arrows'] === 'true' ) ? true : false,
53
+ );
54
+
55
+ return htmlspecialchars( json_encode( $slick_settings ), ENT_QUOTES, 'UTF-8' );
56
+ }
57
+
58
+ private static function products_data() {
59
+ $products = array();
60
+
61
+ $args = array(
62
+ 'post_type' => 'product',
63
+ 'posts_per_page' => (int) self::$atts['products'],
64
+ 'paged' => false,
65
+ );
66
+
67
+ if ( self::$atts['brand'] != 'all' ) {
68
+ $args['tax_query'] = array(
69
+ array(
70
+ 'taxonomy' => 'pwb-brand',
71
+ 'field' => 'slug',
72
+ 'terms' => self::$atts['brand'],
73
+ ),
74
+ );
75
+ }
76
+ if ( self::$atts['category'] != 'all' ) {
77
+ $woo_category_query = array(
78
+ 'taxonomy' => 'product_cat',
79
+ 'field' => 'slug',
80
+ 'terms' => self::$atts['category'],
81
+ );
82
+ if ( isset( $args['tax_query'] ) && is_array( $args['tax_query'] ) ) {
83
+ $args['tax_query'][] = $woo_category_query;
84
+ } else {
85
+ $args['tax_query'] = array( $woo_category_query );
86
+ }
87
+ }
88
+
89
+ $loop = new \WP_Query( $args );
90
+ if ( $loop->have_posts() ) {
91
+ while ( $loop->have_posts() ) :
92
+ $loop->the_post();
93
+ $product = wc_get_product( get_the_ID() );
94
+
95
+ $products[] = array(
96
+ 'id' => get_the_ID(),
97
+ 'permalink' => get_the_permalink(),
98
+ 'thumbnail' => woocommerce_get_product_thumbnail(),
99
+ 'title' => $product->get_title(),
100
+ );
101
+ endwhile;
102
+ }
103
+ wp_reset_postdata();
104
+
105
+ return $products;
106
+ }
107
  }
classes/widgets/class-pwb-dropdown-widget.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Perfect_Woocommerce_Brands\Widgets;
4
+
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class PWB_Dropdown_Widget extends \WP_Widget {
8
+
9
+ function __construct() {
10
+ $params = array(
11
+ 'description' => esc_html__( 'Adds a brands dropdown to your site', 'perfect-woocommerce-brands' ),
12
+ 'name' => esc_html__( 'Brands dropdown', 'perfect-woocommerce-brands' ),
13
+ );
14
+ parent::__construct( 'PWB_Dropdown_Widget', '', $params );
15
+ }
16
+
17
+ public function form( $instance ) {
18
+ extract( $instance );
19
+
20
+ $title = ( isset( $instance['title'] ) ) ? $instance['title'] : esc_html__( 'Brands', 'perfect-woocommerce-brands' );
21
+ $hide_empty = ( isset( $hide_empty ) && $hide_empty == 'on' ) ? true : false;
22
+ $only_featured = ( isset( $only_featured ) && $only_featured == 'on' ) ? true : false;
23
+ ?>
24
+
25
+ <p>
26
+ <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
27
+ <?php esc_html_e( 'Title', 'perfect-woocommerce-brands' ); ?>
28
+ </label>
29
+ <input
30
+ class="widefat"
31
+ type="text"
32
+ id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
33
+ name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
34
+ value="
35
+ <?php
36
+ if ( isset( $title ) ) {
37
+ echo esc_attr( $title );}
38
+ ?>
39
+ ">
40
+ </p>
41
+
42
+ <p>
43
+ <input
44
+ type="checkbox"
45
+ id="<?php echo esc_attr( $this->get_field_id( 'hide_empty' ) ); ?>"
46
+ name="<?php echo esc_attr( $this->get_field_name( 'hide_empty' ) ); ?>"
47
+ <?php checked( $hide_empty ); ?>>
48
+ <label for="<?php echo esc_attr( $this->get_field_id( 'hide_empty' ) ); ?>">
49
+ <?php esc_html_e( 'Hide empty', 'perfect-woocommerce-brands' ); ?>
50
+ </label>
51
+ </p>
52
+
53
+ <p>
54
+ <input
55
+ type="checkbox"
56
+ id="<?php echo esc_attr( $this->get_field_id( 'only_featured' ) ); ?>"
57
+ name="<?php echo esc_attr( $this->get_field_name( 'only_featured' ) ); ?>"
58
+ <?php checked( $only_featured ); ?>>
59
+ <label for="<?php echo esc_attr( $this->get_field_id( 'only_featured' ) ); ?>">
60
+ <?php esc_html_e( 'Only favorite brands', 'perfect-woocommerce-brands' ); ?>
61
+ </label>
62
+ </p>
63
+
64
+ <?php
65
+ }
66
+
67
+ public function widget( $args, $instance ) {
68
+
69
+ extract( $args );
70
+ extract( $instance );
71
+
72
+ $queried_obj = get_queried_object();
73
+ $queried_brand_id = ( isset( $queried_obj->term_id ) ) ? $queried_obj->term_id : false;
74
+
75
+ $hide_empty = ( isset( $hide_empty ) && $hide_empty == 'on' ) ? true : false;
76
+ $only_featured = ( isset( $only_featured ) && $only_featured == 'on' ) ? true : false;
77
+ $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands(
78
+ $hide_empty,
79
+ 'name',
80
+ 'ASC',
81
+ $only_featured,
82
+ true
83
+ );
84
+
85
+ if ( is_array( $brands ) && count( $brands ) > 0 ) {
86
+
87
+ echo $before_widget;// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
88
+
89
+ if ( ! empty( $title ) ) {
90
+ echo $before_title . $title . $after_title;// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
91
+ }
92
+
93
+ echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
94
+ 'dropdown',
95
+ 'widgets',
96
+ array(
97
+ 'brands' => $brands,
98
+ 'selected' => $queried_brand_id,
99
+ ),
100
+ false
101
+ );
102
+
103
+ echo $after_widget;// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
104
+
105
+ }
106
+
107
+ }
108
+
109
+ }
classes/widgets/class-pwb-dropdown.php DELETED
@@ -1,93 +0,0 @@
1
- <?php
2
- namespace Perfect_Woocommerce_Brands\Widgets;
3
-
4
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
5
-
6
- class PWB_Dropdown_Widget extends \WP_Widget {
7
-
8
- function __construct(){
9
- $params = array(
10
- 'description' => __( 'Adds a brands dropdown to your site', 'perfect-woocommerce-brands' ),
11
- 'name' => __( 'Brands dropdown', 'perfect-woocommerce-brands' )
12
- );
13
- parent::__construct('PWB_Dropdown_Widget', '', $params);
14
- }
15
-
16
- public function form($instance){
17
- extract($instance);
18
-
19
- $title = ( isset( $instance[ 'title' ] ) ) ? $instance[ 'title' ] : esc_html__('Brands', 'perfect-woocommerce-brands');
20
- $hide_empty = ( isset( $hide_empty ) && $hide_empty == 'on' ) ? true : false;
21
- $only_featured = ( isset( $only_featured ) && $only_featured == 'on' ) ? true : false;
22
- ?>
23
-
24
- <p>
25
- <label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>">
26
- <?php echo __( 'Title', 'perfect-woocommerce-brands' );?>
27
- </label>
28
- <input
29
- class="widefat"
30
- type="text"
31
- id="<?php echo esc_attr( $this->get_field_id('title') ); ?>"
32
- name="<?php echo esc_attr( $this->get_field_name('title') ); ?>"
33
- value="<?php if(isset($title)) echo esc_attr($title); ?>">
34
- </p>
35
-
36
- <p>
37
- <input
38
- type="checkbox"
39
- id="<?php echo esc_attr( $this->get_field_id('hide_empty') ); ?>"
40
- name="<?php echo esc_attr( $this->get_field_name('hide_empty') ); ?>"
41
- <?php checked( $hide_empty ); ?>>
42
- <label for="<?php echo esc_attr( $this->get_field_id('hide_empty') ); ?>">
43
- <?php echo __( 'Hide empty', 'perfect-woocommerce-brands' );?>
44
- </label>
45
- </p>
46
-
47
- <p>
48
- <input
49
- type="checkbox"
50
- id="<?php echo esc_attr( $this->get_field_id('only_featured') ); ?>"
51
- name="<?php echo esc_attr( $this->get_field_name('only_featured') ); ?>"
52
- <?php checked( $only_featured ); ?>>
53
- <label for="<?php echo esc_attr( $this->get_field_id('only_featured') ); ?>">
54
- <?php echo __( 'Only favorite brands', 'perfect-woocommerce-brands' );?>
55
- </label>
56
- </p>
57
-
58
- <?php
59
- }
60
-
61
- public function widget( $args, $instance ){
62
- extract($args);
63
- extract($instance);
64
-
65
- $queried_obj = get_queried_object();
66
- $queried_brand_id = ( isset( $queried_obj->term_id ) ) ? $queried_obj->term_id : false;
67
-
68
- $hide_empty = ( isset( $hide_empty ) && $hide_empty == 'on' ) ? true : false;
69
- $only_featured = ( isset( $only_featured ) && $only_featured == 'on' ) ? true : false;
70
- $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands(
71
- $hide_empty, 'name', 'ASC', $only_featured, true
72
- );
73
-
74
- if( is_array( $brands ) && count( $brands ) > 0 ){
75
-
76
- echo $before_widget;
77
-
78
- if( !empty( $title ) ) echo $before_title . $title . $after_title;
79
-
80
- echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
81
- 'dropdown',
82
- 'widgets',
83
- array( 'brands' => $brands, 'selected' => $queried_brand_id ),
84
- false
85
- );
86
-
87
- echo $after_widget;
88
-
89
- }
90
-
91
- }
92
-
93
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/widgets/class-pwb-filter-by-brand-widget.php ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Perfect_Woocommerce_Brands\Widgets;
4
+
5
+ use WP_Query;
6
+
7
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
8
+
9
+ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
10
+
11
+ function __construct() {
12
+ $params = array(
13
+ 'description' => __( 'Recommended for product categories or shop page', 'perfect-woocommerce-brands' ),
14
+ 'name' => __( 'Filter products by brand', 'perfect-woocommerce-brands' ),
15
+ );
16
+ parent::__construct( 'PWB_Filter_By_Brand_Widget', '', $params );
17
+ }
18
+
19
+ public function form( $instance ) {
20
+ extract( $instance );
21
+
22
+ $title = ( isset( $instance['title'] ) ) ? $instance['title'] : esc_html__( 'Brands', 'perfect-woocommerce-brands' );
23
+ $limit = ( isset( $instance['limit'] ) ) ? $instance['limit'] : 20;
24
+ $hide_submit_btn = ( isset( $hide_submit_btn ) && $hide_submit_btn == 'on' ) ? true : false;
25
+ $only_first_level_brands = ( isset( $only_first_level_brands ) && $only_first_level_brands == 'on' ) ? true : false;
26
+ ?>
27
+
28
+ <p>
29
+ <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'perfect-woocommerce-brands' ); ?></label>
30
+ <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_html( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
31
+ </p>
32
+
33
+ <p>
34
+ <label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>">
35
+ <?php esc_html_e( 'Max number of brands', 'perfect-woocommerce-brands' ); ?>
36
+ </label>
37
+ <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" name="<?php echo esc_html( $this->get_field_name( 'limit' ) ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" />
38
+ </p>
39
+
40
+ <p>
41
+ <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'hide_submit_btn' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'hide_submit_btn' ) ); ?>" <?php checked( $hide_submit_btn ); ?>>
42
+ <label for="<?php echo esc_attr( $this->get_field_id( 'hide_submit_btn' ) ); ?>">
43
+ <?php esc_html_e( 'Hide filter button', 'perfect-woocommerce-brands' ); ?>
44
+ </label>
45
+ </p>
46
+
47
+ <p>
48
+ <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'only_first_level_brands' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'only_first_level_brands' ) ); ?>" <?php checked( $only_first_level_brands ); ?>>
49
+ <label for="<?php echo esc_attr( $this->get_field_id( 'only_first_level_brands' ) ); ?>">
50
+ <?php esc_html_e( 'Show only first level brands', 'perfect-woocommerce-brands' ); ?>
51
+ </label>
52
+ </p>
53
+
54
+ <?php
55
+ }
56
+
57
+ public function update( $new_instance, $old_instance ) {
58
+ $limit = trim( wp_strip_all_tags( $new_instance['limit'] ) );
59
+ $limit = filter_var( $limit, FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) );
60
+
61
+ $instance = array();
62
+ $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : '';
63
+ $instance['limit'] = ( $limit != false ) ? $limit : $old_instance['limit'];
64
+ $instance['hide_submit_btn'] = ( isset( $new_instance['hide_submit_btn'] ) ) ? $new_instance['hide_submit_btn'] : '';
65
+ $instance['only_first_level_brands'] = ( isset( $new_instance['only_first_level_brands'] ) ) ? $new_instance['only_first_level_brands'] : '';
66
+ return $instance;
67
+ }
68
+
69
+ public function widget( $args, $instance ) {
70
+ extract( $args );
71
+ extract( $instance );
72
+
73
+ if ( ! is_tax( 'pwb-brand' ) && ! is_product() ) {
74
+
75
+ $hide_submit_btn = ( isset( $hide_submit_btn ) && $hide_submit_btn == 'on' ) ? true : false;
76
+ $only_first_level_brands = ( isset( $only_first_level_brands ) && $only_first_level_brands == 'on' ) ? true : false;
77
+
78
+ $show_widget = true;
79
+ $current_products = false;
80
+ if ( is_product_taxonomy() || is_shop() ) {
81
+ $current_products = $this->current_products_query();
82
+ if ( empty( $current_products ) ) {
83
+ $show_widget = false;
84
+ }
85
+ }
86
+
87
+ if ( $show_widget ) {
88
+
89
+ $title = ( isset( $instance['title'] ) ) ? $instance['title'] : esc_html__( 'Brands', 'perfect-woocommerce-brands' );
90
+ $title = apply_filters( 'widget_title', $title );
91
+ $limit = ( isset( $instance['limit'] ) ) ? $instance['limit'] : 20;
92
+
93
+ echo $args['before_widget']; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
94
+ if ( ! empty( $title ) ) {
95
+ echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
96
+ }
97
+ $this->render_widget( $current_products, $limit, $hide_submit_btn, $only_first_level_brands );
98
+ echo $args['after_widget']; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
99
+ }
100
+ }
101
+ }
102
+
103
+ public function render_widget( $current_products, $limit, $hide_submit_btn, $only_first_level_brands ) {
104
+ $result_brands = array();
105
+
106
+ if ( is_product_taxonomy() || is_shop() ) {
107
+
108
+ // obtains brands ids
109
+ if ( ! empty( $current_products ) ) {
110
+ $result_brands = $this->get_products_brands( $current_products );
111
+ }
112
+
113
+ // excludes the child brands if needed
114
+ if ( $only_first_level_brands ) {
115
+ $result_brands = $this->exclude_child_brands( $result_brands );
116
+ }
117
+
118
+ if ( is_shop() ) {
119
+ $cate_url = get_permalink( wc_get_page_id( 'shop' ) );
120
+ } else {
121
+ $cate = get_queried_object();
122
+ $cateID = $cate->term_id;
123
+ $cate_url = get_term_link( $cateID );
124
+ }
125
+ } else {
126
+ // no product category
127
+ $cate_url = get_permalink( wc_get_page_id( 'shop' ) );
128
+ $result_brands = get_terms(
129
+ 'pwb-brand',
130
+ array(
131
+ 'hide_empty' => true,
132
+ 'fields' => 'ids',
133
+ )
134
+ );
135
+ }
136
+
137
+ if ( $limit > 0 ) {
138
+ $result_brands = array_slice( $result_brands, 0, $limit );
139
+ }
140
+
141
+ global $wp;
142
+ $current_url = home_url( add_query_arg( array(), $wp->request ) );
143
+
144
+ if ( ! empty( $result_brands ) ) {
145
+
146
+ $result_brands_ordered = array();
147
+ foreach ( $result_brands as $brand ) {
148
+ $brand = get_term( $brand );
149
+ $result_brands_ordered[ $brand->name ] = $brand;
150
+ }
151
+ ksort( $result_brands_ordered );
152
+
153
+ $result_brands_ordered = apply_filters( 'pwb_widget_brand_filter', $result_brands_ordered );
154
+
155
+ echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(// phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
156
+ 'filter-by-brand',
157
+ 'widgets',
158
+ array(
159
+ 'cate_url' => $cate_url,
160
+ 'brands' => $result_brands_ordered,
161
+ 'hide_submit_btn' => $hide_submit_btn,
162
+ ),
163
+ false
164
+ );
165
+ }
166
+ }
167
+
168
+ private function exclude_child_brands( $brands ) {
169
+ // gets parent for all brands
170
+ foreach ( $brands as $brand_key => $brand ) {
171
+
172
+ $brand_o = get_term( $brand, 'pwb-brand' );
173
+
174
+ if ( $brand_o->parent ) {
175
+
176
+ // exclude this child brand and include the parent
177
+ unset( $brands[ $brand_key ] );
178
+ if ( ! in_array( $brand_o->parent, $brands ) ) {
179
+ $brands[ $brand_key ] = $brand_o->parent;
180
+ }
181
+ }
182
+ }
183
+
184
+ // reset keys
185
+ $brands = array_values( $brands );
186
+
187
+ return $brands;
188
+ }
189
+
190
+ private function current_products_query() {
191
+ $args = array(
192
+ 'posts_per_page' => -1,
193
+ 'post_type' => 'product',
194
+ 'tax_query' => array(
195
+ array(
196
+ 'taxonomy' => 'pwb-brand',
197
+ 'operator' => 'EXISTS',
198
+ ),
199
+ ),
200
+ 'fields' => 'ids',
201
+ );
202
+
203
+ $cat = get_queried_object();
204
+ if ( is_a( $cat, 'WP_Term' ) ) {
205
+ $cat_id = $cat->term_id;
206
+ $cat_id_array = get_term_children( $cat_id, $cat->taxonomy );
207
+ $cat_id_array[] = $cat_id;
208
+ $args['tax_query'][] = array(
209
+ 'taxonomy' => $cat->taxonomy,
210
+ 'field' => 'term_id',
211
+ 'terms' => $cat_id_array,
212
+ );
213
+ }
214
+
215
+ if ( get_option( 'woocommerce_hide_out_of_stock_items' ) === 'yes' ) {
216
+ $args['meta_query'] = array(
217
+ array(
218
+ 'key' => '_stock_status',
219
+ 'value' => 'outofstock',
220
+ 'compare' => 'NOT IN',
221
+ ),
222
+ );
223
+ }
224
+
225
+ $wp_query = new WP_Query( $args );
226
+ wp_reset_postdata();
227
+
228
+ return $wp_query->posts;
229
+ }
230
+
231
+ private function get_products_brands( $product_ids ) {
232
+ $product_ids = implode( ',', array_map( 'intval', $product_ids ) );
233
+
234
+ global $wpdb;
235
+
236
+ $brand_ids = $wpdb->get_col(
237
+ "SELECT DISTINCT t.term_id
238
+ FROM {$wpdb->prefix}terms AS t
239
+ INNER JOIN {$wpdb->prefix}term_taxonomy AS tt
240
+ ON t.term_id = tt.term_id
241
+ INNER JOIN {$wpdb->prefix}term_relationships AS tr
242
+ ON tr.term_taxonomy_id = tt.term_taxonomy_id
243
+ WHERE tt.taxonomy = 'pwb-brand'
244
+ AND tr.object_id IN ($product_ids)
245
+ "
246
+ );
247
+
248
+ return ( $brand_ids ) ? $brand_ids : false;
249
+ }
250
+ }
classes/widgets/class-pwb-filter-by-brand.php DELETED
@@ -1,242 +0,0 @@
1
- <?php
2
-
3
- namespace Perfect_Woocommerce_Brands\Widgets;
4
-
5
- use WP_Query;
6
-
7
- defined('ABSPATH') or die('No script kiddies please!');
8
-
9
- class PWB_Filter_By_Brand_Widget extends \WP_Widget
10
- {
11
-
12
- function __construct()
13
- {
14
- $params = array(
15
- 'description' => __('Recommended for product categories or shop page', 'perfect-woocommerce-brands'),
16
- 'name' => __('Filter products by brand', 'perfect-woocommerce-brands')
17
- );
18
- parent::__construct('PWB_Filter_By_Brand_Widget', '', $params);
19
- }
20
-
21
- public function form($instance)
22
- {
23
- extract($instance);
24
-
25
- $title = (isset($instance['title'])) ? $instance['title'] : esc_html__('Brands', 'perfect-woocommerce-brands');
26
- $limit = (isset($instance['limit'])) ? $instance['limit'] : 20;
27
- $hide_submit_btn = (isset($hide_submit_btn) && $hide_submit_btn == 'on') ? true : false;
28
- $only_first_level_brands = (isset($only_first_level_brands) && $only_first_level_brands == 'on') ? true : false;
29
- ?>
30
-
31
- <p>
32
- <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php _e('Title:'); ?></label>
33
- <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_html($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
34
- </p>
35
-
36
- <p>
37
- <label for="<?php echo esc_attr($this->get_field_id('limit')); ?>">
38
- <?php echo __('Max number of brands', 'perfect-woocommerce-brands'); ?>
39
- </label>
40
- <input class="widefat" id="<?php echo esc_attr($this->get_field_id('limit')); ?>" name="<?php echo esc_html($this->get_field_name('limit')); ?>" type="text" value="<?php echo esc_attr($limit); ?>" />
41
- </p>
42
-
43
- <p>
44
- <input type="checkbox" id="<?php echo esc_attr($this->get_field_id('hide_submit_btn')); ?>" name="<?php echo esc_attr($this->get_field_name('hide_submit_btn')); ?>" <?php checked($hide_submit_btn); ?>>
45
- <label for="<?php echo esc_attr($this->get_field_id('hide_submit_btn')); ?>">
46
- <?php echo __('Hide filter button', 'perfect-woocommerce-brands'); ?>
47
- </label>
48
- </p>
49
-
50
- <p>
51
- <input type="checkbox" id="<?php echo esc_attr($this->get_field_id('only_first_level_brands')); ?>" name="<?php echo esc_attr($this->get_field_name('only_first_level_brands')); ?>" <?php checked($only_first_level_brands); ?>>
52
- <label for="<?php echo esc_attr($this->get_field_id('only_first_level_brands')); ?>">
53
- <?php echo __('Show only first level brands', 'perfect-woocommerce-brands'); ?>
54
- </label>
55
- </p>
56
-
57
- <?php
58
- }
59
-
60
- public function update($new_instance, $old_instance)
61
- {
62
- $limit = trim(strip_tags($new_instance['limit']));
63
- $limit = filter_var($limit, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
64
-
65
- $instance = array();
66
- $instance['title'] = (!empty($new_instance['title'])) ? sanitize_text_field($new_instance['title']) : '';
67
- $instance['limit'] = ($limit != false) ? $limit : $old_instance['limit'];
68
- $instance['hide_submit_btn'] = (isset($new_instance['hide_submit_btn'])) ? $new_instance['hide_submit_btn'] : '';
69
- $instance['only_first_level_brands'] = (isset($new_instance['only_first_level_brands'])) ? $new_instance['only_first_level_brands'] : '';
70
- return $instance;
71
- }
72
-
73
- public function widget($args, $instance)
74
- {
75
- extract($args);
76
- extract($instance);
77
-
78
- if (!is_tax('pwb-brand') && !is_product()) {
79
-
80
- $hide_submit_btn = (isset($hide_submit_btn) && $hide_submit_btn == 'on') ? true : false;
81
- $only_first_level_brands = (isset($only_first_level_brands) && $only_first_level_brands == 'on') ? true : false;
82
-
83
- $show_widget = true;
84
- $current_products = false;
85
- if (is_product_taxonomy() || is_shop()) {
86
- $current_products = $this->current_products_query();
87
- if (empty($current_products)) $show_widget = false;
88
- }
89
-
90
- if ($show_widget) {
91
-
92
- $title = (isset($instance['title'])) ? $instance['title'] : esc_html__('Brands', 'perfect-woocommerce-brands');
93
- $title = apply_filters('widget_title', $title);
94
- $limit = (isset($instance['limit'])) ? $instance['limit'] : 20;
95
-
96
- echo $args['before_widget'];
97
- if (!empty($title)) echo $args['before_title'] . $title . $args['after_title'];
98
- $this->render_widget($current_products, $limit, $hide_submit_btn, $only_first_level_brands);
99
- echo $args['after_widget'];
100
- }
101
- }
102
- }
103
-
104
- public function render_widget($current_products, $limit, $hide_submit_btn, $only_first_level_brands)
105
- {
106
-
107
- $result_brands = array();
108
-
109
- if (is_product_taxonomy() || is_shop()) {
110
-
111
- //obtains brands ids
112
- if (!empty($current_products)) $result_brands = $this->get_products_brands($current_products);
113
-
114
- //excludes the child brands if needed
115
- if ($only_first_level_brands) {
116
- $result_brands = $this->exclude_child_brands($result_brands);
117
- }
118
-
119
- if (is_shop()) {
120
- $cate_url = get_permalink(wc_get_page_id('shop'));
121
- } else {
122
- $cate = get_queried_object();
123
- $cateID = $cate->term_id;
124
- $cate_url = get_term_link($cateID);
125
- }
126
- } else {
127
- //no product category
128
- $cate_url = get_permalink(wc_get_page_id('shop'));
129
- $result_brands = get_terms('pwb-brand', array('hide_empty' => true, 'fields' => 'ids'));
130
- }
131
-
132
- if ($limit > 0) $result_brands = array_slice($result_brands, 0, $limit);
133
-
134
- global $wp;
135
- $current_url = home_url(add_query_arg(array(), $wp->request));
136
-
137
- if (!empty($result_brands)) {
138
-
139
- $result_brands_ordered = array();
140
- foreach ($result_brands as $brand) {
141
- $brand = get_term($brand);
142
- $result_brands_ordered[$brand->name] = $brand;
143
- }
144
- ksort($result_brands_ordered);
145
-
146
- $result_brands_ordered = apply_filters('pwb_widget_brand_filter', $result_brands_ordered);
147
-
148
- echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
149
- 'filter-by-brand',
150
- 'widgets',
151
- array('cate_url' => $cate_url, 'brands' => $result_brands_ordered, 'hide_submit_btn' => $hide_submit_btn),
152
- false
153
- );
154
- }
155
- }
156
-
157
- private function exclude_child_brands($brands)
158
- {
159
-
160
- //gets parent for all brands
161
- foreach ($brands as $brand_key => $brand) {
162
-
163
- $brand_o = get_term($brand, 'pwb-brand');
164
-
165
- if ($brand_o->parent) {
166
-
167
- //exclude this child brand and include the parent
168
- unset($brands[$brand_key]);
169
- if (!in_array($brand_o->parent, $brands)) $brands[$brand_key] = $brand_o->parent;
170
- }
171
- }
172
-
173
- //reset keys
174
- $brands = array_values($brands);
175
-
176
-
177
- return $brands;
178
- }
179
-
180
- private function current_products_query()
181
- {
182
-
183
- $args = array(
184
- 'posts_per_page' => -1,
185
- 'post_type' => 'product',
186
- 'tax_query' => array(
187
- array(
188
- 'taxonomy' => 'pwb-brand',
189
- 'operator' => 'EXISTS'
190
- )
191
- ),
192
- 'fields' => 'ids',
193
- );
194
-
195
- $cat = get_queried_object();
196
- if (is_a($cat, 'WP_Term')) {
197
- $cat_id = $cat->term_id;
198
- $cat_id_array = get_term_children($cat_id, $cat->taxonomy);
199
- $cat_id_array[] = $cat_id;
200
- $args['tax_query'][] = array(
201
- 'taxonomy' => $cat->taxonomy,
202
- 'field' => 'term_id',
203
- 'terms' => $cat_id_array
204
- );
205
- }
206
-
207
- if (get_option('woocommerce_hide_out_of_stock_items') === 'yes') {
208
- $args['meta_query'] = array(
209
- array(
210
- 'key' => '_stock_status',
211
- 'value' => 'outofstock',
212
- 'compare' => 'NOT IN'
213
- )
214
- );
215
- }
216
-
217
- $wp_query = new WP_Query($args);
218
- wp_reset_postdata();
219
-
220
- return $wp_query->posts;
221
- }
222
-
223
- private function get_products_brands($product_ids)
224
- {
225
-
226
- $product_ids = implode(',', array_map('intval', $product_ids));
227
-
228
- global $wpdb;
229
-
230
- $brand_ids = $wpdb->get_col("SELECT DISTINCT t.term_id
231
- FROM {$wpdb->prefix}terms AS t
232
- INNER JOIN {$wpdb->prefix}term_taxonomy AS tt
233
- ON t.term_id = tt.term_id
234
- INNER JOIN {$wpdb->prefix}term_relationships AS tr
235
- ON tr.term_taxonomy_id = tt.term_taxonomy_id
236
- WHERE tt.taxonomy = 'pwb-brand'
237
- AND tr.object_id IN ($product_ids)
238
- ");
239
-
240
- return ($brand_ids) ? $brand_ids : false;
241
- }
242
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/widgets/class-pwb-list-widget.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Perfect_Woocommerce_Brands\Widgets;
4
+
5
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
6
+
7
+ class PWB_List_Widget extends \WP_Widget {
8
+
9
+ function __construct() {
10
+ $params = array(
11
+ 'description' => __( 'Adds a brands list to your site', 'perfect-woocommerce-brands' ),
12
+ 'name' => __( 'Brands list', 'perfect-woocommerce-brands' ),
13
+ );
14
+ parent::__construct( 'PWB_List_Widget', '', $params );
15
+ }
16
+
17
+ public function form( $instance ) {
18
+ extract( $instance );
19
+
20
+ $title = ( isset( $instance['title'] ) ) ? $instance['title'] : esc_html__( 'Brands', 'perfect-woocommerce-brands' );
21
+ if ( ! isset( $display_as ) ) {
22
+ $display_as = 'brand_logo';
23
+ }
24
+ if ( ! isset( $columns ) ) {
25
+ $columns = '2';
26
+ }
27
+ $hide_empty = ( isset( $hide_empty ) && $hide_empty == 'on' ) ? true : false;
28
+ $only_featured = ( isset( $only_featured ) && $only_featured == 'on' ) ? true : false;
29
+ $randomize = ( isset( $randomize ) && $randomize == 'on' ) ? true : false;
30
+ ?>
31
+
32
+ <p>
33
+ <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'perfect-woocommerce-brands' ); ?></label>
34
+ <input
35
+ class="widefat"
36
+ type="text"
37
+ id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
38
+ name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
39
+ value="
40
+ <?php
41
+ if ( isset( $title ) ) {
42
+ echo esc_attr( $title );
43
+ }
44
+ ?>
45
+ ">
46
+ </p>
47
+ <p>
48
+ <label for="<?php echo esc_attr( $this->get_field_id( 'display_as' ) ); ?>"><?php esc_html_e( 'Display as:', 'perfect-woocommerce-brands' ); ?></label>
49
+ <select
50
+ class="widefat pwb-select-display-as"
51
+ id="<?php echo esc_attr( $this->get_field_id( 'display_as' ) ); ?>"
52
+ name="<?php echo esc_attr( $this->get_field_name( 'display_as' ) ); ?>">
53
+ <option value="brand_name" <?php selected( $display_as, 'brand_name' ); ?>><?php esc_html_e( 'Brand name', 'perfect-woocommerce-brands' ); ?></option>
54
+ <option value="brand_logo" <?php selected( $display_as, 'brand_logo' ); ?>><?php esc_html_e( 'Brand logo', 'perfect-woocommerce-brands' ); ?></option>
55
+ </select>
56
+ </p>
57
+ <p class="pwb-display-as-logo<?php echo ( $display_as == 'brand_logo' ) ? ' show' : ''; ?>">
58
+ <label for="<?php echo esc_attr( $this->get_field_id( 'columns' ) ); ?>"><?php esc_html_e( 'Columns:', 'perfect-woocommerce-brands' ); ?></label>
59
+ <select
60
+ class="widefat"
61
+ id="<?php echo esc_attr( $this->get_field_id( 'columns' ) ); ?>"
62
+ name="<?php echo esc_attr( $this->get_field_name( 'columns' ) ); ?>">
63
+ <option value="1" <?php selected( $columns, '1' ); ?>>1</option>
64
+ <option value="2" <?php selected( $columns, '2' ); ?>>2</option>
65
+ <option value="3" <?php selected( $columns, '3' ); ?>>3</option>
66
+ <option value="4" <?php selected( $columns, '4' ); ?>>4</option>
67
+ <option value="5" <?php selected( $columns, '5' ); ?>>5</option>
68
+ <option value="6" <?php selected( $columns, '6' ); ?>>6</option>
69
+ </select>
70
+ </p>
71
+ <p>
72
+ <input
73
+ type="checkbox"
74
+ id="<?php echo esc_attr( $this->get_field_id( 'hide_empty' ) ); ?>"
75
+ name="<?php echo esc_attr( $this->get_field_name( 'hide_empty' ) ); ?>"
76
+ <?php checked( $hide_empty ); ?>>
77
+ <label for="<?php echo esc_attr( $this->get_field_id( 'hide_empty' ) ); ?>">
78
+ <?php esc_html_e( 'Hide empty', 'perfect-woocommerce-brands' ); ?>
79
+ </label>
80
+ </p>
81
+ <p>
82
+ <input
83
+ type="checkbox"
84
+ id="<?php echo esc_attr( $this->get_field_id( 'only_featured' ) ); ?>"
85
+ name="<?php echo esc_attr( $this->get_field_name( 'only_featured' ) ); ?>"
86
+ <?php checked( $only_featured ); ?>>
87
+ <label for="<?php echo esc_attr( $this->get_field_id( 'only_featured' ) ); ?>">
88
+ <?php esc_html_e( 'Only favorite brands', 'perfect-woocommerce-brands' ); ?>
89
+ </label>
90
+ </p>
91
+ <p class="pwb-display-as-logo<?php echo ( $display_as == 'brand_logo' ) ? ' show' : ''; ?>">
92
+ <input
93
+ type="checkbox"
94
+ id="<?php echo esc_attr( $this->get_field_id( 'randomize' ) ); ?>"
95
+ name="<?php echo esc_attr( $this->get_field_name( 'randomize' ) ); ?>"
96
+ <?php checked( $randomize ); ?>>
97
+ <label for="<?php echo esc_attr( $this->get_field_id( 'randomize' ) ); ?>">
98
+ <?php esc_html_e( 'Randomize', 'perfect-woocommerce-brands' ); ?>
99
+ </label>
100
+ </p>
101
+
102
+ <?php
103
+ }
104
+
105
+ public function widget( $args, $instance ) {
106
+ extract( $args );
107
+ extract( $instance );
108
+
109
+ $hide_empty = ( isset( $hide_empty ) && $hide_empty == 'on' ) ? true : false;
110
+ $only_featured = ( isset( $only_featured ) && $only_featured == 'on' ) ? true : false;
111
+ $randomize = ( isset( $randomize ) && $randomize == 'on' ) ? true : false;
112
+ $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands(
113
+ $hide_empty,
114
+ 'name',
115
+ 'ASC',
116
+ $only_featured,
117
+ true
118
+ );
119
+ if ( isset( $randomize ) && $randomize == 'on' && $display_as == 'brand_logo' ) {
120
+ shuffle( $brands );
121
+ }
122
+
123
+ if ( is_array( $brands ) && count( $brands ) > 0 ) {
124
+
125
+ echo $before_widget; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
126
+
127
+ if ( ! empty( $title ) ) {
128
+ echo $before_title . $title . $after_title; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
129
+ }
130
+
131
+ if ( ! isset( $display_as ) ) {
132
+ $display_as = 'brand_logo';
133
+ }
134
+ if ( ! isset( $columns ) ) {
135
+ $columns = '2';
136
+ }
137
+ $li_class = ( $display_as == 'brand_logo' ) ? 'pwb-columns pwb-columns-' . $columns : '';
138
+
139
+ echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template( // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
140
+ ( $display_as == 'brand_logo' ) ? 'list-logo' : 'list',
141
+ 'widgets',
142
+ array(
143
+ 'brands' => $brands,
144
+ 'li_class' => $li_class,
145
+ 'title_prefix' => __( 'Go to', 'perfect-woocommerce-brands' ),
146
+ ),
147
+ false
148
+ );
149
+
150
+ echo $after_widget; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
151
+
152
+ }
153
+
154
+ }
155
+
156
+ }
classes/widgets/class-pwb-list.php DELETED
@@ -1,129 +0,0 @@
1
- <?php
2
- namespace Perfect_Woocommerce_Brands\Widgets;
3
-
4
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
5
-
6
- class PWB_List_Widget extends \WP_Widget {
7
-
8
- function __construct(){
9
- $params = array(
10
- 'description' => __( 'Adds a brands list to your site', 'perfect-woocommerce-brands' ),
11
- 'name' => __( 'Brands list', 'perfect-woocommerce-brands' )
12
- );
13
- parent::__construct('PWB_List_Widget', '', $params);
14
- }
15
-
16
- public function form($instance){
17
- extract($instance);
18
-
19
- $title = ( isset( $instance[ 'title' ] ) ) ? $instance[ 'title' ] : esc_html__('Brands', 'perfect-woocommerce-brands');
20
- if( !isset( $display_as ) ) $display_as = 'brand_logo';
21
- if( !isset( $columns ) ) $columns = '2';
22
- $hide_empty = ( isset( $hide_empty ) && $hide_empty == 'on' ) ? true : false;
23
- $only_featured = ( isset( $only_featured ) && $only_featured == 'on' ) ? true : false;
24
- $randomize = ( isset( $randomize ) && $randomize == 'on' ) ? true : false;
25
- ?>
26
-
27
- <p>
28
- <label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php echo __( 'Title:', 'perfect-woocommerce-brands' );?></label>
29
- <input
30
- class="widefat"
31
- type="text"
32
- id="<?php echo esc_attr( $this->get_field_id('title') ); ?>"
33
- name="<?php echo esc_attr( $this->get_field_name('title') ); ?>"
34
- value="<?php if(isset($title)) echo esc_attr($title); ?>">
35
- </p>
36
- <p>
37
- <label for="<?php echo esc_attr( $this->get_field_id('display_as') ); ?>"><?php echo __( 'Display as:', 'perfect-woocommerce-brands' );?></label>
38
- <select
39
- class="widefat pwb-select-display-as"
40
- id="<?php echo esc_attr( $this->get_field_id('display_as') ); ?>"
41
- name="<?php echo esc_attr( $this->get_field_name('display_as') ); ?>">
42
- <option value="brand_name" <?php selected( $display_as, 'brand_name' ); ?>><?php _e( 'Brand name', 'perfect-woocommerce-brands' );?></option>
43
- <option value="brand_logo" <?php selected( $display_as, 'brand_logo' ); ?>><?php _e( 'Brand logo', 'perfect-woocommerce-brands' );?></option>
44
- </select>
45
- </p>
46
- <p class="pwb-display-as-logo<?php echo ($display_as=='brand_logo') ? ' show' : '' ;?>">
47
- <label for="<?php echo esc_attr( $this->get_field_id('columns') ); ?>"><?php echo __( 'Columns:', 'perfect-woocommerce-brands' );?></label>
48
- <select
49
- class="widefat"
50
- id="<?php echo esc_attr( $this->get_field_id('columns') ); ?>"
51
- name="<?php echo esc_attr( $this->get_field_name('columns') ); ?>">
52
- <option value="1" <?php selected( $columns, '1' ); ?>>1</option>
53
- <option value="2" <?php selected( $columns, '2' ); ?>>2</option>
54
- <option value="3" <?php selected( $columns, '3' ); ?>>3</option>
55
- <option value="4" <?php selected( $columns, '4' ); ?>>4</option>
56
- <option value="5" <?php selected( $columns, '5' ); ?>>5</option>
57
- <option value="6" <?php selected( $columns, '6' ); ?>>6</option>
58
- </select>
59
- </p>
60
- <p>
61
- <input
62
- type="checkbox"
63
- id="<?php echo esc_attr( $this->get_field_id('hide_empty') ); ?>"
64
- name="<?php echo esc_attr( $this->get_field_name('hide_empty') ); ?>"
65
- <?php checked( $hide_empty ); ?>>
66
- <label for="<?php echo esc_attr( $this->get_field_id('hide_empty') ); ?>">
67
- <?php echo __( 'Hide empty', 'perfect-woocommerce-brands' );?>
68
- </label>
69
- </p>
70
- <p>
71
- <input
72
- type="checkbox"
73
- id="<?php echo esc_attr( $this->get_field_id('only_featured') ); ?>"
74
- name="<?php echo esc_attr( $this->get_field_name('only_featured') ); ?>"
75
- <?php checked( $only_featured ); ?>>
76
- <label for="<?php echo esc_attr( $this->get_field_id('only_featured') ); ?>">
77
- <?php echo __( 'Only favorite brands', 'perfect-woocommerce-brands' );?>
78
- </label>
79
- </p>
80
- <p class="pwb-display-as-logo<?php echo ($display_as=='brand_logo') ? ' show' : '' ;?>">
81
- <input
82
- type="checkbox"
83
- id="<?php echo esc_attr( $this->get_field_id('randomize') ); ?>"
84
- name="<?php echo esc_attr( $this->get_field_name('randomize') ); ?>"
85
- <?php checked( $randomize ); ?>>
86
- <label for="<?php echo esc_attr( $this->get_field_id('randomize') ); ?>">
87
- <?php echo __( 'Randomize', 'perfect-woocommerce-brands' );?>
88
- </label>
89
- </p>
90
-
91
- <?php
92
- }
93
-
94
- public function widget( $args, $instance ){
95
- extract( $args );
96
- extract( $instance );
97
-
98
- $hide_empty = ( isset( $hide_empty ) && $hide_empty == 'on' ) ? true : false;
99
- $only_featured = ( isset( $only_featured ) && $only_featured == 'on' ) ? true : false;
100
- $randomize = ( isset( $randomize ) && $randomize == 'on' ) ? true : false;
101
- $brands = \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::get_brands(
102
- $hide_empty, 'name', 'ASC', $only_featured, true
103
- );
104
- if( isset( $randomize ) && $randomize == 'on' && $display_as == 'brand_logo' ) shuffle( $brands );
105
-
106
- if( is_array( $brands ) && count( $brands ) > 0 ){
107
-
108
- echo $before_widget;
109
-
110
- if( !empty( $title ) ) echo $before_title . $title . $after_title;
111
-
112
- if( !isset( $display_as ) ) $display_as = 'brand_logo';
113
- if( !isset( $columns ) ) $columns = '2';
114
- $li_class = ( $display_as == 'brand_logo' ) ? "pwb-columns pwb-columns-".$columns : "";
115
-
116
- echo \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands::render_template(
117
- ( $display_as == 'brand_logo' ) ? 'list-logo' : 'list',
118
- 'widgets',
119
- array( 'brands' => $brands, 'li_class' => $li_class, 'title_prefix' => __( 'Go to', 'perfect-woocommerce-brands' ) ),
120
- false
121
- );
122
-
123
- echo $after_widget;
124
-
125
- }
126
-
127
- }
128
-
129
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/quadlayers/widget.php CHANGED
@@ -1,130 +1,128 @@
1
  <?php
2
 
3
- if (!class_exists('QL_Widget')) {
4
-
5
- class QL_Widget
6
- {
7
- protected static $instance;
8
-
9
- public function __construct()
10
- {
11
- if (is_admin()) {
12
- add_action('wp_network_dashboard_setup', [$this, 'add_dashboard_widget'], -10);
13
- add_action('wp_dashboard_setup', [$this, 'add_dashboard_widget'], -10);
14
- }
15
- }
16
-
17
- public function add_dashboard_widget()
18
- {
19
- wp_add_dashboard_widget(
20
- 'quadlayers-dashboard-overview',
21
- __('QuadLayers News', 'perfect-woocommerce-brands'),
22
- [$this, 'display_dashboard_widget']
23
- );
24
- }
25
-
26
- public function display_dashboard_widget()
27
- {
28
- $feed_items = $this->get_feed();
29
-
30
- ?>
31
- <div>
32
- <div>
33
- <div style="margin-top: 11px;float: left;width: 70%;">
34
- <?php esc_html_e('Hi! We are Quadlayers! Welcome to QuadLayers! We’re a team of international people who have been working in the WordPress sphere for the last ten years.', 'perfect-woocommerce-brands'); ?>
35
- <div style="margin-top: 11px; float: left; width: 70%;"><a href="<?php echo admin_url('admin.php?page=' . PWB_PREFIX . '_suggestions'); ?>" target="_blank" class="button button-secondary"><?php esc_html_e('More products', 'perfect-woocommerce-brands'); ?></a></div>
36
- </div>
37
- <img style="width: 30%;margin-top: 11px;float: right; max-width: 95px;" src="<?php echo plugins_url('/assets/img/quadlayers.jpg', PWB_PLUGIN_FILE); ?>" />
38
- </div>
39
- <div style="clear: both;"></div>
40
- </div>
41
- <div style="margin: 16px -12px 0; padding: 12px 12px 0;border-top: 1px solid #eee;">
42
- <ul>
43
- <?php if (is_array($feed_items)) { ?>
44
- <?php
45
- foreach ($feed_items as $item) {
46
-
47
- $link = $item['link'];
48
- while (stristr($link, 'http') !== $link) {
49
- $link = substr($link, 1);
50
- }
51
-
52
- $link = esc_url(strip_tags($link . '?utm_source=ql_dashboard'));
53
- $title = esc_html(trim(strip_tags($item['title'])));
54
-
55
- if (empty($title)) {
56
- $title = __('Untitled', 'perfect-woocommerce-brands');
57
- }
58
-
59
- $desc = html_entity_decode($item['desc'], ENT_QUOTES, get_option('blog_charset'));
60
- $desc = esc_attr(wp_trim_words($desc, 15, '...'));
61
- $summary = $desc;
62
- $summary = '<div class="rssSummary">' . $summary . '</div>';
63
- $date = $item['date'];
64
- if ($date) {
65
- $date = '<span class="rss-date">' . date_i18n(get_option('date_format'), $date) . '</span>';
66
- }
67
- $author = $item['author'];
68
- $author = ucfirst($author);
69
- $author = ' <cite>' . esc_html(strip_tags($author)) . '</cite>';
70
- printf(__('<li><a href="%s" target="_blank">%s </a>%s%s%s</li>', 'perfect-woocommerce-brands'), $link, $title, $date, $summary, $author);
71
- } ?>
72
- <?php } else {
73
- printf(__('<li>%s</li>', 'perfect-woocommerce-brands'), $feed_items);
74
- } ?>
75
- </ul>
76
- </div>
77
- <div style="display: flex; justify-content: space-between;align-items: center;margin: 16px -12px 0;padding: 12px 12px 0; border-top: 1px solid #eee;">
78
- <a href="<?php printf('https://quadlayers.com/blog/?utm_source=%s&utm_medium=software&utm_campaign=wordpress&utm_content=dashboard', 'perfect-woocommerce-brands'); ?>" target="_blank"><?php esc_html_e('Read more like this on our blog', 'perfect-woocommerce-brands') ?></a>
79
- <a class="button-primary" href="<?php printf('https://quadlayers.com/?utm_source=%s&utm_medium=software&utm_campaign=wordpress&utm_content=dashboard', 'perfect-woocommerce-brands'); ?>" target="_blank"><?php esc_html_e('QuadLayers', 'perfect-woocommerce-brands') ?></a>
80
- </div>
81
- <?php
82
- }
83
-
84
- public function get_feed()
85
- {
86
- $rss_items = get_transient('quadlayers_news_feed');
87
-
88
- if ($rss_items === false) {
89
- $rss = fetch_feed('https://quadlayers.com/news/feed/');
90
-
91
- if (is_wp_error($rss)) {
92
- return "An error has occurred, which probably means the feed is down. Try again later";
93
- }
94
-
95
- if (!$rss->get_item_quantity()) {
96
- $rss->__destruct();
97
- unset($rss);
98
- return "An error has occurred, which probably means the feed is down. Try again later";
99
- }
100
-
101
- $rss_items = [];
102
-
103
- foreach ($rss->get_items(0, 3) as $item) {
104
- $rss_items[] = [
105
- 'link' => $item->get_link(),
106
- 'author' => $item->get_author()->get_name(),
107
- 'title' => $item->get_title(),
108
- 'desc' => $item->get_description(),
109
- 'date' => $item->get_date('U')
110
- ];
111
- }
112
-
113
- set_transient('quadlayers_news_feed', $rss_items, DAY_IN_SECONDS);
114
- }
115
-
116
- return $rss_items;
117
- }
118
-
119
- public static function instance()
120
- {
121
- if (!isset(self::$instance)) {
122
- self::$instance = new self();
123
- }
124
- return self::$instance;
125
- }
126
- }
127
-
128
-
129
- QL_Widget::instance();
130
  }
1
  <?php
2
 
3
+ if ( ! class_exists( 'QL_Widget' ) ) {
4
+
5
+ class QL_Widget {
6
+
7
+ protected static $instance;
8
+
9
+ public function __construct() {
10
+ if ( is_admin() ) {
11
+ add_action( 'wp_network_dashboard_setup', array( $this, 'add_dashboard_widget' ), -10 );
12
+ add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widget' ), -10 );
13
+ }
14
+ }
15
+
16
+ public function add_dashboard_widget() {
17
+ wp_add_dashboard_widget(
18
+ 'quadlayers-dashboard-overview',
19
+ __( 'QuadLayers News', 'perfect-woocommerce-brands' ),
20
+ array( $this, 'display_dashboard_widget' )
21
+ );
22
+ }
23
+
24
+ public function display_dashboard_widget() {
25
+ $feed_items = $this->get_feed();
26
+
27
+ ?>
28
+ <div>
29
+ <div>
30
+ <div style="margin-top: 11px;float: left;width: 70%;">
31
+ <?php esc_html_e( 'Hi! We are Quadlayers! Welcome to QuadLayers! We’re a team of international people who have been working in the WordPress sphere for the last ten years.', 'perfect-woocommerce-brands' ); ?>
32
+ <div style="margin-top: 11px; float: left; width: 70%;"><a href="<?php echo esc_url( admin_url( 'admin.php?page=' . PWB_PREFIX . '_suggestions' ) ); ?>" target="_blank" class="button button-secondary"><?php esc_html_e( 'More products', 'perfect-woocommerce-brands' ); ?></a></div>
33
+ </div>
34
+ <img style="width: 30%;margin-top: 11px;float: right; max-width: 95px;" src="<?php echo esc_url( plugins_url( '/assets/img/quadlayers.jpg', PWB_PLUGIN_FILE ) ); ?>" />
35
+ </div>
36
+ <div style="clear: both;"></div>
37
+ </div>
38
+ <div style="margin: 16px -12px 0; padding: 12px 12px 0;border-top: 1px solid #eee;">
39
+ <ul>
40
+ <?php if ( is_array( $feed_items ) ) { ?>
41
+ <?php
42
+ foreach ( $feed_items as $item ) {
43
+
44
+ $link = $item['link'];
45
+ while ( stristr( $link, 'http' ) !== $link ) {
46
+ $link = substr( $link, 1 );
47
+ }
48
+
49
+ $link = esc_url( wp_strip_all_tags( $link . '?utm_source=ql_dashboard' ) );
50
+ $title = esc_html( trim( wp_strip_all_tags( $item['title'] ) ) );
51
+
52
+ if ( empty( $title ) ) {
53
+ $title = __( 'Untitled', 'perfect-woocommerce-brands' );
54
+ }
55
+
56
+ $desc = html_entity_decode( $item['desc'], ENT_QUOTES, get_option( 'blog_charset' ) );
57
+ $desc = esc_attr( wp_trim_words( $desc, 15, '...' ) );
58
+ $summary = $desc;
59
+ $summary = '<div class="rssSummary">' . $summary . '</div>';
60
+ $date = $item['date'];
61
+ if ( $date ) {
62
+ $date = '<span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';
63
+ }
64
+ $author = $item['author'];
65
+ $author = ucfirst( $author );
66
+ $author = ' <cite>' . esc_html( wp_strip_all_tags( $author ) ) . '</cite>';
67
+ printf( '<li><a href="%1$s" target="_blank">%2$s </a>%3$s%4$s%5$s</li>', esc_url( $link ), esc_html( $title ), esc_html( $date ), esc_html( $summary ), esc_html( $author ) );
68
+ }
69
+ ?>
70
+ <?php
71
+ } else {
72
+ printf( '<li>%s</li>', esc_html( $feed_items ) );
73
+ }
74
+ ?>
75
+ </ul>
76
+ </div>
77
+ <div style="display: flex; justify-content: space-between;align-items: center;margin: 16px -12px 0;padding: 12px 12px 0; border-top: 1px solid #eee;">
78
+ <a href="<?php printf( 'https://quadlayers.com/blog/?utm_source=%s&utm_medium=software&utm_campaign=wordpress&utm_content=dashboard', 'perfect-woocommerce-brands' ); ?>" target="_blank"><?php esc_html_e( 'Read more like this on our blog', 'perfect-woocommerce-brands' ); ?></a>
79
+ <a class="button-primary" href="<?php printf( 'https://quadlayers.com/?utm_source=%s&utm_medium=software&utm_campaign=wordpress&utm_content=dashboard', 'perfect-woocommerce-brands' ); ?>" target="_blank"><?php esc_html_e( 'QuadLayers', 'perfect-woocommerce-brands' ); ?></a>
80
+ </div>
81
+ <?php
82
+ }
83
+
84
+ public function get_feed() {
85
+ $rss_items = get_transient( 'quadlayers_news_feed' );
86
+
87
+ if ( $rss_items === false ) {
88
+ $rss = fetch_feed( 'https://quadlayers.com/news/feed/' );
89
+
90
+ if ( is_wp_error( $rss ) ) {
91
+ return 'An error has occurred, which probably means the feed is down. Try again later';
92
+ }
93
+
94
+ if ( ! $rss->get_item_quantity() ) {
95
+ $rss->__destruct();
96
+ unset( $rss );
97
+ return 'An error has occurred, which probably means the feed is down. Try again later';
98
+ }
99
+
100
+ $rss_items = array();
101
+
102
+ foreach ( $rss->get_items( 0, 3 ) as $item ) {
103
+ $rss_items[] = array(
104
+ 'link' => $item->get_link(),
105
+ 'author' => $item->get_author()->get_name(),
106
+ 'title' => $item->get_title(),
107
+ 'desc' => $item->get_description(),
108
+ 'date' => $item->get_date( 'U' ),
109
+ );
110
+ }
111
+
112
+ set_transient( 'quadlayers_news_feed', $rss_items, DAY_IN_SECONDS );
113
+ }
114
+
115
+ return $rss_items;
116
+ }
117
+
118
+ public static function instance() {
119
+ if ( ! isset( self::$instance ) ) {
120
+ self::$instance = new self();
121
+ }
122
+ return self::$instance;
123
+ }
124
+ }
125
+
126
+
127
+ QL_Widget::instance();
 
 
128
  }
main.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
 
3
- if ($active_plugins = get_option('active_plugins', array())) {
4
- foreach ($active_plugins as $key => $active_plugin) {
5
- if ($active_plugin == 'perfect-woocommerce-brands/main.php') {
6
- $active_plugins[$key] = str_replace('/main.php', '/perfect-woocommerce-brands.php', $active_plugin);
7
- }
8
- }
9
- update_option('active_plugins', $active_plugins);
10
- }
1
  <?php
2
 
3
+ if ( $active_plugins = get_option( 'active_plugins', array() ) ) {
4
+ foreach ( $active_plugins as $key => $active_plugin ) {
5
+ if ( $active_plugin == 'perfect-woocommerce-brands/main.php' ) {
6
+ $active_plugins[ $key ] = str_replace( '/main.php', '/perfect-woocommerce-brands.php', $active_plugin );
7
+ }
8
+ }
9
+ update_option( 'active_plugins', $active_plugins );
10
+ }
perfect-woocommerce-brands.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Perfect Brands for WooCommerce
5
  * Plugin URI: https://quadlayers.com/portfolio/perfect-woocommerce-brands/
6
  * Description: Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store.
7
- * Version: 2.0.5
8
  * Author: QuadLayers
9
  * Author URI: https://quadlayers.com
10
  * Text Domain: perfect-woocommerce-brands
@@ -29,93 +29,108 @@
29
 
30
  namespace Perfect_Woocommerce_Brands;
31
 
32
- defined('ABSPATH') or die('No script kiddies please!');
33
 
34
- //plugin constants
35
- define('PWB_PLUGIN_FILE', __FILE__);
36
- define('PWB_PLUGIN_URL', plugins_url('', __FILE__));
37
- define('PWB_PLUGIN_DIR', __DIR__ . DIRECTORY_SEPARATOR);
38
- define('PWB_PLUGIN_BASENAME', plugin_basename(__FILE__));
39
- define('PWB_PLUGIN_VERSION', '2.0.5');
40
- define('PWB_PLUGIN_NAME', 'Perfect WooCommerce Brands');
41
- define('PWB_PREFIX', 'pwb');
42
- define('PWB_REVIEW_URL', 'https://wordpress.org/support/plugin/perfect-woocommerce-brands/reviews/?filter=5#new-post');
43
- define('PWB_DEMO_URL', 'https://quadlayers.com/portfolio/perfect-woocommerce-brands/?utm_source=pwb_admin');
44
- define('PWB_PURCHASE_URL', PWB_DEMO_URL);
45
- define('PWB_SUPPORT_URL', 'https://quadlayers.com/account/support/?utm_source=pwb_admin');
46
- define('PWB_DOCUMENTATION_URL', 'https://quadlayers.com/documentation/perfect-woocommerce-brands/?utm_source=pwb_admin');
47
- define('PWB_GITHUB_URL', 'https://github.com/quadlayers/perfect-woocommerce-brands/');
48
- define('PWB_GROUP_URL', 'https://www.facebook.com/groups/quadlayers');
49
 
50
- register_activation_hook(__FILE__, function () {
51
- update_option('pwb_activate_on', time());
52
- });
 
 
 
53
 
54
- //clean brands slug on plugin deactivation
55
- register_deactivation_hook(__FILE__, function () {
56
- update_option('old_wc_pwb_admin_tab_slug', 'null');
57
- });
 
 
 
58
 
59
- //loads textdomain for the translations
60
- add_action('plugins_loaded', function () {
61
- load_plugin_textdomain('perfect-woocommerce-brands', false, PWB_PLUGIN_DIR . '/lang');
62
- });
 
 
 
63
 
64
 
65
- if (!class_exists('QL_Widget')) {
66
- include_once(PWB_PLUGIN_DIR . 'includes/quadlayers/widget.php');
67
  }
68
 
69
- include_once(ABSPATH . 'wp-admin/includes/plugin.php');
70
- if (is_plugin_active('woocommerce/woocommerce.php')) {
71
 
72
- require 'classes/class-pwb-term.php';
73
- require 'classes/widgets/class-pwb-dropdown.php';
74
- require 'classes/widgets/class-pwb-list.php';
75
- require 'classes/widgets/class-pwb-filter-by-brand.php';
76
- require 'classes/shortcodes/class-pwb-product-carousel.php';
77
- require 'classes/shortcodes/class-pwb-carousel.php';
78
- require 'classes/shortcodes/class-pwb-all-brands.php';
79
- require 'classes/shortcodes/class-pwb-az-listing.php';
80
- require 'classes/shortcodes/class-pwb-brand.php';
81
- require 'classes/class-perfect-woocommerce-brands.php';
82
- require 'classes/class-pwb-api-support.php';
83
- new PWB_API_Support();
84
- require 'classes/admin/class-pwb-coupon.php';
85
- new Admin\PWB_Coupon();
86
 
87
- if (is_admin()) {
88
- require 'classes/admin/class-pwb-suggestions.php';
89
- new Admin\PWB_Suggestions();
90
- require 'classes/admin/class-pwb-notices.php';
91
- new Admin\PWB_Notices();
92
- require 'classes/admin/class-pwb-system-status.php';
93
- new Admin\PWB_System_Status();
94
- require 'classes/admin/class-pwb-admin-tab.php';
95
- require 'classes/admin/class-pwb-migrate.php';
96
- new Admin\PWB_Migrate();
97
- require 'classes/admin/class-pwb-dummy-data.php';
98
- new Admin\PWB_Dummy_Data();
99
- require 'classes/admin/class-edit-brands-page.php';
100
- new Admin\Edit_Brands_Page();
101
- require 'classes/admin/class-brands-custom-fields.php';
102
- new Admin\Brands_Custom_Fields();
103
- require 'classes/admin/class-brands-exporter.php';
104
- new Admin\Brands_Exporter();
105
- require 'classes/admin/class-pwb-importer-support.php';
106
- new PWB_Importer_Support();
107
- require 'classes/admin/class-pwb-exporter-support.php';
108
- new PWB_Exporter_Support();
109
- } else {
110
- include_once 'classes/class-pwb-product-tab.php';
111
- new PWB_Product_Tab();
112
- }
113
 
114
- new \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands();
115
- } elseif (is_admin()) {
116
 
117
- add_action('admin_notices', function () {
118
- $message = esc_html__('Perfect WooCommerce Brands needs WooCommerce to run. Please, install and active WooCommerce plugin.', 'perfect-woocommerce-brands');
119
- printf('<div class="%1$s"><p>%2$s</p></div>', 'notice notice-error', $message);
120
- });
 
 
 
 
 
 
121
  }
4
  * Plugin Name: Perfect Brands for WooCommerce
5
  * Plugin URI: https://quadlayers.com/portfolio/perfect-woocommerce-brands/
6
  * Description: Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store.
7
+ * Version: 2.0.6
8
  * Author: QuadLayers
9
  * Author URI: https://quadlayers.com
10
  * Text Domain: perfect-woocommerce-brands
29
 
30
  namespace Perfect_Woocommerce_Brands;
31
 
32
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
33
 
34
+ // plugin constants
35
+ define( 'PWB_PLUGIN_FILE', __FILE__ );
36
+ define( 'PWB_PLUGIN_URL', plugins_url( '', __FILE__ ) );
37
+ define( 'PWB_PLUGIN_DIR', __DIR__ . DIRECTORY_SEPARATOR );
38
+ define( 'PWB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
39
+ define( 'PWB_PLUGIN_VERSION', '2.0.6' );
40
+ define( 'PWB_PLUGIN_NAME', 'Perfect WooCommerce Brands' );
41
+ define( 'PWB_PREFIX', 'pwb' );
42
+ define( 'PWB_REVIEW_URL', 'https://wordpress.org/support/plugin/perfect-woocommerce-brands/reviews/?filter=5#new-post' );
43
+ define( 'PWB_DEMO_URL', 'https://quadlayers.com/portfolio/perfect-woocommerce-brands/?utm_source=pwb_admin' );
44
+ define( 'PWB_PURCHASE_URL', PWB_DEMO_URL );
45
+ define( 'PWB_SUPPORT_URL', 'https://quadlayers.com/account/support/?utm_source=pwb_admin' );
46
+ define( 'PWB_DOCUMENTATION_URL', 'https://quadlayers.com/documentation/perfect-woocommerce-brands/?utm_source=pwb_admin' );
47
+ define( 'PWB_GITHUB_URL', 'https://github.com/quadlayers/perfect-woocommerce-brands/' );
48
+ define( 'PWB_GROUP_URL', 'https://www.facebook.com/groups/quadlayers' );
49
 
50
+ register_activation_hook(
51
+ __FILE__,
52
+ function () {
53
+ update_option( 'pwb_activate_on', time() );
54
+ }
55
+ );
56
 
57
+ // clean brands slug on plugin deactivation
58
+ register_deactivation_hook(
59
+ __FILE__,
60
+ function () {
61
+ update_option( 'old_wc_pwb_admin_tab_slug', 'null' );
62
+ }
63
+ );
64
 
65
+ // loads textdomain for the translations
66
+ add_action(
67
+ 'plugins_loaded',
68
+ function () {
69
+ load_plugin_textdomain( 'perfect-woocommerce-brands', false, PWB_PLUGIN_DIR . '/lang' );
70
+ }
71
+ );
72
 
73
 
74
+ if ( ! class_exists( 'QL_Widget' ) ) {
75
+ include_once PWB_PLUGIN_DIR . 'includes/quadlayers/widget.php';
76
  }
77
 
78
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
79
+ if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
80
 
81
+ require 'classes/class-pwb-term.php';
82
+ require 'classes/widgets/class-pwb-dropdown-widget.php';
83
+ require 'classes/widgets/class-pwb-list-widget.php';
84
+ require 'classes/widgets/class-pwb-filter-by-brand-widget.php';
85
+ require 'classes/shortcodes/class-pwb-product-carousel.php';
86
+ require 'classes/shortcodes/class-pwb-carousel.php';
87
+ require 'classes/shortcodes/class-pwb-all-brands.php';
88
+ require 'classes/shortcodes/class-pwb-az-listing.php';
89
+ require 'classes/shortcodes/class-pwb-brand.php';
90
+ require 'classes/class-perfect-woocommerce-brands.php';
91
+ require 'classes/class-pwb-api-support.php';
92
+ new PWB_API_Support();
93
+ require 'classes/admin/class-pwb-coupon.php';
94
+ new Admin\PWB_Coupon();
95
 
96
+ if ( is_admin() ) {
97
+ require 'classes/admin/class-pwb-suggestions.php';
98
+ new Admin\PWB_Suggestions();
99
+ require 'classes/admin/class-pwb-notices.php';
100
+ new Admin\PWB_Notices();
101
+ require 'classes/admin/class-pwb-system-status.php';
102
+ new Admin\PWB_System_Status();
103
+ require 'classes/admin/class-pwb-admin-tab.php';
104
+ require 'classes/admin/class-pwb-migrate.php';
105
+ new Admin\PWB_Migrate();
106
+ require 'classes/admin/class-pwb-dummy-data.php';
107
+ new Admin\PWB_Dummy_Data();
108
+ require 'classes/admin/class-edit-brands-page.php';
109
+ new Admin\Edit_Brands_Page();
110
+ require 'classes/admin/class-brands-custom-fields.php';
111
+ new Admin\Brands_Custom_Fields();
112
+ require 'classes/admin/class-brands-exporter.php';
113
+ new Admin\Brands_Exporter();
114
+ require 'classes/admin/class-pwb-importer-support.php';
115
+ new PWB_Importer_Support();
116
+ require 'classes/admin/class-pwb-exporter-support.php';
117
+ new PWB_Exporter_Support();
118
+ } else {
119
+ include_once 'classes/class-pwb-product-tab.php';
120
+ new PWB_Product_Tab();
121
+ }
122
 
123
+ new \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands();
124
+ } elseif ( is_admin() ) {
125
 
126
+ add_action(
127
+ 'admin_notices',
128
+ function () {
129
+ printf(
130
+ '<div class="%1$s"><p>%2$s</p></div>',
131
+ 'notice notice-error',
132
+ esc_html__( 'Perfect WooCommerce Brands needs WooCommerce to run. Please, install and active WooCommerce plugin.', 'perfect-woocommerce-brands' )
133
+ );
134
+ }
135
+ );
136
  }
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: woocommerce, woocommerce brands, woocommerce product, woocommerce manufact
5
  Requires at least: 4.7
6
  Tested up to: 5.9
7
  Requires PHP: 5.6
8
- Stable tag: 2.0.5
9
  WC requires at least: 3.0
10
  WC tested up to: 6.1
11
  License: GPLv3
@@ -90,6 +90,8 @@ You can also contribute [translating the plugin](https://translate.wordpress.org
90
 
91
 
92
  == Changelog ==
 
 
93
  = 2.0.5 =
94
  * Fix: Security fix
95
  * Fix: WooCommerce compatibility
5
  Requires at least: 4.7
6
  Tested up to: 5.9
7
  Requires PHP: 5.6
8
+ Stable tag: 2.0.6
9
  WC requires at least: 3.0
10
  WC tested up to: 6.1
11
  License: GPLv3
90
 
91
 
92
  == Changelog ==
93
+ = 2.0.6 =
94
+ * Fix: Output sanitization
95
  = 2.0.5 =
96
  * Fix: Security fix
97
  * Fix: WooCommerce compatibility
templates/admin/brands-exporter.php CHANGED
@@ -1,15 +1,16 @@
1
  <?php
2
  /**
3
  * The template for displaying the edit-tags.php exporter/importer
 
4
  * @version 1.0.0
5
  */
6
 
7
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
8
  ?>
9
 
10
  <div class="pwb-brands-exporter pwb-clearfix">
11
- <button class="button pwb-brands-export"><?php esc_html_e('Export brands', 'perfect-woocommerce-brands');?></button>
12
- <button class="button pwb-brands-import"><?php esc_html_e('Import brands', 'perfect-woocommerce-brands');?></button>
13
- <input type="file" class="pwb-brands-import-file" accept="application/json">
14
- <p><?php _e( 'This tool allows you to export and import the brands between different sites using PWB.', 'perfect-woocommerce-brands' );?></p>
15
  </div>
1
  <?php
2
  /**
3
  * The template for displaying the edit-tags.php exporter/importer
4
+ *
5
  * @version 1.0.0
6
  */
7
 
8
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
9
  ?>
10
 
11
  <div class="pwb-brands-exporter pwb-clearfix">
12
+ <button class="button pwb-brands-export"><?php esc_html_e( 'Export brands', 'perfect-woocommerce-brands' ); ?></button>
13
+ <button class="button pwb-brands-import"><?php esc_html_e( 'Import brands', 'perfect-woocommerce-brands' ); ?></button>
14
+ <input type="file" class="pwb-brands-import-file" accept="application/json">
15
+ <p><?php esc_html_e( 'This tool allows you to export and import the brands between different sites using PWB.', 'perfect-woocommerce-brands' ); ?></p>
16
  </div>
templates/admin/edit-brands-bottom.php CHANGED
@@ -1,16 +1,15 @@
1
  <?php
2
-
3
  /**
4
  * The template for displaying the edit-tags.php table footer
 
5
  * @version 1.0.0
6
  */
7
-
8
- defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
  <div class="pwb-edit-brands-bottom pwb-clearfix">
12
- <span class="dashicons dashicons-admin-collapse"></span>
13
- <p class="pwb-featured-count">
14
- <span><?php echo esc_html($data['featured_count']); ?></span> <?php echo esc_html($data['text_featured']); ?>
15
- </p>
16
- </div>
1
  <?php
 
2
  /**
3
  * The template for displaying the edit-tags.php table footer
4
+ *
5
  * @version 1.0.0
6
  */
7
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
 
8
  ?>
9
 
10
  <div class="pwb-edit-brands-bottom pwb-clearfix">
11
+ <span class="dashicons dashicons-admin-collapse"></span>
12
+ <p class="pwb-featured-count">
13
+ <span><?php echo esc_html( $data['featured_count'] ); ?></span> <?php echo esc_html( $data['text_featured'] ); ?>
14
+ </p>
15
+ </div>
templates/shortcodes/az-listing.php CHANGED
@@ -2,53 +2,37 @@
2
 
3
  /**
4
  * The template for displaying the a-z Listing
 
5
  * @version 1.0.1
6
  */
7
 
8
- defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
- <?php if (!empty($grouped_brands)) : ?>
12
-
13
- <div class="pwb-az-listing">
14
-
15
- <div class="pwb-az-listing-header">
16
-
17
- <ul class="pwb-clearfix">
18
-
19
- <?php foreach ($grouped_brands as $letter => $brand_group) : ?>
20
- <li><a href="#pwb-az-listing-<?php echo esc_attr($letter); ?>"><?php echo esc_html($letter); ?></a></li>
21
- <?php endforeach; ?>
22
-
23
- </ul>
24
-
25
- </div>
26
-
27
- <div class="pwb-az-listing-content">
28
-
29
- <?php foreach ($grouped_brands as $letter => $brand_group) : ?>
30
-
31
- <div id="pwb-az-listing-<?php echo esc_attr($letter); ?>" class="pwb-az-listing-row pwb-clearfix">
32
- <p class="pwb-az-listing-title"><?php echo esc_attr($letter); ?></p>
33
- <div class="pwb-az-listing-row-in">
34
-
35
- <?php foreach ($brand_group as $brand) : ?>
36
-
37
- <div class="pwb-az-listing-col">
38
- <a href="<?php echo get_term_link($brand['brand_term']->term_id); ?>">
39
- <?php echo esc_html($brand['brand_term']->name); ?>
40
- </a>
41
- </div>
42
-
43
- <?php endforeach; ?>
44
-
45
- </div>
46
- </div>
47
-
48
- <?php endforeach; ?>
49
-
50
- </div>
51
-
52
- </div>
53
-
54
- <?php endif; ?>
2
 
3
  /**
4
  * The template for displaying the a-z Listing
5
+ *
6
  * @version 1.0.1
7
  */
8
 
9
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
10
  ?>
11
 
12
+ <?php if ( ! empty( $grouped_brands ) ) : ?>
13
+ <div class="pwb-az-listing">
14
+ <div class="pwb-az-listing-header">
15
+ <ul class="pwb-clearfix">
16
+ <?php foreach ( $grouped_brands as $letter => $brand_group ) : ?>
17
+ <li><a href="#pwb-az-listing-<?php echo esc_attr( $letter ); ?>"><?php echo esc_html( $letter ); ?></a></li>
18
+ <?php endforeach; ?>
19
+ </ul>
20
+ </div>
21
+ <div class="pwb-az-listing-content">
22
+ <?php foreach ( $grouped_brands as $letter => $brand_group ) : ?>
23
+ <div id="pwb-az-listing-<?php echo esc_attr( $letter ); ?>" class="pwb-az-listing-row pwb-clearfix">
24
+ <p class="pwb-az-listing-title"><?php echo esc_attr( $letter ); ?></p>
25
+ <div class="pwb-az-listing-row-in">
26
+ <?php foreach ( $brand_group as $brand ) : ?>
27
+ <div class="pwb-az-listing-col">
28
+ <a href="<?php echo esc_url( get_term_link( $brand['brand_term']->term_id ) ); ?>">
29
+ <?php echo esc_html( $brand['brand_term']->name ); ?>
30
+ </a>
31
+ </div>
32
+ <?php endforeach; ?>
33
+ </div>
34
+ </div>
35
+ <?php endforeach; ?>
36
+ </div>
37
+ </div>
38
+ <?php endif; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
templates/shortcodes/brand.php CHANGED
@@ -2,34 +2,35 @@
2
 
3
  /**
4
  * The template for displaying the "pwb-brand" shortcode
 
5
  * @version 1.0.0
6
  */
7
 
8
- defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
- <?php if (!empty($brands)) : ?>
12
 
13
- <div class="pwb-brand-shortcode">
14
 
15
- <?php foreach ($brands as $brand) : ?>
16
 
17
- <a href="<?php echo esc_url($brand->term_link); ?>" title="<?php _e('View brand', 'perfect-woocommerce-brands'); ?>">
18
 
19
- <?php if (!$as_link && !empty($brand->image)) : ?>
20
 
21
- <?php echo wp_kses_post($brand->image); ?>
22
 
23
- <?php else : ?>
24
 
25
- <?php echo esc_html($brand->name); ?>
26
 
27
- <?php endif; ?>
28
 
29
- </a>
30
 
31
- <?php endforeach; ?>
32
 
33
- </div>
34
 
35
- <?php endif; ?>
2
 
3
  /**
4
  * The template for displaying the "pwb-brand" shortcode
5
+ *
6
  * @version 1.0.0
7
  */
8
 
9
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
10
  ?>
11
 
12
+ <?php if ( ! empty( $brands ) ) : ?>
13
 
14
+ <div class="pwb-brand-shortcode">
15
 
16
+ <?php foreach ( $brands as $brand ) : ?>
17
 
18
+ <a href="<?php echo esc_url( $brand->term_link ); ?>" title="<?php esc_html_e( 'View brand', 'perfect-woocommerce-brands' ); ?>">
19
 
20
+ <?php if ( ! $as_link && ! empty( $brand->image ) ) : ?>
21
 
22
+ <?php echo wp_kses_post( $brand->image ); ?>
23
 
24
+ <?php else : ?>
25
 
26
+ <?php echo esc_html( $brand->name ); ?>
27
 
28
+ <?php endif; ?>
29
 
30
+ </a>
31
 
32
+ <?php endforeach; ?>
33
 
34
+ </div>
35
 
36
+ <?php endif; ?>
templates/shortcodes/carousel.php CHANGED
@@ -2,22 +2,20 @@
2
 
3
  /**
4
  * The template for displaying the carousels
 
5
  * @version 1.0.0
6
  */
7
 
8
- defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
- <div class="pwb-carousel" data-slick="<?php echo $slick_settings; ?>">
12
-
13
- <?php foreach ($brands as $brand) : ?>
14
- <div class="pwb-slick-slide">
15
- <a href="<?php echo esc_url($brand['link']); ?>" title="<?php echo esc_html($brand['name']); ?>">
16
- <?php echo wp_kses_post($brand['attachment_html']); ?>
17
- </a>
18
- </div>
19
- <?php endforeach; ?>
20
-
21
- <div class="pwb-carousel-loader"><?php esc_html_e('Loading', 'perfect-woocommerce-brands'); ?>...</div>
22
-
23
- </div>
2
 
3
  /**
4
  * The template for displaying the carousels
5
+ *
6
  * @version 1.0.0
7
  */
8
 
9
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
10
  ?>
11
 
12
+ <div class="pwb-carousel" data-slick="<?php echo $slick_settings; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>">
13
+ <?php foreach ( $brands as $brand ) : ?>
14
+ <div class="pwb-slick-slide">
15
+ <a href="<?php echo esc_url( $brand['link'] ); ?>" title="<?php echo esc_html( $brand['name'] ); ?>">
16
+ <?php echo wp_kses_post( $brand['attachment_html'] ); ?>
17
+ </a>
18
+ </div>
19
+ <?php endforeach; ?>
20
+ <div class="pwb-carousel-loader"><?php esc_html_e( 'Loading', 'perfect-woocommerce-brands' ); ?>...</div>
21
+ </div>
 
 
 
templates/shortcodes/product-carousel.php CHANGED
@@ -2,32 +2,26 @@
2
 
3
  /**
4
  * The template for displaying the product carousels
 
5
  * @version 1.0.0
6
  */
7
 
8
- defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
- <?php if (!empty($products)) : ?>
12
-
13
- <div class="pwb-product-carousel" data-slick="<?php echo $slick_settings; ?>">
14
-
15
- <?php foreach ($products as $product) : ?>
16
- <div class="pwb-slick-slide">
17
- <a href="<?php echo esc_url($product['permalink']); ?>">
18
- <?php echo wp_kses_post($product['thumbnail']); ?>
19
- <h3><?php echo esc_html($product['title']); ?></h3>
20
- <?php echo do_shortcode('[add_to_cart id="' . esc_attr($product['id']) . '" style=""]'); ?>
21
- </a>
22
- </div>
23
- <?php endforeach; ?>
24
-
25
- <div class="pwb-carousel-loader"><?php esc_html_e('Loading', 'perfect-woocommerce-brands'); ?>...</div>
26
-
27
- </div>
28
-
29
  <?php else : ?>
30
-
31
- <div><?php esc_html_e('Nothing found'); ?></div>
32
-
33
- <?php endif; ?>
2
 
3
  /**
4
  * The template for displaying the product carousels
5
+ *
6
  * @version 1.0.0
7
  */
8
 
9
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
10
  ?>
11
 
12
+ <?php if ( ! empty( $products ) ) : ?>
13
+ <div class="pwb-product-carousel" data-slick="<?php echo $slick_settings; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>">
14
+ <?php foreach ( $products as $product ) : ?>
15
+ <div class="pwb-slick-slide">
16
+ <a href="<?php echo esc_url( $product['permalink'] ); ?>">
17
+ <?php echo wp_kses_post( $product['thumbnail'] ); ?>
18
+ <h3><?php echo esc_html( $product['title'] ); ?></h3>
19
+ <?php echo do_shortcode( '[add_to_cart id="' . esc_attr( $product['id'] ) . '" style=""]' ); ?>
20
+ </a>
21
+ </div>
22
+ <?php endforeach; ?>
23
+ <div class="pwb-carousel-loader"><?php esc_html_e( 'Loading', 'perfect-woocommerce-brands' ); ?>...</div>
24
+ </div>
 
 
 
 
 
25
  <?php else : ?>
26
+ <div><?php esc_html_e( 'Nothing found' ); ?></div>
27
+ <?php endif; ?>
 
 
templates/widgets/dropdown.php CHANGED
@@ -2,19 +2,20 @@
2
 
3
  /**
4
  * The template for displaying the dropdown widget
 
5
  * @version 1.0.0
6
  */
7
 
8
- defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
  <select class="pwb-dropdown-widget">
12
- <option selected="true" disabled="disabled">
13
- <?php echo apply_filters('pwb_dropdown_placeholder', __('Brands', 'perfect-woocommerce-brands')); ?>
14
- </option>
15
- <?php foreach ($brands as $brand) : ?>
16
- <option value="<?php echo esc_url($brand->get('link')); ?>" <?php selected($data['selected'], $brand->get('id')); ?>>
17
- <?php echo esc_html($brand->get('name')); ?>
18
- </option>
19
- <?php endforeach; ?>
20
- </select>
2
 
3
  /**
4
  * The template for displaying the dropdown widget
5
+ *
6
  * @version 1.0.0
7
  */
8
 
9
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
10
  ?>
11
 
12
  <select class="pwb-dropdown-widget">
13
+ <option selected="true" disabled="disabled">
14
+ <?php echo esc_html( apply_filters( 'pwb_dropdown_placeholder', __( 'Brands', 'perfect-woocommerce-brands' ) ) ); ?>
15
+ </option>
16
+ <?php foreach ( $brands as $brand ) : ?>
17
+ <option value="<?php echo esc_url( $brand->get( 'link' ) ); ?>" <?php selected( $data['selected'], $brand->get( 'id' ) ); ?>>
18
+ <?php echo esc_html( $brand->get( 'name' ) ); ?>
19
+ </option>
20
+ <?php endforeach; ?>
21
+ </select>
templates/widgets/filter-by-brand.php CHANGED
@@ -2,26 +2,32 @@
2
 
3
  /**
4
  * The template for displaying filter by brand widget
 
5
  * @version 1.0.0
6
  */
7
 
8
- defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
- <div class="pwb-filter-products<?php if ($hide_submit_btn) echo ' pwb-hide-submit-btn'; ?>" data-cat-url="<?php echo esc_url($cate_url); ?>">
12
- <ul>
13
- <?php foreach ($brands as $brand) : ?>
14
- <li>
15
- <label>
16
- <input type="checkbox" data-brand="<?php echo esc_attr($brand->term_id); ?>" value="<?php echo esc_html($brand->slug); ?>"><?php echo esc_html($brand->name); ?>
17
- </label>
18
- </li>
19
- <?php endforeach; ?>
20
- </ul>
21
- <?php if (!$hide_submit_btn) : ?>
22
- <button class="pwb-apply-filter"><?php esc_html_e('Apply filter', 'perfect-woocommerce-brands') ?></button>
23
- <?php endif; ?>
24
- <?php if (!$hide_submit_btn && !empty($_GET['pwb-brand-filter'])) : ?>
25
- <button class="pwb-remove-filter"><?php esc_html_e('Remove filter', 'perfect-woocommerce-brands') ?></button>
26
- <?php endif; ?>
27
- </div>
 
 
 
 
 
2
 
3
  /**
4
  * The template for displaying filter by brand widget
5
+ *
6
  * @version 1.0.0
7
  */
8
 
9
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
10
  ?>
11
 
12
+ <div class="pwb-filter-products
13
+ <?php
14
+ if ( $hide_submit_btn ) {
15
+ echo ' pwb-hide-submit-btn';}
16
+ ?>
17
+ " data-cat-url="<?php echo esc_url( $cate_url ); ?>">
18
+ <ul>
19
+ <?php foreach ( $brands as $brand ) : ?>
20
+ <li>
21
+ <label>
22
+ <input type="checkbox" data-brand="<?php echo esc_attr( $brand->term_id ); ?>" value="<?php echo esc_html( $brand->slug ); ?>"><?php echo esc_html( $brand->name ); ?>
23
+ </label>
24
+ </li>
25
+ <?php endforeach; ?>
26
+ </ul>
27
+ <?php if ( ! $hide_submit_btn ) : ?>
28
+ <button class="pwb-apply-filter"><?php esc_html_e( 'Apply filter', 'perfect-woocommerce-brands' ); ?></button>
29
+ <?php endif; ?>
30
+ <?php if ( ! $hide_submit_btn && ! empty( $_GET['pwb-brand-filter'] ) ) : ?>
31
+ <button class="pwb-remove-filter"><?php esc_html_e( 'Remove filter', 'perfect-woocommerce-brands' ); ?></button>
32
+ <?php endif; ?>
33
+ </div>
templates/widgets/list-logo.php CHANGED
@@ -2,28 +2,21 @@
2
 
3
  /**
4
  * The template for displaying the list logo widget
 
5
  * @version 1.0.0
6
  */
7
 
8
- defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
  <ul class="pwb-row">
12
-
13
- <?php foreach ($data['brands'] as $brand) : ?>
14
-
15
- <li class="<?php echo esc_attr($data['li_class']); ?>">
16
-
17
- <a href="<?php echo esc_url($brand->get('link')); ?>" title="<?php echo esc_html($data['title_prefix'] . ' ' . $brand->get('name')); ?>">
18
-
19
- <?php if (!empty(html_entity_decode($brand->get('image')))) : ?>
20
- <?php echo html_entity_decode($brand->get('image')); ?>
21
- <?php endif; ?>
22
-
23
- </a>
24
-
25
- </li>
26
-
27
- <?php endforeach; ?>
28
-
29
- </ul>
2
 
3
  /**
4
  * The template for displaying the list logo widget
5
+ *
6
  * @version 1.0.0
7
  */
8
 
9
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
10
  ?>
11
 
12
  <ul class="pwb-row">
13
+ <?php foreach ( $data['brands'] as $brand ) : ?>
14
+ <li class="<?php echo esc_attr( $data['li_class'] ); ?>">
15
+ <a href="<?php echo esc_url( $brand->get( 'link' ) ); ?>" title="<?php echo esc_html( $data['title_prefix'] . ' ' . $brand->get( 'name' ) ); ?>">
16
+ <?php if ( ! empty( html_entity_decode( $brand->get( 'image' ) ) ) ) : ?>
17
+ <?php echo wp_kses_post( html_entity_decode( $brand->get( 'image' ) ) ); ?>
18
+ <?php endif; ?>
19
+ </a>
20
+ </li>
21
+ <?php endforeach; ?>
22
+ </ul>
 
 
 
 
 
 
 
 
templates/widgets/list.php CHANGED
@@ -2,22 +2,19 @@
2
 
3
  /**
4
  * The template for displaying the list widget
 
5
  * @version 1.0.0
6
  */
7
 
8
- defined('ABSPATH') or die('No script kiddies please!');
9
  ?>
10
 
11
  <ul class="pwb-row">
12
-
13
- <?php foreach ($data['brands'] as $brand) : ?>
14
-
15
- <li>
16
- <a href="<?php echo esc_html($brand->get('link')); ?>" title="<?php echo esc_html($data['title_prefix'] . ' ' . $brand->get('name')); ?>">
17
- <?php echo esc_html($brand->get('name')); ?>
18
- </a>
19
- </li>
20
-
21
- <?php endforeach; ?>
22
-
23
- </ul>
2
 
3
  /**
4
  * The template for displaying the list widget
5
+ *
6
  * @version 1.0.0
7
  */
8
 
9
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
10
  ?>
11
 
12
  <ul class="pwb-row">
13
+ <?php foreach ( $data['brands'] as $brand ) : ?>
14
+ <li>
15
+ <a href="<?php echo esc_html( $brand->get( 'link' ) ); ?>" title="<?php echo esc_html( $data['title_prefix'] . ' ' . $brand->get( 'name' ) ); ?>">
16
+ <?php echo esc_html( $brand->get( 'name' ) ); ?>
17
+ </a>
18
+ </li>
19
+ <?php endforeach; ?>
20
+ </ul>
 
 
 
 
uninstall.php CHANGED
@@ -1,20 +1,20 @@
1
  <?php
2
- namespace Perfect_Woocommerce_Brands;
3
 
4
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
5
 
6
- delete_option('wc_pwb_admin_tab_section_title');
7
- delete_option('wc_pwb_admin_tab_slug');
8
- delete_option('wc_pwb_admin_tab_brand_logo_size');
9
- delete_option('wc_pwb_admin_tab_brand_single_position');
10
- delete_option('wc_pwb_admin_tab_brand_single_product_tab');
11
- delete_option('wc_pwb_admin_tab_brand_desc');
12
- delete_option('wc_pwb_admin_tab_section_end');
13
- delete_option('wc_pwb_notice_plugin_review');
14
 
15
- //remove exported brands if exists
16
- unlink( WP_CONTENT_DIR . '/uploads/pwb-export.json' );
17
 
18
- //update permalinks and clean cache
19
- flush_rewrite_rules();
20
- wp_cache_flush();
1
  <?php
2
+ namespace Perfect_Woocommerce_Brands;
3
 
4
+ defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
5
 
6
+ delete_option( 'wc_pwb_admin_tab_section_title' );
7
+ delete_option( 'wc_pwb_admin_tab_slug' );
8
+ delete_option( 'wc_pwb_admin_tab_brand_logo_size' );
9
+ delete_option( 'wc_pwb_admin_tab_brand_single_position' );
10
+ delete_option( 'wc_pwb_admin_tab_brand_single_product_tab' );
11
+ delete_option( 'wc_pwb_admin_tab_brand_desc' );
12
+ delete_option( 'wc_pwb_admin_tab_section_end' );
13
+ delete_option( 'wc_pwb_notice_plugin_review' );
14
 
15
+ // remove exported brands if exists
16
+ unlink( WP_CONTENT_DIR . '/uploads/pwb-export.json' );
17
 
18
+ // update permalinks and clean cache
19
+ flush_rewrite_rules();
20
+ wp_cache_flush();