Test Failed
Push — master ( a5e4c3...7495fa )
by Mike
43:00
created
src/Controllers/Version1/class-wc-rest-report-top-sellers-v1-controller.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @since    3.0.0
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -42,16 +42,16 @@  discard block
 block discarded – undo
42 42
 	 * @param WP_REST_Request $request
43 43
 	 * @return array|WP_Error
44 44
 	 */
45
-	public function get_items( $request ) {
45
+	public function get_items($request) {
46 46
 		// Set date filtering.
47 47
 		$filter = array(
48 48
 			'period'   => $request['period'],
49 49
 			'date_min' => $request['date_min'],
50 50
 			'date_max' => $request['date_max'],
51 51
 		);
52
-		$this->setup_report( $filter );
52
+		$this->setup_report($filter);
53 53
 
54
-		$report_data = $this->report->get_order_report_data( array(
54
+		$report_data = $this->report->get_order_report_data(array(
55 55
 			'data' => array(
56 56
 				'_product_id' => array(
57 57
 					'type'            => 'order_item_meta',
@@ -68,32 +68,32 @@  discard block
 block discarded – undo
68 68
 			),
69 69
 			'order_by'     => 'order_item_qty DESC',
70 70
 			'group_by'     => 'product_id',
71
-			'limit'        => isset( $filter['limit'] ) ? absint( $filter['limit'] ) : 12,
71
+			'limit'        => isset($filter['limit']) ? absint($filter['limit']) : 12,
72 72
 			'query_type'   => 'get_results',
73 73
 			'filter_range' => true,
74
-		) );
74
+		));
75 75
 
76 76
 		$top_sellers = array();
77 77
 
78
-		foreach ( $report_data as $item ) {
79
-			$product = wc_get_product( $item->product_id );
78
+		foreach ($report_data as $item) {
79
+			$product = wc_get_product($item->product_id);
80 80
 
81
-			if ( $product ) {
81
+			if ($product) {
82 82
 				$top_sellers[] = array(
83 83
 					'name'      => $product->get_name(),
84 84
 					'product_id' => (int) $item->product_id,
85
-					'quantity'   => wc_stock_amount( $item->order_item_qty ),
85
+					'quantity'   => wc_stock_amount($item->order_item_qty),
86 86
 				);
87 87
 			}
88 88
 		}
89 89
 
90 90
 		$data = array();
91
-		foreach ( $top_sellers as $top_seller ) {
92
-			$item   = $this->prepare_item_for_response( (object) $top_seller, $request );
93
-			$data[] = $this->prepare_response_for_collection( $item );
91
+		foreach ($top_sellers as $top_seller) {
92
+			$item   = $this->prepare_item_for_response((object) $top_seller, $request);
93
+			$data[] = $this->prepare_response_for_collection($item);
94 94
 		}
95 95
 
96
-		return rest_ensure_response( $data );
96
+		return rest_ensure_response($data);
97 97
 	}
98 98
 
99 99
 	/**
@@ -103,27 +103,27 @@  discard block
 block discarded – undo
103 103
 	 * @param WP_REST_Request $request Request object.
104 104
 	 * @return WP_REST_Response $response Response data.
105 105
 	 */
106
-	public function prepare_item_for_response( $top_seller, $request ) {
106
+	public function prepare_item_for_response($top_seller, $request) {
107 107
 		$data = array(
108 108
 			'name'       => $top_seller->name,
109 109
 			'product_id' => $top_seller->product_id,
110 110
 			'quantity'   => $top_seller->quantity,
111 111
 		);
112 112
 
113
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
114
-		$data    = $this->add_additional_fields_to_object( $data, $request );
115
-		$data    = $this->filter_response_by_context( $data, $context );
113
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
114
+		$data    = $this->add_additional_fields_to_object($data, $request);
115
+		$data    = $this->filter_response_by_context($data, $context);
116 116
 
117 117
 		// Wrap the data in a response object.
118
-		$response = rest_ensure_response( $data );
119
-		$response->add_links( array(
118
+		$response = rest_ensure_response($data);
119
+		$response->add_links(array(
120 120
 			'about' => array(
121
-				'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ),
121
+				'href' => rest_url(sprintf('%s/reports', $this->namespace)),
122 122
 			),
123 123
 			'product' => array(
124
-				'href' => rest_url( sprintf( '/%s/products/%s', $this->namespace, $top_seller->product_id ) ),
124
+				'href' => rest_url(sprintf('/%s/products/%s', $this->namespace, $top_seller->product_id)),
125 125
 			),
126
-		) );
126
+		));
127 127
 
128 128
 		/**
129 129
 		 * Filter a report top sellers returned from the API.
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 		 * @param stdClass         $top_seller The original report object.
135 135
 		 * @param WP_REST_Request  $request    Request used to generate the response.
136 136
 		 */
137
-		return apply_filters( 'woocommerce_rest_prepare_report_top_sellers', $response, $top_seller, $request );
137
+		return apply_filters('woocommerce_rest_prepare_report_top_sellers', $response, $top_seller, $request);
138 138
 	}
139 139
 
140 140
 	/**
@@ -149,26 +149,26 @@  discard block
 block discarded – undo
149 149
 			'type'       => 'object',
150 150
 			'properties' => array(
151 151
 				'name' => array(
152
-					'description' => __( 'Product name.', 'woocommerce' ),
152
+					'description' => __('Product name.', 'woocommerce'),
153 153
 					'type'        => 'string',
154
-					'context'     => array( 'view' ),
154
+					'context'     => array('view'),
155 155
 					'readonly'    => true,
156 156
 				),
157 157
 				'product_id' => array(
158
-					'description' => __( 'Product ID.', 'woocommerce' ),
158
+					'description' => __('Product ID.', 'woocommerce'),
159 159
 					'type'        => 'integer',
160
-					'context'     => array( 'view' ),
160
+					'context'     => array('view'),
161 161
 					'readonly'    => true,
162 162
 				),
163 163
 				'quantity' => array(
164
-					'description' => __( 'Total number of purchases.', 'woocommerce' ),
164
+					'description' => __('Total number of purchases.', 'woocommerce'),
165 165
 					'type'        => 'integer',
166
-					'context'     => array( 'view' ),
166
+					'context'     => array('view'),
167 167
 					'readonly'    => true,
168 168
 				),
169 169
 			),
170 170
 		);
171 171
 
172
-		return $this->add_additional_fields_schema( $schema );
172
+		return $this->add_additional_fields_schema($schema);
173 173
 	}
174 174
 }
Please login to merge, or discard this patch.
src/Controllers/Version1/class-wc-rest-taxes-v1-controller.php 1 patch
Spacing   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @since    3.0.0
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -40,67 +40,67 @@  discard block
 block discarded – undo
40 40
 	 * Register the routes for taxes.
41 41
 	 */
42 42
 	public function register_routes() {
43
-		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
43
+		register_rest_route($this->namespace, '/' . $this->rest_base, array(
44 44
 			array(
45 45
 				'methods'             => WP_REST_Server::READABLE,
46
-				'callback'            => array( $this, 'get_items' ),
47
-				'permission_callback' => array( $this, 'get_items_permissions_check' ),
46
+				'callback'            => array($this, 'get_items'),
47
+				'permission_callback' => array($this, 'get_items_permissions_check'),
48 48
 				'args'                => $this->get_collection_params(),
49 49
 			),
50 50
 			array(
51 51
 				'methods'             => WP_REST_Server::CREATABLE,
52
-				'callback'            => array( $this, 'create_item' ),
53
-				'permission_callback' => array( $this, 'create_item_permissions_check' ),
54
-				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
52
+				'callback'            => array($this, 'create_item'),
53
+				'permission_callback' => array($this, 'create_item_permissions_check'),
54
+				'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
55 55
 			),
56
-			'schema' => array( $this, 'get_public_item_schema' ),
57
-		) );
56
+			'schema' => array($this, 'get_public_item_schema'),
57
+		));
58 58
 
59
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
59
+		register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
60 60
 			'args' => array(
61 61
 				'id' => array(
62
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
62
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
63 63
 					'type'        => 'integer',
64 64
 				),
65 65
 			),
66 66
 			array(
67 67
 				'methods'             => WP_REST_Server::READABLE,
68
-				'callback'            => array( $this, 'get_item' ),
69
-				'permission_callback' => array( $this, 'get_item_permissions_check' ),
68
+				'callback'            => array($this, 'get_item'),
69
+				'permission_callback' => array($this, 'get_item_permissions_check'),
70 70
 				'args'                => array(
71
-					'context' => $this->get_context_param( array( 'default' => 'view' ) ),
71
+					'context' => $this->get_context_param(array('default' => 'view')),
72 72
 				),
73 73
 			),
74 74
 			array(
75 75
 				'methods'             => WP_REST_Server::EDITABLE,
76
-				'callback'            => array( $this, 'update_item' ),
77
-				'permission_callback' => array( $this, 'update_item_permissions_check' ),
78
-				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
76
+				'callback'            => array($this, 'update_item'),
77
+				'permission_callback' => array($this, 'update_item_permissions_check'),
78
+				'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
79 79
 			),
80 80
 			array(
81 81
 				'methods'             => WP_REST_Server::DELETABLE,
82
-				'callback'            => array( $this, 'delete_item' ),
83
-				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
82
+				'callback'            => array($this, 'delete_item'),
83
+				'permission_callback' => array($this, 'delete_item_permissions_check'),
84 84
 				'args'                => array(
85 85
 					'force' => array(
86 86
 						'default'     => false,
87 87
 						'type'        => 'boolean',
88
-						'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
88
+						'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
89 89
 					),
90 90
 				),
91 91
 			),
92
-			'schema' => array( $this, 'get_public_item_schema' ),
93
-		) );
92
+			'schema' => array($this, 'get_public_item_schema'),
93
+		));
94 94
 
95
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
95
+		register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', 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' ),
103
-		) );
102
+			'schema' => array($this, 'get_public_batch_schema'),
103
+		));
104 104
 	}
105 105
 
106 106
 	/**
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
 	 * @param  WP_REST_Request $request Full details about the request.
110 110
 	 * @return WP_Error|boolean
111 111
 	 */
