@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Shipping Zone Locations class. |
@@ -26,22 +26,22 @@ discard block |
||
26 | 26 | array( |
27 | 27 | 'args' => array( |
28 | 28 | 'id' => array( |
29 | - 'description' => __( 'Unique ID for the resource.', 'woocommerce' ), |
|
29 | + 'description' => __('Unique ID for the resource.', 'woocommerce'), |
|
30 | 30 | 'type' => 'integer', |
31 | 31 | ), |
32 | 32 | ), |
33 | 33 | array( |
34 | 34 | 'methods' => \WP_REST_Server::READABLE, |
35 | - 'callback' => array( $this, 'get_items' ), |
|
36 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
35 | + 'callback' => array($this, 'get_items'), |
|
36 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
37 | 37 | ), |
38 | 38 | array( |
39 | 39 | 'methods' => \WP_REST_Server::EDITABLE, |
40 | - 'callback' => array( $this, 'update_items' ), |
|
41 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
42 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
40 | + 'callback' => array($this, 'update_items'), |
|
41 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
42 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
43 | 43 | ), |
44 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
44 | + 'schema' => array($this, 'get_public_item_schema'), |
|
45 | 45 | ), |
46 | 46 | true |
47 | 47 | ); |
@@ -53,23 +53,23 @@ discard block |
||
53 | 53 | * @param \WP_REST_Request $request Request data. |
54 | 54 | * @return \WP_REST_Response|\WP_Error |
55 | 55 | */ |
56 | - public function get_items( $request ) { |
|
57 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
56 | + public function get_items($request) { |
|
57 | + $zone = $this->get_zone((int) $request['id']); |
|
58 | 58 | |
59 | - if ( is_wp_error( $zone ) ) { |
|
59 | + if (is_wp_error($zone)) { |
|
60 | 60 | return $zone; |
61 | 61 | } |
62 | 62 | |
63 | 63 | $locations = $zone->get_zone_locations(); |
64 | 64 | $data = array(); |
65 | 65 | |
66 | - foreach ( $locations as $location_obj ) { |
|
67 | - $location = $this->prepare_item_for_response( $location_obj, $request ); |
|
68 | - $location = $this->prepare_response_for_collection( $location ); |
|
66 | + foreach ($locations as $location_obj) { |
|
67 | + $location = $this->prepare_item_for_response($location_obj, $request); |
|
68 | + $location = $this->prepare_response_for_collection($location); |
|
69 | 69 | $data[] = $location; |
70 | 70 | } |
71 | 71 | |
72 | - return rest_ensure_response( $data ); |
|
72 | + return rest_ensure_response($data); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -78,41 +78,41 @@ discard block |
||
78 | 78 | * @param \WP_REST_Request $request Request data. |
79 | 79 | * @return \WP_REST_Response|\WP_Error |
80 | 80 | */ |
81 | - public function update_items( $request ) { |
|
82 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
81 | + public function update_items($request) { |
|
82 | + $zone = $this->get_zone((int) $request['id']); |
|
83 | 83 | |
84 | - if ( is_wp_error( $zone ) ) { |
|
84 | + if (is_wp_error($zone)) { |
|
85 | 85 | return $zone; |
86 | 86 | } |
87 | 87 | |
88 | - if ( 0 === $zone->get_id() ) { |
|
89 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_locations_invalid_zone', __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) ); |
|
88 | + if (0 === $zone->get_id()) { |
|
89 | + return new \WP_Error('woocommerce_rest_shipping_zone_locations_invalid_zone', __('The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce'), array('status' => 403)); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | $raw_locations = $request->get_json_params(); |
93 | 93 | $locations = array(); |
94 | 94 | |
95 | - foreach ( (array) $raw_locations as $raw_location ) { |
|
96 | - if ( empty( $raw_location['code'] ) ) { |
|
95 | + foreach ((array) $raw_locations as $raw_location) { |
|
96 | + if (empty($raw_location['code'])) { |
|
97 | 97 | continue; |
98 | 98 | } |
99 | 99 | |
100 | - $type = ! empty( $raw_location['type'] ) ? sanitize_text_field( $raw_location['type'] ) : 'country'; |
|
100 | + $type = ! empty($raw_location['type']) ? sanitize_text_field($raw_location['type']) : 'country'; |
|
101 | 101 | |
102 | - if ( ! in_array( $type, array( 'postcode', 'state', 'country', 'continent' ), true ) ) { |
|
102 | + if ( ! in_array($type, array('postcode', 'state', 'country', 'continent'), true)) { |
|
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $locations[] = array( |
107 | - 'code' => sanitize_text_field( $raw_location['code'] ), |
|
108 | - 'type' => sanitize_text_field( $type ), |
|
107 | + 'code' => sanitize_text_field($raw_location['code']), |
|
108 | + 'type' => sanitize_text_field($type), |
|
109 | 109 | ); |
110 | 110 | } |
111 | 111 | |
112 | - $zone->set_locations( $locations ); |
|
112 | + $zone->set_locations($locations); |
|
113 | 113 | $zone->save(); |
114 | 114 | |
115 | - return $this->get_items( $request ); |
|
115 | + return $this->get_items($request); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -122,15 +122,15 @@ discard block |
||
122 | 122 | * @param \WP_REST_Request $request Request object. |
123 | 123 | * @return \WP_REST_Response $response |
124 | 124 | */ |
125 | - public function prepare_item_for_response( $item, $request ) { |
|
126 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
127 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
128 | - $data = $this->filter_response_by_context( $data, $context ); |
|
125 | + public function prepare_item_for_response($item, $request) { |
|
126 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
127 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
128 | + $data = $this->filter_response_by_context($data, $context); |
|
129 | 129 | |
130 | 130 | // Wrap the data in a response object. |
131 | - $response = rest_ensure_response( $data ); |
|
131 | + $response = rest_ensure_response($data); |
|
132 | 132 | |
133 | - $response->add_links( $this->prepare_links( (int) $request['id'] ) ); |
|
133 | + $response->add_links($this->prepare_links((int) $request['id'])); |
|
134 | 134 | |
135 | 135 | return $response; |
136 | 136 | } |
@@ -141,14 +141,14 @@ discard block |
||
141 | 141 | * @param int $zone_id Given Shipping Zone ID. |
142 | 142 | * @return array Links for the given Shipping Zone Location. |
143 | 143 | */ |
144 | - protected function prepare_links( $zone_id ) { |
|
144 | + protected function prepare_links($zone_id) { |
|
145 | 145 | $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id; |
146 | 146 | $links = array( |
147 | 147 | 'collection' => array( |
148 | - 'href' => rest_url( $base . '/locations' ), |
|
148 | + 'href' => rest_url($base . '/locations'), |
|
149 | 149 | ), |
150 | 150 | 'describes' => array( |
151 | - 'href' => rest_url( $base ), |
|
151 | + 'href' => rest_url($base), |
|
152 | 152 | ), |
153 | 153 | ); |
154 | 154 | |
@@ -167,12 +167,12 @@ discard block |
||
167 | 167 | 'type' => 'object', |
168 | 168 | 'properties' => array( |
169 | 169 | 'code' => array( |
170 | - 'description' => __( 'Shipping zone location code.', 'woocommerce' ), |
|
170 | + 'description' => __('Shipping zone location code.', 'woocommerce'), |
|
171 | 171 | 'type' => 'string', |
172 | - 'context' => array( 'view', 'edit' ), |
|
172 | + 'context' => array('view', 'edit'), |
|
173 | 173 | ), |
174 | 174 | 'type' => array( |
175 | - 'description' => __( 'Shipping zone location type.', 'woocommerce' ), |
|
175 | + 'description' => __('Shipping zone location type.', 'woocommerce'), |
|
176 | 176 | 'type' => 'string', |
177 | 177 | 'default' => 'country', |
178 | 178 | 'enum' => array( |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | 'country', |
182 | 182 | 'continent', |
183 | 183 | ), |
184 | - 'context' => array( 'view', 'edit' ), |
|
184 | + 'context' => array('view', 'edit'), |
|
185 | 185 | ), |
186 | 186 | ), |
187 | 187 | ); |
188 | 188 | |
189 | - return $this->add_additional_fields_schema( $schema ); |
|
189 | + return $this->add_additional_fields_schema($schema); |
|
190 | 190 | } |
191 | 191 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Shipping Zones class. |
@@ -26,25 +26,25 @@ discard block |
||
26 | 26 | array( |
27 | 27 | array( |
28 | 28 | 'methods' => \WP_REST_Server::READABLE, |
29 | - 'callback' => array( $this, 'get_items' ), |
|
30 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
29 | + 'callback' => array($this, 'get_items'), |
|
30 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
31 | 31 | ), |
32 | 32 | array( |
33 | 33 | 'methods' => \WP_REST_Server::CREATABLE, |
34 | - 'callback' => array( $this, 'create_item' ), |
|
35 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
34 | + 'callback' => array($this, 'create_item'), |
|
35 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
36 | 36 | 'args' => array_merge( |
37 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
37 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
38 | 38 | array( |
39 | 39 | 'name' => array( |
40 | 40 | 'required' => true, |
41 | 41 | 'type' => 'string', |
42 | - 'description' => __( 'Shipping zone name.', 'woocommerce' ), |
|
42 | + 'description' => __('Shipping zone name.', 'woocommerce'), |
|
43 | 43 | ), |
44 | 44 | ) |
45 | 45 | ), |
46 | 46 | ), |
47 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
47 | + 'schema' => array($this, 'get_public_item_schema'), |
|
48 | 48 | ), |
49 | 49 | true |
50 | 50 | ); |
@@ -55,34 +55,34 @@ discard block |
||
55 | 55 | array( |
56 | 56 | 'args' => array( |
57 | 57 | 'id' => array( |
58 | - 'description' => __( 'Unique ID for the resource.', 'woocommerce' ), |
|
58 | + 'description' => __('Unique ID for the resource.', 'woocommerce'), |
|
59 | 59 | 'type' => 'integer', |
60 | 60 | ), |
61 | 61 | ), |
62 | 62 | array( |
63 | 63 | 'methods' => \WP_REST_Server::READABLE, |
64 | - 'callback' => array( $this, 'get_item' ), |
|
65 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
64 | + 'callback' => array($this, 'get_item'), |
|
65 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
66 | 66 | ), |
67 | 67 | array( |
68 | 68 | 'methods' => \WP_REST_Server::EDITABLE, |
69 | - 'callback' => array( $this, 'update_item' ), |
|
70 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
71 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
69 | + 'callback' => array($this, 'update_item'), |
|
70 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
71 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
72 | 72 | ), |
73 | 73 | array( |
74 | 74 | 'methods' => \WP_REST_Server::DELETABLE, |
75 | - 'callback' => array( $this, 'delete_item' ), |
|
76 | - 'permission_callback' => array( $this, 'delete_items_permissions_check' ), |
|
75 | + 'callback' => array($this, 'delete_item'), |
|
76 | + 'permission_callback' => array($this, 'delete_items_permissions_check'), |
|
77 | 77 | 'args' => array( |
78 | 78 | 'force' => array( |
79 | 79 | 'default' => false, |
80 | 80 | 'type' => 'boolean', |
81 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
81 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
82 | 82 | ), |
83 | 83 | ), |
84 | 84 | ), |
85 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
85 | + 'schema' => array($this, 'get_public_item_schema'), |
|
86 | 86 | ), |
87 | 87 | true |
88 | 88 | ); |
@@ -94,18 +94,18 @@ discard block |
||
94 | 94 | * @param \WP_REST_Request $request Request data. |
95 | 95 | * @return \WP_REST_Response|\WP_Error |
96 | 96 | */ |
97 | - public function get_item( $request ) { |
|
98 | - $zone = $this->get_zone( $request->get_param( 'id' ) ); |
|
97 | + public function get_item($request) { |
|
98 | + $zone = $this->get_zone($request->get_param('id')); |
|
99 | 99 | |
100 | - if ( is_wp_error( $zone ) ) { |
|
100 | + if (is_wp_error($zone)) { |
|
101 | 101 | return $zone; |
102 | 102 | } |
103 | 103 | |
104 | 104 | $data = $zone->get_data(); |
105 | - $data = $this->prepare_item_for_response( $data, $request ); |
|
106 | - $data = $this->prepare_response_for_collection( $data ); |
|
105 | + $data = $this->prepare_item_for_response($data, $request); |
|
106 | + $data = $this->prepare_response_for_collection($data); |
|
107 | 107 | |
108 | - return rest_ensure_response( $data ); |
|
108 | + return rest_ensure_response($data); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -114,20 +114,20 @@ discard block |
||
114 | 114 | * @param \WP_REST_Request $request Request data. |
115 | 115 | * @return \WP_REST_Response |
116 | 116 | */ |
117 | - public function get_items( $request ) { |
|
118 | - $rest_of_the_world = \WC_Shipping_Zones::get_zone_by( 'zone_id', 0 ); |
|
117 | + public function get_items($request) { |
|
118 | + $rest_of_the_world = \WC_Shipping_Zones::get_zone_by('zone_id', 0); |
|
119 | 119 | |
120 | 120 | $zones = \WC_Shipping_Zones::get_zones(); |
121 | - array_unshift( $zones, $rest_of_the_world->get_data() ); |
|
121 | + array_unshift($zones, $rest_of_the_world->get_data()); |
|
122 | 122 | $data = array(); |
123 | 123 | |
124 | - foreach ( $zones as $zone_obj ) { |
|
125 | - $zone = $this->prepare_item_for_response( $zone_obj, $request ); |
|
126 | - $zone = $this->prepare_response_for_collection( $zone ); |
|
124 | + foreach ($zones as $zone_obj) { |
|
125 | + $zone = $this->prepare_item_for_response($zone_obj, $request); |
|
126 | + $zone = $this->prepare_response_for_collection($zone); |
|
127 | 127 | $data[] = $zone; |
128 | 128 | } |
129 | 129 | |
130 | - return rest_ensure_response( $data ); |
|
130 | + return rest_ensure_response($data); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -136,27 +136,27 @@ discard block |
||
136 | 136 | * @param \WP_REST_Request $request Full details about the request. |
137 | 137 | * @return \WP_REST_Request|\WP_Error |
138 | 138 | */ |
139 | - public function create_item( $request ) { |
|
140 | - $zone = new \WC_Shipping_Zone( null ); |
|
139 | + public function create_item($request) { |
|
140 | + $zone = new \WC_Shipping_Zone(null); |
|
141 | 141 | |
142 | - if ( ! is_null( $request->get_param( 'name' ) ) ) { |
|
143 | - $zone->set_zone_name( $request->get_param( 'name' ) ); |
|
142 | + if ( ! is_null($request->get_param('name'))) { |
|
143 | + $zone->set_zone_name($request->get_param('name')); |
|
144 | 144 | } |
145 | 145 | |
146 | - if ( ! is_null( $request->get_param( 'order' ) ) ) { |
|
147 | - $zone->set_zone_order( $request->get_param( 'order' ) ); |
|
146 | + if ( ! is_null($request->get_param('order'))) { |
|
147 | + $zone->set_zone_order($request->get_param('order')); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | $zone->save(); |
151 | 151 | |
152 | - if ( $zone->get_id() !== 0 ) { |
|
153 | - $request->set_param( 'id', $zone->get_id() ); |
|
154 | - $response = $this->get_item( $request ); |
|
155 | - $response->set_status( 201 ); |
|
156 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $zone->get_id() ) ) ); |
|
152 | + if ($zone->get_id() !== 0) { |
|
153 | + $request->set_param('id', $zone->get_id()); |
|
154 | + $response = $this->get_item($request); |
|
155 | + $response->set_status(201); |
|
156 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $zone->get_id()))); |
|
157 | 157 | return $response; |
158 | 158 | } else { |
159 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_not_created', __( "Resource cannot be created. Check to make sure 'order' and 'name' are present.", 'woocommerce' ), array( 'status' => 500 ) ); |
|
159 | + return new \WP_Error('woocommerce_rest_shipping_zone_not_created', __("Resource cannot be created. Check to make sure 'order' and 'name' are present.", 'woocommerce'), array('status' => 500)); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -166,34 +166,34 @@ discard block |
||
166 | 166 | * @param \WP_REST_Request $request Full details about the request. |
167 | 167 | * @return \WP_REST_Request|\WP_Error |
168 | 168 | */ |
169 | - public function update_item( $request ) { |
|
170 | - $zone = $this->get_zone( $request->get_param( 'id' ) ); |
|
169 | + public function update_item($request) { |
|
170 | + $zone = $this->get_zone($request->get_param('id')); |
|
171 | 171 | |
172 | - if ( is_wp_error( $zone ) ) { |
|
172 | + if (is_wp_error($zone)) { |
|
173 | 173 | return $zone; |
174 | 174 | } |
175 | 175 | |
176 | - if ( 0 === $zone->get_id() ) { |
|
177 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_invalid_zone', __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) ); |
|
176 | + if (0 === $zone->get_id()) { |
|
177 | + return new \WP_Error('woocommerce_rest_shipping_zone_invalid_zone', __('The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce'), array('status' => 403)); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | $zone_changed = false; |
181 | 181 | |
182 | - if ( ! is_null( $request->get_param( 'name' ) ) ) { |
|
183 | - $zone->set_zone_name( $request->get_param( 'name' ) ); |
|
182 | + if ( ! is_null($request->get_param('name'))) { |
|
183 | + $zone->set_zone_name($request->get_param('name')); |
|
184 | 184 | $zone_changed = true; |
185 | 185 | } |
186 | 186 | |
187 | - if ( ! is_null( $request->get_param( 'order' ) ) ) { |
|
188 | - $zone->set_zone_order( $request->get_param( 'order' ) ); |
|
187 | + if ( ! is_null($request->get_param('order'))) { |
|
188 | + $zone->set_zone_order($request->get_param('order')); |
|
189 | 189 | $zone_changed = true; |
190 | 190 | } |
191 | 191 | |
192 | - if ( $zone_changed ) { |
|
192 | + if ($zone_changed) { |
|
193 | 193 | $zone->save(); |
194 | 194 | } |
195 | 195 | |
196 | - return $this->get_item( $request ); |
|
196 | + return $this->get_item($request); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -202,21 +202,21 @@ discard block |
||
202 | 202 | * @param \WP_REST_Request $request Full details about the request. |
203 | 203 | * @return \WP_REST_Request|\WP_Error |
204 | 204 | */ |
205 | - public function delete_item( $request ) { |
|
206 | - $zone = $this->get_zone( $request->get_param( 'id' ) ); |
|
205 | + public function delete_item($request) { |
|
206 | + $zone = $this->get_zone($request->get_param('id')); |
|
207 | 207 | |
208 | - if ( is_wp_error( $zone ) ) { |
|
208 | + if (is_wp_error($zone)) { |
|
209 | 209 | return $zone; |
210 | 210 | } |
211 | 211 | |
212 | 212 | $force = $request['force']; |
213 | 213 | |
214 | 214 | // We don't support trashing for this type, error out. |
215 | - if ( ! $force ) { |
|
216 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Shipping zones do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
215 | + if ( ! $force) { |
|
216 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Shipping zones do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
217 | 217 | } |
218 | 218 | |
219 | - $previous = $this->get_item( $request ); |
|
219 | + $previous = $this->get_item($request); |
|
220 | 220 | $zone->delete(); |
221 | 221 | $response = new \WP_REST_Response(); |
222 | 222 | $response->set_data( |
@@ -236,21 +236,21 @@ discard block |
||
236 | 236 | * @param \WP_REST_Request $request Request object. |
237 | 237 | * @return \WP_REST_Response $response |
238 | 238 | */ |
239 | - public function prepare_item_for_response( $item, $request ) { |
|
239 | + public function prepare_item_for_response($item, $request) { |
|
240 | 240 | $data = array( |
241 | 241 | 'id' => (int) $item['id'], |
242 | 242 | 'name' => $item['zone_name'], |
243 | 243 | 'order' => (int) $item['zone_order'], |
244 | 244 | ); |
245 | 245 | |
246 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
247 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
248 | - $data = $this->filter_response_by_context( $data, $context ); |
|
246 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
247 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
248 | + $data = $this->filter_response_by_context($data, $context); |
|
249 | 249 | |
250 | 250 | // Wrap the data in a response object. |
251 | - $response = rest_ensure_response( $data ); |
|
251 | + $response = rest_ensure_response($data); |
|
252 | 252 | |
253 | - $response->add_links( $this->prepare_links( $data['id'] ) ); |
|
253 | + $response->add_links($this->prepare_links($data['id'])); |
|
254 | 254 | |
255 | 255 | return $response; |
256 | 256 | } |
@@ -261,17 +261,17 @@ discard block |
||
261 | 261 | * @param int $zone_id Given Shipping Zone ID. |
262 | 262 | * @return array Links for the given Shipping Zone. |
263 | 263 | */ |
264 | - protected function prepare_links( $zone_id ) { |
|
264 | + protected function prepare_links($zone_id) { |
|
265 | 265 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
266 | 266 | $links = array( |
267 | 267 | 'self' => array( |
268 | - 'href' => rest_url( trailingslashit( $base ) . $zone_id ), |
|
268 | + 'href' => rest_url(trailingslashit($base) . $zone_id), |
|
269 | 269 | ), |
270 | 270 | 'collection' => array( |
271 | - 'href' => rest_url( $base ), |
|
271 | + 'href' => rest_url($base), |
|
272 | 272 | ), |
273 | 273 | 'describedby' => array( |
274 | - 'href' => rest_url( trailingslashit( $base ) . $zone_id . '/locations' ), |
|
274 | + 'href' => rest_url(trailingslashit($base) . $zone_id . '/locations'), |
|
275 | 275 | ), |
276 | 276 | ); |
277 | 277 | |
@@ -290,27 +290,27 @@ discard block |
||
290 | 290 | 'type' => 'object', |
291 | 291 | 'properties' => array( |
292 | 292 | 'id' => array( |
293 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
293 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
294 | 294 | 'type' => 'integer', |
295 | - 'context' => array( 'view', 'edit' ), |
|
295 | + 'context' => array('view', 'edit'), |
|
296 | 296 | 'readonly' => true, |
297 | 297 | ), |
298 | 298 | 'name' => array( |
299 | - 'description' => __( 'Shipping zone name.', 'woocommerce' ), |
|
299 | + 'description' => __('Shipping zone name.', 'woocommerce'), |
|
300 | 300 | 'type' => 'string', |
301 | - 'context' => array( 'view', 'edit' ), |
|
301 | + 'context' => array('view', 'edit'), |
|
302 | 302 | 'arg_options' => array( |
303 | 303 | 'sanitize_callback' => 'sanitize_text_field', |
304 | 304 | ), |
305 | 305 | ), |
306 | 306 | 'order' => array( |
307 | - 'description' => __( 'Shipping zone order.', 'woocommerce' ), |
|
307 | + 'description' => __('Shipping zone order.', 'woocommerce'), |
|
308 | 308 | 'type' => 'integer', |
309 | - 'context' => array( 'view', 'edit' ), |
|
309 | + 'context' => array('view', 'edit'), |
|
310 | 310 | ), |
311 | 311 | ), |
312 | 312 | ); |
313 | 313 | |
314 | - return $this->add_additional_fields_schema( $schema ); |
|
314 | + return $this->add_additional_fields_schema($schema); |
|
315 | 315 | } |
316 | 316 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Tax Class controller class. |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | array( |
34 | 34 | array( |
35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
36 | - 'callback' => array( $this, 'get_items' ), |
|
37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
36 | + 'callback' => array($this, 'get_items'), |
|
37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
38 | 38 | 'args' => $this->get_collection_params(), |
39 | 39 | ), |
40 | 40 | array( |
41 | 41 | 'methods' => \WP_REST_Server::CREATABLE, |
42 | - 'callback' => array( $this, 'create_item' ), |
|
43 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
44 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
42 | + 'callback' => array($this, 'create_item'), |
|
43 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
44 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
45 | 45 | ), |
46 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
46 | + 'schema' => array($this, 'get_public_item_schema'), |
|
47 | 47 | ), |
48 | 48 | true |
49 | 49 | ); |
@@ -54,23 +54,23 @@ discard block |
||
54 | 54 | array( |
55 | 55 | 'args' => array( |
56 | 56 | 'slug' => array( |
57 | - 'description' => __( 'Unique slug for the resource.', 'woocommerce' ), |
|
57 | + 'description' => __('Unique slug for the resource.', 'woocommerce'), |
|
58 | 58 | 'type' => 'string', |
59 | 59 | ), |
60 | 60 | ), |
61 | 61 | array( |
62 | 62 | 'methods' => \WP_REST_Server::DELETABLE, |
63 | - 'callback' => array( $this, 'delete_item' ), |
|
64 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
63 | + 'callback' => array($this, 'delete_item'), |
|
64 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
65 | 65 | 'args' => array( |
66 | 66 | 'force' => array( |
67 | 67 | 'default' => false, |
68 | 68 | 'type' => 'boolean', |
69 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
69 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
70 | 70 | ), |
71 | 71 | ), |
72 | 72 | ), |
73 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
73 | + 'schema' => array($this, 'get_public_item_schema'), |
|
74 | 74 | ), |
75 | 75 | true |
76 | 76 | ); |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * @param \WP_REST_Request $request Full details about the request. |
83 | 83 | * @return \WP_Error|boolean |
84 | 84 | */ |
85 | - public function get_items_permissions_check( $request ) { |
|
86 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
87 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
85 | + public function get_items_permissions_check($request) { |
|
86 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
87 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | return true; |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @return bool|\WP_Error |
99 | 99 | */ |
100 | - public function create_item_permissions_check( $request ) { |
|
101 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'create' ) ) { |
|
102 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
100 | + public function create_item_permissions_check($request) { |
|
101 | + if ( ! wc_rest_check_manager_permissions('settings', 'create')) { |
|
102 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return true; |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return bool|\WP_Error |
114 | 114 | */ |
115 | - public function delete_item_permissions_check( $request ) { |
|
116 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) { |
|
117 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
115 | + public function delete_item_permissions_check($request) { |
|
116 | + if ( ! wc_rest_check_manager_permissions('settings', 'delete')) { |
|
117 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | return true; |
@@ -126,32 +126,32 @@ discard block |
||
126 | 126 | * @param \WP_REST_Request $request Request params. |
127 | 127 | * @return array |
128 | 128 | */ |
129 | - public function get_items( $request ) { |
|
129 | + public function get_items($request) { |
|
130 | 130 | $tax_classes = array(); |
131 | 131 | |
132 | 132 | // Add standard class. |
133 | 133 | $tax_classes[] = array( |
134 | 134 | 'slug' => 'standard', |
135 | - 'name' => __( 'Standard rate', 'woocommerce' ), |
|
135 | + 'name' => __('Standard rate', 'woocommerce'), |
|
136 | 136 | ); |
137 | 137 | |
138 | 138 | $classes = \WC_Tax::get_tax_classes(); |
139 | 139 | |
140 | - foreach ( $classes as $class ) { |
|
140 | + foreach ($classes as $class) { |
|
141 | 141 | $tax_classes[] = array( |
142 | - 'slug' => sanitize_title( $class ), |
|
142 | + 'slug' => sanitize_title($class), |
|
143 | 143 | 'name' => $class, |
144 | 144 | ); |
145 | 145 | } |
146 | 146 | |
147 | 147 | $data = array(); |
148 | - foreach ( $tax_classes as $tax_class ) { |
|
149 | - $class = $this->prepare_item_for_response( $tax_class, $request ); |
|
150 | - $class = $this->prepare_response_for_collection( $class ); |
|
148 | + foreach ($tax_classes as $tax_class) { |
|
149 | + $class = $this->prepare_item_for_response($tax_class, $request); |
|
150 | + $class = $this->prepare_response_for_collection($class); |
|
151 | 151 | $data[] = $class; |
152 | 152 | } |
153 | 153 | |
154 | - return rest_ensure_response( $data ); |
|
154 | + return rest_ensure_response($data); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -160,33 +160,33 @@ discard block |
||
160 | 160 | * @param \WP_REST_Request $request Full details about the request. |
161 | 161 | * @return \WP_Error\WP_REST_Response |
162 | 162 | */ |
163 | - public function create_item( $request ) { |
|
163 | + public function create_item($request) { |
|
164 | 164 | $exists = false; |
165 | 165 | $classes = \WC_Tax::get_tax_classes(); |
166 | 166 | $tax_class = array( |
167 | - 'slug' => sanitize_title( $request['name'] ), |
|
167 | + 'slug' => sanitize_title($request['name']), |
|
168 | 168 | 'name' => $request['name'], |
169 | 169 | ); |
170 | 170 | |
171 | 171 | // Check if class exists. |
172 | - foreach ( $classes as $key => $class ) { |
|
173 | - if ( sanitize_title( $class ) === $tax_class['slug'] ) { |
|
172 | + foreach ($classes as $key => $class) { |
|
173 | + if (sanitize_title($class) === $tax_class['slug']) { |
|
174 | 174 | $exists = true; |
175 | 175 | break; |
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | 179 | // Return error if tax class already exists. |
180 | - if ( $exists ) { |
|
181 | - return new \WP_Error( 'woocommerce_rest_tax_class_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
180 | + if ($exists) { |
|
181 | + return new \WP_Error('woocommerce_rest_tax_class_exists', __('Cannot create existing resource.', 'woocommerce'), array('status' => 400)); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | // Add the new class. |
185 | 185 | $classes[] = $tax_class['name']; |
186 | 186 | |
187 | - update_option( 'woocommerce_tax_classes', implode( "\n", $classes ) ); |
|
187 | + update_option('woocommerce_tax_classes', implode("\n", $classes)); |
|
188 | 188 | |
189 | - $this->update_additional_fields_for_object( $tax_class, $request ); |
|
189 | + $this->update_additional_fields_for_object($tax_class, $request); |
|
190 | 190 | |
191 | 191 | /** |
192 | 192 | * Fires after a tax class is created or updated via the REST API. |
@@ -195,13 +195,13 @@ discard block |
||
195 | 195 | * @param \WP_REST_Request $request Request object. |
196 | 196 | * @param boolean $creating True when creating tax class, false when updating tax class. |
197 | 197 | */ |
198 | - do_action( 'woocommerce_rest_insert_tax_class', (object) $tax_class, $request, true ); |
|
198 | + do_action('woocommerce_rest_insert_tax_class', (object) $tax_class, $request, true); |
|
199 | 199 | |
200 | - $request->set_param( 'context', 'edit' ); |
|
201 | - $response = $this->prepare_item_for_response( $tax_class, $request ); |
|
202 | - $response = rest_ensure_response( $response ); |
|
203 | - $response->set_status( 201 ); |
|
204 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug'] ) ) ); |
|
200 | + $request->set_param('context', 'edit'); |
|
201 | + $response = $this->prepare_item_for_response($tax_class, $request); |
|
202 | + $response = rest_ensure_response($response); |
|
203 | + $response->set_status(201); |
|
204 | + $response->header('Location', rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug']))); |
|
205 | 205 | |
206 | 206 | return $response; |
207 | 207 | } |
@@ -212,40 +212,40 @@ discard block |
||
212 | 212 | * @param \WP_REST_Request $request Full details about the request. |
213 | 213 | * @return \WP_Error\WP_REST_Response |
214 | 214 | */ |
215 | - public function delete_item( $request ) { |
|
215 | + public function delete_item($request) { |
|
216 | 216 | global $wpdb; |
217 | 217 | |
218 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
218 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
219 | 219 | |
220 | 220 | // We don't support trashing for this type, error out. |
221 | - if ( ! $force ) { |
|
222 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Taxes do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
221 | + if ( ! $force) { |
|
222 | + return new \WP_Error('woocommerce_rest_trash_not_supported', __('Taxes do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | $tax_class = array( |
226 | - 'slug' => sanitize_title( $request['slug'] ), |
|
226 | + 'slug' => sanitize_title($request['slug']), |
|
227 | 227 | 'name' => '', |
228 | 228 | ); |
229 | 229 | $classes = \WC_Tax::get_tax_classes(); |
230 | 230 | $deleted = false; |
231 | 231 | |
232 | - foreach ( $classes as $key => $class ) { |
|
233 | - if ( sanitize_title( $class ) === $tax_class['slug'] ) { |
|
232 | + foreach ($classes as $key => $class) { |
|
233 | + if (sanitize_title($class) === $tax_class['slug']) { |
|
234 | 234 | $tax_class['name'] = $class; |
235 | - unset( $classes[ $key ] ); |
|
235 | + unset($classes[$key]); |
|
236 | 236 | $deleted = true; |
237 | 237 | break; |
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | - if ( ! $deleted ) { |
|
242 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
241 | + if ( ! $deleted) { |
|
242 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource id.', 'woocommerce'), array('status' => 400)); |
|
243 | 243 | } |
244 | 244 | |
245 | - $request->set_param( 'context', 'edit' ); |
|
246 | - $previous = $this->prepare_item_for_response( $tax_class, $request ); |
|
245 | + $request->set_param('context', 'edit'); |
|
246 | + $previous = $this->prepare_item_for_response($tax_class, $request); |
|
247 | 247 | |
248 | - update_option( 'woocommerce_tax_classes', implode( "\n", $classes ) ); |
|
248 | + update_option('woocommerce_tax_classes', implode("\n", $classes)); |
|
249 | 249 | |
250 | 250 | // Delete tax rate locations locations from the selected class. |
251 | 251 | $wpdb->query( |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | ); |
264 | 264 | |
265 | 265 | // Delete tax rates in the selected class. |
266 | - $wpdb->delete( $wpdb->prefix . 'woocommerce_tax_rates', array( 'tax_rate_class' => $tax_class['slug'] ), array( '%s' ) ); |
|
266 | + $wpdb->delete($wpdb->prefix . 'woocommerce_tax_rates', array('tax_rate_class' => $tax_class['slug']), array('%s')); |
|
267 | 267 | |
268 | 268 | $response = new \WP_REST_Response(); |
269 | 269 | $response->set_data( |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * @param \WP_REST_Response $response The response returned from the API. |
281 | 281 | * @param \WP_REST_Request $request The request sent to the API. |
282 | 282 | */ |
283 | - do_action( 'woocommerce_rest_delete_tax', (object) $tax_class, $response, $request ); |
|
283 | + do_action('woocommerce_rest_delete_tax', (object) $tax_class, $response, $request); |
|
284 | 284 | |
285 | 285 | return $response; |
286 | 286 | } |
@@ -292,17 +292,17 @@ discard block |
||
292 | 292 | * @param \WP_REST_Request $request Request object. |
293 | 293 | * @return \WP_REST_Response $response Response data. |
294 | 294 | */ |
295 | - public function prepare_item_for_response( $tax_class, $request ) { |
|
295 | + public function prepare_item_for_response($tax_class, $request) { |
|
296 | 296 | $data = $tax_class; |
297 | 297 | |
298 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
299 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
300 | - $data = $this->filter_response_by_context( $data, $context ); |
|
298 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
299 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
300 | + $data = $this->filter_response_by_context($data, $context); |
|
301 | 301 | |
302 | 302 | // Wrap the data in a response object. |
303 | - $response = rest_ensure_response( $data ); |
|
303 | + $response = rest_ensure_response($data); |
|
304 | 304 | |
305 | - $response->add_links( $this->prepare_links() ); |
|
305 | + $response->add_links($this->prepare_links()); |
|
306 | 306 | |
307 | 307 | /** |
308 | 308 | * Filter tax object returned from the REST API. |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | * @param stdClass $tax_class Tax object used to create response. |
312 | 312 | * @param \WP_REST_Request $request Request object. |
313 | 313 | */ |
314 | - return apply_filters( 'woocommerce_rest_prepare_tax', $response, (object) $tax_class, $request ); |
|
314 | + return apply_filters('woocommerce_rest_prepare_tax', $response, (object) $tax_class, $request); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | protected function prepare_links() { |
323 | 323 | $links = array( |
324 | 324 | 'collection' => array( |
325 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
325 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
326 | 326 | ), |
327 | 327 | ); |
328 | 328 | |
@@ -341,15 +341,15 @@ discard block |
||
341 | 341 | 'type' => 'object', |
342 | 342 | 'properties' => array( |
343 | 343 | 'slug' => array( |
344 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
344 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
345 | 345 | 'type' => 'string', |
346 | - 'context' => array( 'view', 'edit' ), |
|
346 | + 'context' => array('view', 'edit'), |
|
347 | 347 | 'readonly' => true, |
348 | 348 | ), |
349 | 349 | 'name' => array( |
350 | - 'description' => __( 'Tax class name.', 'woocommerce' ), |
|
350 | + 'description' => __('Tax class name.', 'woocommerce'), |
|
351 | 351 | 'type' => 'string', |
352 | - 'context' => array( 'view', 'edit' ), |
|
352 | + 'context' => array('view', 'edit'), |
|
353 | 353 | 'required' => true, |
354 | 354 | 'arg_options' => array( |
355 | 355 | 'sanitize_callback' => 'sanitize_text_field', |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | ), |
359 | 359 | ); |
360 | 360 | |
361 | - return $this->add_additional_fields_schema( $schema ); |
|
361 | + return $this->add_additional_fields_schema($schema); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | */ |
369 | 369 | public function get_collection_params() { |
370 | 370 | return array( |
371 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
371 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
372 | 372 | ); |
373 | 373 | } |
374 | 374 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API System Status controller class. |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | array( |
34 | 34 | array( |
35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
36 | - 'callback' => array( $this, 'get_items' ), |
|
37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
36 | + 'callback' => array($this, 'get_items'), |
|
37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
38 | 38 | 'args' => $this->get_collection_params(), |
39 | 39 | ), |
40 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
40 | + 'schema' => array($this, 'get_public_item_schema'), |
|
41 | 41 | ), |
42 | 42 | true |
43 | 43 | ); |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | * @param \WP_REST_Request $request Full details about the request. |
50 | 50 | * @return \WP_Error|boolean |
51 | 51 | */ |
52 | - public function get_items_permissions_check( $request ) { |
|
53 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { |
|
54 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
52 | + public function get_items_permissions_check($request) { |
|
53 | + if ( ! wc_rest_check_manager_permissions('system_status', 'read')) { |
|
54 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
55 | 55 | } |
56 | 56 | return true; |
57 | 57 | } |
@@ -62,24 +62,24 @@ discard block |
||
62 | 62 | * @param \WP_REST_Request $request Full details about the request. |
63 | 63 | * @return \WP_Error\WP_REST_Response |
64 | 64 | */ |
65 | - public function get_items( $request ) { |
|
65 | + public function get_items($request) { |
|
66 | 66 | $schema = $this->get_item_schema(); |
67 | 67 | $mappings = $this->get_item_mappings(); |
68 | 68 | $response = array(); |
69 | 69 | |
70 | - foreach ( $mappings as $section => $values ) { |
|
71 | - foreach ( $values as $key => $value ) { |
|
72 | - if ( isset( $schema['properties'][ $section ]['properties'][ $key ]['type'] ) ) { |
|
73 | - settype( $values[ $key ], $schema['properties'][ $section ]['properties'][ $key ]['type'] ); |
|
70 | + foreach ($mappings as $section => $values) { |
|
71 | + foreach ($values as $key => $value) { |
|
72 | + if (isset($schema['properties'][$section]['properties'][$key]['type'])) { |
|
73 | + settype($values[$key], $schema['properties'][$section]['properties'][$key]['type']); |
|
74 | 74 | } |
75 | 75 | } |
76 | - settype( $values, $schema['properties'][ $section ]['type'] ); |
|
77 | - $response[ $section ] = $values; |
|
76 | + settype($values, $schema['properties'][$section]['type']); |
|
77 | + $response[$section] = $values; |
|
78 | 78 | } |
79 | 79 | |
80 | - $response = $this->prepare_item_for_response( $response, $request ); |
|
80 | + $response = $this->prepare_item_for_response($response, $request); |
|
81 | 81 | |
82 | - return rest_ensure_response( $response ); |
|
82 | + return rest_ensure_response($response); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -94,229 +94,229 @@ discard block |
||
94 | 94 | 'type' => 'object', |
95 | 95 | 'properties' => array( |
96 | 96 | 'environment' => array( |
97 | - 'description' => __( 'Environment.', 'woocommerce' ), |
|
97 | + 'description' => __('Environment.', 'woocommerce'), |
|
98 | 98 | 'type' => 'object', |
99 | - 'context' => array( 'view' ), |
|
99 | + 'context' => array('view'), |
|
100 | 100 | 'readonly' => true, |
101 | 101 | 'properties' => array( |
102 | 102 | 'home_url' => array( |
103 | - 'description' => __( 'Home URL.', 'woocommerce' ), |
|
103 | + 'description' => __('Home URL.', 'woocommerce'), |
|
104 | 104 | 'type' => 'string', |
105 | 105 | 'format' => 'uri', |
106 | - 'context' => array( 'view' ), |
|
106 | + 'context' => array('view'), |
|
107 | 107 | 'readonly' => true, |
108 | 108 | ), |
109 | 109 | 'site_url' => array( |
110 | - 'description' => __( 'Site URL.', 'woocommerce' ), |
|
110 | + 'description' => __('Site URL.', 'woocommerce'), |
|
111 | 111 | 'type' => 'string', |
112 | 112 | 'format' => 'uri', |
113 | - 'context' => array( 'view' ), |
|
113 | + 'context' => array('view'), |
|
114 | 114 | 'readonly' => true, |
115 | 115 | ), |
116 | 116 | 'wc_version' => array( |
117 | - 'description' => __( 'WooCommerce version.', 'woocommerce' ), |
|
117 | + 'description' => __('WooCommerce version.', 'woocommerce'), |
|
118 | 118 | 'type' => 'string', |
119 | - 'context' => array( 'view' ), |
|
119 | + 'context' => array('view'), |
|
120 | 120 | 'readonly' => true, |
121 | 121 | ), |
122 | 122 | 'log_directory' => array( |
123 | - 'description' => __( 'Log directory.', 'woocommerce' ), |
|
123 | + 'description' => __('Log directory.', 'woocommerce'), |
|
124 | 124 | 'type' => 'string', |
125 | - 'context' => array( 'view' ), |
|
125 | + 'context' => array('view'), |
|
126 | 126 | 'readonly' => true, |
127 | 127 | ), |
128 | 128 | 'log_directory_writable' => array( |
129 | - 'description' => __( 'Is log directory writable?', 'woocommerce' ), |
|
129 | + 'description' => __('Is log directory writable?', 'woocommerce'), |
|
130 | 130 | 'type' => 'boolean', |
131 | - 'context' => array( 'view' ), |
|
131 | + 'context' => array('view'), |
|
132 | 132 | 'readonly' => true, |
133 | 133 | ), |
134 | 134 | 'wp_version' => array( |
135 | - 'description' => __( 'WordPress version.', 'woocommerce' ), |
|
135 | + 'description' => __('WordPress version.', 'woocommerce'), |
|
136 | 136 | 'type' => 'string', |
137 | - 'context' => array( 'view' ), |
|
137 | + 'context' => array('view'), |
|
138 | 138 | 'readonly' => true, |
139 | 139 | ), |
140 | 140 | 'wp_multisite' => array( |
141 | - 'description' => __( 'Is WordPress multisite?', 'woocommerce' ), |
|
141 | + 'description' => __('Is WordPress multisite?', 'woocommerce'), |
|
142 | 142 | 'type' => 'boolean', |
143 | - 'context' => array( 'view' ), |
|
143 | + 'context' => array('view'), |
|
144 | 144 | 'readonly' => true, |
145 | 145 | ), |
146 | 146 | 'wp_memory_limit' => array( |
147 | - 'description' => __( 'WordPress memory limit.', 'woocommerce' ), |
|
147 | + 'description' => __('WordPress memory limit.', 'woocommerce'), |
|
148 | 148 | 'type' => 'integer', |
149 | - 'context' => array( 'view' ), |
|
149 | + 'context' => array('view'), |
|
150 | 150 | 'readonly' => true, |
151 | 151 | ), |
152 | 152 | 'wp_debug_mode' => array( |
153 | - 'description' => __( 'Is WordPress debug mode active?', 'woocommerce' ), |
|
153 | + 'description' => __('Is WordPress debug mode active?', 'woocommerce'), |
|
154 | 154 | 'type' => 'boolean', |
155 | - 'context' => array( 'view' ), |
|
155 | + 'context' => array('view'), |
|
156 | 156 | 'readonly' => true, |
157 | 157 | ), |
158 | 158 | 'wp_cron' => array( |
159 | - 'description' => __( 'Are WordPress cron jobs enabled?', 'woocommerce' ), |
|
159 | + 'description' => __('Are WordPress cron jobs enabled?', 'woocommerce'), |
|
160 | 160 | 'type' => 'boolean', |
161 | - 'context' => array( 'view' ), |
|
161 | + 'context' => array('view'), |
|
162 | 162 | 'readonly' => true, |
163 | 163 | ), |
164 | 164 | 'language' => array( |
165 | - 'description' => __( 'WordPress language.', 'woocommerce' ), |
|
165 | + 'description' => __('WordPress language.', 'woocommerce'), |
|
166 | 166 | 'type' => 'string', |
167 | - 'context' => array( 'view' ), |
|
167 | + 'context' => array('view'), |
|
168 | 168 | 'readonly' => true, |
169 | 169 | ), |
170 | 170 | 'server_info' => array( |
171 | - 'description' => __( 'Server info.', 'woocommerce' ), |
|
171 | + 'description' => __('Server info.', 'woocommerce'), |
|
172 | 172 | 'type' => 'string', |
173 | - 'context' => array( 'view' ), |
|
173 | + 'context' => array('view'), |
|
174 | 174 | 'readonly' => true, |
175 | 175 | ), |
176 | 176 | 'php_version' => array( |
177 | - 'description' => __( 'PHP version.', 'woocommerce' ), |
|
177 | + 'description' => __('PHP version.', 'woocommerce'), |
|
178 | 178 | 'type' => 'string', |
179 | - 'context' => array( 'view' ), |
|
179 | + 'context' => array('view'), |
|
180 | 180 | 'readonly' => true, |
181 | 181 | ), |
182 | 182 | 'php_post_max_size' => array( |
183 | - 'description' => __( 'PHP post max size.', 'woocommerce' ), |
|
183 | + 'description' => __('PHP post max size.', 'woocommerce'), |
|
184 | 184 | 'type' => 'integer', |
185 | - 'context' => array( 'view' ), |
|
185 | + 'context' => array('view'), |
|
186 | 186 | 'readonly' => true, |
187 | 187 | ), |
188 | 188 | 'php_max_execution_time' => array( |
189 | - 'description' => __( 'PHP max execution time.', 'woocommerce' ), |
|
189 | + 'description' => __('PHP max execution time.', 'woocommerce'), |
|
190 | 190 | 'type' => 'integer', |
191 | - 'context' => array( 'view' ), |
|
191 | + 'context' => array('view'), |
|
192 | 192 | 'readonly' => true, |
193 | 193 | ), |
194 | 194 | 'php_max_input_vars' => array( |
195 | - 'description' => __( 'PHP max input vars.', 'woocommerce' ), |
|
195 | + 'description' => __('PHP max input vars.', 'woocommerce'), |
|
196 | 196 | 'type' => 'integer', |
197 | - 'context' => array( 'view' ), |
|
197 | + 'context' => array('view'), |
|
198 | 198 | 'readonly' => true, |
199 | 199 | ), |
200 | 200 | 'curl_version' => array( |
201 | - 'description' => __( 'cURL version.', 'woocommerce' ), |
|
201 | + 'description' => __('cURL version.', 'woocommerce'), |
|
202 | 202 | 'type' => 'string', |
203 | - 'context' => array( 'view' ), |
|
203 | + 'context' => array('view'), |
|
204 | 204 | 'readonly' => true, |
205 | 205 | ), |
206 | 206 | 'suhosin_installed' => array( |
207 | - 'description' => __( 'Is SUHOSIN installed?', 'woocommerce' ), |
|
207 | + 'description' => __('Is SUHOSIN installed?', 'woocommerce'), |
|
208 | 208 | 'type' => 'boolean', |
209 | - 'context' => array( 'view' ), |
|
209 | + 'context' => array('view'), |
|
210 | 210 | 'readonly' => true, |
211 | 211 | ), |
212 | 212 | 'max_upload_size' => array( |
213 | - 'description' => __( 'Max upload size.', 'woocommerce' ), |
|
213 | + 'description' => __('Max upload size.', 'woocommerce'), |
|
214 | 214 | 'type' => 'integer', |
215 | - 'context' => array( 'view' ), |
|
215 | + 'context' => array('view'), |
|
216 | 216 | 'readonly' => true, |
217 | 217 | ), |
218 | 218 | 'mysql_version' => array( |
219 | - 'description' => __( 'MySQL version.', 'woocommerce' ), |
|
219 | + 'description' => __('MySQL version.', 'woocommerce'), |
|
220 | 220 | 'type' => 'string', |
221 | - 'context' => array( 'view' ), |
|
221 | + 'context' => array('view'), |
|
222 | 222 | 'readonly' => true, |
223 | 223 | ), |
224 | 224 | 'mysql_version_string' => array( |
225 | - 'description' => __( 'MySQL version string.', 'woocommerce' ), |
|
225 | + 'description' => __('MySQL version string.', 'woocommerce'), |
|
226 | 226 | 'type' => 'string', |
227 | - 'context' => array( 'view' ), |
|
227 | + 'context' => array('view'), |
|
228 | 228 | 'readonly' => true, |
229 | 229 | ), |
230 | 230 | 'default_timezone' => array( |
231 | - 'description' => __( 'Default timezone.', 'woocommerce' ), |
|
231 | + 'description' => __('Default timezone.', 'woocommerce'), |
|
232 | 232 | 'type' => 'string', |
233 | - 'context' => array( 'view' ), |
|
233 | + 'context' => array('view'), |
|
234 | 234 | 'readonly' => true, |
235 | 235 | ), |
236 | 236 | 'fsockopen_or_curl_enabled' => array( |
237 | - 'description' => __( 'Is fsockopen/cURL enabled?', 'woocommerce' ), |
|
237 | + 'description' => __('Is fsockopen/cURL enabled?', 'woocommerce'), |
|
238 | 238 | 'type' => 'boolean', |
239 | - 'context' => array( 'view' ), |
|
239 | + 'context' => array('view'), |
|
240 | 240 | 'readonly' => true, |
241 | 241 | ), |
242 | 242 | 'soapclient_enabled' => array( |
243 | - 'description' => __( 'Is SoapClient class enabled?', 'woocommerce' ), |
|
243 | + 'description' => __('Is SoapClient class enabled?', 'woocommerce'), |
|
244 | 244 | 'type' => 'boolean', |
245 | - 'context' => array( 'view' ), |
|
245 | + 'context' => array('view'), |
|
246 | 246 | 'readonly' => true, |
247 | 247 | ), |
248 | 248 | 'domdocument_enabled' => array( |
249 | - 'description' => __( 'Is DomDocument class enabled?', 'woocommerce' ), |
|
249 | + 'description' => __('Is DomDocument class enabled?', 'woocommerce'), |
|
250 | 250 | 'type' => 'boolean', |
251 | - 'context' => array( 'view' ), |
|
251 | + 'context' => array('view'), |
|
252 | 252 | 'readonly' => true, |
253 | 253 | ), |
254 | 254 | 'gzip_enabled' => array( |
255 | - 'description' => __( 'Is GZip enabled?', 'woocommerce' ), |
|
255 | + 'description' => __('Is GZip enabled?', 'woocommerce'), |
|
256 | 256 | 'type' => 'boolean', |
257 | - 'context' => array( 'view' ), |
|
257 | + 'context' => array('view'), |
|
258 | 258 | 'readonly' => true, |
259 | 259 | ), |
260 | 260 | 'mbstring_enabled' => array( |
261 | - 'description' => __( 'Is mbstring enabled?', 'woocommerce' ), |
|
261 | + 'description' => __('Is mbstring enabled?', 'woocommerce'), |
|
262 | 262 | 'type' => 'boolean', |
263 | - 'context' => array( 'view' ), |
|
263 | + 'context' => array('view'), |
|
264 | 264 | 'readonly' => true, |
265 | 265 | ), |
266 | 266 | 'remote_post_successful' => array( |
267 | - 'description' => __( 'Remote POST successful?', 'woocommerce' ), |
|
267 | + 'description' => __('Remote POST successful?', 'woocommerce'), |
|
268 | 268 | 'type' => 'boolean', |
269 | - 'context' => array( 'view' ), |
|
269 | + 'context' => array('view'), |
|
270 | 270 | 'readonly' => true, |
271 | 271 | ), |
272 | 272 | 'remote_post_response' => array( |
273 | - 'description' => __( 'Remote POST response.', 'woocommerce' ), |
|
273 | + 'description' => __('Remote POST response.', 'woocommerce'), |
|
274 | 274 | 'type' => 'string', |
275 | - 'context' => array( 'view' ), |
|
275 | + 'context' => array('view'), |
|
276 | 276 | 'readonly' => true, |
277 | 277 | ), |
278 | 278 | 'remote_get_successful' => array( |
279 | - 'description' => __( 'Remote GET successful?', 'woocommerce' ), |
|
279 | + 'description' => __('Remote GET successful?', 'woocommerce'), |
|
280 | 280 | 'type' => 'boolean', |
281 | - 'context' => array( 'view' ), |
|
281 | + 'context' => array('view'), |
|
282 | 282 | 'readonly' => true, |
283 | 283 | ), |
284 | 284 | 'remote_get_response' => array( |
285 | - 'description' => __( 'Remote GET response.', 'woocommerce' ), |
|
285 | + 'description' => __('Remote GET response.', 'woocommerce'), |
|
286 | 286 | 'type' => 'string', |
287 | - 'context' => array( 'view' ), |
|
287 | + 'context' => array('view'), |
|
288 | 288 | 'readonly' => true, |
289 | 289 | ), |
290 | 290 | ), |
291 | 291 | ), |
292 | 292 | 'database' => array( |
293 | - 'description' => __( 'Database.', 'woocommerce' ), |
|
293 | + 'description' => __('Database.', 'woocommerce'), |
|
294 | 294 | 'type' => 'object', |
295 | - 'context' => array( 'view' ), |
|
295 | + 'context' => array('view'), |
|
296 | 296 | 'readonly' => true, |
297 | 297 | 'properties' => array( |
298 | 298 | 'wc_database_version' => array( |
299 | - 'description' => __( 'WC database version.', 'woocommerce' ), |
|
299 | + 'description' => __('WC database version.', 'woocommerce'), |
|
300 | 300 | 'type' => 'string', |
301 | - 'context' => array( 'view' ), |
|
301 | + 'context' => array('view'), |
|
302 | 302 | 'readonly' => true, |
303 | 303 | ), |
304 | 304 | 'database_prefix' => array( |
305 | - 'description' => __( 'Database prefix.', 'woocommerce' ), |
|
305 | + 'description' => __('Database prefix.', 'woocommerce'), |
|
306 | 306 | 'type' => 'string', |
307 | - 'context' => array( 'view' ), |
|
307 | + 'context' => array('view'), |
|
308 | 308 | 'readonly' => true, |
309 | 309 | ), |
310 | 310 | 'maxmind_geoip_database' => array( |
311 | - 'description' => __( 'MaxMind GeoIP database.', 'woocommerce' ), |
|
311 | + 'description' => __('MaxMind GeoIP database.', 'woocommerce'), |
|
312 | 312 | 'type' => 'string', |
313 | - 'context' => array( 'view' ), |
|
313 | + 'context' => array('view'), |
|
314 | 314 | 'readonly' => true, |
315 | 315 | ), |
316 | 316 | 'database_tables' => array( |
317 | - 'description' => __( 'Database tables.', 'woocommerce' ), |
|
317 | + 'description' => __('Database tables.', 'woocommerce'), |
|
318 | 318 | 'type' => 'array', |
319 | - 'context' => array( 'view' ), |
|
319 | + 'context' => array('view'), |
|
320 | 320 | 'readonly' => true, |
321 | 321 | 'items' => array( |
322 | 322 | 'type' => 'string', |
@@ -325,190 +325,190 @@ discard block |
||
325 | 325 | ), |
326 | 326 | ), |
327 | 327 | 'active_plugins' => array( |
328 | - 'description' => __( 'Active plugins.', 'woocommerce' ), |
|
328 | + 'description' => __('Active plugins.', 'woocommerce'), |
|
329 | 329 | 'type' => 'array', |
330 | - 'context' => array( 'view' ), |
|
330 | + 'context' => array('view'), |
|
331 | 331 | 'readonly' => true, |
332 | 332 | 'items' => array( |
333 | 333 | 'type' => 'string', |
334 | 334 | ), |
335 | 335 | ), |
336 | 336 | 'inactive_plugins' => array( |
337 | - 'description' => __( 'Inactive plugins.', 'woocommerce' ), |
|
337 | + 'description' => __('Inactive plugins.', 'woocommerce'), |
|
338 | 338 | 'type' => 'array', |
339 | - 'context' => array( 'view' ), |
|
339 | + 'context' => array('view'), |
|
340 | 340 | 'readonly' => true, |
341 | 341 | 'items' => array( |
342 | 342 | 'type' => 'string', |
343 | 343 | ), |
344 | 344 | ), |
345 | 345 | 'dropins_mu_plugins' => array( |
346 | - 'description' => __( 'Dropins & MU plugins.', 'woocommerce' ), |
|
346 | + 'description' => __('Dropins & MU plugins.', 'woocommerce'), |
|
347 | 347 | 'type' => 'array', |
348 | - 'context' => array( 'view' ), |
|
348 | + 'context' => array('view'), |
|
349 | 349 | 'readonly' => true, |
350 | 350 | 'items' => array( |
351 | 351 | 'type' => 'string', |
352 | 352 | ), |
353 | 353 | ), |
354 | 354 | 'theme' => array( |
355 | - 'description' => __( 'Theme.', 'woocommerce' ), |
|
355 | + 'description' => __('Theme.', 'woocommerce'), |
|
356 | 356 | 'type' => 'object', |
357 | - 'context' => array( 'view' ), |
|
357 | + 'context' => array('view'), |
|
358 | 358 | 'readonly' => true, |
359 | 359 | 'properties' => array( |
360 | 360 | 'name' => array( |
361 | - 'description' => __( 'Theme name.', 'woocommerce' ), |
|
361 | + 'description' => __('Theme name.', 'woocommerce'), |
|
362 | 362 | 'type' => 'string', |
363 | - 'context' => array( 'view' ), |
|
363 | + 'context' => array('view'), |
|
364 | 364 | 'readonly' => true, |
365 | 365 | ), |
366 | 366 | 'version' => array( |
367 | - 'description' => __( 'Theme version.', 'woocommerce' ), |
|
367 | + 'description' => __('Theme version.', 'woocommerce'), |
|
368 | 368 | 'type' => 'string', |
369 | - 'context' => array( 'view' ), |
|
369 | + 'context' => array('view'), |
|
370 | 370 | 'readonly' => true, |
371 | 371 | ), |
372 | 372 | 'version_latest' => array( |
373 | - 'description' => __( 'Latest version of theme.', 'woocommerce' ), |
|
373 | + 'description' => __('Latest version of theme.', 'woocommerce'), |
|
374 | 374 | 'type' => 'string', |
375 | - 'context' => array( 'view' ), |
|
375 | + 'context' => array('view'), |
|
376 | 376 | 'readonly' => true, |
377 | 377 | ), |
378 | 378 | 'author_url' => array( |
379 | - 'description' => __( 'Theme author URL.', 'woocommerce' ), |
|
379 | + 'description' => __('Theme author URL.', 'woocommerce'), |
|
380 | 380 | 'type' => 'string', |
381 | 381 | 'format' => 'uri', |
382 | - 'context' => array( 'view' ), |
|
382 | + 'context' => array('view'), |
|
383 | 383 | 'readonly' => true, |
384 | 384 | ), |
385 | 385 | 'is_child_theme' => array( |
386 | - 'description' => __( 'Is this theme a child theme?', 'woocommerce' ), |
|
386 | + 'description' => __('Is this theme a child theme?', 'woocommerce'), |
|
387 | 387 | 'type' => 'boolean', |
388 | - 'context' => array( 'view' ), |
|
388 | + 'context' => array('view'), |
|
389 | 389 | 'readonly' => true, |
390 | 390 | ), |
391 | 391 | 'has_woocommerce_support' => array( |
392 | - 'description' => __( 'Does the theme declare WooCommerce support?', 'woocommerce' ), |
|
392 | + 'description' => __('Does the theme declare WooCommerce support?', 'woocommerce'), |
|
393 | 393 | 'type' => 'boolean', |
394 | - 'context' => array( 'view' ), |
|
394 | + 'context' => array('view'), |
|
395 | 395 | 'readonly' => true, |
396 | 396 | ), |
397 | 397 | 'has_woocommerce_file' => array( |
398 | - 'description' => __( 'Does the theme have a woocommerce.php file?', 'woocommerce' ), |
|
398 | + 'description' => __('Does the theme have a woocommerce.php file?', 'woocommerce'), |
|
399 | 399 | 'type' => 'boolean', |
400 | - 'context' => array( 'view' ), |
|
400 | + 'context' => array('view'), |
|
401 | 401 | 'readonly' => true, |
402 | 402 | ), |
403 | 403 | 'has_outdated_templates' => array( |
404 | - 'description' => __( 'Does this theme have outdated templates?', 'woocommerce' ), |
|
404 | + 'description' => __('Does this theme have outdated templates?', 'woocommerce'), |
|
405 | 405 | 'type' => 'boolean', |
406 | - 'context' => array( 'view' ), |
|
406 | + 'context' => array('view'), |
|
407 | 407 | 'readonly' => true, |
408 | 408 | ), |
409 | 409 | 'overrides' => array( |
410 | - 'description' => __( 'Template overrides.', 'woocommerce' ), |
|
410 | + 'description' => __('Template overrides.', 'woocommerce'), |
|
411 | 411 | 'type' => 'array', |
412 | - 'context' => array( 'view' ), |
|
412 | + 'context' => array('view'), |
|
413 | 413 | 'readonly' => true, |
414 | 414 | 'items' => array( |
415 | 415 | 'type' => 'string', |
416 | 416 | ), |
417 | 417 | ), |
418 | 418 | 'parent_name' => array( |
419 | - 'description' => __( 'Parent theme name.', 'woocommerce' ), |
|
419 | + 'description' => __('Parent theme name.', 'woocommerce'), |
|
420 | 420 | 'type' => 'string', |
421 | - 'context' => array( 'view' ), |
|
421 | + 'context' => array('view'), |
|
422 | 422 | 'readonly' => true, |
423 | 423 | ), |
424 | 424 | 'parent_version' => array( |
425 | - 'description' => __( 'Parent theme version.', 'woocommerce' ), |
|
425 | + 'description' => __('Parent theme version.', 'woocommerce'), |
|
426 | 426 | 'type' => 'string', |
427 | - 'context' => array( 'view' ), |
|
427 | + 'context' => array('view'), |
|
428 | 428 | 'readonly' => true, |
429 | 429 | ), |
430 | 430 | 'parent_author_url' => array( |
431 | - 'description' => __( 'Parent theme author URL.', 'woocommerce' ), |
|
431 | + 'description' => __('Parent theme author URL.', 'woocommerce'), |
|
432 | 432 | 'type' => 'string', |
433 | 433 | 'format' => 'uri', |
434 | - 'context' => array( 'view' ), |
|
434 | + 'context' => array('view'), |
|
435 | 435 | 'readonly' => true, |
436 | 436 | ), |
437 | 437 | ), |
438 | 438 | ), |
439 | 439 | 'settings' => array( |
440 | - 'description' => __( 'Settings.', 'woocommerce' ), |
|
440 | + 'description' => __('Settings.', 'woocommerce'), |
|
441 | 441 | 'type' => 'object', |
442 | - 'context' => array( 'view' ), |
|
442 | + 'context' => array('view'), |
|
443 | 443 | 'readonly' => true, |
444 | 444 | 'properties' => array( |
445 | 445 | 'api_enabled' => array( |
446 | - 'description' => __( 'REST API enabled?', 'woocommerce' ), |
|
446 | + 'description' => __('REST API enabled?', 'woocommerce'), |
|
447 | 447 | 'type' => 'boolean', |
448 | - 'context' => array( 'view' ), |
|
448 | + 'context' => array('view'), |
|
449 | 449 | 'readonly' => true, |
450 | 450 | ), |
451 | 451 | 'force_ssl' => array( |
452 | - 'description' => __( 'SSL forced?', 'woocommerce' ), |
|
452 | + 'description' => __('SSL forced?', 'woocommerce'), |
|
453 | 453 | 'type' => 'boolean', |
454 | - 'context' => array( 'view' ), |
|
454 | + 'context' => array('view'), |
|
455 | 455 | 'readonly' => true, |
456 | 456 | ), |
457 | 457 | 'currency' => array( |
458 | - 'description' => __( 'Currency.', 'woocommerce' ), |
|
458 | + 'description' => __('Currency.', 'woocommerce'), |
|
459 | 459 | 'type' => 'string', |
460 | - 'context' => array( 'view' ), |
|
460 | + 'context' => array('view'), |
|
461 | 461 | 'readonly' => true, |
462 | 462 | ), |
463 | 463 | 'currency_symbol' => array( |
464 | - 'description' => __( 'Currency symbol.', 'woocommerce' ), |
|
464 | + 'description' => __('Currency symbol.', 'woocommerce'), |
|
465 | 465 | 'type' => 'string', |
466 | - 'context' => array( 'view' ), |
|
466 | + 'context' => array('view'), |
|
467 | 467 | 'readonly' => true, |
468 | 468 | ), |
469 | 469 | 'currency_position' => array( |
470 | - 'description' => __( 'Currency position.', 'woocommerce' ), |
|
470 | + 'description' => __('Currency position.', 'woocommerce'), |
|
471 | 471 | 'type' => 'string', |
472 | - 'context' => array( 'view' ), |
|
472 | + 'context' => array('view'), |
|
473 | 473 | 'readonly' => true, |
474 | 474 | ), |
475 | 475 | 'thousand_separator' => array( |
476 | - 'description' => __( 'Thousand separator.', 'woocommerce' ), |
|
476 | + 'description' => __('Thousand separator.', 'woocommerce'), |
|
477 | 477 | 'type' => 'string', |
478 | - 'context' => array( 'view' ), |
|
478 | + 'context' => array('view'), |
|
479 | 479 | 'readonly' => true, |
480 | 480 | ), |
481 | 481 | 'decimal_separator' => array( |
482 | - 'description' => __( 'Decimal separator.', 'woocommerce' ), |
|
482 | + 'description' => __('Decimal separator.', 'woocommerce'), |
|
483 | 483 | 'type' => 'string', |
484 | - 'context' => array( 'view' ), |
|
484 | + 'context' => array('view'), |
|
485 | 485 | 'readonly' => true, |
486 | 486 | ), |
487 | 487 | 'number_of_decimals' => array( |
488 | - 'description' => __( 'Number of decimals.', 'woocommerce' ), |
|
488 | + 'description' => __('Number of decimals.', 'woocommerce'), |
|
489 | 489 | 'type' => 'integer', |
490 | - 'context' => array( 'view' ), |
|
490 | + 'context' => array('view'), |
|
491 | 491 | 'readonly' => true, |
492 | 492 | ), |
493 | 493 | 'geolocation_enabled' => array( |
494 | - 'description' => __( 'Geolocation enabled?', 'woocommerce' ), |
|
494 | + 'description' => __('Geolocation enabled?', 'woocommerce'), |
|
495 | 495 | 'type' => 'boolean', |
496 | - 'context' => array( 'view' ), |
|
496 | + 'context' => array('view'), |
|
497 | 497 | 'readonly' => true, |
498 | 498 | ), |
499 | 499 | 'taxonomies' => array( |
500 | - 'description' => __( 'Taxonomy terms for product/order statuses.', 'woocommerce' ), |
|
500 | + 'description' => __('Taxonomy terms for product/order statuses.', 'woocommerce'), |
|
501 | 501 | 'type' => 'array', |
502 | - 'context' => array( 'view' ), |
|
502 | + 'context' => array('view'), |
|
503 | 503 | 'readonly' => true, |
504 | 504 | 'items' => array( |
505 | 505 | 'type' => 'string', |
506 | 506 | ), |
507 | 507 | ), |
508 | 508 | 'product_visibility_terms' => array( |
509 | - 'description' => __( 'Terms in the product visibility taxonomy.', 'woocommerce' ), |
|
509 | + 'description' => __('Terms in the product visibility taxonomy.', 'woocommerce'), |
|
510 | 510 | 'type' => 'array', |
511 | - 'context' => array( 'view' ), |
|
511 | + 'context' => array('view'), |
|
512 | 512 | 'readonly' => true, |
513 | 513 | 'items' => array( |
514 | 514 | 'type' => 'string', |
@@ -517,38 +517,38 @@ discard block |
||
517 | 517 | ), |
518 | 518 | ), |
519 | 519 | 'security' => array( |
520 | - 'description' => __( 'Security.', 'woocommerce' ), |
|
520 | + 'description' => __('Security.', 'woocommerce'), |
|
521 | 521 | 'type' => 'object', |
522 | - 'context' => array( 'view' ), |
|
522 | + 'context' => array('view'), |
|
523 | 523 | 'readonly' => true, |
524 | 524 | 'properties' => array( |
525 | 525 | 'secure_connection' => array( |
526 | - 'description' => __( 'Is the connection to your store secure?', 'woocommerce' ), |
|
526 | + 'description' => __('Is the connection to your store secure?', 'woocommerce'), |
|
527 | 527 | 'type' => 'boolean', |
528 | - 'context' => array( 'view' ), |
|
528 | + 'context' => array('view'), |
|
529 | 529 | 'readonly' => true, |
530 | 530 | ), |
531 | 531 | 'hide_errors' => array( |
532 | - 'description' => __( 'Hide errors from visitors?', 'woocommerce' ), |
|
532 | + 'description' => __('Hide errors from visitors?', 'woocommerce'), |
|
533 | 533 | 'type' => 'boolean', |
534 | - 'context' => array( 'view' ), |
|
534 | + 'context' => array('view'), |
|
535 | 535 | 'readonly' => true, |
536 | 536 | ), |
537 | 537 | ), |
538 | 538 | ), |
539 | 539 | 'pages' => array( |
540 | - 'description' => __( 'WooCommerce pages.', 'woocommerce' ), |
|
540 | + 'description' => __('WooCommerce pages.', 'woocommerce'), |
|
541 | 541 | 'type' => 'array', |
542 | - 'context' => array( 'view' ), |
|
542 | + 'context' => array('view'), |
|
543 | 543 | 'readonly' => true, |
544 | 544 | 'items' => array( |
545 | 545 | 'type' => 'string', |
546 | 546 | ), |
547 | 547 | ), |
548 | 548 | 'post_type_counts' => array( |
549 | - 'description' => __( 'Post type counts.', 'woocommerce' ), |
|
549 | + 'description' => __('Post type counts.', 'woocommerce'), |
|
550 | 550 | 'type' => 'array', |
551 | - 'context' => array( 'view' ), |
|
551 | + 'context' => array('view'), |
|
552 | 552 | 'readonly' => true, |
553 | 553 | 'items' => array( |
554 | 554 | 'type' => 'string', |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | ), |
558 | 558 | ); |
559 | 559 | |
560 | - return $this->add_additional_fields_schema( $schema ); |
|
560 | + return $this->add_additional_fields_schema($schema); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -591,23 +591,23 @@ discard block |
||
591 | 591 | |
592 | 592 | // Figure out cURL version, if installed. |
593 | 593 | $curl_version = ''; |
594 | - if ( function_exists( 'curl_version' ) ) { |
|
594 | + if (function_exists('curl_version')) { |
|
595 | 595 | $curl_version = curl_version(); |
596 | 596 | $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version']; |
597 | - } elseif ( extension_loaded( 'curl' ) ) { |
|
598 | - $curl_version = __( 'cURL installed but unable to retrieve version.', 'woocommerce' ); |
|
597 | + } elseif (extension_loaded('curl')) { |
|
598 | + $curl_version = __('cURL installed but unable to retrieve version.', 'woocommerce'); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | // WP memory limit. |
602 | - $wp_memory_limit = wc_let_to_num( WP_MEMORY_LIMIT ); |
|
603 | - if ( function_exists( 'memory_get_usage' ) ) { |
|
604 | - $wp_memory_limit = max( $wp_memory_limit, wc_let_to_num( @ini_get( 'memory_limit' ) ) ); |
|
602 | + $wp_memory_limit = wc_let_to_num(WP_MEMORY_LIMIT); |
|
603 | + if (function_exists('memory_get_usage')) { |
|
604 | + $wp_memory_limit = max($wp_memory_limit, wc_let_to_num(@ini_get('memory_limit'))); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | // Test POST requests. |
608 | - $post_response_code = get_transient( 'woocommerce_test_remote_post' ); |
|
608 | + $post_response_code = get_transient('woocommerce_test_remote_post'); |
|
609 | 609 | |
610 | - if ( false === $post_response_code || is_wp_error( $post_response_code ) ) { |
|
610 | + if (false === $post_response_code || is_wp_error($post_response_code)) { |
|
611 | 611 | $response = wp_safe_remote_post( |
612 | 612 | 'https://www.paypal.com/cgi-bin/webscr', |
613 | 613 | array( |
@@ -619,63 +619,63 @@ discard block |
||
619 | 619 | ), |
620 | 620 | ) |
621 | 621 | ); |
622 | - if ( ! is_wp_error( $response ) ) { |
|
622 | + if ( ! is_wp_error($response)) { |
|
623 | 623 | $post_response_code = $response['response']['code']; |
624 | 624 | } |
625 | - set_transient( 'woocommerce_test_remote_post', $post_response_code, HOUR_IN_SECONDS ); |
|
625 | + set_transient('woocommerce_test_remote_post', $post_response_code, HOUR_IN_SECONDS); |
|
626 | 626 | } |
627 | 627 | |
628 | - $post_response_successful = ! is_wp_error( $post_response_code ) && $post_response_code >= 200 && $post_response_code < 300; |
|
628 | + $post_response_successful = ! is_wp_error($post_response_code) && $post_response_code >= 200 && $post_response_code < 300; |
|
629 | 629 | |
630 | 630 | // Test GET requests. |
631 | - $get_response_code = get_transient( 'woocommerce_test_remote_get' ); |
|
631 | + $get_response_code = get_transient('woocommerce_test_remote_get'); |
|
632 | 632 | |
633 | - if ( false === $get_response_code || is_wp_error( $get_response_code ) ) { |
|
634 | - $response = wp_safe_remote_get( 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . ( is_multisite() ? '1' : '0' ) ); |
|
635 | - if ( ! is_wp_error( $response ) ) { |
|
633 | + if (false === $get_response_code || is_wp_error($get_response_code)) { |
|
634 | + $response = wp_safe_remote_get('https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . (is_multisite() ? '1' : '0')); |
|
635 | + if ( ! is_wp_error($response)) { |
|
636 | 636 | $get_response_code = $response['response']['code']; |
637 | 637 | } |
638 | - set_transient( 'woocommerce_test_remote_get', $get_response_code, HOUR_IN_SECONDS ); |
|
638 | + set_transient('woocommerce_test_remote_get', $get_response_code, HOUR_IN_SECONDS); |
|
639 | 639 | } |
640 | 640 | |
641 | - $get_response_successful = ! is_wp_error( $get_response_code ) && $get_response_code >= 200 && $get_response_code < 300; |
|
641 | + $get_response_successful = ! is_wp_error($get_response_code) && $get_response_code >= 200 && $get_response_code < 300; |
|
642 | 642 | |
643 | 643 | $database_version = wc_get_server_database_version(); |
644 | 644 | |
645 | 645 | // Return all environment info. Described by JSON Schema. |
646 | 646 | return array( |
647 | - 'home_url' => get_option( 'home' ), |
|
648 | - 'site_url' => get_option( 'siteurl' ), |
|
647 | + 'home_url' => get_option('home'), |
|
648 | + 'site_url' => get_option('siteurl'), |
|
649 | 649 | 'version' => WC()->version, |
650 | 650 | 'log_directory' => WC_LOG_DIR, |
651 | - 'log_directory_writable' => (bool) @fopen( WC_LOG_DIR . 'test-log.log', 'a' ), |
|
652 | - 'wp_version' => get_bloginfo( 'version' ), |
|
651 | + 'log_directory_writable' => (bool) @fopen(WC_LOG_DIR . 'test-log.log', 'a'), |
|
652 | + 'wp_version' => get_bloginfo('version'), |
|
653 | 653 | 'wp_multisite' => is_multisite(), |
654 | 654 | 'wp_memory_limit' => $wp_memory_limit, |
655 | - 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ), |
|
656 | - 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ), |
|
655 | + 'wp_debug_mode' => (defined('WP_DEBUG') && WP_DEBUG), |
|
656 | + 'wp_cron' => ! (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON), |
|
657 | 657 | 'language' => get_locale(), |
658 | 658 | 'external_object_cache' => wp_using_ext_object_cache(), |
659 | - 'server_info' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? wc_clean( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '', |
|
659 | + 'server_info' => isset($_SERVER['SERVER_SOFTWARE']) ? wc_clean(wp_unslash($_SERVER['SERVER_SOFTWARE'])) : '', |
|
660 | 660 | 'php_version' => phpversion(), |
661 | - 'php_post_max_size' => wc_let_to_num( ini_get( 'post_max_size' ) ), |
|
662 | - 'php_max_execution_time' => ini_get( 'max_execution_time' ), |
|
663 | - 'php_max_input_vars' => ini_get( 'max_input_vars' ), |
|
661 | + 'php_post_max_size' => wc_let_to_num(ini_get('post_max_size')), |
|
662 | + 'php_max_execution_time' => ini_get('max_execution_time'), |
|
663 | + 'php_max_input_vars' => ini_get('max_input_vars'), |
|
664 | 664 | 'curl_version' => $curl_version, |
665 | - 'suhosin_installed' => extension_loaded( 'suhosin' ), |
|
665 | + 'suhosin_installed' => extension_loaded('suhosin'), |
|
666 | 666 | 'max_upload_size' => wp_max_upload_size(), |
667 | 667 | 'mysql_version' => $database_version['number'], |
668 | 668 | 'mysql_version_string' => $database_version['string'], |
669 | 669 | 'default_timezone' => date_default_timezone_get(), |
670 | - 'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ), |
|
671 | - 'soapclient_enabled' => class_exists( 'SoapClient' ), |
|
672 | - 'domdocument_enabled' => class_exists( 'DOMDocument' ), |
|
673 | - 'gzip_enabled' => is_callable( 'gzopen' ), |
|
674 | - 'mbstring_enabled' => extension_loaded( 'mbstring' ), |
|
670 | + 'fsockopen_or_curl_enabled' => (function_exists('fsockopen') || function_exists('curl_init')), |
|
671 | + 'soapclient_enabled' => class_exists('SoapClient'), |
|
672 | + 'domdocument_enabled' => class_exists('DOMDocument'), |
|
673 | + 'gzip_enabled' => is_callable('gzopen'), |
|
674 | + 'mbstring_enabled' => extension_loaded('mbstring'), |
|
675 | 675 | 'remote_post_successful' => $post_response_successful, |
676 | - 'remote_post_response' => is_wp_error( $post_response_code ) ? $post_response_code->get_error_message() : $post_response_code, |
|
676 | + 'remote_post_response' => is_wp_error($post_response_code) ? $post_response_code->get_error_message() : $post_response_code, |
|
677 | 677 | 'remote_get_successful' => $get_response_successful, |
678 | - 'remote_get_response' => is_wp_error( $get_response_code ) ? $get_response_code->get_error_message() : $get_response_code, |
|
678 | + 'remote_get_response' => is_wp_error($get_response_code) ? $get_response_code->get_error_message() : $get_response_code, |
|
679 | 679 | ); |
680 | 680 | } |
681 | 681 | |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | * @param string $table Table name. |
686 | 686 | * @return stromg |
687 | 687 | */ |
688 | - protected function add_db_table_prefix( $table ) { |
|
688 | + protected function add_db_table_prefix($table) { |
|
689 | 689 | global $wpdb; |
690 | 690 | return $wpdb->prefix . $table; |
691 | 691 | } |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | * |
739 | 739 | * If we changed the tables above to include the prefix, then any filters against that table could break. |
740 | 740 | */ |
741 | - $core_tables = array_map( array( $this, 'add_db_table_prefix' ), $core_tables ); |
|
741 | + $core_tables = array_map(array($this, 'add_db_table_prefix'), $core_tables); |
|
742 | 742 | |
743 | 743 | /** |
744 | 744 | * Organize WooCommerce and non-WooCommerce tables separately for display purposes later. |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | * To ensure we include all WC tables, even if they do not exist, pre-populate the WC array with all the tables. |
747 | 747 | */ |
748 | 748 | $tables = array( |
749 | - 'woocommerce' => array_fill_keys( $core_tables, false ), |
|
749 | + 'woocommerce' => array_fill_keys($core_tables, false), |
|
750 | 750 | 'other' => array(), |
751 | 751 | ); |
752 | 752 | |
@@ -755,16 +755,16 @@ discard block |
||
755 | 755 | 'index' => 0, |
756 | 756 | ); |
757 | 757 | |
758 | - $site_tables_prefix = $wpdb->get_blog_prefix( get_current_blog_id() ); |
|
759 | - $global_tables = $wpdb->tables( 'global', true ); |
|
760 | - foreach ( $database_table_information as $table ) { |
|
758 | + $site_tables_prefix = $wpdb->get_blog_prefix(get_current_blog_id()); |
|
759 | + $global_tables = $wpdb->tables('global', true); |
|
760 | + foreach ($database_table_information as $table) { |
|
761 | 761 | // Only include tables matching the prefix of the current site, this is to prevent displaying all tables on a MS install not relating to the current. |
762 | - if ( is_multisite() && 0 !== strpos( $table->name, $site_tables_prefix ) && ! in_array( $table->name, $global_tables, true ) ) { |
|
762 | + if (is_multisite() && 0 !== strpos($table->name, $site_tables_prefix) && ! in_array($table->name, $global_tables, true)) { |
|
763 | 763 | continue; |
764 | 764 | } |
765 | - $table_type = in_array( $table->name, $core_tables, true ) ? 'woocommerce' : 'other'; |
|
765 | + $table_type = in_array($table->name, $core_tables, true) ? 'woocommerce' : 'other'; |
|
766 | 766 | |
767 | - $tables[ $table_type ][ $table->name ] = array( |
|
767 | + $tables[$table_type][$table->name] = array( |
|
768 | 768 | 'data' => $table->data, |
769 | 769 | 'index' => $table->index, |
770 | 770 | 'engine' => $table->engine, |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | |
777 | 777 | // Return all database info. Described by JSON Schema. |
778 | 778 | return array( |
779 | - 'wc_database_version' => get_option( 'woocommerce_db_version' ), |
|
779 | + 'wc_database_version' => get_option('woocommerce_db_version'), |
|
780 | 780 | 'database_prefix' => $wpdb->prefix, |
781 | 781 | 'maxmind_geoip_database' => \WC_Geolocation::get_local_database_path(), |
782 | 782 | 'database_tables' => $tables, |
@@ -792,9 +792,9 @@ discard block |
||
792 | 792 | public function get_post_type_counts() { |
793 | 793 | global $wpdb; |
794 | 794 | |
795 | - $post_type_counts = $wpdb->get_results( "SELECT post_type AS 'type', count(1) AS 'count' FROM {$wpdb->posts} GROUP BY post_type;" ); |
|
795 | + $post_type_counts = $wpdb->get_results("SELECT post_type AS 'type', count(1) AS 'count' FROM {$wpdb->posts} GROUP BY post_type;"); |
|
796 | 796 | |
797 | - return is_array( $post_type_counts ) ? $post_type_counts : array(); |
|
797 | + return is_array($post_type_counts) ? $post_type_counts : array(); |
|
798 | 798 | } |
799 | 799 | |
800 | 800 | /** |
@@ -805,21 +805,21 @@ discard block |
||
805 | 805 | public function get_active_plugins() { |
806 | 806 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
807 | 807 | |
808 | - if ( ! function_exists( 'get_plugin_data' ) ) { |
|
808 | + if ( ! function_exists('get_plugin_data')) { |
|
809 | 809 | return array(); |
810 | 810 | } |
811 | 811 | |
812 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
813 | - if ( is_multisite() ) { |
|
814 | - $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
|
815 | - $active_plugins = array_merge( $active_plugins, $network_activated_plugins ); |
|
812 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
813 | + if (is_multisite()) { |
|
814 | + $network_activated_plugins = array_keys(get_site_option('active_sitewide_plugins', array())); |
|
815 | + $active_plugins = array_merge($active_plugins, $network_activated_plugins); |
|
816 | 816 | } |
817 | 817 | |
818 | 818 | $active_plugins_data = array(); |
819 | 819 | |
820 | - foreach ( $active_plugins as $plugin ) { |
|
821 | - $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
|
822 | - $active_plugins_data[] = $this->format_plugin_data( $plugin, $data ); |
|
820 | + foreach ($active_plugins as $plugin) { |
|
821 | + $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
822 | + $active_plugins_data[] = $this->format_plugin_data($plugin, $data); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | return $active_plugins_data; |
@@ -833,25 +833,25 @@ discard block |
||
833 | 833 | public function get_inactive_plugins() { |
834 | 834 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
835 | 835 | |
836 | - if ( ! function_exists( 'get_plugins' ) ) { |
|
836 | + if ( ! function_exists('get_plugins')) { |
|
837 | 837 | return array(); |
838 | 838 | } |
839 | 839 | |
840 | 840 | $plugins = get_plugins(); |
841 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
841 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
842 | 842 | |
843 | - if ( is_multisite() ) { |
|
844 | - $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
|
845 | - $active_plugins = array_merge( $active_plugins, $network_activated_plugins ); |
|
843 | + if (is_multisite()) { |
|
844 | + $network_activated_plugins = array_keys(get_site_option('active_sitewide_plugins', array())); |
|
845 | + $active_plugins = array_merge($active_plugins, $network_activated_plugins); |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | $plugins_data = array(); |
849 | 849 | |
850 | - foreach ( $plugins as $plugin => $data ) { |
|
851 | - if ( in_array( $plugin, $active_plugins, true ) ) { |
|
850 | + foreach ($plugins as $plugin => $data) { |
|
851 | + if (in_array($plugin, $active_plugins, true)) { |
|
852 | 852 | continue; |
853 | 853 | } |
854 | - $plugins_data[] = $this->format_plugin_data( $plugin, $data ); |
|
854 | + $plugins_data[] = $this->format_plugin_data($plugin, $data); |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | return $plugins_data; |
@@ -865,23 +865,23 @@ discard block |
||
865 | 865 | * @param array $data Plugin data from WP. |
866 | 866 | * @return array Formatted data. |
867 | 867 | */ |
868 | - protected function format_plugin_data( $plugin, $data ) { |
|
868 | + protected function format_plugin_data($plugin, $data) { |
|
869 | 869 | require_once ABSPATH . 'wp-admin/includes/update.php'; |
870 | 870 | |
871 | - if ( ! function_exists( 'get_plugin_updates' ) ) { |
|
871 | + if ( ! function_exists('get_plugin_updates')) { |
|
872 | 872 | return array(); |
873 | 873 | } |
874 | 874 | |
875 | 875 | // Use WP API to lookup latest updates for plugins. WC_Helper injects updates for premium plugins. |
876 | - if ( empty( $this->available_updates ) ) { |
|
876 | + if (empty($this->available_updates)) { |
|
877 | 877 | $this->available_updates = get_plugin_updates(); |
878 | 878 | } |
879 | 879 | |
880 | 880 | $version_latest = $data['Version']; |
881 | 881 | |
882 | 882 | // Find latest version. |
883 | - if ( isset( $this->available_updates[ $plugin ]->update->new_version ) ) { |
|
884 | - $version_latest = $this->available_updates[ $plugin ]->update->new_version; |
|
883 | + if (isset($this->available_updates[$plugin]->update->new_version)) { |
|
884 | + $version_latest = $this->available_updates[$plugin]->update->new_version; |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | return array( |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | 'version_latest' => $version_latest, |
892 | 892 | 'url' => $data['PluginURI'], |
893 | 893 | 'author_name' => $data['AuthorName'], |
894 | - 'author_url' => esc_url_raw( $data['AuthorURI'] ), |
|
894 | + 'author_url' => esc_url_raw($data['AuthorURI']), |
|
895 | 895 | 'network_activated' => $data['Network'], |
896 | 896 | ); |
897 | 897 | } |
@@ -908,7 +908,7 @@ discard block |
||
908 | 908 | 'dropins' => array(), |
909 | 909 | 'mu_plugins' => array(), |
910 | 910 | ); |
911 | - foreach ( $dropins as $key => $dropin ) { |
|
911 | + foreach ($dropins as $key => $dropin) { |
|
912 | 912 | $plugins['dropins'][] = array( |
913 | 913 | 'plugin' => $key, |
914 | 914 | 'name' => $dropin['Name'], |
@@ -916,14 +916,14 @@ discard block |
||
916 | 916 | } |
917 | 917 | |
918 | 918 | $mu_plugins = get_mu_plugins(); |
919 | - foreach ( $mu_plugins as $plugin => $mu_plugin ) { |
|
919 | + foreach ($mu_plugins as $plugin => $mu_plugin) { |
|
920 | 920 | $plugins['mu_plugins'][] = array( |
921 | 921 | 'plugin' => $plugin, |
922 | 922 | 'name' => $mu_plugin['Name'], |
923 | 923 | 'version' => $mu_plugin['Version'], |
924 | 924 | 'url' => $mu_plugin['PluginURI'], |
925 | 925 | 'author_name' => $mu_plugin['AuthorName'], |
926 | - 'author_url' => esc_url_raw( $mu_plugin['AuthorURI'] ), |
|
926 | + 'author_url' => esc_url_raw($mu_plugin['AuthorURI']), |
|
927 | 927 | ); |
928 | 928 | } |
929 | 929 | return $plugins; |
@@ -940,12 +940,12 @@ discard block |
||
940 | 940 | |
941 | 941 | // Get parent theme info if this theme is a child theme, otherwise |
942 | 942 | // pass empty info in the response. |
943 | - if ( is_child_theme() ) { |
|
944 | - $parent_theme = wp_get_theme( $active_theme->template ); |
|
943 | + if (is_child_theme()) { |
|
944 | + $parent_theme = wp_get_theme($active_theme->template); |
|
945 | 945 | $parent_theme_info = array( |
946 | 946 | 'parent_name' => $parent_theme->name, |
947 | 947 | 'parent_version' => $parent_theme->version, |
948 | - 'parent_version_latest' => \WC_Admin_Status::get_latest_theme_version( $parent_theme ), |
|
948 | + 'parent_version_latest' => \WC_Admin_Status::get_latest_theme_version($parent_theme), |
|
949 | 949 | 'parent_author_url' => $parent_theme->{'Author URI'}, |
950 | 950 | ); |
951 | 951 | } else { |
@@ -963,34 +963,34 @@ discard block |
||
963 | 963 | */ |
964 | 964 | $override_files = array(); |
965 | 965 | $outdated_templates = false; |
966 | - $scan_files = \WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates/' ); |
|
967 | - foreach ( $scan_files as $file ) { |
|
968 | - $located = apply_filters( 'wc_get_template', $file, $file, array(), WC()->template_path(), WC()->plugin_path() . '/templates/' ); |
|
966 | + $scan_files = \WC_Admin_Status::scan_template_files(WC()->plugin_path() . '/templates/'); |
|
967 | + foreach ($scan_files as $file) { |
|
968 | + $located = apply_filters('wc_get_template', $file, $file, array(), WC()->template_path(), WC()->plugin_path() . '/templates/'); |
|
969 | 969 | |
970 | - if ( file_exists( $located ) ) { |
|
970 | + if (file_exists($located)) { |
|
971 | 971 | $theme_file = $located; |
972 | - } elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { |
|
972 | + } elseif (file_exists(get_stylesheet_directory() . '/' . $file)) { |
|
973 | 973 | $theme_file = get_stylesheet_directory() . '/' . $file; |
974 | - } elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) { |
|
974 | + } elseif (file_exists(get_stylesheet_directory() . '/' . WC()->template_path() . $file)) { |
|
975 | 975 | $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file; |
976 | - } elseif ( file_exists( get_template_directory() . '/' . $file ) ) { |
|
976 | + } elseif (file_exists(get_template_directory() . '/' . $file)) { |
|
977 | 977 | $theme_file = get_template_directory() . '/' . $file; |
978 | - } elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) { |
|
978 | + } elseif (file_exists(get_template_directory() . '/' . WC()->template_path() . $file)) { |
|
979 | 979 | $theme_file = get_template_directory() . '/' . WC()->template_path() . $file; |
980 | 980 | } else { |
981 | 981 | $theme_file = false; |
982 | 982 | } |
983 | 983 | |
984 | - if ( ! empty( $theme_file ) ) { |
|
985 | - $core_version = \WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file ); |
|
986 | - $theme_version = \WC_Admin_Status::get_file_version( $theme_file ); |
|
987 | - if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) { |
|
988 | - if ( ! $outdated_templates ) { |
|
984 | + if ( ! empty($theme_file)) { |
|
985 | + $core_version = \WC_Admin_Status::get_file_version(WC()->plugin_path() . '/templates/' . $file); |
|
986 | + $theme_version = \WC_Admin_Status::get_file_version($theme_file); |
|
987 | + if ($core_version && (empty($theme_version) || version_compare($theme_version, $core_version, '<'))) { |
|
988 | + if ( ! $outdated_templates) { |
|
989 | 989 | $outdated_templates = true; |
990 | 990 | } |
991 | 991 | } |
992 | 992 | $override_files[] = array( |
993 | - 'file' => str_replace( WP_CONTENT_DIR . '/themes/', '', $theme_file ), |
|
993 | + 'file' => str_replace(WP_CONTENT_DIR . '/themes/', '', $theme_file), |
|
994 | 994 | 'version' => $theme_version, |
995 | 995 | 'core_version' => $core_version, |
996 | 996 | ); |
@@ -1000,16 +1000,16 @@ discard block |
||
1000 | 1000 | $active_theme_info = array( |
1001 | 1001 | 'name' => $active_theme->name, |
1002 | 1002 | 'version' => $active_theme->version, |
1003 | - 'version_latest' => \WC_Admin_Status::get_latest_theme_version( $active_theme ), |
|
1004 | - 'author_url' => esc_url_raw( $active_theme->{'Author URI'} ), |
|
1003 | + 'version_latest' => \WC_Admin_Status::get_latest_theme_version($active_theme), |
|
1004 | + 'author_url' => esc_url_raw($active_theme->{'Author URI'} ), |
|
1005 | 1005 | 'is_child_theme' => is_child_theme(), |
1006 | - 'has_woocommerce_support' => current_theme_supports( 'woocommerce' ), |
|
1007 | - 'has_woocommerce_file' => ( file_exists( get_stylesheet_directory() . '/woocommerce.php' ) || file_exists( get_template_directory() . '/woocommerce.php' ) ), |
|
1006 | + 'has_woocommerce_support' => current_theme_supports('woocommerce'), |
|
1007 | + 'has_woocommerce_file' => (file_exists(get_stylesheet_directory() . '/woocommerce.php') || file_exists(get_template_directory() . '/woocommerce.php')), |
|
1008 | 1008 | 'has_outdated_templates' => $outdated_templates, |
1009 | 1009 | 'overrides' => $override_files, |
1010 | 1010 | ); |
1011 | 1011 | |
1012 | - return array_merge( $active_theme_info, $parent_theme_info ); |
|
1012 | + return array_merge($active_theme_info, $parent_theme_info); |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | 1015 | /** |
@@ -1021,36 +1021,36 @@ discard block |
||
1021 | 1021 | public function get_settings() { |
1022 | 1022 | // Get a list of terms used for product/order taxonomies. |
1023 | 1023 | $term_response = array(); |
1024 | - $terms = get_terms( 'product_type', array( 'hide_empty' => 0 ) ); |
|
1025 | - foreach ( $terms as $term ) { |
|
1026 | - $term_response[ $term->slug ] = strtolower( $term->name ); |
|
1024 | + $terms = get_terms('product_type', array('hide_empty' => 0)); |
|
1025 | + foreach ($terms as $term) { |
|
1026 | + $term_response[$term->slug] = strtolower($term->name); |
|
1027 | 1027 | } |
1028 | 1028 | |
1029 | 1029 | // Get a list of terms used for product visibility. |
1030 | 1030 | $product_visibility_terms = array(); |
1031 | - $terms = get_terms( 'product_visibility', array( 'hide_empty' => 0 ) ); |
|
1032 | - foreach ( $terms as $term ) { |
|
1033 | - $product_visibility_terms[ $term->slug ] = strtolower( $term->name ); |
|
1031 | + $terms = get_terms('product_visibility', array('hide_empty' => 0)); |
|
1032 | + foreach ($terms as $term) { |
|
1033 | + $product_visibility_terms[$term->slug] = strtolower($term->name); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | // Check if WooCommerce.com account is connected. |
1037 | 1037 | $woo_com_connected = 'no'; |
1038 | - $helper_options = get_option( 'woocommerce_helper_data', array() ); |
|
1039 | - if ( array_key_exists( 'auth', $helper_options ) && ! empty( $helper_options['auth'] ) ) { |
|
1038 | + $helper_options = get_option('woocommerce_helper_data', array()); |
|
1039 | + if (array_key_exists('auth', $helper_options) && ! empty($helper_options['auth'])) { |
|
1040 | 1040 | $woo_com_connected = 'yes'; |
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | // Return array of useful settings for debugging. |
1044 | 1044 | return array( |
1045 | - 'api_enabled' => 'yes' === get_option( 'woocommerce_api_enabled' ), |
|
1046 | - 'force_ssl' => 'yes' === get_option( 'woocommerce_force_ssl_checkout' ), |
|
1045 | + 'api_enabled' => 'yes' === get_option('woocommerce_api_enabled'), |
|
1046 | + 'force_ssl' => 'yes' === get_option('woocommerce_force_ssl_checkout'), |
|
1047 | 1047 | 'currency' => get_woocommerce_currency(), |
1048 | 1048 | 'currency_symbol' => get_woocommerce_currency_symbol(), |
1049 | - 'currency_position' => get_option( 'woocommerce_currency_pos' ), |
|
1049 | + 'currency_position' => get_option('woocommerce_currency_pos'), |
|
1050 | 1050 | 'thousand_separator' => wc_get_price_thousand_separator(), |
1051 | 1051 | 'decimal_separator' => wc_get_price_decimal_separator(), |
1052 | 1052 | 'number_of_decimals' => wc_get_price_decimals(), |
1053 | - 'geolocation_enabled' => in_array( get_option( 'woocommerce_default_customer_address' ), array( 'geolocation_ajax', 'geolocation' ) ), |
|
1053 | + 'geolocation_enabled' => in_array(get_option('woocommerce_default_customer_address'), array('geolocation_ajax', 'geolocation')), |
|
1054 | 1054 | 'taxonomies' => $term_response, |
1055 | 1055 | 'product_visibility_terms' => $product_visibility_terms, |
1056 | 1056 | 'woocommerce_com_connected' => $woo_com_connected, |
@@ -1063,10 +1063,10 @@ discard block |
||
1063 | 1063 | * @return array |
1064 | 1064 | */ |
1065 | 1065 | public function get_security_info() { |
1066 | - $check_page = wc_get_page_permalink( 'shop' ); |
|
1066 | + $check_page = wc_get_page_permalink('shop'); |
|
1067 | 1067 | return array( |
1068 | - 'secure_connection' => 'https' === substr( $check_page, 0, 5 ), |
|
1069 | - 'hide_errors' => ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ), |
|
1068 | + 'secure_connection' => 'https' === substr($check_page, 0, 5), |
|
1069 | + 'hide_errors' => ! (defined('WP_DEBUG') && defined('WP_DEBUG_DISPLAY') && WP_DEBUG && WP_DEBUG_DISPLAY) || 0 === intval(ini_get('display_errors')), |
|
1070 | 1070 | ); |
1071 | 1071 | } |
1072 | 1072 | |
@@ -1079,31 +1079,31 @@ discard block |
||
1079 | 1079 | public function get_pages() { |
1080 | 1080 | // WC pages to check against. |
1081 | 1081 | $check_pages = array( |
1082 | - _x( 'Shop base', 'Page setting', 'woocommerce' ) => array( |
|
1082 | + _x('Shop base', 'Page setting', 'woocommerce') => array( |
|
1083 | 1083 | 'option' => 'woocommerce_shop_page_id', |
1084 | 1084 | 'shortcode' => '', |
1085 | 1085 | ), |
1086 | - _x( 'Cart', 'Page setting', 'woocommerce' ) => array( |
|
1086 | + _x('Cart', 'Page setting', 'woocommerce') => array( |
|
1087 | 1087 | 'option' => 'woocommerce_cart_page_id', |
1088 | - 'shortcode' => '[' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']', |
|
1088 | + 'shortcode' => '[' . apply_filters('woocommerce_cart_shortcode_tag', 'woocommerce_cart') . ']', |
|
1089 | 1089 | ), |
1090 | - _x( 'Checkout', 'Page setting', 'woocommerce' ) => array( |
|
1090 | + _x('Checkout', 'Page setting', 'woocommerce') => array( |
|
1091 | 1091 | 'option' => 'woocommerce_checkout_page_id', |
1092 | - 'shortcode' => '[' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']', |
|
1092 | + 'shortcode' => '[' . apply_filters('woocommerce_checkout_shortcode_tag', 'woocommerce_checkout') . ']', |
|
1093 | 1093 | ), |
1094 | - _x( 'My account', 'Page setting', 'woocommerce' ) => array( |
|
1094 | + _x('My account', 'Page setting', 'woocommerce') => array( |
|
1095 | 1095 | 'option' => 'woocommerce_myaccount_page_id', |
1096 | - 'shortcode' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']', |
|
1096 | + 'shortcode' => '[' . apply_filters('woocommerce_my_account_shortcode_tag', 'woocommerce_my_account') . ']', |
|
1097 | 1097 | ), |
1098 | - _x( 'Terms and conditions', 'Page setting', 'woocommerce' ) => array( |
|
1098 | + _x('Terms and conditions', 'Page setting', 'woocommerce') => array( |
|
1099 | 1099 | 'option' => 'woocommerce_terms_page_id', |
1100 | 1100 | 'shortcode' => '', |
1101 | 1101 | ), |
1102 | 1102 | ); |
1103 | 1103 | |
1104 | 1104 | $pages_output = array(); |
1105 | - foreach ( $check_pages as $page_name => $values ) { |
|
1106 | - $page_id = get_option( $values['option'] ); |
|
1105 | + foreach ($check_pages as $page_name => $values) { |
|
1106 | + $page_id = get_option($values['option']); |
|
1107 | 1107 | $page_set = false; |
1108 | 1108 | $page_exists = false; |
1109 | 1109 | $page_visible = false; |
@@ -1111,21 +1111,21 @@ discard block |
||
1111 | 1111 | $shortcode_required = false; |
1112 | 1112 | |
1113 | 1113 | // Page checks. |
1114 | - if ( $page_id ) { |
|
1114 | + if ($page_id) { |
|
1115 | 1115 | $page_set = true; |
1116 | 1116 | } |
1117 | - if ( get_post( $page_id ) ) { |
|
1117 | + if (get_post($page_id)) { |
|
1118 | 1118 | $page_exists = true; |
1119 | 1119 | } |
1120 | - if ( 'publish' === get_post_status( $page_id ) ) { |
|
1120 | + if ('publish' === get_post_status($page_id)) { |
|
1121 | 1121 | $page_visible = true; |
1122 | 1122 | } |
1123 | 1123 | |
1124 | 1124 | // Shortcode checks. |
1125 | - if ( $values['shortcode'] && get_post( $page_id ) ) { |
|
1125 | + if ($values['shortcode'] && get_post($page_id)) { |
|
1126 | 1126 | $shortcode_required = true; |
1127 | - $page = get_post( $page_id ); |
|
1128 | - if ( strstr( $page->post_content, $values['shortcode'] ) ) { |
|
1127 | + $page = get_post($page_id); |
|
1128 | + if (strstr($page->post_content, $values['shortcode'])) { |
|
1129 | 1129 | $shortcode_present = true; |
1130 | 1130 | } |
1131 | 1131 | } |
@@ -1153,7 +1153,7 @@ discard block |
||
1153 | 1153 | */ |
1154 | 1154 | public function get_collection_params() { |
1155 | 1155 | return array( |
1156 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
1156 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
1157 | 1157 | ); |
1158 | 1158 | } |
1159 | 1159 | |
@@ -1164,11 +1164,11 @@ discard block |
||
1164 | 1164 | * @param \WP_REST_Request $request Request object. |
1165 | 1165 | * @return \WP_REST_Response |
1166 | 1166 | */ |
1167 | - public function prepare_item_for_response( $system_status, $request ) { |
|
1168 | - $data = $this->add_additional_fields_to_object( $system_status, $request ); |
|
1169 | - $data = $this->filter_response_by_context( $data, 'view' ); |
|
1167 | + public function prepare_item_for_response($system_status, $request) { |
|
1168 | + $data = $this->add_additional_fields_to_object($system_status, $request); |
|
1169 | + $data = $this->filter_response_by_context($data, 'view'); |
|
1170 | 1170 | |
1171 | - $response = rest_ensure_response( $data ); |
|
1171 | + $response = rest_ensure_response($data); |
|
1172 | 1172 | |
1173 | 1173 | /** |
1174 | 1174 | * Filter the system status returned from the REST API. |
@@ -1177,6 +1177,6 @@ discard block |
||
1177 | 1177 | * @param mixed $system_status System status |
1178 | 1178 | * @param \WP_REST_Request $request Request object. |
1179 | 1179 | */ |
1180 | - return apply_filters( 'woocommerce_rest_prepare_system_status', $response, $system_status, $request ); |
|
1180 | + return apply_filters('woocommerce_rest_prepare_system_status', $response, $system_status, $request); |
|
1181 | 1181 | } |
1182 | 1182 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Shipping Zone Methods class. |
@@ -26,31 +26,31 @@ discard block |
||
26 | 26 | array( |
27 | 27 | 'args' => array( |
28 | 28 | 'zone_id' => array( |
29 | - 'description' => __( 'Unique ID for the zone.', 'woocommerce' ), |
|
29 | + 'description' => __('Unique ID for the zone.', 'woocommerce'), |
|
30 | 30 | 'type' => 'integer', |
31 | 31 | ), |
32 | 32 | ), |
33 | 33 | array( |
34 | 34 | 'methods' => \WP_REST_Server::READABLE, |
35 | - 'callback' => array( $this, 'get_items' ), |
|
36 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
35 | + 'callback' => array($this, 'get_items'), |
|
36 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
37 | 37 | ), |
38 | 38 | array( |
39 | 39 | 'methods' => \WP_REST_Server::CREATABLE, |
40 | - 'callback' => array( $this, 'create_item' ), |
|
41 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
40 | + 'callback' => array($this, 'create_item'), |
|
41 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
42 | 42 | 'args' => array_merge( |
43 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
43 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
44 | 44 | array( |
45 | 45 | 'method_id' => array( |
46 | 46 | 'required' => true, |
47 | 47 | 'readonly' => false, |
48 | - 'description' => __( 'Shipping method ID.', 'woocommerce' ), |
|
48 | + 'description' => __('Shipping method ID.', 'woocommerce'), |
|
49 | 49 | ), |
50 | 50 | ) |
51 | 51 | ), |
52 | 52 | ), |
53 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
53 | + 'schema' => array($this, 'get_public_item_schema'), |
|
54 | 54 | ), |
55 | 55 | true |
56 | 56 | ); |
@@ -61,38 +61,38 @@ discard block |
||
61 | 61 | array( |
62 | 62 | 'args' => array( |
63 | 63 | 'zone_id' => array( |
64 | - 'description' => __( 'Unique ID for the zone.', 'woocommerce' ), |
|
64 | + 'description' => __('Unique ID for the zone.', 'woocommerce'), |
|
65 | 65 | 'type' => 'integer', |
66 | 66 | ), |
67 | 67 | 'instance_id' => array( |
68 | - 'description' => __( 'Unique ID for the instance.', 'woocommerce' ), |
|
68 | + 'description' => __('Unique ID for the instance.', 'woocommerce'), |
|
69 | 69 | 'type' => 'integer', |
70 | 70 | ), |
71 | 71 | ), |
72 | 72 | array( |
73 | 73 | 'methods' => \WP_REST_Server::READABLE, |
74 | - 'callback' => array( $this, 'get_item' ), |
|
75 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
74 | + 'callback' => array($this, 'get_item'), |
|
75 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
76 | 76 | ), |
77 | 77 | array( |
78 | 78 | 'methods' => \WP_REST_Server::EDITABLE, |
79 | - 'callback' => array( $this, 'update_item' ), |
|
80 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
81 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
79 | + 'callback' => array($this, 'update_item'), |
|
80 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
81 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
82 | 82 | ), |
83 | 83 | array( |
84 | 84 | 'methods' => \WP_REST_Server::DELETABLE, |
85 | - 'callback' => array( $this, 'delete_item' ), |
|
86 | - 'permission_callback' => array( $this, 'delete_items_permissions_check' ), |
|
85 | + 'callback' => array($this, 'delete_item'), |
|
86 | + 'permission_callback' => array($this, 'delete_items_permissions_check'), |
|
87 | 87 | 'args' => array( |
88 | 88 | 'force' => array( |
89 | 89 | 'default' => false, |
90 | 90 | 'type' => 'boolean', |
91 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
91 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
92 | 92 | ), |
93 | 93 | ), |
94 | 94 | ), |
95 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
95 | + 'schema' => array($this, 'get_public_item_schema'), |
|
96 | 96 | ), |
97 | 97 | true |
98 | 98 | ); |
@@ -104,10 +104,10 @@ discard block |
||
104 | 104 | * @param \WP_REST_Request $request Request data. |
105 | 105 | * @return \WP_REST_Response|\WP_Error |
106 | 106 | */ |
107 | - public function get_item( $request ) { |
|
108 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
107 | + public function get_item($request) { |
|
108 | + $zone = $this->get_zone($request['zone_id']); |
|
109 | 109 | |
110 | - if ( is_wp_error( $zone ) ) { |
|
110 | + if (is_wp_error($zone)) { |
|
111 | 111 | return $zone; |
112 | 112 | } |
113 | 113 | |
@@ -115,20 +115,20 @@ discard block |
||
115 | 115 | $methods = $zone->get_shipping_methods(); |
116 | 116 | $method = false; |
117 | 117 | |
118 | - foreach ( $methods as $method_obj ) { |
|
119 | - if ( $instance_id === $method_obj->instance_id ) { |
|
118 | + foreach ($methods as $method_obj) { |
|
119 | + if ($instance_id === $method_obj->instance_id) { |
|
120 | 120 | $method = $method_obj; |
121 | 121 | break; |
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | - if ( false === $method ) { |
|
126 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
125 | + if (false === $method) { |
|
126 | + return new \WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
127 | 127 | } |
128 | 128 | |
129 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
129 | + $data = $this->prepare_item_for_response($method, $request); |
|
130 | 130 | |
131 | - return rest_ensure_response( $data ); |
|
131 | + return rest_ensure_response($data); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -137,22 +137,22 @@ discard block |
||
137 | 137 | * @param \WP_REST_Request $request Request data. |
138 | 138 | * @return \WP_REST_Response|\WP_Error |
139 | 139 | */ |
140 | - public function get_items( $request ) { |
|
141 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
140 | + public function get_items($request) { |
|
141 | + $zone = $this->get_zone($request['zone_id']); |
|
142 | 142 | |
143 | - if ( is_wp_error( $zone ) ) { |
|
143 | + if (is_wp_error($zone)) { |
|
144 | 144 | return $zone; |
145 | 145 | } |
146 | 146 | |
147 | 147 | $methods = $zone->get_shipping_methods(); |
148 | 148 | $data = array(); |
149 | 149 | |
150 | - foreach ( $methods as $method_obj ) { |
|
151 | - $method = $this->prepare_item_for_response( $method_obj, $request ); |
|
150 | + foreach ($methods as $method_obj) { |
|
151 | + $method = $this->prepare_item_for_response($method_obj, $request); |
|
152 | 152 | $data[] = $method; |
153 | 153 | } |
154 | 154 | |
155 | - return rest_ensure_response( $data ); |
|
155 | + return rest_ensure_response($data); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -161,34 +161,34 @@ discard block |
||
161 | 161 | * @param \WP_REST_Request $request Full details about the request. |
162 | 162 | * @return \WP_REST_Request|\WP_Error |
163 | 163 | */ |
164 | - public function create_item( $request ) { |
|
164 | + public function create_item($request) { |
|
165 | 165 | $method_id = $request['method_id']; |
166 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
167 | - if ( is_wp_error( $zone ) ) { |
|
166 | + $zone = $this->get_zone($request['zone_id']); |
|
167 | + if (is_wp_error($zone)) { |
|
168 | 168 | return $zone; |
169 | 169 | } |
170 | 170 | |
171 | - $instance_id = $zone->add_shipping_method( $method_id ); |
|
171 | + $instance_id = $zone->add_shipping_method($method_id); |
|
172 | 172 | $methods = $zone->get_shipping_methods(); |
173 | 173 | $method = false; |
174 | - foreach ( $methods as $method_obj ) { |
|
175 | - if ( $instance_id === $method_obj->instance_id ) { |
|
174 | + foreach ($methods as $method_obj) { |
|
175 | + if ($instance_id === $method_obj->instance_id) { |
|
176 | 176 | $method = $method_obj; |
177 | 177 | break; |
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | - if ( false === $method ) { |
|
182 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_not_created', __( 'Resource cannot be created.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
181 | + if (false === $method) { |
|
182 | + return new \WP_Error('woocommerce_rest_shipping_zone_not_created', __('Resource cannot be created.', 'woocommerce'), array('status' => 500)); |
|
183 | 183 | } |
184 | 184 | |
185 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
186 | - if ( is_wp_error( $method ) ) { |
|
185 | + $method = $this->update_fields($instance_id, $method, $request); |
|
186 | + if (is_wp_error($method)) { |
|
187 | 187 | return $method; |
188 | 188 | } |
189 | 189 | |
190 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
191 | - return rest_ensure_response( $data ); |
|
190 | + $data = $this->prepare_item_for_response($method, $request); |
|
191 | + return rest_ensure_response($data); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -197,9 +197,9 @@ discard block |
||
197 | 197 | * @param \WP_REST_Request $request Full details about the request. |
198 | 198 | * @return \WP_Error|boolean |
199 | 199 | */ |
200 | - public function delete_item( $request ) { |
|
201 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
202 | - if ( is_wp_error( $zone ) ) { |
|
200 | + public function delete_item($request) { |
|
201 | + $zone = $this->get_zone($request['zone_id']); |
|
202 | + if (is_wp_error($zone)) { |
|
203 | 203 | return $zone; |
204 | 204 | } |
205 | 205 | |
@@ -207,34 +207,34 @@ discard block |
||
207 | 207 | $force = $request['force']; |
208 | 208 | |
209 | 209 | // We don't support trashing for this type, error out. |
210 | - if ( ! $force ) { |
|
211 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Shipping methods do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
210 | + if ( ! $force) { |
|
211 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Shipping methods do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | $methods = $zone->get_shipping_methods(); |
215 | 215 | $method = false; |
216 | 216 | |
217 | - foreach ( $methods as $method_obj ) { |
|
218 | - if ( $instance_id === $method_obj->instance_id ) { |
|
217 | + foreach ($methods as $method_obj) { |
|
218 | + if ($instance_id === $method_obj->instance_id) { |
|
219 | 219 | $method = $method_obj; |
220 | 220 | break; |
221 | 221 | } |
222 | 222 | } |
223 | 223 | |
224 | - if ( false === $method ) { |
|
225 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
224 | + if (false === $method) { |
|
225 | + return new \WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
226 | 226 | } |
227 | 227 | |
228 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
229 | - if ( is_wp_error( $method ) ) { |
|
228 | + $method = $this->update_fields($instance_id, $method, $request); |
|
229 | + if (is_wp_error($method)) { |
|
230 | 230 | return $method; |
231 | 231 | } |
232 | 232 | |
233 | - $request->set_param( 'context', 'view' ); |
|
234 | - $previous = $this->prepare_item_for_response( $method, $request ); |
|
233 | + $request->set_param('context', 'view'); |
|
234 | + $previous = $this->prepare_item_for_response($method, $request); |
|
235 | 235 | |
236 | 236 | // Actually delete. |
237 | - $zone->delete_shipping_method( $instance_id ); |
|
237 | + $zone->delete_shipping_method($instance_id); |
|
238 | 238 | $response = new \WP_REST_Response(); |
239 | 239 | $response->set_data( |
240 | 240 | array( |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @param \WP_REST_Response $response The response data. |
251 | 251 | * @param \WP_REST_Request $request The request sent to the API. |
252 | 252 | */ |
253 | - do_action( 'woocommerce_rest_delete_shipping_zone_method', $method, $response, $request ); |
|
253 | + do_action('woocommerce_rest_delete_shipping_zone_method', $method, $response, $request); |
|
254 | 254 | |
255 | 255 | return $response; |
256 | 256 | } |
@@ -261,9 +261,9 @@ discard block |
||
261 | 261 | * @param \WP_REST_Request $request Request data. |
262 | 262 | * @return \WP_REST_Response|\WP_Error |
263 | 263 | */ |
264 | - public function update_item( $request ) { |
|
265 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
266 | - if ( is_wp_error( $zone ) ) { |
|
264 | + public function update_item($request) { |
|
265 | + $zone = $this->get_zone($request['zone_id']); |
|
266 | + if (is_wp_error($zone)) { |
|
267 | 267 | return $zone; |
268 | 268 | } |
269 | 269 | |
@@ -271,24 +271,24 @@ discard block |
||
271 | 271 | $methods = $zone->get_shipping_methods(); |
272 | 272 | $method = false; |
273 | 273 | |
274 | - foreach ( $methods as $method_obj ) { |
|
275 | - if ( $instance_id === $method_obj->instance_id ) { |
|
274 | + foreach ($methods as $method_obj) { |
|
275 | + if ($instance_id === $method_obj->instance_id) { |
|
276 | 276 | $method = $method_obj; |
277 | 277 | break; |
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
281 | - if ( false === $method ) { |
|
282 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
281 | + if (false === $method) { |
|
282 | + return new \WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
283 | 283 | } |
284 | 284 | |
285 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
286 | - if ( is_wp_error( $method ) ) { |
|
285 | + $method = $this->update_fields($instance_id, $method, $request); |
|
286 | + if (is_wp_error($method)) { |
|
287 | 287 | return $method; |
288 | 288 | } |
289 | 289 | |
290 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
291 | - return rest_ensure_response( $data ); |
|
290 | + $data = $this->prepare_item_for_response($method, $request); |
|
291 | + return rest_ensure_response($data); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -300,47 +300,47 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @return WC_Shipping_Method |
302 | 302 | */ |
303 | - public function update_fields( $instance_id, $method, $request ) { |
|
303 | + public function update_fields($instance_id, $method, $request) { |
|
304 | 304 | global $wpdb; |
305 | 305 | |
306 | 306 | // Update settings if present. |
307 | - if ( isset( $request['settings'] ) ) { |
|
307 | + if (isset($request['settings'])) { |
|
308 | 308 | $method->init_instance_settings(); |
309 | 309 | $instance_settings = $method->instance_settings; |
310 | 310 | $errors_found = false; |
311 | - foreach ( $method->get_instance_form_fields() as $key => $field ) { |
|
312 | - if ( isset( $request['settings'][ $key ] ) ) { |
|
313 | - if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) { |
|
314 | - $value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field ); |
|
311 | + foreach ($method->get_instance_form_fields() as $key => $field) { |
|
312 | + if (isset($request['settings'][$key])) { |
|
313 | + if (is_callable(array($this, 'validate_setting_' . $field['type'] . '_field'))) { |
|
314 | + $value = $this->{'validate_setting_' . $field['type'] . '_field'}($request['settings'][$key], $field); |
|
315 | 315 | } else { |
316 | - $value = $this->validate_setting_text_field( $request['settings'][ $key ], $field ); |
|
316 | + $value = $this->validate_setting_text_field($request['settings'][$key], $field); |
|
317 | 317 | } |
318 | - if ( is_wp_error( $value ) ) { |
|
318 | + if (is_wp_error($value)) { |
|
319 | 319 | $errors_found = true; |
320 | 320 | break; |
321 | 321 | } |
322 | - $instance_settings[ $key ] = $value; |
|
322 | + $instance_settings[$key] = $value; |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | |
326 | - if ( $errors_found ) { |
|
327 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
326 | + if ($errors_found) { |
|
327 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
328 | 328 | } |
329 | 329 | |
330 | - update_option( $method->get_instance_option_key(), apply_filters( 'woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method ) ); |
|
330 | + update_option($method->get_instance_option_key(), apply_filters('woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method)); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | // Update order. |
334 | - if ( isset( $request['order'] ) ) { |
|
335 | - $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'method_order' => absint( $request['order'] ) ), array( 'instance_id' => absint( $instance_id ) ) ); |
|
336 | - $method->method_order = absint( $request['order'] ); |
|
334 | + if (isset($request['order'])) { |
|
335 | + $wpdb->update("{$wpdb->prefix}woocommerce_shipping_zone_methods", array('method_order' => absint($request['order'])), array('instance_id' => absint($instance_id))); |
|
336 | + $method->method_order = absint($request['order']); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // Update if this method is enabled or not. |
340 | - if ( isset( $request['enabled'] ) ) { |
|
341 | - if ( $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'is_enabled' => $request['enabled'] ), array( 'instance_id' => absint( $instance_id ) ) ) ) { |
|
342 | - do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled'] ); |
|
343 | - $method->enabled = ( true === $request['enabled'] ? 'yes' : 'no' ); |
|
340 | + if (isset($request['enabled'])) { |
|
341 | + if ($wpdb->update("{$wpdb->prefix}woocommerce_shipping_zone_methods", array('is_enabled' => $request['enabled']), array('instance_id' => absint($instance_id)))) { |
|
342 | + do_action('woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled']); |
|
343 | + $method->enabled = (true === $request['enabled'] ? 'yes' : 'no'); |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
@@ -354,29 +354,29 @@ discard block |
||
354 | 354 | * @param \WP_REST_Request $request Request object. |
355 | 355 | * @return \WP_REST_Response $response |
356 | 356 | */ |
357 | - public function prepare_item_for_response( $item, $request ) { |
|
357 | + public function prepare_item_for_response($item, $request) { |
|
358 | 358 | $method = array( |
359 | 359 | 'id' => $item->instance_id, |
360 | 360 | 'instance_id' => $item->instance_id, |
361 | 361 | 'title' => $item->instance_settings['title'], |
362 | 362 | 'order' => $item->method_order, |
363 | - 'enabled' => ( 'yes' === $item->enabled ), |
|
363 | + 'enabled' => ('yes' === $item->enabled), |
|
364 | 364 | 'method_id' => $item->id, |
365 | 365 | 'method_title' => $item->method_title, |
366 | 366 | 'method_description' => $item->method_description, |
367 | - 'settings' => $this->get_settings( $item ), |
|
367 | + 'settings' => $this->get_settings($item), |
|
368 | 368 | ); |
369 | 369 | |
370 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
371 | - $data = $this->add_additional_fields_to_object( $method, $request ); |
|
372 | - $data = $this->filter_response_by_context( $data, $context ); |
|
370 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
371 | + $data = $this->add_additional_fields_to_object($method, $request); |
|
372 | + $data = $this->filter_response_by_context($data, $context); |
|
373 | 373 | |
374 | 374 | // Wrap the data in a response object. |
375 | - $response = rest_ensure_response( $data ); |
|
375 | + $response = rest_ensure_response($data); |
|
376 | 376 | |
377 | - $response->add_links( $this->prepare_links( $request['zone_id'], $item->instance_id ) ); |
|
377 | + $response->add_links($this->prepare_links($request['zone_id'], $item->instance_id)); |
|
378 | 378 | |
379 | - $response = $this->prepare_response_for_collection( $response ); |
|
379 | + $response = $this->prepare_response_for_collection($response); |
|
380 | 380 | |
381 | 381 | return $response; |
382 | 382 | } |
@@ -388,24 +388,24 @@ discard block |
||
388 | 388 | * |
389 | 389 | * @return array |
390 | 390 | */ |
391 | - public function get_settings( $item ) { |
|
391 | + public function get_settings($item) { |
|
392 | 392 | $item->init_instance_settings(); |
393 | 393 | $settings = array(); |
394 | - foreach ( $item->get_instance_form_fields() as $id => $field ) { |
|
394 | + foreach ($item->get_instance_form_fields() as $id => $field) { |
|
395 | 395 | $data = array( |
396 | 396 | 'id' => $id, |
397 | 397 | 'label' => $field['title'], |
398 | - 'description' => empty( $field['description'] ) ? '' : $field['description'], |
|
398 | + 'description' => empty($field['description']) ? '' : $field['description'], |
|
399 | 399 | 'type' => $field['type'], |
400 | - 'value' => $item->instance_settings[ $id ], |
|
401 | - 'default' => empty( $field['default'] ) ? '' : $field['default'], |
|
402 | - 'tip' => empty( $field['description'] ) ? '' : $field['description'], |
|
403 | - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], |
|
400 | + 'value' => $item->instance_settings[$id], |
|
401 | + 'default' => empty($field['default']) ? '' : $field['default'], |
|
402 | + 'tip' => empty($field['description']) ? '' : $field['description'], |
|
403 | + 'placeholder' => empty($field['placeholder']) ? '' : $field['placeholder'], |
|
404 | 404 | ); |
405 | - if ( ! empty( $field['options'] ) ) { |
|
405 | + if ( ! empty($field['options'])) { |
|
406 | 406 | $data['options'] = $field['options']; |
407 | 407 | } |
408 | - $settings[ $id ] = $data; |
|
408 | + $settings[$id] = $data; |
|
409 | 409 | } |
410 | 410 | return $settings; |
411 | 411 | } |
@@ -417,17 +417,17 @@ discard block |
||
417 | 417 | * @param int $instance_id Given Shipping Zone Method Instance ID. |
418 | 418 | * @return array Links for the given Shipping Zone Method. |
419 | 419 | */ |
420 | - protected function prepare_links( $zone_id, $instance_id ) { |
|
420 | + protected function prepare_links($zone_id, $instance_id) { |
|
421 | 421 | $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id; |
422 | 422 | $links = array( |
423 | 423 | 'self' => array( |
424 | - 'href' => rest_url( $base . '/methods/' . $instance_id ), |
|
424 | + 'href' => rest_url($base . '/methods/' . $instance_id), |
|
425 | 425 | ), |
426 | 426 | 'collection' => array( |
427 | - 'href' => rest_url( $base . '/methods' ), |
|
427 | + 'href' => rest_url($base . '/methods'), |
|
428 | 428 | ), |
429 | 429 | 'describes' => array( |
430 | - 'href' => rest_url( $base ), |
|
430 | + 'href' => rest_url($base), |
|
431 | 431 | ), |
432 | 432 | ); |
433 | 433 | |
@@ -446,102 +446,102 @@ discard block |
||
446 | 446 | 'type' => 'object', |
447 | 447 | 'properties' => array( |
448 | 448 | 'id' => array( |
449 | - 'description' => __( 'Shipping method instance ID.', 'woocommerce' ), |
|
449 | + 'description' => __('Shipping method instance ID.', 'woocommerce'), |
|
450 | 450 | 'type' => 'integer', |
451 | - 'context' => array( 'view', 'edit' ), |
|
451 | + 'context' => array('view', 'edit'), |
|
452 | 452 | 'readonly' => true, |
453 | 453 | ), |
454 | 454 | 'instance_id' => array( |
455 | - 'description' => __( 'Shipping method instance ID.', 'woocommerce' ), |
|
455 | + 'description' => __('Shipping method instance ID.', 'woocommerce'), |
|
456 | 456 | 'type' => 'integer', |
457 | - 'context' => array( 'view', 'edit' ), |
|
457 | + 'context' => array('view', 'edit'), |
|
458 | 458 | 'readonly' => true, |
459 | 459 | ), |
460 | 460 | 'title' => array( |
461 | - 'description' => __( 'Shipping method customer facing title.', 'woocommerce' ), |
|
461 | + 'description' => __('Shipping method customer facing title.', 'woocommerce'), |
|
462 | 462 | 'type' => 'string', |
463 | - 'context' => array( 'view', 'edit' ), |
|
463 | + 'context' => array('view', 'edit'), |
|
464 | 464 | 'readonly' => true, |
465 | 465 | ), |
466 | 466 | 'order' => array( |
467 | - 'description' => __( 'Shipping method sort order.', 'woocommerce' ), |
|
467 | + 'description' => __('Shipping method sort order.', 'woocommerce'), |
|
468 | 468 | 'type' => 'integer', |
469 | - 'context' => array( 'view', 'edit' ), |
|
469 | + 'context' => array('view', 'edit'), |
|
470 | 470 | ), |
471 | 471 | 'enabled' => array( |
472 | - 'description' => __( 'Shipping method enabled status.', 'woocommerce' ), |
|
472 | + 'description' => __('Shipping method enabled status.', 'woocommerce'), |
|
473 | 473 | 'type' => 'boolean', |
474 | - 'context' => array( 'view', 'edit' ), |
|
474 | + 'context' => array('view', 'edit'), |
|
475 | 475 | ), |
476 | 476 | 'method_id' => array( |
477 | - 'description' => __( 'Shipping method ID.', 'woocommerce' ), |
|
477 | + 'description' => __('Shipping method ID.', 'woocommerce'), |
|
478 | 478 | 'type' => 'string', |
479 | - 'context' => array( 'view', 'edit' ), |
|
479 | + 'context' => array('view', 'edit'), |
|
480 | 480 | 'readonly' => true, |
481 | 481 | ), |
482 | 482 | 'method_title' => array( |
483 | - 'description' => __( 'Shipping method title.', 'woocommerce' ), |
|
483 | + 'description' => __('Shipping method title.', 'woocommerce'), |
|
484 | 484 | 'type' => 'string', |
485 | - 'context' => array( 'view', 'edit' ), |
|
485 | + 'context' => array('view', 'edit'), |
|
486 | 486 | 'readonly' => true, |
487 | 487 | ), |
488 | 488 | 'method_description' => array( |
489 | - 'description' => __( 'Shipping method description.', 'woocommerce' ), |
|
489 | + 'description' => __('Shipping method description.', 'woocommerce'), |
|
490 | 490 | 'type' => 'string', |
491 | - 'context' => array( 'view', 'edit' ), |
|
491 | + 'context' => array('view', 'edit'), |
|
492 | 492 | 'readonly' => true, |
493 | 493 | ), |
494 | 494 | 'settings' => array( |
495 | - 'description' => __( 'Shipping method settings.', 'woocommerce' ), |
|
495 | + 'description' => __('Shipping method settings.', 'woocommerce'), |
|
496 | 496 | 'type' => 'object', |
497 | - 'context' => array( 'view', 'edit' ), |
|
497 | + 'context' => array('view', 'edit'), |
|
498 | 498 | 'properties' => array( |
499 | 499 | 'id' => array( |
500 | - 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ), |
|
500 | + 'description' => __('A unique identifier for the setting.', 'woocommerce'), |
|
501 | 501 | 'type' => 'string', |
502 | - 'context' => array( 'view', 'edit' ), |
|
502 | + 'context' => array('view', 'edit'), |
|
503 | 503 | 'readonly' => true, |
504 | 504 | ), |
505 | 505 | 'label' => array( |
506 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
506 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
507 | 507 | 'type' => 'string', |
508 | - 'context' => array( 'view', 'edit' ), |
|
508 | + 'context' => array('view', 'edit'), |
|
509 | 509 | 'readonly' => true, |
510 | 510 | ), |
511 | 511 | 'description' => array( |
512 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
512 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
513 | 513 | 'type' => 'string', |
514 | - 'context' => array( 'view', 'edit' ), |
|
514 | + 'context' => array('view', 'edit'), |
|
515 | 515 | 'readonly' => true, |
516 | 516 | ), |
517 | 517 | 'type' => array( |
518 | - 'description' => __( 'Type of setting.', 'woocommerce' ), |
|
518 | + 'description' => __('Type of setting.', 'woocommerce'), |
|
519 | 519 | 'type' => 'string', |
520 | - 'context' => array( 'view', 'edit' ), |
|
521 | - 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ), |
|
520 | + 'context' => array('view', 'edit'), |
|
521 | + 'enum' => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'), |
|
522 | 522 | 'readonly' => true, |
523 | 523 | ), |
524 | 524 | 'value' => array( |
525 | - 'description' => __( 'Setting value.', 'woocommerce' ), |
|
525 | + 'description' => __('Setting value.', 'woocommerce'), |
|
526 | 526 | 'type' => 'string', |
527 | - 'context' => array( 'view', 'edit' ), |
|
527 | + 'context' => array('view', 'edit'), |
|
528 | 528 | ), |
529 | 529 | 'default' => array( |
530 | - 'description' => __( 'Default value for the setting.', 'woocommerce' ), |
|
530 | + 'description' => __('Default value for the setting.', 'woocommerce'), |
|
531 | 531 | 'type' => 'string', |
532 | - 'context' => array( 'view', 'edit' ), |
|
532 | + 'context' => array('view', 'edit'), |
|
533 | 533 | 'readonly' => true, |
534 | 534 | ), |
535 | 535 | 'tip' => array( |
536 | - 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ), |
|
536 | + 'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'), |
|
537 | 537 | 'type' => 'string', |
538 | - 'context' => array( 'view', 'edit' ), |
|
538 | + 'context' => array('view', 'edit'), |
|
539 | 539 | 'readonly' => true, |
540 | 540 | ), |
541 | 541 | 'placeholder' => array( |
542 | - 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ), |
|
542 | + 'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'), |
|
543 | 543 | 'type' => 'string', |
544 | - 'context' => array( 'view', 'edit' ), |
|
544 | + 'context' => array('view', 'edit'), |
|
545 | 545 | 'readonly' => true, |
546 | 546 | ), |
547 | 547 | ), |
@@ -549,6 +549,6 @@ discard block |
||
549 | 549 | ), |
550 | 550 | ); |
551 | 551 | |
552 | - return $this->add_additional_fields_schema( $schema ); |
|
552 | + return $this->add_additional_fields_schema($schema); |
|
553 | 553 | } |
554 | 554 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | namespace WooCommerce\RestApi\Controllers\Version4; |
12 | 12 | |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | +defined('ABSPATH') || exit; |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * REST API Shipping Zones base class. |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | * @param int $zone_id Shipping Zone ID. |
34 | 34 | * @return WC_Shipping_Zone|\WP_Error |
35 | 35 | */ |
36 | - protected function get_zone( $zone_id ) { |
|
37 | - $zone = \WC_Shipping_Zones::get_zone_by( 'zone_id', $zone_id ); |
|
36 | + protected function get_zone($zone_id) { |
|
37 | + $zone = \WC_Shipping_Zones::get_zone_by('zone_id', $zone_id); |
|
38 | 38 | |
39 | - if ( false === $zone ) { |
|
40 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
39 | + if (false === $zone) { |
|
40 | + return new \WP_Error('woocommerce_rest_shipping_zone_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | return $zone; |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | * @param \WP_REST_Request $request Full details about the request. |
50 | 50 | * @return \WP_Error|boolean |
51 | 51 | */ |
52 | - public function get_items_permissions_check( $request ) { |
|
53 | - if ( ! wc_shipping_enabled() ) { |
|
54 | - return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
52 | + public function get_items_permissions_check($request) { |
|
53 | + if ( ! wc_shipping_enabled()) { |
|
54 | + return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404)); |
|
55 | 55 | } |
56 | 56 | |
57 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
58 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
57 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
58 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | return true; |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | * @param \WP_REST_Request $request Full details about the request. |
68 | 68 | * @return \WP_Error|boolean |
69 | 69 | */ |
70 | - public function create_item_permissions_check( $request ) { |
|
71 | - if ( ! wc_shipping_enabled() ) { |
|
72 | - return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
70 | + public function create_item_permissions_check($request) { |
|
71 | + if ( ! wc_shipping_enabled()) { |
|
72 | + return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404)); |
|
73 | 73 | } |
74 | 74 | |
75 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
76 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
75 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
76 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | return true; |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | * @param \WP_REST_Request $request Full details about the request. |
86 | 86 | * @return \WP_Error|boolean |
87 | 87 | */ |
88 | - public function update_items_permissions_check( $request ) { |
|
89 | - if ( ! wc_shipping_enabled() ) { |
|
90 | - return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
88 | + public function update_items_permissions_check($request) { |
|
89 | + if ( ! wc_shipping_enabled()) { |
|
90 | + return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404)); |
|
91 | 91 | } |
92 | 92 | |
93 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
94 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
93 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
94 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | return true; |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | * @param \WP_REST_Request $request Full details about the request. |
104 | 104 | * @return \WP_Error|boolean |
105 | 105 | */ |
106 | - public function delete_items_permissions_check( $request ) { |
|
107 | - if ( ! wc_shipping_enabled() ) { |
|
108 | - return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
106 | + public function delete_items_permissions_check($request) { |
|
107 | + if ( ! wc_shipping_enabled()) { |
|
108 | + return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404)); |
|
109 | 109 | } |
110 | 110 | |
111 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) { |
|
112 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
111 | + if ( ! wc_rest_check_manager_permissions('settings', 'delete')) { |
|
112 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return true; |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Taxes controller class. |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | array( |
34 | 34 | array( |
35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
36 | - 'callback' => array( $this, 'get_items' ), |
|
37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
36 | + 'callback' => array($this, 'get_items'), |
|
37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
38 | 38 | 'args' => $this->get_collection_params(), |
39 | 39 | ), |
40 | 40 | array( |
41 | 41 | 'methods' => \WP_REST_Server::CREATABLE, |
42 | - 'callback' => array( $this, 'create_item' ), |
|
43 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
44 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
42 | + 'callback' => array($this, 'create_item'), |
|
43 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
44 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
45 | 45 | ), |
46 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
46 | + 'schema' => array($this, 'get_public_item_schema'), |
|
47 | 47 | ), |
48 | 48 | true |
49 | 49 | ); |
@@ -54,37 +54,37 @@ discard block |
||
54 | 54 | array( |
55 | 55 | 'args' => array( |
56 | 56 | 'id' => array( |
57 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
57 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
58 | 58 | 'type' => 'integer', |
59 | 59 | ), |
60 | 60 | ), |
61 | 61 | array( |
62 | 62 | 'methods' => \WP_REST_Server::READABLE, |
63 | - 'callback' => array( $this, 'get_item' ), |
|
64 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
63 | + 'callback' => array($this, 'get_item'), |
|
64 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
65 | 65 | 'args' => array( |
66 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
66 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
67 | 67 | ), |
68 | 68 | ), |
69 | 69 | array( |
70 | 70 | 'methods' => \WP_REST_Server::EDITABLE, |
71 | - 'callback' => array( $this, 'update_item' ), |
|
72 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
73 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
71 | + 'callback' => array($this, 'update_item'), |
|
72 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
73 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
74 | 74 | ), |
75 | 75 | array( |
76 | 76 | 'methods' => \WP_REST_Server::DELETABLE, |
77 | - 'callback' => array( $this, 'delete_item' ), |
|
78 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
77 | + 'callback' => array($this, 'delete_item'), |
|
78 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
79 | 79 | 'args' => array( |
80 | 80 | 'force' => array( |
81 | 81 | 'default' => false, |
82 | 82 | 'type' => 'boolean', |
83 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
83 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
84 | 84 | ), |
85 | 85 | ), |
86 | 86 | ), |
87 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
87 | + 'schema' => array($this, 'get_public_item_schema'), |
|
88 | 88 | ), |
89 | 89 | true |
90 | 90 | ); |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | array( |
96 | 96 | array( |
97 | 97 | 'methods' => \WP_REST_Server::EDITABLE, |
98 | - 'callback' => array( $this, 'batch_items' ), |
|
99 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
100 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
98 | + 'callback' => array($this, 'batch_items'), |
|
99 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
100 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
101 | 101 | ), |
102 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
102 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
103 | 103 | ), |
104 | 104 | true |
105 | 105 | ); |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | * @param \WP_REST_Request $request Full details about the request. |
112 | 112 | * @return \WP_Error|boolean |
113 | 113 | */ |
114 | - public function get_items_permissions_check( $request ) { |
|
115 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
116 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
114 | + public function get_items_permissions_check($request) { |
|
115 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
116 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | return true; |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return bool|\WP_Error |
128 | 128 | */ |
129 | - public function create_item_permissions_check( $request ) { |
|
130 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'create' ) ) { |
|
131 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
129 | + public function create_item_permissions_check($request) { |
|
130 | + if ( ! wc_rest_check_manager_permissions('settings', 'create')) { |
|
131 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | return true; |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | * @param \WP_REST_Request $request Full details about the request. |
141 | 141 | * @return \WP_Error|boolean |
142 | 142 | */ |
143 | - public function get_item_permissions_check( $request ) { |
|
144 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
145 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
143 | + public function get_item_permissions_check($request) { |
|
144 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
145 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | return true; |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return bool|\WP_Error |
157 | 157 | */ |
158 | - public function update_item_permissions_check( $request ) { |
|
159 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
160 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
158 | + public function update_item_permissions_check($request) { |
|
159 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
160 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | return true; |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @return bool|\WP_Error |
172 | 172 | */ |
173 | - public function delete_item_permissions_check( $request ) { |
|
174 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) { |
|
175 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
173 | + public function delete_item_permissions_check($request) { |
|
174 | + if ( ! wc_rest_check_manager_permissions('settings', 'delete')) { |
|
175 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | return true; |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @return bool|\WP_Error |
187 | 187 | */ |
188 | - public function batch_items_permissions_check( $request ) { |
|
189 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'batch' ) ) { |
|
190 | - return new \WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
188 | + public function batch_items_permissions_check($request) { |
|
189 | + if ( ! wc_rest_check_manager_permissions('settings', 'batch')) { |
|
190 | + return new \WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | return true; |
@@ -199,22 +199,22 @@ discard block |
||
199 | 199 | * @param \WP_REST_Request $request Full details about the request. |
200 | 200 | * @return \WP_Error\WP_REST_Response |
201 | 201 | */ |
202 | - public function get_items( $request ) { |
|
202 | + public function get_items($request) { |
|
203 | 203 | global $wpdb; |
204 | 204 | |
205 | 205 | $prepared_args = array(); |
206 | 206 | $prepared_args['order'] = $request['order']; |
207 | 207 | $prepared_args['number'] = $request['per_page']; |
208 | - if ( ! empty( $request['offset'] ) ) { |
|
208 | + if ( ! empty($request['offset'])) { |
|
209 | 209 | $prepared_args['offset'] = $request['offset']; |
210 | 210 | } else { |
211 | - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; |
|
211 | + $prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number']; |
|
212 | 212 | } |
213 | 213 | $orderby_possibles = array( |
214 | 214 | 'id' => 'tax_rate_id', |
215 | 215 | 'order' => 'tax_rate_order', |
216 | 216 | ); |
217 | - $prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ]; |
|
217 | + $prepared_args['orderby'] = $orderby_possibles[$request['orderby']]; |
|
218 | 218 | $prepared_args['class'] = $request['class']; |
219 | 219 | $prepared_args['code'] = $request['code']; |
220 | 220 | $prepared_args['include'] = $request['include']; |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param array $prepared_args Array of arguments for $wpdb->get_results(). |
226 | 226 | * @param \WP_REST_Request $request The current request. |
227 | 227 | */ |
228 | - $prepared_args = apply_filters( 'woocommerce_rest_tax_query', $prepared_args, $request ); |
|
228 | + $prepared_args = apply_filters('woocommerce_rest_tax_query', $prepared_args, $request); |
|
229 | 229 | |
230 | 230 | $query = " |
231 | 231 | SELECT * |
@@ -234,69 +234,69 @@ discard block |
||
234 | 234 | "; |
235 | 235 | |
236 | 236 | // Filter by tax class. |
237 | - if ( ! empty( $prepared_args['class'] ) ) { |
|
238 | - $class = 'standard' !== $prepared_args['class'] ? sanitize_title( $prepared_args['class'] ) : ''; |
|
237 | + if ( ! empty($prepared_args['class'])) { |
|
238 | + $class = 'standard' !== $prepared_args['class'] ? sanitize_title($prepared_args['class']) : ''; |
|
239 | 239 | $query .= " AND tax_rate_class = '$class'"; |
240 | 240 | } |
241 | 241 | |
242 | 242 | // Filter by tax code. |
243 | 243 | $tax_code_search = $prepared_args['code']; |
244 | - if ( $tax_code_search ) { |
|
245 | - $tax_code_search = $wpdb->esc_like( $tax_code_search ); |
|
244 | + if ($tax_code_search) { |
|
245 | + $tax_code_search = $wpdb->esc_like($tax_code_search); |
|
246 | 246 | $tax_code_search = ' \'%' . $tax_code_search . '%\''; |
247 | 247 | $query .= ' AND CONCAT_WS( "-", NULLIF(tax_rate_country, ""), NULLIF(tax_rate_state, ""), NULLIF(tax_rate_name, ""), NULLIF(tax_rate_priority, "") ) LIKE ' . $tax_code_search; |
248 | 248 | } |
249 | 249 | |
250 | 250 | // Filter by included tax rate IDs. |
251 | 251 | $included_taxes = $prepared_args['include']; |
252 | - if ( ! empty( $included_taxes ) ) { |
|
253 | - $included_taxes = implode( ',', $prepared_args['include'] ); |
|
252 | + if ( ! empty($included_taxes)) { |
|
253 | + $included_taxes = implode(',', $prepared_args['include']); |
|
254 | 254 | $query .= " AND tax_rate_id IN ({$included_taxes})"; |
255 | 255 | } |
256 | 256 | |
257 | 257 | // Order tax rates. |
258 | - $order_by = sprintf( ' ORDER BY %s', sanitize_key( $prepared_args['orderby'] ) ); |
|
258 | + $order_by = sprintf(' ORDER BY %s', sanitize_key($prepared_args['orderby'])); |
|
259 | 259 | |
260 | 260 | // Pagination. |
261 | - $pagination = sprintf( ' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number'] ); |
|
261 | + $pagination = sprintf(' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number']); |
|
262 | 262 | |
263 | 263 | // Query taxes. |
264 | - $results = $wpdb->get_results( $query . $order_by . $pagination ); // @codingStandardsIgnoreLine. |
|
264 | + $results = $wpdb->get_results($query . $order_by . $pagination); // @codingStandardsIgnoreLine. |
|
265 | 265 | |
266 | 266 | $taxes = array(); |
267 | - foreach ( $results as $tax ) { |
|
268 | - $data = $this->prepare_item_for_response( $tax, $request ); |
|
269 | - $taxes[] = $this->prepare_response_for_collection( $data ); |
|
267 | + foreach ($results as $tax) { |
|
268 | + $data = $this->prepare_item_for_response($tax, $request); |
|
269 | + $taxes[] = $this->prepare_response_for_collection($data); |
|
270 | 270 | } |
271 | 271 | |
272 | - $response = rest_ensure_response( $taxes ); |
|
272 | + $response = rest_ensure_response($taxes); |
|
273 | 273 | |
274 | 274 | // Store pagination values for headers then unset for count query. |
275 | 275 | $per_page = (int) $prepared_args['number']; |
276 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
276 | + $page = ceil((((int) $prepared_args['offset']) / $per_page) + 1); |
|
277 | 277 | |
278 | 278 | // Query only for ids. |
279 | - $wpdb->get_results( str_replace( 'SELECT *', 'SELECT tax_rate_id', $query ) ); // @codingStandardsIgnoreLine. |
|
279 | + $wpdb->get_results(str_replace('SELECT *', 'SELECT tax_rate_id', $query)); // @codingStandardsIgnoreLine. |
|
280 | 280 | |
281 | 281 | // Calculate totals. |
282 | 282 | $total_taxes = (int) $wpdb->num_rows; |
283 | - $response->header( 'X-WP-Total', (int) $total_taxes ); |
|
284 | - $max_pages = ceil( $total_taxes / $per_page ); |
|
285 | - $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
283 | + $response->header('X-WP-Total', (int) $total_taxes); |
|
284 | + $max_pages = ceil($total_taxes / $per_page); |
|
285 | + $response->header('X-WP-TotalPages', (int) $max_pages); |
|
286 | 286 | |
287 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
288 | - if ( $page > 1 ) { |
|
287 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
288 | + if ($page > 1) { |
|
289 | 289 | $prev_page = $page - 1; |
290 | - if ( $prev_page > $max_pages ) { |
|
290 | + if ($prev_page > $max_pages) { |
|
291 | 291 | $prev_page = $max_pages; |
292 | 292 | } |
293 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
294 | - $response->link_header( 'prev', $prev_link ); |
|
293 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
294 | + $response->link_header('prev', $prev_link); |
|
295 | 295 | } |
296 | - if ( $max_pages > $page ) { |
|
296 | + if ($max_pages > $page) { |
|
297 | 297 | $next_page = $page + 1; |
298 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
299 | - $response->link_header( 'next', $next_link ); |
|
298 | + $next_link = add_query_arg('page', $next_page, $base); |
|
299 | + $response->link_header('next', $next_link); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | return $response; |
@@ -309,8 +309,8 @@ discard block |
||
309 | 309 | * @param stdClass|null $current Existing tax object. |
310 | 310 | * @return object |
311 | 311 | */ |
312 | - protected function create_or_update_tax( $request, $current = null ) { |
|
313 | - $id = absint( isset( $request['id'] ) ? $request['id'] : 0 ); |
|
312 | + protected function create_or_update_tax($request, $current = null) { |
|
313 | + $id = absint(isset($request['id']) ? $request['id'] : 0); |
|
314 | 314 | $data = array(); |
315 | 315 | $fields = array( |
316 | 316 | 'tax_rate_country', |
@@ -324,52 +324,52 @@ discard block |
||
324 | 324 | 'tax_rate_class', |
325 | 325 | ); |
326 | 326 | |
327 | - foreach ( $fields as $field ) { |
|
327 | + foreach ($fields as $field) { |
|
328 | 328 | // Keys via API differ from the stored names returned by _get_tax_rate. |
329 | - $key = 'tax_rate' === $field ? 'rate' : str_replace( 'tax_rate_', '', $field ); |
|
329 | + $key = 'tax_rate' === $field ? 'rate' : str_replace('tax_rate_', '', $field); |
|
330 | 330 | |
331 | 331 | // Remove data that was not posted. |
332 | - if ( ! isset( $request[ $key ] ) ) { |
|
332 | + if ( ! isset($request[$key])) { |
|
333 | 333 | continue; |
334 | 334 | } |
335 | 335 | |
336 | 336 | // Test new data against current data. |
337 | - if ( $current && $current->$field === $request[ $key ] ) { |
|
337 | + if ($current && $current->$field === $request[$key]) { |
|
338 | 338 | continue; |
339 | 339 | } |
340 | 340 | |
341 | 341 | // Add to data array. |
342 | - switch ( $key ) { |
|
342 | + switch ($key) { |
|
343 | 343 | case 'tax_rate_priority': |
344 | 344 | case 'tax_rate_compound': |
345 | 345 | case 'tax_rate_shipping': |
346 | 346 | case 'tax_rate_order': |
347 | - $data[ $field ] = absint( $request[ $key ] ); |
|
347 | + $data[$field] = absint($request[$key]); |
|
348 | 348 | break; |
349 | 349 | case 'tax_rate_class': |
350 | - $data[ $field ] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : ''; |
|
350 | + $data[$field] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : ''; |
|
351 | 351 | break; |
352 | 352 | default: |
353 | - $data[ $field ] = wc_clean( $request[ $key ] ); |
|
353 | + $data[$field] = wc_clean($request[$key]); |
|
354 | 354 | break; |
355 | 355 | } |
356 | 356 | } |
357 | 357 | |
358 | - if ( $id ) { |
|
359 | - \WC_Tax::_update_tax_rate( $id, $data ); |
|
358 | + if ($id) { |
|
359 | + \WC_Tax::_update_tax_rate($id, $data); |
|
360 | 360 | } else { |
361 | - $id = \WC_Tax::_insert_tax_rate( $data ); |
|
361 | + $id = \WC_Tax::_insert_tax_rate($data); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | // Add locales. |
365 | - if ( ! empty( $request['postcode'] ) ) { |
|
366 | - \WC_Tax::_update_tax_rate_postcodes( $id, wc_clean( $request['postcode'] ) ); |
|
365 | + if ( ! empty($request['postcode'])) { |
|
366 | + \WC_Tax::_update_tax_rate_postcodes($id, wc_clean($request['postcode'])); |
|
367 | 367 | } |
368 | - if ( ! empty( $request['city'] ) ) { |
|
369 | - \WC_Tax::_update_tax_rate_cities( $id, wc_clean( $request['city'] ) ); |
|
368 | + if ( ! empty($request['city'])) { |
|
369 | + \WC_Tax::_update_tax_rate_cities($id, wc_clean($request['city'])); |
|
370 | 370 | } |
371 | 371 | |
372 | - return \WC_Tax::_get_tax_rate( $id, OBJECT ); |
|
372 | + return \WC_Tax::_get_tax_rate($id, OBJECT); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -378,14 +378,14 @@ discard block |
||
378 | 378 | * @param \WP_REST_Request $request Full details about the request. |
379 | 379 | * @return \WP_Error\WP_REST_Response |
380 | 380 | */ |
381 | - public function create_item( $request ) { |
|
382 | - if ( ! empty( $request['id'] ) ) { |
|
383 | - return new \WP_Error( 'woocommerce_rest_tax_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
381 | + public function create_item($request) { |
|
382 | + if ( ! empty($request['id'])) { |
|
383 | + return new \WP_Error('woocommerce_rest_tax_exists', __('Cannot create existing resource.', 'woocommerce'), array('status' => 400)); |
|
384 | 384 | } |
385 | 385 | |
386 | - $tax = $this->create_or_update_tax( $request ); |
|
386 | + $tax = $this->create_or_update_tax($request); |
|
387 | 387 | |
388 | - $this->update_additional_fields_for_object( $tax, $request ); |
|
388 | + $this->update_additional_fields_for_object($tax, $request); |
|
389 | 389 | |
390 | 390 | /** |
391 | 391 | * Fires after a tax is created or updated via the REST API. |
@@ -394,13 +394,13 @@ discard block |
||
394 | 394 | * @param \WP_REST_Request $request Request object. |
395 | 395 | * @param boolean $creating True when creating tax, false when updating tax. |
396 | 396 | */ |
397 | - do_action( 'woocommerce_rest_insert_tax', $tax, $request, true ); |
|
397 | + do_action('woocommerce_rest_insert_tax', $tax, $request, true); |
|
398 | 398 | |
399 | - $request->set_param( 'context', 'edit' ); |
|
400 | - $response = $this->prepare_item_for_response( $tax, $request ); |
|
401 | - $response = rest_ensure_response( $response ); |
|
402 | - $response->set_status( 201 ); |
|
403 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id ) ) ); |
|
399 | + $request->set_param('context', 'edit'); |
|
400 | + $response = $this->prepare_item_for_response($tax, $request); |
|
401 | + $response = rest_ensure_response($response); |
|
402 | + $response->set_status(201); |
|
403 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id))); |
|
404 | 404 | |
405 | 405 | return $response; |
406 | 406 | } |
@@ -411,16 +411,16 @@ discard block |
||
411 | 411 | * @param \WP_REST_Request $request Full details about the request. |
412 | 412 | * @return \WP_Error\WP_REST_Response |
413 | 413 | */ |
414 | - public function get_item( $request ) { |
|
414 | + public function get_item($request) { |
|
415 | 415 | $id = (int) $request['id']; |
416 | - $tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT ); |
|
416 | + $tax_obj = \WC_Tax::_get_tax_rate($id, OBJECT); |
|
417 | 417 | |
418 | - if ( empty( $id ) || empty( $tax_obj ) ) { |
|
419 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
418 | + if (empty($id) || empty($tax_obj)) { |
|
419 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
420 | 420 | } |
421 | 421 | |
422 | - $tax = $this->prepare_item_for_response( $tax_obj, $request ); |
|
423 | - $response = rest_ensure_response( $tax ); |
|
422 | + $tax = $this->prepare_item_for_response($tax_obj, $request); |
|
423 | + $response = rest_ensure_response($tax); |
|
424 | 424 | |
425 | 425 | return $response; |
426 | 426 | } |
@@ -431,17 +431,17 @@ discard block |
||
431 | 431 | * @param \WP_REST_Request $request Full details about the request. |
432 | 432 | * @return \WP_Error\WP_REST_Response |
433 | 433 | */ |
434 | - public function update_item( $request ) { |
|
434 | + public function update_item($request) { |
|
435 | 435 | $id = (int) $request['id']; |
436 | - $tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT ); |
|
436 | + $tax_obj = \WC_Tax::_get_tax_rate($id, OBJECT); |
|
437 | 437 | |
438 | - if ( empty( $id ) || empty( $tax_obj ) ) { |
|
439 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
438 | + if (empty($id) || empty($tax_obj)) { |
|
439 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
440 | 440 | } |
441 | 441 | |
442 | - $tax = $this->create_or_update_tax( $request, $tax_obj ); |
|
442 | + $tax = $this->create_or_update_tax($request, $tax_obj); |
|
443 | 443 | |
444 | - $this->update_additional_fields_for_object( $tax, $request ); |
|
444 | + $this->update_additional_fields_for_object($tax, $request); |
|
445 | 445 | |
446 | 446 | /** |
447 | 447 | * Fires after a tax is created or updated via the REST API. |
@@ -450,11 +450,11 @@ discard block |
||
450 | 450 | * @param \WP_REST_Request $request Request object. |
451 | 451 | * @param boolean $creating True when creating tax, false when updating tax. |
452 | 452 | */ |
453 | - do_action( 'woocommerce_rest_insert_tax', $tax, $request, false ); |
|
453 | + do_action('woocommerce_rest_insert_tax', $tax, $request, false); |
|
454 | 454 | |
455 | - $request->set_param( 'context', 'edit' ); |
|
456 | - $response = $this->prepare_item_for_response( $tax, $request ); |
|
457 | - $response = rest_ensure_response( $response ); |
|
455 | + $request->set_param('context', 'edit'); |
|
456 | + $response = $this->prepare_item_for_response($tax, $request); |
|
457 | + $response = rest_ensure_response($response); |
|
458 | 458 | |
459 | 459 | return $response; |
460 | 460 | } |
@@ -465,30 +465,30 @@ discard block |
||
465 | 465 | * @param \WP_REST_Request $request Full details about the request. |
466 | 466 | * @return \WP_Error\WP_REST_Response |
467 | 467 | */ |
468 | - public function delete_item( $request ) { |
|
468 | + public function delete_item($request) { |
|
469 | 469 | global $wpdb; |
470 | 470 | |
471 | 471 | $id = (int) $request['id']; |
472 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
472 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
473 | 473 | |
474 | 474 | // We don't support trashing for this type, error out. |
475 | - if ( ! $force ) { |
|
476 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Taxes do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
475 | + if ( ! $force) { |
|
476 | + return new \WP_Error('woocommerce_rest_trash_not_supported', __('Taxes do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
477 | 477 | } |
478 | 478 | |
479 | - $tax = \WC_Tax::_get_tax_rate( $id, OBJECT ); |
|
479 | + $tax = \WC_Tax::_get_tax_rate($id, OBJECT); |
|
480 | 480 | |
481 | - if ( empty( $id ) || empty( $tax ) ) { |
|
482 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
481 | + if (empty($id) || empty($tax)) { |
|
482 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 400)); |
|
483 | 483 | } |
484 | 484 | |
485 | - $request->set_param( 'context', 'edit' ); |
|
486 | - $response = $this->prepare_item_for_response( $tax, $request ); |
|
485 | + $request->set_param('context', 'edit'); |
|
486 | + $response = $this->prepare_item_for_response($tax, $request); |
|
487 | 487 | |
488 | - \WC_Tax::_delete_tax_rate( $id ); |
|
488 | + \WC_Tax::_delete_tax_rate($id); |
|
489 | 489 | |
490 | - if ( 0 === $wpdb->rows_affected ) { |
|
491 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
490 | + if (0 === $wpdb->rows_affected) { |
|
491 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | /** |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | * @param \WP_REST_Response $response The response returned from the API. |
499 | 499 | * @param \WP_REST_Request $request The request sent to the API. |
500 | 500 | */ |
501 | - do_action( 'woocommerce_rest_delete_tax', $tax, $response, $request ); |
|
501 | + do_action('woocommerce_rest_delete_tax', $tax, $response, $request); |
|
502 | 502 | |
503 | 503 | return $response; |
504 | 504 | } |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | * @param \WP_REST_Request $request Request object. |
511 | 511 | * @return \WP_REST_Response $response Response data. |
512 | 512 | */ |
513 | - public function prepare_item_for_response( $tax, $request ) { |
|
513 | + public function prepare_item_for_response($tax, $request) { |
|
514 | 514 | global $wpdb; |
515 | 515 | |
516 | 516 | $id = (int) $tax->tax_rate_id; |
@@ -541,20 +541,20 @@ discard block |
||
541 | 541 | ) |
542 | 542 | ); |
543 | 543 | |
544 | - if ( ! is_wp_error( $tax ) && ! is_null( $tax ) ) { |
|
545 | - foreach ( $locales as $locale ) { |
|
546 | - $data[ $locale->location_type ] = $locale->location_code; |
|
544 | + if ( ! is_wp_error($tax) && ! is_null($tax)) { |
|
545 | + foreach ($locales as $locale) { |
|
546 | + $data[$locale->location_type] = $locale->location_code; |
|
547 | 547 | } |
548 | 548 | } |
549 | 549 | |
550 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
551 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
552 | - $data = $this->filter_response_by_context( $data, $context ); |
|
550 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
551 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
552 | + $data = $this->filter_response_by_context($data, $context); |
|
553 | 553 | |
554 | 554 | // Wrap the data in a response object. |
555 | - $response = rest_ensure_response( $data ); |
|
555 | + $response = rest_ensure_response($data); |
|
556 | 556 | |
557 | - $response->add_links( $this->prepare_links( $tax ) ); |
|
557 | + $response->add_links($this->prepare_links($tax)); |
|
558 | 558 | |
559 | 559 | /** |
560 | 560 | * Filter tax object returned from the REST API. |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | * @param stdClass $tax Tax object used to create response. |
564 | 564 | * @param \WP_REST_Request $request Request object. |
565 | 565 | */ |
566 | - return apply_filters( 'woocommerce_rest_prepare_tax', $response, $tax, $request ); |
|
566 | + return apply_filters('woocommerce_rest_prepare_tax', $response, $tax, $request); |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | /** |
@@ -572,13 +572,13 @@ discard block |
||
572 | 572 | * @param stdClass $tax Tax object. |
573 | 573 | * @return array Links for the given tax. |
574 | 574 | */ |
575 | - protected function prepare_links( $tax ) { |
|
575 | + protected function prepare_links($tax) { |
|
576 | 576 | $links = array( |
577 | 577 | 'self' => array( |
578 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id ) ), |
|
578 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id)), |
|
579 | 579 | ), |
580 | 580 | 'collection' => array( |
581 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
581 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
582 | 582 | ), |
583 | 583 | ); |
584 | 584 | |
@@ -597,75 +597,75 @@ discard block |
||
597 | 597 | 'type' => 'object', |
598 | 598 | 'properties' => array( |
599 | 599 | 'id' => array( |
600 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
600 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
601 | 601 | 'type' => 'integer', |
602 | - 'context' => array( 'view', 'edit' ), |
|
602 | + 'context' => array('view', 'edit'), |
|
603 | 603 | 'readonly' => true, |
604 | 604 | ), |
605 | 605 | 'country' => array( |
606 | - 'description' => __( 'Country ISO 3166 code.', 'woocommerce' ), |
|
606 | + 'description' => __('Country ISO 3166 code.', 'woocommerce'), |
|
607 | 607 | 'type' => 'string', |
608 | - 'context' => array( 'view', 'edit' ), |
|
608 | + 'context' => array('view', 'edit'), |
|
609 | 609 | ), |
610 | 610 | 'state' => array( |
611 | - 'description' => __( 'State code.', 'woocommerce' ), |
|
611 | + 'description' => __('State code.', 'woocommerce'), |
|
612 | 612 | 'type' => 'string', |
613 | - 'context' => array( 'view', 'edit' ), |
|
613 | + 'context' => array('view', 'edit'), |
|
614 | 614 | ), |
615 | 615 | 'postcode' => array( |
616 | - 'description' => __( 'Postcode / ZIP.', 'woocommerce' ), |
|
616 | + 'description' => __('Postcode / ZIP.', 'woocommerce'), |
|
617 | 617 | 'type' => 'string', |
618 | - 'context' => array( 'view', 'edit' ), |
|
618 | + 'context' => array('view', 'edit'), |
|
619 | 619 | ), |
620 | 620 | 'city' => array( |
621 | - 'description' => __( 'City name.', 'woocommerce' ), |
|
621 | + 'description' => __('City name.', 'woocommerce'), |
|
622 | 622 | 'type' => 'string', |
623 | - 'context' => array( 'view', 'edit' ), |
|
623 | + 'context' => array('view', 'edit'), |
|
624 | 624 | ), |
625 | 625 | 'rate' => array( |
626 | - 'description' => __( 'Tax rate.', 'woocommerce' ), |
|
626 | + 'description' => __('Tax rate.', 'woocommerce'), |
|
627 | 627 | 'type' => 'string', |
628 | - 'context' => array( 'view', 'edit' ), |
|
628 | + 'context' => array('view', 'edit'), |
|
629 | 629 | ), |
630 | 630 | 'name' => array( |
631 | - 'description' => __( 'Tax rate name.', 'woocommerce' ), |
|
631 | + 'description' => __('Tax rate name.', 'woocommerce'), |
|
632 | 632 | 'type' => 'string', |
633 | - 'context' => array( 'view', 'edit' ), |
|
633 | + 'context' => array('view', 'edit'), |
|
634 | 634 | ), |
635 | 635 | 'priority' => array( |
636 | - 'description' => __( 'Tax priority.', 'woocommerce' ), |
|
636 | + 'description' => __('Tax priority.', 'woocommerce'), |
|
637 | 637 | 'type' => 'integer', |
638 | 638 | 'default' => 1, |
639 | - 'context' => array( 'view', 'edit' ), |
|
639 | + 'context' => array('view', 'edit'), |
|
640 | 640 | ), |
641 | 641 | 'compound' => array( |
642 | - 'description' => __( 'Whether or not this is a compound rate.', 'woocommerce' ), |
|
642 | + 'description' => __('Whether or not this is a compound rate.', 'woocommerce'), |
|
643 | 643 | 'type' => 'boolean', |
644 | 644 | 'default' => false, |
645 | - 'context' => array( 'view', 'edit' ), |
|
645 | + 'context' => array('view', 'edit'), |
|
646 | 646 | ), |
647 | 647 | 'shipping' => array( |
648 | - 'description' => __( 'Whether or not this tax rate also gets applied to shipping.', 'woocommerce' ), |
|
648 | + 'description' => __('Whether or not this tax rate also gets applied to shipping.', 'woocommerce'), |
|
649 | 649 | 'type' => 'boolean', |
650 | 650 | 'default' => true, |
651 | - 'context' => array( 'view', 'edit' ), |
|
651 | + 'context' => array('view', 'edit'), |
|
652 | 652 | ), |
653 | 653 | 'order' => array( |
654 | - 'description' => __( 'Indicates the order that will appear in queries.', 'woocommerce' ), |
|
654 | + 'description' => __('Indicates the order that will appear in queries.', 'woocommerce'), |
|
655 | 655 | 'type' => 'integer', |
656 | - 'context' => array( 'view', 'edit' ), |
|
656 | + 'context' => array('view', 'edit'), |
|
657 | 657 | ), |
658 | 658 | 'class' => array( |
659 | - 'description' => __( 'Tax class.', 'woocommerce' ), |
|
659 | + 'description' => __('Tax class.', 'woocommerce'), |
|
660 | 660 | 'type' => 'string', |
661 | 661 | 'default' => 'standard', |
662 | - 'enum' => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ), |
|
663 | - 'context' => array( 'view', 'edit' ), |
|
662 | + 'enum' => array_merge(array('standard'), \WC_Tax::get_tax_class_slugs()), |
|
663 | + 'context' => array('view', 'edit'), |
|
664 | 664 | ), |
665 | 665 | ), |
666 | 666 | ); |
667 | 667 | |
668 | - return $this->add_additional_fields_schema( $schema ); |
|
668 | + return $this->add_additional_fields_schema($schema); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | /** |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | $params['context']['default'] = 'view'; |
680 | 680 | |
681 | 681 | $params['page'] = array( |
682 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
682 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
683 | 683 | 'type' => 'integer', |
684 | 684 | 'default' => 1, |
685 | 685 | 'sanitize_callback' => 'absint', |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | 'minimum' => 1, |
688 | 688 | ); |
689 | 689 | $params['per_page'] = array( |
690 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
690 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
691 | 691 | 'type' => 'integer', |
692 | 692 | 'default' => 10, |
693 | 693 | 'minimum' => 1, |
@@ -696,22 +696,22 @@ discard block |
||
696 | 696 | 'validate_callback' => 'rest_validate_request_arg', |
697 | 697 | ); |
698 | 698 | $params['offset'] = array( |
699 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
699 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
700 | 700 | 'type' => 'integer', |
701 | 701 | 'sanitize_callback' => 'absint', |
702 | 702 | 'validate_callback' => 'rest_validate_request_arg', |
703 | 703 | ); |
704 | 704 | $params['order'] = array( |
705 | 705 | 'default' => 'asc', |
706 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
707 | - 'enum' => array( 'asc', 'desc' ), |
|
706 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
707 | + 'enum' => array('asc', 'desc'), |
|
708 | 708 | 'sanitize_callback' => 'sanitize_key', |
709 | 709 | 'type' => 'string', |
710 | 710 | 'validate_callback' => 'rest_validate_request_arg', |
711 | 711 | ); |
712 | 712 | $params['orderby'] = array( |
713 | 713 | 'default' => 'order', |
714 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
714 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
715 | 715 | 'enum' => array( |
716 | 716 | 'id', |
717 | 717 | 'order', |
@@ -721,19 +721,19 @@ discard block |
||
721 | 721 | 'validate_callback' => 'rest_validate_request_arg', |
722 | 722 | ); |
723 | 723 | $params['class'] = array( |
724 | - 'description' => __( 'Sort by tax class.', 'woocommerce' ), |
|
725 | - 'enum' => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ), |
|
724 | + 'description' => __('Sort by tax class.', 'woocommerce'), |
|
725 | + 'enum' => array_merge(array('standard'), \WC_Tax::get_tax_class_slugs()), |
|
726 | 726 | 'sanitize_callback' => 'sanitize_title', |
727 | 727 | 'type' => 'string', |
728 | 728 | 'validate_callback' => 'rest_validate_request_arg', |
729 | 729 | ); |
730 | - $params['code'] = array( |
|
731 | - 'description' => __( 'Search by similar tax code.', 'woocommerce' ), |
|
730 | + $params['code'] = array( |
|
731 | + 'description' => __('Search by similar tax code.', 'woocommerce'), |
|
732 | 732 | 'type' => 'string', |
733 | 733 | 'validate_callback' => 'rest_validate_request_arg', |
734 | 734 | ); |
735 | 735 | $params['include'] = array( |
736 | - 'description' => __( 'Limit result set to items that have the specified rate ID(s) assigned.', 'woocommerce' ), |
|
736 | + 'description' => __('Limit result set to items that have the specified rate ID(s) assigned.', 'woocommerce'), |
|
737 | 737 | 'type' => 'array', |
738 | 738 | 'items' => array( |
739 | 739 | 'type' => 'integer', |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Setting Options controller class. |
@@ -35,16 +35,16 @@ discard block |
||
35 | 35 | array( |
36 | 36 | 'args' => array( |
37 | 37 | 'group' => array( |
38 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
38 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
39 | 39 | 'type' => 'string', |
40 | 40 | ), |
41 | 41 | ), |
42 | 42 | array( |
43 | 43 | 'methods' => \WP_REST_Server::READABLE, |
44 | - 'callback' => array( $this, 'get_items' ), |
|
45 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
44 | + 'callback' => array($this, 'get_items'), |
|
45 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
46 | 46 | ), |
47 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
47 | + 'schema' => array($this, 'get_public_item_schema'), |
|
48 | 48 | ), |
49 | 49 | true |
50 | 50 | ); |
@@ -55,17 +55,17 @@ discard block |
||
55 | 55 | array( |
56 | 56 | 'args' => array( |
57 | 57 | 'group' => array( |
58 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
58 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
59 | 59 | 'type' => 'string', |
60 | 60 | ), |
61 | 61 | ), |
62 | 62 | array( |
63 | 63 | 'methods' => \WP_REST_Server::EDITABLE, |
64 | - 'callback' => array( $this, 'batch_items' ), |
|
65 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
66 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
64 | + 'callback' => array($this, 'batch_items'), |
|
65 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
66 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
67 | 67 | ), |
68 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
68 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
69 | 69 | ), |
70 | 70 | true |
71 | 71 | ); |
@@ -76,26 +76,26 @@ discard block |
||
76 | 76 | array( |
77 | 77 | 'args' => array( |
78 | 78 | 'group' => array( |
79 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
79 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
80 | 80 | 'type' => 'string', |
81 | 81 | ), |
82 | 82 | 'id' => array( |
83 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
83 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
84 | 84 | 'type' => 'string', |
85 | 85 | ), |
86 | 86 | ), |
87 | 87 | array( |
88 | 88 | 'methods' => \WP_REST_Server::READABLE, |
89 | - 'callback' => array( $this, 'get_item' ), |
|
90 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
89 | + 'callback' => array($this, 'get_item'), |
|
90 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
91 | 91 | ), |
92 | 92 | array( |
93 | 93 | 'methods' => \WP_REST_Server::EDITABLE, |
94 | - 'callback' => array( $this, 'update_item' ), |
|
95 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
96 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
94 | + 'callback' => array($this, 'update_item'), |
|
95 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
96 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
97 | 97 | ), |
98 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
98 | + 'schema' => array($this, 'get_public_item_schema'), |
|
99 | 99 | ), |
100 | 100 | true |
101 | 101 | ); |
@@ -108,16 +108,16 @@ discard block |
||
108 | 108 | * @param \WP_REST_Request $request Request data. |
109 | 109 | * @return \WP_Error\WP_REST_Response |
110 | 110 | */ |
111 | - public function get_item( $request ) { |
|
112 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
111 | + public function get_item($request) { |
|
112 | + $setting = $this->get_setting($request['group_id'], $request['id']); |
|
113 | 113 | |
114 | - if ( is_wp_error( $setting ) ) { |
|
114 | + if (is_wp_error($setting)) { |
|
115 | 115 | return $setting; |
116 | 116 | } |
117 | 117 | |
118 | - $response = $this->prepare_item_for_response( $setting, $request ); |
|
118 | + $response = $this->prepare_item_for_response($setting, $request); |
|
119 | 119 | |
120 | - return rest_ensure_response( $response ); |
|
120 | + return rest_ensure_response($response); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,24 +127,24 @@ discard block |
||
127 | 127 | * @param \WP_REST_Request $request Request data. |
128 | 128 | * @return \WP_Error\WP_REST_Response |
129 | 129 | */ |
130 | - public function get_items( $request ) { |
|
131 | - $settings = $this->get_group_settings( $request['group_id'] ); |
|
130 | + public function get_items($request) { |
|
131 | + $settings = $this->get_group_settings($request['group_id']); |
|
132 | 132 | |
133 | - if ( is_wp_error( $settings ) ) { |
|
133 | + if (is_wp_error($settings)) { |
|
134 | 134 | return $settings; |
135 | 135 | } |
136 | 136 | |
137 | 137 | $data = array(); |
138 | 138 | |
139 | - foreach ( $settings as $setting_obj ) { |
|
140 | - $setting = $this->prepare_item_for_response( $setting_obj, $request ); |
|
141 | - $setting = $this->prepare_response_for_collection( $setting ); |
|
142 | - if ( $this->is_setting_type_valid( $setting['type'] ) ) { |
|
139 | + foreach ($settings as $setting_obj) { |
|
140 | + $setting = $this->prepare_item_for_response($setting_obj, $request); |
|
141 | + $setting = $this->prepare_response_for_collection($setting); |
|
142 | + if ($this->is_setting_type_valid($setting['type'])) { |
|
143 | 143 | $data[] = $setting; |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | - return rest_ensure_response( $data ); |
|
147 | + return rest_ensure_response($data); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -153,39 +153,39 @@ discard block |
||
153 | 153 | * @param string $group_id Group ID. |
154 | 154 | * @return array|\WP_Error |
155 | 155 | */ |
156 | - public function get_group_settings( $group_id ) { |
|
157 | - if ( empty( $group_id ) ) { |
|
158 | - return new \WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
156 | + public function get_group_settings($group_id) { |
|
157 | + if (empty($group_id)) { |
|
158 | + return new \WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404)); |
|
159 | 159 | } |
160 | 160 | |
161 | - $settings = apply_filters( 'woocommerce_settings-' . $group_id, array() ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
161 | + $settings = apply_filters('woocommerce_settings-' . $group_id, array()); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
162 | 162 | |
163 | - if ( empty( $settings ) ) { |
|
164 | - return new \WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
163 | + if (empty($settings)) { |
|
164 | + return new \WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404)); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | $filtered_settings = array(); |
168 | - foreach ( $settings as $setting ) { |
|
168 | + foreach ($settings as $setting) { |
|
169 | 169 | $option_key = $setting['option_key']; |
170 | - $setting = $this->filter_setting( $setting ); |
|
171 | - $default = isset( $setting['default'] ) ? $setting['default'] : ''; |
|
170 | + $setting = $this->filter_setting($setting); |
|
171 | + $default = isset($setting['default']) ? $setting['default'] : ''; |
|
172 | 172 | // Get the option value. |
173 | - if ( is_array( $option_key ) ) { |
|
174 | - $option = get_option( $option_key[0] ); |
|
175 | - $setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default; |
|
173 | + if (is_array($option_key)) { |
|
174 | + $option = get_option($option_key[0]); |
|
175 | + $setting['value'] = isset($option[$option_key[1]]) ? $option[$option_key[1]] : $default; |
|
176 | 176 | } else { |
177 | - $admin_setting_value = \WC_Admin_Settings::get_option( $option_key, $default ); |
|
177 | + $admin_setting_value = \WC_Admin_Settings::get_option($option_key, $default); |
|
178 | 178 | $setting['value'] = $admin_setting_value; |
179 | 179 | } |
180 | 180 | |
181 | - if ( 'multi_select_countries' === $setting['type'] ) { |
|
181 | + if ('multi_select_countries' === $setting['type']) { |
|
182 | 182 | $setting['options'] = WC()->countries->get_countries(); |
183 | 183 | $setting['type'] = 'multiselect'; |
184 | - } elseif ( 'single_select_country' === $setting['type'] ) { |
|
184 | + } elseif ('single_select_country' === $setting['type']) { |
|
185 | 185 | $setting['type'] = 'select'; |
186 | 186 | $setting['options'] = $this->get_countries_and_states(); |
187 | - } elseif ( 'single_select_page' === $setting['type'] ) { |
|
188 | - $pages = get_pages( |
|
187 | + } elseif ('single_select_page' === $setting['type']) { |
|
188 | + $pages = get_pages( |
|
189 | 189 | array( |
190 | 190 | 'sort_column' => 'menu_order', |
191 | 191 | 'sort_order' => 'ASC', |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | ) |
194 | 194 | ); |
195 | 195 | $options = array(); |
196 | - foreach ( $pages as $page ) { |
|
197 | - $options[ $page->ID ] = ! empty( $page->post_title ) ? $page->post_title : '#' . $page->ID; |
|
196 | + foreach ($pages as $page) { |
|
197 | + $options[$page->ID] = ! empty($page->post_title) ? $page->post_title : '#' . $page->ID; |
|
198 | 198 | } |
199 | 199 | $setting['type'] = 'select'; |
200 | 200 | $setting['options'] = $options; |
@@ -214,19 +214,19 @@ discard block |
||
214 | 214 | */ |
215 | 215 | private function get_countries_and_states() { |
216 | 216 | $countries = WC()->countries->get_countries(); |
217 | - if ( ! $countries ) { |
|
217 | + if ( ! $countries) { |
|
218 | 218 | return array(); |
219 | 219 | } |
220 | 220 | $output = array(); |
221 | - foreach ( $countries as $key => $value ) { |
|
222 | - $states = WC()->countries->get_states( $key ); |
|
221 | + foreach ($countries as $key => $value) { |
|
222 | + $states = WC()->countries->get_states($key); |
|
223 | 223 | |
224 | - if ( $states ) { |
|
225 | - foreach ( $states as $state_key => $state_value ) { |
|
226 | - $output[ $key . ':' . $state_key ] = $value . ' - ' . $state_value; |
|
224 | + if ($states) { |
|
225 | + foreach ($states as $state_key => $state_value) { |
|
226 | + $output[$key . ':' . $state_key] = $value . ' - ' . $state_value; |
|
227 | 227 | } |
228 | 228 | } else { |
229 | - $output[ $key ] = $value; |
|
229 | + $output[$key] = $value; |
|
230 | 230 | } |
231 | 231 | } |
232 | 232 | return $output; |
@@ -240,30 +240,30 @@ discard block |
||
240 | 240 | * @param string $setting_id Setting ID. |
241 | 241 | * @return stdClass|\WP_Error |
242 | 242 | */ |
243 | - public function get_setting( $group_id, $setting_id ) { |
|
244 | - if ( empty( $setting_id ) ) { |
|
245 | - return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
243 | + public function get_setting($group_id, $setting_id) { |
|
244 | + if (empty($setting_id)) { |
|
245 | + return new \WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
246 | 246 | } |
247 | 247 | |
248 | - $settings = $this->get_group_settings( $group_id ); |
|
248 | + $settings = $this->get_group_settings($group_id); |
|
249 | 249 | |
250 | - if ( is_wp_error( $settings ) ) { |
|
250 | + if (is_wp_error($settings)) { |
|
251 | 251 | return $settings; |
252 | 252 | } |
253 | 253 | |
254 | - $array_key = array_keys( wp_list_pluck( $settings, 'id' ), $setting_id ); |
|
254 | + $array_key = array_keys(wp_list_pluck($settings, 'id'), $setting_id); |
|
255 | 255 | |
256 | - if ( empty( $array_key ) ) { |
|
257 | - return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
256 | + if (empty($array_key)) { |
|
257 | + return new \WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
258 | 258 | } |
259 | 259 | |
260 | - $setting = $settings[ $array_key[0] ]; |
|
260 | + $setting = $settings[$array_key[0]]; |
|
261 | 261 | |
262 | - if ( ! $this->is_setting_type_valid( $setting['type'] ) ) { |
|
263 | - return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
262 | + if ( ! $this->is_setting_type_valid($setting['type'])) { |
|
263 | + return new \WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
264 | 264 | } |
265 | 265 | |
266 | - if ( is_wp_error( $setting ) ) { |
|
266 | + if (is_wp_error($setting)) { |
|
267 | 267 | return $setting; |
268 | 268 | } |
269 | 269 | |
@@ -279,24 +279,24 @@ discard block |
||
279 | 279 | * @param \WP_REST_Request $request Full details about the request. |
280 | 280 | * @return array Of \WP_Error or \WP_REST_Response. |
281 | 281 | */ |
282 | - public function batch_items( $request ) { |
|
282 | + public function batch_items($request) { |
|
283 | 283 | // Get the request params. |
284 | - $items = array_filter( $request->get_params() ); |
|
284 | + $items = array_filter($request->get_params()); |
|
285 | 285 | |
286 | 286 | /* |
287 | 287 | * Since our batch settings update is group-specific and matches based on the route, |
288 | 288 | * we inject the URL parameters (containing group) into the batch items |
289 | 289 | */ |
290 | - if ( ! empty( $items['update'] ) ) { |
|
290 | + if ( ! empty($items['update'])) { |
|
291 | 291 | $to_update = array(); |
292 | - foreach ( $items['update'] as $item ) { |
|
293 | - $to_update[] = array_merge( $request->get_url_params(), $item ); |
|
292 | + foreach ($items['update'] as $item) { |
|
293 | + $to_update[] = array_merge($request->get_url_params(), $item); |
|
294 | 294 | } |
295 | - $request = new \WP_REST_Request( $request->get_method() ); |
|
296 | - $request->set_body_params( array( 'update' => $to_update ) ); |
|
295 | + $request = new \WP_REST_Request($request->get_method()); |
|
296 | + $request->set_body_params(array('update' => $to_update)); |
|
297 | 297 | } |
298 | 298 | |
299 | - return parent::batch_items( $request ); |
|
299 | + return parent::batch_items($request); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -306,39 +306,39 @@ discard block |
||
306 | 306 | * @param \WP_REST_Request $request Request data. |
307 | 307 | * @return \WP_Error\WP_REST_Response |
308 | 308 | */ |
309 | - public function update_item( $request ) { |
|
310 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
309 | + public function update_item($request) { |
|
310 | + $setting = $this->get_setting($request['group_id'], $request['id']); |
|
311 | 311 | |
312 | - if ( is_wp_error( $setting ) ) { |
|
312 | + if (is_wp_error($setting)) { |
|
313 | 313 | return $setting; |
314 | 314 | } |
315 | 315 | |
316 | - if ( is_callable( array( $this, 'validate_setting_' . $setting['type'] . '_field' ) ) ) { |
|
317 | - $value = $this->{'validate_setting_' . $setting['type'] . '_field'}( $request['value'], $setting ); |
|
316 | + if (is_callable(array($this, 'validate_setting_' . $setting['type'] . '_field'))) { |
|
317 | + $value = $this->{'validate_setting_' . $setting['type'] . '_field'}($request['value'], $setting); |
|
318 | 318 | } else { |
319 | - $value = $this->validate_setting_text_field( $request['value'], $setting ); |
|
319 | + $value = $this->validate_setting_text_field($request['value'], $setting); |
|
320 | 320 | } |
321 | 321 | |
322 | - if ( is_wp_error( $value ) ) { |
|
322 | + if (is_wp_error($value)) { |
|
323 | 323 | return $value; |
324 | 324 | } |
325 | 325 | |
326 | - if ( is_array( $setting['option_key'] ) ) { |
|
326 | + if (is_array($setting['option_key'])) { |
|
327 | 327 | $setting['value'] = $value; |
328 | 328 | $option_key = $setting['option_key']; |
329 | - $prev = get_option( $option_key[0] ); |
|
330 | - $prev[ $option_key[1] ] = $request['value']; |
|
331 | - update_option( $option_key[0], $prev ); |
|
329 | + $prev = get_option($option_key[0]); |
|
330 | + $prev[$option_key[1]] = $request['value']; |
|
331 | + update_option($option_key[0], $prev); |
|
332 | 332 | } else { |
333 | 333 | $update_data = array(); |
334 | - $update_data[ $setting['option_key'] ] = $value; |
|
334 | + $update_data[$setting['option_key']] = $value; |
|
335 | 335 | $setting['value'] = $value; |
336 | - \WC_Admin_Settings::save_fields( array( $setting ), $update_data ); |
|
336 | + \WC_Admin_Settings::save_fields(array($setting), $update_data); |
|
337 | 337 | } |
338 | 338 | |
339 | - $response = $this->prepare_item_for_response( $setting, $request ); |
|
339 | + $response = $this->prepare_item_for_response($setting, $request); |
|
340 | 340 | |
341 | - return rest_ensure_response( $response ); |
|
341 | + return rest_ensure_response($response); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -349,13 +349,13 @@ discard block |
||
349 | 349 | * @param \WP_REST_Request $request Request object. |
350 | 350 | * @return \WP_REST_Response $response Response data. |
351 | 351 | */ |
352 | - public function prepare_item_for_response( $item, $request ) { |
|
353 | - unset( $item['option_key'] ); |
|
354 | - $data = $this->filter_setting( $item ); |
|
355 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
356 | - $data = $this->filter_response_by_context( $data, empty( $request['context'] ) ? 'view' : $request['context'] ); |
|
357 | - $response = rest_ensure_response( $data ); |
|
358 | - $response->add_links( $this->prepare_links( $data['id'], $request['group_id'] ) ); |
|
352 | + public function prepare_item_for_response($item, $request) { |
|
353 | + unset($item['option_key']); |
|
354 | + $data = $this->filter_setting($item); |
|
355 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
356 | + $data = $this->filter_response_by_context($data, empty($request['context']) ? 'view' : $request['context']); |
|
357 | + $response = rest_ensure_response($data); |
|
358 | + $response->add_links($this->prepare_links($data['id'], $request['group_id'])); |
|
359 | 359 | return $response; |
360 | 360 | } |
361 | 361 | |
@@ -367,14 +367,14 @@ discard block |
||
367 | 367 | * @param string $group_id Group ID. |
368 | 368 | * @return array Links for the given setting. |
369 | 369 | */ |
370 | - protected function prepare_links( $setting_id, $group_id ) { |
|
371 | - $base = str_replace( '(?P<group_id>[\w-]+)', $group_id, $this->rest_base ); |
|
370 | + protected function prepare_links($setting_id, $group_id) { |
|
371 | + $base = str_replace('(?P<group_id>[\w-]+)', $group_id, $this->rest_base); |
|
372 | 372 | $links = array( |
373 | 373 | 'self' => array( |
374 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $base, $setting_id ) ), |
|
374 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $base, $setting_id)), |
|
375 | 375 | ), |
376 | 376 | 'collection' => array( |
377 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
377 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
378 | 378 | ), |
379 | 379 | ); |
380 | 380 | |
@@ -388,9 +388,9 @@ discard block |
||
388 | 388 | * @param \WP_REST_Request $request Full data about the request. |
389 | 389 | * @return \WP_Error|boolean |
390 | 390 | */ |
391 | - public function get_items_permissions_check( $request ) { |
|
392 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
393 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
391 | + public function get_items_permissions_check($request) { |
|
392 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
393 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | return true; |
@@ -403,9 +403,9 @@ discard block |
||
403 | 403 | * @param \WP_REST_Request $request Full data about the request. |
404 | 404 | * @return \WP_Error|boolean |
405 | 405 | */ |
406 | - public function update_items_permissions_check( $request ) { |
|
407 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
408 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
406 | + public function update_items_permissions_check($request) { |
|
407 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
408 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | return true; |
@@ -419,18 +419,18 @@ discard block |
||
419 | 419 | * @param array $setting Settings. |
420 | 420 | * @return array |
421 | 421 | */ |
422 | - public function filter_setting( $setting ) { |
|
422 | + public function filter_setting($setting) { |
|
423 | 423 | $setting = array_intersect_key( |
424 | 424 | $setting, |
425 | - array_flip( array_filter( array_keys( $setting ), array( $this, 'allowed_setting_keys' ) ) ) |
|
425 | + array_flip(array_filter(array_keys($setting), array($this, 'allowed_setting_keys'))) |
|
426 | 426 | ); |
427 | 427 | |
428 | - if ( empty( $setting['options'] ) ) { |
|
429 | - unset( $setting['options'] ); |
|
428 | + if (empty($setting['options'])) { |
|
429 | + unset($setting['options']); |
|
430 | 430 | } |
431 | 431 | |
432 | - if ( 'image_width' === $setting['type'] ) { |
|
433 | - $setting = $this->cast_image_width( $setting ); |
|
432 | + if ('image_width' === $setting['type']) { |
|
433 | + $setting = $this->cast_image_width($setting); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | return $setting; |
@@ -445,12 +445,12 @@ discard block |
||
445 | 445 | * @param array $setting Settings. |
446 | 446 | * @return array |
447 | 447 | */ |
448 | - public function cast_image_width( $setting ) { |
|
449 | - foreach ( array( 'default', 'value' ) as $key ) { |
|
450 | - if ( isset( $setting[ $key ] ) ) { |
|
451 | - $setting[ $key ]['width'] = intval( $setting[ $key ]['width'] ); |
|
452 | - $setting[ $key ]['height'] = intval( $setting[ $key ]['height'] ); |
|
453 | - $setting[ $key ]['crop'] = (bool) $setting[ $key ]['crop']; |
|
448 | + public function cast_image_width($setting) { |
|
449 | + foreach (array('default', 'value') as $key) { |
|
450 | + if (isset($setting[$key])) { |
|
451 | + $setting[$key]['width'] = intval($setting[$key]['width']); |
|
452 | + $setting[$key]['height'] = intval($setting[$key]['height']); |
|
453 | + $setting[$key]['crop'] = (bool) $setting[$key]['crop']; |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | return $setting; |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | * @param string $key Key to check. |
463 | 463 | * @return boolean |
464 | 464 | */ |
465 | - public function allowed_setting_keys( $key ) { |
|
465 | + public function allowed_setting_keys($key) { |
|
466 | 466 | return in_array( |
467 | 467 | $key, array( |
468 | 468 | 'id', |
@@ -487,20 +487,20 @@ discard block |
||
487 | 487 | * @param string $type Type. |
488 | 488 | * @return bool |
489 | 489 | */ |
490 | - public function is_setting_type_valid( $type ) { |
|
490 | + public function is_setting_type_valid($type) { |
|
491 | 491 | return in_array( |
492 | 492 | $type, array( |
493 | - 'text', // Validates with validate_setting_text_field. |
|
494 | - 'email', // Validates with validate_setting_text_field. |
|
495 | - 'number', // Validates with validate_setting_text_field. |
|
496 | - 'color', // Validates with validate_setting_text_field. |
|
497 | - 'password', // Validates with validate_setting_text_field. |
|
498 | - 'textarea', // Validates with validate_setting_textarea_field. |
|
499 | - 'select', // Validates with validate_setting_select_field. |
|
500 | - 'multiselect', // Validates with validate_setting_multiselect_field. |
|
501 | - 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
502 | - 'checkbox', // Validates with validate_setting_checkbox_field. |
|
503 | - 'image_width', // Validates with validate_setting_image_width_field. |
|
493 | + 'text', // Validates with validate_setting_text_field. |
|
494 | + 'email', // Validates with validate_setting_text_field. |
|
495 | + 'number', // Validates with validate_setting_text_field. |
|
496 | + 'color', // Validates with validate_setting_text_field. |
|
497 | + 'password', // Validates with validate_setting_text_field. |
|
498 | + 'textarea', // Validates with validate_setting_textarea_field. |
|
499 | + 'select', // Validates with validate_setting_select_field. |
|
500 | + 'multiselect', // Validates with validate_setting_multiselect_field. |
|
501 | + 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
502 | + 'checkbox', // Validates with validate_setting_checkbox_field. |
|
503 | + 'image_width', // Validates with validate_setting_image_width_field. |
|
504 | 504 | 'thumbnail_cropping', // Validates with validate_setting_text_field. |
505 | 505 | ) |
506 | 506 | ); |
@@ -518,89 +518,89 @@ discard block |
||
518 | 518 | 'type' => 'object', |
519 | 519 | 'properties' => array( |
520 | 520 | 'id' => array( |
521 | - 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ), |
|
521 | + 'description' => __('A unique identifier for the setting.', 'woocommerce'), |
|
522 | 522 | 'type' => 'string', |
523 | 523 | 'arg_options' => array( |
524 | 524 | 'sanitize_callback' => 'sanitize_title', |
525 | 525 | ), |
526 | - 'context' => array( 'view', 'edit' ), |
|
526 | + 'context' => array('view', 'edit'), |
|
527 | 527 | 'readonly' => true, |
528 | 528 | ), |
529 | 529 | 'group_id' => array( |
530 | - 'description' => __( 'An identifier for the group this setting belongs to.', 'woocommerce' ), |
|
530 | + 'description' => __('An identifier for the group this setting belongs to.', 'woocommerce'), |
|
531 | 531 | 'type' => 'string', |
532 | 532 | 'arg_options' => array( |
533 | 533 | 'sanitize_callback' => 'sanitize_title', |
534 | 534 | ), |
535 | - 'context' => array( 'view', 'edit' ), |
|
535 | + 'context' => array('view', 'edit'), |
|
536 | 536 | 'readonly' => true, |
537 | 537 | ), |
538 | 538 | 'label' => array( |
539 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
539 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
540 | 540 | 'type' => 'string', |
541 | 541 | 'arg_options' => array( |
542 | 542 | 'sanitize_callback' => 'sanitize_text_field', |
543 | 543 | ), |
544 | - 'context' => array( 'view', 'edit' ), |
|
544 | + 'context' => array('view', 'edit'), |
|
545 | 545 | 'readonly' => true, |
546 | 546 | ), |
547 | 547 | 'description' => array( |
548 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
548 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
549 | 549 | 'type' => 'string', |
550 | 550 | 'arg_options' => array( |
551 | 551 | 'sanitize_callback' => 'sanitize_text_field', |
552 | 552 | ), |
553 | - 'context' => array( 'view', 'edit' ), |
|
553 | + 'context' => array('view', 'edit'), |
|
554 | 554 | 'readonly' => true, |
555 | 555 | ), |
556 | 556 | 'value' => array( |
557 | - 'description' => __( 'Setting value.', 'woocommerce' ), |
|
557 | + 'description' => __('Setting value.', 'woocommerce'), |
|
558 | 558 | 'type' => 'mixed', |
559 | - 'context' => array( 'view', 'edit' ), |
|
559 | + 'context' => array('view', 'edit'), |
|
560 | 560 | ), |
561 | 561 | 'default' => array( |
562 | - 'description' => __( 'Default value for the setting.', 'woocommerce' ), |
|
562 | + 'description' => __('Default value for the setting.', 'woocommerce'), |
|
563 | 563 | 'type' => 'mixed', |
564 | - 'context' => array( 'view', 'edit' ), |
|
564 | + 'context' => array('view', 'edit'), |
|
565 | 565 | 'readonly' => true, |
566 | 566 | ), |
567 | 567 | 'tip' => array( |
568 | - 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ), |
|
568 | + 'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'), |
|
569 | 569 | 'type' => 'string', |
570 | 570 | 'arg_options' => array( |
571 | 571 | 'sanitize_callback' => 'sanitize_text_field', |
572 | 572 | ), |
573 | - 'context' => array( 'view', 'edit' ), |
|
573 | + 'context' => array('view', 'edit'), |
|
574 | 574 | 'readonly' => true, |
575 | 575 | ), |
576 | 576 | 'placeholder' => array( |
577 | - 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ), |
|
577 | + 'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'), |
|
578 | 578 | 'type' => 'string', |
579 | 579 | 'arg_options' => array( |
580 | 580 | 'sanitize_callback' => 'sanitize_text_field', |
581 | 581 | ), |
582 | - 'context' => array( 'view', 'edit' ), |
|
582 | + 'context' => array('view', 'edit'), |
|
583 | 583 | 'readonly' => true, |
584 | 584 | ), |
585 | 585 | 'type' => array( |
586 | - 'description' => __( 'Type of setting.', 'woocommerce' ), |
|
586 | + 'description' => __('Type of setting.', 'woocommerce'), |
|
587 | 587 | 'type' => 'string', |
588 | 588 | 'arg_options' => array( |
589 | 589 | 'sanitize_callback' => 'sanitize_text_field', |
590 | 590 | ), |
591 | - 'context' => array( 'view', 'edit' ), |
|
592 | - 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ), |
|
591 | + 'context' => array('view', 'edit'), |
|
592 | + 'enum' => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'), |
|
593 | 593 | 'readonly' => true, |
594 | 594 | ), |
595 | 595 | 'options' => array( |
596 | - 'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ), |
|
596 | + 'description' => __('Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce'), |
|
597 | 597 | 'type' => 'object', |
598 | - 'context' => array( 'view', 'edit' ), |
|
598 | + 'context' => array('view', 'edit'), |
|
599 | 599 | 'readonly' => true, |
600 | 600 | ), |
601 | 601 | ), |
602 | 602 | ); |
603 | 603 | |
604 | - return $this->add_additional_fields_schema( $schema ); |
|
604 | + return $this->add_additional_fields_schema($schema); |
|
605 | 605 | } |
606 | 606 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Coupons controller class. |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | array( |
36 | 36 | array( |
37 | 37 | 'methods' => \WP_REST_Server::READABLE, |
38 | - 'callback' => array( $this, 'get_items' ), |
|
39 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
38 | + 'callback' => array($this, 'get_items'), |
|
39 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
40 | 40 | ), |
41 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
41 | + 'schema' => array($this, 'get_public_item_schema'), |
|
42 | 42 | ), |
43 | 43 | true |
44 | 44 | ); |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | * @param \WP_REST_Request $request Full details about the request. |
51 | 51 | * @return \WP_Error|boolean |
52 | 52 | */ |
53 | - public function get_items_permissions_check( $request ) { |
|
54 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
55 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
53 | + public function get_items_permissions_check($request) { |
|
54 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
55 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | return true; |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | * @param \WP_REST_Request $request Full details about the request. |
65 | 65 | * @return \WP_Error|boolean |
66 | 66 | */ |
67 | - public function get_item_permissions_check( $request ) { |
|
68 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
69 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
67 | + public function get_item_permissions_check($request) { |
|
68 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
69 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | return true; |
@@ -79,33 +79,33 @@ discard block |
||
79 | 79 | * @param \WP_REST_Request $request Request data. |
80 | 80 | * @return \WP_Error\WP_REST_Response |
81 | 81 | */ |
82 | - public function get_items( $request ) { |
|
82 | + public function get_items($request) { |
|
83 | 83 | $data = array(); |
84 | 84 | $resources = array( |
85 | 85 | array( |
86 | 86 | 'slug' => 'continents', |
87 | - 'description' => __( 'List of supported continents, countries, and states.', 'woocommerce' ), |
|
87 | + 'description' => __('List of supported continents, countries, and states.', 'woocommerce'), |
|
88 | 88 | ), |
89 | 89 | array( |
90 | 90 | 'slug' => 'countries', |
91 | - 'description' => __( 'List of supported states in a given country.', 'woocommerce' ), |
|
91 | + 'description' => __('List of supported states in a given country.', 'woocommerce'), |
|
92 | 92 | ), |
93 | 93 | array( |
94 | 94 | 'slug' => 'currencies', |
95 | - 'description' => __( 'List of supported currencies.', 'woocommerce' ), |
|
95 | + 'description' => __('List of supported currencies.', 'woocommerce'), |
|
96 | 96 | ), |
97 | 97 | array( |
98 | 98 | 'slug' => 'download-ips', |
99 | - 'description' => __( 'An endpoint used for searching download logs for a specific IP address.', 'woocommerce' ), |
|
99 | + 'description' => __('An endpoint used for searching download logs for a specific IP address.', 'woocommerce'), |
|
100 | 100 | ), |
101 | 101 | ); |
102 | 102 | |
103 | - foreach ( $resources as $resource ) { |
|
104 | - $item = $this->prepare_item_for_response( (object) $resource, $request ); |
|
105 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
103 | + foreach ($resources as $resource) { |
|
104 | + $item = $this->prepare_item_for_response((object) $resource, $request); |
|
105 | + $data[] = $this->prepare_response_for_collection($item); |
|
106 | 106 | } |
107 | 107 | |
108 | - return rest_ensure_response( $data ); |
|
108 | + return rest_ensure_response($data); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -115,18 +115,18 @@ discard block |
||
115 | 115 | * @param \WP_REST_Request $request Request object. |
116 | 116 | * @return \WP_REST_Response $response Response data. |
117 | 117 | */ |
118 | - public function prepare_item_for_response( $resource, $request ) { |
|
118 | + public function prepare_item_for_response($resource, $request) { |
|
119 | 119 | $data = array( |
120 | 120 | 'slug' => $resource->slug, |
121 | 121 | 'description' => $resource->description, |
122 | 122 | ); |
123 | 123 | |
124 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
125 | - $data = $this->filter_response_by_context( $data, 'view' ); |
|
124 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
125 | + $data = $this->filter_response_by_context($data, 'view'); |
|
126 | 126 | |
127 | 127 | // Wrap the data in a response object. |
128 | - $response = rest_ensure_response( $data ); |
|
129 | - $response->add_links( $this->prepare_links( $resource ) ); |
|
128 | + $response = rest_ensure_response($data); |
|
129 | + $response->add_links($this->prepare_links($resource)); |
|
130 | 130 | |
131 | 131 | return $response; |
132 | 132 | } |
@@ -137,13 +137,13 @@ discard block |
||
137 | 137 | * @param object $item Data object. |
138 | 138 | * @return array Links for the given country. |
139 | 139 | */ |
140 | - protected function prepare_links( $item ) { |
|
140 | + protected function prepare_links($item) { |
|
141 | 141 | $links = array( |
142 | 142 | 'self' => array( |
143 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $item->slug ) ), |
|
143 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $item->slug)), |
|
144 | 144 | ), |
145 | 145 | 'collection' => array( |
146 | - 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), |
|
146 | + 'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)), |
|
147 | 147 | ), |
148 | 148 | ); |
149 | 149 | |
@@ -163,20 +163,20 @@ discard block |
||
163 | 163 | 'type' => 'object', |
164 | 164 | 'properties' => array( |
165 | 165 | 'slug' => array( |
166 | - 'description' => __( 'Data resource ID.', 'woocommerce' ), |
|
166 | + 'description' => __('Data resource ID.', 'woocommerce'), |
|
167 | 167 | 'type' => 'string', |
168 | - 'context' => array( 'view' ), |
|
168 | + 'context' => array('view'), |
|
169 | 169 | 'readonly' => true, |
170 | 170 | ), |
171 | 171 | 'description' => array( |
172 | - 'description' => __( 'Data resource description.', 'woocommerce' ), |
|
172 | + 'description' => __('Data resource description.', 'woocommerce'), |
|
173 | 173 | 'type' => 'string', |
174 | - 'context' => array( 'view' ), |
|
174 | + 'context' => array('view'), |
|
175 | 175 | 'readonly' => true, |
176 | 176 | ), |
177 | 177 | ), |
178 | 178 | ); |
179 | 179 | |
180 | - return $this->add_additional_fields_schema( $schema ); |
|
180 | + return $this->add_additional_fields_schema($schema); |
|
181 | 181 | } |
182 | 182 | } |