Completed
Push — master ( a986bf...ee9494 )
by Mike
104:12 queued 59:10
created
src/Controllers/Version3/class-wc-rest-order-notes-controller.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Order Notes controller class.
@@ -32,24 +32,24 @@  discard block
 block discarded – undo
32 32
 	 * @param WP_REST_Request $request Request object.
33 33
 	 * @return WP_REST_Response $response Response data.
34 34
 	 */
35
-	public function prepare_item_for_response( $note, $request ) {
35
+	public function prepare_item_for_response($note, $request) {
36 36
 		$data = array(
37 37
 			'id'               => (int) $note->comment_ID,
38
-			'author'           => __( 'WooCommerce', 'woocommerce' ) === $note->comment_author ? 'system' : $note->comment_author,
39
-			'date_created'     => wc_rest_prepare_date_response( $note->comment_date ),
40
-			'date_created_gmt' => wc_rest_prepare_date_response( $note->comment_date_gmt ),
38
+			'author'           => __('WooCommerce', 'woocommerce') === $note->comment_author ? 'system' : $note->comment_author,
39
+			'date_created'     => wc_rest_prepare_date_response($note->comment_date),
40
+			'date_created_gmt' => wc_rest_prepare_date_response($note->comment_date_gmt),
41 41
 			'note'             => $note->comment_content,
42
-			'customer_note'    => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ),
42
+			'customer_note'    => (bool) get_comment_meta($note->comment_ID, 'is_customer_note', true),
43 43
 		);
44 44
 
45
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
46
-		$data    = $this->add_additional_fields_to_object( $data, $request );
47
-		$data    = $this->filter_response_by_context( $data, $context );
45
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
46
+		$data    = $this->add_additional_fields_to_object($data, $request);
47
+		$data    = $this->filter_response_by_context($data, $context);
48 48
 
49 49
 		// Wrap the data in a response object.
50
-		$response = rest_ensure_response( $data );
50
+		$response = rest_ensure_response($data);
51 51
 
52
-		$response->add_links( $this->prepare_links( $note ) );
52
+		$response->add_links($this->prepare_links($note));
53 53
 
54 54
 		/**
55 55
 		 * Filter order note object returned from the REST API.
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 		 * @param WP_Comment       $note     Order note object used to create response.
59 59
 		 * @param WP_REST_Request  $request  Request object.
60 60
 		 */
61
-		return apply_filters( 'woocommerce_rest_prepare_order_note', $response, $note, $request );
61
+		return apply_filters('woocommerce_rest_prepare_order_note', $response, $note, $request);
62 62
 	}
63 63
 
64 64
 	/**
@@ -67,27 +67,27 @@  discard block
 block discarded – undo
67 67
 	 * @param WP_REST_Request $request Full details about the request.
68 68
 	 * @return WP_Error|WP_REST_Response
69 69
 	 */
70
-	public function create_item( $request ) {
71
-		if ( ! empty( $request['id'] ) ) {
70
+	public function create_item($request) {
71
+		if ( ! empty($request['id'])) {
72 72
 			/* translators: %s: post type */
73
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) );
73
+			return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400));
74 74
 		}
75 75
 
76
-		$order = wc_get_order( (int) $request['order_id'] );
76
+		$order = wc_get_order((int) $request['order_id']);
77 77
 
78
-		if ( ! $order || $this->post_type !== $order->get_type() ) {
79
-			return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) );
78
+		if ( ! $order || $this->post_type !== $order->get_type()) {
79
+			return new WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404));
80 80
 		}
81 81
 
82 82
 		// Create the note.
83
-		$note_id = $order->add_order_note( $request['note'], $request['customer_note'], $request['added_by_user'] );
83
+		$note_id = $order->add_order_note($request['note'], $request['customer_note'], $request['added_by_user']);
84 84
 
85
-		if ( ! $note_id ) {
86
-			return new WP_Error( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce' ), array( 'status' => 500 ) );
85
+		if ( ! $note_id) {
86
+			return new WP_Error('woocommerce_api_cannot_create_order_note', __('Cannot create order note, please try again.', 'woocommerce'), array('status' => 500));
87 87
 		}
88 88
 
89
-		$note = get_comment( $note_id );
90
-		$this->update_additional_fields_for_object( $note, $request );
89
+		$note = get_comment($note_id);
90
+		$this->update_additional_fields_for_object($note, $request);
91 91
 
92 92
 		/**
93 93
 		 * Fires after a order note is created or updated via the REST API.
@@ -96,13 +96,13 @@  discard block
 block discarded – undo
96 96
 		 * @param WP_REST_Request $request   Request object.
97 97
 		 * @param boolean         $creating  True when creating item, false when updating.
98 98
 		 */
99
-		do_action( 'woocommerce_rest_insert_order_note', $note, $request, true );
99
+		do_action('woocommerce_rest_insert_order_note', $note, $request, true);
100 100
 
101
-		$request->set_param( 'context', 'edit' );
102
-		$response = $this->prepare_item_for_response( $note, $request );
103
-		$response = rest_ensure_response( $response );
104
-		$response->set_status( 201 );
105
-		$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 ) ) );
101
+		$request->set_param('context', 'edit');
102
+		$response = $this->prepare_item_for_response($note, $request);
103
+		$response = rest_ensure_response($response);
104
+		$response->set_status(201);
105
+		$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)));
106 106
 
107 107
 		return $response;
108 108
 	}
@@ -119,49 +119,49 @@  discard block
 block discarded – undo
119 119
 			'type'       => 'object',
120 120
 			'properties' => array(
121 121
 				'id'               => array(
122
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
122
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
123 123
 					'type'        => 'integer',
124
-					'context'     => array( 'view', 'edit' ),
124
+					'context'     => array('view', 'edit'),
125 125
 					'readonly'    => true,
126 126
 				),
127 127
 				'author'           => array(
128
-					'description' => __( 'Order note author.', 'woocommerce' ),
128
+					'description' => __('Order note author.', 'woocommerce'),
129 129
 					'type'        => 'string',
130
-					'context'     => array( 'view', 'edit' ),
130
+					'context'     => array('view', 'edit'),
131 131
 					'readonly'    => true,
132 132
 				),
133 133
 				'date_created'     => array(
134
-					'description' => __( "The date the order note was created, in the site's timezone.", 'woocommerce' ),
134
+					'description' => __("The date the order note was created, in the site's timezone.", 'woocommerce'),
135 135
 					'type'        => 'date-time',
136
-					'context'     => array( 'view', 'edit' ),
136
+					'context'     => array('view', 'edit'),
137 137
 					'readonly'    => true,
138 138
 				),
139 139
 				'date_created_gmt' => array(
140
-					'description' => __( 'The date the order note was created, as GMT.', 'woocommerce' ),
140
+					'description' => __('The date the order note was created, as GMT.', 'woocommerce'),
141 141
 					'type'        => 'date-time',
142
-					'context'     => array( 'view', 'edit' ),
142
+					'context'     => array('view', 'edit'),
143 143
 					'readonly'    => true,
144 144
 				),
145 145
 				'note'             => array(
146
-					'description' => __( 'Order note content.', 'woocommerce' ),
146
+					'description' => __('Order note content.', 'woocommerce'),
147 147
 					'type'        => 'string',
148
-					'context'     => array( 'view', 'edit' ),
148
+					'context'     => array('view', 'edit'),
149 149
 				),
150 150
 				'customer_note'    => array(
151
-					'description' => __( 'If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.', 'woocommerce' ),
151
+					'description' => __('If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.', 'woocommerce'),
152 152
 					'type'        => 'boolean',
153 153
 					'default'     => false,
154
-					'context'     => array( 'view', 'edit' ),
154
+					'context'     => array('view', 'edit'),
155 155
 				),
156 156
 				'added_by_user'    => array(
157
-					'description' => __( 'If true, this note will be attributed to the current user. If false, the note will be attributed to the system.', 'woocommerce' ),
157
+					'description' => __('If true, this note will be attributed to the current user. If false, the note will be attributed to the system.', 'woocommerce'),
158 158
 					'type'        => 'boolean',
159 159
 					'default'     => false,
160
-					'context'     => array( 'edit' ),
160
+					'context'     => array('edit'),
161 161
 				),
162 162
 			),
163 163
 		);
164 164
 
165
-		return $this->add_additional_fields_schema( $schema );
165
+		return $this->add_additional_fields_schema($schema);
166 166
 	}
167 167
 }
Please login to merge, or discard this patch.
Controllers/Version3/class-wc-rest-product-attribute-terms-controller.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Product Attribute Terms controller class.
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-product-variations-controller.php 1 patch
Spacing   +266 added lines, -266 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
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API variations controller class.
@@ -32,29 +32,29 @@  discard block
 block discarded – undo
32 32
 	 * @param  WP_REST_Request $request Request object.
33 33
 	 * @return WP_REST_Response
34 34
 	 */
35
-	public function prepare_object_for_response( $object, $request ) {
35
+	public function prepare_object_for_response($object, $request) {
36 36
 		$data = array(
37 37
 			'id'                    => $object->get_id(),
38
-			'date_created'          => wc_rest_prepare_date_response( $object->get_date_created(), false ),
39
-			'date_created_gmt'      => wc_rest_prepare_date_response( $object->get_date_created() ),
40
-			'date_modified'         => wc_rest_prepare_date_response( $object->get_date_modified(), false ),
41
-			'date_modified_gmt'     => wc_rest_prepare_date_response( $object->get_date_modified() ),
42
-			'description'           => wc_format_content( $object->get_description() ),
38
+			'date_created'          => wc_rest_prepare_date_response($object->get_date_created(), false),
39
+			'date_created_gmt'      => wc_rest_prepare_date_response($object->get_date_created()),
40
+			'date_modified'         => wc_rest_prepare_date_response($object->get_date_modified(), false),
41
+			'date_modified_gmt'     => wc_rest_prepare_date_response($object->get_date_modified()),
42
+			'description'           => wc_format_content($object->get_description()),
43 43
 			'permalink'             => $object->get_permalink(),
44 44
 			'sku'                   => $object->get_sku(),
45 45
 			'price'                 => $object->get_price(),
46 46
 			'regular_price'         => $object->get_regular_price(),
47 47
 			'sale_price'            => $object->get_sale_price(),
48
-			'date_on_sale_from'     => wc_rest_prepare_date_response( $object->get_date_on_sale_from(), false ),
49
-			'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_from() ),
50
-			'date_on_sale_to'       => wc_rest_prepare_date_response( $object->get_date_on_sale_to(), false ),
51
-			'date_on_sale_to_gmt'   => wc_rest_prepare_date_response( $object->get_date_on_sale_to() ),
48
+			'date_on_sale_from'     => wc_rest_prepare_date_response($object->get_date_on_sale_from(), false),
49
+			'date_on_sale_from_gmt' => wc_rest_prepare_date_response($object->get_date_on_sale_from()),
50
+			'date_on_sale_to'       => wc_rest_prepare_date_response($object->get_date_on_sale_to(), false),
51
+			'date_on_sale_to_gmt'   => wc_rest_prepare_date_response($object->get_date_on_sale_to()),
52 52
 			'on_sale'               => $object->is_on_sale(),
53 53
 			'status'                => $object->get_status(),
54 54
 			'purchasable'           => $object->is_purchasable(),
55 55
 			'virtual'               => $object->is_virtual(),
56 56
 			'downloadable'          => $object->is_downloadable(),
57
-			'downloads'             => $this->get_downloads( $object ),
57
+			'downloads'             => $this->get_downloads($object),
58 58
 			'download_limit'        => '' !== $object->get_download_limit() ? (int) $object->get_download_limit() : -1,
59 59
 			'download_expiry'       => '' !== $object->get_download_expiry() ? (int) $object->get_download_expiry() : -1,
60 60
 			'tax_status'            => $object->get_tax_status(),
@@ -73,17 +73,17 @@  discard block
 block discarded – undo
73 73
 			),
74 74
 			'shipping_class'        => $object->get_shipping_class(),
75 75
 			'shipping_class_id'     => $object->get_shipping_class_id(),
76
-			'image'                 => $this->get_image( $object ),
77
-			'attributes'            => $this->get_attributes( $object ),
76
+			'image'                 => $this->get_image($object),
77
+			'attributes'            => $this->get_attributes($object),
78 78
 			'menu_order'            => $object->get_menu_order(),
79 79
 			'meta_data'             => $object->get_meta_data(),
80 80
 		);
81 81
 
82
-		$context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
83
-		$data     = $this->add_additional_fields_to_object( $data, $request );
84
-		$data     = $this->filter_response_by_context( $data, $context );
85
-		$response = rest_ensure_response( $data );
86
-		$response->add_links( $this->prepare_links( $object, $request ) );
82
+		$context  = ! empty($request['context']) ? $request['context'] : 'view';
83
+		$data     = $this->add_additional_fields_to_object($data, $request);
84
+		$data     = $this->filter_response_by_context($data, $context);
85
+		$response = rest_ensure_response($data);
86
+		$response->add_links($this->prepare_links($object, $request));
87 87
 
88 88
 		/**
89 89
 		 * Filter the data for a response.
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		 * @param WC_Data          $object   Object data.
96 96
 		 * @param WP_REST_Request  $request  Request object.
97 97
 		 */
98
-		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
98
+		return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request);
99 99
 	}
100 100
 
101 101
 	/**
@@ -105,136 +105,136 @@  discard block
 block discarded – undo
105 105
 	 * @param  bool            $creating If is creating a new object.
106 106
 	 * @return WP_Error|WC_Data
107 107
 	 */