112
-	public function get_items_permissions_check( $request ) {
113
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
114
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
112
+	public function get_items_permissions_check($request) {
113
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
114
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
115 115
 		}
116 116
 
117 117
 		return true;
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
 	 *
125 125
 	 * @return bool|WP_Error
126 126
 	 */
127
-	public function create_item_permissions_check( $request ) {
128
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'create' ) ) {
129
-			return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
127
+	public function create_item_permissions_check($request) {
128
+		if ( ! wc_rest_check_manager_permissions('settings', 'create')) {
129
+			return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
130 130
 		}
131 131
 
132 132
 		return true;
@@ -138,9 +138,9 @@  discard block
 block discarded – undo
138 138
 	 * @param  WP_REST_Request $request Full details about the request.
139 139
 	 * @return WP_Error|boolean
140 140
 	 */
141
-	public function get_item_permissions_check( $request ) {
142
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
143
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
141
+	public function get_item_permissions_check($request) {
142
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
143
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
144 144
 		}
145 145
 
146 146
 		return true;
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
 	 *
154 154
 	 * @return bool|WP_Error
155 155
 	 */
156
-	public function update_item_permissions_check( $request ) {
157
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
158
-			return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
156
+	public function update_item_permissions_check($request) {
157
+		if ( ! wc_rest_check_manager_permissions('settings', 'edit')) {
158
+			return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
159 159
 		}
160 160
 
161 161
 		return true;
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
 	 *
169 169
 	 * @return bool|WP_Error
170 170
 	 */
171
-	public function delete_item_permissions_check( $request ) {
172
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) {
173
-			return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
171
+	public function delete_item_permissions_check($request) {
172
+		if ( ! wc_rest_check_manager_permissions('settings', 'delete')) {
173
+			return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
174 174
 		}
175 175
 
176 176
 		return true;
@@ -183,9 +183,9 @@  discard block
 block discarded – undo
183 183
 	 *
184 184
 	 * @return bool|WP_Error
185 185
 	 */
186
-	public function batch_items_permissions_check( $request ) {
187
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'batch' ) ) {
188
-			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() ) );
186
+	public function batch_items_permissions_check($request) {
187
+		if ( ! wc_rest_check_manager_permissions('settings', 'batch')) {
188
+			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()));
189 189
 		}
190 190
 
191 191
 		return true;
@@ -197,22 +197,22 @@  discard block
 block discarded – undo
197 197
 	 * @param WP_REST_Request $request Full details about the request.
198 198
 	 * @return WP_Error|WP_REST_Response
199 199
 	 */
200
-	public function get_items( $request ) {
200
+	public function get_items($request) {
201 201
 		global $wpdb;
202 202
 
203 203
 		$prepared_args = array();
204 204
 		$prepared_args['order']  = $request['order'];
205 205
 		$prepared_args['number'] = $request['per_page'];
206
-		if ( ! empty( $request['offset'] ) ) {
206
+		if ( ! empty($request['offset'])) {
207 207
 			$prepared_args['offset'] = $request['offset'];
208 208
 		} else {
209
-			$prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
209
+			$prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number'];
210 210
 		}
211 211
 		$orderby_possibles = array(
212 212
 			'id'    => 'tax_rate_id',
213 213
 			'order' => 'tax_rate_order',
214 214
 		);
215
-		$prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ];
215
+		$prepared_args['orderby'] = $orderby_possibles[$request['orderby']];
216 216
 		$prepared_args['class']   = $request['class'];
217 217
 
218 218
 		/**
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 		 * @param array           $prepared_args Array of arguments for $wpdb->get_results().
222 222
 		 * @param WP_REST_Request $request       The current request.
223 223
 		 */
224
-		$prepared_args = apply_filters( 'woocommerce_rest_tax_query', $prepared_args, $request );
224
+		$prepared_args = apply_filters('woocommerce_rest_tax_query', $prepared_args, $request);
225 225
 
226 226
 		$query = "
227 227
 			SELECT *
@@ -230,54 +230,54 @@  discard block
 block discarded – undo
230 230
 		";
231 231
 
232 232
 		// Filter by tax class.
233
-		if ( ! empty( $prepared_args['class'] ) ) {
234
-			$class = 'standard' !== $prepared_args['class'] ? sanitize_title( $prepared_args['class'] ) : '';
233
+		if ( ! empty($prepared_args['class'])) {
234
+			$class = 'standard' !== $prepared_args['class'] ? sanitize_title($prepared_args['class']) : '';
235 235
 			$query .= " AND tax_rate_class = '$class'";
236 236
 		}
237 237
 
238 238
 		// Order tax rates.
239
-		$order_by = sprintf( ' ORDER BY %s', sanitize_key( $prepared_args['orderby'] ) );
239
+		$order_by = sprintf(' ORDER BY %s', sanitize_key($prepared_args['orderby']));
240 240
 
241 241
 		// Pagination.
242
-		$pagination = sprintf( ' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number'] );
242
+		$pagination = sprintf(' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number']);
243 243
 
244 244
 		// Query taxes.
245
-		$results = $wpdb->get_results( $query . $order_by . $pagination );
245
+		$results = $wpdb->get_results($query . $order_by . $pagination);
246 246
 
247 247
 		$taxes = array();
248
-		foreach ( $results as $tax ) {
249
-			$data = $this->prepare_item_for_response( $tax, $request );
250
-			$taxes[] = $this->prepare_response_for_collection( $data );
248
+		foreach ($results as $tax) {
249
+			$data = $this->prepare_item_for_response($tax, $request);
250
+			$taxes[] = $this->prepare_response_for_collection($data);
251 251
 		}
252 252
 
253
-		$response = rest_ensure_response( $taxes );
253
+		$response = rest_ensure_response($taxes);
254 254
 
255 255
 		// Store pagination values for headers then unset for count query.
256 256
 		$per_page = (int) $prepared_args['number'];
257
-		$page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
257
+		$page = ceil((((int) $prepared_args['offset']) / $per_page) + 1);
258 258
 
259 259
 		// Query only for ids.
260
-		$wpdb->get_results( str_replace( 'SELECT *', 'SELECT tax_rate_id', $query ) );
260
+		$wpdb->get_results(str_replace('SELECT *', 'SELECT tax_rate_id', $query));
261 261
 
262 262
 		// Calculate totals.
263 263
 		$total_taxes = (int) $wpdb->num_rows;
264
-		$response->header( 'X-WP-Total', (int) $total_taxes );
265
-		$max_pages = ceil( $total_taxes / $per_page );
266
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
264
+		$response->header('X-WP-Total', (int) $total_taxes);
265
+		$max_pages = ceil($total_taxes / $per_page);
266
+		$response->header('X-WP-TotalPages', (int) $max_pages);
267 267
 
268
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
269
-		if ( $page > 1 ) {
268
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
269
+		if ($page > 1) {
270 270
 			$prev_page = $page - 1;
271
-			if ( $prev_page > $max_pages ) {
271
+			if ($prev_page > $max_pages) {
272 272
 				$prev_page = $max_pages;
273 273
 			}
274
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
275
-			$response->link_header( 'prev', $prev_link );
274
+			$prev_link = add_query_arg('page', $prev_page, $base);
275
+			$response->link_header('prev', $prev_link);
276 276
 		}
277
-		if ( $max_pages > $page ) {
277
+		if ($max_pages > $page) {
278 278
 			$next_page = $page + 1;
279
-			$next_link = add_query_arg( 'page', $next_page, $base );
280
-			$response->link_header( 'next', $next_link );
279
+			$next_link = add_query_arg('page', $next_page, $base);
280
+			$response->link_header('next', $next_link);
281 281
 		}
282 282
 
283 283
 		return $response;
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
 	 * @param stdClass|null $current Existing tax object.
291 291
 	 * @return object
292 292
 	 */
293
-	protected function create_or_update_tax( $request, $current = null ) {
294
-		$id          = absint( isset( $request['id'] ) ? $request['id'] : 0 );
293
+	protected function create_or_update_tax($request, $current = null) {
294
+		$id          = absint(isset($request['id']) ? $request['id'] : 0);
295 295
 		$data        = array();
296 296
 		$fields      = array(
297 297
 			'tax_rate_country',
@@ -305,52 +305,52 @@  discard block
 block discarded – undo
305 305
 			'tax_rate_class',
306 306
 		);
307 307
 
308
-		foreach ( $fields as $field ) {
308
+		foreach ($fields as $field) {
309 309
 			// Keys via API differ from the stored names returned by _get_tax_rate.
310
-			$key = 'tax_rate' === $field ? 'rate' : str_replace( 'tax_rate_', '', $field );
310
+			$key = 'tax_rate' === $field ? 'rate' : str_replace('tax_rate_', '', $field);
311 311
 
312 312
 			// Remove data that was not posted.
313
-			if ( ! isset( $request[ $key ] ) ) {
313
+			if ( ! isset($request[$key])) {
314 314
 				continue;
315 315
 			}
316 316
 
317 317
 			// Test new data against current data.
318
-			if ( $current && $current->$field === $request[ $key ] ) {
318
+			if ($current && $current->$field === $request[$key]) {
319 319
 				continue;
320 320
 			}
321 321
 
322 322
 			// Add to data array.
323
-			switch ( $key ) {
323
+			switch ($key) {
324 324
 				case 'tax_rate_priority' :
325 325
 				case 'tax_rate_compound' :
326 326
 				case 'tax_rate_shipping' :
327 327
 				case 'tax_rate_order' :
328
-					$data[ $field ] = absint( $request[ $key ] );
328
+					$data[$field] = absint($request[$key]);
329 329
 					break;
330 330
 				case 'tax_rate_class' :
331
-					$data[ $field ] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : '';
331
+					$data[$field] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : '';
332 332
 					break;
333 333
 				default :
334
-					$data[ $field ] = wc_clean( $request[ $key ] );
334
+					$data[$field] = wc_clean($request[$key]);
335 335
 					break;
336 336
 			}
337 337
 		}
338 338
 
339
-		if ( $id ) {
340
-			WC_Tax::_update_tax_rate( $id, $data );
339
+		if ($id) {
340
+			WC_Tax::_update_tax_rate($id, $data);
341 341
 		} else {
342
-			$id = WC_Tax::_insert_tax_rate( $data );
342
+			$id = WC_Tax::_insert_tax_rate($data);
343 343
 		}
344 344
 
345 345
 		// Add locales.
346
-		if ( ! empty( $request['postcode'] ) ) {
347
-			WC_Tax::_update_tax_rate_postcodes( $id, wc_clean( $request['postcode'] ) );
346
+		if ( ! empty($request['postcode'])) {
347
+			WC_Tax::_update_tax_rate_postcodes($id, wc_clean($request['postcode']));
348 348
 		}
349
-		if ( ! empty( $request['city'] ) ) {
350
-			WC_Tax::_update_tax_rate_cities( $id, wc_clean( $request['city'] ) );
349
+		if ( ! empty($request['city'])) {
350
+			WC_Tax::_update_tax_rate_cities($id, wc_clean($request['city']));
351 351
 		}
352 352
 
353
-		return WC_Tax::_get_tax_rate( $id, OBJECT );
353
+		return WC_Tax::_get_tax_rate($id, OBJECT);
354 354
 	}
355 355
 
356 356
 	/**
@@ -359,14 +359,14 @@  discard block
 block discarded – undo
359 359
 	 * @param WP_REST_Request $request Full details about the request.
360 360
 	 * @return WP_Error|WP_REST_Response
361 361
 	 */
362
-	public function create_item( $request ) {
363
-		if ( ! empty( $request['id'] ) ) {
364
-			return new WP_Error( 'woocommerce_rest_tax_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) );
362
+	public function create_item($request) {
363
+		if ( ! empty($request['id'])) {
364
+			return new WP_Error('woocommerce_rest_tax_exists', __('Cannot create existing resource.', 'woocommerce'), array('status' => 400));
365 365
 		}
366 366
 
367
-		$tax = $this->create_or_update_tax( $request );
367
+		$tax = $this->create_or_update_tax($request);
368 368
 
369
-		$this->update_additional_fields_for_object( $tax, $request );
369
+		$this->update_additional_fields_for_object($tax, $request);
370 370
 
371 371
 		/**
372 372
 		 * Fires after a tax is created or updated via the REST API.
@@ -375,13 +375,13 @@  discard block
 block discarded – undo
375 375
 		 * @param WP_REST_Request $request   Request object.
376 376
 		 * @param boolean         $creating  True when creating tax, false when updating tax.
377 377
 		 */
378
-		do_action( 'woocommerce_rest_insert_tax', $tax, $request, true );
378
+		do_action('woocommerce_rest_insert_tax', $tax, $request, true);
379 379
 
380
-		$request->set_param( 'context', 'edit' );
381
-		$response = $this->prepare_item_for_response( $tax, $request );
382
-		$response = rest_ensure_response( $response );
383
-		$response->set_status( 201 );
384
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id ) ) );
380
+		$request->set_param('context', 'edit');
381
+		$response = $this->prepare_item_for_response($tax, $request);
382
+		$response = rest_ensure_response($response);
383
+		$response->set_status(201);
384
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id)));
385 385
 
386 386
 		return $response;
387 387
 	}
@@ -392,16 +392,16 @@  discard block
 block discarded – undo
392 392
 	 * @param WP_REST_Request $request Full details about the request.
393 393
 	 * @return WP_Error|WP_REST_Response
394 394
 	 */
395
-	public function get_item( $request ) {
395
+	public function get_item($request) {
396 396
 		$id      = (int) $request['id'];
397
-		$tax_obj = WC_Tax::_get_tax_rate( $id, OBJECT );
397
+		$tax_obj = WC_Tax::_get_tax_rate($id, OBJECT);
398 398
 
399
-		if ( empty( $id ) || empty( $tax_obj ) ) {
400
-			return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
399
+		if (empty($id) || empty($tax_obj)) {
400
+			return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404));
401 401
 		}
402 402
 
403
-		$tax      = $this->prepare_item_for_response( $tax_obj, $request );
404
-		$response = rest_ensure_response( $tax );
403
+		$tax      = $this->prepare_item_for_response($tax_obj, $request);
404
+		$response = rest_ensure_response($tax);
405 405
 
406 406
 		return $response;
407 407
 	}
@@ -412,17 +412,17 @@  discard block
 block discarded – undo
412 412
 	 * @param WP_REST_Request $request Full details about the request.
413 413
 	 * @return WP_Error|WP_REST_Response
414 414
 	 */
415
-	public function update_item( $request ) {
415
+	public function update_item($request) {
416 416
 		$id      = (int) $request['id'];
417
-		$tax_obj = WC_Tax::_get_tax_rate( $id, OBJECT );
417
+		$tax_obj = WC_Tax::_get_tax_rate($id, OBJECT);
418 418
 
419
-		if ( empty( $id ) || empty( $tax_obj ) ) {
420
-			return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
419
+		if (empty($id) || empty($tax_obj)) {
420
+			return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404));
421 421
 		}
422 422
 
423
-		$tax = $this->create_or_update_tax( $request, $tax_obj );
423
+		$tax = $this->create_or_update_tax($request, $tax_obj);
424 424
 
425
-		$this->update_additional_fields_for_object( $tax, $request );
425
+		$this->update_additional_fields_for_object($tax, $request);
426 426
 
427 427
 		/**
428 428
 		 * Fires after a tax is created or updated via the REST API.
@@ -431,11 +431,11 @@  discard block
 block discarded – undo
431 431
 		 * @param WP_REST_Request $request   Request object.
432 432
 		 * @param boolean         $creating  True when creating tax, false when updating tax.
433 433
 		 */
434
-		do_action( 'woocommerce_rest_insert_tax', $tax, $request, false );
434
+		do_action('woocommerce_rest_insert_tax', $tax, $request, false);
435 435
 
436
-		$request->set_param( 'context', 'edit' );
437
-		$response = $this->prepare_item_for_response( $tax, $request );
438
-		$response = rest_ensure_response( $response );
436
+		$request->set_param('context', 'edit');
437
+		$response = $this->prepare_item_for_response($tax, $request);
438
+		$response = rest_ensure_response($response);
439 439
 
440 440
 		return $response;
441 441
 	}
@@ -446,30 +446,30 @@  discard block
 block discarded – undo
446 446
 	 * @param WP_REST_Request $request Full details about the request.
447 447
 	 * @return WP_Error|WP_REST_Response
448 448
 	 */
449
-	public function delete_item( $request ) {
449
+	public function delete_item($request) {
450 450
 		global $wpdb;
451 451
 
452 452
 		$id    = (int) $request['id'];
453
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
453
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
454 454
 
455 455
 		// We don't support trashing for this type, error out.
456
-		if ( ! $force ) {
457
-			return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Taxes do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
456
+		if ( ! $force) {
457
+			return new WP_Error('woocommerce_rest_trash_not_supported', __('Taxes do not support trashing.', 'woocommerce'), array('status' => 501));
458 458
 		}
459 459
 
460
-		$tax = WC_Tax::_get_tax_rate( $id, OBJECT );
460
+		$tax = WC_Tax::_get_tax_rate($id, OBJECT);
461 461
 
462
-		if ( empty( $id ) || empty( $tax ) ) {
463
-			return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 400 ) );
462
+		if (empty($id) || empty($tax)) {
463
+			return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 400));
464 464
 		}
465 465
 
466
-		$request->set_param( 'context', 'edit' );
467
-		$response = $this->prepare_item_for_response( $tax, $request );
466
+		$request->set_param('context', 'edit');
467
+		$response = $this->prepare_item_for_response($tax, $request);
468 468
 
469
-		WC_Tax::_delete_tax_rate( $id );
469
+		WC_Tax::_delete_tax_rate($id);
470 470
 
471
-		if ( 0 === $wpdb->rows_affected ) {
472
-			return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
471
+		if (0 === $wpdb->rows_affected) {
472
+			return new WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500));
473 473
 		}
474 474
 
475 475
 		/**
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 		 * @param WP_REST_Response $response The response returned from the API.
480 480
 		 * @param WP_REST_Request  $request  The request sent to the API.
481 481
 		 */
482
-		do_action( 'woocommerce_rest_delete_tax', $tax, $response, $request );
482
+		do_action('woocommerce_rest_delete_tax', $tax, $response, $request);
483 483
 
484 484
 		return $response;
485 485
 	}
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
 	 * @param WP_REST_Request $request Request object.
492 492
 	 * @return WP_REST_Response $response Response data.
493 493
 	 */
494
-	public function prepare_item_for_response( $tax, $request ) {
494
+	public function prepare_item_for_response($tax, $request) {
495 495
 		global $wpdb;
496 496
 
497 497
 		$id   = (int) $tax->tax_rate_id;
@@ -511,26 +511,26 @@  discard block
 block discarded – undo
511 511
 		);
512 512
 
513 513
 		// Get locales from a tax rate.
514
-		$locales = $wpdb->get_results( $wpdb->prepare( "
514
+		$locales = $wpdb->get_results($wpdb->prepare("
515 515
 			SELECT location_code, location_type
516 516
 			FROM {$wpdb->prefix}woocommerce_tax_rate_locations
517 517
 			WHERE tax_rate_id = %d
518
-		", $id ) );
518
+		", $id));
519 519
 
520
-		if ( ! is_wp_error( $tax ) && ! is_null( $tax ) ) {
521
-			foreach ( $locales as $locale ) {
522
-				$data[ $locale->location_type ] = $locale->location_code;
520
+		if ( ! is_wp_error($tax) && ! is_null($tax)) {
521
+			foreach ($locales as $locale) {
522
+				$data[$locale->location_type] = $locale->location_code;
523 523
 			}
524 524
 		}
525 525
 
526
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
527
-		$data    = $this->add_additional_fields_to_object( $data, $request );
528
-		$data    = $this->filter_response_by_context( $data, $context );
526
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
527
+		$data    = $this->add_additional_fields_to_object($data, $request);
528
+		$data    = $this->filter_response_by_context($data, $context);
529 529
 
530 530
 		// Wrap the data in a response object.
531
-		$response = rest_ensure_response( $data );
531
+		$response = rest_ensure_response($data);
532 532
 
533
-		$response->add_links( $this->prepare_links( $tax ) );
533
+		$response->add_links($this->prepare_links($tax));
534 534
 
535 535
 		/**
536 536
 		 * Filter tax object returned from the REST API.
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 		 * @param stdClass         $tax      Tax object used to create response.
540 540
 		 * @param WP_REST_Request  $request  Request object.
541 541
 		 */
542
-		return apply_filters( 'woocommerce_rest_prepare_tax', $response, $tax, $request );
542
+		return apply_filters('woocommerce_rest_prepare_tax', $response, $tax, $request);
543 543
 	}
544 544
 
545 545
 	/**
@@ -548,13 +548,13 @@  discard block
 block discarded – undo
548 548
 	 * @param stdClass $tax Tax object.
549 549
 	 * @return array Links for the given tax.
550 550
 	 */
551
-	protected function prepare_links( $tax ) {
551
+	protected function prepare_links($tax) {
552 552
 		$links = array(
553 553
 			'self' => array(
554
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id ) ),
554
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id)),
555 555
 			),
556 556
 			'collection' => array(
557
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
557
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
558 558
 			),
559 559
 		);
560 560
 
@@ -573,75 +573,75 @@  discard block
 block discarded – undo
573 573
 			'type'       => 'object',
574 574
 			'properties' => array(
575 575
 				'id' => array(
576
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
576
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
577 577
 					'type'        => 'integer',
578
-					'context'     => array( 'view', 'edit' ),
578
+					'context'     => array('view', 'edit'),
579 579
 					'readonly'    => true,
580 580
 				),
581 581
 				'country' => array(
582
-					'description' => __( 'Country ISO 3166 code.', 'woocommerce' ),
582
+					'description' => __('Country ISO 3166 code.', 'woocommerce'),
583 583
 					'type'        => 'string',
584
-					'context'     => array( 'view', 'edit' ),
584
+					'context'     => array('view', 'edit'),
585 585
 				),
586 586
 				'state' => array(
587
-					'description' => __( 'State code.', 'woocommerce' ),
587
+					'description' => __('State code.', 'woocommerce'),
588 588
 					'type'        => 'string',
589
-					'context'     => array( 'view', 'edit' ),
589
+					'context'     => array('view', 'edit'),
590 590
 				),
591 591
 				'postcode' => array(
592
-					'description' => __( 'Postcode / ZIP.', 'woocommerce' ),
592
+					'description' => __('Postcode / ZIP.', 'woocommerce'),
593 593
 					'type'        => 'string',
594
-					'context'     => array( 'view', 'edit' ),
594
+					'context'     => array('view', 'edit'),
595 595
 				),
596 596
 				'city' => array(
597
-					'description' => __( 'City name.', 'woocommerce' ),
597
+					'description' => __('City name.', 'woocommerce'),
598 598
 					'type'        => 'string',
599
-					'context'     => array( 'view', 'edit' ),
599
+					'context'     => array('view', 'edit'),
600 600
 				),
601 601
 				'rate' => array(
602
-					'description' => __( 'Tax rate.', 'woocommerce' ),
602
+					'description' => __('Tax rate.', 'woocommerce'),
603 603
 					'type'        => 'string',
604
-					'context'     => array( 'view', 'edit' ),
604
+					'context'     => array('view', 'edit'),
605 605
 				),
606 606
 				'name' => array(
607
-					'description' => __( 'Tax rate name.', 'woocommerce' ),
607
+					'description' => __('Tax rate name.', 'woocommerce'),
608 608
 					'type'        => 'string',
609
-					'context'     => array( 'view', 'edit' ),
609
+					'context'     => array('view', 'edit'),
610 610
 				),
611 611
 				'priority' => array(
612
-					'description' => __( 'Tax priority.', 'woocommerce' ),
612
+					'description' => __('Tax priority.', 'woocommerce'),
613 613
 					'type'        => 'integer',
614 614
 					'default'     => 1,
615
-					'context'     => array( 'view', 'edit' ),
615
+					'context'     => array('view', 'edit'),
616 616
 				),
617 617
 				'compound' => array(
618
-					'description' => __( 'Whether or not this is a compound rate.', 'woocommerce' ),
618
+					'description' => __('Whether or not this is a compound rate.', 'woocommerce'),
619 619
 					'type'        => 'boolean',
620 620
 					'default'     => false,
621
-					'context'     => array( 'view', 'edit' ),
621
+					'context'     => array('view', 'edit'),
622 622
 				),
623 623
 				'shipping' => array(
624
-					'description' => __( 'Whether or not this tax rate also gets applied to shipping.', 'woocommerce' ),
624
+					'description' => __('Whether or not this tax rate also gets applied to shipping.', 'woocommerce'),
625 625
 					'type'        => 'boolean',
626 626
 					'default'     => true,
627
-					'context'     => array( 'view', 'edit' ),
627
+					'context'     => array('view', 'edit'),
628 628
 				),
629 629
 				'order' => array(
630
-					'description' => __( 'Indicates the order that will appear in queries.', 'woocommerce' ),
630
+					'description' => __('Indicates the order that will appear in queries.', 'woocommerce'),
631 631
 					'type'        => 'integer',
632
-					'context'     => array( 'view', 'edit' ),
632
+					'context'     => array('view', 'edit'),
633 633
 				),
634 634
 				'class' => array(
635
-					'description' => __( 'Tax class.', 'woocommerce' ),
635
+					'description' => __('Tax class.', 'woocommerce'),
636 636
 					'type'        => 'string',
637 637
 					'default'     => 'standard',
638
-					'enum'        => array_merge( array( 'standard' ), WC_Tax::get_tax_class_slugs() ),
639
-					'context'     => array( 'view', 'edit' ),
638
+					'enum'        => array_merge(array('standard'), WC_Tax::get_tax_class_slugs()),
639
+					'context'     => array('view', 'edit'),
640 640
 				),
641 641
 			),
642 642
 		);
643 643
 
644
-		return $this->add_additional_fields_schema( $schema );
644
+		return $this->add_additional_fields_schema($schema);
645 645
 	}
646 646
 
647 647
 	/**
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
 		$params['context']['default'] = 'view';
656 656
 
657 657
 		$params['page'] = array(
658
-			'description'        => __( 'Current page of the collection.', 'woocommerce' ),
658
+			'description'        => __('Current page of the collection.', 'woocommerce'),
659 659
 			'type'               => 'integer',
660 660
 			'default'            => 1,
661 661
 			'sanitize_callback'  => 'absint',
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
 			'minimum'            => 1,
664 664
 		);
665 665
 		$params['per_page'] = array(
666
-			'description'        => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
666
+			'description'        => __('Maximum number of items to be returned in result set.', 'woocommerce'),
667 667
 			'type'               => 'integer',
668 668
 			'default'            => 10,
669 669
 			'minimum'            => 1,
@@ -672,22 +672,22 @@  discard block
 block discarded – undo
672 672
 			'validate_callback'  => 'rest_validate_request_arg',
673 673
 		);
674 674
 		$params['offset'] = array(
675
-			'description'        => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
675
+			'description'        => __('Offset the result set by a specific number of items.', 'woocommerce'),
676 676
 			'type'               => 'integer',
677 677
 			'sanitize_callback'  => 'absint',
678 678
 			'validate_callback'  => 'rest_validate_request_arg',
679 679
 		);
680 680
 		$params['order'] = array(
681 681
 			'default'            => 'asc',
682
-			'description'        => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
683
-			'enum'               => array( 'asc', 'desc' ),
682
+			'description'        => __('Order sort attribute ascending or descending.', 'woocommerce'),
683
+			'enum'               => array('asc', 'desc'),
684 684
 			'sanitize_callback'  => 'sanitize_key',
685 685
 			'type'               => 'string',
686 686
 			'validate_callback'  => 'rest_validate_request_arg',
687 687
 		);
688 688
 		$params['orderby'] = array(
689 689
 			'default'            => 'order',
690
-			'description'        => __( 'Sort collection by object attribute.', 'woocommerce' ),
690
+			'description'        => __('Sort collection by object attribute.', 'woocommerce'),
691 691
 			'enum'               => array(
692 692
 				'id',
693 693
 				'order',
@@ -697,8 +697,8 @@  discard block
 block discarded – undo
697 697
 			'validate_callback'  => 'rest_validate_request_arg',
698 698
 		);
699 699
 		$params['class'] = array(
700
-			'description'        => __( 'Sort by tax class.', 'woocommerce' ),
701
-			'enum'               => array_merge( array( 'standard' ), WC_Tax::get_tax_class_slugs() ),
700
+			'description'        => __('Sort by tax class.', 'woocommerce'),
701
+			'enum'               => array_merge(array('standard'), WC_Tax::get_tax_class_slugs()),
702 702
 			'sanitize_callback'  => 'sanitize_title',
703 703
 			'type'               => 'string',
704 704
 			'validate_callback'  => 'rest_validate_request_arg',
Please login to merge, or discard this patch.
src/Controllers/Version1/class-wc-rest-tax-classes-v1-controller.php 1 patch
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @since    3.0.0
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -40,43 +40,43 @@  discard block
 block discarded – undo
40 40
 	 * Register the routes for tax classes.
41 41
 	 */
42 42
 	public function register_routes() {
43
-		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
43
+		register_rest_route($this->namespace, '/' . $this->rest_base, array(
44 44
 			array(
45 45
 				'methods'             => WP_REST_Server::READABLE,
46
-				'callback'            => array( $this, 'get_items' ),
47
-				'permission_callback' => array( $this, 'get_items_permissions_check' ),
46
+				'callback'            => array($this, 'get_items'),
47
+				'permission_callback' => array($this, 'get_items_permissions_check'),
48 48
 				'args'                => $this->get_collection_params(),
49 49
 			),
50 50
 			array(
51 51
 				'methods'             => WP_REST_Server::CREATABLE,
52
-				'callback'            => array( $this, 'create_item' ),
53
-				'permission_callback' => array( $this, 'create_item_permissions_check' ),
54
-				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
52
+				'callback'            => array($this, 'create_item'),
53
+				'permission_callback' => array($this, 'create_item_permissions_check'),
54
+				'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
55 55
 			),
56
-			'schema' => array( $this, 'get_public_item_schema' ),
57
-		) );
56
+			'schema' => array($this, 'get_public_item_schema'),
57
+		));
58 58
 
59
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<slug>\w[\w\s\-]*)', array(
59
+		register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<slug>\w[\w\s\-]*)', array(
60 60
 			'args' => array(
61 61
 				'slug' => array(
62
-					'description' => __( 'Unique slug for the resource.', 'woocommerce' ),
62
+					'description' => __('Unique slug for the resource.', 'woocommerce'),
63 63
 					'type'        => 'string',
64 64
 				),
65 65
 			),
66 66
 			array(
67 67
 				'methods'             => WP_REST_Server::DELETABLE,
68
-				'callback'            => array( $this, 'delete_item' ),
69
-				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
68
+				'callback'            => array($this, 'delete_item'),
69
+				'permission_callback' => array($this, 'delete_item_permissions_check'),
70 70
 				'args'                => array(
71 71
 					'force' => array(
72 72
 						'default'     => false,
73 73
 						'type'        => 'boolean',
74
-						'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
74
+						'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
75 75
 					),
76 76
 				),
77 77
 			),
78
-			'schema' => array( $this, 'get_public_item_schema' ),
79
-		) );
78
+			'schema' => array($this, 'get_public_item_schema'),
79
+		));
80 80
 	}
81 81
 
82 82
 	/**
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	 * @param  WP_REST_Request $request Full details about the request.
86 86
 	 * @return WP_Error|boolean
87 87
 	 */
88
-	public function get_items_permissions_check( $request ) {
89
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
90
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
88
+	public function get_items_permissions_check($request) {
89
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
90
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
91 91
 		}
92 92
 
93 93
 		return true;
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
 	 *
101 101
 	 * @return bool|WP_Error
102 102
 	 */
103
-	public function create_item_permissions_check( $request ) {
104
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'create' ) ) {
105
-			return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
103
+	public function create_item_permissions_check($request) {
104
+		if ( ! wc_rest_check_manager_permissions('settings', 'create')) {
105
+			return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
106 106
 		}
107 107
 
108 108
 		return true;
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
 	 *
116 116
 	 * @return bool|WP_Error
117 117
 	 */
118
-	public function delete_item_permissions_check( $request ) {
119
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) {
120
-			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
+	public function delete_item_permissions_check($request) {
119
+		if ( ! wc_rest_check_manager_permissions('settings', 'delete')) {
120
+			return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
121 121
 		}
122 122
 
123 123
 		return true;
@@ -129,32 +129,32 @@  discard block
 block discarded – undo
129 129
 	 * @param WP_REST_Request $request
130 130
 	 * @return array
131 131
 	 */
132
-	public function get_items( $request ) {
132
+	public function get_items($request) {
133 133
 		$tax_classes = array();
134 134
 
135 135
 		// Add standard class.
136 136
 		$tax_classes[] = array(
137 137
 			'slug' => 'standard',
138
-			'name' => __( 'Standard rate', 'woocommerce' ),
138
+			'name' => __('Standard rate', 'woocommerce'),
139 139
 		);
140 140
 
141 141
 		$classes = WC_Tax::get_tax_classes();
142 142
 
143
-		foreach ( $classes as $class ) {
143
+		foreach ($classes as $class) {
144 144
 			$tax_classes[] = array(
145
-				'slug' => sanitize_title( $class ),
145
+				'slug' => sanitize_title($class),
146 146
 				'name' => $class,
147 147
 			);
148 148
 		}
149 149
 
150 150
 		$data = array();
151
-		foreach ( $tax_classes as $tax_class ) {
152
-			$class  = $this->prepare_item_for_response( $tax_class, $request );
153
-			$class  = $this->prepare_response_for_collection( $class );
151
+		foreach ($tax_classes as $tax_class) {
152
+			$class  = $this->prepare_item_for_response($tax_class, $request);
153
+			$class  = $this->prepare_response_for_collection($class);
154 154
 			$data[] = $class;
155 155
 		}
156 156
 
157
-		return rest_ensure_response( $data );
157
+		return rest_ensure_response($data);
158 158
 	}
159 159
 
160 160
 	/**
@@ -163,33 +163,33 @@  discard block
 block discarded – undo
163 163
 	 * @param WP_REST_Request $request Full details about the request.
164 164
 	 * @return WP_Error|WP_REST_Response
165 165
 	 */
166
-	public function create_item( $request ) {
166
+	public function create_item($request) {
167 167
 		$exists    = false;
168 168
 		$classes   = WC_Tax::get_tax_classes();
169 169
 		$tax_class = array(
170
-			'slug' => sanitize_title( $request['name'] ),
170
+			'slug' => sanitize_title($request['name']),
171 171
 			'name' => $request['name'],
172 172
 		);
173 173
 
174 174
 		// Check if class exists.
175
-		foreach ( $classes as $key => $class ) {
176
-			if ( sanitize_title( $class ) === $tax_class['slug'] ) {
175
+		foreach ($classes as $key => $class) {
176
+			if (sanitize_title($class) === $tax_class['slug']) {
177 177
 				$exists = true;
178 178
 				break;
179 179
 			}
180 180
 		}
181 181
 
182 182
 		// Return error if tax class already exists.
183
-		if ( $exists ) {
184
-			return new WP_Error( 'woocommerce_rest_tax_class_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) );
183
+		if ($exists) {
184
+			return new WP_Error('woocommerce_rest_tax_class_exists', __('Cannot create existing resource.', 'woocommerce'), array('status' => 400));
185 185
 		}
186 186
 
187 187
 		// Add the new class.
188 188
 		$classes[] = $tax_class['name'];
189 189
 
190
-		update_option( 'woocommerce_tax_classes', implode( "\n", $classes ) );
190
+		update_option('woocommerce_tax_classes', implode("\n", $classes));
191 191
 
192
-		$this->update_additional_fields_for_object( $tax_class, $request );
192
+		$this->update_additional_fields_for_object($tax_class, $request);
193 193
 
194 194
 		/**
195 195
 		 * Fires after a tax class is created or updated via the REST API.
@@ -198,13 +198,13 @@  discard block
 block discarded – undo
198 198
 		 * @param WP_REST_Request $request   Request object.
199 199
 		 * @param boolean         $creating  True when creating tax class, false when updating tax class.
200 200
 		 */
201
-		do_action( 'woocommerce_rest_insert_tax_class', (object) $tax_class, $request, true );
201
+		do_action('woocommerce_rest_insert_tax_class', (object) $tax_class, $request, true);
202 202
 
203
-		$request->set_param( 'context', 'edit' );
204
-		$response = $this->prepare_item_for_response( $tax_class, $request );
205
-		$response = rest_ensure_response( $response );
206
-		$response->set_status( 201 );
207
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug'] ) ) );
203
+		$request->set_param('context', 'edit');
204
+		$response = $this->prepare_item_for_response($tax_class, $request);
205
+		$response = rest_ensure_response($response);
206
+		$response->set_status(201);
207
+		$response->header('Location', rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug'])));
208 208
 
209 209
 		return $response;
210 210
 	}
@@ -215,53 +215,53 @@  discard block
 block discarded – undo
215 215
 	 * @param WP_REST_Request $request Full details about the request.
216 216
 	 * @return WP_Error|WP_REST_Response
217 217
 	 */
218
-	public function delete_item( $request ) {
218
+	public function delete_item($request) {
219 219
 		global $wpdb;
220 220
 
221
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
221
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
222 222
 
223 223
 		// We don't support trashing for this type, error out.
224
-		if ( ! $force ) {
225
-			return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Taxes do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
224
+		if ( ! $force) {
225
+			return new WP_Error('woocommerce_rest_trash_not_supported', __('Taxes do not support trashing.', 'woocommerce'), array('status' => 501));
226 226
 		}
227 227
 
228 228
 		$tax_class = array(
229
-			'slug' => sanitize_title( $request['slug'] ),
229
+			'slug' => sanitize_title($request['slug']),
230 230
 			'name' => '',
231 231
 		);
232 232
 		$classes = WC_Tax::get_tax_classes();
233 233
 		$deleted = false;
234 234
 
235
-		foreach ( $classes as $key => $class ) {
236
-			if ( sanitize_title( $class ) === $tax_class['slug'] ) {
235
+		foreach ($classes as $key => $class) {
236
+			if (sanitize_title($class) === $tax_class['slug']) {
237 237
 				$tax_class['name'] = $class;
238
-				unset( $classes[ $key ] );
238
+				unset($classes[$key]);
239 239
 				$deleted = true;
240 240
 				break;
241 241
 			}
242 242
 		}
243 243
 
244
-		if ( ! $deleted ) {
245
-			return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 400 ) );
244
+		if ( ! $deleted) {
245
+			return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource id.', 'woocommerce'), array('status' => 400));
246 246
 		}
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
-		$wpdb->query( $wpdb->prepare( "
251
+		$wpdb->query($wpdb->prepare("
252 252
 			DELETE locations.*
253 253
 			FROM {$wpdb->prefix}woocommerce_tax_rate_locations AS locations
254 254
 			INNER JOIN
255 255
 				{$wpdb->prefix}woocommerce_tax_rates AS rates
256 256
 				ON rates.tax_rate_id = locations.tax_rate_id
257 257
 			WHERE rates.tax_rate_class = '%s'
258
-		", $tax_class['slug'] ) );
258
+		", $tax_class['slug']));
259 259
 
260 260
 		// Delete tax rates in the selected class.
261
-		$wpdb->delete( $wpdb->prefix . 'woocommerce_tax_rates', array( 'tax_rate_class' => $tax_class['slug'] ), array( '%s' ) );
261
+		$wpdb->delete($wpdb->prefix . 'woocommerce_tax_rates', array('tax_rate_class' => $tax_class['slug']), array('%s'));
262 262
 
263
-		$request->set_param( 'context', 'edit' );
264
-		$response = $this->prepare_item_for_response( $tax_class, $request );
263
+		$request->set_param('context', 'edit');
264
+		$response = $this->prepare_item_for_response($tax_class, $request);
265 265
 
266 266
 		/**
267 267
 		 * Fires after a tax class is deleted via the REST API.
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 		 * @param WP_REST_Response $response  The response returned from the API.
271 271
 		 * @param WP_REST_Request  $request   The request sent to the API.
272 272
 		 */
273
-		do_action( 'woocommerce_rest_delete_tax', (object) $tax_class, $response, $request );
273
+		do_action('woocommerce_rest_delete_tax', (object) $tax_class, $response, $request);
274 274
 
275 275
 		return $response;
276 276
 	}
@@ -282,17 +282,17 @@  discard block
 block discarded – undo
282 282
 	 * @param WP_REST_Request $request Request object.
283 283
 	 * @return WP_REST_Response $response Response data.
284 284
 	 */
285
-	public function prepare_item_for_response( $tax_class, $request ) {
285
+	public function prepare_item_for_response($tax_class, $request) {
286 286
 		$data = $tax_class;
287 287
 
288
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
289
-		$data    = $this->add_additional_fields_to_object( $data, $request );
290
-		$data    = $this->filter_response_by_context( $data, $context );
288
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
289
+		$data    = $this->add_additional_fields_to_object($data, $request);
290
+		$data    = $this->filter_response_by_context($data, $context);
291 291
 
292 292
 		// Wrap the data in a response object.
293
-		$response = rest_ensure_response( $data );
293
+		$response = rest_ensure_response($data);
294 294
 
295
-		$response->add_links( $this->prepare_links() );
295
+		$response->add_links($this->prepare_links());
296 296
 
297 297
 		/**
298 298
 		 * Filter tax object returned from the REST API.
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 		 * @param stdClass         $tax_class Tax object used to create response.
302 302
 		 * @param WP_REST_Request  $request   Request object.
303 303
 		 */
304
-		return apply_filters( 'woocommerce_rest_prepare_tax', $response, (object) $tax_class, $request );
304
+		return apply_filters('woocommerce_rest_prepare_tax', $response, (object) $tax_class, $request);
305 305
 	}
306 306
 
307 307
 	/**
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 	protected function prepare_links() {
313 313
 		$links = array(
314 314
 			'collection' => array(
315
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
315
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
316 316
 			),
317 317
 		);
318 318
 
@@ -331,15 +331,15 @@  discard block
 block discarded – undo
331 331
 			'type'       => 'object',
332 332
 			'properties' => array(
333 333
 				'slug' => array(
334
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
334
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
335 335
 					'type'        => 'string',
336
-					'context'     => array( 'view', 'edit' ),
336
+					'context'     => array('view', 'edit'),
337 337
 					'readonly'    => true,
338 338
 				),
339 339
 				'name' => array(
340
-					'description' => __( 'Tax class name.', 'woocommerce' ),
340
+					'description' => __('Tax class name.', 'woocommerce'),
341 341
 					'type'        => 'string',
342
-					'context'     => array( 'view', 'edit' ),
342
+					'context'     => array('view', 'edit'),
343 343
 					'required'    => true,
344 344
 					'arg_options' => array(
345 345
 						'sanitize_callback' => 'sanitize_text_field',
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 			),
349 349
 		);
350 350
 
351
-		return $this->add_additional_fields_schema( $schema );
351
+		return $this->add_additional_fields_schema($schema);
352 352
 	}
353 353
 
354 354
 	/**
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 	 */
359 359
 	public function get_collection_params() {
360 360
 		return array(
361
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
361
+			'context' => $this->get_context_param(array('default' => 'view')),
362 362
 		);
363 363
 	}
364 364
 }
Please login to merge, or discard this patch.
src/Controllers/Version1/class-wc-rest-webhooks-v1-controller.php 1 patch
Spacing   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since    3.0.0
9 9
  */
10 10
 
11
-if ( ! defined( 'ABSPATH' ) ) {
11
+if ( ! defined('ABSPATH')) {
12 12
 	exit;
13 13
 }
14 14
 
@@ -45,78 +45,78 @@  discard block
 block discarded – undo
45 45
 	 * Register the routes for webhooks.
46 46
 	 */
47 47
 	public function register_routes() {
48
-		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
48
+		register_rest_route($this->namespace, '/' . $this->rest_base, array(
49 49
 			array(
50 50
 				'methods'             => WP_REST_Server::READABLE,
51
-				'callback'            => array( $this, 'get_items' ),
52
-				'permission_callback' => array( $this, 'get_items_permissions_check' ),
51
+				'callback'            => array($this, 'get_items'),
52
+				'permission_callback' => array($this, 'get_items_permissions_check'),
53 53
 				'args'                => $this->get_collection_params(),
54 54
 			),
55 55
 			array(
56 56
 				'methods'             => WP_REST_Server::CREATABLE,
57
-				'callback'            => array( $this, 'create_item' ),
58
-				'permission_callback' => array( $this, 'create_item_permissions_check' ),
59
-				'args'                => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
57
+				'callback'            => array($this, 'create_item'),
58
+				'permission_callback' => array($this, 'create_item_permissions_check'),
59
+				'args'                => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array(
60 60
 					'topic' => array(
61 61
 						'required'    => true,
62 62
 						'type'        => 'string',
63
-						'description' => __( 'Webhook topic.', 'woocommerce' ),
63
+						'description' => __('Webhook topic.', 'woocommerce'),
64 64
 					),
65 65
 					'delivery_url' => array(
66 66
 						'required'    => true,
67 67
 						'type'        => 'string',
68
-						'description' => __( 'Webhook delivery URL.', 'woocommerce' ),
68
+						'description' => __('Webhook delivery URL.', 'woocommerce'),
69 69
 					),
70
-				) ),
70
+				)),
71 71
 			),
72
-			'schema' => array( $this, 'get_public_item_schema' ),
73
-		) );
72
+			'schema' => array($this, 'get_public_item_schema'),
73
+		));
74 74
 
75
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
75
+		register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
76 76
 			'args' => array(
77 77
 				'id' => array(
78
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
78
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
79 79
 					'type'        => 'integer',
80 80
 				),
81 81
 			),
82 82
 			array(
83 83
 				'methods'             => WP_REST_Server::READABLE,
84
-				'callback'            => array( $this, 'get_item' ),
85
-				'permission_callback' => array( $this, 'get_item_permissions_check' ),
84
+				'callback'            => array($this, 'get_item'),
85
+				'permission_callback' => array($this, 'get_item_permissions_check'),
86 86
 				'args'                => array(
87
-					'context' => $this->get_context_param( array( 'default' => 'view' ) ),
87
+					'context' => $this->get_context_param(array('default' => 'view')),
88 88
 				),
89 89
 			),
90 90
 			array(
91 91
 				'methods'             => WP_REST_Server::EDITABLE,
92
-				'callback'            => array( $this, 'update_item' ),
93
-				'permission_callback' => array( $this, 'update_item_permissions_check' ),
94
-				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
92
+				'callback'            => array($this, 'update_item'),
93
+				'permission_callback' => array($this, 'update_item_permissions_check'),
94
+				'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
95 95
 			),
96 96
 			array(
97 97
 				'methods'             => WP_REST_Server::DELETABLE,
98
-				'callback'            => array( $this, 'delete_item' ),
99
-				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
98
+				'callback'            => array($this, 'delete_item'),
99
+				'permission_callback' => array($this, 'delete_item_permissions_check'),
100 100
 				'args'                => array(
101 101
 					'force' => array(
102 102
 						'default'     => false,
103 103
 						'type'        => 'boolean',
104
-						'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
104
+						'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
105 105
 					),
106 106
 				),
107 107
 			),
108
-			'schema' => array( $this, 'get_public_item_schema' ),
109
-		) );
108
+			'schema' => array($this, 'get_public_item_schema'),
109
+		));
110 110
 
111
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
111
+		register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array(
112 112
 			array(
113 113
 				'methods'             => WP_REST_Server::EDITABLE,
114
-				'callback'            => array( $this, 'batch_items' ),
115
-				'permission_callback' => array( $this, 'batch_items_permissions_check' ),
116
-				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
114
+				'callback'            => array($this, 'batch_items'),
115
+				'permission_callback' => array($this, 'batch_items_permissions_check'),
116
+				'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
117 117
 			),
118
-			'schema' => array( $this, 'get_public_batch_schema' ),
119
-		) );
118
+			'schema' => array($this, 'get_public_batch_schema'),
119
+		));
120 120
 	}
121 121
 
122 122
 	/**
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 	 * @param  WP_REST_Request $request Full details about the request.
126 126
 	 * @return WP_Error|boolean
127 127
 	 */
128
-	public function get_items_permissions_check( $request ) {
129
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) {
130
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
128
+	public function get_items_permissions_check($request) {
129
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) {
130
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
131 131
 		}
132 132
 
133 133
 		return true;
@@ -140,9 +140,9 @@  discard block
 block discarded – undo
140 140
 	 *
141 141
 	 * @return bool|WP_Error
142 142
 	 */
143
-	public function create_item_permissions_check( $request ) {
144
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'create' ) ) {
145
-			return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
143
+	public function create_item_permissions_check($request) {
144
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'create')) {
145
+			return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
146 146
 		}
147 147
 
148 148
 		return true;
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
 	 * @param  WP_REST_Request $request Full details about the request.
155 155
 	 * @return WP_Error|boolean
156 156
 	 */
157
-	public function get_item_permissions_check( $request ) {
158
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) {
159
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
157
+	public function get_item_permissions_check($request) {
158
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) {
159
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
160 160
 		}
161 161
 
162 162
 		return true;
@@ -169,9 +169,9 @@  discard block
 block discarded – undo
169 169
 	 *
170 170
 	 * @return bool|WP_Error
171 171
 	 */
172
-	public function update_item_permissions_check( $request ) {
173
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'edit' ) ) {
174
-			return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
172
+	public function update_item_permissions_check($request) {
173
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'edit')) {
174
+			return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
175 175
 		}
176 176
 
177 177
 		return true;
@@ -184,9 +184,9 @@  discard block
 block discarded – undo
184 184
 	 *
185 185
 	 * @return bool|WP_Error
186 186
 	 */
187
-	public function delete_item_permissions_check( $request ) {
188
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'delete' ) ) {
189
-			return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
187
+	public function delete_item_permissions_check($request) {
188
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'delete')) {
189
+			return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
190 190
 		}
191 191
 
192 192
 		return true;
@@ -199,9 +199,9 @@  discard block
 block discarded – undo
199 199
 	 *
200 200
 	 * @return bool|WP_Error
201 201
 	 */
202
-	public function batch_items_permissions_check( $request ) {
203
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'batch' ) ) {
204
-			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() ) );
202
+	public function batch_items_permissions_check($request) {
203
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'batch')) {
204
+			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()));
205 205
 		}
206 206
 
207 207
 		return true;
@@ -223,20 +223,20 @@  discard block
 block discarded – undo
223 223
 	 * @param WP_REST_Request $request Full details about the request.
224 224
 	 * @return WP_Error|WP_REST_Response
225 225
 	 */
226
-	public function get_items( $request ) {
226
+	public function get_items($request) {
227 227
 		$args            = array();
228 228
 		$args['order']   = $request['order'];
229 229
 		$args['orderby'] = $request['orderby'];
230 230
 		$args['status']  = 'all' === $request['status'] ? '' : $request['status'];
231
-		$args['include'] = implode( ',', $request['include'] );
232
-		$args['exclude'] = implode( ',', $request['exclude'] );
231
+		$args['include'] = implode(',', $request['include']);
232
+		$args['exclude'] = implode(',', $request['exclude']);
233 233
 		$args['limit']   = $request['per_page'];
234 234
 		$args['search']  = $request['search'];
235 235
 		$args['before']  = $request['before'];
236 236
 		$args['after']   = $request['after'];
237 237
 
238
-		if ( empty( $request['offset'] ) ) {
239
-			$args['offset'] = 1 < $request['page'] ? ( $request['page'] - 1 ) * $args['limit'] : 0;
238
+		if (empty($request['offset'])) {
239
+			$args['offset'] = 1 < $request['page'] ? ($request['page'] - 1) * $args['limit'] : 0;
240 240
 		}
241 241
 
242 242
 		/**
@@ -245,43 +245,43 @@  discard block
 block discarded – undo
245 245
 		 * @param array           $args    Array of arguments for $wpdb->get_results().
246 246
 		 * @param WP_REST_Request $request The current request.
247 247
 		 */
248
-		$prepared_args = apply_filters( 'woocommerce_rest_webhook_query', $args, $request );
249
-		unset( $prepared_args['page'] );
248
+		$prepared_args = apply_filters('woocommerce_rest_webhook_query', $args, $request);
249
+		unset($prepared_args['page']);
250 250
 		$prepared_args['paginate'] = true;
251 251
 
252 252
 		// Get the webhooks.
253 253
 		$webhooks       = array();
254
-		$data_store     = WC_Data_Store::load( 'webhook' );
255
-		$results        = $data_store->search_webhooks( $prepared_args );
254
+		$data_store     = WC_Data_Store::load('webhook');
255
+		$results        = $data_store->search_webhooks($prepared_args);
256 256
 		$webhook_ids    = $results->webhooks;
257 257
 
258
-		foreach ( $webhook_ids as $webhook_id ) {
259
-			$data = $this->prepare_item_for_response( $webhook_id, $request );
260
-			$webhooks[] = $this->prepare_response_for_collection( $data );
258
+		foreach ($webhook_ids as $webhook_id) {
259
+			$data = $this->prepare_item_for_response($webhook_id, $request);
260
+			$webhooks[] = $this->prepare_response_for_collection($data);
261 261
 		}
262 262
 
263
-		$response       = rest_ensure_response( $webhooks );
263
+		$response       = rest_ensure_response($webhooks);
264 264
 		$per_page       = (int) $prepared_args['limit'];
265
-		$page           = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
265
+		$page           = ceil((((int) $prepared_args['offset']) / $per_page) + 1);
266 266
 		$total_webhooks = $results->total;
267 267
 		$max_pages      = $results->max_num_pages;
268
-		$base           = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
268
+		$base           = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
269 269
 
270
-		$response->header( 'X-WP-Total', $total_webhooks );
271
-		$response->header( 'X-WP-TotalPages', $max_pages );
270
+		$response->header('X-WP-Total', $total_webhooks);
271
+		$response->header('X-WP-TotalPages', $max_pages);
272 272
 
273
-		if ( $page > 1 ) {
273
+		if ($page > 1) {
274 274
 			$prev_page = $page - 1;
275
-			if ( $prev_page > $max_pages ) {
275
+			if ($prev_page > $max_pages) {
276 276
 				$prev_page = $max_pages;
277 277
 			}
278
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
279
-			$response->link_header( 'prev', $prev_link );
278
+			$prev_link = add_query_arg('page', $prev_page, $base);
279
+			$response->link_header('prev', $prev_link);
280 280
 		}
281
-		if ( $max_pages > $page ) {
281
+		if ($max_pages > $page) {
282 282
 			$next_page = $page + 1;
283
-			$next_link = add_query_arg( 'page', $next_page, $base );
284
-			$response->link_header( 'next', $next_link );
283
+			$next_link = add_query_arg('page', $next_page, $base);
284
+			$response->link_header('next', $next_link);
285 285
 		}
286 286
 
287 287
 		return $response;
@@ -293,15 +293,15 @@  discard block
 block discarded – undo
293 293
 	 * @param WP_REST_Request $request Full details about the request.
294 294
 	 * @return WP_Error|WP_REST_Response
295 295
 	 */
296
-	public function get_item( $request ) {
296
+	public function get_item($request) {
297 297
 		$id = (int) $request['id'];
298 298
 
299
-		if ( empty( $id ) ) {
300
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
299
+		if (empty($id)) {
300
+			return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
301 301
 		}
302 302
 
303
-		$data     = $this->prepare_item_for_response( $id, $request );
304
-		$response = rest_ensure_response( $data );
303
+		$data     = $this->prepare_item_for_response($id, $request);
304
+		$response = rest_ensure_response($data);
305 305
 
306 306
 		return $response;
307 307
 	}
@@ -312,38 +312,38 @@  discard block
 block discarded – undo
312 312
 	 * @param WP_REST_Request $request Full details about the request.
313 313
 	 * @return WP_Error|WP_REST_Response
314 314
 	 */
315
-	public function create_item( $request ) {
316
-		if ( ! empty( $request['id'] ) ) {
315
+	public function create_item($request) {
316
+		if ( ! empty($request['id'])) {
317 317
 			/* translators: %s: post type */
318
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) );
318
+			return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400));
319 319
 		}
320 320
 
321 321
 		// Validate topic.
322
-		if ( empty( $request['topic'] ) || ! wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) {
323
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic is required and must be valid.', 'woocommerce' ), array( 'status' => 400 ) );
322
+		if (empty($request['topic']) || ! wc_is_webhook_valid_topic(strtolower($request['topic']))) {
323
+			return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_topic", __('Webhook topic is required and must be valid.', 'woocommerce'), array('status' => 400));
324 324
 		}
325 325
 
326 326
 		// Validate delivery URL.
327
-		if ( empty( $request['delivery_url'] ) || ! wc_is_valid_url( $request['delivery_url'] ) ) {
328
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_delivery_url", __( 'Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce' ), array( 'status' => 400 ) );
327
+		if (empty($request['delivery_url']) || ! wc_is_valid_url($request['delivery_url'])) {
328
+			return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_delivery_url", __('Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce'), array('status' => 400));
329 329
 		}
330 330
 
331
-		$post = $this->prepare_item_for_database( $request );
332
-		if ( is_wp_error( $post ) ) {
331
+		$post = $this->prepare_item_for_database($request);
332
+		if (is_wp_error($post)) {
333 333
 			return $post;
334 334
 		}
335 335
 
336 336
 		$webhook = new WC_Webhook();
337
-		$webhook->set_name( $post->post_title );
338
-		$webhook->set_user_id( $post->post_author );
339
-		$webhook->set_status( 'publish' === $post->post_status ? 'active' : 'disabled' );
340
-		$webhook->set_topic( $request['topic'] );
341
-		$webhook->set_delivery_url( $request['delivery_url'] );
342
-		$webhook->set_secret( ! empty( $request['secret'] ) ? $request['secret'] : wp_generate_password( 50, true, true ) );
343
-		$webhook->set_api_version( $this->get_default_api_version() );
337
+		$webhook->set_name($post->post_title);
338
+		$webhook->set_user_id($post->post_author);
339
+		$webhook->set_status('publish' === $post->post_status ? 'active' : 'disabled');
340
+		$webhook->set_topic($request['topic']);
341
+		$webhook->set_delivery_url($request['delivery_url']);
342
+		$webhook->set_secret( ! empty($request['secret']) ? $request['secret'] : wp_generate_password(50, true, true));
343
+		$webhook->set_api_version($this->get_default_api_version());
344 344
 		$webhook->save();
345 345
 
346
-		$this->update_additional_fields_for_object( $webhook, $request );
346
+		$this->update_additional_fields_for_object($webhook, $request);
347 347
 
348 348
 		/**
349 349
 		 * Fires after a single item is created or updated via the REST API.
@@ -352,13 +352,13 @@  discard block
 block discarded – undo
352 352
 		 * @param WP_REST_Request $request  Request object.
353 353
 		 * @param bool            $creating True when creating item, false when updating.
354 354
 		 */
355
-		do_action( "woocommerce_rest_insert_webhook_object", $webhook, $request, true );
355
+		do_action("woocommerce_rest_insert_webhook_object", $webhook, $request, true);
356 356
 
357
-		$request->set_param( 'context', 'edit' );
358
-		$response = $this->prepare_item_for_response( $webhook->get_id(), $request );
359
-		$response = rest_ensure_response( $response );
360
-		$response->set_status( 201 );
361
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $webhook->get_id() ) ) );
357
+		$request->set_param('context', 'edit');
358
+		$response = $this->prepare_item_for_response($webhook->get_id(), $request);
359
+		$response = rest_ensure_response($response);
360
+		$response->set_status(201);
361
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $webhook->get_id())));
362 362
 
363 363
 		// Send ping.
364 364
 		$webhook->deliver_ping();
@@ -372,58 +372,58 @@  discard block
 block discarded – undo
372 372
 	 * @param WP_REST_Request $request Full details about the request.
373 373
 	 * @return WP_Error|WP_REST_Response
374 374
 	 */
375
-	public function update_item( $request ) {
375
+	public function update_item($request) {
376 376
 		$id      = (int) $request['id'];
377
-		$webhook = wc_get_webhook( $id );
377
+		$webhook = wc_get_webhook($id);
378 378
 
379
-		if ( empty( $webhook ) || is_null( $webhook ) ) {
380
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) );
379
+		if (empty($webhook) || is_null($webhook)) {
380
+			return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400));
381 381
 		}
382 382
 
383 383
 		// Update topic.
384
-		if ( ! empty( $request['topic'] ) ) {
385
-			if ( wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) {
386
-				$webhook->set_topic( $request['topic'] );
384
+		if ( ! empty($request['topic'])) {
385
+			if (wc_is_webhook_valid_topic(strtolower($request['topic']))) {
386
+				$webhook->set_topic($request['topic']);
387 387
 			} else {
388
-				return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic must be valid.', 'woocommerce' ), array( 'status' => 400 ) );
388
+				return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_topic", __('Webhook topic must be valid.', 'woocommerce'), array('status' => 400));
389 389
 			}
390 390
 		}
391 391
 
392 392
 		// Update delivery URL.
393
-		if ( ! empty( $request['delivery_url'] ) ) {
394
-			if ( wc_is_valid_url( $request['delivery_url'] ) ) {
395
-				$webhook->set_delivery_url( $request['delivery_url'] );
393
+		if ( ! empty($request['delivery_url'])) {
394
+			if (wc_is_valid_url($request['delivery_url'])) {
395
+				$webhook->set_delivery_url($request['delivery_url']);
396 396
 			} else {
397
-				return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_delivery_url", __( 'Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce' ), array( 'status' => 400 ) );
397
+				return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_delivery_url", __('Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce'), array('status' => 400));
398 398
 			}
399 399
 		}
400 400
 
401 401
 		// Update secret.
402
-		if ( ! empty( $request['secret'] ) ) {
403
-			$webhook->set_secret( $request['secret'] );
402
+		if ( ! empty($request['secret'])) {
403
+			$webhook->set_secret($request['secret']);
404 404
 		}
405 405
 
406 406
 		// Update status.
407
-		if ( ! empty( $request['status'] ) ) {
408
-			if ( wc_is_webhook_valid_status( strtolower( $request['status'] ) ) ) {
409
-				$webhook->set_status( $request['status'] );
407
+		if ( ! empty($request['status'])) {
408
+			if (wc_is_webhook_valid_status(strtolower($request['status']))) {
409
+				$webhook->set_status($request['status']);
410 410
 			} else {
411
-				return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_status", __( 'Webhook status must be valid.', 'woocommerce' ), array( 'status' => 400 ) );
411
+				return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_status", __('Webhook status must be valid.', 'woocommerce'), array('status' => 400));
412 412
 			}
413 413
 		}
414 414
 
415
-		$post = $this->prepare_item_for_database( $request );
416
-		if ( is_wp_error( $post ) ) {
415
+		$post = $this->prepare_item_for_database($request);
416
+		if (is_wp_error($post)) {
417 417
 			return $post;
418 418
 		}
419 419
 
420
-		if ( isset( $post->post_title ) ) {
421
-			$webhook->set_name( $post->post_title );
420
+		if (isset($post->post_title)) {
421
+			$webhook->set_name($post->post_title);
422 422
 		}
423 423
 
424 424
 		$webhook->save();
425 425
 
426
-		$this->update_additional_fields_for_object( $webhook, $request );
426
+		$this->update_additional_fields_for_object($webhook, $request);
427 427
 
428 428
 		/**
429 429
 		 * Fires after a single item is created or updated via the REST API.
@@ -432,12 +432,12 @@  discard block
 block discarded – undo
432 432
 		 * @param WP_REST_Request $request  Request object.
433 433
 		 * @param bool            $creating True when creating item, false when updating.
434 434
 		 */
435
-		do_action( "woocommerce_rest_insert_webhook_object", $webhook, $request, false );
435
+		do_action("woocommerce_rest_insert_webhook_object", $webhook, $request, false);
436 436
 
437
-		$request->set_param( 'context', 'edit' );
438
-		$response = $this->prepare_item_for_response( $webhook->get_id(), $request );
437
+		$request->set_param('context', 'edit');
438
+		$response = $this->prepare_item_for_response($webhook->get_id(), $request);
439 439
 
440
-		return rest_ensure_response( $response );
440
+		return rest_ensure_response($response);
441 441
 	}
442 442
 
443 443
 	/**
@@ -446,28 +446,28 @@  discard block
 block discarded – undo
446 446
 	 * @param WP_REST_Request $request Full details about the request.
447 447
 	 * @return WP_REST_Response|WP_Error
448 448
 	 */
449
-	public function delete_item( $request ) {
449
+	public function delete_item($request) {
450 450
 		$id    = (int) $request['id'];
451
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
451
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
452 452
 
453 453
 		// We don't support trashing for this type, error out.
454
-		if ( ! $force ) {
455
-			return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
454
+		if ( ! $force) {
455
+			return new WP_Error('woocommerce_rest_trash_not_supported', __('Webhooks do not support trashing.', 'woocommerce'), array('status' => 501));
456 456
 		}
457 457
 
458
-		$webhook = wc_get_webhook( $id );
458
+		$webhook = wc_get_webhook($id);
459 459
 
460
-		if ( empty( $webhook ) || is_null( $webhook ) ) {
461
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
460
+		if (empty($webhook) || is_null($webhook)) {
461
+			return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
462 462
 		}
463 463
 
464
-		$request->set_param( 'context', 'edit' );
465
-		$response = $this->prepare_item_for_response( $webhook, $request );
466
-		$result   = $webhook->delete( true );
464
+		$request->set_param('context', 'edit');
465
+		$response = $this->prepare_item_for_response($webhook, $request);
466
+		$result   = $webhook->delete(true);
467 467
 
468
-		if ( ! $result ) {
468
+		if ( ! $result) {
469 469
 			/* translators: %s: post type */
470
-			return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) );
470
+			return new WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array('status' => 500));
471 471
 		}
472 472
 
473 473
 		/**
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 		 * @param WP_REST_Response $response The response data.
478 478
 		 * @param WP_REST_Request  $request  The request sent to the API.
479 479
 		 */
480
-		do_action( "woocommerce_rest_delete_webhook_object", $webhook, $response, $request );
480
+		do_action("woocommerce_rest_delete_webhook_object", $webhook, $response, $request);
481 481
 
482 482
 		return $response;
483 483
 	}
@@ -488,17 +488,17 @@  discard block
 block discarded – undo
488 488
 	 * @param WP_REST_Request $request Request object.
489 489
 	 * @return WP_Error|stdClass $data Post object.
490 490
 	 */
491
-	protected function prepare_item_for_database( $request ) {
491
+	protected function prepare_item_for_database($request) {
492 492
 		$data = new stdClass;
493 493
 
494 494
 		// Post ID.
495
-		if ( isset( $request['id'] ) ) {
496
-			$data->ID = absint( $request['id'] );
495
+		if (isset($request['id'])) {
496
+			$data->ID = absint($request['id']);
497 497
 		}
498 498
 
499 499
 		// Validate required POST fields.
500
-		if ( 'POST' === $request->get_method() && empty( $data->ID ) ) {
501
-			$data->post_title = ! empty( $request['name'] ) ? $request['name'] : sprintf( __( 'Webhook created on %s', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce' ) ) ); // @codingStandardsIgnoreLine
500
+		if ('POST' === $request->get_method() && empty($data->ID)) {
501
+			$data->post_title = ! empty($request['name']) ? $request['name'] : sprintf(__('Webhook created on %s', 'woocommerce'), strftime(_x('%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce'))); // @codingStandardsIgnoreLine
502 502
 
503 503
 			// Post author.
504 504
 			$data->post_author = get_current_user_id();
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 		} else {
512 512
 
513 513
 			// Allow edit post title.
514
-			if ( ! empty( $request['name'] ) ) {
514
+			if ( ! empty($request['name'])) {
515 515
 				$data->post_title = $request['name'];
516 516
 			}
517 517
 		}
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 		 *                                       for inserting or updating the database.
533 533
 		 * @param WP_REST_Request $request       Request object.
534 534
 		 */
535
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}", $data, $request );
535
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $data, $request);
536 536
 	}
537 537
 
538 538
 	/**
@@ -542,14 +542,14 @@  discard block
 block discarded – undo
542 542
 	 * @param WP_REST_Request   $request  Request object.
543 543
 	 * @return WP_REST_Response $response Response data.
544 544
 	 */
545
-	public function prepare_item_for_response( $id, $request ) {
546
-		$webhook = wc_get_webhook( $id );
545
+	public function prepare_item_for_response($id, $request) {
546
+		$webhook = wc_get_webhook($id);
547 547
 
548
-		if ( empty( $webhook ) || is_null( $webhook ) ) {
549
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) );
548
+		if (empty($webhook) || is_null($webhook)) {
549
+			return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400));
550 550
 		}
551 551
 
552
-		$data    = array(
552
+		$data = array(
553 553
 			'id'            => $webhook->get_id(),
554 554
 			'name'          => $webhook->get_name(),
555 555
 			'status'        => $webhook->get_status(),
@@ -558,18 +558,18 @@  discard block
 block discarded – undo
558 558
 			'event'         => $webhook->get_event(),
559 559
 			'hooks'         => $webhook->get_hooks(),
560 560
 			'delivery_url'  => $webhook->get_delivery_url(),
561
-			'date_created'  => wc_rest_prepare_date_response( $webhook->get_date_created() ),
562
-			'date_modified' => wc_rest_prepare_date_response( $webhook->get_date_modified() ),
561
+			'date_created'  => wc_rest_prepare_date_response($webhook->get_date_created()),
562
+			'date_modified' => wc_rest_prepare_date_response($webhook->get_date_modified()),
563 563
 		);
564 564
 
565
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
566
-		$data    = $this->add_additional_fields_to_object( $data, $request );
567
-		$data    = $this->filter_response_by_context( $data, $context );
565
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
566
+		$data    = $this->add_additional_fields_to_object($data, $request);
567
+		$data    = $this->filter_response_by_context($data, $context);
568 568
 
569 569
 		// Wrap the data in a response object.
570
-		$response = rest_ensure_response( $data );
570
+		$response = rest_ensure_response($data);
571 571
 
572
-		$response->add_links( $this->prepare_links( $webhook->get_id() ) );
572
+		$response->add_links($this->prepare_links($webhook->get_id()));
573 573
 
574 574
 		/**
575 575
 		 * Filter webhook object returned from the REST API.
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
 		 * @param WC_Webhook       $webhook  Webhook object used to create response.
579 579
 		 * @param WP_REST_Request  $request  Request object.
580 580
 		 */
581
-		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $webhook, $request );
581
+		return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $webhook, $request);
582 582
 	}
583 583
 
584 584
 	/**
@@ -587,13 +587,13 @@  discard block
 block discarded – undo
587 587
 	 * @param int $id Webhook ID.
588 588
 	 * @return array
589 589
 	 */
590
-	protected function prepare_links( $id ) {
590
+	protected function prepare_links($id) {
591 591
 		$links = array(
592 592
 			'self' => array(
593
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $id ) ),
593
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $id)),
594 594
 			),
595 595
 			'collection' => array(
596
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
596
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
597 597
 			),
598 598
 		);
599 599
 
@@ -612,77 +612,77 @@  discard block
 block discarded – undo
612 612
 			'type'       => 'object',
613 613
 			'properties' => array(
614 614
 				'id' => array(
615
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
615
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
616 616
 					'type'        => 'integer',
617
-					'context'     => array( 'view', 'edit' ),
617
+					'context'     => array('view', 'edit'),
618 618
 					'readonly'    => true,
619 619
 				),
620 620
 				'name' => array(
621
-					'description' => __( 'A friendly name for the webhook.', 'woocommerce' ),
621
+					'description' => __('A friendly name for the webhook.', 'woocommerce'),
622 622
 					'type'        => 'string',
623
-					'context'     => array( 'view', 'edit' ),
623
+					'context'     => array('view', 'edit'),
624 624
 				),
625 625
 				'status' => array(
626
-					'description' => __( 'Webhook status.', 'woocommerce' ),
626
+					'description' => __('Webhook status.', 'woocommerce'),
627 627
 					'type'        => 'string',
628 628
 					'default'     => 'active',
629
-					'enum'        => array_keys( wc_get_webhook_statuses() ),
630
-					'context'     => array( 'view', 'edit' ),
629
+					'enum'        => array_keys(wc_get_webhook_statuses()),
630
+					'context'     => array('view', 'edit'),
631 631
 				),
632 632
 				'topic' => array(
633
-					'description' => __( 'Webhook topic.', 'woocommerce' ),
633
+					'description' => __('Webhook topic.', 'woocommerce'),
634 634
 					'type'        => 'string',
635
-					'context'     => array( 'view', 'edit' ),
635
+					'context'     => array('view', 'edit'),
636 636
 				),
637 637
 				'resource' => array(
638
-					'description' => __( 'Webhook resource.', 'woocommerce' ),
638
+					'description' => __('Webhook resource.', 'woocommerce'),
639 639
 					'type'        => 'string',
640
-					'context'     => array( 'view', 'edit' ),
640
+					'context'     => array('view', 'edit'),
641 641
 					'readonly'    => true,
642 642
 				),
643 643
 				'event' => array(
644
-					'description' => __( 'Webhook event.', 'woocommerce' ),
644
+					'description' => __('Webhook event.', 'woocommerce'),
645 645
 					'type'        => 'string',
646
-					'context'     => array( 'view', 'edit' ),
646
+					'context'     => array('view', 'edit'),
647 647
 					'readonly'    => true,
648 648
 				),
649 649
 				'hooks' => array(
650
-					'description' => __( 'WooCommerce action names associated with the webhook.', 'woocommerce' ),
650
+					'description' => __('WooCommerce action names associated with the webhook.', 'woocommerce'),
651 651
 					'type'        => 'array',
652
-					'context'     => array( 'view', 'edit' ),
652
+					'context'     => array('view', 'edit'),
653 653
 					'readonly'    => true,
654 654
 					'items'       => array(
655 655
 						'type'    => 'string',
656 656
 					),
657 657
 				),
658 658
 				'delivery_url' => array(
659
-					'description' => __( 'The URL where the webhook payload is delivered.', 'woocommerce' ),
659
+					'description' => __('The URL where the webhook payload is delivered.', 'woocommerce'),
660 660
 					'type'        => 'string',
661 661
 					'format'      => 'uri',
662
-					'context'     => array( 'view', 'edit' ),
662
+					'context'     => array('view', 'edit'),
663 663
 					'readonly'    => true,
664 664
 				),
665 665
 				'secret' => array(
666
-					'description' => __( "Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce' ),
666
+					'description' => __("Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce'),
667 667
 					'type'        => 'string',
668
-					'context'     => array( 'edit' ),
668
+					'context'     => array('edit'),
669 669
 				),
670 670
 				'date_created' => array(
671
-					'description' => __( "The date the webhook was created, in the site's timezone.", 'woocommerce' ),
671
+					'description' => __("The date the webhook was created, in the site's timezone.", 'woocommerce'),
672 672
 					'type'        => 'date-time',
673
-					'context'     => array( 'view', 'edit' ),
673
+					'context'     => array('view', 'edit'),
674 674
 					'readonly'    => true,
675 675
 				),
676 676
 				'date_modified' => array(
677
-					'description' => __( "The date the webhook was last modified, in the site's timezone.", 'woocommerce' ),
677
+					'description' => __("The date the webhook was last modified, in the site's timezone.", 'woocommerce'),
678 678
 					'type'        => 'date-time',
679
-					'context'     => array( 'view', 'edit' ),
679
+					'context'     => array('view', 'edit'),
680 680
 					'readonly'    => true,
681 681
 				),
682 682
 			),
683 683
 		);
684 684
 
685
-		return $this->add_additional_fields_schema( $schema );
685
+		return $this->add_additional_fields_schema($schema);
686 686
 	}
687 687
 
688 688
 	/**
@@ -696,19 +696,19 @@  discard block
 block discarded – undo
696 696
 		$params['context']['default'] = 'view';
697 697
 
698 698
 		$params['after'] = array(
699
-			'description'        => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
699
+			'description'        => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
700 700
 			'type'               => 'string',
701 701
 			'format'             => 'date-time',
702 702
 			'validate_callback'  => 'rest_validate_request_arg',
703 703
 		);
704 704
 		$params['before'] = array(
705
-			'description'        => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
705
+			'description'        => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
706 706
 			'type'               => 'string',
707 707
 			'format'             => 'date-time',
708 708
 			'validate_callback'  => 'rest_validate_request_arg',
709 709
 		);
710 710
 		$params['exclude'] = array(
711
-			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
711
+			'description'       => __('Ensure result set excludes specific IDs.', 'woocommerce'),
712 712
 			'type'              => 'array',
713 713
 			'items'             => array(
714 714
 				'type'          => 'integer',
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
 			'sanitize_callback' => 'wp_parse_id_list',
718 718
 		);
719 719
 		$params['include'] = array(
720
-			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
720
+			'description'       => __('Limit result set to specific ids.', 'woocommerce'),
721 721
 			'type'              => 'array',
722 722
 			'items'             => array(
723 723
 				'type'          => 'integer',
@@ -726,20 +726,20 @@  discard block
 block discarded – undo
726 726
 			'sanitize_callback' => 'wp_parse_id_list',
727 727
 		);
728 728
 		$params['offset'] = array(
729
-			'description'        => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
729
+			'description'        => __('Offset the result set by a specific number of items.', 'woocommerce'),
730 730
 			'type'               => 'integer',
731 731
 			'sanitize_callback'  => 'absint',
732 732
 			'validate_callback'  => 'rest_validate_request_arg',
733 733
 		);
734 734
 		$params['order'] = array(
735
-			'description'        => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
735
+			'description'        => __('Order sort attribute ascending or descending.', 'woocommerce'),
736 736
 			'type'               => 'string',
737 737
 			'default'            => 'desc',
738
-			'enum'               => array( 'asc', 'desc' ),
738
+			'enum'               => array('asc', 'desc'),
739 739
 			'validate_callback'  => 'rest_validate_request_arg',
740 740
 		);
741 741
 		$params['orderby'] = array(
742
-			'description'        => __( 'Sort collection by object attribute.', 'woocommerce' ),
742
+			'description'        => __('Sort collection by object attribute.', 'woocommerce'),
743 743
 			'type'               => 'string',
744 744
 			'default'            => 'date',
745 745
 			'enum'               => array(
@@ -751,9 +751,9 @@  discard block
 block discarded – undo
751 751
 		);
752 752
 		$params['status'] = array(
753 753
 			'default'           => 'all',
754
-			'description'       => __( 'Limit result set to webhooks assigned a specific status.', 'woocommerce' ),
754
+			'description'       => __('Limit result set to webhooks assigned a specific status.', 'woocommerce'),
755 755
 			'type'              => 'string',
756
-			'enum'              => array( 'all', 'active', 'paused', 'disabled' ),
756
+			'enum'              => array('all', 'active', 'paused', 'disabled'),
757 757
 			'sanitize_callback' => 'sanitize_key',
758 758
 			'validate_callback' => 'rest_validate_request_arg',
759 759
 		);
Please login to merge, or discard this patch.
src/Controllers/Version1/class-wc-rest-reports-v1-controller.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @since    3.0.0
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
 	 * Register the routes for reports.
41 41
 	 */
42 42
 	public function register_routes() {
43
-		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
43
+		register_rest_route($this->namespace, '/' . $this->rest_base, array(
44 44
 			array(
45 45
 				'methods'             => WP_REST_Server::READABLE,
46
-				'callback'            => array( $this, 'get_items' ),
47
-				'permission_callback' => array( $this, 'get_items_permissions_check' ),
46
+				'callback'            => array($this, 'get_items'),
47
+				'permission_callback' => array($this, 'get_items_permissions_check'),
48 48
 				'args'                => $this->get_collection_params(),
49 49
 			),
50
-			'schema' => array( $this, 'get_public_item_schema' ),
51
-		) );
50
+			'schema' => array($this, 'get_public_item_schema'),
51
+		));
52 52
 	}
53 53
 
54 54
 	/**
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 * @param  WP_REST_Request $request Full details about the request.
58 58
 	 * @return WP_Error|boolean
59 59
 	 */
60
-	public function get_items_permissions_check( $request ) {
61
-		if ( ! wc_rest_check_manager_permissions( 'reports', 'read' ) ) {
62
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
60
+	public function get_items_permissions_check($request) {
61
+		if ( ! wc_rest_check_manager_permissions('reports', 'read')) {
62
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
63 63
 		}
64 64
 
65 65
 		return true;
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
 		return array(
76 76
 			array(
77 77
 				'slug'        => 'sales',
78
-				'description' => __( 'List of sales reports.', 'woocommerce' ),
78
+				'description' => __('List of sales reports.', 'woocommerce'),
79 79
 			),
80 80
 			array(
81 81
 				'slug'        => 'top_sellers',
82
-				'description' => __( 'List of top sellers products.', 'woocommerce' ),
82
+				'description' => __('List of top sellers products.', 'woocommerce'),
83 83
 			),
84 84
 		);
85 85
 	}
@@ -90,16 +90,16 @@  discard block
 block discarded – undo
90 90
 	 * @param WP_REST_Request $request
91 91
 	 * @return array|WP_Error
92 92
 	 */
93
-	public function get_items( $request ) {
93
+	public function get_items($request) {
94 94
 		$data    = array();
95 95
 		$reports = $this->get_reports();
96 96
 
97
-		foreach ( $reports as $report ) {
98
-			$item   = $this->prepare_item_for_response( (object) $report, $request );
99
-			$data[] = $this->prepare_response_for_collection( $item );
97
+		foreach ($reports as $report) {
98
+			$item   = $this->prepare_item_for_response((object) $report, $request);
99
+			$data[] = $this->prepare_response_for_collection($item);
100 100
 		}
101 101
 
102
-		return rest_ensure_response( $data );
102
+		return rest_ensure_response($data);
103 103
 	}
104 104
 
105 105
 	/**
@@ -109,26 +109,26 @@  discard block
 block discarded – undo
109 109
 	 * @param WP_REST_Request $request Request object.
110 110
 	 * @return WP_REST_Response $response Response data.
111 111
 	 */
112
-	public function prepare_item_for_response( $report, $request ) {
112
+	public function prepare_item_for_response($report, $request) {
113 113
 		$data = array(
114 114
 			'slug'        => $report->slug,
115 115
 			'description' => $report->description,
116 116
 		);
117 117
 
118
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
119
-		$data = $this->add_additional_fields_to_object( $data, $request );
120
-		$data = $this->filter_response_by_context( $data, $context );
118
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
119
+		$data = $this->add_additional_fields_to_object($data, $request);
120
+		$data = $this->filter_response_by_context($data, $context);
121 121
 
122 122
 		// Wrap the data in a response object.
123
-		$response = rest_ensure_response( $data );
124
-		$response->add_links( array(
123
+		$response = rest_ensure_response($data);
124
+		$response->add_links(array(
125 125
 			'self' => array(
126
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $report->slug ) ),
126
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $report->slug)),
127 127
 			),
128 128
 			'collection' => array(
129
-				'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
129
+				'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)),
130 130
 			),
131
-		) );
131
+		));
132 132
 
133 133
 		/**
134 134
 		 * Filter a report returned from the API.
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 		 * @param object           $report   The original report object.
140 140
 		 * @param WP_REST_Request  $request  Request used to generate the response.
141 141
 		 */
142
-		return apply_filters( 'woocommerce_rest_prepare_report', $response, $report, $request );
142
+		return apply_filters('woocommerce_rest_prepare_report', $response, $report, $request);
143 143
 	}
144 144
 
145 145
 	/**
@@ -154,21 +154,21 @@  discard block
 block discarded – undo
154 154
 			'type'       => 'object',
155 155
 			'properties' => array(
156 156
 				'slug' => array(
157
-					'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ),
157
+					'description' => __('An alphanumeric identifier for the resource.', 'woocommerce'),
158 158
 					'type'        => 'string',
159
-					'context'     => array( 'view' ),
159
+					'context'     => array('view'),
160 160
 					'readonly'    => true,
161 161
 				),
162 162
 				'description' => array(
163
-					'description' => __( 'A human-readable description of the resource.', 'woocommerce' ),
163
+					'description' => __('A human-readable description of the resource.', 'woocommerce'),
164 164
 					'type'        => 'string',
165
-					'context'     => array( 'view' ),
165
+					'context'     => array('view'),
166 166
 					'readonly'    => true,
167 167
 				),
168 168
 			),
169 169
 		);
170 170
 
171
-		return $this->add_additional_fields_schema( $schema );
171
+		return $this->add_additional_fields_schema($schema);
172 172
 	}
173 173
 
174 174
 	/**
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 */
179 179
 	public function get_collection_params() {
180 180
 		return array(
181
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
181
+			'context' => $this->get_context_param(array('default' => 'view')),
182 182
 		);
183 183
 	}
184 184
 }
Please login to merge, or discard this patch.
src/Controllers/Version1/class-wc-rest-product-attributes-v1-controller.php 1 patch
Spacing   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @since    3.0.0
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -47,73 +47,73 @@  discard block
 block discarded – undo
47 47
 	 * Register the routes for product attributes.
48 48
 	 */
49 49
 	public function register_routes() {
50
-		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
50
+		register_rest_route($this->namespace, '/' . $this->rest_base, array(
51 51
 			array(
52 52
 				'methods'             => WP_REST_Server::READABLE,
53
-				'callback'            => array( $this, 'get_items' ),
54
-				'permission_callback' => array( $this, 'get_items_permissions_check' ),
53
+				'callback'            => array($this, 'get_items'),
54
+				'permission_callback' => array($this, 'get_items_permissions_check'),
55 55
 				'args'                => $this->get_collection_params(),
56 56
 			),
57 57
 			array(
58 58
 				'methods'             => WP_REST_Server::CREATABLE,
59
-				'callback'            => array( $this, 'create_item' ),
60
-				'permission_callback' => array( $this, 'create_item_permissions_check' ),
61
-				'args'                => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
59
+				'callback'            => array($this, 'create_item'),
60
+				'permission_callback' => array($this, 'create_item_permissions_check'),
61
+				'args'                => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array(
62 62
 					'name' => array(
63
-						'description' => __( 'Name for the resource.', 'woocommerce' ),
63
+						'description' => __('Name for the resource.', 'woocommerce'),
64 64
 						'type'        => 'string',
65 65
 						'required'    => true,
66 66
 					),
67
-				) ),
67
+				)),
68 68
 			),
69
-			'schema' => array( $this, 'get_public_item_schema' ),
69
+			'schema' => array($this, 'get_public_item_schema'),
70 70
 		));
71 71
 
72
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
72
+		register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
73 73
 			'args' => array(
74 74
 				'id' => array(
75
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
75
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
76 76
 					'type'        => 'integer',
77 77
 				),
78 78
 			),
79 79
 			array(
80 80
 				'methods'             => WP_REST_Server::READABLE,
81
-				'callback'            => array( $this, 'get_item' ),
82
-				'permission_callback' => array( $this, 'get_item_permissions_check' ),
81
+				'callback'            => array($this, 'get_item'),
82
+				'permission_callback' => array($this, 'get_item_permissions_check'),
83 83
 				'args'                => array(
84
-					'context'         => $this->get_context_param( array( 'default' => 'view' ) ),
84
+					'context'         => $this->get_context_param(array('default' => 'view')),
85 85
 				),
86 86
 			),
87 87
 			array(
88 88
 				'methods'             => WP_REST_Server::EDITABLE,
89
-				'callback'            => array( $this, 'update_item' ),
90
-				'permission_callback' => array( $this, 'update_item_permissions_check' ),
91
-				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
89
+				'callback'            => array($this, 'update_item'),
90
+				'permission_callback' => array($this, 'update_item_permissions_check'),
91
+				'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
92 92
 			),
93 93
 			array(
94 94
 				'methods'             => WP_REST_Server::DELETABLE,
95
-				'callback'            => array( $this, 'delete_item' ),
96
-				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
95
+				'callback'            => array($this, 'delete_item'),
96
+				'permission_callback' => array($this, 'delete_item_permissions_check'),
97 97
 				'args'                => array(
98 98
 					'force' => array(
99 99
 						'default'     => true,
100 100
 						'type'        => 'boolean',
101
-						'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
101
+						'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
102 102
 					),
103 103
 				),
104 104
 			),
105
-			'schema' => array( $this, 'get_public_item_schema' ),
106
-		) );
105
+			'schema' => array($this, 'get_public_item_schema'),
106
+		));
107 107
 
108
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
108
+		register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array(
109 109
 			array(
110 110
 				'methods'             => WP_REST_Server::EDITABLE,
111
-				'callback'            => array( $this, 'batch_items' ),
112
-				'permission_callback' => array( $this, 'batch_items_permissions_check' ),
113
-				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
111
+				'callback'            => array($this, 'batch_items'),
112
+				'permission_callback' => array($this, 'batch_items_permissions_check'),
113
+				'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
114 114
 			),
115
-			'schema' => array( $this, 'get_public_batch_schema' ),
116
-		) );
115
+			'schema' => array($this, 'get_public_batch_schema'),
116
+		));
117 117
 	}
118 118
 
119 119
 	/**
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
 	 * @param  WP_REST_Request $request Full details about the request.
123 123
 	 * @return WP_Error|boolean
124 124
 	 */
125
-	public function get_items_permissions_check( $request ) {
126
-		if ( ! wc_rest_check_manager_permissions( 'attributes', 'read' ) ) {
127
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
125
+	public function get_items_permissions_check($request) {
126
+		if ( ! wc_rest_check_manager_permissions('attributes', 'read')) {
127
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
128 128
 		}
129 129
 
130 130
 		return true;
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
 	 * @param  WP_REST_Request $request Full details about the request.
137 137
 	 * @return WP_Error|boolean
138 138
 	 */
139
-	public function create_item_permissions_check( $request ) {
140
-		if ( ! wc_rest_check_manager_permissions( 'attributes', 'create' ) ) {
141
-			return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you cannot create new resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
139
+	public function create_item_permissions_check($request) {
140
+		if ( ! wc_rest_check_manager_permissions('attributes', 'create')) {
141
+			return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you cannot create new resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
142 142
 		}
143 143
 
144 144
 		return true;
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
 	 * @param  WP_REST_Request $request Full details about the request.
151 151
 	 * @return WP_Error|boolean
152 152
 	 */
153
-	public function get_item_permissions_check( $request ) {
154
-		if ( ! $this->get_taxonomy( $request ) ) {
155
-			return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
153
+	public function get_item_permissions_check($request) {
154
+		if ( ! $this->get_taxonomy($request)) {
155
+			return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
156 156
 		}
157 157
 
158
-		if ( ! wc_rest_check_manager_permissions( 'attributes', 'read' ) ) {
159
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
158
+		if ( ! wc_rest_check_manager_permissions('attributes', 'read')) {
159
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
160 160
 		}
161 161
 
162 162
 		return true;
@@ -168,13 +168,13 @@  discard block
 block discarded – undo
168 168
 	 * @param  WP_REST_Request $request Full details about the request.
169 169
 	 * @return WP_Error|boolean
170 170
 	 */
171
-	public function update_item_permissions_check( $request ) {
172
-		if ( ! $this->get_taxonomy( $request ) ) {
173
-			return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
171
+	public function update_item_permissions_check($request) {
172
+		if ( ! $this->get_taxonomy($request)) {
173
+			return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
174 174
 		}
175 175
 
176
-		if ( ! wc_rest_check_manager_permissions( 'attributes', 'edit' ) ) {
177
-			return new WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot update resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
176
+		if ( ! wc_rest_check_manager_permissions('attributes', 'edit')) {
177
+			return new WP_Error('woocommerce_rest_cannot_update', __('Sorry, you cannot update resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
178 178
 		}
179 179
 
180 180
 		return true;
@@ -186,13 +186,13 @@  discard block
 block discarded – undo
186 186
 	 * @param  WP_REST_Request $request Full details about the request.
187 187
 	 * @return WP_Error|boolean
188 188
 	 */
189
-	public function delete_item_permissions_check( $request ) {
190
-		if ( ! $this->get_taxonomy( $request ) ) {
191
-			return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
189
+	public function delete_item_permissions_check($request) {
190
+		if ( ! $this->get_taxonomy($request)) {
191
+			return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
192 192
 		}
193 193
 
194
-		if ( ! wc_rest_check_manager_permissions( 'attributes', 'delete' ) ) {
195
-			return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
194
+		if ( ! wc_rest_check_manager_permissions('attributes', 'delete')) {
195
+			return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
196 196
 		}
197 197
 
198 198
 		return true;
@@ -205,9 +205,9 @@  discard block
 block discarded – undo
205 205
 	 *
206 206
 	 * @return bool|WP_Error
207 207
 	 */
208
-	public function batch_items_permissions_check( $request ) {
209
-		if ( ! wc_rest_check_manager_permissions( 'attributes', 'batch' ) ) {
210
-			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() ) );
208
+	public function batch_items_permissions_check($request) {
209
+		if ( ! wc_rest_check_manager_permissions('attributes', 'batch')) {
210
+			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()));
211 211
 		}
212 212
 
213 213
 		return true;
@@ -219,16 +219,16 @@  discard block
 block discarded – undo
219 219
 	 * @param WP_REST_Request $request
220 220
 	 * @return array
221 221
 	 */
222
-	public function get_items( $request ) {
222
+	public function get_items($request) {
223 223
 		$attributes = wc_get_attribute_taxonomies();
224 224
 		$data       = array();
225
-		foreach ( $attributes as $attribute_obj ) {
226
-			$attribute = $this->prepare_item_for_response( $attribute_obj, $request );
227
-			$attribute = $this->prepare_response_for_collection( $attribute );
225
+		foreach ($attributes as $attribute_obj) {
226
+			$attribute = $this->prepare_item_for_response($attribute_obj, $request);
227
+			$attribute = $this->prepare_response_for_collection($attribute);
228 228
 			$data[] = $attribute;
229 229
 		}
230 230
 
231
-		return rest_ensure_response( $data );
231
+		return rest_ensure_response($data);
232 232
 	}
233 233
 
234 234
 	/**
@@ -237,29 +237,29 @@  discard block
 block discarded – undo
237 237
 	 * @param WP_REST_Request $request Full details about the request.
238 238
 	 * @return WP_REST_Request|WP_Error
239 239
 	 */
240
-	public function create_item( $request ) {
240
+	public function create_item($request) {
241 241
 		global $wpdb;
242 242
 
243
-		$id = wc_create_attribute( array(
243
+		$id = wc_create_attribute(array(
244 244
 			'name'         => $request['name'],
245
-			'slug'         => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ),
246
-			'type'         => ! empty( $request['type'] ) ? $request['type'] : 'select',
247
-			'order_by'     => ! empty( $request['order_by'] ) ? $request['order_by'] : 'menu_order',
245
+			'slug'         => wc_sanitize_taxonomy_name(stripslashes($request['slug'])),
246
+			'type'         => ! empty($request['type']) ? $request['type'] : 'select',
247
+			'order_by'     => ! empty($request['order_by']) ? $request['order_by'] : 'menu_order',
248 248
 			'has_archives' => true === $request['has_archives'],
249
-		) );
249
+		));
250 250
 
251 251
 		// Checks for errors.
252
-		if ( is_wp_error( $id ) ) {
253
-			return new WP_Error( 'woocommerce_rest_cannot_create', $id->get_error_message(), array( 'status' => 400 ) );
252
+		if (is_wp_error($id)) {
253
+			return new WP_Error('woocommerce_rest_cannot_create', $id->get_error_message(), array('status' => 400));
254 254
 		}
255 255
 
256
-		$attribute = $this->get_attribute( $id );
256
+		$attribute = $this->get_attribute($id);
257 257
 
258
-		if ( is_wp_error( $attribute ) ) {
258
+		if (is_wp_error($attribute)) {
259 259
 			return $attribute;
260 260
 		}
261 261
 
262
-		$this->update_additional_fields_for_object( $attribute, $request );
262
+		$this->update_additional_fields_for_object($attribute, $request);
263 263
 
264 264
 		/**
265 265
 		 * Fires after a single product attribute is created or updated via the REST API.
@@ -268,13 +268,13 @@  discard block
 block discarded – undo
268 268
 		 * @param WP_REST_Request $request   Request object.
269 269
 		 * @param boolean         $creating  True when creating attribute, false when updating.
270 270
 		 */
271
-		do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, true );
271
+		do_action('woocommerce_rest_insert_product_attribute', $attribute, $request, true);
272 272
 
273
-		$request->set_param( 'context', 'edit' );
274
-		$response = $this->prepare_item_for_response( $attribute, $request );
275
-		$response = rest_ensure_response( $response );
276
-		$response->set_status( 201 );
277
-		$response->header( 'Location', rest_url( '/' . $this->namespace . '/' . $this->rest_base . '/' . $attribute->attribute_id ) );
273
+		$request->set_param('context', 'edit');
274
+		$response = $this->prepare_item_for_response($attribute, $request);
275
+		$response = rest_ensure_response($response);
276
+		$response->set_status(201);
277
+		$response->header('Location', rest_url('/' . $this->namespace . '/' . $this->rest_base . '/' . $attribute->attribute_id));
278 278
 
279 279
 		return $response;
280 280
 	}
@@ -285,16 +285,16 @@  discard block
 block discarded – undo
285 285
 	 * @param WP_REST_Request $request Full details about the request.
286 286
 	 * @return WP_REST_Request|WP_Error
287 287
 	 */
288
-	public function get_item( $request ) {
289
-		$attribute = $this->get_attribute( (int) $request['id'] );
288
+	public function get_item($request) {
289
+		$attribute = $this->get_attribute((int) $request['id']);
290 290
 
291
-		if ( is_wp_error( $attribute ) ) {
291
+		if (is_wp_error($attribute)) {
292 292
 			return $attribute;
293 293
 		}
294 294
 
295
-		$response = $this->prepare_item_for_response( $attribute, $request );
295
+		$response = $this->prepare_item_for_response($attribute, $request);
296 296
 
297
-		return rest_ensure_response( $response );
297
+		return rest_ensure_response($response);
298 298
 	}
299 299
 
300 300
 	/**
@@ -303,30 +303,30 @@  discard block
 block discarded – undo
303 303
 	 * @param WP_REST_Request $request Full details about the request.
304 304
 	 * @return WP_REST_Request|WP_Error
305 305
 	 */
306
-	public function update_item( $request ) {
306
+	public function update_item($request) {
307 307
 		global $wpdb;
308 308
 
309 309
 		$id     = (int) $request['id'];
310
-		$edited = wc_update_attribute( $id, array(
310
+		$edited = wc_update_attribute($id, array(
311 311
 			'name'         => $request['name'],
312
-			'slug'         => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ),
312
+			'slug'         => wc_sanitize_taxonomy_name(stripslashes($request['slug'])),
313 313
 			'type'         => $request['type'],
314 314
 			'order_by'     => $request['order_by'],
315 315
 			'has_archives' => $request['has_archives'],
316
-		) );
316
+		));
317 317
 
318 318
 		// Checks for errors.
319
-		if ( is_wp_error( $edited ) ) {
320
-			return new WP_Error( 'woocommerce_rest_cannot_edit', $edited->get_error_message(), array( 'status' => 400 ) );
319
+		if (is_wp_error($edited)) {
320
+			return new WP_Error('woocommerce_rest_cannot_edit', $edited->get_error_message(), array('status' => 400));
321 321
 		}
322 322
 
323
-		$attribute = $this->get_attribute( $id );
323
+		$attribute = $this->get_attribute($id);
324 324
 
325
-		if ( is_wp_error( $attribute ) ) {
325
+		if (is_wp_error($attribute)) {
326 326
 			return $attribute;
327 327
 		}
328 328
 
329
-		$this->update_additional_fields_for_object( $attribute, $request );
329
+		$this->update_additional_fields_for_object($attribute, $request);
330 330
 
331 331
 		/**
332 332
 		 * Fires after a single product attribute is created or updated via the REST API.
@@ -335,12 +335,12 @@  discard block
 block discarded – undo
335 335
 		 * @param WP_REST_Request $request   Request object.
336 336
 		 * @param boolean         $creating  True when creating attribute, false when updating.
337 337
 		 */
338
-		do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, false );
338
+		do_action('woocommerce_rest_insert_product_attribute', $attribute, $request, false);
339 339
 
340
-		$request->set_param( 'context', 'edit' );
341
-		$response = $this->prepare_item_for_response( $attribute, $request );
340
+		$request->set_param('context', 'edit');
341
+		$response = $this->prepare_item_for_response($attribute, $request);
342 342
 
343
-		return rest_ensure_response( $response );
343
+		return rest_ensure_response($response);
344 344
 	}
345 345
 
346 346
 	/**
@@ -349,27 +349,27 @@  discard block
 block discarded – undo
349 349
 	 * @param WP_REST_Request $request Full details about the request.
350 350
 	 * @return WP_REST_Response|WP_Error
351 351
 	 */
352
-	public function delete_item( $request ) {
353
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
352
+	public function delete_item($request) {
353
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
354 354
 
355 355
 		// We don't support trashing for this type, error out.
356
-		if ( ! $force ) {
357
-			return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Resource does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
356
+		if ( ! $force) {
357
+			return new WP_Error('woocommerce_rest_trash_not_supported', __('Resource does not support trashing.', 'woocommerce'), array('status' => 501));
358 358
 		}
359 359
 
360
-		$attribute = $this->get_attribute( (int) $request['id'] );
360
+		$attribute = $this->get_attribute((int) $request['id']);
361 361
 
362
-		if ( is_wp_error( $attribute ) ) {
362
+		if (is_wp_error($attribute)) {
363 363
 			return $attribute;
364 364
 		}
365 365
 
366
-		$request->set_param( 'context', 'edit' );
367
-		$response = $this->prepare_item_for_response( $attribute, $request );
366
+		$request->set_param('context', 'edit');
367
+		$response = $this->prepare_item_for_response($attribute, $request);
368 368
 
369
-		$deleted = wc_delete_attribute( $attribute->attribute_id );
369
+		$deleted = wc_delete_attribute($attribute->attribute_id);
370 370
 
371
-		if ( false === $deleted ) {
372
-			return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
371
+		if (false === $deleted) {
372
+			return new WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500));
373 373
 		}
374 374
 
375 375
 		/**
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 		 * @param WP_REST_Response $response The response data.
380 380
 		 * @param WP_REST_Request  $request  The request sent to the API.
381 381
 		 */
382
-		do_action( 'woocommerce_rest_delete_product_attribute', $attribute, $response, $request );
382
+		do_action('woocommerce_rest_delete_product_attribute', $attribute, $response, $request);
383 383
 
384 384
 		return $response;
385 385
 	}
@@ -391,23 +391,23 @@  discard block
 block discarded – undo
391 391
 	 * @param WP_REST_Request $request
392 392
 	 * @return WP_REST_Response $response
393 393
 	 */
394
-	public function prepare_item_for_response( $item, $request ) {
394
+	public function prepare_item_for_response($item, $request) {
395 395
 		$data = array(
396 396
 			'id'           => (int) $item->attribute_id,
397 397
 			'name'         => $item->attribute_label,
398
-			'slug'         => wc_attribute_taxonomy_name( $item->attribute_name ),
398
+			'slug'         => wc_attribute_taxonomy_name($item->attribute_name),
399 399
 			'type'         => $item->attribute_type,
400 400
 			'order_by'     => $item->attribute_orderby,
401 401
 			'has_archives' => (bool) $item->attribute_public,
402 402
 		);
403 403
 
404
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
405
-		$data    = $this->add_additional_fields_to_object( $data, $request );
406
-		$data    = $this->filter_response_by_context( $data, $context );
404
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
405
+		$data    = $this->add_additional_fields_to_object($data, $request);
406
+		$data    = $this->filter_response_by_context($data, $context);
407 407
 
408
-		$response = rest_ensure_response( $data );
408
+		$response = rest_ensure_response($data);
409 409
 
410
-		$response->add_links( $this->prepare_links( $item ) );
410
+		$response->add_links($this->prepare_links($item));
411 411
 
412 412
 		/**
413 413
 		 * Filter a attribute item returned from the API.
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 		 * @param object            $item      The original attribute object.
419 419
 		 * @param WP_REST_Request   $request   Request used to generate the response.
420 420
 		 */
421
-		return apply_filters( 'woocommerce_rest_prepare_product_attribute', $response, $item, $request );
421
+		return apply_filters('woocommerce_rest_prepare_product_attribute', $response, $item, $request);
422 422
 	}
423 423
 
424 424
 	/**
@@ -427,14 +427,14 @@  discard block
 block discarded – undo
427 427
 	 * @param object $attribute Attribute object.
428 428
 	 * @return array Links for the given attribute.
429 429
 	 */
430
-	protected function prepare_links( $attribute ) {
430
+	protected function prepare_links($attribute) {
431 431
 		$base  = '/' . $this->namespace . '/' . $this->rest_base;
432 432
 		$links = array(
433 433
 			'self' => array(
434
-				'href' => rest_url( trailingslashit( $base ) . $attribute->attribute_id ),
434
+				'href' => rest_url(trailingslashit($base) . $attribute->attribute_id),
435 435
 			),
436 436
 			'collection' => array(
437
-				'href' => rest_url( $base ),
437
+				'href' => rest_url($base),
438 438
 			),
439 439
 		);
440 440
 
@@ -453,51 +453,51 @@  discard block
 block discarded – undo
453 453
 			'type'                 => 'object',
454 454
 			'properties'           => array(
455 455
 				'id' => array(
456
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
456
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
457 457
 					'type'        => 'integer',
458
-					'context'     => array( 'view', 'edit' ),
458
+					'context'     => array('view', 'edit'),
459 459
 					'readonly'    => true,
460 460
 				),
461 461
 				'name' => array(
462
-					'description' => __( 'Attribute name.', 'woocommerce' ),
462
+					'description' => __('Attribute name.', 'woocommerce'),
463 463
 					'type'        => 'string',
464
-					'context'     => array( 'view', 'edit' ),
464
+					'context'     => array('view', 'edit'),
465 465
 					'arg_options' => array(
466 466
 						'sanitize_callback' => 'sanitize_text_field',
467 467
 					),
468 468
 				),
469 469
 				'slug' => array(
470
-					'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ),
470
+					'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'),
471 471
 					'type'        => 'string',
472
-					'context'     => array( 'view', 'edit' ),
472
+					'context'     => array('view', 'edit'),
473 473
 					'arg_options' => array(
474 474
 						'sanitize_callback' => 'sanitize_title',
475 475
 					),
476 476
 				),
477 477
 				'type' => array(
478
-					'description' => __( 'Type of attribute.', 'woocommerce' ),
478
+					'description' => __('Type of attribute.', 'woocommerce'),
479 479
 					'type'        => 'string',
480 480
 					'default'     => 'select',
481
-					'enum'        => array_keys( wc_get_attribute_types() ),
482
-					'context'     => array( 'view', 'edit' ),
481
+					'enum'        => array_keys(wc_get_attribute_types()),
482
+					'context'     => array('view', 'edit'),
483 483
 				),
484 484
 				'order_by' => array(
485
-					'description' => __( 'Default sort order.', 'woocommerce' ),
485
+					'description' => __('Default sort order.', 'woocommerce'),
486 486
 					'type'        => 'string',
487 487
 					'default'     => 'menu_order',
488
-					'enum'        => array( 'menu_order', 'name', 'name_num', 'id' ),
489
-					'context'     => array( 'view', 'edit' ),
488
+					'enum'        => array('menu_order', 'name', 'name_num', 'id'),
489
+					'context'     => array('view', 'edit'),
490 490
 				),
491 491
 				'has_archives' => array(
492
-					'description' => __( 'Enable/Disable attribute archives.', 'woocommerce' ),
492
+					'description' => __('Enable/Disable attribute archives.', 'woocommerce'),
493 493
 					'type'        => 'boolean',
494 494
 					'default'     => false,
495
-					'context'     => array( 'view', 'edit' ),
495
+					'context'     => array('view', 'edit'),
496 496
 				),
497 497
 			),
498 498
 		);
499 499
 
500
-		return $this->add_additional_fields_schema( $schema );
500
+		return $this->add_additional_fields_schema($schema);
501 501
 	}
502 502
 
503 503
 	/**
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
 	 */
508 508
 	public function get_collection_params() {
509 509
 		$params = array();
510
-		$params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
510
+		$params['context'] = $this->get_context_param(array('default' => 'view'));
511 511
 
512 512
 		return $params;
513 513
 	}
@@ -518,13 +518,13 @@  discard block
 block discarded – undo
518 518
 	 * @param WP_REST_Request $request Full details about the request.
519 519
 	 * @return string
520 520
 	 */
521
-	protected function get_taxonomy( $request ) {
522
-		if ( '' !== $this->attribute ) {
521
+	protected function get_taxonomy($request) {
522
+		if ('' !== $this->attribute) {
523 523
 			return $this->attribute;
524 524
 		}
525 525
 
526
-		if ( $request['id'] ) {
527
-			$name = wc_attribute_taxonomy_name_by_id( (int) $request['id'] );
526
+		if ($request['id']) {
527
+			$name = wc_attribute_taxonomy_name_by_id((int) $request['id']);
528 528
 
529 529
 			$this->attribute = $name;
530 530
 		}
@@ -538,17 +538,17 @@  discard block
 block discarded – undo
538 538
 	 * @param int $id Attribute ID.
539 539
 	 * @return stdClass|WP_Error
540 540
 	 */
541
-	protected function get_attribute( $id ) {
541
+	protected function get_attribute($id) {
542 542
 		global $wpdb;
543 543
 
544
-		$attribute = $wpdb->get_row( $wpdb->prepare( "
544
+		$attribute = $wpdb->get_row($wpdb->prepare("
545 545
 			SELECT *
546 546
 			FROM {$wpdb->prefix}woocommerce_attribute_taxonomies
547 547
 			WHERE attribute_id = %d
548
-		 ", $id ) );
548
+		 ", $id));
549 549
 
550
-		if ( is_wp_error( $attribute ) || is_null( $attribute ) ) {
551
-			return new WP_Error( 'woocommerce_rest_attribute_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
550
+		if (is_wp_error($attribute) || is_null($attribute)) {
551
+			return new WP_Error('woocommerce_rest_attribute_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
552 552
 		}
553 553
 
554 554
 		return $attribute;
@@ -562,13 +562,13 @@  discard block
 block discarded – undo
562 562
 	 * @param bool $new_data
563 563
 	 * @return bool|WP_Error
564 564
 	 */
565
-	protected function validate_attribute_slug( $slug, $new_data = true ) {
566
-		if ( strlen( $slug ) >= 28 ) {
567
-			return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf( __( 'Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) );
568
-		} elseif ( wc_check_if_attribute_name_is_reserved( $slug ) ) {
569
-			return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf( __( 'Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) );
570
-		} elseif ( $new_data && taxonomy_exists( wc_attribute_taxonomy_name( $slug ) ) ) {
571
-			return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf( __( 'Slug "%s" is already in use. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) );
565
+	protected function validate_attribute_slug($slug, $new_data = true) {
566
+		if (strlen($slug) >= 28) {
567
+			return new WP_Error('woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf(__('Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce'), $slug), array('status' => 400));
568
+		} elseif (wc_check_if_attribute_name_is_reserved($slug)) {
569
+			return new WP_Error('woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf(__('Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce'), $slug), array('status' => 400));
570
+		} elseif ($new_data && taxonomy_exists(wc_attribute_taxonomy_name($slug))) {
571
+			return new WP_Error('woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf(__('Slug "%s" is already in use. Change it, please.', 'woocommerce'), $slug), array('status' => 400));
572 572
 		}
573 573
 
574 574
 		return true;
@@ -581,6 +581,6 @@  discard block
 block discarded – undo
581 581
 	 * @since 3.0.0
582 582
 	 */
583 583
 	protected function flush_rewrite_rules() {
584
-		wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' );
584
+		wp_schedule_single_event(time(), 'woocommerce_flush_rewrite_rules');
585 585
 	}
586 586
 }
Please login to merge, or discard this patch.
src/Controllers/Version1/class-wc-rest-order-notes-v1-controller.php 1 patch
Spacing   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @since    3.0.0
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -47,67 +47,67 @@  discard block
 block discarded – undo
47 47
 	 * Register the routes for order notes.
48 48
 	 */
49 49
 	public function register_routes() {
50
-		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
50
+		register_rest_route($this->namespace, '/' . $this->rest_base, array(
51 51
 			'args' => array(
52 52
 				'order_id'  => array(
53
-					'description' => __( 'The order ID.', 'woocommerce' ),
53
+					'description' => __('The order ID.', 'woocommerce'),
54 54
 					'type'        => 'integer',
55 55
 				),
56 56
 			),
57 57
 			array(
58 58
 				'methods'             => WP_REST_Server::READABLE,
59
-				'callback'            => array( $this, 'get_items' ),
60
-				'permission_callback' => array( $this, 'get_items_permissions_check' ),
59
+				'callback'            => array($this, 'get_items'),
60
+				'permission_callback' => array($this, 'get_items_permissions_check'),
61 61
 				'args'                => $this->get_collection_params(),
62 62
 			),
63 63
 			array(
64 64
 				'methods'             => WP_REST_Server::CREATABLE,
65
-				'callback'            => array( $this, 'create_item' ),
66
-				'permission_callback' => array( $this, 'create_item_permissions_check' ),
67
-				'args'                => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
65
+				'callback'            => array($this, 'create_item'),
66
+				'permission_callback' => array($this, 'create_item_permissions_check'),
67
+				'args'                => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array(
68 68
 					'note' => array(
69 69
 						'type'        => 'string',
70
-						'description' => __( 'Order note content.', 'woocommerce' ),
70
+						'description' => __('Order note content.', 'woocommerce'),
71 71
 						'required'    => true,
72 72
 					),
73
-				) ),
73
+				)),
74 74
 			),
75
-			'schema' => array( $this, 'get_public_item_schema' ),
76
-		) );
75
+			'schema' => array($this, 'get_public_item_schema'),
76
+		));
77 77
 
78
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
78
+		register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
79 79
 			'args' => array(
80 80
 				'id' => array(
81
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
81
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
82 82
 					'type'        => 'integer',
83 83
 				),
84 84
 				'order_id'  => array(
85
-					'description' => __( 'The order ID.', 'woocommerce' ),
85
+					'description' => __('The order ID.', 'woocommerce'),
86 86
 					'type'        => 'integer',
87 87
 				),
88 88
 			),
89 89
 			array(
90 90
 				'methods'             => WP_REST_Server::READABLE,
91
-				'callback'            => array( $this, 'get_item' ),
92
-				'permission_callback' => array( $this, 'get_item_permissions_check' ),
91
+				'callback'            => array($this, 'get_item'),
92
+				'permission_callback' => array($this, 'get_item_permissions_check'),
93 93
 				'args'                => array(
94
-					'context' => $this->get_context_param( array( 'default' => 'view' ) ),
94
+					'context' => $this->get_context_param(array('default' => 'view')),
95 95
 				),
96 96
 			),
97 97
 			array(
98 98
 				'methods'             => WP_REST_Server::DELETABLE,
99
-				'callback'            => array( $this, 'delete_item' ),
100
-				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
99
+				'callback'            => array($this, 'delete_item'),
100
+				'permission_callback' => array($this, 'delete_item_permissions_check'),
101 101
 				'args'                => array(
102 102
 					'force' => array(
103 103
 						'default'     => false,
104 104
 						'type'        => 'boolean',
105
-						'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
105
+						'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
106 106
 					),
107 107
 				),
108 108
 			),
109
-			'schema' => array( $this, 'get_public_item_schema' ),
110
-		) );
109
+			'schema' => array($this, 'get_public_item_schema'),
110
+		));
111 111
 	}
112 112
 
113 113
 	/**
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 	 * @param  WP_REST_Request $request Full details about the request.
117 117
 	 * @return WP_Error|boolean
118 118
 	 */
119
-	public function get_items_permissions_check( $request ) {
120
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'read' ) ) {
121
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
119
+	public function get_items_permissions_check($request) {
120
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'read')) {
121
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
122 122
 		}
123 123
 
124 124
 		return true;
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 	 *
132 132
 	 * @return bool|WP_Error
133 133
 	 */
134
-	public function create_item_permissions_check( $request ) {
135
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'create' ) ) {
136
-			return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
134
+	public function create_item_permissions_check($request) {
135
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'create')) {
136
+			return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
137 137
 		}
138 138
 
139 139
 		return true;
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
 	 * @param  WP_REST_Request $request Full details about the request.
146 146
 	 * @return WP_Error|boolean
147 147
 	 */
148
-	public function get_item_permissions_check( $request ) {
149
-		$order = wc_get_order( (int) $request['order_id'] );
148
+	public function get_item_permissions_check($request) {
149
+		$order = wc_get_order((int) $request['order_id']);
150 150
 
151
-		if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'read', $order->get_id() ) ) {
152
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
151
+		if ($order && ! wc_rest_check_post_permissions($this->post_type, 'read', $order->get_id())) {
152
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
153 153
 		}
154 154
 
155 155
 		return true;
@@ -162,11 +162,11 @@  discard block
 block discarded – undo
162 162
 	 *
163 163
 	 * @return bool|WP_Error
164 164
 	 */
165
-	public function delete_item_permissions_check( $request ) {
166
-		$order = wc_get_order( (int) $request['order_id'] );
165
+	public function delete_item_permissions_check($request) {
166
+		$order = wc_get_order((int) $request['order_id']);
167 167
 
168
-		if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $order->get_id() ) ) {
169
-			return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
168
+		if ($order && ! wc_rest_check_post_permissions($this->post_type, 'delete', $order->get_id())) {
169
+			return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
170 170
 		}
171 171
 
172 172
 		return true;
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 	 *
180 180
 	 * @return array|WP_Error
181 181
 	 */
182
-	public function get_items( $request ) {
183
-		$order = wc_get_order( (int) $request['order_id'] );
182
+	public function get_items($request) {
183
+		$order = wc_get_order((int) $request['order_id']);
184 184
 
185
-		if ( ! $order || $this->post_type !== $order->get_type() ) {
186
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) );
185
+		if ( ! $order || $this->post_type !== $order->get_type()) {
186
+			return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid order ID.', 'woocommerce'), array('status' => 404));
187 187
 		}
188 188
 
189 189
 		$args = array(
@@ -192,20 +192,20 @@  discard block
 block discarded – undo
192 192
 			'type'    => 'order_note',
193 193
 		);
194 194
 
195
-		remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
195
+		remove_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1);
196 196
 
197
-		$notes = get_comments( $args );
197
+		$notes = get_comments($args);
198 198
 
199
-		add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
199
+		add_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1);
200 200
 
201 201
 		$data = array();
202
-		foreach ( $notes as $note ) {
203
-			$order_note = $this->prepare_item_for_response( $note, $request );
204
-			$order_note = $this->prepare_response_for_collection( $order_note );
202
+		foreach ($notes as $note) {
203
+			$order_note = $this->prepare_item_for_response($note, $request);
204
+			$order_note = $this->prepare_response_for_collection($order_note);
205 205
 			$data[]     = $order_note;
206 206
 		}
207 207
 
208
-		return rest_ensure_response( $data );
208
+		return rest_ensure_response($data);
209 209
 	}
210 210
 
211 211
 	/**
@@ -214,27 +214,27 @@  discard block
 block discarded – undo
214 214
 	 * @param WP_REST_Request $request Full details about the request.
215 215
 	 * @return WP_Error|WP_REST_Response
216 216
 	 */
217
-	public function create_item( $request ) {
218
-		if ( ! empty( $request['id'] ) ) {
217
+	public function create_item($request) {
218
+		if ( ! empty($request['id'])) {
219 219
 			/* translators: %s: post type */
220
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) );
220
+			return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400));
221 221
 		}
222 222
 
223
-		$order = wc_get_order( (int) $request['order_id'] );
223
+		$order = wc_get_order((int) $request['order_id']);
224 224
 
225
-		if ( ! $order || $this->post_type !== $order->get_type() ) {
226
-			return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) );
225
+		if ( ! $order || $this->post_type !== $order->get_type()) {
226
+			return new WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404));
227 227
 		}
228 228
 
229 229
 		// Create the note.
230
-		$note_id = $order->add_order_note( $request['note'], $request['customer_note'] );
230
+		$note_id = $order->add_order_note($request['note'], $request['customer_note']);
231 231
 
232
-		if ( ! $note_id ) {
233
-			return new WP_Error( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce' ), array( 'status' => 500 ) );
232
+		if ( ! $note_id) {
233
+			return new WP_Error('woocommerce_api_cannot_create_order_note', __('Cannot create order note, please try again.', 'woocommerce'), array('status' => 500));
234 234
 		}
235 235
 
236
-		$note = get_comment( $note_id );
237
-		$this->update_additional_fields_for_object( $note, $request );
236
+		$note = get_comment($note_id);
237
+		$this->update_additional_fields_for_object($note, $request);
238 238
 
239 239
 		/**
240 240
 		 * Fires after a order note is created or updated via the REST API.
@@ -243,13 +243,13 @@  discard block
 block discarded – undo
243 243
 		 * @param WP_REST_Request $request   Request object.
244 244
 		 * @param boolean         $creating  True when creating item, false when updating.
245 245
 		 */
246
-		do_action( 'woocommerce_rest_insert_order_note', $note, $request, true );
246
+		do_action('woocommerce_rest_insert_order_note', $note, $request, true);
247 247
 
248
-		$request->set_param( 'context', 'edit' );
249
-		$response = $this->prepare_item_for_response( $note, $request );
250
-		$response = rest_ensure_response( $response );
251
-		$response->set_status( 201 );
252
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, str_replace( '(?P<order_id>[\d]+)', $order->get_id(), $this->rest_base ), $note_id ) ) );
248
+		$request->set_param('context', 'edit');
249
+		$response = $this->prepare_item_for_response($note, $request);
250
+		$response = rest_ensure_response($response);
251
+		$response->set_status(201);
252
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, str_replace('(?P<order_id>[\d]+)', $order->get_id(), $this->rest_base), $note_id)));
253 253
 
254 254
 		return $response;
255 255
 	}
@@ -260,22 +260,22 @@  discard block
 block discarded – undo
260 260
 	 * @param WP_REST_Request $request Full details about the request.
261 261
 	 * @return WP_Error|WP_REST_Response
262 262
 	 */
263
-	public function get_item( $request ) {
263
+	public function get_item($request) {
264 264
 		$id    = (int) $request['id'];
265
-		$order = wc_get_order( (int) $request['order_id'] );
265
+		$order = wc_get_order((int) $request['order_id']);
266 266
 
267
-		if ( ! $order || $this->post_type !== $order->get_type() ) {
268
-			return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) );
267
+		if ( ! $order || $this->post_type !== $order->get_type()) {
268
+			return new WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404));
269 269
 		}
270 270
 
271
-		$note = get_comment( $id );
271
+		$note = get_comment($id);
272 272
 
273
-		if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) {
274
-			return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
273
+		if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) {
274
+			return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404));
275 275
 		}
276 276
 
277
-		$order_note = $this->prepare_item_for_response( $note, $request );
278
-		$response   = rest_ensure_response( $order_note );
277
+		$order_note = $this->prepare_item_for_response($note, $request);
278
+		$response   = rest_ensure_response($order_note);
279 279
 
280 280
 		return $response;
281 281
 	}
@@ -286,34 +286,34 @@  discard block
 block discarded – undo
286 286
 	 * @param WP_REST_Request $request Full details about the request.
287 287
 	 * @return WP_REST_Response|WP_Error
288 288
 	 */
289
-	public function delete_item( $request ) {
289
+	public function delete_item($request) {
290 290
 		$id    = (int) $request['id'];
291
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
291
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
292 292
 
293 293
 		// We don't support trashing for this type, error out.
294
-		if ( ! $force ) {
295
-			return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
294
+		if ( ! $force) {
295
+			return new WP_Error('woocommerce_rest_trash_not_supported', __('Webhooks do not support trashing.', 'woocommerce'), array('status' => 501));
296 296
 		}
297 297
 
298
-		$order = wc_get_order( (int) $request['order_id'] );
298
+		$order = wc_get_order((int) $request['order_id']);
299 299
 
300
-		if ( ! $order || $this->post_type !== $order->get_type() ) {
301
-			return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) );
300
+		if ( ! $order || $this->post_type !== $order->get_type()) {
301
+			return new WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404));
302 302
 		}
303 303
 
304
-		$note = get_comment( $id );
304
+		$note = get_comment($id);
305 305
 
306
-		if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) {
307
-			return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
306
+		if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) {
307
+			return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404));
308 308
 		}
309 309
 
310
-		$request->set_param( 'context', 'edit' );
311
-		$response = $this->prepare_item_for_response( $note, $request );
310
+		$request->set_param('context', 'edit');
311
+		$response = $this->prepare_item_for_response($note, $request);
312 312
 
313
-		$result = wc_delete_order_note( $note->comment_ID );
313
+		$result = wc_delete_order_note($note->comment_ID);
314 314
 
315
-		if ( ! $result ) {
316
-			return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), 'order_note' ), array( 'status' => 500 ) );
315
+		if ( ! $result) {
316
+			return new WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), 'order_note'), array('status' => 500));
317 317
 		}
318 318
 
319 319
 		/**
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 		 * @param WP_REST_Response $response The response data.
324 324
 		 * @param WP_REST_Request  $request  The request sent to the API.
325 325
 		 */
326
-		do_action( 'woocommerce_rest_delete_order_note', $note, $response, $request );
326
+		do_action('woocommerce_rest_delete_order_note', $note, $response, $request);
327 327
 
328 328
 		return $response;
329 329
 	}
@@ -335,22 +335,22 @@  discard block
 block discarded – undo
335 335
 	 * @param WP_REST_Request $request Request object.
336 336
 	 * @return WP_REST_Response $response Response data.
337 337
 	 */
338
-	public function prepare_item_for_response( $note, $request ) {
338
+	public function prepare_item_for_response($note, $request) {
339 339
 		$data = array(
340 340
 			'id'            => (int) $note->comment_ID,
341
-			'date_created'  => wc_rest_prepare_date_response( $note->comment_date_gmt ),
341
+			'date_created'  => wc_rest_prepare_date_response($note->comment_date_gmt),
342 342
 			'note'          => $note->comment_content,
343
-			'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ),
343
+			'customer_note' => (bool) get_comment_meta($note->comment_ID, 'is_customer_note', true),
344 344
 		);
345 345
 
346
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
347
-		$data    = $this->add_additional_fields_to_object( $data, $request );
348
-		$data    = $this->filter_response_by_context( $data, $context );
346
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
347
+		$data    = $this->add_additional_fields_to_object($data, $request);
348
+		$data    = $this->filter_response_by_context($data, $context);
349 349
 
350 350
 		// Wrap the data in a response object.
351
-		$response = rest_ensure_response( $data );
351
+		$response = rest_ensure_response($data);
352 352
 
353
-		$response->add_links( $this->prepare_links( $note ) );
353
+		$response->add_links($this->prepare_links($note));
354 354
 
355 355
 		/**
356 356
 		 * Filter order note object returned from the REST API.
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 		 * @param WP_Comment       $note     Order note object used to create response.
360 360
 		 * @param WP_REST_Request  $request  Request object.
361 361
 		 */
362
-		return apply_filters( 'woocommerce_rest_prepare_order_note', $response, $note, $request );
362
+		return apply_filters('woocommerce_rest_prepare_order_note', $response, $note, $request);
363 363
 	}
364 364
 
365 365
 	/**
@@ -368,18 +368,18 @@  discard block
 block discarded – undo
368 368
 	 * @param WP_Comment $note Delivery order_note object.
369 369
 	 * @return array Links for the given order note.
370 370
 	 */
371
-	protected function prepare_links( $note ) {
371
+	protected function prepare_links($note) {
372 372
 		$order_id = (int) $note->comment_post_ID;
373
-		$base     = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base );
373
+		$base     = str_replace('(?P<order_id>[\d]+)', $order_id, $this->rest_base);
374 374
 		$links    = array(
375 375
 			'self' => array(
376
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $note->comment_ID ) ),
376
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $note->comment_ID)),
377 377
 			),
378 378
 			'collection' => array(
379
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
379
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)),
380 380
 			),
381 381
 			'up' => array(
382
-				'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order_id ) ),
382
+				'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $order_id)),
383 383
 			),
384 384
 		);
385 385
 
@@ -398,32 +398,32 @@  discard block
 block discarded – undo
398 398
 			'type'       => 'object',
399 399
 			'properties' => array(
400 400
 				'id' => array(
401
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
401
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
402 402
 					'type'        => 'integer',
403
-					'context'     => array( 'view', 'edit' ),
403
+					'context'     => array('view', 'edit'),
404 404
 					'readonly'    => true,
405 405
 				),
406 406
 				'date_created' => array(
407
-					'description' => __( "The date the order note was created, in the site's timezone.", 'woocommerce' ),
407
+					'description' => __("The date the order note was created, in the site's timezone.", 'woocommerce'),
408 408
 					'type'        => 'date-time',
409
-					'context'     => array( 'view', 'edit' ),
409
+					'context'     => array('view', 'edit'),
410 410
 					'readonly'    => true,
411 411
 				),
412 412
 				'note' => array(
413
-					'description' => __( 'Order note.', 'woocommerce' ),
413
+					'description' => __('Order note.', 'woocommerce'),
414 414
 					'type'        => 'string',
415
-					'context'     => array( 'view', 'edit' ),
415
+					'context'     => array('view', 'edit'),
416 416
 				),
417 417
 				'customer_note' => array(
418
-					'description' => __( 'Shows/define if the note is only for reference or for the customer (the user will be notified).', 'woocommerce' ),
418
+					'description' => __('Shows/define if the note is only for reference or for the customer (the user will be notified).', 'woocommerce'),
419 419
 					'type'        => 'boolean',
420 420
 					'default'     => false,
421
-					'context'     => array( 'view', 'edit' ),
421
+					'context'     => array('view', 'edit'),
422 422
 				),
423 423
 			),
424 424
 		);
425 425
 
426
-		return $this->add_additional_fields_schema( $schema );
426
+		return $this->add_additional_fields_schema($schema);
427 427
 	}
428 428
 
429 429
 	/**
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 	 */
434 434
 	public function get_collection_params() {
435 435
 		return array(
436
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
436
+			'context' => $this->get_context_param(array('default' => 'view')),
437 437
 		);
438 438
 	}
439 439
 }
Please login to merge, or discard this patch.
src/Controllers/Version1/class-wc-rest-customers-v1-controller.php 1 patch
Spacing   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @since    3.0.0
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -40,88 +40,88 @@  discard block
 block discarded – undo
40 40
 	 * Register the routes for customers.
41 41
 	 */
42 42
 	public function register_routes() {
43
-		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
43
+		register_rest_route($this->namespace, '/' . $this->rest_base, array(
44 44
 			array(
45 45
 				'methods'             => WP_REST_Server::READABLE,
46
-				'callback'            => array( $this, 'get_items' ),
47
-				'permission_callback' => array( $this, 'get_items_permissions_check' ),
46
+				'callback'            => array($this, 'get_items'),
47
+				'permission_callback' => array($this, 'get_items_permissions_check'),
48 48
 				'args'                => $this->get_collection_params(),
49 49
 			),
50 50
 			array(
51 51
 				'methods'             => WP_REST_Server::CREATABLE,
52
-				'callback'            => array( $this, 'create_item' ),
53
-				'permission_callback' => array( $this, 'create_item_permissions_check' ),
54
-				'args'                => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
52
+				'callback'            => array($this, 'create_item'),
53
+				'permission_callback' => array($this, 'create_item_permissions_check'),
54
+				'args'                => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array(
55 55
 					'email' => array(
56 56
 						'required' => true,
57 57
 						'type'     => 'string',
58
-						'description' => __( 'New user email address.', 'woocommerce' ),
58
+						'description' => __('New user email address.', 'woocommerce'),
59 59
 					),
60 60
 					'username' => array(
61
-						'required' => 'no' === get_option( 'woocommerce_registration_generate_username', 'yes' ),
62
-						'description' => __( 'New user username.', 'woocommerce' ),
61
+						'required' => 'no' === get_option('woocommerce_registration_generate_username', 'yes'),
62
+						'description' => __('New user username.', 'woocommerce'),
63 63
 						'type'     => 'string',
64 64
 					),
65 65
 					'password' => array(
66
-						'required' => 'no' === get_option( 'woocommerce_registration_generate_password', 'no' ),
67
-						'description' => __( 'New user password.', 'woocommerce' ),
66
+						'required' => 'no' === get_option('woocommerce_registration_generate_password', 'no'),
67
+						'description' => __('New user password.', 'woocommerce'),
68 68
 						'type'     => 'string',
69 69
 					),
70
-				) ),
70
+				)),
71 71
 			),
72
-			'schema' => array( $this, 'get_public_item_schema' ),
73
-		) );
72
+			'schema' => array($this, 'get_public_item_schema'),
73
+		));
74 74
 
75
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
75
+		register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
76 76
 			'args' => array(
77 77
 				'id' => array(
78
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
78
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
79 79
 					'type'        => 'integer',
80 80
 				),
81 81
 			),
82 82
 			array(
83 83
 				'methods'             => WP_REST_Server::READABLE,
84
-				'callback'            => array( $this, 'get_item' ),
85
-				'permission_callback' => array( $this, 'get_item_permissions_check' ),
84
+				'callback'            => array($this, 'get_item'),
85
+				'permission_callback' => array($this, 'get_item_permissions_check'),
86 86
 				'args'                => array(
87
-					'context' => $this->get_context_param( array( 'default' => 'view' ) ),
87
+					'context' => $this->get_context_param(array('default' => 'view')),
88 88
 				),
89 89
 			),
90 90
 			array(
91 91
 				'methods'             => WP_REST_Server::EDITABLE,
92
-				'callback'            => array( $this, 'update_item' ),
93
-				'permission_callback' => array( $this, 'update_item_permissions_check' ),
94
-				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
92
+				'callback'            => array($this, 'update_item'),
93
+				'permission_callback' => array($this, 'update_item_permissions_check'),
94
+				'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
95 95
 			),
96 96
 			array(
97 97
 				'methods'             => WP_REST_Server::DELETABLE,
98
-				'callback'            => array( $this, 'delete_item' ),
99
-				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
98
+				'callback'            => array($this, 'delete_item'),
99
+				'permission_callback' => array($this, 'delete_item_permissions_check'),
100 100
 				'args'                => array(
101 101
 					'force' => array(
102 102
 						'default'     => false,
103 103
 						'type'        => 'boolean',
104
-						'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
104
+						'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
105 105
 					),
106 106
 					'reassign' => array(
107 107
 						'default'     => 0,
108 108
 						'type'        => 'integer',
109
-						'description' => __( 'ID to reassign posts to.', 'woocommerce' ),
109
+						'description' => __('ID to reassign posts to.', 'woocommerce'),
110 110
 					),
111 111
 				),
112 112
 			),
113
-			'schema' => array( $this, 'get_public_item_schema' ),
114
-		) );
113
+			'schema' => array($this, 'get_public_item_schema'),
114
+		));
115 115
 
116
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
116
+		register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array(
117 117
 			array(
118 118
 				'methods'             => WP_REST_Server::EDITABLE,
119
-				'callback'            => array( $this, 'batch_items' ),
120
-				'permission_callback' => array( $this, 'batch_items_permissions_check' ),
121
-				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
119
+				'callback'            => array($this, 'batch_items'),
120
+				'permission_callback' => array($this, 'batch_items_permissions_check'),
121
+				'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
122 122
 			),
123
-			'schema' => array( $this, 'get_public_batch_schema' ),
124
-		) );
123
+			'schema' => array($this, 'get_public_batch_schema'),
124
+		));
125 125
 	}
126 126
 
127 127
 	/**
@@ -130,9 +130,9 @@  discard block
 block discarded – undo
130 130
 	 * @param  WP_REST_Request $request Full details about the request.
131 131
 	 * @return WP_Error|boolean
132 132
 	 */
133
-	public function get_items_permissions_check( $request ) {
134
-		if ( ! wc_rest_check_user_permissions( 'read' ) ) {
135
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
133
+	public function get_items_permissions_check($request) {
134
+		if ( ! wc_rest_check_user_permissions('read')) {
135
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
136 136
 		}
137 137
 
138 138
 		return true;
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
 	 *
146 146
 	 * @return bool|WP_Error
147 147
 	 */
148
-	public function create_item_permissions_check( $request ) {
149
-		if ( ! wc_rest_check_user_permissions( 'create' ) ) {
150
-			return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
148
+	public function create_item_permissions_check($request) {
149
+		if ( ! wc_rest_check_user_permissions('create')) {
150
+			return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
151 151
 		}
152 152
 
153 153
 		return true;
@@ -159,11 +159,11 @@  discard block
 block discarded – undo
159 159
 	 * @param  WP_REST_Request $request Full details about the request.
160 160
 	 * @return WP_Error|boolean
161 161
 	 */
162
-	public function get_item_permissions_check( $request ) {
162
+	public function get_item_permissions_check($request) {
163 163
 		$id = (int) $request['id'];
164 164
 
165
-		if ( ! wc_rest_check_user_permissions( 'read', $id ) ) {
166
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
165
+		if ( ! wc_rest_check_user_permissions('read', $id)) {
166
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
167 167
 		}
168 168
 
169 169
 		return true;
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
 	 *
177 177
 	 * @return bool|WP_Error
178 178
 	 */
179
-	public function update_item_permissions_check( $request ) {
179
+	public function update_item_permissions_check($request) {
180 180
 		$id = (int) $request['id'];
181 181
 
182
-		if ( ! wc_rest_check_user_permissions( 'edit', $id ) ) {
183
-			return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
182
+		if ( ! wc_rest_check_user_permissions('edit', $id)) {
183
+			return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
184 184
 		}
185 185
 
186 186
 		return true;
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
 	 *
194 194
 	 * @return bool|WP_Error
195 195
 	 */
196
-	public function delete_item_permissions_check( $request ) {
196
+	public function delete_item_permissions_check($request) {
197 197
 		$id = (int) $request['id'];
198 198
 
199
-		if ( ! wc_rest_check_user_permissions( 'delete', $id ) ) {
200
-			return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
199
+		if ( ! wc_rest_check_user_permissions('delete', $id)) {
200
+			return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
201 201
 		}
202 202
 
203 203
 		return true;
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
 	 *
211 211
 	 * @return bool|WP_Error
212 212
 	 */
213
-	public function batch_items_permissions_check( $request ) {
214
-		if ( ! wc_rest_check_user_permissions( 'batch' ) ) {
215
-			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() ) );
213
+	public function batch_items_permissions_check($request) {
214
+		if ( ! wc_rest_check_user_permissions('batch')) {
215
+			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()));
216 216
 		}
217 217
 
218 218
 		return true;
@@ -224,16 +224,16 @@  discard block
 block discarded – undo
224 224
 	 * @param WP_REST_Request $request Full details about the request.
225 225
 	 * @return WP_Error|WP_REST_Response
226 226
 	 */
227
-	public function get_items( $request ) {
227
+	public function get_items($request) {
228 228
 		$prepared_args = array();
229 229
 		$prepared_args['exclude'] = $request['exclude'];
230 230
 		$prepared_args['include'] = $request['include'];
231 231
 		$prepared_args['order']   = $request['order'];
232 232
 		$prepared_args['number']  = $request['per_page'];
233
-		if ( ! empty( $request['offset'] ) ) {
233
+		if ( ! empty($request['offset'])) {
234 234
 			$prepared_args['offset'] = $request['offset'];
235 235
 		} else {
236
-			$prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
236
+			$prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number'];
237 237
 		}
238 238
 		$orderby_possibles = array(
239 239
 			'id'              => 'ID',
@@ -241,21 +241,21 @@  discard block
 block discarded – undo
241 241
 			'name'            => 'display_name',
242 242
 			'registered_date' => 'registered',
243 243
 		);
244
-		$prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ];
244
+		$prepared_args['orderby'] = $orderby_possibles[$request['orderby']];
245 245
 		$prepared_args['search']  = $request['search'];
246 246
 
247
-		if ( '' !== $prepared_args['search'] ) {
247
+		if ('' !== $prepared_args['search']) {
248 248
 			$prepared_args['search'] = '*' . $prepared_args['search'] . '*';
249 249
 		}
250 250
 
251 251
 		// Filter by email.
252
-		if ( ! empty( $request['email'] ) ) {
252
+		if ( ! empty($request['email'])) {
253 253
 			$prepared_args['search']         = $request['email'];
254
-			$prepared_args['search_columns'] = array( 'user_email' );
254
+			$prepared_args['search_columns'] = array('user_email');
255 255
 		}
256 256
 
257 257
 		// Filter by role.
258
-		if ( 'all' !== $request['role'] ) {
258
+		if ('all' !== $request['role']) {
259 259
 			$prepared_args['role'] = $request['role'];
260 260
 		}
261 261
 
@@ -267,49 +267,49 @@  discard block
 block discarded – undo
267 267
 		 * @param array           $prepared_args Array of arguments for WP_User_Query.
268 268
 		 * @param WP_REST_Request $request       The current request.
269 269
 		 */
270
-		$prepared_args = apply_filters( 'woocommerce_rest_customer_query', $prepared_args, $request );
270
+		$prepared_args = apply_filters('woocommerce_rest_customer_query', $prepared_args, $request);
271 271
 
272
-		$query = new WP_User_Query( $prepared_args );
272
+		$query = new WP_User_Query($prepared_args);
273 273
 
274 274
 		$users = array();
275
-		foreach ( $query->results as $user ) {
276
-			$data = $this->prepare_item_for_response( $user, $request );
277
-			$users[] = $this->prepare_response_for_collection( $data );
275
+		foreach ($query->results as $user) {
276
+			$data = $this->prepare_item_for_response($user, $request);
277
+			$users[] = $this->prepare_response_for_collection($data);
278 278
 		}
279 279
 
280
-		$response = rest_ensure_response( $users );
280
+		$response = rest_ensure_response($users);
281 281
 
282 282
 		// Store pagination values for headers then unset for count query.
283 283
 		$per_page = (int) $prepared_args['number'];
284
-		$page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
284
+		$page = ceil((((int) $prepared_args['offset']) / $per_page) + 1);
285 285
 
286 286
 		$prepared_args['fields'] = 'ID';
287 287
 
288 288
 		$total_users = $query->get_total();
289
-		if ( $total_users < 1 ) {
289
+		if ($total_users < 1) {
290 290
 			// Out-of-bounds, run the query again without LIMIT for total count.
291
-			unset( $prepared_args['number'] );
292
-			unset( $prepared_args['offset'] );
293
-			$count_query = new WP_User_Query( $prepared_args );
291
+			unset($prepared_args['number']);
292
+			unset($prepared_args['offset']);
293
+			$count_query = new WP_User_Query($prepared_args);
294 294
 			$total_users = $count_query->get_total();
295 295
 		}
296
-		$response->header( 'X-WP-Total', (int) $total_users );
297
-		$max_pages = ceil( $total_users / $per_page );
298
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
296
+		$response->header('X-WP-Total', (int) $total_users);
297
+		$max_pages = ceil($total_users / $per_page);
298
+		$response->header('X-WP-TotalPages', (int) $max_pages);
299 299
 
300
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
301
-		if ( $page > 1 ) {
300
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
301
+		if ($page > 1) {
302 302
 			$prev_page = $page - 1;
303
-			if ( $prev_page > $max_pages ) {
303
+			if ($prev_page > $max_pages) {
304 304
 				$prev_page = $max_pages;
305 305
 			}
306
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
307
-			$response->link_header( 'prev', $prev_link );
306
+			$prev_link = add_query_arg('page', $prev_page, $base);
307
+			$response->link_header('prev', $prev_link);
308 308
 		}
309
-		if ( $max_pages > $page ) {
309
+		if ($max_pages > $page) {
310 310
 			$next_page = $page + 1;
311
-			$next_link = add_query_arg( 'page', $next_page, $base );
312
-			$response->link_header( 'next', $next_link );
311
+			$next_link = add_query_arg('page', $next_page, $base);
312
+			$response->link_header('next', $next_link);
313 313
 		}
314 314
 
315 315
 		return $response;
@@ -321,32 +321,32 @@  discard block
 block discarded – undo
321 321
 	 * @param WP_REST_Request $request Full details about the request.
322 322
 	 * @return WP_Error|WP_REST_Response
323 323
 	 */
324
-	public function create_item( $request ) {
324
+	public function create_item($request) {
325 325
 		try {
326
-			if ( ! empty( $request['id'] ) ) {
327
-				throw new WC_REST_Exception( 'woocommerce_rest_customer_exists', __( 'Cannot create existing resource.', 'woocommerce' ), 400 );
326
+			if ( ! empty($request['id'])) {
327
+				throw new WC_REST_Exception('woocommerce_rest_customer_exists', __('Cannot create existing resource.', 'woocommerce'), 400);
328 328
 			}
329 329
 
330 330
 			// Sets the username.
331
-			$request['username'] = ! empty( $request['username'] ) ? $request['username'] : '';
331
+			$request['username'] = ! empty($request['username']) ? $request['username'] : '';
332 332
 
333 333
 			// Sets the password.
334
-			$request['password'] = ! empty( $request['password'] ) ? $request['password'] : '';
334
+			$request['password'] = ! empty($request['password']) ? $request['password'] : '';
335 335
 
336 336
 			// Create customer.
337 337
 			$customer = new WC_Customer;
338
-			$customer->set_username( $request['username'] );
339
-			$customer->set_password( $request['password'] );
340
-			$customer->set_email( $request['email'] );
341
-			$this->update_customer_meta_fields( $customer, $request );
338
+			$customer->set_username($request['username']);
339
+			$customer->set_password($request['password']);
340
+			$customer->set_email($request['email']);
341
+			$this->update_customer_meta_fields($customer, $request);
342 342
 			$customer->save();
343 343
 
344
-			if ( ! $customer->get_id() ) {
345
-				throw new WC_REST_Exception( 'woocommerce_rest_cannot_create', __( 'This resource cannot be created.', 'woocommerce' ), 400 );
344
+			if ( ! $customer->get_id()) {
345
+				throw new WC_REST_Exception('woocommerce_rest_cannot_create', __('This resource cannot be created.', 'woocommerce'), 400);
346 346
 			}
347 347
 
348
-			$user_data = get_userdata( $customer->get_id() );
349
-			$this->update_additional_fields_for_object( $user_data, $request );
348
+			$user_data = get_userdata($customer->get_id());
349
+			$this->update_additional_fields_for_object($user_data, $request);
350 350
 
351 351
 			/**
352 352
 			 * Fires after a customer is created or updated via the REST API.
@@ -355,17 +355,17 @@  discard block
 block discarded – undo
355 355
 			 * @param WP_REST_Request $request   Request object.
356 356
 			 * @param boolean         $creating  True when creating customer, false when updating customer.
357 357
 			 */
358
-			do_action( 'woocommerce_rest_insert_customer', $user_data, $request, true );
358
+			do_action('woocommerce_rest_insert_customer', $user_data, $request, true);
359 359
 
360
-			$request->set_param( 'context', 'edit' );
361
-			$response = $this->prepare_item_for_response( $user_data, $request );
362
-			$response = rest_ensure_response( $response );
363
-			$response->set_status( 201 );
364
-			$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $customer->get_id() ) ) );
360
+			$request->set_param('context', 'edit');
361
+			$response = $this->prepare_item_for_response($user_data, $request);
362
+			$response = rest_ensure_response($response);
363
+			$response->set_status(201);
364
+			$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $customer->get_id())));
365 365
 
366 366
 			return $response;
367
-		} catch ( Exception $e ) {
368
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
367
+		} catch (Exception $e) {
368
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
369 369
 		}
370 370
 	}
371 371
 
@@ -375,16 +375,16 @@  discard block
 block discarded – undo
375 375
 	 * @param WP_REST_Request $request Full details about the request.
376 376
 	 * @return WP_Error|WP_REST_Response
377 377
 	 */
378
-	public function get_item( $request ) {
378
+	public function get_item($request) {
379 379
 		$id        = (int) $request['id'];
380
-		$user_data = get_userdata( $id );
380
+		$user_data = get_userdata($id);
381 381
 
382
-		if ( empty( $id ) || empty( $user_data->ID ) ) {
383
-			return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
382
+		if (empty($id) || empty($user_data->ID)) {
383
+			return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404));
384 384
 		}
385 385
 
386
-		$customer = $this->prepare_item_for_response( $user_data, $request );
387
-		$response = rest_ensure_response( $customer );
386
+		$customer = $this->prepare_item_for_response($user_data, $request);
387
+		$response = rest_ensure_response($customer);
388 388
 
389 389
 		return $response;
390 390
 	}
@@ -395,41 +395,41 @@  discard block
 block discarded – undo
395 395
 	 * @param WP_REST_Request $request Full details about the request.
396 396
 	 * @return WP_Error|WP_REST_Response
397 397
 	 */
398
-	public function update_item( $request ) {
398
+	public function update_item($request) {
399 399
 		try {
400 400
 			$id       = (int) $request['id'];
401
-			$customer = new WC_Customer( $id );
401
+			$customer = new WC_Customer($id);
402 402
 
403
-			if ( ! $customer->get_id() ) {
404
-				throw new WC_REST_Exception( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), 400 );
403
+			if ( ! $customer->get_id()) {
404
+				throw new WC_REST_Exception('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), 400);
405 405
 			}
406 406
 
407
-			if ( ! empty( $request['email'] ) && email_exists( $request['email'] ) && $request['email'] !== $customer->get_email() ) {
408
-				throw new WC_REST_Exception( 'woocommerce_rest_customer_invalid_email', __( 'Email address is invalid.', 'woocommerce' ), 400 );
407
+			if ( ! empty($request['email']) && email_exists($request['email']) && $request['email'] !== $customer->get_email()) {
408
+				throw new WC_REST_Exception('woocommerce_rest_customer_invalid_email', __('Email address is invalid.', 'woocommerce'), 400);
409 409
 			}
410 410
 
411
-			if ( ! empty( $request['username'] ) && $request['username'] !== $customer->get_username() ) {
412
-				throw new WC_REST_Exception( 'woocommerce_rest_customer_invalid_argument', __( "Username isn't editable.", 'woocommerce' ), 400 );
411
+			if ( ! empty($request['username']) && $request['username'] !== $customer->get_username()) {
412
+				throw new WC_REST_Exception('woocommerce_rest_customer_invalid_argument', __("Username isn't editable.", 'woocommerce'), 400);
413 413
 			}
414 414
 
415 415
 			// Customer email.
416
-			if ( isset( $request['email'] ) ) {
417
-				$customer->set_email( sanitize_email( $request['email'] ) );
416
+			if (isset($request['email'])) {
417
+				$customer->set_email(sanitize_email($request['email']));
418 418
 			}
419 419
 
420 420
 			// Customer password.
421
-			if ( isset( $request['password'] ) ) {
422
-				$customer->set_password( $request['password'] );
421
+			if (isset($request['password'])) {
422
+				$customer->set_password($request['password']);
423 423
 			}
424 424
 
425
-			$this->update_customer_meta_fields( $customer, $request );
425
+			$this->update_customer_meta_fields($customer, $request);
426 426
 			$customer->save();
427 427
 
428
-			$user_data = get_userdata( $customer->get_id() );
429
-			$this->update_additional_fields_for_object( $user_data, $request );
428
+			$user_data = get_userdata($customer->get_id());
429
+			$this->update_additional_fields_for_object($user_data, $request);
430 430
 
431
-			if ( ! is_user_member_of_blog( $user_data->ID ) ) {
432
-				$user_data->add_role( 'customer' );
431
+			if ( ! is_user_member_of_blog($user_data->ID)) {
432
+				$user_data->add_role('customer');
433 433
 			}
434 434
 
435 435
 			/**
@@ -439,14 +439,14 @@  discard block
 block discarded – undo
439 439
 			 * @param WP_REST_Request $request   Request object.
440 440
 			 * @param boolean         $creating  True when creating customer, false when updating customer.
441 441
 			 */
442
-			do_action( 'woocommerce_rest_insert_customer', $user_data, $request, false );
442
+			do_action('woocommerce_rest_insert_customer', $user_data, $request, false);
443 443
 
444
-			$request->set_param( 'context', 'edit' );
445
-			$response = $this->prepare_item_for_response( $user_data, $request );
446
-			$response = rest_ensure_response( $response );
444
+			$request->set_param('context', 'edit');
445
+			$response = $this->prepare_item_for_response($user_data, $request);
446
+			$response = rest_ensure_response($response);
447 447
 			return $response;
448
-		} catch ( Exception $e ) {
449
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
448
+		} catch (Exception $e) {
449
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
450 450
 		}
451 451
 	}
452 452
 
@@ -456,43 +456,43 @@  discard block
 block discarded – undo
456 456
 	 * @param WP_REST_Request $request Full details about the request.
457 457
 	 * @return WP_Error|WP_REST_Response
458 458
 	 */
459
-	public function delete_item( $request ) {
459
+	public function delete_item($request) {
460 460
 		$id       = (int) $request['id'];
461
-		$reassign = isset( $request['reassign'] ) ? absint( $request['reassign'] ) : null;
462
-		$force    = isset( $request['force'] ) ? (bool) $request['force'] : false;
461
+		$reassign = isset($request['reassign']) ? absint($request['reassign']) : null;
462
+		$force    = isset($request['force']) ? (bool) $request['force'] : false;
463 463
 
464 464
 		// We don't support trashing for this type, error out.
465
-		if ( ! $force ) {
466
-			return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Customers do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
465
+		if ( ! $force) {
466
+			return new WP_Error('woocommerce_rest_trash_not_supported', __('Customers do not support trashing.', 'woocommerce'), array('status' => 501));
467 467
 		}
468 468
 
469
-		$user_data = get_userdata( $id );
470
-		if ( ! $user_data ) {
471
-			return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 400 ) );
469
+		$user_data = get_userdata($id);
470
+		if ( ! $user_data) {
471
+			return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource id.', 'woocommerce'), array('status' => 400));
472 472
 		}
473 473
 
474
-		if ( ! empty( $reassign ) ) {
475
-			if ( $reassign === $id || ! get_userdata( $reassign ) ) {
476
-				return new WP_Error( 'woocommerce_rest_customer_invalid_reassign', __( 'Invalid resource id for reassignment.', 'woocommerce' ), array( 'status' => 400 ) );
474
+		if ( ! empty($reassign)) {
475
+			if ($reassign === $id || ! get_userdata($reassign)) {
476
+				return new WP_Error('woocommerce_rest_customer_invalid_reassign', __('Invalid resource id for reassignment.', 'woocommerce'), array('status' => 400));
477 477
 			}
478 478
 		}
479 479
 
480
-		$request->set_param( 'context', 'edit' );
481
-		$response = $this->prepare_item_for_response( $user_data, $request );
480
+		$request->set_param('context', 'edit');
481
+		$response = $this->prepare_item_for_response($user_data, $request);
482 482
 
483 483
 		/** Include admin customer functions to get access to wp_delete_user() */
484 484
 		require_once ABSPATH . 'wp-admin/includes/user.php';
485 485
 
486
-		$customer = new WC_Customer( $id );
486
+		$customer = new WC_Customer($id);
487 487
 
488
-		if ( ! is_null( $reassign ) ) {
489
-			$result = $customer->delete_and_reassign( $reassign );
488
+		if ( ! is_null($reassign)) {
489
+			$result = $customer->delete_and_reassign($reassign);
490 490
 		} else {
491 491
 			$result = $customer->delete();
492 492
 		}
493 493
 
494
-		if ( ! $result ) {
495
-			return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
494
+		if ( ! $result) {
495
+			return new WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500));
496 496
 		}
497 497
 
498 498
 		/**
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 		 * @param WP_REST_Response $response  The response returned from the API.
503 503
 		 * @param WP_REST_Request  $request   The request sent to the API.
504 504
 		 */
505
-		do_action( 'woocommerce_rest_delete_customer', $user_data, $response, $request );
505
+		do_action('woocommerce_rest_delete_customer', $user_data, $response, $request);
506 506
 
507 507
 		return $response;
508 508
 	}
@@ -514,15 +514,15 @@  discard block
 block discarded – undo
514 514
 	 * @param  WP_REST_Request  $request Request object.
515 515
 	 * @return WP_REST_Response $response Response data.
516 516
 	 */
517
-	public function prepare_item_for_response( $user_data, $request ) {
518
-		$customer    = new WC_Customer( $user_data->ID );
517
+	public function prepare_item_for_response($user_data, $request) {
518
+		$customer    = new WC_Customer($user_data->ID);
519 519
 		$_data       = $customer->get_data();
520
-		$last_order  = wc_get_customer_last_order( $customer->get_id() );
521
-		$format_date = array( 'date_created', 'date_modified' );
520
+		$last_order  = wc_get_customer_last_order($customer->get_id());
521
+		$format_date = array('date_created', 'date_modified');
522 522
 
523 523
 		// Format date values.
524
-		foreach ( $format_date as $key ) {
525
-			$_data[ $key ] = $_data[ $key ] ? wc_rest_prepare_date_response( $_data[ $key ] ) : null; // v1 API used UTC.
524
+		foreach ($format_date as $key) {
525
+			$_data[$key] = $_data[$key] ? wc_rest_prepare_date_response($_data[$key]) : null; // v1 API used UTC.
526 526
 		}
527 527
 
528 528
 		$data = array(
@@ -534,8 +534,8 @@  discard block
 block discarded – undo
534 534
 			'last_name'     => $_data['last_name'],
535 535
 			'username'      => $_data['username'],
536 536
 			'last_order'    => array(
537
-				'id'   => is_object( $last_order ) ? $last_order->get_id() : null,
538
-				'date' => is_object( $last_order ) ? wc_rest_prepare_date_response( $last_order->get_date_created() ) : null, // v1 API used UTC.
537
+				'id'   => is_object($last_order) ? $last_order->get_id() : null,
538
+				'date' => is_object($last_order) ? wc_rest_prepare_date_response($last_order->get_date_created()) : null, // v1 API used UTC.
539 539
 			),
540 540
 			'orders_count'  => $customer->get_order_count(),
541 541
 			'total_spent'   => $customer->get_total_spent(),
@@ -544,11 +544,11 @@  discard block
 block discarded – undo
544 544
 			'shipping'      => $_data['shipping'],
545 545
 		);
546 546
 
547
-		$context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
548
-		$data     = $this->add_additional_fields_to_object( $data, $request );
549
-		$data     = $this->filter_response_by_context( $data, $context );
550
-		$response = rest_ensure_response( $data );
551
-		$response->add_links( $this->prepare_links( $user_data ) );
547
+		$context  = ! empty($request['context']) ? $request['context'] : 'view';
548
+		$data     = $this->add_additional_fields_to_object($data, $request);
549
+		$data     = $this->filter_response_by_context($data, $context);
550
+		$response = rest_ensure_response($data);
551
+		$response->add_links($this->prepare_links($user_data));
552 552
 
553 553
 		/**
554 554
 		 * Filter customer data returned from the REST API.
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
 		 * @param WP_User          $user_data  User object used to create response.
558 558
 		 * @param WP_REST_Request  $request    Request object.
559 559
 		 */
560
-		return apply_filters( 'woocommerce_rest_prepare_customer', $response, $user_data, $request );
560
+		return apply_filters('woocommerce_rest_prepare_customer', $response, $user_data, $request);
561 561
 	}
562 562
 
563 563
 	/**
@@ -566,33 +566,33 @@  discard block
 block discarded – undo
566 566
 	 * @param WC_Customer $customer
567 567
 	 * @param WP_REST_Request $request
568 568
 	 */
569
-	protected function update_customer_meta_fields( $customer, $request ) {
569
+	protected function update_customer_meta_fields($customer, $request) {
570 570
 		$schema = $this->get_item_schema();
571 571
 
572 572
 		// Customer first name.
573
-		if ( isset( $request['first_name'] ) ) {
574
-			$customer->set_first_name( wc_clean( $request['first_name'] ) );
573
+		if (isset($request['first_name'])) {
574
+			$customer->set_first_name(wc_clean($request['first_name']));
575 575
 		}
576 576
 
577 577
 		// Customer last name.
578
-		if ( isset( $request['last_name'] ) ) {
579
-			$customer->set_last_name( wc_clean( $request['last_name'] ) );
578
+		if (isset($request['last_name'])) {
579
+			$customer->set_last_name(wc_clean($request['last_name']));
580 580
 		}
581 581
 
582 582
 		// Customer billing address.
583
-		if ( isset( $request['billing'] ) ) {
584
-			foreach ( array_keys( $schema['properties']['billing']['properties'] ) as $field ) {
585
-				if ( isset( $request['billing'][ $field ] ) && is_callable( array( $customer, "set_billing_{$field}" ) ) ) {
586
-					$customer->{"set_billing_{$field}"}( $request['billing'][ $field ] );
583
+		if (isset($request['billing'])) {
584
+			foreach (array_keys($schema['properties']['billing']['properties']) as $field) {
585
+				if (isset($request['billing'][$field]) && is_callable(array($customer, "set_billing_{$field}"))) {
586
+					$customer->{"set_billing_{$field}"}($request['billing'][$field]);
587 587
 				}
588 588
 			}
589 589
 		}
590 590
 
591 591
 		// Customer shipping address.
592
-		if ( isset( $request['shipping'] ) ) {
593
-			foreach ( array_keys( $schema['properties']['shipping']['properties'] ) as $field ) {
594
-				if ( isset( $request['shipping'][ $field ] ) && is_callable( array( $customer, "set_shipping_{$field}" ) ) ) {
595
-					$customer->{"set_shipping_{$field}"}( $request['shipping'][ $field ] );
592
+		if (isset($request['shipping'])) {
593
+			foreach (array_keys($schema['properties']['shipping']['properties']) as $field) {
594
+				if (isset($request['shipping'][$field]) && is_callable(array($customer, "set_shipping_{$field}"))) {
595
+					$customer->{"set_shipping_{$field}"}($request['shipping'][$field]);
596 596
 				}
597 597
 			}
598 598
 		}
@@ -604,13 +604,13 @@  discard block
 block discarded – undo
604 604
 	 * @param WP_User $customer Customer object.
605 605
 	 * @return array Links for the given customer.
606 606
 	 */
607
-	protected function prepare_links( $customer ) {
607
+	protected function prepare_links($customer) {
608 608
 		$links = array(
609 609
 			'self' => array(
610
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $customer->ID ) ),
610
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $customer->ID)),
611 611
 			),
612 612
 			'collection' => array(
613
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
613
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
614 614
 			),
615 615
 		);
616 616
 
@@ -629,215 +629,215 @@  discard block
 block discarded – undo
629 629
 			'type'       => 'object',
630 630
 			'properties' => array(
631 631
 				'id' => array(
632
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
632
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
633 633
 					'type'        => 'integer',
634
-					'context'     => array( 'view', 'edit' ),
634
+					'context'     => array('view', 'edit'),
635 635
 					'readonly'    => true,
636 636
 				),
637 637
 				'date_created' => array(
638
-					'description' => __( 'The date the customer was created, as GMT.', 'woocommerce' ),
638
+					'description' => __('The date the customer was created, as GMT.', 'woocommerce'),
639 639
 					'type'        => 'date-time',
640
-					'context'     => array( 'view', 'edit' ),
640
+					'context'     => array('view', 'edit'),
641 641
 					'readonly'    => true,
642 642
 				),
643 643
 				'date_modified' => array(
644
-					'description' => __( 'The date the customer was last modified, as GMT.', 'woocommerce' ),
644
+					'description' => __('The date the customer was last modified, as GMT.', 'woocommerce'),
645 645
 					'type'        => 'date-time',
646
-					'context'     => array( 'view', 'edit' ),
646
+					'context'     => array('view', 'edit'),
647 647
 					'readonly'    => true,
648 648
 				),
649 649
 				'email' => array(
650
-					'description' => __( 'The email address for the customer.', 'woocommerce' ),
650
+					'description' => __('The email address for the customer.', 'woocommerce'),
651 651
 					'type'        => 'string',
652 652
 					'format'      => 'email',
653
-					'context'     => array( 'view', 'edit' ),
653
+					'context'     => array('view', 'edit'),
654 654
 				),
655 655
 				'first_name' => array(
656
-					'description' => __( 'Customer first name.', 'woocommerce' ),
656
+					'description' => __('Customer first name.', 'woocommerce'),
657 657
 					'type'        => 'string',
658
-					'context'     => array( 'view', 'edit' ),
658
+					'context'     => array('view', 'edit'),
659 659
 					'arg_options' => array(
660 660
 						'sanitize_callback' => 'sanitize_text_field',
661 661
 					),
662 662
 				),
663 663
 				'last_name' => array(
664
-					'description' => __( 'Customer last name.', 'woocommerce' ),
664
+					'description' => __('Customer last name.', 'woocommerce'),
665 665
 					'type'        => 'string',
666
-					'context'     => array( 'view', 'edit' ),
666
+					'context'     => array('view', 'edit'),
667 667
 					'arg_options' => array(
668 668
 						'sanitize_callback' => 'sanitize_text_field',
669 669
 					),
670 670
 				),
671 671
 				'username' => array(
672
-					'description' => __( 'Customer login name.', 'woocommerce' ),
672
+					'description' => __('Customer login name.', 'woocommerce'),
673 673
 					'type'        => 'string',
674
-					'context'     => array( 'view', 'edit' ),
674
+					'context'     => array('view', 'edit'),
675 675
 					'arg_options' => array(
676 676
 						'sanitize_callback' => 'sanitize_user',
677 677
 					),
678 678
 				),
679 679
 				'password' => array(
680
-					'description' => __( 'Customer password.', 'woocommerce' ),
680
+					'description' => __('Customer password.', 'woocommerce'),
681 681
 					'type'        => 'string',
682
-					'context'     => array( 'edit' ),
682
+					'context'     => array('edit'),
683 683
 				),
684 684
 				'last_order' => array(
685
-					'description' => __( 'Last order data.', 'woocommerce' ),
685
+					'description' => __('Last order data.', 'woocommerce'),
686 686
 					'type'        => 'object',
687
-					'context'     => array( 'view', 'edit' ),
687
+					'context'     => array('view', 'edit'),
688 688
 					'readonly'    => true,
689 689
 					'properties'  => array(
690 690
 						'id' => array(
691
-							'description' => __( 'Last order ID.', 'woocommerce' ),
691
+							'description' => __('Last order ID.', 'woocommerce'),
692 692
 							'type'        => 'integer',
693
-							'context'     => array( 'view', 'edit' ),
693
+							'context'     => array('view', 'edit'),
694 694
 							'readonly'    => true,
695 695
 						),
696 696
 						'date' => array(
697
-							'description' => __( 'The date of the customer last order, as GMT.', 'woocommerce' ),
697
+							'description' => __('The date of the customer last order, as GMT.', 'woocommerce'),
698 698
 							'type'        => 'date-time',
699
-							'context'     => array( 'view', 'edit' ),
699
+							'context'     => array('view', 'edit'),
700 700
 							'readonly'    => true,
701 701
 						),
702 702
 					),
703 703
 				),
704 704
 				'orders_count' => array(
705
-					'description' => __( 'Quantity of orders made by the customer.', 'woocommerce' ),
705
+					'description' => __('Quantity of orders made by the customer.', 'woocommerce'),
706 706
 					'type'        => 'integer',
707
-					'context'     => array( 'view', 'edit' ),
707
+					'context'     => array('view', 'edit'),
708 708
 					'readonly'    => true,
709 709
 				),
710 710
 				'total_spent' => array(
711
-					'description' => __( 'Total amount spent.', 'woocommerce' ),
711
+					'description' => __('Total amount spent.', 'woocommerce'),
712 712
 					'type'        => 'string',
713
-					'context'     => array( 'view', 'edit' ),
713
+					'context'     => array('view', 'edit'),
714 714
 					'readonly'    => true,
715 715
 				),
716 716
 				'avatar_url' => array(
717
-					'description' => __( 'Avatar URL.', 'woocommerce' ),
717
+					'description' => __('Avatar URL.', 'woocommerce'),
718 718
 					'type'        => 'string',
719
-					'context'     => array( 'view', 'edit' ),
719
+					'context'     => array('view', 'edit'),
720 720
 					'readonly'    => true,
721 721
 				),
722 722
 				'billing' => array(
723
-					'description' => __( 'List of billing address data.', 'woocommerce' ),
723
+					'description' => __('List of billing address data.', 'woocommerce'),
724 724
 					'type'        => 'object',
725
-					'context'     => array( 'view', 'edit' ),
725
+					'context'     => array('view', 'edit'),
726 726
 					'properties' => array(
727 727
 						'first_name' => array(
728
-							'description' => __( 'First name.', 'woocommerce' ),
728
+							'description' => __('First name.', 'woocommerce'),
729 729
 							'type'        => 'string',
730
-							'context'     => array( 'view', 'edit' ),
730
+							'context'     => array('view', 'edit'),
731 731
 						),
732 732
 						'last_name' => array(
733
-							'description' => __( 'Last name.', 'woocommerce' ),
733
+							'description' => __('Last name.', 'woocommerce'),
734 734
 							'type'        => 'string',
735
-							'context'     => array( 'view', 'edit' ),
735
+							'context'     => array('view', 'edit'),
736 736
 						),
737 737
 						'company' => array(
738
-							'description' => __( 'Company name.', 'woocommerce' ),
738
+							'description' => __('Company name.', 'woocommerce'),
739 739
 							'type'        => 'string',
740
-							'context'     => array( 'view', 'edit' ),
740
+							'context'     => array('view', 'edit'),
741 741
 						),
742 742
 						'address_1' => array(
743
-							'description' => __( 'Address line 1.', 'woocommerce' ),
743
+							'description' => __('Address line 1.', 'woocommerce'),
744 744
 							'type'        => 'string',
745
-							'context'     => array( 'view', 'edit' ),
745
+							'context'     => array('view', 'edit'),
746 746
 						),
747 747
 						'address_2' => array(
748
-							'description' => __( 'Address line 2.', 'woocommerce' ),
748
+							'description' => __('Address line 2.', 'woocommerce'),
749 749
 							'type'        => 'string',
750
-							'context'     => array( 'view', 'edit' ),
750
+							'context'     => array('view', 'edit'),
751 751
 						),
752 752
 						'city' => array(
753
-							'description' => __( 'City name.', 'woocommerce' ),
753
+							'description' => __('City name.', 'woocommerce'),
754 754
 							'type'        => 'string',
755
-							'context'     => array( 'view', 'edit' ),
755
+							'context'     => array('view', 'edit'),
756 756
 						),
757 757
 						'state' => array(
758
-							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
758
+							'description' => __('ISO code or name of the state, province or district.', 'woocommerce'),
759 759
 							'type'        => 'string',
760
-							'context'     => array( 'view', 'edit' ),
760
+							'context'     => array('view', 'edit'),
761 761
 						),
762 762
 						'postcode' => array(
763
-							'description' => __( 'Postal code.', 'woocommerce' ),
763
+							'description' => __('Postal code.', 'woocommerce'),
764 764
 							'type'        => 'string',
765
-							'context'     => array( 'view', 'edit' ),
765
+							'context'     => array('view', 'edit'),
766 766
 						),
767 767
 						'country' => array(
768
-							'description' => __( 'ISO code of the country.', 'woocommerce' ),
768
+							'description' => __('ISO code of the country.', 'woocommerce'),
769 769
 							'type'        => 'string',
770
-							'context'     => array( 'view', 'edit' ),
770
+							'context'     => array('view', 'edit'),
771 771
 						),
772 772
 						'email' => array(
773
-							'description' => __( 'Email address.', 'woocommerce' ),
773
+							'description' => __('Email address.', 'woocommerce'),
774 774
 							'type'        => 'string',
775 775
 							'format'      => 'email',
776
-							'context'     => array( 'view', 'edit' ),
776
+							'context'     => array('view', 'edit'),
777 777
 						),
778 778
 						'phone' => array(
779
-							'description' => __( 'Phone number.', 'woocommerce' ),
779
+							'description' => __('Phone number.', 'woocommerce'),
780 780
 							'type'        => 'string',
781
-							'context'     => array( 'view', 'edit' ),
781
+							'context'     => array('view', 'edit'),
782 782
 						),
783 783
 					),
784 784
 				),
785 785
 				'shipping' => array(
786
-					'description' => __( 'List of shipping address data.', 'woocommerce' ),
786
+					'description' => __('List of shipping address data.', 'woocommerce'),
787 787
 					'type'        => 'object',
788
-					'context'     => array( 'view', 'edit' ),
788
+					'context'     => array('view', 'edit'),
789 789
 					'properties' => array(
790 790
 						'first_name' => array(
791
-							'description' => __( 'First name.', 'woocommerce' ),
791
+							'description' => __('First name.', 'woocommerce'),
792 792
 							'type'        => 'string',
793
-							'context'     => array( 'view', 'edit' ),
793
+							'context'     => array('view', 'edit'),
794 794
 						),
795 795
 						'last_name' => array(
796
-							'description' => __( 'Last name.', 'woocommerce' ),
796
+							'description' => __('Last name.', 'woocommerce'),
797 797
 							'type'        => 'string',
798
-							'context'     => array( 'view', 'edit' ),
798
+							'context'     => array('view', 'edit'),
799 799
 						),
800 800
 						'company' => array(
801
-							'description' => __( 'Company name.', 'woocommerce' ),
801
+							'description' => __('Company name.', 'woocommerce'),
802 802
 							'type'        => 'string',
803
-							'context'     => array( 'view', 'edit' ),
803
+							'context'     => array('view', 'edit'),
804 804
 						),
805 805
 						'address_1' => array(
806
-							'description' => __( 'Address line 1.', 'woocommerce' ),
806
+							'description' => __('Address line 1.', 'woocommerce'),
807 807
 							'type'        => 'string',
808
-							'context'     => array( 'view', 'edit' ),
808
+							'context'     => array('view', 'edit'),
809 809
 						),
810 810
 						'address_2' => array(
811
-							'description' => __( 'Address line 2.', 'woocommerce' ),
811
+							'description' => __('Address line 2.', 'woocommerce'),
812 812
 							'type'        => 'string',
813
-							'context'     => array( 'view', 'edit' ),
813
+							'context'     => array('view', 'edit'),
814 814
 						),
815 815
 						'city' => array(
816
-							'description' => __( 'City name.', 'woocommerce' ),
816
+							'description' => __('City name.', 'woocommerce'),
817 817
 							'type'        => 'string',
818
-							'context'     => array( 'view', 'edit' ),
818
+							'context'     => array('view', 'edit'),
819 819
 						),
820 820
 						'state' => array(
821
-							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
821
+							'description' => __('ISO code or name of the state, province or district.', 'woocommerce'),
822 822
 							'type'        => 'string',
823
-							'context'     => array( 'view', 'edit' ),
823
+							'context'     => array('view', 'edit'),
824 824
 						),
825 825
 						'postcode' => array(
826
-							'description' => __( 'Postal code.', 'woocommerce' ),
826
+							'description' => __('Postal code.', 'woocommerce'),
827 827
 							'type'        => 'string',
828
-							'context'     => array( 'view', 'edit' ),
828
+							'context'     => array('view', 'edit'),
829 829
 						),
830 830
 						'country' => array(
831
-							'description' => __( 'ISO code of the country.', 'woocommerce' ),
831
+							'description' => __('ISO code of the country.', 'woocommerce'),
832 832
 							'type'        => 'string',
833
-							'context'     => array( 'view', 'edit' ),
833
+							'context'     => array('view', 'edit'),
834 834
 						),
835 835
 					),
836 836
 				),
837 837
 			),
838 838
 		);
839 839
 
840
-		return $this->add_additional_fields_schema( $schema );
840
+		return $this->add_additional_fields_schema($schema);
841 841
 	}
842 842
 
843 843
 	/**
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 	protected function get_role_names() {
849 849
 		global $wp_roles;
850 850
 
851
-		return array_keys( $wp_roles->role_names );
851
+		return array_keys($wp_roles->role_names);
852 852
 	}
853 853
 
854 854
 	/**
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
 		$params['context']['default'] = 'view';
863 863
 
864 864
 		$params['exclude'] = array(
865
-			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
865
+			'description'       => __('Ensure result set excludes specific IDs.', 'woocommerce'),
866 866
 			'type'              => 'array',
867 867
 			'items'             => array(
868 868
 				'type'          => 'integer',
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
 			'sanitize_callback' => 'wp_parse_id_list',
872 872
 		);
873 873
 		$params['include'] = array(
874
-			'description'       => __( 'Limit result set to specific IDs.', 'woocommerce' ),
874
+			'description'       => __('Limit result set to specific IDs.', 'woocommerce'),
875 875
 			'type'              => 'array',
876 876
 			'items'             => array(
877 877
 				'type'          => 'integer',
@@ -880,22 +880,22 @@  discard block
 block discarded – undo
880 880
 			'sanitize_callback' => 'wp_parse_id_list',
881 881
 		);
882 882
 		$params['offset'] = array(
883
-			'description'        => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
883
+			'description'        => __('Offset the result set by a specific number of items.', 'woocommerce'),
884 884
 			'type'               => 'integer',
885 885
 			'sanitize_callback'  => 'absint',
886 886
 			'validate_callback'  => 'rest_validate_request_arg',
887 887
 		);
888 888
 		$params['order'] = array(
889 889
 			'default'            => 'asc',
890
-			'description'        => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
891
-			'enum'               => array( 'asc', 'desc' ),
890
+			'description'        => __('Order sort attribute ascending or descending.', 'woocommerce'),
891
+			'enum'               => array('asc', 'desc'),
892 892
 			'sanitize_callback'  => 'sanitize_key',
893 893
 			'type'               => 'string',
894 894
 			'validate_callback'  => 'rest_validate_request_arg',
895 895
 		);
896 896
 		$params['orderby'] = array(
897 897
 			'default'            => 'name',
898
-			'description'        => __( 'Sort collection by object attribute.', 'woocommerce' ),
898
+			'description'        => __('Sort collection by object attribute.', 'woocommerce'),
899 899
 			'enum'               => array(
900 900
 				'id',
901 901
 				'include',
@@ -907,16 +907,16 @@  discard block
 block discarded – undo
907 907
 			'validate_callback'  => 'rest_validate_request_arg',
908 908
 		);
909 909
 		$params['email'] = array(
910
-			'description'        => __( 'Limit result set to resources with a specific email.', 'woocommerce' ),
910
+			'description'        => __('Limit result set to resources with a specific email.', 'woocommerce'),
911 911
 			'type'               => 'string',
912 912
 			'format'             => 'email',
913 913
 			'validate_callback'  => 'rest_validate_request_arg',
914 914
 		);
915 915
 		$params['role'] = array(
916
-			'description'        => __( 'Limit result set to resources with a specific role.', 'woocommerce' ),
916
+			'description'        => __('Limit result set to resources with a specific role.', 'woocommerce'),
917 917
 			'type'               => 'string',
918 918
 			'default'            => 'customer',
919
-			'enum'               => array_merge( array( 'all' ), $this->get_role_names() ),
919
+			'enum'               => array_merge(array('all'), $this->get_role_names()),
920 920
 			'validate_callback'  => 'rest_validate_request_arg',
921 921
 		);
922 922
 		return $params;
Please login to merge, or discard this patch.
src/Controllers/Version1/class-wc-rest-product-tags-v1-controller.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @since    3.0.0
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * @param WP_REST_Request $request
51 51
 	 * @return WP_REST_Response $response
52 52
 	 */
53
-	public function prepare_item_for_response( $item, $request ) {
53
+	public function prepare_item_for_response($item, $request) {
54 54
 		$data = array(
55 55
 			'id'          => (int) $item->term_id,
56 56
 			'name'        => $item->name,
@@ -59,13 +59,13 @@  discard block
 block discarded – undo
59 59
 			'count'       => (int) $item->count,
60 60
 		);
61 61
 
62
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
63
-		$data    = $this->add_additional_fields_to_object( $data, $request );
64
-		$data    = $this->filter_response_by_context( $data, $context );
62
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
63
+		$data    = $this->add_additional_fields_to_object($data, $request);
64
+		$data    = $this->filter_response_by_context($data, $context);
65 65
 
66
-		$response = rest_ensure_response( $data );
66
+		$response = rest_ensure_response($data);
67 67
 
68
-		$response->add_links( $this->prepare_links( $item, $request ) );
68
+		$response->add_links($this->prepare_links($item, $request));
69 69
 
70 70
 		/**
71 71
 		 * Filter a term item returned from the API.
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 		 * @param object            $item      The original term object.
77 77
 		 * @param WP_REST_Request   $request   Request used to generate the response.
78 78
 		 */
79
-		return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request );
79
+		return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request);
80 80
 	}
81 81
 
82 82
 	/**
@@ -91,44 +91,44 @@  discard block
 block discarded – undo
91 91
 			'type'                 => 'object',
92 92
 			'properties'           => array(
93 93
 				'id' => array(
94
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
94
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
95 95
 					'type'        => 'integer',
96
-					'context'     => array( 'view', 'edit' ),
96
+					'context'     => array('view', 'edit'),
97 97
 					'readonly'    => true,
98 98
 				),
99 99
 				'name' => array(
100
-					'description' => __( 'Tag name.', 'woocommerce' ),
100
+					'description' => __('Tag name.', 'woocommerce'),
101 101
 					'type'        => 'string',
102
-					'context'     => array( 'view', 'edit' ),
102
+					'context'     => array('view', 'edit'),
103 103
 					'arg_options' => array(
104 104
 						'sanitize_callback' => 'sanitize_text_field',
105 105
 					),
106 106
 				),
107 107
 				'slug' => array(
108
-					'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ),
108
+					'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'),
109 109
 					'type'        => 'string',
110
-					'context'     => array( 'view', 'edit' ),
110
+					'context'     => array('view', 'edit'),
111 111
 					'arg_options' => array(
112 112
 						'sanitize_callback' => 'sanitize_title',
113 113
 					),
114 114
 				),
115 115
 				'description' => array(
116
-					'description' => __( 'HTML description of the resource.', 'woocommerce' ),
116
+					'description' => __('HTML description of the resource.', 'woocommerce'),
117 117
 					'type'        => 'string',
118
-					'context'     => array( 'view', 'edit' ),
118
+					'context'     => array('view', 'edit'),
119 119
 					'arg_options' => array(
120 120
 						'sanitize_callback' => 'wp_filter_post_kses',
121 121
 					),
122 122
 				),
123 123
 				'count' => array(
124
-					'description' => __( 'Number of published products for the resource.', 'woocommerce' ),
124
+					'description' => __('Number of published products for the resource.', 'woocommerce'),
125 125
 					'type'        => 'integer',
126
-					'context'     => array( 'view', 'edit' ),
126
+					'context'     => array('view', 'edit'),
127 127
 					'readonly'    => true,
128 128
 				),
129 129
 			),
130 130
 		);
131 131
 
132
-		return $this->add_additional_fields_schema( $schema );
132
+		return $this->add_additional_fields_schema($schema);
133 133
 	}
134 134
 }
Please login to merge, or discard this patch.