Perfect Brands for WooCommerce - Version 1.8.0

Version Description

  • Enhancement: Main file renamed according to WordPress standards
  • Enhancement: "Show only first level brands" option added for the filter by brand widget
Download this release

Release Info

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

Code changes from version 1.7.9 to 1.8.0

classes/admin/class-pwb-dummy-data.php CHANGED
@@ -64,7 +64,7 @@
64
  for( $i=1; $i<11; $i++ ) {
65
  $term_desc = $this->build_description();
66
  $brand_name = 'brand'.$i;
67
- $attachment_id = self::upload_image( false, PWB_PLUGIN . '/assets/img/dummy-data/'.$brand_name.'.png' );
68
  $inserted_brand = wp_insert_term( ucfirst( $brand_name ), 'pwb-brand', array( "description" => $term_desc ) );
69
  if( !is_wp_error( $inserted_brand ) && isset( $inserted_brand['term_id'] ) ){
70
  add_term_meta( $inserted_brand['term_id'], 'pwb_brand_image', $attachment_id );
64
  for( $i=1; $i<11; $i++ ) {
65
  $term_desc = $this->build_description();
66
  $brand_name = 'brand'.$i;
67
+ $attachment_id = self::upload_image( false, PWB_PLUGIN_URL . '/assets/img/dummy-data/'.$brand_name.'.png' );
68
  $inserted_brand = wp_insert_term( ucfirst( $brand_name ), 'pwb-brand', array( "description" => $term_desc ) );
69
  if( !is_wp_error( $inserted_brand ) && isset( $inserted_brand['term_id'] ) ){
70
  add_term_meta( $inserted_brand['term_id'], 'pwb_brand_image', $attachment_id );
classes/admin/class-pwb-notices.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
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
+ }
classes/class-perfect-woocommerce-brands.php CHANGED
@@ -21,7 +21,6 @@ class Perfect_Woocommerce_Brands{
21
  add_action( 'widgets_init', array( $this, 'register_widgets' ) );
22
  add_filter( 'woocommerce_structured_data_product', array( $this, 'product_microdata' ), 10, 2 );
23
  add_action( 'pre_get_posts', array( $this, 'pwb_brand_filter' ) );
24
- add_filter( 'plugin_action_links_' . PWB_PLUGIN_BASENAME, array( $this, 'plugin_action_links' ) );
25
  add_action( 'wp_ajax_dismiss_pwb_notice', array( $this, 'dismiss_pwb_notice' ) );
26
  add_action( 'admin_notices', array( $this, 'review_notice' ) );
27
 
@@ -182,15 +181,6 @@ class Perfect_Woocommerce_Brands{
182
  wp_die();
183
  }
184
 
185
- /**
186
- * Adds a settings shortcut to plugin´s actions on plugins list
187
- */
188
- public function plugin_action_links( $links ) {
189
- $settings_url = esc_url( admin_url( 'admin.php?page=wc-settings&tab=pwb_admin_tab' ) );
190
- array_unshift( $links, '<a href="'. $settings_url .'">'.__('Settings','perfect-woocommerce-brands').'</a>' );
191
- return $links;
192
- }
193
-
194
  public function pwb_brand_filter( $query ){
195
 
196
  if( !empty( $_GET['pwb-brand-filter'] ) ){
@@ -406,7 +396,7 @@ class Perfect_Woocommerce_Brands{
406
  "description" => __( "Product carousel by brand or by category", "perfect-woocommerce-brands" ),
407
  "base" => "pwb-product-carousel",
408
  "class" => "",
409
- "icon" => PWB_PLUGIN.'/assets/img/icon_pwb.jpg',
410
  "category" => "WooCommerce",
411
  "params" => array(
412
  array(
@@ -462,7 +452,7 @@ class Perfect_Woocommerce_Brands{
462
  "description" => __( "Brands carousel", "perfect-woocommerce-brands" ),
463
  "base" => "pwb-carousel",
464
  "class" => "",
465
- "icon" => PWB_PLUGIN.'/assets/img/icon_pwb.jpg',
466
  "category" => "WooCommerce",
467
  "params" => array(
468
  array(
@@ -520,7 +510,7 @@ class Perfect_Woocommerce_Brands{
520
  "description" => __( "Show all brands", "perfect-woocommerce-brands" ),
521
  "base" => "pwb-all-brands",
522
  "class" => "",
523
- "icon" => PWB_PLUGIN.'/assets/img/icon_pwb.jpg',
524
  "category" => "WooCommerce",
525
  "params" => array(
526
  array(
@@ -590,7 +580,7 @@ class Perfect_Woocommerce_Brands{
590
  "description" => __( "AZ Listing for brands", "perfect-woocommerce-brands" ),
591
  "base" => "pwb-az-listing",
592
  "class" => "",
593
- "icon" => PWB_PLUGIN.'/assets/img/icon_pwb.jpg',
594
  "category" => "WooCommerce",
595
  "params" => array(
596
  array(
@@ -608,7 +598,7 @@ class Perfect_Woocommerce_Brands{
608
  "description" => __( "Show brand for a specific product", "perfect-woocommerce-brands" ),
609
  "base" => "pwb-brand",
610
  "class" => "",
611
- "icon" => PWB_PLUGIN.'/assets/img/icon_pwb.jpg',
612
  "category" => "WooCommerce",
613
 
614
  "params" => array(
@@ -690,7 +680,7 @@ class Perfect_Woocommerce_Brands{
690
 
691
  wp_register_script(
692
  'pwb-lib-slick',
693
- PWB_PLUGIN . '/assets/lib/slick/slick.min.js',
694
  array('jquery'),
695
  '1.8.0',
696
  true
@@ -698,7 +688,7 @@ class Perfect_Woocommerce_Brands{
698
 
699
  wp_register_style(
700
  'pwb-lib-slick',
701
- PWB_PLUGIN . '/assets/lib/slick/slick.css',
702
  array(),
703
  '1.8.0',
704
  'all'
@@ -706,7 +696,7 @@ class Perfect_Woocommerce_Brands{
706
 
707
  wp_enqueue_style(
708
  'pwb-styles-frontend',
709
- PWB_PLUGIN . '/assets/css/styles-frontend.min.css',
710
  array(),
711
  PWB_PLUGIN_VERSION,
712
  'all'
@@ -714,7 +704,7 @@ class Perfect_Woocommerce_Brands{
714
 
715
  wp_register_script(
716
  'pwb-functions-frontend',
717
- PWB_PLUGIN . '/assets/js/functions-frontend.min.js',
718
  array('jquery'),
719
  PWB_PLUGIN_VERSION,
720
  true
@@ -735,9 +725,9 @@ class Perfect_Woocommerce_Brands{
735
  wp_enqueue_media();
736
  }
737
 
738
- wp_enqueue_style('pwb-styles-admin', PWB_PLUGIN . '/assets/css/styles-admin.min.css', array(), PWB_PLUGIN_VERSION);
739
 
740
- wp_register_script('pwb-functions-admin', PWB_PLUGIN . '/assets/js/functions-admin.min.js', array('jquery'), PWB_PLUGIN_VERSION, true);
741
  wp_localize_script( 'pwb-functions-admin', 'pwb_ajax_object_admin', array(
742
  'ajax_url' => admin_url( 'admin-ajax.php' ),
743
  'site_url' => site_url(),
21
  add_action( 'widgets_init', array( $this, 'register_widgets' ) );
22
  add_filter( 'woocommerce_structured_data_product', array( $this, 'product_microdata' ), 10, 2 );
23
  add_action( 'pre_get_posts', array( $this, 'pwb_brand_filter' ) );
 
24
  add_action( 'wp_ajax_dismiss_pwb_notice', array( $this, 'dismiss_pwb_notice' ) );
25
  add_action( 'admin_notices', array( $this, 'review_notice' ) );
26
 
181
  wp_die();
182
  }
183
 
 
 
 
 
 
 
 
 
 
184
  public function pwb_brand_filter( $query ){
185
 
186
  if( !empty( $_GET['pwb-brand-filter'] ) ){
396
  "description" => __( "Product carousel by brand or by category", "perfect-woocommerce-brands" ),
397
  "base" => "pwb-product-carousel",
398
  "class" => "",
399
+ "icon" => PWB_PLUGIN_URL .'/assets/img/icon_pwb.jpg',
400
  "category" => "WooCommerce",
401
  "params" => array(
402
  array(
452
  "description" => __( "Brands carousel", "perfect-woocommerce-brands" ),
453
  "base" => "pwb-carousel",
454
  "class" => "",
455
+ "icon" => PWB_PLUGIN_URL .'/assets/img/icon_pwb.jpg',
456
  "category" => "WooCommerce",
457
  "params" => array(
458
  array(
510
  "description" => __( "Show all brands", "perfect-woocommerce-brands" ),
511
  "base" => "pwb-all-brands",
512
  "class" => "",
513
+ "icon" => PWB_PLUGIN_URL .'/assets/img/icon_pwb.jpg',
514
  "category" => "WooCommerce",
515
  "params" => array(
516
  array(
580
  "description" => __( "AZ Listing for brands", "perfect-woocommerce-brands" ),
581
  "base" => "pwb-az-listing",
582
  "class" => "",
583
+ "icon" => PWB_PLUGIN_URL .'/assets/img/icon_pwb.jpg',
584
  "category" => "WooCommerce",
585
  "params" => array(
586
  array(
598
  "description" => __( "Show brand for a specific product", "perfect-woocommerce-brands" ),
599
  "base" => "pwb-brand",
600
  "class" => "",
601
+ "icon" => PWB_PLUGIN_URL .'/assets/img/icon_pwb.jpg',
602
  "category" => "WooCommerce",
603
 
604
  "params" => array(
680
 
681
  wp_register_script(
682
  'pwb-lib-slick',
683
+ PWB_PLUGIN_URL . '/assets/lib/slick/slick.min.js',
684
  array('jquery'),
685
  '1.8.0',
686
  true
688
 
689
  wp_register_style(
690
  'pwb-lib-slick',
691
+ PWB_PLUGIN_URL . '/assets/lib/slick/slick.css',
692
  array(),
693
  '1.8.0',
694
  'all'
696
 
697
  wp_enqueue_style(
698
  'pwb-styles-frontend',
699
+ PWB_PLUGIN_URL . '/assets/css/styles-frontend.min.css',
700
  array(),
701
  PWB_PLUGIN_VERSION,
702
  'all'
704
 
705
  wp_register_script(
706
  'pwb-functions-frontend',
707
+ PWB_PLUGIN_URL . '/assets/js/functions-frontend.min.js',
708
  array('jquery'),
709
  PWB_PLUGIN_VERSION,
710
  true
725
  wp_enqueue_media();
726
  }
727
 
728
+ wp_enqueue_style('pwb-styles-admin', PWB_PLUGIN_URL . '/assets/css/styles-admin.min.css', array(), PWB_PLUGIN_VERSION);
729
 
730
+ wp_register_script('pwb-functions-admin', PWB_PLUGIN_URL . '/assets/js/functions-admin.min.js', array('jquery'), PWB_PLUGIN_VERSION, true);
731
  wp_localize_script( 'pwb-functions-admin', 'pwb_ajax_object_admin', array(
732
  'ajax_url' => admin_url( 'admin-ajax.php' ),
733
  'site_url' => site_url(),
classes/shortcodes/class-pwb-all-brands.php CHANGED
@@ -62,7 +62,7 @@ class PWB_All_Brands_Shortcode{
62
  'tax_query' => array(
63
  array(
64
  'taxonomy' => 'pwb-brand',
65
- 'field' => 'ID',
66
  'terms' => $brand_id
67
  ),
68
  array(
62
  'tax_query' => array(
63
  array(
64
  'taxonomy' => 'pwb-brand',
65
+ 'field' => 'term_id',
66
  'terms' => $brand_id
67
  ),
68
  array(
classes/widgets/class-pwb-filter-by-brand.php CHANGED
@@ -19,19 +19,23 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
19
 
20
  $title = ( isset( $instance[ 'title' ] ) ) ? $instance[ 'title' ] : __('Brands', 'perfect-woocommerce-brands');
21
  $limit = ( isset( $instance[ 'limit' ] ) ) ? $instance[ 'limit' ] : 20;
22
- $hide_submit_btn = ( isset( $hide_submit_btn ) && $hide_submit_btn == 'on' ) ? true : false;
 
23
  ?>
24
- <p>
 
25
  <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
26
  <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
27
  </p>
28
- <p>
 
29
  <label for="<?php echo $this->get_field_id( 'limit' ); ?>">
30
  <?php echo __( 'Max number of brands', 'perfect-woocommerce-brands' );?>
31
  </label>
32
  <input class="widefat" id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" />
33
  </p>
34
- <p>
 
35
  <input
36
  type="checkbox"
37
  id="<?php echo esc_attr( $this->get_field_id('hide_submit_btn') ); ?>"
@@ -41,6 +45,18 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
41
  <?php echo __( 'Hide filter button', 'perfect-woocommerce-brands' );?>
42
  </label>
43
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
44
  <?php
45
  }
46
 
@@ -52,6 +68,7 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
52
  $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : '';
53
  $instance['limit'] = ( $limit != false ) ? $limit : $old_instance['limit'];
54
  $instance['hide_submit_btn'] = ( isset( $new_instance['hide_submit_btn'] ) ) ? $new_instance['hide_submit_btn'] : '';
 
55
  return $instance;
56
  }
57
 
@@ -62,6 +79,7 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
62
  if( !is_tax('pwb-brand') && !is_product() ){
63
 
64
  $hide_submit_btn = ( isset( $hide_submit_btn ) && $hide_submit_btn == 'on' ) ? true : false;
 
65
 
66
  $show_widget = true;
67
  $current_products = false;
@@ -78,7 +96,7 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
78
 
79
  echo $args['before_widget'];
80
  if ( ! empty( $title ) ) echo $args['before_title'] . $title . $args['after_title'];
81
- $this->render_widget( $current_products, $limit, $hide_submit_btn );
82
  echo $args['after_widget'];
83
  }
84
 
@@ -86,13 +104,19 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
86
 
87
  }
88
 
89
- public function render_widget( $current_products, $limit, $hide_submit_btn ){
90
 
91
  $result_brands = array();
92
 
93
- if( is_product_taxonomy() || is_shop() ){
 
 
 
94
 
95
- if( !empty( $current_products ) ) $result_brands = $this->get_products_brands( $current_products );
 
 
 
96
 
97
  if( is_shop() ){
98
  $cate_url = get_permalink( wc_get_page_id( 'shop' ) );
@@ -113,10 +137,10 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
113
  global $wp;
114
  $current_url = home_url(add_query_arg(array(),$wp->request));
115
 
116
- if( !empty( $result_brands ) ){
117
 
118
  $result_brands_ordered = array();
119
- foreach( $result_brands as $brand ){
120
  $brand = get_term($brand);
121
  $result_brands_ordered[$brand->name] = $brand;
122
  }
@@ -135,7 +159,32 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
135
 
136
  }
137
 
138
- private function current_products_query(){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
  $args = array(
141
  'posts_per_page' => -1,
@@ -146,7 +195,7 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
146
  'operator' => 'EXISTS'
147
  )
148
  ),
149
- 'fields' => 'ids'
150
  );
151
 
152
  $cat = get_queried_object();
@@ -173,24 +222,25 @@ class PWB_Filter_By_Brand_Widget extends \WP_Widget {
173
 
174
  $wp_query = new WP_Query($args);
175
  wp_reset_postdata();
 
176
  return $wp_query->posts;
177
 
178
  }
179
 
180
- private function get_products_brands( $product_ids ){
181
 
182
  $product_ids = implode(',', array_map('intval', $product_ids) );
183
 
184
  global $wpdb;
 
185
  $brand_ids = $wpdb->get_col( "SELECT DISTINCT t.term_id
186
  FROM {$wpdb->prefix}terms AS t
187
  INNER JOIN {$wpdb->prefix}term_taxonomy AS tt
188
  ON t.term_id = tt.term_id
189
  INNER JOIN {$wpdb->prefix}term_relationships AS tr
190
  ON tr.term_taxonomy_id = tt.term_taxonomy_id
191
- WHERE tt.taxonomy IN ('pwb-brand')
192
  AND tr.object_id IN ($product_ids)
193
- ORDER BY t.name ASC
194
  " );
195
 
196
  return ( $brand_ids ) ? $brand_ids : false;
19
 
20
  $title = ( isset( $instance[ 'title' ] ) ) ? $instance[ 'title' ] : __('Brands', 'perfect-woocommerce-brands');
21
  $limit = ( isset( $instance[ 'limit' ] ) ) ? $instance[ 'limit' ] : 20;
22
+ $hide_submit_btn = ( isset( $hide_submit_btn ) && $hide_submit_btn == 'on' ) ? true : false;
23
+ $only_first_level_brands = ( isset( $only_first_level_brands ) && $only_first_level_brands == 'on' ) ? true : false;
24
  ?>
25
+
26
+ <p>
27
  <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
28
  <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
29
  </p>
30
+
31
+ <p>
32
  <label for="<?php echo $this->get_field_id( 'limit' ); ?>">
33
  <?php echo __( 'Max number of brands', 'perfect-woocommerce-brands' );?>
34
  </label>
35
  <input class="widefat" id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" />
36
  </p>
37
+
38
+ <p>
39
  <input
40
  type="checkbox"
41
  id="<?php echo esc_attr( $this->get_field_id('hide_submit_btn') ); ?>"
45
  <?php echo __( 'Hide filter button', 'perfect-woocommerce-brands' );?>
46
  </label>
47
  </p>
48
+
49
+ <p>
50
+ <input
51
+ type="checkbox"
52
+ id="<?php echo esc_attr( $this->get_field_id('only_first_level_brands') ); ?>"
53
+ name="<?php echo esc_attr( $this->get_field_name('only_first_level_brands') ); ?>"
54
+ <?php checked( $only_first_level_brands ); ?>>
55
+ <label for="<?php echo esc_attr( $this->get_field_id('only_first_level_brands') ); ?>">
56
+ <?php echo __( 'Show only first level brands', 'perfect-woocommerce-brands' );?>
57
+ </label>
58
+ </p>
59
+
60
  <?php
61
  }
62
 
68
  $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : '';
69
  $instance['limit'] = ( $limit != false ) ? $limit : $old_instance['limit'];
70
  $instance['hide_submit_btn'] = ( isset( $new_instance['hide_submit_btn'] ) ) ? $new_instance['hide_submit_btn'] : '';
71
+ $instance['only_first_level_brands'] = ( isset( $new_instance['only_first_level_brands'] ) ) ? $new_instance['only_first_level_brands'] : '';
72
  return $instance;
73
  }
74
 
79
  if( !is_tax('pwb-brand') && !is_product() ){
80
 
81
  $hide_submit_btn = ( isset( $hide_submit_btn ) && $hide_submit_btn == 'on' ) ? true : false;
82
+ $only_first_level_brands = ( isset( $only_first_level_brands ) && $only_first_level_brands == 'on' ) ? true : false;
83
 
84
  $show_widget = true;
85
  $current_products = false;
96
 
97
  echo $args['before_widget'];
98
  if ( ! empty( $title ) ) echo $args['before_title'] . $title . $args['after_title'];
99
+ $this->render_widget( $current_products, $limit, $hide_submit_btn, $only_first_level_brands );
100
  echo $args['after_widget'];
101
  }
102
 
104
 
105
  }
106
 
107
+ public function render_widget( $current_products, $limit, $hide_submit_btn, $only_first_level_brands ) {
108
 
109
  $result_brands = array();
110
 
111
+ if ( is_product_taxonomy() || is_shop() ) {
112
+
113
+ //obtains brands ids
114
+ if ( ! empty( $current_products ) ) $result_brands = $this->get_products_brands( $current_products );
115
 
116
+ //excludes the child brands if needed
117
+ if ( $only_first_level_brands ) {
118
+ $result_brands = $this->exclude_child_brands( $result_brands );
119
+ }
120
 
121
  if( is_shop() ){
122
  $cate_url = get_permalink( wc_get_page_id( 'shop' ) );
137
  global $wp;
138
  $current_url = home_url(add_query_arg(array(),$wp->request));
139
 
140
+ if ( ! empty( $result_brands ) ) {
141
 
142
  $result_brands_ordered = array();
143
+ foreach ( $result_brands as $brand ) {
144
  $brand = get_term($brand);
145
  $result_brands_ordered[$brand->name] = $brand;
146
  }
159
 
160
  }
161
 
162
+ private function exclude_child_brands( $brands ) {
163
+
164
+ //gets parent for all brands
165
+ foreach ( $brands as $brand_key => $brand ) {
166
+
167
+ $brand_o = get_term( $brand, 'pwb-brand' );
168
+
169
+ if ( $brand_o->parent ) {
170
+
171
+ //exclude this child brand and include the parent
172
+ unset( $brands[$brand_key] );
173
+ if ( ! in_array( $brand_o->parent, $brands ) ) $brands[$brand_key] = $brand_o->parent;
174
+
175
+ }
176
+
177
+ }
178
+
179
+ //reset keys
180
+ $brands = array_values( $brands );
181
+
182
+
183
+ return $brands;
184
+
185
+ }
186
+
187
+ private function current_products_query() {
188
 
189
  $args = array(
190
  'posts_per_page' => -1,
195
  'operator' => 'EXISTS'
196
  )
197
  ),
198
+ 'fields' => 'ids',
199
  );
200
 
201
  $cat = get_queried_object();
222
 
223
  $wp_query = new WP_Query($args);
224
  wp_reset_postdata();
225
+
226
  return $wp_query->posts;
227
 
228
  }
229
 
230
+ private function get_products_brands( $product_ids ) {
231
 
232
  $product_ids = implode(',', array_map('intval', $product_ids) );
233
 
234
  global $wpdb;
235
+
236
  $brand_ids = $wpdb->get_col( "SELECT DISTINCT t.term_id
237
  FROM {$wpdb->prefix}terms AS t
238
  INNER JOIN {$wpdb->prefix}term_taxonomy AS tt
239
  ON t.term_id = tt.term_id
240
  INNER JOIN {$wpdb->prefix}term_relationships AS tr
241
  ON tr.term_taxonomy_id = tt.term_taxonomy_id
242
+ WHERE tt.taxonomy = 'pwb-brand'
243
  AND tr.object_id IN ($product_ids)
 
244
  " );
245
 
246
  return ( $brand_ids ) ? $brand_ids : false;
main.php CHANGED
@@ -1,107 +1,10 @@
1
  <?php
2
- /**
3
- * Plugin Name: Perfect WooCommerce Brands
4
- * Plugin URI: https://wordpress.org/plugins/perfect-woocommerce-brands/
5
- * Description: Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store.
6
- * Version: 1.7.9
7
- * Author: Alberto de Vera Sevilla
8
- * Author URI: https://profiles.wordpress.org/titodevera/
9
- * Text Domain: perfect-woocommerce-brands
10
- * Domain Path: /lang
11
- * License: GPL3
12
- * Perfect WooCommerce Brands version 1.7.9, Copyright (C) 2019 Alberto de Vera Sevilla
13
- * Perfect WooCommerce Brands is free software: you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License as published by
15
- * the Free Software Foundation, either version 3 of the License, or
16
- * (at your option) any later version.
17
- *
18
- * Perfect WooCommerce Brands is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU General Public License for more details.
22
- * You should have received a copy of the GNU General Public License
23
- * along with Perfect WooCommerce Brands. If not, see <http://www.gnu.org/licenses/>.
24
- *
25
- * WC requires at least: 3.1.0
26
- * WC tested up to: 4.0
27
- */
28
 
29
- namespace Perfect_Woocommerce_Brands;
30
-
31
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
32
-
33
- //plugin constants
34
- define( 'PWB_PLUGIN', plugins_url( '', __FILE__ ) );
35
- define( 'PWB_PLUGIN_PATH', plugin_basename( dirname( __FILE__ ) ) );
36
- define( 'PWB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
37
- define( 'PWB_PLUGIN_VERSION', '1.7.9' );
38
- define( 'PWB_WP_VERSION', get_bloginfo( 'version' ) );
39
- define( 'PWB_WC_VERSION', get_option( 'woocommerce_version' ) );
40
-
41
- register_activation_hook( __FILE__, function(){
42
- update_option( 'pwb_activate_on', time() );
43
- } );
44
-
45
- //clean brands slug on plugin deactivation
46
- register_deactivation_hook( __FILE__, function(){
47
- update_option( 'old_wc_pwb_admin_tab_slug', 'null' );
48
- } );
49
-
50
- //loads textdomain for the translations
51
- add_action( 'plugins_loaded', function(){
52
- load_plugin_textdomain( 'perfect-woocommerce-brands', false, PWB_PLUGIN_PATH . '/lang' );
53
- } );
54
-
55
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
56
- if( is_plugin_active( 'woocommerce/woocommerce.php' ) ){
57
-
58
- require 'classes/class-pwb-term.php';
59
- require 'classes/widgets/class-pwb-dropdown.php';
60
- require 'classes/widgets/class-pwb-list.php';
61
- require 'classes/widgets/class-pwb-filter-by-brand.php';
62
- require 'classes/shortcodes/class-pwb-product-carousel.php';
63
- require 'classes/shortcodes/class-pwb-carousel.php';
64
- require 'classes/shortcodes/class-pwb-all-brands.php';
65
- require 'classes/shortcodes/class-pwb-az-listing.php';
66
- require 'classes/shortcodes/class-pwb-brand.php';
67
- require 'classes/class-perfect-woocommerce-brands.php';
68
- require 'classes/class-pwb-api-support.php';
69
- new PWB_API_Support();
70
- require 'classes/admin/class-pwb-coupon.php';
71
- new Admin\PWB_Coupon();
72
-
73
- if( is_admin() ){
74
-
75
- require 'classes/admin/class-pwb-system-status.php';
76
- new Admin\PWB_System_Status();
77
- require 'classes/admin/class-pwb-admin-tab.php';
78
- require 'classes/admin/class-pwb-migrate.php';
79
- new Admin\PWB_Migrate();
80
- require 'classes/admin/class-pwb-dummy-data.php';
81
- new Admin\PWB_Dummy_Data();
82
- require 'classes/admin/class-edit-brands-page.php';
83
- new Admin\Edit_Brands_Page();
84
- require 'classes/admin/class-brands-custom-fields.php';
85
- new Admin\Brands_Custom_Fields();
86
- require 'classes/admin/class-brands-exporter.php';
87
- new Admin\Brands_Exporter();
88
- require 'classes/admin/class-pwb-importer-support.php';
89
- new PWB_Importer_Support();
90
- require 'classes/admin/class-pwb-exporter-support.php';
91
- new PWB_Exporter_Support();
92
-
93
- }else{
94
- include_once 'classes/class-pwb-product-tab.php';
95
- new PWB_Product_Tab();
96
  }
97
-
98
- new \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands();
99
-
100
- }elseif( is_admin() ){
101
-
102
- add_action( 'admin_notices', function() {
103
- $message = __( 'Perfect WooCommerce Brands needs WooCommerce to run. Please, install and active WooCommerce plugin.', 'perfect-woocommerce-brands' );
104
- printf( '<div class="%1$s"><p>%2$s</p></div>', 'notice notice-error', $message );
105
- });
106
-
107
- }
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 ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Plugin Name: Perfect WooCommerce Brands
5
+ * Plugin URI: https://wordpress.org/plugins/perfect-woocommerce-brands/
6
+ * Description: Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store.
7
+ * Version: 1.8.0
8
+ * Author: QuadLayers
9
+ * Author URI: https://quadlayers.com
10
+ * Text Domain: perfect-woocommerce-brands
11
+ * Domain Path: /lang
12
+ * License: GPL3
13
+ * Perfect WooCommerce Brands version 1.8.0, Copyright (C) 2019 QuadLayers
14
+ * Perfect WooCommerce Brands is free software: you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License as published by
16
+ * the Free Software Foundation, either version 3 of the License, or
17
+ * (at your option) any later version.
18
+ *
19
+ * Perfect WooCommerce Brands is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ * GNU General Public License for more details.
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with Perfect WooCommerce Brands. If not, see <http://www.gnu.org/licenses/>.
25
+ *
26
+ * WC requires at least: 3.1.0
27
+ * WC tested up to: 4.0
28
+ */
29
+
30
+ namespace Perfect_Woocommerce_Brands;
31
+
32
+ defined('ABSPATH') or die('No script kiddies please!');
33
+
34
+ //plugin constants
35
+ define('PWB_PLUGIN_URL', plugins_url('', __FILE__));
36
+ define('PWB_PLUGIN_DIR', __DIR__ . DIRECTORY_SEPARATOR);
37
+ define('PWB_PLUGIN_BASENAME', plugin_basename(__FILE__));
38
+ define('PWB_PLUGIN_VERSION', '1.8.0');
39
+ define('PWB_PLUGIN_NAME', 'Perfect WooCommerce Brands');
40
+ define('PWB_REVIEW_URL', 'https://wordpress.org/support/plugin/perfect-woocommerce-brands/reviews/?filter=5#new-post');
41
+ define('PWB_DEMO_URL', 'https://quadlayers.com/portfolio/perfect-woocommerce-brands/?utm_source=pwb_admin');
42
+ define('PWB_PURCHASE_URL', PWB_DEMO_URL);
43
+ define('PWB_SUPPORT_URL', 'https://quadlayers.com/account/support/?utm_source=pwb_admin');
44
+ define('PWB_DOCUMENTATION_URL', 'https://github.com/titodevera/perfect-woocommerce-brands/wiki');
45
+ define('PWB_GROUP_URL', 'https://www.facebook.com/groups/quadlayers');
46
+
47
+ register_activation_hook(__FILE__, function() {
48
+ update_option('pwb_activate_on', time());
49
+ });
50
+
51
+ //clean brands slug on plugin deactivation
52
+ register_deactivation_hook(__FILE__, function() {
53
+ update_option('old_wc_pwb_admin_tab_slug', 'null');
54
+ });
55
+
56
+ //loads textdomain for the translations
57
+ add_action('plugins_loaded', function() {
58
+ load_plugin_textdomain('perfect-woocommerce-brands', false, PWB_PLUGIN_DIR . '/lang');
59
+ });
60
+
61
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
62
+ if (is_plugin_active('woocommerce/woocommerce.php')) {
63
+
64
+ require 'classes/class-pwb-term.php';
65
+ require 'classes/widgets/class-pwb-dropdown.php';
66
+ require 'classes/widgets/class-pwb-list.php';
67
+ require 'classes/widgets/class-pwb-filter-by-brand.php';
68
+ require 'classes/shortcodes/class-pwb-product-carousel.php';
69
+ require 'classes/shortcodes/class-pwb-carousel.php';
70
+ require 'classes/shortcodes/class-pwb-all-brands.php';
71
+ require 'classes/shortcodes/class-pwb-az-listing.php';
72
+ require 'classes/shortcodes/class-pwb-brand.php';
73
+ require 'classes/class-perfect-woocommerce-brands.php';
74
+ require 'classes/class-pwb-api-support.php';
75
+ new PWB_API_Support();
76
+ require 'classes/admin/class-pwb-coupon.php';
77
+ new Admin\PWB_Coupon();
78
+
79
+ if (is_admin()) {
80
+ require 'classes/admin/class-pwb-notices.php';
81
+ new Admin\PWB_Notices();
82
+ require 'classes/admin/class-pwb-system-status.php';
83
+ new Admin\PWB_System_Status();
84
+ require 'classes/admin/class-pwb-admin-tab.php';
85
+ require 'classes/admin/class-pwb-migrate.php';
86
+ new Admin\PWB_Migrate();
87
+ require 'classes/admin/class-pwb-dummy-data.php';
88
+ new Admin\PWB_Dummy_Data();
89
+ require 'classes/admin/class-edit-brands-page.php';
90
+ new Admin\Edit_Brands_Page();
91
+ require 'classes/admin/class-brands-custom-fields.php';
92
+ new Admin\Brands_Custom_Fields();
93
+ require 'classes/admin/class-brands-exporter.php';
94
+ new Admin\Brands_Exporter();
95
+ require 'classes/admin/class-pwb-importer-support.php';
96
+ new PWB_Importer_Support();
97
+ require 'classes/admin/class-pwb-exporter-support.php';
98
+ new PWB_Exporter_Support();
99
+ } else {
100
+ include_once 'classes/class-pwb-product-tab.php';
101
+ new PWB_Product_Tab();
102
+ }
103
+
104
+ new \Perfect_Woocommerce_Brands\Perfect_Woocommerce_Brands();
105
+ } elseif (is_admin()) {
106
+
107
+ add_action('admin_notices', function() {
108
+ $message = __('Perfect WooCommerce Brands needs WooCommerce to run. Please, install and active WooCommerce plugin.', 'perfect-woocommerce-brands');
109
+ printf('<div class="%1$s"><p>%2$s</p></div>', 'notice notice-error', $message);
110
+ });
111
+ }
readme.txt CHANGED
@@ -1,17 +1,20 @@
1
  === Perfect WooCommerce Brands ===
2
- Contributors: quadlayers, titodevera
3
- Donate link: mailto:hola@albertodevera.es
4
- Tags: woocommerce, brands, brand taxonomy, product brands, woocommerce manufacturer, woocommerce supplier, e-commerce
5
  Requires at least: 4.7
6
- Tested up to: 5.3
7
  Requires PHP: 5.6
8
- Stable tag: 1.7.9
9
  License: GPL3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.en.html
11
 
12
  Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store
13
 
14
  == Description ==
 
 
 
15
  Whether we like to admit it or not, we are all influenced by brands. Brands are a guarantee for quality, they assure product recognition in customers.
16
  Is essential to work with product brands for increase sales and generate reliability on your e-commerce site.
17
  With this extension you can add product brands to your WooCommerce site.
@@ -66,7 +69,7 @@ Go to `WooCommerce/Settings/` and click on `Brands` tab
66
  Go to `Settings/Permalinks` and click on `Save Changes` button to flush the permalinks
67
 
68
  = PWB is awesome! Can I contribute? =
69
- Yes you can! Join in on our [GitHub repository](https://github.com/titodevera/perfect-woocommerce-brands) 🙂
70
  You can also contribute [translating the plugin](https://translate.wordpress.org/projects/wp-plugins/perfect-woocommerce-brands/)
71
 
72
  = Developer Documentation =
@@ -81,6 +84,9 @@ You can also contribute [translating the plugin](https://translate.wordpress.org
81
 
82
 
83
  == Changelog ==
 
 
 
84
  = 1.7.9 =
85
  * Fix: Breadcrumbs issues
86
  * Fix: Ajax search plugins conflict since previous release
1
  === Perfect WooCommerce Brands ===
2
+ Contributors: titodevera
3
+ Donate link: https://quadlayers.com
4
+ Tags: woocommerce, woocommerce brands, woocommerce product, woocommerce manufacturer, woocommerce supplier, e-commerce
5
  Requires at least: 4.7
6
+ Tested up to: 5.3.2
7
  Requires PHP: 5.6
8
+ Stable tag: 1.8.0
9
  License: GPL3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.en.html
11
 
12
  Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store
13
 
14
  == Description ==
15
+
16
+ [About Us](https://quadlayers.com/) | [Community](https://www.facebook.com/groups/quadlayers/)
17
+
18
  Whether we like to admit it or not, we are all influenced by brands. Brands are a guarantee for quality, they assure product recognition in customers.
19
  Is essential to work with product brands for increase sales and generate reliability on your e-commerce site.
20
  With this extension you can add product brands to your WooCommerce site.
69
  Go to `Settings/Permalinks` and click on `Save Changes` button to flush the permalinks
70
 
71
  = PWB is awesome! Can I contribute? =
72
+ Yes you can! Join in on our [GitHub repository](https://github.com/quadlayers/perfect-woocommerce-brands) 🙂
73
  You can also contribute [translating the plugin](https://translate.wordpress.org/projects/wp-plugins/perfect-woocommerce-brands/)
74
 
75
  = Developer Documentation =
84
 
85
 
86
  == Changelog ==
87
+ = 1.8.0 =
88
+ * Enhancement: Main file renamed according to WordPress standards
89
+ * Enhancement: "Show only first level brands" option added for the filter by brand widget
90
  = 1.7.9 =
91
  * Fix: Breadcrumbs issues
92
  * Fix: Ajax search plugins conflict since previous release