108
-	protected function prepare_object_for_database( $request, $creating = false ) {
109
-		if ( isset( $request['id'] ) ) {
110
-			$variation = wc_get_product( absint( $request['id'] ) );
108
+	protected function prepare_object_for_database($request, $creating = false) {
109
+		if (isset($request['id'])) {
110
+			$variation = wc_get_product(absint($request['id']));
111 111
 		} else {
112 112
 			$variation = new WC_Product_Variation();
113 113
 		}
114 114
 
115
-		$variation->set_parent_id( absint( $request['product_id'] ) );
115
+		$variation->set_parent_id(absint($request['product_id']));
116 116
 
117 117
 		// Status.
118
-		if ( isset( $request['status'] ) ) {
119
-			$variation->set_status( get_post_status_object( $request['status'] ) ? $request['status'] : 'draft' );
118
+		if (isset($request['status'])) {
119
+			$variation->set_status(get_post_status_object($request['status']) ? $request['status'] : 'draft');
120 120
 		}
121 121
 
122 122
 		// SKU.
123
-		if ( isset( $request['sku'] ) ) {
124
-			$variation->set_sku( wc_clean( $request['sku'] ) );
123
+		if (isset($request['sku'])) {
124
+			$variation->set_sku(wc_clean($request['sku']));
125 125
 		}
126 126
 
127 127
 		// Thumbnail.
128
-		if ( isset( $request['image'] ) ) {
129
-			if ( is_array( $request['image'] ) ) {
130
-				$variation = $this->set_variation_image( $variation, $request['image'] );
128
+		if (isset($request['image'])) {
129
+			if (is_array($request['image'])) {
130
+				$variation = $this->set_variation_image($variation, $request['image']);
131 131
 			} else {
132
-				$variation->set_image_id( '' );
132
+				$variation->set_image_id('');
133 133
 			}
134 134
 		}
135 135
 
136 136
 		// Virtual variation.
137
-		if ( isset( $request['virtual'] ) ) {
138
-			$variation->set_virtual( $request['virtual'] );
137
+		if (isset($request['virtual'])) {
138
+			$variation->set_virtual($request['virtual']);
139 139
 		}
140 140
 
141 141
 		// Downloadable variation.
142
-		if ( isset( $request['downloadable'] ) ) {
143
-			$variation->set_downloadable( $request['downloadable'] );
142
+		if (isset($request['downloadable'])) {
143
+			$variation->set_downloadable($request['downloadable']);
144 144
 		}
145 145
 
146 146
 		// Downloads.
147
-		if ( $variation->get_downloadable() ) {
147
+		if ($variation->get_downloadable()) {
148 148
 			// Downloadable files.
149
-			if ( isset( $request['downloads'] ) && is_array( $request['downloads'] ) ) {
150
-				$variation = $this->save_downloadable_files( $variation, $request['downloads'] );
149
+			if (isset($request['downloads']) && is_array($request['downloads'])) {
150
+				$variation = $this->save_downloadable_files($variation, $request['downloads']);
151 151
 			}
152 152
 
153 153
 			// Download limit.
154
-			if ( isset( $request['download_limit'] ) ) {
155
-				$variation->set_download_limit( $request['download_limit'] );
154
+			if (isset($request['download_limit'])) {
155
+				$variation->set_download_limit($request['download_limit']);
156 156
 			}
157 157
 
158 158
 			// Download expiry.
159
-			if ( isset( $request['download_expiry'] ) ) {
160
-				$variation->set_download_expiry( $request['download_expiry'] );
159
+			if (isset($request['download_expiry'])) {
160
+				$variation->set_download_expiry($request['download_expiry']);
161 161
 			}
162 162
 		}
163 163
 
164 164
 		// Shipping data.
165
-		$variation = $this->save_product_shipping_data( $variation, $request );
165
+		$variation = $this->save_product_shipping_data($variation, $request);
166 166
 
167 167
 		// Stock handling.
168
-		if ( isset( $request['manage_stock'] ) ) {
169
-			$variation->set_manage_stock( $request['manage_stock'] );
168
+		if (isset($request['manage_stock'])) {
169
+			$variation->set_manage_stock($request['manage_stock']);
170 170
 		}
171 171
 
172
-		if ( isset( $request['stock_status'] ) ) {
173
-			$variation->set_stock_status( $request['stock_status'] );
172
+		if (isset($request['stock_status'])) {
173
+			$variation->set_stock_status($request['stock_status']);
174 174
 		}
175 175
 
176
-		if ( isset( $request['backorders'] ) ) {
177
-			$variation->set_backorders( $request['backorders'] );
176
+		if (isset($request['backorders'])) {
177
+			$variation->set_backorders($request['backorders']);
178 178
 		}
179 179
 
180
-		if ( $variation->get_manage_stock() ) {
181
-			if ( isset( $request['stock_quantity'] ) ) {
182
-				$variation->set_stock_quantity( $request['stock_quantity'] );
183
-			} elseif ( isset( $request['inventory_delta'] ) ) {
184
-				$stock_quantity  = wc_stock_amount( $variation->get_stock_quantity() );
185
-				$stock_quantity += wc_stock_amount( $request['inventory_delta'] );
186
-				$variation->set_stock_quantity( $stock_quantity );
180
+		if ($variation->get_manage_stock()) {
181
+			if (isset($request['stock_quantity'])) {
182
+				$variation->set_stock_quantity($request['stock_quantity']);
183
+			} elseif (isset($request['inventory_delta'])) {
184
+				$stock_quantity  = wc_stock_amount($variation->get_stock_quantity());
185
+				$stock_quantity += wc_stock_amount($request['inventory_delta']);
186
+				$variation->set_stock_quantity($stock_quantity);
187 187
 			}
188 188
 		} else {
189
-			$variation->set_backorders( 'no' );
190
-			$variation->set_stock_quantity( '' );
189
+			$variation->set_backorders('no');
190
+			$variation->set_stock_quantity('');
191 191
 		}
192 192
 
193 193
 		// Regular Price.
194
-		if ( isset( $request['regular_price'] ) ) {
195
-			$variation->set_regular_price( $request['regular_price'] );
194
+		if (isset($request['regular_price'])) {
195
+			$variation->set_regular_price($request['regular_price']);
196 196
 		}
197 197
 
198 198
 		// Sale Price.
199
-		if ( isset( $request['sale_price'] ) ) {
200
-			$variation->set_sale_price( $request['sale_price'] );
199
+		if (isset($request['sale_price'])) {
200
+			$variation->set_sale_price($request['sale_price']);
201 201
 		}
202 202
 
203
-		if ( isset( $request['date_on_sale_from'] ) ) {
204
-			$variation->set_date_on_sale_from( $request['date_on_sale_from'] );
203
+		if (isset($request['date_on_sale_from'])) {
204
+			$variation->set_date_on_sale_from($request['date_on_sale_from']);
205 205
 		}
206 206
 
207
-		if ( isset( $request['date_on_sale_from_gmt'] ) ) {
208
-			$variation->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null );
207
+		if (isset($request['date_on_sale_from_gmt'])) {
208
+			$variation->set_date_on_sale_from($request['date_on_sale_from_gmt'] ? strtotime($request['date_on_sale_from_gmt']) : null);
209 209
 		}
210 210
 
211
-		if ( isset( $request['date_on_sale_to'] ) ) {
212
-			$variation->set_date_on_sale_to( $request['date_on_sale_to'] );
211
+		if (isset($request['date_on_sale_to'])) {
212
+			$variation->set_date_on_sale_to($request['date_on_sale_to']);
213 213
 		}
214 214
 
215
-		if ( isset( $request['date_on_sale_to_gmt'] ) ) {
216
-			$variation->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null );
215
+		if (isset($request['date_on_sale_to_gmt'])) {
216
+			$variation->set_date_on_sale_to($request['date_on_sale_to_gmt'] ? strtotime($request['date_on_sale_to_gmt']) : null);
217 217
 		}
218 218
 
219 219
 		// Tax class.
220
-		if ( isset( $request['tax_class'] ) ) {
221
-			$variation->set_tax_class( $request['tax_class'] );
220
+		if (isset($request['tax_class'])) {
221
+			$variation->set_tax_class($request['tax_class']);
222 222
 		}
223 223
 
224 224
 		// Description.
225
-		if ( isset( $request['description'] ) ) {
226
-			$variation->set_description( wp_kses_post( $request['description'] ) );
225
+		if (isset($request['description'])) {
226
+			$variation->set_description(wp_kses_post($request['description']));
227 227
 		}
228 228
 
229 229
 		// Update taxonomies.
230
-		if ( isset( $request['attributes'] ) ) {
230
+		if (isset($request['attributes'])) {
231 231
 			$attributes = array();
232
-			$parent     = wc_get_product( $variation->get_parent_id() );
232
+			$parent     = wc_get_product($variation->get_parent_id());
233 233
 
234
-			if ( ! $parent ) {
234
+			if ( ! $parent) {
235 235
 				return new WP_Error(
236 236
 					// Translators: %d parent ID.
237
-					"woocommerce_rest_{$this->post_type}_invalid_parent", sprintf( __( 'Cannot set attributes due to invalid parent product.', 'woocommerce' ), $variation->get_parent_id() ), array(
237
+					"woocommerce_rest_{$this->post_type}_invalid_parent", sprintf(__('Cannot set attributes due to invalid parent product.', 'woocommerce'), $variation->get_parent_id()), array(
238 238
 						'status' => 404,
239 239
 					)
240 240
 				);
@@ -242,55 +242,55 @@  discard block
 block discarded – undo
242 242
 
243 243
 			$parent_attributes = $parent->get_attributes();
244 244
 
245
-			foreach ( $request['attributes'] as $attribute ) {
245
+			foreach ($request['attributes'] as $attribute) {
246 246
 				$attribute_id   = 0;
247 247
 				$attribute_name = '';
248 248
 
249 249
 				// Check ID for global attributes or name for product attributes.
250
-				if ( ! empty( $attribute['id'] ) ) {
251
-					$attribute_id   = absint( $attribute['id'] );
252
-					$attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id );
253
-				} elseif ( ! empty( $attribute['name'] ) ) {
254
-					$attribute_name = sanitize_title( $attribute['name'] );
250
+				if ( ! empty($attribute['id'])) {
251
+					$attribute_id   = absint($attribute['id']);
252
+					$attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id);
253
+				} elseif ( ! empty($attribute['name'])) {
254
+					$attribute_name = sanitize_title($attribute['name']);
255 255
 				}
256 256
 
257
-				if ( ! $attribute_id && ! $attribute_name ) {
257
+				if ( ! $attribute_id && ! $attribute_name) {
258 258
 					continue;
259 259
 				}
260 260
 
261
-				if ( ! isset( $parent_attributes[ $attribute_name ] ) || ! $parent_attributes[ $attribute_name ]->get_variation() ) {
261
+				if ( ! isset($parent_attributes[$attribute_name]) || ! $parent_attributes[$attribute_name]->get_variation()) {
262 262
 					continue;
263 263
 				}
264 264
 
265
-				$attribute_key   = sanitize_title( $parent_attributes[ $attribute_name ]->get_name() );
266
-				$attribute_value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : '';
265
+				$attribute_key   = sanitize_title($parent_attributes[$attribute_name]->get_name());
266
+				$attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : '';
267 267
 
268
-				if ( $parent_attributes[ $attribute_name ]->is_taxonomy() ) {
268
+				if ($parent_attributes[$attribute_name]->is_taxonomy()) {
269 269
 					// If dealing with a taxonomy, we need to get the slug from the name posted to the API.
270
-					$term = get_term_by( 'name', $attribute_value, $attribute_name );
270
+					$term = get_term_by('name', $attribute_value, $attribute_name);
271 271
 
272
-					if ( $term && ! is_wp_error( $term ) ) {
272
+					if ($term && ! is_wp_error($term)) {
273 273
 						$attribute_value = $term->slug;
274 274
 					} else {
275
-						$attribute_value = sanitize_title( $attribute_value );
275
+						$attribute_value = sanitize_title($attribute_value);
276 276
 					}
277 277
 				}
278 278
 
279
-				$attributes[ $attribute_key ] = $attribute_value;
279
+				$attributes[$attribute_key] = $attribute_value;
280 280
 			}
281 281
 
282
-			$variation->set_attributes( $attributes );
282
+			$variation->set_attributes($attributes);
283 283
 		}
284 284
 
285 285
 		// Menu order.
286
-		if ( $request['menu_order'] ) {
287
-			$variation->set_menu_order( $request['menu_order'] );
286
+		if ($request['menu_order']) {
287
+			$variation->set_menu_order($request['menu_order']);
288 288
 		}
289 289
 
290 290
 		// Meta data.
291
-		if ( is_array( $request['meta_data'] ) ) {
292
-			foreach ( $request['meta_data'] as $meta ) {
293
-				$variation->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
291
+		if (is_array($request['meta_data'])) {
292
+			foreach ($request['meta_data'] as $meta) {
293
+				$variation->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
294 294
 			}
295 295
 		}
296 296
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 		 * @param WP_REST_Request $request   Request object.
305 305
 		 * @param bool            $creating  If is creating a new object.
306 306
 		 */
307
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating );
307
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating);
308 308
 	}
309 309
 
310 310
 	/**
@@ -313,32 +313,32 @@  discard block
 block discarded – undo
313 313
 	 * @param WC_Product_Variation $variation Variation data.
314 314
 	 * @return array
315 315
 	 */
316
-	protected function get_image( $variation ) {
317
-		if ( ! $variation->get_image_id() ) {
316
+	protected function get_image($variation) {
317
+		if ( ! $variation->get_image_id()) {
318 318
 			return;
319 319
 		}
320 320
 
321 321
 		$attachment_id   = $variation->get_image_id();
322
-		$attachment_post = get_post( $attachment_id );
323
-		if ( is_null( $attachment_post ) ) {
322
+		$attachment_post = get_post($attachment_id);
323
+		if (is_null($attachment_post)) {
324 324
 			return;
325 325
 		}
326 326
 
327
-		$attachment = wp_get_attachment_image_src( $attachment_id, 'full' );
328
-		if ( ! is_array( $attachment ) ) {
327
+		$attachment = wp_get_attachment_image_src($attachment_id, 'full');
328
+		if ( ! is_array($attachment)) {
329 329
 			return;
330 330
 		}
331 331
 
332
-		if ( ! isset( $image ) ) {
332
+		if ( ! isset($image)) {
333 333
 			return array(
334 334
 				'id'                => (int) $attachment_id,
335
-				'date_created'      => wc_rest_prepare_date_response( $attachment_post->post_date, false ),
336
-				'date_created_gmt'  => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ),
337
-				'date_modified'     => wc_rest_prepare_date_response( $attachment_post->post_modified, false ),
338
-				'date_modified_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_modified_gmt ) ),
339
-				'src'               => current( $attachment ),
340
-				'name'              => get_the_title( $attachment_id ),
341
-				'alt'               => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
335
+				'date_created'      => wc_rest_prepare_date_response($attachment_post->post_date, false),
336
+				'date_created_gmt'  => wc_rest_prepare_date_response(strtotime($attachment_post->post_date_gmt)),
337
+				'date_modified'     => wc_rest_prepare_date_response($attachment_post->post_modified, false),
338
+				'date_modified_gmt' => wc_rest_prepare_date_response(strtotime($attachment_post->post_modified_gmt)),
339
+				'src'               => current($attachment),
340
+				'name'              => get_the_title($attachment_id),
341
+				'alt'               => get_post_meta($attachment_id, '_wp_attachment_image_alt', true),
342 342
 			);
343 343
 		}
344 344
 	}
@@ -351,35 +351,35 @@  discard block
 block discarded – undo
351 351
 	 * @param  array                $image    Image data.
352 352
 	 * @return WC_Product_Variation
353 353
 	 */
354
-	protected function set_variation_image( $variation, $image ) {
355
-		$attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0;
354
+	protected function set_variation_image($variation, $image) {
355
+		$attachment_id = isset($image['id']) ? absint($image['id']) : 0;
356 356
 
357
-		if ( 0 === $attachment_id && isset( $image['src'] ) ) {
358
-			$upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) );
357
+		if (0 === $attachment_id && isset($image['src'])) {
358
+			$upload = wc_rest_upload_image_from_url(esc_url_raw($image['src']));
359 359
 
360
-			if ( is_wp_error( $upload ) ) {
361
-				if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array( $image ) ) ) {
362
-					throw new WC_REST_Exception( 'woocommerce_variation_image_upload_error', $upload->get_error_message(), 400 );
360
+			if (is_wp_error($upload)) {
361
+				if ( ! apply_filters('woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array($image))) {
362
+					throw new WC_REST_Exception('woocommerce_variation_image_upload_error', $upload->get_error_message(), 400);
363 363
 				}
364 364
 			}
365 365
 
366
-			$attachment_id = wc_rest_set_uploaded_image_as_attachment( $upload, $variation->get_id() );
366
+			$attachment_id = wc_rest_set_uploaded_image_as_attachment($upload, $variation->get_id());
367 367
 		}
368 368
 
369
-		if ( ! wp_attachment_is_image( $attachment_id ) ) {
369
+		if ( ! wp_attachment_is_image($attachment_id)) {
370 370
 			/* translators: %s: attachment ID */
371
-			throw new WC_REST_Exception( 'woocommerce_variation_invalid_image_id', sprintf( __( '#%s is an invalid image ID.', 'woocommerce' ), $attachment_id ), 400 );
371
+			throw new WC_REST_Exception('woocommerce_variation_invalid_image_id', sprintf(__('#%s is an invalid image ID.', 'woocommerce'), $attachment_id), 400);
372 372
 		}
373 373
 
374
-		$variation->set_image_id( $attachment_id );
374
+		$variation->set_image_id($attachment_id);
375 375
 
376 376
 		// Set the image alt if present.
377
-		if ( ! empty( $image['alt'] ) ) {
378
-			update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) );
377
+		if ( ! empty($image['alt'])) {
378
+			update_post_meta($attachment_id, '_wp_attachment_image_alt', wc_clean($image['alt']));
379 379
 		}
380 380
 
381 381
 		// Set the image name if present.
382
-		if ( ! empty( $image['name'] ) ) {
382
+		if ( ! empty($image['name'])) {
383 383
 			wp_update_post(
384 384
 				array(
385 385
 					'ID'         => $attachment_id,
@@ -397,354 +397,354 @@  discard block
 block discarded – undo
397 397
 	 * @return array
398 398
 	 */
399 399
 	public function get_item_schema() {
400
-		$weight_unit    = get_option( 'woocommerce_weight_unit' );
401
-		$dimension_unit = get_option( 'woocommerce_dimension_unit' );
400
+		$weight_unit    = get_option('woocommerce_weight_unit');
401
+		$dimension_unit = get_option('woocommerce_dimension_unit');
402 402
 		$schema         = array(
403 403
 			'$schema'    => 'http://json-schema.org/draft-04/schema#',
404 404
 			'title'      => $this->post_type,
405 405
 			'type'       => 'object',
406 406
 			'properties' => array(
407 407
 				'id'                    => array(
408
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
408
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
409 409
 					'type'        => 'integer',
410
-					'context'     => array( 'view', 'edit' ),
410
+					'context'     => array('view', 'edit'),
411 411
 					'readonly'    => true,
412 412
 				),
413 413
 				'date_created'          => array(
414
-					'description' => __( "The date the variation was created, in the site's timezone.", 'woocommerce' ),
414
+					'description' => __("The date the variation was created, in the site's timezone.", 'woocommerce'),
415 415
 					'type'        => 'date-time',
416
-					'context'     => array( 'view', 'edit' ),
416
+					'context'     => array('view', 'edit'),
417 417
 					'readonly'    => true,
418 418
 				),
419 419
 				'date_modified'         => array(
420
-					'description' => __( "The date the variation was last modified, in the site's timezone.", 'woocommerce' ),
420
+					'description' => __("The date the variation was last modified, in the site's timezone.", 'woocommerce'),
421 421
 					'type'        => 'date-time',
422
-					'context'     => array( 'view', 'edit' ),
422
+					'context'     => array('view', 'edit'),
423 423
 					'readonly'    => true,
424 424
 				),
425 425
 				'description'           => array(
426
-					'description' => __( 'Variation description.', 'woocommerce' ),
426
+					'description' => __('Variation description.', 'woocommerce'),
427 427
 					'type'        => 'string',
428
-					'context'     => array( 'view', 'edit' ),
428
+					'context'     => array('view', 'edit'),
429 429
 				),
430 430
 				'permalink'             => array(
431
-					'description' => __( 'Variation URL.', 'woocommerce' ),
431
+					'description' => __('Variation URL.', 'woocommerce'),
432 432
 					'type'        => 'string',
433 433
 					'format'      => 'uri',
434
-					'context'     => array( 'view', 'edit' ),
434
+					'context'     => array('view', 'edit'),
435 435
 					'readonly'    => true,
436 436
 				),
437 437
 				'sku'                   => array(
438
-					'description' => __( 'Unique identifier.', 'woocommerce' ),
438
+					'description' => __('Unique identifier.', 'woocommerce'),
439 439
 					'type'        => 'string',
440
-					'context'     => array( 'view', 'edit' ),
440
+					'context'     => array('view', 'edit'),
441 441
 				),
442 442
 				'price'                 => array(
443
-					'description' => __( 'Current variation price.', 'woocommerce' ),
443
+					'description' => __('Current variation price.', 'woocommerce'),
444 444
 					'type'        => 'string',
445
-					'context'     => array( 'view', 'edit' ),
445
+					'context'     => array('view', 'edit'),
446 446
 					'readonly'    => true,
447 447
 				),
448 448
 				'regular_price'         => array(
449
-					'description' => __( 'Variation regular price.', 'woocommerce' ),
449
+					'description' => __('Variation regular price.', 'woocommerce'),
450 450
 					'type'        => 'string',
451
-					'context'     => array( 'view', 'edit' ),
451
+					'context'     => array('view', 'edit'),
452 452
 				),
453 453
 				'sale_price'            => array(
454
-					'description' => __( 'Variation sale price.', 'woocommerce' ),
454
+					'description' => __('Variation sale price.', 'woocommerce'),
455 455
 					'type'        => 'string',
456
-					'context'     => array( 'view', 'edit' ),
456
+					'context'     => array('view', 'edit'),
457 457
 				),
458 458
 				'date_on_sale_from'     => array(
459
-					'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ),
459
+					'description' => __("Start date of sale price, in the site's timezone.", 'woocommerce'),
460 460
 					'type'        => 'date-time',
461
-					'context'     => array( 'view', 'edit' ),
461
+					'context'     => array('view', 'edit'),
462 462
 				),
463 463
 				'date_on_sale_from_gmt' => array(
464
-					'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ),
464
+					'description' => __('Start date of sale price, as GMT.', 'woocommerce'),
465 465
 					'type'        => 'date-time',
466
-					'context'     => array( 'view', 'edit' ),
466
+					'context'     => array('view', 'edit'),
467 467
 				),
468 468
 				'date_on_sale_to'       => array(
469
-					'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ),
469
+					'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'),
470 470
 					'type'        => 'date-time',
471
-					'context'     => array( 'view', 'edit' ),
471
+					'context'     => array('view', 'edit'),
472 472
 				),
473 473
 				'date_on_sale_to_gmt'   => array(
474
-					'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ),
474
+					'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'),
475 475
 					'type'        => 'date-time',
476
-					'context'     => array( 'view', 'edit' ),
476
+					'context'     => array('view', 'edit'),
477 477
 				),
478 478
 				'on_sale'               => array(
479
-					'description' => __( 'Shows if the variation is on sale.', 'woocommerce' ),
479
+					'description' => __('Shows if the variation is on sale.', 'woocommerce'),
480 480
 					'type'        => 'boolean',
481
-					'context'     => array( 'view', 'edit' ),
481
+					'context'     => array('view', 'edit'),
482 482
 					'readonly'    => true,
483 483
 				),
484 484
 				'status'                => array(
485
-					'description' => __( 'Variation status.', 'woocommerce' ),
485
+					'description' => __('Variation status.', 'woocommerce'),
486 486
 					'type'        => 'string',
487 487
 					'default'     => 'publish',
488
-					'enum'        => array_keys( get_post_statuses() ),
489
-					'context'     => array( 'view', 'edit' ),
488
+					'enum'        => array_keys(get_post_statuses()),
489
+					'context'     => array('view', 'edit'),
490 490
 				),
491 491
 				'purchasable'           => array(
492
-					'description' => __( 'Shows if the variation can be bought.', 'woocommerce' ),
492
+					'description' => __('Shows if the variation can be bought.', 'woocommerce'),
493 493
 					'type'        => 'boolean',
494
-					'context'     => array( 'view', 'edit' ),
494
+					'context'     => array('view', 'edit'),
495 495
 					'readonly'    => true,
496 496
 				),
497 497
 				'virtual'               => array(
498
-					'description' => __( 'If the variation is virtual.', 'woocommerce' ),
498
+					'description' => __('If the variation is virtual.', 'woocommerce'),
499 499
 					'type'        => 'boolean',
500 500
 					'default'     => false,
501
-					'context'     => array( 'view', 'edit' ),
501
+					'context'     => array('view', 'edit'),
502 502
 				),
503 503
 				'downloadable'          => array(
504
-					'description' => __( 'If the variation is downloadable.', 'woocommerce' ),
504
+					'description' => __('If the variation is downloadable.', 'woocommerce'),
505 505
 					'type'        => 'boolean',
506 506
 					'default'     => false,
507
-					'context'     => array( 'view', 'edit' ),
507
+					'context'     => array('view', 'edit'),
508 508
 				),
509 509
 				'downloads'             => array(
510
-					'description' => __( 'List of downloadable files.', 'woocommerce' ),
510
+					'description' => __('List of downloadable files.', 'woocommerce'),
511 511
 					'type'        => 'array',
512
-					'context'     => array( 'view', 'edit' ),
512
+					'context'     => array('view', 'edit'),
513 513
 					'items'       => array(
514 514
 						'type'       => 'object',
515 515
 						'properties' => array(
516 516
 							'id'   => array(
517
-								'description' => __( 'File ID.', 'woocommerce' ),
517
+								'description' => __('File ID.', 'woocommerce'),
518 518
 								'type'        => 'string',
519
-								'context'     => array( 'view', 'edit' ),
519
+								'context'     => array('view', 'edit'),
520 520
 							),
521 521
 							'name' => array(
522
-								'description' => __( 'File name.', 'woocommerce' ),
522
+								'description' => __('File name.', 'woocommerce'),
523 523
 								'type'        => 'string',
524
-								'context'     => array( 'view', 'edit' ),
524
+								'context'     => array('view', 'edit'),
525 525
 							),
526 526
 							'file' => array(
527
-								'description' => __( 'File URL.', 'woocommerce' ),
527
+								'description' => __('File URL.', 'woocommerce'),
528 528
 								'type'        => 'string',
529
-								'context'     => array( 'view', 'edit' ),
529
+								'context'     => array('view', 'edit'),
530 530
 							),
531 531
 						),
532 532
 					),
533 533
 				),
534 534
 				'download_limit'        => array(
535
-					'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ),
535
+					'description' => __('Number of times downloadable files can be downloaded after purchase.', 'woocommerce'),
536 536
 					'type'        => 'integer',
537 537
 					'default'     => -1,
538
-					'context'     => array( 'view', 'edit' ),
538
+					'context'     => array('view', 'edit'),
539 539
 				),
540 540
 				'download_expiry'       => array(
541
-					'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ),
541
+					'description' => __('Number of days until access to downloadable files expires.', 'woocommerce'),
542 542
 					'type'        => 'integer',
543 543
 					'default'     => -1,
544
-					'context'     => array( 'view', 'edit' ),
544
+					'context'     => array('view', 'edit'),
545 545
 				),
546 546
 				'tax_status'            => array(
547
-					'description' => __( 'Tax status.', 'woocommerce' ),
547
+					'description' => __('Tax status.', 'woocommerce'),
548 548
 					'type'        => 'string',
549 549
 					'default'     => 'taxable',
550
-					'enum'        => array( 'taxable', 'shipping', 'none' ),
551
-					'context'     => array( 'view', 'edit' ),
550
+					'enum'        => array('taxable', 'shipping', 'none'),
551
+					'context'     => array('view', 'edit'),
552 552
 				),
553 553
 				'tax_class'             => array(
554
-					'description' => __( 'Tax class.', 'woocommerce' ),
554
+					'description' => __('Tax class.', 'woocommerce'),
555 555
 					'type'        => 'string',
556
-					'context'     => array( 'view', 'edit' ),
556
+					'context'     => array('view', 'edit'),
557 557
 				),
558 558
 				'manage_stock'          => array(
559
-					'description' => __( 'Stock management at variation level.', 'woocommerce' ),
559
+					'description' => __('Stock management at variation level.', 'woocommerce'),
560 560
 					'type'        => 'boolean',
561 561
 					'default'     => false,
562
-					'context'     => array( 'view', 'edit' ),
562
+					'context'     => array('view', 'edit'),
563 563
 				),
564 564
 				'stock_quantity'        => array(
565
-					'description' => __( 'Stock quantity.', 'woocommerce' ),
565
+					'description' => __('Stock quantity.', 'woocommerce'),
566 566
 					'type'        => 'integer',
567
-					'context'     => array( 'view', 'edit' ),
567
+					'context'     => array('view', 'edit'),
568 568
 				),
569 569
 				'stock_status'          => array(
570
-					'description' => __( 'Controls the stock status of the product.', 'woocommerce' ),
570
+					'description' => __('Controls the stock status of the product.', 'woocommerce'),
571 571
 					'type'        => 'string',
572 572
 					'default'     => 'instock',
573
-					'enum'        => array_keys( wc_get_product_stock_status_options() ),
574
-					'context'     => array( 'view', 'edit' ),
573
+					'enum'        => array_keys(wc_get_product_stock_status_options()),
574
+					'context'     => array('view', 'edit'),
575 575
 				),
576 576
 				'backorders'            => array(
577
-					'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ),
577
+					'description' => __('If managing stock, this controls if backorders are allowed.', 'woocommerce'),
578 578
 					'type'        => 'string',
579 579
 					'default'     => 'no',
580
-					'enum'        => array( 'no', 'notify', 'yes' ),
581
-					'context'     => array( 'view', 'edit' ),
580
+					'enum'        => array('no', 'notify', 'yes'),
581
+					'context'     => array('view', 'edit'),
582 582
 				),
583 583
 				'backorders_allowed'    => array(
584
-					'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ),
584
+					'description' => __('Shows if backorders are allowed.', 'woocommerce'),
585 585
 					'type'        => 'boolean',
586
-					'context'     => array( 'view', 'edit' ),
586
+					'context'     => array('view', 'edit'),
587 587
 					'readonly'    => true,
588 588
 				),
589 589
 				'backordered'           => array(
590
-					'description' => __( 'Shows if the variation is on backordered.', 'woocommerce' ),
590
+					'description' => __('Shows if the variation is on backordered.', 'woocommerce'),
591 591
 					'type'        => 'boolean',
592
-					'context'     => array( 'view', 'edit' ),
592
+					'context'     => array('view', 'edit'),
593 593
 					'readonly'    => true,
594 594
 				),
595 595
 				'weight'                => array(
596 596
 					/* translators: %s: weight unit */
597
-					'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ),
597
+					'description' => sprintf(__('Variation weight (%s).', 'woocommerce'), $weight_unit),
598 598
 					'type'        => 'string',
599
-					'context'     => array( 'view', 'edit' ),
599
+					'context'     => array('view', 'edit'),
600 600
 				),
601 601
 				'dimensions'            => array(
602
-					'description' => __( 'Variation dimensions.', 'woocommerce' ),
602
+					'description' => __('Variation dimensions.', 'woocommerce'),
603 603
 					'type'        => 'object',
604
-					'context'     => array( 'view', 'edit' ),
604
+					'context'     => array('view', 'edit'),
605 605
 					'properties'  => array(
606 606
 						'length' => array(
607 607
 							/* translators: %s: dimension unit */
608
-							'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ),
608
+							'description' => sprintf(__('Variation length (%s).', 'woocommerce'), $dimension_unit),
609 609
 							'type'        => 'string',
610
-							'context'     => array( 'view', 'edit' ),
610
+							'context'     => array('view', 'edit'),
611 611
 						),
612 612
 						'width'  => array(
613 613
 							/* translators: %s: dimension unit */
614
-							'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ),
614
+							'description' => sprintf(__('Variation width (%s).', 'woocommerce'), $dimension_unit),
615 615
 							'type'        => 'string',
616
-							'context'     => array( 'view', 'edit' ),
616
+							'context'     => array('view', 'edit'),
617 617
 						),
618 618
 						'height' => array(
619 619
 							/* translators: %s: dimension unit */
620
-							'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ),
620
+							'description' => sprintf(__('Variation height (%s).', 'woocommerce'), $dimension_unit),
621 621
 							'type'        => 'string',
622
-							'context'     => array( 'view', 'edit' ),
622
+							'context'     => array('view', 'edit'),
623 623
 						),
624 624
 					),
625 625
 				),
626 626
 				'shipping_class'        => array(
627
-					'description' => __( 'Shipping class slug.', 'woocommerce' ),
627
+					'description' => __('Shipping class slug.', 'woocommerce'),
628 628
 					'type'        => 'string',
629
-					'context'     => array( 'view', 'edit' ),
629
+					'context'     => array('view', 'edit'),
630 630
 				),
631 631
 				'shipping_class_id'     => array(
632
-					'description' => __( 'Shipping class ID.', 'woocommerce' ),
632
+					'description' => __('Shipping class ID.', 'woocommerce'),
633 633
 					'type'        => 'string',
634
-					'context'     => array( 'view', 'edit' ),
634
+					'context'     => array('view', 'edit'),
635 635
 					'readonly'    => true,
636 636
 				),
637 637
 				'image'                 => array(
638
-					'description' => __( 'Variation image data.', 'woocommerce' ),
638
+					'description' => __('Variation image data.', 'woocommerce'),
639 639
 					'type'        => 'object',
640
-					'context'     => array( 'view', 'edit' ),
640
+					'context'     => array('view', 'edit'),
641 641
 					'properties'  => array(
642 642
 						'id'                => array(
643
-							'description' => __( 'Image ID.', 'woocommerce' ),
643
+							'description' => __('Image ID.', 'woocommerce'),
644 644
 							'type'        => 'integer',
645
-							'context'     => array( 'view', 'edit' ),
645
+							'context'     => array('view', 'edit'),
646 646
 						),
647 647
 						'date_created'      => array(
648
-							'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ),
648
+							'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'),
649 649
 							'type'        => 'date-time',
650
-							'context'     => array( 'view', 'edit' ),
650
+							'context'     => array('view', 'edit'),
651 651
 							'readonly'    => true,
652 652
 						),
653 653
 						'date_created_gmt'  => array(
654
-							'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ),
654
+							'description' => __('The date the image was created, as GMT.', 'woocommerce'),
655 655
 							'type'        => 'date-time',
656
-							'context'     => array( 'view', 'edit' ),
656
+							'context'     => array('view', 'edit'),
657 657
 							'readonly'    => true,
658 658
 						),
659 659
 						'date_modified'     => array(
660
-							'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ),
660
+							'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'),
661 661
 							'type'        => 'date-time',
662
-							'context'     => array( 'view', 'edit' ),
662
+							'context'     => array('view', 'edit'),
663 663
 							'readonly'    => true,
664 664
 						),
665 665
 						'date_modified_gmt' => array(
666
-							'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ),
666
+							'description' => __('The date the image was last modified, as GMT.', 'woocommerce'),
667 667
 							'type'        => 'date-time',
668
-							'context'     => array( 'view', 'edit' ),
668
+							'context'     => array('view', 'edit'),
669 669
 							'readonly'    => true,
670 670
 						),
671 671
 						'src'               => array(
672
-							'description' => __( 'Image URL.', 'woocommerce' ),
672
+							'description' => __('Image URL.', 'woocommerce'),
673 673
 							'type'        => 'string',
674 674
 							'format'      => 'uri',
675
-							'context'     => array( 'view', 'edit' ),
675
+							'context'     => array('view', 'edit'),
676 676
 						),
677 677
 						'name'              => array(
678
-							'description' => __( 'Image name.', 'woocommerce' ),
678
+							'description' => __('Image name.', 'woocommerce'),
679 679
 							'type'        => 'string',
680
-							'context'     => array( 'view', 'edit' ),
680
+							'context'     => array('view', 'edit'),
681 681
 						),
682 682
 						'alt'               => array(
683
-							'description' => __( 'Image alternative text.', 'woocommerce' ),
683
+							'description' => __('Image alternative text.', 'woocommerce'),
684 684
 							'type'        => 'string',
685
-							'context'     => array( 'view', 'edit' ),
685
+							'context'     => array('view', 'edit'),
686 686
 						),
687 687
 					),
688 688
 				),
689 689
 				'attributes'            => array(
690
-					'description' => __( 'List of attributes.', 'woocommerce' ),
690
+					'description' => __('List of attributes.', 'woocommerce'),
691 691
 					'type'        => 'array',
692
-					'context'     => array( 'view', 'edit' ),
692
+					'context'     => array('view', 'edit'),
693 693
 					'items'       => array(
694 694
 						'type'       => 'object',
695 695
 						'properties' => array(
696 696
 							'id'     => array(
697
-								'description' => __( 'Attribute ID.', 'woocommerce' ),
697
+								'description' => __('Attribute ID.', 'woocommerce'),
698 698
 								'type'        => 'integer',
699
-								'context'     => array( 'view', 'edit' ),
699
+								'context'     => array('view', 'edit'),
700 700
 							),
701 701
 							'name'   => array(
702
-								'description' => __( 'Attribute name.', 'woocommerce' ),
702
+								'description' => __('Attribute name.', 'woocommerce'),
703 703
 								'type'        => 'string',
704
-								'context'     => array( 'view', 'edit' ),
704
+								'context'     => array('view', 'edit'),
705 705
 							),
706 706
 							'option' => array(
707
-								'description' => __( 'Selected attribute term name.', 'woocommerce' ),
707
+								'description' => __('Selected attribute term name.', 'woocommerce'),
708 708
 								'type'        => 'string',
709
-								'context'     => array( 'view', 'edit' ),
709
+								'context'     => array('view', 'edit'),
710 710
 							),
711 711
 						),
712 712
 					),
713 713
 				),
714 714
 				'menu_order'            => array(
715
-					'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ),
715
+					'description' => __('Menu order, used to custom sort products.', 'woocommerce'),
716 716
 					'type'        => 'integer',
717
-					'context'     => array( 'view', 'edit' ),
717
+					'context'     => array('view', 'edit'),
718 718
 				),
719 719
 				'meta_data'             => array(
720
-					'description' => __( 'Meta data.', 'woocommerce' ),
720
+					'description' => __('Meta data.', 'woocommerce'),
721 721
 					'type'        => 'array',
722
-					'context'     => array( 'view', 'edit' ),
722
+					'context'     => array('view', 'edit'),
723 723
 					'items'       => array(
724 724
 						'type'       => 'object',
725 725
 						'properties' => array(
726 726
 							'id'    => array(
727
-								'description' => __( 'Meta ID.', 'woocommerce' ),
727
+								'description' => __('Meta ID.', 'woocommerce'),
728 728
 								'type'        => 'integer',
729
-								'context'     => array( 'view', 'edit' ),
729
+								'context'     => array('view', 'edit'),
730 730
 								'readonly'    => true,
731 731
 							),
732 732
 							'key'   => array(
733
-								'description' => __( 'Meta key.', 'woocommerce' ),
733
+								'description' => __('Meta key.', 'woocommerce'),
734 734
 								'type'        => 'string',
735
-								'context'     => array( 'view', 'edit' ),
735
+								'context'     => array('view', 'edit'),
736 736
 							),
737 737
 							'value' => array(
738
-								'description' => __( 'Meta value.', 'woocommerce' ),
738
+								'description' => __('Meta value.', 'woocommerce'),
739 739
 								'type'        => 'mixed',
740
-								'context'     => array( 'view', 'edit' ),
740
+								'context'     => array('view', 'edit'),
741 741
 							),
742 742
 						),
743 743
 					),
744 744
 				),
745 745
 			),
746 746
 		);
747
-		return $this->add_additional_fields_schema( $schema );
747
+		return $this->add_additional_fields_schema($schema);
748 748
 	}
749 749
 
750 750
 	/**
@@ -754,17 +754,17 @@  discard block
 block discarded – undo
754 754
 	 * @param  WP_REST_Request $request Full details about the request.
755 755
 	 * @return array
756 756
 	 */
757
-	protected function prepare_objects_query( $request ) {
758
-		$args = WC_REST_CRUD_Controller::prepare_objects_query( $request );
757
+	protected function prepare_objects_query($request) {
758
+		$args = WC_REST_CRUD_Controller::prepare_objects_query($request);
759 759
 
760 760
 		// Set post_status.
761 761
 		$args['post_status'] = $request['status'];
762 762
 
763 763
 		// Filter by sku.
764
-		if ( ! empty( $request['sku'] ) ) {
765
-			$skus = explode( ',', $request['sku'] );
764
+		if ( ! empty($request['sku'])) {
765
+			$skus = explode(',', $request['sku']);
766 766
 			// Include the current string as a SKU too.
767
-			if ( 1 < count( $skus ) ) {
767
+			if (1 < count($skus)) {
768 768
 				$skus[] = $request['sku'];
769 769
 			}
770 770
 
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
 		}
780 780
 
781 781
 		// Filter by tax class.
782
-		if ( ! empty( $request['tax_class'] ) ) {
782
+		if ( ! empty($request['tax_class'])) {
783 783
 			$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
784 784
 				$args,
785 785
 				array(
@@ -790,12 +790,12 @@  discard block
 block discarded – undo
790 790
 		}
791 791
 
792 792
 		// Price filter.
793
-		if ( ! empty( $request['min_price'] ) || ! empty( $request['max_price'] ) ) {
794
-			$args['meta_query'] = $this->add_meta_query( $args, wc_get_min_max_price_meta_query( $request ) );  // WPCS: slow query ok.
793
+		if ( ! empty($request['min_price']) || ! empty($request['max_price'])) {
794
+			$args['meta_query'] = $this->add_meta_query($args, wc_get_min_max_price_meta_query($request)); // WPCS: slow query ok.
795 795
 		}
796 796
 
797 797
 		// Filter product based on stock_status.
798
-		if ( ! empty( $request['stock_status'] ) ) {
798
+		if ( ! empty($request['stock_status'])) {
799 799
 			$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
800 800
 				$args,
801 801
 				array(
@@ -806,19 +806,19 @@  discard block
 block discarded – undo
806 806
 		}
807 807
 
808 808
 		// Filter by on sale products.
809
-		if ( is_bool( $request['on_sale'] ) ) {
809
+		if (is_bool($request['on_sale'])) {
810 810
 			$on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in';
811 811
 			$on_sale_ids = wc_get_product_ids_on_sale();
812 812
 
813 813
 			// Use 0 when there's no on sale products to avoid return all products.
814
-			$on_sale_ids = empty( $on_sale_ids ) ? array( 0 ) : $on_sale_ids;
814
+			$on_sale_ids = empty($on_sale_ids) ? array(0) : $on_sale_ids;
815 815
 
816
-			$args[ $on_sale_key ] += $on_sale_ids;
816
+			$args[$on_sale_key] += $on_sale_ids;
817 817
 		}
818 818
 
819 819
 		// Force the post_type argument, since it's not a user input variable.
820
-		if ( ! empty( $request['sku'] ) ) {
821
-			$args['post_type'] = array( 'product', 'product_variation' );
820
+		if ( ! empty($request['sku'])) {
821
+			$args['post_type'] = array('product', 'product_variation');
822 822
 		} else {
823 823
 			$args['post_type'] = $this->post_type;
824 824
 		}
@@ -848,9 +848,9 @@  discard block
 block discarded – undo
848 848
 		);
849 849
 
850 850
 		$params['stock_status'] = array(
851
-			'description'       => __( 'Limit result set to products with specified stock status.', 'woocommerce' ),
851
+			'description'       => __('Limit result set to products with specified stock status.', 'woocommerce'),
852 852
 			'type'              => 'string',
853
-			'enum'              => array_keys( wc_get_product_stock_status_options() ),
853
+			'enum'              => array_keys(wc_get_product_stock_status_options()),
854 854
 			'sanitize_callback' => 'sanitize_text_field',
855 855
 			'validate_callback' => 'rest_validate_request_arg',
856 856
 		);
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-data-controller.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   3.5.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Data controller class.
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 			$this->namespace, '/' . $this->rest_base, array(
43 43
 				array(
44 44
 					'methods'             => WP_REST_Server::READABLE,
45
-					'callback'            => array( $this, 'get_items' ),
46
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
45
+					'callback'            => array($this, 'get_items'),
46
+					'permission_callback' => array($this, 'get_items_permissions_check'),
47 47
 				),
48
-				'schema' => array( $this, 'get_public_item_schema' ),
48
+				'schema' => array($this, 'get_public_item_schema'),
49 49
 			)
50 50
 		);
51 51
 	}
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 	 * @param  WP_REST_Request $request Full details about the request.
57 57
 	 * @return WP_Error|boolean
58 58
 	 */
59
-	public function get_items_permissions_check( $request ) {
60
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
61
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
59
+	public function get_items_permissions_check($request) {
60
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
61
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
62 62
 		}
63 63
 
64 64
 		return true;
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
 	 * @param  WP_REST_Request $request Full details about the request.
71 71
 	 * @return WP_Error|boolean
72 72
 	 */
73
-	public function get_item_permissions_check( $request ) {
74
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
75
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
73
+	public function get_item_permissions_check($request) {
74
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
75
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
76 76
 		}
77 77
 
78 78
 		return true;
@@ -85,29 +85,29 @@  discard block
 block discarded – undo
85 85
 	 * @param  WP_REST_Request $request Request data.
86 86
 	 * @return WP_Error|WP_REST_Response
87 87
 	 */
88
-	public function get_items( $request ) {
88
+	public function get_items($request) {
89 89
 		$data      = array();
90 90
 		$resources = array(
91 91
 			array(
92 92
 				'slug'        => 'continents',
93
-				'description' => __( 'List of supported continents, countries, and states.', 'woocommerce' ),
93
+				'description' => __('List of supported continents, countries, and states.', 'woocommerce'),
94 94
 			),
95 95
 			array(
96 96
 				'slug'        => 'countries',
97
-				'description' => __( 'List of supported states in a given country.', 'woocommerce' ),
97
+				'description' => __('List of supported states in a given country.', 'woocommerce'),
98 98
 			),
99 99
 			array(
100 100
 				'slug'        => 'currencies',
101
-				'description' => __( 'List of supported currencies.', 'woocommerce' ),
101
+				'description' => __('List of supported currencies.', 'woocommerce'),
102 102
 			),
103 103
 		);
104 104
 
105
-		foreach ( $resources as $resource ) {
106
-			$item   = $this->prepare_item_for_response( (object) $resource, $request );
107
-			$data[] = $this->prepare_response_for_collection( $item );
105
+		foreach ($resources as $resource) {
106
+			$item   = $this->prepare_item_for_response((object) $resource, $request);
107
+			$data[] = $this->prepare_response_for_collection($item);
108 108
 		}
109 109
 
110
-		return rest_ensure_response( $data );
110
+		return rest_ensure_response($data);
111 111
 	}
112 112
 
113 113
 	/**
@@ -117,18 +117,18 @@  discard block
 block discarded – undo
117 117
 	 * @param WP_REST_Request $request  Request object.
118 118
 	 * @return WP_REST_Response $response Response data.
119 119
 	 */
120
-	public function prepare_item_for_response( $resource, $request ) {
120
+	public function prepare_item_for_response($resource, $request) {
121 121
 		$data = array(
122 122
 			'slug'        => $resource->slug,
123 123
 			'description' => $resource->description,
124 124
 		);
125 125
 
126
-		$data = $this->add_additional_fields_to_object( $data, $request );
127
-		$data = $this->filter_response_by_context( $data, 'view' );
126
+		$data = $this->add_additional_fields_to_object($data, $request);
127
+		$data = $this->filter_response_by_context($data, 'view');
128 128
 
129 129
 		// Wrap the data in a response object.
130
-		$response = rest_ensure_response( $data );
131
-		$response->add_links( $this->prepare_links( $resource ) );
130
+		$response = rest_ensure_response($data);
131
+		$response->add_links($this->prepare_links($resource));
132 132
 
133 133
 		return $response;
134 134
 	}
@@ -139,13 +139,13 @@  discard block
 block discarded – undo
139 139
 	 * @param object $item Data object.
140 140
 	 * @return array Links for the given country.
141 141
 	 */
142
-	protected function prepare_links( $item ) {
142
+	protected function prepare_links($item) {
143 143
 		$links = array(
144 144
 			'self'       => array(
145
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $item->slug ) ),
145
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $item->slug)),
146 146
 			),
147 147
 			'collection' => array(
148
-				'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
148
+				'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)),
149 149
 			),
150 150
 		);
151 151
 
@@ -165,20 +165,20 @@  discard block
 block discarded – undo
165 165
 			'type'       => 'object',
166 166
 			'properties' => array(
167 167
 				'slug'        => array(
168
-					'description' => __( 'Data resource ID.', 'woocommerce' ),
168
+					'description' => __('Data resource ID.', 'woocommerce'),
169 169
 					'type'        => 'string',
170
-					'context'     => array( 'view' ),
170
+					'context'     => array('view'),
171 171
 					'readonly'    => true,
172 172
 				),
173 173
 				'description' => array(
174
-					'description' => __( 'Data resource description.', 'woocommerce' ),
174
+					'description' => __('Data resource description.', 'woocommerce'),
175 175
 					'type'        => 'string',
176
-					'context'     => array( 'view' ),
176
+					'context'     => array('view'),
177 177
 					'readonly'    => true,
178 178
 				),
179 179
 			),
180 180
 		);
181 181
 
182
-		return $this->add_additional_fields_schema( $schema );
182
+		return $this->add_additional_fields_schema($schema);
183 183
 	}
184 184
 }
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-customers-controller.php 1 patch
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Customers controller class.
@@ -33,16 +33,16 @@  discard block
 block discarded – undo
33 33
 	 * @since  3.0.0
34 34
 	 * @return array
35 35
 	 */
36
-	protected function get_formatted_item_data( $object ) {
36
+	protected function get_formatted_item_data($object) {
37 37
 		$data        = $object->get_data();
38
-		$format_date = array( 'date_created', 'date_modified' );
38
+		$format_date = array('date_created', 'date_modified');
39 39
 
40 40
 		// Format date values.
41
-		foreach ( $format_date as $key ) {
41
+		foreach ($format_date as $key) {
42 42
 			// Date created is stored UTC, date modified is stored WP local time.
43
-			$datetime              = 'date_created' === $key ? get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $data[ $key ]->getTimestamp() ) ) : $data[ $key ];
44
-			$data[ $key ]          = wc_rest_prepare_date_response( $datetime, false );
45
-			$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
43
+			$datetime              = 'date_created' === $key ? get_date_from_gmt(gmdate('Y-m-d H:i:s', $data[$key]->getTimestamp())) : $data[$key];
44
+			$data[$key]          = wc_rest_prepare_date_response($datetime, false);
45
+			$data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime);
46 46
 		}
47 47
 
48 48
 		return array(
@@ -76,225 +76,225 @@  discard block
 block discarded – undo
76 76
 			'type'       => 'object',
77 77
 			'properties' => array(
78 78
 				'id'                 => array(
79
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
79
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
80 80
 					'type'        => 'integer',
81
-					'context'     => array( 'view', 'edit' ),
81
+					'context'     => array('view', 'edit'),
82 82
 					'readonly'    => true,
83 83
 				),
84 84
 				'date_created'       => array(
85
-					'description' => __( "The date the customer was created, in the site's timezone.", 'woocommerce' ),
85
+					'description' => __("The date the customer was created, in the site's timezone.", 'woocommerce'),
86 86
 					'type'        => 'date-time',
87
-					'context'     => array( 'view', 'edit' ),
87
+					'context'     => array('view', 'edit'),
88 88
 					'readonly'    => true,
89 89
 				),
90 90
 				'date_created_gmt'   => array(
91
-					'description' => __( 'The date the customer was created, as GMT.', 'woocommerce' ),
91
+					'description' => __('The date the customer was created, as GMT.', 'woocommerce'),
92 92
 					'type'        => 'date-time',
93
-					'context'     => array( 'view', 'edit' ),
93
+					'context'     => array('view', 'edit'),
94 94
 					'readonly'    => true,
95 95
 				),
96 96
 				'date_modified'      => array(
97
-					'description' => __( "The date the customer was last modified, in the site's timezone.", 'woocommerce' ),
97
+					'description' => __("The date the customer was last modified, in the site's timezone.", 'woocommerce'),
98 98
 					'type'        => 'date-time',
99
-					'context'     => array( 'view', 'edit' ),
99
+					'context'     => array('view', 'edit'),
100 100
 					'readonly'    => true,
101 101
 				),
102 102
 				'date_modified_gmt'  => array(
103
-					'description' => __( 'The date the customer was last modified, as GMT.', 'woocommerce' ),
103
+					'description' => __('The date the customer was last modified, as GMT.', 'woocommerce'),
104 104
 					'type'        => 'date-time',
105
-					'context'     => array( 'view', 'edit' ),
105
+					'context'     => array('view', 'edit'),
106 106
 					'readonly'    => true,
107 107
 				),
108 108
 				'email'              => array(
109
-					'description' => __( 'The email address for the customer.', 'woocommerce' ),
109
+					'description' => __('The email address for the customer.', 'woocommerce'),
110 110
 					'type'        => 'string',
111 111
 					'format'      => 'email',
112
-					'context'     => array( 'view', 'edit' ),
112
+					'context'     => array('view', 'edit'),
113 113
 				),
114 114
 				'first_name'         => array(
115
-					'description' => __( 'Customer first name.', 'woocommerce' ),
115
+					'description' => __('Customer first name.', 'woocommerce'),
116 116
 					'type'        => 'string',
117
-					'context'     => array( 'view', 'edit' ),
117
+					'context'     => array('view', 'edit'),
118 118
 					'arg_options' => array(
119 119
 						'sanitize_callback' => 'sanitize_text_field',
120 120
 					),
121 121
 				),
122 122
 				'last_name'          => array(
123
-					'description' => __( 'Customer last name.', 'woocommerce' ),
123
+					'description' => __('Customer last name.', 'woocommerce'),
124 124
 					'type'        => 'string',
125
-					'context'     => array( 'view', 'edit' ),
125
+					'context'     => array('view', 'edit'),
126 126
 					'arg_options' => array(
127 127
 						'sanitize_callback' => 'sanitize_text_field',
128 128
 					),
129 129
 				),
130 130
 				'role'               => array(
131
-					'description' => __( 'Customer role.', 'woocommerce' ),
131
+					'description' => __('Customer role.', 'woocommerce'),
132 132
 					'type'        => 'string',
133
-					'context'     => array( 'view', 'edit' ),
133
+					'context'     => array('view', 'edit'),
134 134
 					'readonly'    => true,
135 135
 				),
136 136
 				'username'           => array(
137
-					'description' => __( 'Customer login name.', 'woocommerce' ),
137
+					'description' => __('Customer login name.', 'woocommerce'),
138 138
 					'type'        => 'string',
139
-					'context'     => array( 'view', 'edit' ),
139
+					'context'     => array('view', 'edit'),
140 140
 					'arg_options' => array(
141 141
 						'sanitize_callback' => 'sanitize_user',
142 142
 					),
143 143
 				),
144 144
 				'password'           => array(
145
-					'description' => __( 'Customer password.', 'woocommerce' ),
145
+					'description' => __('Customer password.', 'woocommerce'),
146 146
 					'type'        => 'string',
147
-					'context'     => array( 'edit' ),
147
+					'context'     => array('edit'),
148 148
 				),
149 149
 				'billing'            => array(
150
-					'description' => __( 'List of billing address data.', 'woocommerce' ),
150
+					'description' => __('List of billing address data.', 'woocommerce'),
151 151
 					'type'        => 'object',
152
-					'context'     => array( 'view', 'edit' ),
152
+					'context'     => array('view', 'edit'),
153 153
 					'properties'  => array(
154 154
 						'first_name' => array(
155
-							'description' => __( 'First name.', 'woocommerce' ),
155
+							'description' => __('First name.', 'woocommerce'),
156 156
 							'type'        => 'string',
157
-							'context'     => array( 'view', 'edit' ),
157
+							'context'     => array('view', 'edit'),
158 158
 						),
159 159
 						'last_name'  => array(
160
-							'description' => __( 'Last name.', 'woocommerce' ),
160
+							'description' => __('Last name.', 'woocommerce'),
161 161
 							'type'        => 'string',
162
-							'context'     => array( 'view', 'edit' ),
162
+							'context'     => array('view', 'edit'),
163 163
 						),
164 164
 						'company'    => array(
165
-							'description' => __( 'Company name.', 'woocommerce' ),
165
+							'description' => __('Company name.', 'woocommerce'),
166 166
 							'type'        => 'string',
167
-							'context'     => array( 'view', 'edit' ),
167
+							'context'     => array('view', 'edit'),
168 168
 						),
169 169
 						'address_1'  => array(
170
-							'description' => __( 'Address line 1', 'woocommerce' ),
170
+							'description' => __('Address line 1', 'woocommerce'),
171 171
 							'type'        => 'string',
172
-							'context'     => array( 'view', 'edit' ),
172
+							'context'     => array('view', 'edit'),
173 173
 						),
174 174
 						'address_2'  => array(
175
-							'description' => __( 'Address line 2', 'woocommerce' ),
175
+							'description' => __('Address line 2', 'woocommerce'),
176 176
 							'type'        => 'string',
177
-							'context'     => array( 'view', 'edit' ),
177
+							'context'     => array('view', 'edit'),
178 178
 						),
179 179
 						'city'       => array(
180
-							'description' => __( 'City name.', 'woocommerce' ),
180
+							'description' => __('City name.', 'woocommerce'),
181 181
 							'type'        => 'string',
182
-							'context'     => array( 'view', 'edit' ),
182
+							'context'     => array('view', 'edit'),
183 183
 						),
184 184
 						'state'      => array(
185
-							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
185
+							'description' => __('ISO code or name of the state, province or district.', 'woocommerce'),
186 186
 							'type'        => 'string',
187
-							'context'     => array( 'view', 'edit' ),
187
+							'context'     => array('view', 'edit'),
188 188
 						),
189 189
 						'postcode'   => array(
190
-							'description' => __( 'Postal code.', 'woocommerce' ),
190
+							'description' => __('Postal code.', 'woocommerce'),
191 191
 							'type'        => 'string',
192
-							'context'     => array( 'view', 'edit' ),
192
+							'context'     => array('view', 'edit'),
193 193
 						),
194 194
 						'country'    => array(
195
-							'description' => __( 'ISO code of the country.', 'woocommerce' ),
195
+							'description' => __('ISO code of the country.', 'woocommerce'),
196 196
 							'type'        => 'string',
197
-							'context'     => array( 'view', 'edit' ),
197
+							'context'     => array('view', 'edit'),
198 198
 						),
199 199
 						'email'      => array(
200
-							'description' => __( 'Email address.', 'woocommerce' ),
200
+							'description' => __('Email address.', 'woocommerce'),
201 201
 							'type'        => 'string',
202 202
 							'format'      => 'email',
203
-							'context'     => array( 'view', 'edit' ),
203
+							'context'     => array('view', 'edit'),
204 204
 						),
205 205
 						'phone'      => array(
206
-							'description' => __( 'Phone number.', 'woocommerce' ),
206
+							'description' => __('Phone number.', 'woocommerce'),
207 207
 							'type'        => 'string',
208
-							'context'     => array( 'view', 'edit' ),
208
+							'context'     => array('view', 'edit'),
209 209
 						),
210 210
 					),
211 211
 				),
212 212
 				'shipping'           => array(
213
-					'description' => __( 'List of shipping address data.', 'woocommerce' ),
213
+					'description' => __('List of shipping address data.', 'woocommerce'),
214 214
 					'type'        => 'object',
215
-					'context'     => array( 'view', 'edit' ),
215
+					'context'     => array('view', 'edit'),
216 216
 					'properties'  => array(
217 217
 						'first_name' => array(
218
-							'description' => __( 'First name.', 'woocommerce' ),
218
+							'description' => __('First name.', 'woocommerce'),
219 219
 							'type'        => 'string',
220
-							'context'     => array( 'view', 'edit' ),
220
+							'context'     => array('view', 'edit'),
221 221
 						),
222 222
 						'last_name'  => array(
223
-							'description' => __( 'Last name.', 'woocommerce' ),
223
+							'description' => __('Last name.', 'woocommerce'),
224 224
 							'type'        => 'string',
225
-							'context'     => array( 'view', 'edit' ),
225
+							'context'     => array('view', 'edit'),
226 226
 						),
227 227
 						'company'    => array(
228
-							'description' => __( 'Company name.', 'woocommerce' ),
228
+							'description' => __('Company name.', 'woocommerce'),
229 229
 							'type'        => 'string',
230
-							'context'     => array( 'view', 'edit' ),
230
+							'context'     => array('view', 'edit'),
231 231
 						),
232 232
 						'address_1'  => array(
233
-							'description' => __( 'Address line 1', 'woocommerce' ),
233
+							'description' => __('Address line 1', 'woocommerce'),
234 234
 							'type'        => 'string',
235
-							'context'     => array( 'view', 'edit' ),
235
+							'context'     => array('view', 'edit'),
236 236
 						),
237 237
 						'address_2'  => array(
238
-							'description' => __( 'Address line 2', 'woocommerce' ),
238
+							'description' => __('Address line 2', 'woocommerce'),
239 239
 							'type'        => 'string',
240
-							'context'     => array( 'view', 'edit' ),
240
+							'context'     => array('view', 'edit'),
241 241
 						),
242 242
 						'city'       => array(
243
-							'description' => __( 'City name.', 'woocommerce' ),
243
+							'description' => __('City name.', 'woocommerce'),
244 244
 							'type'        => 'string',
245
-							'context'     => array( 'view', 'edit' ),
245
+							'context'     => array('view', 'edit'),
246 246
 						),
247 247
 						'state'      => array(
248
-							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
248
+							'description' => __('ISO code or name of the state, province or district.', 'woocommerce'),
249 249
 							'type'        => 'string',
250
-							'context'     => array( 'view', 'edit' ),
250
+							'context'     => array('view', 'edit'),
251 251
 						),
252 252
 						'postcode'   => array(
253
-							'description' => __( 'Postal code.', 'woocommerce' ),
253
+							'description' => __('Postal code.', 'woocommerce'),
254 254
 							'type'        => 'string',
255
-							'context'     => array( 'view', 'edit' ),
255
+							'context'     => array('view', 'edit'),
256 256
 						),
257 257
 						'country'    => array(
258
-							'description' => __( 'ISO code of the country.', 'woocommerce' ),
258
+							'description' => __('ISO code of the country.', 'woocommerce'),
259 259
 							'type'        => 'string',
260
-							'context'     => array( 'view', 'edit' ),
260
+							'context'     => array('view', 'edit'),
261 261
 						),
262 262
 					),
263 263
 				),
264 264
 				'is_paying_customer' => array(
265
-					'description' => __( 'Is the customer a paying customer?', 'woocommerce' ),
265
+					'description' => __('Is the customer a paying customer?', 'woocommerce'),
266 266
 					'type'        => 'bool',
267
-					'context'     => array( 'view', 'edit' ),
267
+					'context'     => array('view', 'edit'),
268 268
 					'readonly'    => true,
269 269
 				),
270 270
 				'avatar_url'         => array(
271
-					'description' => __( 'Avatar URL.', 'woocommerce' ),
271
+					'description' => __('Avatar URL.', 'woocommerce'),
272 272
 					'type'        => 'string',
273
-					'context'     => array( 'view', 'edit' ),
273
+					'context'     => array('view', 'edit'),
274 274
 					'readonly'    => true,
275 275
 				),
276 276
 				'meta_data'          => array(
277
-					'description' => __( 'Meta data.', 'woocommerce' ),
277
+					'description' => __('Meta data.', 'woocommerce'),
278 278
 					'type'        => 'array',
279
-					'context'     => array( 'view', 'edit' ),
279
+					'context'     => array('view', 'edit'),
280 280
 					'items'       => array(
281 281
 						'type'       => 'object',
282 282
 						'properties' => array(
283 283
 							'id'    => array(
284
-								'description' => __( 'Meta ID.', 'woocommerce' ),
284
+								'description' => __('Meta ID.', 'woocommerce'),
285 285
 								'type'        => 'integer',
286
-								'context'     => array( 'view', 'edit' ),
286
+								'context'     => array('view', 'edit'),
287 287
 								'readonly'    => true,
288 288
 							),
289 289
 							'key'   => array(
290
-								'description' => __( 'Meta key.', 'woocommerce' ),
290
+								'description' => __('Meta key.', 'woocommerce'),
291 291
 								'type'        => 'string',
292
-								'context'     => array( 'view', 'edit' ),
292
+								'context'     => array('view', 'edit'),
293 293
 							),
294 294
 							'value' => array(
295
-								'description' => __( 'Meta value.', 'woocommerce' ),
295
+								'description' => __('Meta value.', 'woocommerce'),
296 296
 								'type'        => 'mixed',
297
-								'context'     => array( 'view', 'edit' ),
297
+								'context'     => array('view', 'edit'),
298 298
 							),
299 299
 						),
300 300
 					),
@@ -302,6 +302,6 @@  discard block
 block discarded – undo
302 302
 			),
303 303
 		);
304 304
 
305
-		return $this->add_additional_fields_schema( $schema );
305
+		return $this->add_additional_fields_schema($schema);
306 306
 	}
307 307
 }
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-crud-controller.php 1 patch
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @version  3.0.0
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if ( ! defined('ABSPATH')) {
11 11
 	exit;
12 12
 }
13 13
 
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
 	 * @param  int $id Object ID.
39 39
 	 * @return object WC_Data object or WP_Error object.
40 40
 	 */
41
-	protected function get_object( $id ) {
41
+	protected function get_object($id) {
42 42
 		// translators: %s: Class method name.
43
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
43
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce'), __METHOD__), array('status' => 405));
44 44
 	}
45 45
 
46 46
 	/**
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
 	 * @param  WP_REST_Request $request Full details about the request.
50 50
 	 * @return WP_Error|boolean
51 51
 	 */
52
-	public function get_item_permissions_check( $request ) {
53
-		$object = $this->get_object( (int) $request['id'] );
52
+	public function get_item_permissions_check($request) {
53
+		$object = $this->get_object((int) $request['id']);
54 54
 
55
-		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'read', $object->get_id() ) ) {
56
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
55
+		if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'read', $object->get_id())) {
56
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
57 57
 		}
58 58
 
59 59
 		return true;
@@ -65,11 +65,11 @@  discard block
 block discarded – undo
65 65
 	 * @param  WP_REST_Request $request Full details about the request.
66 66
 	 * @return WP_Error|boolean
67 67
 	 */
68
-	public function update_item_permissions_check( $request ) {
69
-		$object = $this->get_object( (int) $request['id'] );
68
+	public function update_item_permissions_check($request) {
69
+		$object = $this->get_object((int) $request['id']);
70 70
 
71
-		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) {
72
-			return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
71
+		if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'edit', $object->get_id())) {
72
+			return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
73 73
 		}
74 74
 
75 75
 		return true;
@@ -81,11 +81,11 @@  discard block
 block discarded – undo
81 81
 	 * @param  WP_REST_Request $request Full details about the request.
82 82
 	 * @return bool|WP_Error
83 83
 	 */
84
-	public function delete_item_permissions_check( $request ) {
85
-		$object = $this->get_object( (int) $request['id'] );
84
+	public function delete_item_permissions_check($request) {
85
+		$object = $this->get_object((int) $request['id']);
86 86
 
87
-		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
88
-			return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
87
+		if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) {
88
+			return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
89 89
 		}
90 90
 
91 91
 		return true;
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 * @param  object $object Object.
98 98
 	 * @return string
99 99
 	 */
100
-	protected function get_permalink( $object ) {
100
+	protected function get_permalink($object) {
101 101
 		return '';
102 102
 	}
103 103
 
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
 	 * @param  WP_REST_Request $request Request object.
110 110
 	 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
111 111
 	 */
112
-	protected function prepare_object_for_response( $object, $request ) {
112
+	protected function prepare_object_for_response($object, $request) {
113 113
 		// translators: %s: Class method name.
114
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
114
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce'), __METHOD__), array('status' => 405));
115 115
 	}
116 116
 
117 117
 	/**
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
 	 * @param  bool            $creating If is creating a new object.
123 123
 	 * @return WP_Error|WC_Data The prepared item, or WP_Error object on failure.
124 124
 	 */
125
-	protected function prepare_object_for_database( $request, $creating = false ) {
125
+	protected function prepare_object_for_database($request, $creating = false) {
126 126
 		// translators: %s: Class method name.
127
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
127
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce'), __METHOD__), array('status' => 405));
128 128
 	}
129 129
 
130 130
 	/**
@@ -133,18 +133,18 @@  discard block
 block discarded – undo
133 133
 	 * @param WP_REST_Request $request Full details about the request.
134 134
 	 * @return WP_Error|WP_REST_Response
135 135
 	 */
136
-	public function get_item( $request ) {
137
-		$object = $this->get_object( (int) $request['id'] );
136
+	public function get_item($request) {
137
+		$object = $this->get_object((int) $request['id']);
138 138
 
139
-		if ( ! $object || 0 === $object->get_id() ) {
140
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
139
+		if ( ! $object || 0 === $object->get_id()) {
140
+			return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
141 141
 		}
142 142
 
143
-		$data     = $this->prepare_object_for_response( $object, $request );
144
-		$response = rest_ensure_response( $data );
143
+		$data     = $this->prepare_object_for_response($object, $request);
144
+		$response = rest_ensure_response($data);
145 145
 
146
-		if ( $this->public ) {
147
-			$response->link_header( 'alternate', $this->get_permalink( $object ), array( 'type' => 'text/html' ) );
146
+		if ($this->public) {
147
+			$response->link_header('alternate', $this->get_permalink($object), array('type' => 'text/html'));
148 148
 		}
149 149
 
150 150
 		return $response;
@@ -158,21 +158,21 @@  discard block
 block discarded – undo
158 158
 	 * @param  bool            $creating If is creating a new object.
159 159
 	 * @return WC_Data|WP_Error
160 160
 	 */
161
-	protected function save_object( $request, $creating = false ) {
161
+	protected function save_object($request, $creating = false) {
162 162
 		try {
163
-			$object = $this->prepare_object_for_database( $request, $creating );
163
+			$object = $this->prepare_object_for_database($request, $creating);
164 164
 
165
-			if ( is_wp_error( $object ) ) {
165
+			if (is_wp_error($object)) {
166 166
 				return $object;
167 167
 			}
168 168
 
169 169
 			$object->save();
170 170
 
171
-			return $this->get_object( $object->get_id() );
172
-		} catch ( WC_Data_Exception $e ) {
173
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
174
-		} catch ( WC_REST_Exception $e ) {
175
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
171
+			return $this->get_object($object->get_id());
172
+		} catch (WC_Data_Exception $e) {
173
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData());
174
+		} catch (WC_REST_Exception $e) {
175
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
176 176
 		}
177 177
 	}
178 178
 
@@ -182,26 +182,26 @@  discard block
 block discarded – undo
182 182
 	 * @param WP_REST_Request $request Full details about the request.
183 183
 	 * @return WP_Error|WP_REST_Response
184 184
 	 */
185
-	public function create_item( $request ) {
186
-		if ( ! empty( $request['id'] ) ) {
185
+	public function create_item($request) {
186
+		if ( ! empty($request['id'])) {
187 187
 			/* translators: %s: post type */
188
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) );
188
+			return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400));
189 189
 		}
190 190
 
191
-		$object = $this->save_object( $request, true );
191
+		$object = $this->save_object($request, true);
192 192
 
193
-		if ( is_wp_error( $object ) ) {
193
+		if (is_wp_error($object)) {
194 194
 			return $object;
195 195
 		}
196 196
 
197 197
 		try {
198
-			$this->update_additional_fields_for_object( $object, $request );
199
-		} catch ( WC_Data_Exception $e ) {
198
+			$this->update_additional_fields_for_object($object, $request);
199
+		} catch (WC_Data_Exception $e) {
200 200
 			$object->delete();
201
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
202
-		} catch ( WC_REST_Exception $e ) {
201
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData());
202
+		} catch (WC_REST_Exception $e) {
203 203
 			$object->delete();
204
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
204
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
205 205
 		}
206 206
 
207 207
 		/**
@@ -211,13 +211,13 @@  discard block
 block discarded – undo
211 211
 		 * @param WP_REST_Request $request   Request object.
212 212
 		 * @param boolean         $creating  True when creating object, false when updating.
213 213
 		 */
214
-		do_action( "woocommerce_rest_insert_{$this->post_type}_object", $object, $request, true );
214
+		do_action("woocommerce_rest_insert_{$this->post_type}_object", $object, $request, true);
215 215
 
216
-		$request->set_param( 'context', 'edit' );
217
-		$response = $this->prepare_object_for_response( $object, $request );
218
-		$response = rest_ensure_response( $response );
219
-		$response->set_status( 201 );
220
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ) );
216
+		$request->set_param('context', 'edit');
217
+		$response = $this->prepare_object_for_response($object, $request);
218
+		$response = rest_ensure_response($response);
219
+		$response->set_status(201);
220
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())));
221 221
 
222 222
 		return $response;
223 223
 	}
@@ -228,25 +228,25 @@  discard block
 block discarded – undo
228 228
 	 * @param WP_REST_Request $request Full details about the request.
229 229
 	 * @return WP_Error|WP_REST_Response
230 230
 	 */
231
-	public function update_item( $request ) {
232
-		$object = $this->get_object( (int) $request['id'] );
231
+	public function update_item($request) {
232
+		$object = $this->get_object((int) $request['id']);
233 233
 
234
-		if ( ! $object || 0 === $object->get_id() ) {
235
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 400 ) );
234
+		if ( ! $object || 0 === $object->get_id()) {
235
+			return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 400));
236 236
 		}
237 237
 
238
-		$object = $this->save_object( $request, false );
238
+		$object = $this->save_object($request, false);
239 239
 
240
-		if ( is_wp_error( $object ) ) {
240
+		if (is_wp_error($object)) {
241 241
 			return $object;
242 242
 		}
243 243
 
244 244
 		try {
245
-			$this->update_additional_fields_for_object( $object, $request );
246
-		} catch ( WC_Data_Exception $e ) {
247
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
248
-		} catch ( WC_REST_Exception $e ) {
249
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
245
+			$this->update_additional_fields_for_object($object, $request);
246
+		} catch (WC_Data_Exception $e) {
247
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData());
248
+		} catch (WC_REST_Exception $e) {
249
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
250 250
 		}
251 251
 
252 252
 		/**
@@ -256,11 +256,11 @@  discard block
 block discarded – undo
256 256
 		 * @param WP_REST_Request $request   Request object.
257 257
 		 * @param boolean         $creating  True when creating object, false when updating.
258 258
 		 */
259
-		do_action( "woocommerce_rest_insert_{$this->post_type}_object", $object, $request, false );
259
+		do_action("woocommerce_rest_insert_{$this->post_type}_object", $object, $request, false);
260 260
 
261
-		$request->set_param( 'context', 'edit' );
262
-		$response = $this->prepare_object_for_response( $object, $request );
263
-		return rest_ensure_response( $response );
261
+		$request->set_param('context', 'edit');
262
+		$response = $this->prepare_object_for_response($object, $request);
263
+		return rest_ensure_response($response);
264 264
 	}
265 265
 
266 266
 	/**
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	 * @param  WP_REST_Request $request Full details about the request.
271 271
 	 * @return array
272 272
 	 */
273
-	protected function prepare_objects_query( $request ) {
273
+	protected function prepare_objects_query($request) {
274 274
 		$args                        = array();
275 275
 		$args['offset']              = $request['offset'];
276 276
 		$args['order']               = $request['order'];
@@ -284,18 +284,18 @@  discard block
 block discarded – undo
284 284
 		$args['post_parent__not_in'] = $request['parent_exclude'];
285 285
 		$args['s']                   = $request['search'];
286 286
 
287
-		if ( 'date' === $args['orderby'] ) {
287
+		if ('date' === $args['orderby']) {
288 288
 			$args['orderby'] = 'date ID';
289 289
 		}
290 290
 
291 291
 		$args['date_query'] = array();
292 292
 		// Set before into date query. Date query must be specified as an array of an array.
293
-		if ( isset( $request['before'] ) ) {
293
+		if (isset($request['before'])) {
294 294
 			$args['date_query'][0]['before'] = $request['before'];
295 295
 		}
296 296
 
297 297
 		// Set after into date query. Date query must be specified as an array of an array.
298
-		if ( isset( $request['after'] ) ) {
298
+		if (isset($request['after'])) {
299 299
 			$args['date_query'][0]['after'] = $request['after'];
300 300
 		}
301 301
 
@@ -311,9 +311,9 @@  discard block
 block discarded – undo
311 311
 		 * @param array           $args    Key value array of query var to query value.
312 312
 		 * @param WP_REST_Request $request The request used.
313 313
 		 */
314
-		$args = apply_filters( "woocommerce_rest_{$this->post_type}_object_query", $args, $request );
314
+		$args = apply_filters("woocommerce_rest_{$this->post_type}_object_query", $args, $request);
315 315
 
316
-		return $this->prepare_items_query( $args, $request );
316
+		return $this->prepare_items_query($args, $request);
317 317
 	}
318 318
 
319 319
 	/**
@@ -323,23 +323,23 @@  discard block
 block discarded – undo
323 323
 	 * @param  array $query_args Query args.
324 324
 	 * @return array
325 325
 	 */
326
-	protected function get_objects( $query_args ) {
326
+	protected function get_objects($query_args) {
327 327
 		$query  = new WP_Query();
328
-		$result = $query->query( $query_args );
328
+		$result = $query->query($query_args);
329 329
 
330 330
 		$total_posts = $query->found_posts;
331
-		if ( $total_posts < 1 ) {
331
+		if ($total_posts < 1) {
332 332
 			// Out-of-bounds, run the query again without LIMIT for total count.
333
-			unset( $query_args['paged'] );
333
+			unset($query_args['paged']);
334 334
 			$count_query = new WP_Query();
335
-			$count_query->query( $query_args );
335
+			$count_query->query($query_args);
336 336
 			$total_posts = $count_query->found_posts;
337 337
 		}
338 338
 
339 339
 		return array(
340
-			'objects' => array_map( array( $this, 'get_object' ), $result ),
340
+			'objects' => array_map(array($this, 'get_object'), $result),
341 341
 			'total'   => (int) $total_posts,
342
-			'pages'   => (int) ceil( $total_posts / (int) $query->query_vars['posts_per_page'] ),
342
+			'pages'   => (int) ceil($total_posts / (int) $query->query_vars['posts_per_page']),
343 343
 		);
344 344
 	}
345 345
 
@@ -349,55 +349,55 @@  discard block
 block discarded – undo
349 349
 	 * @param WP_REST_Request $request Full details about the request.
350 350
 	 * @return WP_Error|WP_REST_Response
351 351
 	 */
352
-	public function get_items( $request ) {
353
-		$query_args    = $this->prepare_objects_query( $request );
354
-		$query_results = $this->get_objects( $query_args );
352
+	public function get_items($request) {
353
+		$query_args    = $this->prepare_objects_query($request);
354
+		$query_results = $this->get_objects($query_args);
355 355
 
356 356
 		$objects = array();
357
-		foreach ( $query_results['objects'] as $object ) {
358
-			if ( ! wc_rest_check_post_permissions( $this->post_type, 'read', $object->get_id() ) ) {
357
+		foreach ($query_results['objects'] as $object) {
358
+			if ( ! wc_rest_check_post_permissions($this->post_type, 'read', $object->get_id())) {
359 359
 				continue;
360 360
 			}
361 361
 
362
-			$data = $this->prepare_object_for_response( $object, $request );
363
-			$objects[] = $this->prepare_response_for_collection( $data );
362
+			$data = $this->prepare_object_for_response($object, $request);
363
+			$objects[] = $this->prepare_response_for_collection($data);
364 364
 		}
365 365
 
366 366
 		$page      = (int) $query_args['paged'];
367 367
 		$max_pages = $query_results['pages'];
368 368
 
369
-		$response = rest_ensure_response( $objects );
370
-		$response->header( 'X-WP-Total', $query_results['total'] );
371
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
369
+		$response = rest_ensure_response($objects);
370
+		$response->header('X-WP-Total', $query_results['total']);
371
+		$response->header('X-WP-TotalPages', (int) $max_pages);
372 372
 
373 373
 		$base          = $this->rest_base;
374 374
 		$attrib_prefix = '(?P<';
375
-		if ( strpos( $base, $attrib_prefix ) !== false ) {
375
+		if (strpos($base, $attrib_prefix) !== false) {
376 376
 			$attrib_names = array();
377
-			preg_match( '/\(\?P<[^>]+>.*\)/', $base, $attrib_names, PREG_OFFSET_CAPTURE );
378
-			foreach ( $attrib_names as $attrib_name_match ) {
379
-				$beginning_offset = strlen( $attrib_prefix );
380
-				$attrib_name_end  = strpos( $attrib_name_match[0], '>', $attrib_name_match[1] );
381
-				$attrib_name      = substr( $attrib_name_match[0], $beginning_offset, $attrib_name_end - $beginning_offset );
382
-				if ( isset( $request[ $attrib_name ] ) ) {
383
-					$base  = str_replace( "(?P<$attrib_name>[\d]+)", $request[ $attrib_name ], $base );
377
+			preg_match('/\(\?P<[^>]+>.*\)/', $base, $attrib_names, PREG_OFFSET_CAPTURE);
378
+			foreach ($attrib_names as $attrib_name_match) {
379
+				$beginning_offset = strlen($attrib_prefix);
380
+				$attrib_name_end  = strpos($attrib_name_match[0], '>', $attrib_name_match[1]);
381
+				$attrib_name      = substr($attrib_name_match[0], $beginning_offset, $attrib_name_end - $beginning_offset);
382
+				if (isset($request[$attrib_name])) {
383
+					$base = str_replace("(?P<$attrib_name>[\d]+)", $request[$attrib_name], $base);
384 384
 				}
385 385
 			}
386 386
 		}
387
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ) );
387
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $base)));
388 388
 
389
-		if ( $page > 1 ) {
389
+		if ($page > 1) {
390 390
 			$prev_page = $page - 1;
391
-			if ( $prev_page > $max_pages ) {
391
+			if ($prev_page > $max_pages) {
392 392
 				$prev_page = $max_pages;
393 393
 			}
394
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
395
-			$response->link_header( 'prev', $prev_link );
394
+			$prev_link = add_query_arg('page', $prev_page, $base);
395
+			$response->link_header('prev', $prev_link);
396 396
 		}
397
-		if ( $max_pages > $page ) {
397
+		if ($max_pages > $page) {
398 398
 			$next_page = $page + 1;
399
-			$next_link = add_query_arg( 'page', $next_page, $base );
400
-			$response->link_header( 'next', $next_link );
399
+			$next_link = add_query_arg('page', $next_page, $base);
400
+			$response->link_header('next', $next_link);
401 401
 		}
402 402
 
403 403
 		return $response;
@@ -409,16 +409,16 @@  discard block
 block discarded – undo
409 409
 	 * @param WP_REST_Request $request Full details about the request.
410 410
 	 * @return WP_REST_Response|WP_Error
411 411
 	 */
412
-	public function delete_item( $request ) {
412
+	public function delete_item($request) {
413 413
 		$force  = (bool) $request['force'];
414
-		$object = $this->get_object( (int) $request['id'] );
414
+		$object = $this->get_object((int) $request['id']);
415 415
 		$result = false;
416 416
 
417
-		if ( ! $object || 0 === $object->get_id() ) {
418
-			return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
417
+		if ( ! $object || 0 === $object->get_id()) {
418
+			return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
419 419
 		}
420 420
 
421
-		$supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) );
421
+		$supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable(array($object, 'get_status'));
422 422
 
423 423
 		/**
424 424
 		 * Filter whether an object is trashable.
@@ -428,32 +428,32 @@  discard block
 block discarded – undo
428 428
 		 * @param boolean $supports_trash Whether the object type support trashing.
429 429
 		 * @param WC_Data $object         The object being considered for trashing support.
430 430
 		 */
431
-		$supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object );
431
+		$supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object);
432 432
 
433
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
433
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) {
434 434
 			/* translators: %s: post type */
435
-			return new WP_Error( "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array( 'status' => rest_authorization_required_code() ) );
435
+			return new WP_Error("woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), array('status' => rest_authorization_required_code()));
436 436
 		}
437 437
 
438
-		$request->set_param( 'context', 'edit' );
439
-		$response = $this->prepare_object_for_response( $object, $request );
438
+		$request->set_param('context', 'edit');
439
+		$response = $this->prepare_object_for_response($object, $request);
440 440
 
441 441
 		// If we're forcing, then delete permanently.
442
-		if ( $force ) {
443
-			$object->delete( true );
442
+		if ($force) {
443
+			$object->delete(true);
444 444
 			$result = 0 === $object->get_id();
445 445
 		} else {
446 446
 			// If we don't support trashing for this type, error out.
447
-			if ( ! $supports_trash ) {
447
+			if ( ! $supports_trash) {
448 448
 				/* translators: %s: post type */
449
-				return new WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( 'status' => 501 ) );
449
+				return new WP_Error('woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array('status' => 501));
450 450
 			}
451 451
 
452 452
 			// Otherwise, only trash if we haven't already.
453
-			if ( is_callable( array( $object, 'get_status' ) ) ) {
454
-				if ( 'trash' === $object->get_status() ) {
453
+			if (is_callable(array($object, 'get_status'))) {
454
+				if ('trash' === $object->get_status()) {
455 455
 					/* translators: %s: post type */
456
-					return new WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 410 ) );
456
+					return new WP_Error('woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array('status' => 410));
457 457
 				}
458 458
 
459 459
 				$object->delete();
@@ -461,9 +461,9 @@  discard block
 block discarded – undo
461 461
 			}
462 462
 		}
463 463
 
464
-		if ( ! $result ) {
464
+		if ( ! $result) {
465 465
 			/* translators: %s: post type */
466
-			return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) );
466
+			return new WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array('status' => 500));
467 467
 		}
468 468
 
469 469
 		/**
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 		 * @param WP_REST_Response $response The response data.
474 474
 		 * @param WP_REST_Request  $request  The request sent to the API.
475 475
 		 */
476
-		do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request );
476
+		do_action("woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request);
477 477
 
478 478
 		return $response;
479 479
 	}
@@ -485,13 +485,13 @@  discard block
 block discarded – undo
485 485
 	 * @param WP_REST_Request $request Request object.
486 486
 	 * @return array                   Links for the given post.
487 487
 	 */
488
-	protected function prepare_links( $object, $request ) {
488
+	protected function prepare_links($object, $request) {
489 489
 		$links = array(
490 490
 			'self' => array(
491
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ),
491
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())),
492 492
 			),
493 493
 			'collection' => array(
494
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
494
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
495 495
 			),
496 496
 		);
497 497
 
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 		$params['context']['default'] = 'view';
510 510
 
511 511
 		$params['page'] = array(
512
-			'description'        => __( 'Current page of the collection.', 'woocommerce' ),
512
+			'description'        => __('Current page of the collection.', 'woocommerce'),
513 513
 			'type'               => 'integer',
514 514
 			'default'            => 1,
515 515
 			'sanitize_callback'  => 'absint',
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
 			'minimum'            => 1,
518 518
 		);
519 519
 		$params['per_page'] = array(
520
-			'description'        => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
520
+			'description'        => __('Maximum number of items to be returned in result set.', 'woocommerce'),
521 521
 			'type'               => 'integer',
522 522
 			'default'            => 10,
523 523
 			'minimum'            => 1,
@@ -526,25 +526,25 @@  discard block
 block discarded – undo
526 526
 			'validate_callback'  => 'rest_validate_request_arg',
527 527
 		);
528 528
 		$params['search'] = array(
529
-			'description'        => __( 'Limit results to those matching a string.', 'woocommerce' ),
529
+			'description'        => __('Limit results to those matching a string.', 'woocommerce'),
530 530
 			'type'               => 'string',
531 531
 			'sanitize_callback'  => 'sanitize_text_field',
532 532
 			'validate_callback'  => 'rest_validate_request_arg',
533 533
 		);
534 534
 		$params['after'] = array(
535
-			'description'        => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
535
+			'description'        => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
536 536
 			'type'               => 'string',
537 537
 			'format'             => 'date-time',
538 538
 			'validate_callback'  => 'rest_validate_request_arg',
539 539
 		);
540 540
 		$params['before'] = array(
541
-			'description'        => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
541
+			'description'        => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
542 542
 			'type'               => 'string',
543 543
 			'format'             => 'date-time',
544 544
 			'validate_callback'  => 'rest_validate_request_arg',
545 545
 		);
546 546
 		$params['exclude'] = array(
547
-			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
547
+			'description'       => __('Ensure result set excludes specific IDs.', 'woocommerce'),
548 548
 			'type'              => 'array',
549 549
 			'items'             => array(
550 550
 				'type'          => 'integer',
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
 			'sanitize_callback' => 'wp_parse_id_list',
554 554
 		);
555 555
 		$params['include'] = array(
556
-			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
556
+			'description'       => __('Limit result set to specific ids.', 'woocommerce'),
557 557
 			'type'              => 'array',
558 558
 			'items'             => array(
559 559
 				'type'          => 'integer',
@@ -562,20 +562,20 @@  discard block
 block discarded – undo
562 562
 			'sanitize_callback' => 'wp_parse_id_list',
563 563
 		);
564 564
 		$params['offset'] = array(
565
-			'description'        => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
565
+			'description'        => __('Offset the result set by a specific number of items.', 'woocommerce'),
566 566
 			'type'               => 'integer',
567 567
 			'sanitize_callback'  => 'absint',
568 568
 			'validate_callback'  => 'rest_validate_request_arg',
569 569
 		);
570 570
 		$params['order'] = array(
571
-			'description'        => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
571
+			'description'        => __('Order sort attribute ascending or descending.', 'woocommerce'),
572 572
 			'type'               => 'string',
573 573
 			'default'            => 'desc',
574
-			'enum'               => array( 'asc', 'desc' ),
574
+			'enum'               => array('asc', 'desc'),
575 575
 			'validate_callback'  => 'rest_validate_request_arg',
576 576
 		);
577 577
 		$params['orderby'] = array(
578
-			'description'        => __( 'Sort collection by object attribute.', 'woocommerce' ),
578
+			'description'        => __('Sort collection by object attribute.', 'woocommerce'),
579 579
 			'type'               => 'string',
580 580
 			'default'            => 'date',
581 581
 			'enum'               => array(
@@ -588,9 +588,9 @@  discard block
 block discarded – undo
588 588
 			'validate_callback'  => 'rest_validate_request_arg',
589 589
 		);
590 590
 
591
-		if ( $this->hierarchical ) {
591
+		if ($this->hierarchical) {
592 592
 			$params['parent'] = array(
593
-				'description'       => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ),
593
+				'description'       => __('Limit result set to those of particular parent IDs.', 'woocommerce'),
594 594
 				'type'              => 'array',
595 595
 				'items'             => array(
596 596
 					'type'          => 'integer',
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 				'default'           => array(),
600 600
 			);
601 601
 			$params['parent_exclude'] = array(
602
-				'description'       => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ),
602
+				'description'       => __('Limit result set to all items except those of a particular parent ID.', 'woocommerce'),
603 603
 				'type'              => 'array',
604 604
 				'items'             => array(
605 605
 					'type'          => 'integer',
@@ -622,6 +622,6 @@  discard block
 block discarded – undo
622 622
 		 * @param array        $query_params JSON Schema-formatted collection parameters.
623 623
 		 * @param WP_Post_Type $post_type    Post type object.
624 624
 		 */
625
-		return apply_filters( "rest_{$this->post_type}_collection_params", $params, $this->post_type );
625
+		return apply_filters("rest_{$this->post_type}_collection_params", $params, $this->post_type);
626 626
 	}
627 627
 }
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-webhooks-controller.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
  * @since   2.6.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Webhooks controller class.
Please login to merge, or discard this patch.
Controllers/Version3/class-wc-rest-report-customers-totals-controller.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   3.5.0
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * REST API Reports Customers Totals controller class.
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 		$users_count     = count_users();
43 43
 		$total_customers = 0;
44 44
 
45
-		foreach ( $users_count['avail_roles'] as $role => $total ) {
46
-			if ( in_array( $role, array( 'administrator', 'shop_manager' ), true ) ) {
45
+		foreach ($users_count['avail_roles'] as $role => $total) {
46
+			if (in_array($role, array('administrator', 'shop_manager'), true)) {
47 47
 				continue;
48 48
 			}
49 49
 
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 
53 53
 		$customers_query = new WP_User_Query(
54 54
 			array(
55
-				'role__not_in' => array( 'administrator', 'shop_manager' ),
55
+				'role__not_in' => array('administrator', 'shop_manager'),
56 56
 				'number'       => 0,
57 57
 				'fields'       => 'ID',
58 58
 				'count_total'  => true,
@@ -71,12 +71,12 @@  discard block
 block discarded – undo
71 71
 		$data = array(
72 72
 			array(
73 73
 				'slug'  => 'paying',
74
-				'name'  => __( 'Paying customer', 'woocommerce' ),
74
+				'name'  => __('Paying customer', 'woocommerce'),
75 75
 				'total' => $total_paying,
76 76
 			),
77 77
 			array(
78 78
 				'slug'  => 'non_paying',
79
-				'name'  => __( 'Non-paying customer', 'woocommerce' ),
79
+				'name'  => __('Non-paying customer', 'woocommerce'),
80 80
 				'total' => $total_customers - $total_paying,
81 81
 			),
82 82
 		);
@@ -91,19 +91,19 @@  discard block
 block discarded – undo
91 91
 	 * @param  WP_REST_Request $request Request object.
92 92
 	 * @return WP_REST_Response $response Response data.
93 93
 	 */
94
-	public function prepare_item_for_response( $report, $request ) {
94
+	public function prepare_item_for_response($report, $request) {
95 95
 		$data = array(
96 96
 			'slug'  => $report->slug,
97 97
 			'name'  => $report->name,
98 98
 			'total' => $report->total,
99 99
 		);
100 100
 
101
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
102
-		$data    = $this->add_additional_fields_to_object( $data, $request );
103
-		$data    = $this->filter_response_by_context( $data, $context );
101
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
102
+		$data    = $this->add_additional_fields_to_object($data, $request);
103
+		$data    = $this->filter_response_by_context($data, $context);
104 104
 
105 105
 		// Wrap the data in a response object.
106
-		$response = rest_ensure_response( $data );
106
+		$response = rest_ensure_response($data);
107 107
 
108 108
 		/**
109 109
 		 * Filter a report returned from the API.
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 		 * @param object           $report   The original report object.
115 115
 		 * @param WP_REST_Request  $request  Request used to generate the response.
116 116
 		 */
117
-		return apply_filters( 'woocommerce_rest_prepare_report_customers_count', $response, $report, $request );
117
+		return apply_filters('woocommerce_rest_prepare_report_customers_count', $response, $report, $request);
118 118
 	}
119 119
 
120 120
 	/**
@@ -129,26 +129,26 @@  discard block
 block discarded – undo
129 129
 			'type'       => 'object',
130 130
 			'properties' => array(
131 131
 				'slug'  => array(
132
-					'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ),
132
+					'description' => __('An alphanumeric identifier for the resource.', 'woocommerce'),
133 133
 					'type'        => 'string',
134
-					'context'     => array( 'view' ),
134
+					'context'     => array('view'),
135 135
 					'readonly'    => true,
136 136
 				),
137 137
 				'name'  => array(
138
-					'description' => __( 'Customer type name.', 'woocommerce' ),
138
+					'description' => __('Customer type name.', 'woocommerce'),
139 139
 					'type'        => 'string',
140
-					'context'     => array( 'view' ),
140
+					'context'     => array('view'),
141 141
 					'readonly'    => true,
142 142
 				),
143 143
 				'total' => array(
144
-					'description' => __( 'Amount of customers.', 'woocommerce' ),
144
+					'description' => __('Amount of customers.', 'woocommerce'),
145 145
 					'type'        => 'string',
146
-					'context'     => array( 'view' ),
146
+					'context'     => array('view'),
147 147
 					'readonly'    => true,
148 148
 				),
149 149
 			),
150 150
 		);
151 151
 
152
-		return $this->add_additional_fields_schema( $schema );
152
+		return $this->add_additional_fields_schema($schema);
153 153
 	}
154 154
 }
Please login to merge, or discard this patch.
src/Controllers/Version3/class-wc-rest-controller.php 1 patch
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @see     https://developer.wordpress.org/rest-api/extending-the-rest-api/controller-classes/
17 17
  */
18 18
 
19
-if ( ! defined( 'ABSPATH' ) ) {
19
+if ( ! defined('ABSPATH')) {
20 20
 	exit;
21 21
 }
22 22
 
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @return array
54 54
 	 */
55
-	protected function add_additional_fields_schema( $schema ) {
56
-		if ( empty( $schema['title'] ) ) {
55
+	protected function add_additional_fields_schema($schema) {
56
+		if (empty($schema['title'])) {
57 57
 			return $schema;
58 58
 		}
59 59
 
@@ -62,17 +62,17 @@  discard block
 block discarded – undo
62 62
 		 */
63 63
 		$object_type = $schema['title'];
64 64
 
65
-		$additional_fields = $this->get_additional_fields( $object_type );
65
+		$additional_fields = $this->get_additional_fields($object_type);
66 66
 
67
-		foreach ( $additional_fields as $field_name => $field_options ) {
68
-			if ( ! $field_options['schema'] ) {
67
+		foreach ($additional_fields as $field_name => $field_options) {
68
+			if ( ! $field_options['schema']) {
69 69
 				continue;
70 70
 			}
71 71
 
72
-			$schema['properties'][ $field_name ] = $field_options['schema'];
72
+			$schema['properties'][$field_name] = $field_options['schema'];
73 73
 		}
74 74
 
75
-		$schema['properties'] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema['properties'] );
75
+		$schema['properties'] = apply_filters('woocommerce_rest_' . $object_type . '_schema', $schema['properties']);
76 76
 
77 77
 		return $schema;
78 78
 	}
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @return string
84 84
 	 */
85 85
 	protected function get_normalized_rest_base() {
86
-		return preg_replace( '/\(.*\)\//i', '', $this->rest_base );
86
+		return preg_replace('/\(.*\)\//i', '', $this->rest_base);
87 87
 	}
88 88
 
89 89
 	/**
@@ -92,25 +92,25 @@  discard block
 block discarded – undo
92 92
 	 * @param array $items Request items.
93 93
 	 * @return bool|WP_Error
94 94
 	 */
95
-	protected function check_batch_limit( $items ) {
96
-		$limit = apply_filters( 'woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base() );
95
+	protected function check_batch_limit($items) {
96
+		$limit = apply_filters('woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base());
97 97
 		$total = 0;
98 98
 
99
-		if ( ! empty( $items['create'] ) ) {
100
-			$total += count( $items['create'] );
99
+		if ( ! empty($items['create'])) {
100
+			$total += count($items['create']);
101 101
 		}
102 102
 
103
-		if ( ! empty( $items['update'] ) ) {
104
-			$total += count( $items['update'] );
103
+		if ( ! empty($items['update'])) {
104
+			$total += count($items['update']);
105 105
 		}
106 106
 
107
-		if ( ! empty( $items['delete'] ) ) {
108
-			$total += count( $items['delete'] );
107
+		if ( ! empty($items['delete'])) {
108
+			$total += count($items['delete']);
109 109
 		}
110 110
 
111
-		if ( $total > $limit ) {
111
+		if ($total > $limit) {
112 112
 			/* translators: %s: items limit */
113
-			return new WP_Error( 'woocommerce_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'woocommerce' ), $limit ), array( 'status' => 413 ) );
113
+			return new WP_Error('woocommerce_rest_request_entity_too_large', sprintf(__('Unable to accept more than %s items for this request.', 'woocommerce'), $limit), array('status' => 413));
114 114
 		}
115 115
 
116 116
 		return true;
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 * @param WP_REST_Request $request Full details about the request.
123 123
 	 * @return array Of WP_Error or WP_REST_Response.
124 124
 	 */
125
-	public function batch_items( $request ) {
125
+	public function batch_items($request) {
126 126
 		/**
127 127
 		 * REST Server
128 128
 		 *
@@ -131,34 +131,34 @@  discard block
 block discarded – undo
131 131
 		global $wp_rest_server;
132 132
 
133 133
 		// Get the request params.
134
-		$items    = array_filter( $request->get_params() );
134
+		$items    = array_filter($request->get_params());
135 135
 		$response = array();
136 136
 
137 137
 		// Check batch limit.
138
-		$limit = $this->check_batch_limit( $items );
139
-		if ( is_wp_error( $limit ) ) {
138
+		$limit = $this->check_batch_limit($items);
139
+		if (is_wp_error($limit)) {
140 140
 			return $limit;
141 141
 		}
142 142
 
143
-		if ( ! empty( $items['create'] ) ) {
144
-			foreach ( $items['create'] as $item ) {
145
-				$_item = new WP_REST_Request( 'POST' );
143
+		if ( ! empty($items['create'])) {
144
+			foreach ($items['create'] as $item) {
145
+				$_item = new WP_REST_Request('POST');
146 146
 
147 147
 				// Default parameters.
148 148
 				$defaults = array();
149 149
 				$schema   = $this->get_public_item_schema();
150
-				foreach ( $schema['properties'] as $arg => $options ) {
151
-					if ( isset( $options['default'] ) ) {
152
-						$defaults[ $arg ] = $options['default'];
150
+				foreach ($schema['properties'] as $arg => $options) {
151
+					if (isset($options['default'])) {
152
+						$defaults[$arg] = $options['default'];
153 153
 					}
154 154
 				}
155
-				$_item->set_default_params( $defaults );
155
+				$_item->set_default_params($defaults);
156 156
 
157 157
 				// Set request parameters.
158
-				$_item->set_body_params( $item );
159
-				$_response = $this->create_item( $_item );
158
+				$_item->set_body_params($item);
159
+				$_response = $this->create_item($_item);
160 160
 
161
-				if ( is_wp_error( $_response ) ) {
161
+				if (is_wp_error($_response)) {
162 162
 					$response['create'][] = array(
163 163
 						'id'    => 0,
164 164
 						'error' => array(
@@ -168,18 +168,18 @@  discard block
 block discarded – undo
168 168
 						),
169 169
 					);
170 170
 				} else {
171
-					$response['create'][] = $wp_rest_server->response_to_data( $_response, '' );
171
+					$response['create'][] = $wp_rest_server->response_to_data($_response, '');
172 172
 				}
173 173
 			}
174 174
 		}
175 175
 
176
-		if ( ! empty( $items['update'] ) ) {
177
-			foreach ( $items['update'] as $item ) {
178
-				$_item = new WP_REST_Request( 'PUT' );
179
-				$_item->set_body_params( $item );
180
-				$_response = $this->update_item( $_item );
176
+		if ( ! empty($items['update'])) {
177
+			foreach ($items['update'] as $item) {
178
+				$_item = new WP_REST_Request('PUT');
179
+				$_item->set_body_params($item);
180
+				$_response = $this->update_item($_item);
181 181
 
182
-				if ( is_wp_error( $_response ) ) {
182
+				if (is_wp_error($_response)) {
183 183
 					$response['update'][] = array(
184 184
 						'id'    => $item['id'],
185 185
 						'error' => array(
@@ -189,29 +189,29 @@  discard block
 block discarded – undo
189 189
 						),
190 190
 					);
191 191
 				} else {
192
-					$response['update'][] = $wp_rest_server->response_to_data( $_response, '' );
192
+					$response['update'][] = $wp_rest_server->response_to_data($_response, '');
193 193
 				}
194 194
 			}
195 195
 		}
196 196
 
197
-		if ( ! empty( $items['delete'] ) ) {
198
-			foreach ( $items['delete'] as $id ) {
197
+		if ( ! empty($items['delete'])) {
198
+			foreach ($items['delete'] as $id) {
199 199
 				$id = (int) $id;
200 200
 
201
-				if ( 0 === $id ) {
201
+				if (0 === $id) {
202 202
 					continue;
203 203
 				}
204 204
 
205
-				$_item = new WP_REST_Request( 'DELETE' );
205
+				$_item = new WP_REST_Request('DELETE');
206 206
 				$_item->set_query_params(
207 207
 					array(
208 208
 						'id'    => $id,
209 209
 						'force' => true,
210 210
 					)
211 211
 				);
212
-				$_response = $this->delete_item( $_item );
212
+				$_response = $this->delete_item($_item);
213 213
 
214
-				if ( is_wp_error( $_response ) ) {
214
+				if (is_wp_error($_response)) {
215 215
 					$response['delete'][] = array(
216 216
 						'id'    => $id,
217 217
 						'error' => array(
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 						),
222 222
 					);
223 223
 				} else {
224
-					$response['delete'][] = $wp_rest_server->response_to_data( $_response, '' );
224
+					$response['delete'][] = $wp_rest_server->response_to_data($_response, '');
225 225
 				}
226 226
 			}
227 227
 		}
@@ -237,9 +237,9 @@  discard block
 block discarded – undo
237 237
 	 * @param array  $setting Setting.
238 238
 	 * @return string
239 239
 	 */
240
-	public function validate_setting_text_field( $value, $setting ) {
241
-		$value = is_null( $value ) ? '' : $value;
242
-		return wp_kses_post( trim( stripslashes( $value ) ) );
240
+	public function validate_setting_text_field($value, $setting) {
241
+		$value = is_null($value) ? '' : $value;
242
+		return wp_kses_post(trim(stripslashes($value)));
243 243
 	}
244 244
 
245 245
 	/**
@@ -250,11 +250,11 @@  discard block
 block discarded – undo
250 250
 	 * @param array  $setting Setting.
251 251
 	 * @return string|WP_Error
252 252
 	 */
253
-	public function validate_setting_select_field( $value, $setting ) {
254
-		if ( array_key_exists( $value, $setting['options'] ) ) {
253
+	public function validate_setting_select_field($value, $setting) {
254
+		if (array_key_exists($value, $setting['options'])) {
255 255
 			return $value;
256 256
 		} else {
257
-			return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
257
+			return new WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
258 258
 		}
259 259
 	}
260 260
 
@@ -266,18 +266,18 @@  discard block
 block discarded – undo
266 266
 	 * @param array $setting Setting.
267 267
 	 * @return array|WP_Error
268 268
 	 */
269
-	public function validate_setting_multiselect_field( $values, $setting ) {
270
-		if ( empty( $values ) ) {
269
+	public function validate_setting_multiselect_field($values, $setting) {
270
+		if (empty($values)) {
271 271
 			return array();
272 272
 		}
273 273
 
274
-		if ( ! is_array( $values ) ) {
275
-			return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
274
+		if ( ! is_array($values)) {
275
+			return new WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
276 276
 		}
277 277
 
278 278
 		$final_values = array();
279
-		foreach ( $values as $value ) {
280
-			if ( array_key_exists( $value, $setting['options'] ) ) {
279
+		foreach ($values as $value) {
280
+			if (array_key_exists($value, $setting['options'])) {
281 281
 				$final_values[] = $value;
282 282
 			}
283 283
 		}
@@ -293,19 +293,19 @@  discard block
 block discarded – undo
293 293
 	 * @param array $setting Setting.
294 294
 	 * @return string|WP_Error
295 295
 	 */
296
-	public function validate_setting_image_width_field( $values, $setting ) {
297
-		if ( ! is_array( $values ) ) {
298
-			return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
296
+	public function validate_setting_image_width_field($values, $setting) {
297
+		if ( ! is_array($values)) {
298
+			return new WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
299 299
 		}
300 300
 
301 301
 		$current = $setting['value'];
302
-		if ( isset( $values['width'] ) ) {
303
-			$current['width'] = intval( $values['width'] );
302
+		if (isset($values['width'])) {
303
+			$current['width'] = intval($values['width']);
304 304
 		}
305
-		if ( isset( $values['height'] ) ) {
306
-			$current['height'] = intval( $values['height'] );
305
+		if (isset($values['height'])) {
306
+			$current['height'] = intval($values['height']);
307 307
 		}
308
-		if ( isset( $values['crop'] ) ) {
308
+		if (isset($values['crop'])) {
309 309
 			$current['crop'] = (bool) $values['crop'];
310 310
 		}
311 311
 		return $current;
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
 	 * @param array  $setting Setting.
320 320
 	 * @return string|WP_Error
321 321
 	 */
322
-	public function validate_setting_radio_field( $value, $setting ) {
323
-		return $this->validate_setting_select_field( $value, $setting );
322
+	public function validate_setting_radio_field($value, $setting) {
323
+		return $this->validate_setting_select_field($value, $setting);
324 324
 	}
325 325
 
326 326
 	/**
@@ -331,14 +331,14 @@  discard block
 block discarded – undo
331 331
 	 * @param array  $setting Setting.
332 332
 	 * @return string|WP_Error
333 333
 	 */
334
-	public function validate_setting_checkbox_field( $value, $setting ) {
335
-		if ( in_array( $value, array( 'yes', 'no' ) ) ) {
334
+	public function validate_setting_checkbox_field($value, $setting) {
335
+		if (in_array($value, array('yes', 'no'))) {
336 336
 			return $value;
337
-		} elseif ( empty( $value ) ) {
338
-			$value = isset( $setting['default'] ) ? $setting['default'] : 'no';
337
+		} elseif (empty($value)) {
338
+			$value = isset($setting['default']) ? $setting['default'] : 'no';
339 339
 			return $value;
340 340
 		} else {
341
-			return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
341
+			return new WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
342 342
 		}
343 343
 	}
344 344
 
@@ -350,10 +350,10 @@  discard block
 block discarded – undo
350 350
 	 * @param array  $setting Setting.
351 351
 	 * @return string
352 352
 	 */
353
-	public function validate_setting_textarea_field( $value, $setting ) {
354
-		$value = is_null( $value ) ? '' : $value;
353
+	public function validate_setting_textarea_field($value, $setting) {
354
+		$value = is_null($value) ? '' : $value;
355 355
 		return wp_kses(
356
-			trim( stripslashes( $value ) ),
356
+			trim(stripslashes($value)),
357 357
 			array_merge(
358 358
 				array(
359 359
 					'iframe' => array(
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 						'class' => true,
364 364
 					),
365 365
 				),
366
-				wp_kses_allowed_html( 'post' )
366
+				wp_kses_allowed_html('post')
367 367
 			)
368 368
 		);
369 369
 	}
@@ -376,8 +376,8 @@  discard block
 block discarded – undo
376 376
 	 * @param array $meta_query Meta query.
377 377
 	 * @return array
378 378
 	 */
379
-	protected function add_meta_query( $args, $meta_query ) {
380
-		if ( empty( $args['meta_query'] ) ) {
379
+	protected function add_meta_query($args, $meta_query) {
380
+		if (empty($args['meta_query'])) {
381 381
 			$args['meta_query'] = array();
382 382
 		}
383 383
 
@@ -398,25 +398,25 @@  discard block
 block discarded – undo
398 398
 			'type'       => 'object',
399 399
 			'properties' => array(
400 400
 				'create' => array(
401
-					'description' => __( 'List of created resources.', 'woocommerce' ),
401
+					'description' => __('List of created resources.', 'woocommerce'),
402 402
 					'type'        => 'array',
403
-					'context'     => array( 'view', 'edit' ),
403
+					'context'     => array('view', 'edit'),
404 404
 					'items'       => array(
405 405
 						'type'    => 'object',
406 406
 					),
407 407
 				),
408 408
 				'update' => array(
409
-					'description' => __( 'List of updated resources.', 'woocommerce' ),
409
+					'description' => __('List of updated resources.', 'woocommerce'),
410 410
 					'type'        => 'array',
411
-					'context'     => array( 'view', 'edit' ),
411
+					'context'     => array('view', 'edit'),
412 412
 					'items'       => array(
413 413
 						'type'    => 'object',
414 414
 					),
415 415
 				),
416 416
 				'delete' => array(
417
-					'description' => __( 'List of delete resources.', 'woocommerce' ),
417
+					'description' => __('List of delete resources.', 'woocommerce'),
418 418
 					'type'        => 'array',
419
-					'context'     => array( 'view', 'edit' ),
419
+					'context'     => array('view', 'edit'),
420 420
 					'items'       => array(
421 421
 						'type'    => 'integer',
422 422
 					),
@@ -436,32 +436,32 @@  discard block
 block discarded – undo
436 436
 	 * @param WP_REST_Request $request Full details about the request.
437 437
 	 * @return array Fields to be included in the response.
438 438
 	 */
439
-	public function get_fields_for_response( $request ) {
439
+	public function get_fields_for_response($request) {
440 440
 		$schema = $this->get_item_schema();
441
-		$fields = isset( $schema['properties'] ) ? array_keys( $schema['properties'] ) : array();
441
+		$fields = isset($schema['properties']) ? array_keys($schema['properties']) : array();
442 442
 
443 443
 		$additional_fields = $this->get_additional_fields();
444
-		foreach ( $additional_fields as $field_name => $field_options ) {
444
+		foreach ($additional_fields as $field_name => $field_options) {
445 445
 			// For back-compat, include any field with an empty schema
446 446
 			// because it won't be present in $this->get_item_schema().
447
-			if ( is_null( $field_options['schema'] ) ) {
447
+			if (is_null($field_options['schema'])) {
448 448
 				$fields[] = $field_name;
449 449
 			}
450 450
 		}
451 451
 
452
-		if ( ! isset( $request['_fields'] ) ) {
452
+		if ( ! isset($request['_fields'])) {
453 453
 			return $fields;
454 454
 		}
455
-		$requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] );
456
-		if ( 0 === count( $requested_fields ) ) {
455
+		$requested_fields = is_array($request['_fields']) ? $request['_fields'] : preg_split('/[\s,]+/', $request['_fields']);
456
+		if (0 === count($requested_fields)) {
457 457
 			return $fields;
458 458
 		}
459 459
 		// Trim off outside whitespace from the comma delimited list.
460
-		$requested_fields = array_map( 'trim', $requested_fields );
460
+		$requested_fields = array_map('trim', $requested_fields);
461 461
 		// Always persist 'id', because it can be needed for add_additional_fields_to_object().
462
-		if ( in_array( 'id', $fields, true ) ) {
462
+		if (in_array('id', $fields, true)) {
463 463
 			$requested_fields[] = 'id';
464 464
 		}
465
-		return array_intersect( $fields, $requested_fields );
465
+		return array_intersect($fields, $requested_fields);
466 466
 	}
467 467
 }
Please login to merge, or discard this patch.