Perfect Brands for WooCommerce - Version 1.8.5

Version Description

  • Fix: security issues
Download this release

Release Info

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

Code changes from version 1.8.4 to 1.8.5

classes/class-pwb-api-support.php CHANGED
@@ -1,140 +1,159 @@
1
  <?php
2
 
3
  namespace Perfect_Woocommerce_Brands;
 
4
  use WP_Error, WP_REST_Server;
5
 
6
  defined('ABSPATH') or die('No script kiddies please!');
7
 
8
- class PWB_API_Support{
9
-
10
- private $namespaces = array( "wc/v1", "wc/v2", "wc/v3" );
11
- private $base = 'brands';
12
-
13
- function __construct(){
14
- add_action('rest_api_init', array($this, 'register_endpoints'));
15
- add_action('rest_api_init', array($this, 'register_fields'));
16
- }
17
-
18
- /**
19
- * Registers the endpoint for all possible $namespaces
20
- */
21
- public function register_endpoints(){
22
- foreach( $this->namespaces as $namespace ) {
23
- register_rest_route($namespace, '/'.$this->base, array(
24
- array(
25
- 'methods' => WP_REST_Server::READABLE,
26
- 'callback' => function () {
27
- return rest_ensure_response(
28
- Perfect_Woocommerce_Brands::get_brands()
29
- );
30
- }
31
- ),
32
- array(
33
- 'methods' => WP_REST_Server::CREATABLE,
34
- 'callback' => array( $this, 'create_brand' )
35
- ),
36
- array(
37
- 'methods' => WP_REST_Server::DELETABLE,
38
- 'callback' => array( $this, 'delete_brand' )
39
- )
40
- ));
41
- }
42
- }
43
-
44
- public function delete_brand( $request ){
45
- foreach( $request['brands'] as $brand ){
46
- $delete_result = wp_delete_term( $brand, 'pwb-brand' );
47
- if( is_wp_error( $delete_result ) ) return $delete_result;
48
- }
49
- return true;
50
- }
51
-
52
- public function create_brand( $request ){
53
- $new_brand = wp_insert_term( $request['name'], 'pwb-brand', array( 'slug' => $request['slug'], 'description' => $request['description'] ) );
54
- if( !is_wp_error( $new_brand ) ){
55
- return array('id' => $new_brand['term_id'], 'name' => $request['name'], 'slug' => $request['slug'], 'description' => $request['description']);
56
- }else{
57
- return $new_brand;
58
- }
59
- }
60
-
61
- /**
62
- * Entry point for all rest field settings
63
- */
64
- public function register_fields(){
65
- register_rest_field('product', 'brands', array(
66
- 'get_callback' => array($this, "get_callback"),
67
- 'update_callback' => array($this, "update_callback"),
68
- 'schema' => $this->get_schema(),
69
- ));
70
- }
71
-
72
- /**
73
- * Returns the schema of the "brands" field on the /product route
74
- * To attach a brand to a product just append a "brands" key containing an array of brand id's
75
- * An empty array wil detach all brands.
76
- * @return array
77
- */
78
- public function get_schema(){
79
- return array(
80
- 'description' => __('Product brands', 'perfect-woocommerce-brands'),
81
- 'type' => 'array',
82
- 'items' => array(
83
- "type" => "integer"
84
- ),
85
- 'context' => array("view", "edit")
86
- );
87
- }
88
-
89
- /**
90
- * Returns all attached brands to a GET request to /products(/id)
91
- * @param $product
92
- * @return array|\WP_Error
93
- */
94
- public function get_callback($product){
95
- $brands = wp_get_post_terms($product['id'], 'pwb-brand');
96
-
97
- $result_brands_array = array();
98
- foreach ($brands as $brand) {
99
- $result_brands_array[] = array(
100
- 'id' => $brand->term_id,
101
- 'name' => $brand->name,
102
- 'slug' => $brand->slug
103
  );
104
- }
105
-
106
- return $result_brands_array;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  }
 
108
 
109
- /**
110
- * Entry point for an update call
111
- * @param $brands
112
- * @param $product
113
- */
114
- public function update_callback($brands, $product){
115
- $this->remove_brands($product);
116
- $this->add_brands($brands, $product);
117
  }
118
-
119
-
120
- /**
121
- * Detaches all brands from a product
122
- * @param \WC_Product $product
123
- */
124
- private function remove_brands($product){
125
- $brands = wp_get_post_terms($product->get_id(), 'pwb-brand');
126
- if (!empty($brands)) {
127
- wp_set_post_terms($product->get_id(), array(), 'pwb-brand');
128
- }
129
  }
130
-
131
- /**
132
- * Attaches the given brands to a product. Earlier attached brands, not in this array, will be removed
133
- * @param array $brands
134
- * @param \WC_Product $product
135
- */
136
- private function add_brands($brands, $product){
137
- wp_set_post_terms($product->get_id(), $brands, "pwb-brand");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  }
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  }
1
  <?php
2
 
3
  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
  }
perfect-woocommerce-brands.php CHANGED
@@ -4,13 +4,13 @@
4
  * Plugin Name: Perfect Brands for WooCommerce
5
  * Plugin URI: https://quadlayers.com/portfolio/perfect-woocommerce-brands/
6
  * Description: Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store.
7
- * Version: 1.8.4
8
  * Author: QuadLayers
9
  * Author URI: https://quadlayers.com
10
  * Text Domain: perfect-woocommerce-brands
11
  * Domain Path: /lang
12
  * License: GPLv3
13
- * Perfect WooCommerce Brands version 1.8.4, Copyright (C) 2019 QuadLayers
14
  * Perfect WooCommerce Brands is free software: you can redistribute it and/or modify
15
  * it under the terms of the GNU General Public License as published by
16
  * the Free Software Foundation, either version 3 of the License, or
@@ -24,7 +24,7 @@
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.2.0
28
  */
29
 
30
  namespace Perfect_Woocommerce_Brands;
@@ -36,7 +36,7 @@ define('PWB_PLUGIN_FILE', __FILE__);
36
  define('PWB_PLUGIN_URL', plugins_url('', __FILE__));
37
  define('PWB_PLUGIN_DIR', __DIR__ . DIRECTORY_SEPARATOR);
38
  define('PWB_PLUGIN_BASENAME', plugin_basename(__FILE__));
39
- define('PWB_PLUGIN_VERSION', '1.8.4');
40
  define('PWB_PLUGIN_NAME', 'Perfect WooCommerce Brands');
41
  define('PWB_PREFIX', 'pwb');
42
  define('PWB_REVIEW_URL', 'https://wordpress.org/support/plugin/perfect-woocommerce-brands/reviews/?filter=5#new-post');
4
  * Plugin Name: Perfect Brands for WooCommerce
5
  * Plugin URI: https://quadlayers.com/portfolio/perfect-woocommerce-brands/
6
  * Description: Perfect WooCommerce Brands allows you to show product brands in your WooCommerce based store.
7
+ * Version: 1.8.5
8
  * Author: QuadLayers
9
  * Author URI: https://quadlayers.com
10
  * Text Domain: perfect-woocommerce-brands
11
  * Domain Path: /lang
12
  * License: GPLv3
13
+ * Perfect WooCommerce Brands version 1.8.5, 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
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.6.3
28
  */
29
 
30
  namespace Perfect_Woocommerce_Brands;
36
  define('PWB_PLUGIN_URL', plugins_url('', __FILE__));
37
  define('PWB_PLUGIN_DIR', __DIR__ . DIRECTORY_SEPARATOR);
38
  define('PWB_PLUGIN_BASENAME', plugin_basename(__FILE__));
39
+ define('PWB_PLUGIN_VERSION', '1.8.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');
readme.txt CHANGED
@@ -3,11 +3,11 @@ Contributors: quadlayers, titodevera
3
  Donate link: https://quadlayers.com
4
  Tags: woocommerce, woocommerce brands, woocommerce product, woocommerce manufacturer, woocommerce supplier, e-commerce
5
  Requires at least: 4.7
6
- Tested up to: 5.4.2
7
  Requires PHP: 5.6
8
- Stable tag: 1.8.4
9
  WC requires at least: 3.0
10
- WC tested up to: 4.2.0
11
  License: GPLv3
12
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
13
 
@@ -90,6 +90,8 @@ You can also contribute [translating the plugin](https://translate.wordpress.org
90
 
91
 
92
  == Changelog ==
 
 
93
  = 1.8.4 =
94
  * Enhancement: dynamic data escaped
95
  = 1.8.3 =
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.5.1
7
  Requires PHP: 5.6
8
+ Stable tag: 1.8.5
9
  WC requires at least: 3.0
10
+ WC tested up to: 4.6.3
11
  License: GPLv3
12
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
13
 
90
 
91
 
92
  == Changelog ==
93
+ = 1.8.5 =
94
+ * Fix: security issues
95
  = 1.8.4 =
96
  * Enhancement: dynamic data escaped
97
  = 1.8.3 =