Test Failed
Push — master ( a5e4c3...7495fa )
by Mike
43:00
created
src/Controllers/Version2/class-wc-rest-webhook-deliveries-v2-controller.php 1 patch
Spacing   +33 added lines, -33 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 Webhook Deliveries controller class.
@@ -33,17 +33,17 @@  discard block
 block discarded – undo
33 33
 	 * @param  WP_REST_Request $request Request object.
34 34
 	 * @return WP_REST_Response
35 35
 	 */
36
-	public function prepare_item_for_response( $log, $request ) {
36
+	public function prepare_item_for_response($log, $request) {
37 37
 		$data = (array) $log;
38 38
 
39
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
40
-		$data    = $this->add_additional_fields_to_object( $data, $request );
41
-		$data    = $this->filter_response_by_context( $data, $context );
39
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
40
+		$data    = $this->add_additional_fields_to_object($data, $request);
41
+		$data    = $this->filter_response_by_context($data, $context);
42 42
 
43 43
 		// Wrap the data in a response object.
44
-		$response = rest_ensure_response( $data );
44
+		$response = rest_ensure_response($data);
45 45
 
46
-		$response->add_links( $this->prepare_links( $log ) );
46
+		$response->add_links($this->prepare_links($log));
47 47
 
48 48
 		/**
49 49
 		 * Filter webhook delivery object returned from the REST API.
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 		 * @param stdClass         $log      Delivery log object used to create response.
53 53
 		 * @param WP_REST_Request  $request  Request object.
54 54
 		 */
55
-		return apply_filters( 'woocommerce_rest_prepare_webhook_delivery', $response, $log, $request );
55
+		return apply_filters('woocommerce_rest_prepare_webhook_delivery', $response, $log, $request);
56 56
 	}
57 57
 
58 58
 	/**
@@ -67,87 +67,87 @@  discard block
 block discarded – undo
67 67
 			'type'       => 'object',
68 68
 			'properties' => array(
69 69
 				'id'               => array(
70
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
70
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
71 71
 					'type'        => 'integer',
72
-					'context'     => array( 'view' ),
72
+					'context'     => array('view'),
73 73
 					'readonly'    => true,
74 74
 				),
75 75
 				'duration'         => array(
76
-					'description' => __( 'The delivery duration, in seconds.', 'woocommerce' ),
76
+					'description' => __('The delivery duration, in seconds.', 'woocommerce'),
77 77
 					'type'        => 'string',
78
-					'context'     => array( 'view' ),
78
+					'context'     => array('view'),
79 79
 					'readonly'    => true,
80 80
 				),
81 81
 				'summary'          => array(
82
-					'description' => __( 'A friendly summary of the response including the HTTP response code, message, and body.', 'woocommerce' ),
82
+					'description' => __('A friendly summary of the response including the HTTP response code, message, and body.', 'woocommerce'),
83 83
 					'type'        => 'string',
84
-					'context'     => array( 'view' ),
84
+					'context'     => array('view'),
85 85
 					'readonly'    => true,
86 86
 				),
87 87
 				'request_url'      => array(
88
-					'description' => __( 'The URL where the webhook was delivered.', 'woocommerce' ),
88
+					'description' => __('The URL where the webhook was delivered.', 'woocommerce'),
89 89
 					'type'        => 'string',
90 90
 					'format'      => 'uri',
91
-					'context'     => array( 'view' ),
91
+					'context'     => array('view'),
92 92
 					'readonly'    => true,
93 93
 				),
94 94
 				'request_headers'  => array(
95
-					'description' => __( 'Request headers.', 'woocommerce' ),
95
+					'description' => __('Request headers.', 'woocommerce'),
96 96
 					'type'        => 'array',
97
-					'context'     => array( 'view' ),
97
+					'context'     => array('view'),
98 98
 					'readonly'    => true,
99 99
 					'items'       => array(
100 100
 						'type' => 'string',
101 101
 					),
102 102
 				),
103 103
 				'request_body'     => array(
104
-					'description' => __( 'Request body.', 'woocommerce' ),
104
+					'description' => __('Request body.', 'woocommerce'),
105 105
 					'type'        => 'string',
106
-					'context'     => array( 'view' ),
106
+					'context'     => array('view'),
107 107
 					'readonly'    => true,
108 108
 				),
109 109
 				'response_code'    => array(
110
-					'description' => __( 'The HTTP response code from the receiving server.', 'woocommerce' ),
110
+					'description' => __('The HTTP response code from the receiving server.', 'woocommerce'),
111 111
 					'type'        => 'string',
112
-					'context'     => array( 'view' ),
112
+					'context'     => array('view'),
113 113
 					'readonly'    => true,
114 114
 				),
115 115
 				'response_message' => array(
116
-					'description' => __( 'The HTTP response message from the receiving server.', 'woocommerce' ),
116
+					'description' => __('The HTTP response message from the receiving server.', 'woocommerce'),
117 117
 					'type'        => 'string',
118
-					'context'     => array( 'view' ),
118
+					'context'     => array('view'),
119 119
 					'readonly'    => true,
120 120
 				),
121 121
 				'response_headers' => array(
122
-					'description' => __( 'Array of the response headers from the receiving server.', 'woocommerce' ),
122
+					'description' => __('Array of the response headers from the receiving server.', 'woocommerce'),
123 123
 					'type'        => 'array',
124
-					'context'     => array( 'view' ),
124
+					'context'     => array('view'),
125 125
 					'readonly'    => true,
126 126
 					'items'       => array(
127 127
 						'type' => 'string',
128 128
 					),
129 129
 				),
130 130
 				'response_body'    => array(
131
-					'description' => __( 'The response body from the receiving server.', 'woocommerce' ),
131
+					'description' => __('The response body from the receiving server.', 'woocommerce'),
132 132
 					'type'        => 'string',
133
-					'context'     => array( 'view' ),
133
+					'context'     => array('view'),
134 134
 					'readonly'    => true,
135 135
 				),
136 136
 				'date_created'     => array(
137
-					'description' => __( "The date the webhook delivery was logged, in the site's timezone.", 'woocommerce' ),
137
+					'description' => __("The date the webhook delivery was logged, in the site's timezone.", 'woocommerce'),
138 138
 					'type'        => 'date-time',
139
-					'context'     => array( 'view', 'edit' ),
139
+					'context'     => array('view', 'edit'),
140 140
 					'readonly'    => true,
141 141
 				),
142 142
 				'date_created_gmt' => array(
143
-					'description' => __( 'The date the webhook delivery was logged, as GMT.', 'woocommerce' ),
143
+					'description' => __('The date the webhook delivery was logged, as GMT.', 'woocommerce'),
144 144
 					'type'        => 'date-time',
145
-					'context'     => array( 'view', 'edit' ),
145
+					'context'     => array('view', 'edit'),
146 146
 					'readonly'    => true,
147 147
 				),
148 148
 			),
149 149
 		);
150 150
 
151
-		return $this->add_additional_fields_schema( $schema );
151
+		return $this->add_additional_fields_schema($schema);
152 152
 	}
153 153
 }
Please login to merge, or discard this patch.
src/Controllers/Version2/class-wc-rest-product-tags-v2-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 Tags controller class.
Please login to merge, or discard this patch.
Version2/class-wc-rest-product-shipping-classes-v2-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 Shipping Classes controller class.
Please login to merge, or discard this patch.
src/Controllers/Version2/class-wc-rest-shipping-zones-v2-controller.php 1 patch
Spacing   +77 added lines, -77 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 Shipping Zones class.
@@ -26,24 +26,24 @@  discard block
 block discarded – undo
26 26
 			$this->namespace, '/' . $this->rest_base, array(
27 27
 				array(
28 28
 					'methods'             => WP_REST_Server::READABLE,
29
-					'callback'            => array( $this, 'get_items' ),
30
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
29
+					'callback'            => array($this, 'get_items'),
30
+					'permission_callback' => array($this, 'get_items_permissions_check'),
31 31
 				),
32 32
 				array(
33 33
 					'methods'             => WP_REST_Server::CREATABLE,
34
-					'callback'            => array( $this, 'create_item' ),
35
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
34
+					'callback'            => array($this, 'create_item'),
35
+					'permission_callback' => array($this, 'create_item_permissions_check'),
36 36
 					'args'                => array_merge(
37
-						$this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
37
+						$this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array(
38 38
 							'name' => array(
39 39
 								'required'    => true,
40 40
 								'type'        => 'string',
41
-								'description' => __( 'Shipping zone name.', 'woocommerce' ),
41
+								'description' => __('Shipping zone name.', 'woocommerce'),
42 42
 							),
43 43
 						)
44 44
 					),
45 45
 				),
46
-				'schema' => array( $this, 'get_public_item_schema' ),
46
+				'schema' => array($this, 'get_public_item_schema'),
47 47
 			)
48 48
 		);
49 49
 
@@ -51,34 +51,34 @@  discard block
 block discarded – undo
51 51
 			$this->namespace, '/' . $this->rest_base . '/(?P<id>[\d-]+)', array(
52 52
 				'args'   => array(
53 53
 					'id' => array(
54
-						'description' => __( 'Unique ID for the resource.', 'woocommerce' ),
54
+						'description' => __('Unique ID for the resource.', 'woocommerce'),
55 55
 						'type'        => 'integer',
56 56
 					),
57 57
 				),
58 58
 				array(
59 59
 					'methods'             => WP_REST_Server::READABLE,
60
-					'callback'            => array( $this, 'get_item' ),
61
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
60
+					'callback'            => array($this, 'get_item'),
61
+					'permission_callback' => array($this, 'get_items_permissions_check'),
62 62
 				),
63 63
 				array(
64 64
 					'methods'             => WP_REST_Server::EDITABLE,
65
-					'callback'            => array( $this, 'update_item' ),
66
-					'permission_callback' => array( $this, 'update_items_permissions_check' ),
67
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
65
+					'callback'            => array($this, 'update_item'),
66
+					'permission_callback' => array($this, 'update_items_permissions_check'),
67
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
68 68
 				),
69 69
 				array(
70 70
 					'methods'             => WP_REST_Server::DELETABLE,
71
-					'callback'            => array( $this, 'delete_item' ),
72
-					'permission_callback' => array( $this, 'delete_items_permissions_check' ),
71
+					'callback'            => array($this, 'delete_item'),
72
+					'permission_callback' => array($this, 'delete_items_permissions_check'),
73 73
 					'args'                => array(
74 74
 						'force' => array(
75 75
 							'default'     => false,
76 76
 							'type'        => 'boolean',
77
-							'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
77
+							'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'),
78 78
 						),
79 79
 					),
80 80
 				),
81
-				'schema' => array( $this, 'get_public_item_schema' ),
81
+				'schema' => array($this, 'get_public_item_schema'),
82 82
 			)
83 83
 		);
84 84
 	}
@@ -89,18 +89,18 @@  discard block
 block discarded – undo
89 89
 	 * @param WP_REST_Request $request Request data.
90 90
 	 * @return WP_REST_Response|WP_Error
91 91
 	 */
92
-	public function get_item( $request ) {
93
-		$zone = $this->get_zone( $request->get_param( 'id' ) );
92
+	public function get_item($request) {
93
+		$zone = $this->get_zone($request->get_param('id'));
94 94
 
95
-		if ( is_wp_error( $zone ) ) {
95
+		if (is_wp_error($zone)) {
96 96
 			return $zone;
97 97
 		}
98 98
 
99 99
 		$data = $zone->get_data();
100
-		$data = $this->prepare_item_for_response( $data, $request );
101
-		$data = $this->prepare_response_for_collection( $data );
100
+		$data = $this->prepare_item_for_response($data, $request);
101
+		$data = $this->prepare_response_for_collection($data);
102 102
 
103
-		return rest_ensure_response( $data );
103
+		return rest_ensure_response($data);
104 104
 	}
105 105
 
106 106
 	/**
@@ -109,20 +109,20 @@  discard block
 block discarded – undo
109 109
 	 * @param WP_REST_Request $request Request data.
110 110
 	 * @return WP_REST_Response
111 111
 	 */
112
-	public function get_items( $request ) {
113
-		$rest_of_the_world = WC_Shipping_Zones::get_zone_by( 'zone_id', 0 );
112
+	public function get_items($request) {
113
+		$rest_of_the_world = WC_Shipping_Zones::get_zone_by('zone_id', 0);
114 114
 
115 115
 		$zones = WC_Shipping_Zones::get_zones();
116
-		array_unshift( $zones, $rest_of_the_world->get_data() );
116
+		array_unshift($zones, $rest_of_the_world->get_data());
117 117
 		$data = array();
118 118
 
119
-		foreach ( $zones as $zone_obj ) {
120
-			$zone   = $this->prepare_item_for_response( $zone_obj, $request );
121
-			$zone   = $this->prepare_response_for_collection( $zone );
119
+		foreach ($zones as $zone_obj) {
120
+			$zone   = $this->prepare_item_for_response($zone_obj, $request);
121
+			$zone   = $this->prepare_response_for_collection($zone);
122 122
 			$data[] = $zone;
123 123
 		}
124 124
 
125
-		return rest_ensure_response( $data );
125
+		return rest_ensure_response($data);
126 126
 	}
127 127
 
128 128
 	/**
@@ -131,27 +131,27 @@  discard block
 block discarded – undo
131 131
 	 * @param WP_REST_Request $request Full details about the request.
132 132
 	 * @return WP_REST_Request|WP_Error
133 133
 	 */
134
-	public function create_item( $request ) {
135
-		$zone = new WC_Shipping_Zone( null );
134
+	public function create_item($request) {
135
+		$zone = new WC_Shipping_Zone(null);
136 136
 
137
-		if ( ! is_null( $request->get_param( 'name' ) ) ) {
138
-			$zone->set_zone_name( $request->get_param( 'name' ) );
137
+		if ( ! is_null($request->get_param('name'))) {
138
+			$zone->set_zone_name($request->get_param('name'));
139 139
 		}
140 140
 
141
-		if ( ! is_null( $request->get_param( 'order' ) ) ) {
142
-			$zone->set_zone_order( $request->get_param( 'order' ) );
141
+		if ( ! is_null($request->get_param('order'))) {
142
+			$zone->set_zone_order($request->get_param('order'));
143 143
 		}
144 144
 
145 145
 		$zone->save();
146 146
 
147
-		if ( $zone->get_id() !== 0 ) {
148
-			$request->set_param( 'id', $zone->get_id() );
149
-			$response = $this->get_item( $request );
150
-			$response->set_status( 201 );
151
-			$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $zone->get_id() ) ) );
147
+		if ($zone->get_id() !== 0) {
148
+			$request->set_param('id', $zone->get_id());
149
+			$response = $this->get_item($request);
150
+			$response->set_status(201);
151
+			$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $zone->get_id())));
152 152
 			return $response;
153 153
 		} else {
154
-			return new WP_Error( 'woocommerce_rest_shipping_zone_not_created', __( "Resource cannot be created. Check to make sure 'order' and 'name' are present.", 'woocommerce' ), array( 'status' => 500 ) );
154
+			return new WP_Error('woocommerce_rest_shipping_zone_not_created', __("Resource cannot be created. Check to make sure 'order' and 'name' are present.", 'woocommerce'), array('status' => 500));
155 155
 		}
156 156
 	}
157 157
 
@@ -161,34 +161,34 @@  discard block
 block discarded – undo
161 161
 	 * @param WP_REST_Request $request Full details about the request.
162 162
 	 * @return WP_REST_Request|WP_Error
163 163
 	 */
164
-	public function update_item( $request ) {
165
-		$zone = $this->get_zone( $request->get_param( 'id' ) );
164
+	public function update_item($request) {
165
+		$zone = $this->get_zone($request->get_param('id'));
166 166
 
167
-		if ( is_wp_error( $zone ) ) {
167
+		if (is_wp_error($zone)) {
168 168
 			return $zone;
169 169
 		}
170 170
 
171
-		if ( 0 === $zone->get_id() ) {
172
-			return new WP_Error( 'woocommerce_rest_shipping_zone_invalid_zone', __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) );
171
+		if (0 === $zone->get_id()) {
172
+			return new WP_Error('woocommerce_rest_shipping_zone_invalid_zone', __('The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce'), array('status' => 403));
173 173
 		}
174 174
 
175 175
 		$zone_changed = false;
176 176
 
177
-		if ( ! is_null( $request->get_param( 'name' ) ) ) {
178
-			$zone->set_zone_name( $request->get_param( 'name' ) );
177
+		if ( ! is_null($request->get_param('name'))) {
178
+			$zone->set_zone_name($request->get_param('name'));
179 179
 			$zone_changed = true;
180 180
 		}
181 181
 
182
-		if ( ! is_null( $request->get_param( 'order' ) ) ) {
183
-			$zone->set_zone_order( $request->get_param( 'order' ) );
182
+		if ( ! is_null($request->get_param('order'))) {
183
+			$zone->set_zone_order($request->get_param('order'));
184 184
 			$zone_changed = true;
185 185
 		}
186 186
 
187
-		if ( $zone_changed ) {
187
+		if ($zone_changed) {
188 188
 			$zone->save();
189 189
 		}
190 190
 
191
-		return $this->get_item( $request );
191
+		return $this->get_item($request);
192 192
 	}
193 193
 
194 194
 	/**
@@ -197,21 +197,21 @@  discard block
 block discarded – undo
197 197
 	 * @param WP_REST_Request $request Full details about the request.
198 198
 	 * @return WP_REST_Request|WP_Error
199 199
 	 */
200
-	public function delete_item( $request ) {
201
-		$zone = $this->get_zone( $request->get_param( 'id' ) );
200
+	public function delete_item($request) {
201
+		$zone = $this->get_zone($request->get_param('id'));
202 202
 
203
-		if ( is_wp_error( $zone ) ) {
203
+		if (is_wp_error($zone)) {
204 204
 			return $zone;
205 205
 		}
206 206
 
207 207
 		$force = $request['force'];
208 208
 
209
-		$response = $this->get_item( $request );
209
+		$response = $this->get_item($request);
210 210
 
211
-		if ( $force ) {
211
+		if ($force) {
212 212
 			$zone->delete();
213 213
 		} else {
214
-			return new WP_Error( 'rest_trash_not_supported', __( 'Shipping zones do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
214
+			return new WP_Error('rest_trash_not_supported', __('Shipping zones do not support trashing.', 'woocommerce'), array('status' => 501));
215 215
 		}
216 216
 
217 217
 		return $response;
@@ -224,21 +224,21 @@  discard block
 block discarded – undo
224 224
 	 * @param WP_REST_Request $request Request object.
225 225
 	 * @return WP_REST_Response $response
226 226
 	 */
227
-	public function prepare_item_for_response( $item, $request ) {
227
+	public function prepare_item_for_response($item, $request) {
228 228
 		$data = array(
229 229
 			'id'    => (int) $item['id'],
230 230
 			'name'  => $item['zone_name'],
231 231
 			'order' => (int) $item['zone_order'],
232 232
 		);
233 233
 
234
-		$context = empty( $request['context'] ) ? 'view' : $request['context'];
235
-		$data    = $this->add_additional_fields_to_object( $data, $request );
236
-		$data    = $this->filter_response_by_context( $data, $context );
234
+		$context = empty($request['context']) ? 'view' : $request['context'];
235
+		$data    = $this->add_additional_fields_to_object($data, $request);
236
+		$data    = $this->filter_response_by_context($data, $context);
237 237
 
238 238
 		// Wrap the data in a response object.
239
-		$response = rest_ensure_response( $data );
239
+		$response = rest_ensure_response($data);
240 240
 
241
-		$response->add_links( $this->prepare_links( $data['id'] ) );
241
+		$response->add_links($this->prepare_links($data['id']));
242 242
 
243 243
 		return $response;
244 244
 	}
@@ -249,17 +249,17 @@  discard block
 block discarded – undo
249 249
 	 * @param int $zone_id Given Shipping Zone ID.
250 250
 	 * @return array Links for the given Shipping Zone.
251 251
 	 */
252
-	protected function prepare_links( $zone_id ) {
252
+	protected function prepare_links($zone_id) {
253 253
 		$base  = '/' . $this->namespace . '/' . $this->rest_base;
254 254
 		$links = array(
255 255
 			'self'        => array(
256
-				'href' => rest_url( trailingslashit( $base ) . $zone_id ),
256
+				'href' => rest_url(trailingslashit($base) . $zone_id),
257 257
 			),
258 258
 			'collection'  => array(
259
-				'href' => rest_url( $base ),
259
+				'href' => rest_url($base),
260 260
 			),
261 261
 			'describedby' => array(
262
-				'href' => rest_url( trailingslashit( $base ) . $zone_id . '/locations' ),
262
+				'href' => rest_url(trailingslashit($base) . $zone_id . '/locations'),
263 263
 			),
264 264
 		);
265 265
 
@@ -278,27 +278,27 @@  discard block
 block discarded – undo
278 278
 			'type'       => 'object',
279 279
 			'properties' => array(
280 280
 				'id'    => array(
281
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
281
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
282 282
 					'type'        => 'integer',
283
-					'context'     => array( 'view', 'edit' ),
283
+					'context'     => array('view', 'edit'),
284 284
 					'readonly'    => true,
285 285
 				),
286 286
 				'name'  => array(
287
-					'description' => __( 'Shipping zone name.', 'woocommerce' ),
287
+					'description' => __('Shipping zone name.', 'woocommerce'),
288 288
 					'type'        => 'string',
289
-					'context'     => array( 'view', 'edit' ),
289
+					'context'     => array('view', 'edit'),
290 290
 					'arg_options' => array(
291 291
 						'sanitize_callback' => 'sanitize_text_field',
292 292
 					),
293 293
 				),
294 294
 				'order' => array(
295
-					'description' => __( 'Shipping zone order.', 'woocommerce' ),
295
+					'description' => __('Shipping zone order.', 'woocommerce'),
296 296
 					'type'        => 'integer',
297
-					'context'     => array( 'view', 'edit' ),
297
+					'context'     => array('view', 'edit'),
298 298
 				),
299 299
 			),
300 300
 		);
301 301
 
302
-		return $this->add_additional_fields_schema( $schema );
302
+		return $this->add_additional_fields_schema($schema);
303 303
 	}
304 304
 }
Please login to merge, or discard this patch.
Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php 1 patch
Spacing   +140 added lines, -140 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
  * System status tools controller.
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
 			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
 					'args'                => $this->get_collection_params(),
48 48
 				),
49
-				'schema' => array( $this, 'get_public_item_schema' ),
49
+				'schema' => array($this, 'get_public_item_schema'),
50 50
 			)
51 51
 		);
52 52
 
@@ -56,22 +56,22 @@  discard block
 block discarded – undo
56 56
 			array(
57 57
 				'args'   => array(
58 58
 					'id' => array(
59
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
59
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
60 60
 						'type'        => 'string',
61 61
 					),
62 62
 				),
63 63
 				array(
64 64
 					'methods'             => WP_REST_Server::READABLE,
65
-					'callback'            => array( $this, 'get_item' ),
66
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
65
+					'callback'            => array($this, 'get_item'),
66
+					'permission_callback' => array($this, 'get_item_permissions_check'),
67 67
 				),
68 68
 				array(
69 69
 					'methods'             => WP_REST_Server::EDITABLE,
70
-					'callback'            => array( $this, 'update_item' ),
71
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
72
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
70
+					'callback'            => array($this, 'update_item'),
71
+					'permission_callback' => array($this, 'update_item_permissions_check'),
72
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
73 73
 				),
74
-				'schema' => array( $this, 'get_public_item_schema' ),
74
+				'schema' => array($this, 'get_public_item_schema'),
75 75
 			)
76 76
 		);
77 77
 	}
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 	 * @param  WP_REST_Request $request Full details about the request.
83 83
 	 * @return WP_Error|boolean
84 84
 	 */
85
-	public function get_items_permissions_check( $request ) {
86
-		if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) {
87
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
85
+	public function get_items_permissions_check($request) {
86
+		if ( ! wc_rest_check_manager_permissions('system_status', 'read')) {
87
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
88 88
 		}
89 89
 		return true;
90 90
 	}
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
 	 * @param  WP_REST_Request $request Full details about the request.
96 96
 	 * @return WP_Error|boolean
97 97
 	 */
98
-	public function get_item_permissions_check( $request ) {
99
-		if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) {
100
-			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
98
+	public function get_item_permissions_check($request) {
99
+		if ( ! wc_rest_check_manager_permissions('system_status', 'read')) {
100
+			return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
101 101
 		}
102 102
 		return true;
103 103
 	}
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
 	 * @param  WP_REST_Request $request Full details about the request.
109 109
 	 * @return WP_Error|boolean
110 110
 	 */
111
-	public function update_item_permissions_check( $request ) {
112
-		if ( ! wc_rest_check_manager_permissions( 'system_status', 'edit' ) ) {
113
-			return new WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot update resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
111
+	public function update_item_permissions_check($request) {
112
+		if ( ! wc_rest_check_manager_permissions('system_status', 'edit')) {
113
+			return new WP_Error('woocommerce_rest_cannot_update', __('Sorry, you cannot update resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
114 114
 		}
115 115
 		return true;
116 116
 	}
@@ -124,89 +124,89 @@  discard block
 block discarded – undo
124 124
 	public function get_tools() {
125 125
 		$tools = array(
126 126
 			'clear_transients'                   => array(
127
-				'name'   => __( 'WooCommerce transients', 'woocommerce' ),
128
-				'button' => __( 'Clear transients', 'woocommerce' ),
129
-				'desc'   => __( 'This tool will clear the product/shop transients cache.', 'woocommerce' ),
127
+				'name'   => __('WooCommerce transients', 'woocommerce'),
128
+				'button' => __('Clear transients', 'woocommerce'),
129
+				'desc'   => __('This tool will clear the product/shop transients cache.', 'woocommerce'),
130 130
 			),
131 131
 			'clear_expired_transients'           => array(
132
-				'name'   => __( 'Expired transients', 'woocommerce' ),
133
-				'button' => __( 'Clear transients', 'woocommerce' ),
134
-				'desc'   => __( 'This tool will clear ALL expired transients from WordPress.', 'woocommerce' ),
132
+				'name'   => __('Expired transients', 'woocommerce'),
133
+				'button' => __('Clear transients', 'woocommerce'),
134
+				'desc'   => __('This tool will clear ALL expired transients from WordPress.', 'woocommerce'),
135 135
 			),
136 136
 			'delete_orphaned_variations'         => array(
137
-				'name'   => __( 'Orphaned variations', 'woocommerce' ),
138
-				'button' => __( 'Delete orphaned variations', 'woocommerce' ),
139
-				'desc'   => __( 'This tool will delete all variations which have no parent.', 'woocommerce' ),
137
+				'name'   => __('Orphaned variations', 'woocommerce'),
138
+				'button' => __('Delete orphaned variations', 'woocommerce'),
139
+				'desc'   => __('This tool will delete all variations which have no parent.', 'woocommerce'),
140 140
 			),
141 141
 			'clear_expired_download_permissions' => array(
142
-				'name'   => __( 'Used-up download permissions', 'woocommerce' ),
143
-				'button' => __( 'Clean up download permissions', 'woocommerce' ),
144
-				'desc'   => __( 'This tool will delete expired download permissions and permissions with 0 remaining downloads.', 'woocommerce' ),
142
+				'name'   => __('Used-up download permissions', 'woocommerce'),
143
+				'button' => __('Clean up download permissions', 'woocommerce'),
144
+				'desc'   => __('This tool will delete expired download permissions and permissions with 0 remaining downloads.', 'woocommerce'),
145 145
 			),
146 146
 			'regenerate_product_lookup_tables' => array(
147
-				'name'   => __( 'Product lookup tables', 'woocommerce' ),
148
-				'button' => __( 'Regenerate', 'woocommerce' ),
149
-				'desc'   => __( 'This tool will regenerate product lookup table data. This process may take a while.', 'woocommerce' ),
147
+				'name'   => __('Product lookup tables', 'woocommerce'),
148
+				'button' => __('Regenerate', 'woocommerce'),
149
+				'desc'   => __('This tool will regenerate product lookup table data. This process may take a while.', 'woocommerce'),
150 150
 			),
151 151
 			'recount_terms'                      => array(
152
-				'name'   => __( 'Term counts', 'woocommerce' ),
153
-				'button' => __( 'Recount terms', 'woocommerce' ),
154
-				'desc'   => __( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', 'woocommerce' ),
152
+				'name'   => __('Term counts', 'woocommerce'),
153
+				'button' => __('Recount terms', 'woocommerce'),
154
+				'desc'   => __('This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', 'woocommerce'),
155 155
 			),
156 156
 			'reset_roles'                        => array(
157
-				'name'   => __( 'Capabilities', 'woocommerce' ),
158
-				'button' => __( 'Reset capabilities', 'woocommerce' ),
159
-				'desc'   => __( 'This tool will reset the admin, customer and shop_manager roles to default. Use this if your users cannot access all of the WooCommerce admin pages.', 'woocommerce' ),
157
+				'name'   => __('Capabilities', 'woocommerce'),
158
+				'button' => __('Reset capabilities', 'woocommerce'),
159
+				'desc'   => __('This tool will reset the admin, customer and shop_manager roles to default. Use this if your users cannot access all of the WooCommerce admin pages.', 'woocommerce'),
160 160
 			),
161 161
 			'clear_sessions'                     => array(
162
-				'name'   => __( 'Clear customer sessions', 'woocommerce' ),
163
-				'button' => __( 'Clear', 'woocommerce' ),
162
+				'name'   => __('Clear customer sessions', 'woocommerce'),
163
+				'button' => __('Clear', 'woocommerce'),
164 164
 				'desc'   => sprintf(
165 165
 					'<strong class="red">%1$s</strong> %2$s',
166
-					__( 'Note:', 'woocommerce' ),
167
-					__( 'This tool will delete all customer session data from the database, including current carts and saved carts in the database.', 'woocommerce' )
166
+					__('Note:', 'woocommerce'),
167
+					__('This tool will delete all customer session data from the database, including current carts and saved carts in the database.', 'woocommerce')
168 168
 				),
169 169
 			),
170 170
 			'install_pages'                      => array(
171
-				'name'   => __( 'Create default WooCommerce pages', 'woocommerce' ),
172
-				'button' => __( 'Create pages', 'woocommerce' ),
171
+				'name'   => __('Create default WooCommerce pages', 'woocommerce'),
172
+				'button' => __('Create pages', 'woocommerce'),
173 173
 				'desc'   => sprintf(
174 174
 					'<strong class="red">%1$s</strong> %2$s',
175
-					__( 'Note:', 'woocommerce' ),
176
-					__( 'This tool will install all the missing WooCommerce pages. Pages already defined and set up will not be replaced.', 'woocommerce' )
175
+					__('Note:', 'woocommerce'),
176
+					__('This tool will install all the missing WooCommerce pages. Pages already defined and set up will not be replaced.', 'woocommerce')
177 177
 				),
178 178
 			),
179 179
 			'delete_taxes'                       => array(
180
-				'name'   => __( 'Delete WooCommerce tax rates', 'woocommerce' ),
181
-				'button' => __( 'Delete tax rates', 'woocommerce' ),
180
+				'name'   => __('Delete WooCommerce tax rates', 'woocommerce'),
181
+				'button' => __('Delete tax rates', 'woocommerce'),
182 182
 				'desc'   => sprintf(
183 183
 					'<strong class="red">%1$s</strong> %2$s',
184
-					__( 'Note:', 'woocommerce' ),
185
-					__( 'This option will delete ALL of your tax rates, use with caution. This action cannot be reversed.', 'woocommerce' )
184
+					__('Note:', 'woocommerce'),
185
+					__('This option will delete ALL of your tax rates, use with caution. This action cannot be reversed.', 'woocommerce')
186 186
 				),
187 187
 			),
188 188
 			'regenerate_thumbnails'              => array(
189
-				'name'   => __( 'Regenerate shop thumbnails', 'woocommerce' ),
190
-				'button' => __( 'Regenerate', 'woocommerce' ),
191
-				'desc'   => __( 'This will regenerate all shop thumbnails to match your theme and/or image settings.', 'woocommerce' ),
189
+				'name'   => __('Regenerate shop thumbnails', 'woocommerce'),
190
+				'button' => __('Regenerate', 'woocommerce'),
191
+				'desc'   => __('This will regenerate all shop thumbnails to match your theme and/or image settings.', 'woocommerce'),
192 192
 			),
193 193
 			'db_update_routine'                  => array(
194
-				'name'   => __( 'Update database', 'woocommerce' ),
195
-				'button' => __( 'Update database', 'woocommerce' ),
194
+				'name'   => __('Update database', 'woocommerce'),
195
+				'button' => __('Update database', 'woocommerce'),
196 196
 				'desc'   => sprintf(
197 197
 					'<strong class="red">%1$s</strong> %2$s',
198
-					__( 'Note:', 'woocommerce' ),
199
-					__( 'This tool will update your WooCommerce database to the latest version. Please ensure you make sufficient backups before proceeding.', 'woocommerce' )
198
+					__('Note:', 'woocommerce'),
199
+					__('This tool will update your WooCommerce database to the latest version. Please ensure you make sufficient backups before proceeding.', 'woocommerce')
200 200
 				),
201 201
 			),
202 202
 		);
203 203
 
204 204
 		// Jetpack does the image resizing heavy lifting so you don't have to.
205
-		if ( ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) || ! apply_filters( 'woocommerce_background_image_regeneration', true ) ) {
206
-			unset( $tools['regenerate_thumbnails'] );
205
+		if ((class_exists('Jetpack') && Jetpack::is_module_active('photon')) || ! apply_filters('woocommerce_background_image_regeneration', true)) {
206
+			unset($tools['regenerate_thumbnails']);
207 207
 		}
208 208
 
209
-		return apply_filters( 'woocommerce_debug_tools', $tools );
209
+		return apply_filters('woocommerce_debug_tools', $tools);
210 210
 	}
211 211
 
212 212
 	/**
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
 	 * @param WP_REST_Request $request Full details about the request.
216 216
 	 * @return WP_Error|WP_REST_Response
217 217
 	 */
218
-	public function get_items( $request ) {
218
+	public function get_items($request) {
219 219
 		$tools = array();
220
-		foreach ( $this->get_tools() as $id => $tool ) {
220
+		foreach ($this->get_tools() as $id => $tool) {
221 221
 			$tools[] = $this->prepare_response_for_collection(
222 222
 				$this->prepare_item_for_response(
223 223
 					array(
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 			);
232 232
 		}
233 233
 
234
-		$response = rest_ensure_response( $tools );
234
+		$response = rest_ensure_response($tools);
235 235
 		return $response;
236 236
 	}
237 237
 
@@ -241,12 +241,12 @@  discard block
 block discarded – undo
241 241
 	 * @param  WP_REST_Request $request Request data.
242 242
 	 * @return WP_Error|WP_REST_Response
243 243
 	 */
244
-	public function get_item( $request ) {
244
+	public function get_item($request) {
245 245
 		$tools = $this->get_tools();
246
-		if ( empty( $tools[ $request['id'] ] ) ) {
247
-			return new WP_Error( 'woocommerce_rest_system_status_tool_invalid_id', __( 'Invalid tool ID.', 'woocommerce' ), array( 'status' => 404 ) );
246
+		if (empty($tools[$request['id']])) {
247
+			return new WP_Error('woocommerce_rest_system_status_tool_invalid_id', __('Invalid tool ID.', 'woocommerce'), array('status' => 404));
248 248
 		}
249
-		$tool = $tools[ $request['id'] ];
249
+		$tool = $tools[$request['id']];
250 250
 		return rest_ensure_response(
251 251
 			$this->prepare_item_for_response(
252 252
 				array(
@@ -266,13 +266,13 @@  discard block
 block discarded – undo
266 266
 	 * @param  WP_REST_Request $request Request data.
267 267
 	 * @return WP_Error|WP_REST_Response
268 268
 	 */
269
-	public function update_item( $request ) {
269
+	public function update_item($request) {
270 270
 		$tools = $this->get_tools();
271
-		if ( empty( $tools[ $request['id'] ] ) ) {
272
-			return new WP_Error( 'woocommerce_rest_system_status_tool_invalid_id', __( 'Invalid tool ID.', 'woocommerce' ), array( 'status' => 404 ) );
271
+		if (empty($tools[$request['id']])) {
272
+			return new WP_Error('woocommerce_rest_system_status_tool_invalid_id', __('Invalid tool ID.', 'woocommerce'), array('status' => 404));
273 273
 		}
274 274
 
275
-		$tool = $tools[ $request['id'] ];
275
+		$tool = $tools[$request['id']];
276 276
 		$tool = array(
277 277
 			'id'          => $request['id'],
278 278
 			'name'        => $tool['name'],
@@ -280,8 +280,8 @@  discard block
 block discarded – undo
280 280
 			'description' => $tool['desc'],
281 281
 		);
282 282
 
283
-		$execute_return = $this->execute_tool( $request['id'] );
284
-		$tool           = array_merge( $tool, $execute_return );
283
+		$execute_return = $this->execute_tool($request['id']);
284
+		$tool           = array_merge($tool, $execute_return);
285 285
 
286 286
 		/**
287 287
 		 * Fires after a WooCommerce REST system status tool has been executed.
@@ -289,11 +289,11 @@  discard block
 block discarded – undo
289 289
 		 * @param array           $tool    Details about the tool that has been executed.
290 290
 		 * @param WP_REST_Request $request The current WP_REST_Request object.
291 291
 		 */
292
-		do_action( 'woocommerce_rest_insert_system_status_tool', $tool, $request );
292
+		do_action('woocommerce_rest_insert_system_status_tool', $tool, $request);
293 293
 
294
-		$request->set_param( 'context', 'edit' );
295
-		$response = $this->prepare_item_for_response( $tool, $request );
296
-		return rest_ensure_response( $response );
294
+		$request->set_param('context', 'edit');
295
+		$response = $this->prepare_item_for_response($tool, $request);
296
+		return rest_ensure_response($response);
297 297
 	}
298 298
 
299 299
 	/**
@@ -303,14 +303,14 @@  discard block
 block discarded – undo
303 303
 	 * @param  WP_REST_Request $request  Request object.
304 304
 	 * @return WP_REST_Response $response Response data.
305 305
 	 */
306
-	public function prepare_item_for_response( $item, $request ) {
307
-		$context = empty( $request['context'] ) ? 'view' : $request['context'];
308
-		$data    = $this->add_additional_fields_to_object( $item, $request );
309
-		$data    = $this->filter_response_by_context( $data, $context );
306
+	public function prepare_item_for_response($item, $request) {
307
+		$context = empty($request['context']) ? 'view' : $request['context'];
308
+		$data    = $this->add_additional_fields_to_object($item, $request);
309
+		$data    = $this->filter_response_by_context($data, $context);
310 310
 
311
-		$response = rest_ensure_response( $data );
311
+		$response = rest_ensure_response($data);
312 312
 
313
-		$response->add_links( $this->prepare_links( $item['id'] ) );
313
+		$response->add_links($this->prepare_links($item['id']));
314 314
 
315 315
 		return $response;
316 316
 	}
@@ -327,46 +327,46 @@  discard block
 block discarded – undo
327 327
 			'type'       => 'object',
328 328
 			'properties' => array(
329 329
 				'id'          => array(
330
-					'description' => __( 'A unique identifier for the tool.', 'woocommerce' ),
330
+					'description' => __('A unique identifier for the tool.', 'woocommerce'),
331 331
 					'type'        => 'string',
332
-					'context'     => array( 'view', 'edit' ),
332
+					'context'     => array('view', 'edit'),
333 333
 					'arg_options' => array(
334 334
 						'sanitize_callback' => 'sanitize_title',
335 335
 					),
336 336
 				),
337 337
 				'name'        => array(
338
-					'description' => __( 'Tool name.', 'woocommerce' ),
338
+					'description' => __('Tool name.', 'woocommerce'),
339 339
 					'type'        => 'string',
340
-					'context'     => array( 'view', 'edit' ),
340
+					'context'     => array('view', 'edit'),
341 341
 					'arg_options' => array(
342 342
 						'sanitize_callback' => 'sanitize_text_field',
343 343
 					),
344 344
 				),
345 345
 				'action'      => array(
346
-					'description' => __( 'What running the tool will do.', 'woocommerce' ),
346
+					'description' => __('What running the tool will do.', 'woocommerce'),
347 347
 					'type'        => 'string',
348
-					'context'     => array( 'view', 'edit' ),
348
+					'context'     => array('view', 'edit'),
349 349
 					'arg_options' => array(
350 350
 						'sanitize_callback' => 'sanitize_text_field',
351 351
 					),
352 352
 				),
353 353
 				'description' => array(
354
-					'description' => __( 'Tool description.', 'woocommerce' ),
354
+					'description' => __('Tool description.', 'woocommerce'),
355 355
 					'type'        => 'string',
356
-					'context'     => array( 'view', 'edit' ),
356
+					'context'     => array('view', 'edit'),
357 357
 					'arg_options' => array(
358 358
 						'sanitize_callback' => 'sanitize_text_field',
359 359
 					),
360 360
 				),
361 361
 				'success'     => array(
362
-					'description' => __( 'Did the tool run successfully?', 'woocommerce' ),
362
+					'description' => __('Did the tool run successfully?', 'woocommerce'),
363 363
 					'type'        => 'boolean',
364
-					'context'     => array( 'edit' ),
364
+					'context'     => array('edit'),
365 365
 				),
366 366
 				'message'     => array(
367
-					'description' => __( 'Tool return message.', 'woocommerce' ),
367
+					'description' => __('Tool return message.', 'woocommerce'),
368 368
 					'type'        => 'string',
369
-					'context'     => array( 'edit' ),
369
+					'context'     => array('edit'),
370 370
 					'arg_options' => array(
371 371
 						'sanitize_callback' => 'sanitize_text_field',
372 372
 					),
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 			),
375 375
 		);
376 376
 
377
-		return $this->add_additional_fields_schema( $schema );
377
+		return $this->add_additional_fields_schema($schema);
378 378
 	}
379 379
 
380 380
 	/**
@@ -383,11 +383,11 @@  discard block
 block discarded – undo
383 383
 	 * @param string $id ID.
384 384
 	 * @return array
385 385
 	 */
386
-	protected function prepare_links( $id ) {
386
+	protected function prepare_links($id) {
387 387
 		$base  = '/' . $this->namespace . '/' . $this->rest_base;
388 388
 		$links = array(
389 389
 			'item' => array(
390
-				'href'       => rest_url( trailingslashit( $base ) . $id ),
390
+				'href'       => rest_url(trailingslashit($base) . $id),
391 391
 				'embeddable' => true,
392 392
 			),
393 393
 		);
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 	 */
403 403
 	public function get_collection_params() {
404 404
 		return array(
405
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
405
+			'context' => $this->get_context_param(array('default' => 'view')),
406 406
 		);
407 407
 	}
408 408
 
@@ -412,30 +412,30 @@  discard block
 block discarded – undo
412 412
 	 * @param  string $tool Tool.
413 413
 	 * @return array
414 414
 	 */
415
-	public function execute_tool( $tool ) {
415
+	public function execute_tool($tool) {
416 416
 		global $wpdb;
417 417
 		$ran = true;
418
-		switch ( $tool ) {
418
+		switch ($tool) {
419 419
 			case 'clear_transients':
420 420
 				wc_delete_product_transients();
421 421
 				wc_delete_shop_order_transients();
422
-				delete_transient( 'wc_count_comments' );
422
+				delete_transient('wc_count_comments');
423 423
 
424 424
 				$attribute_taxonomies = wc_get_attribute_taxonomies();
425 425
 
426
-				if ( $attribute_taxonomies ) {
427
-					foreach ( $attribute_taxonomies as $attribute ) {
428
-						delete_transient( 'wc_layered_nav_counts_pa_' . $attribute->attribute_name );
426
+				if ($attribute_taxonomies) {
427
+					foreach ($attribute_taxonomies as $attribute) {
428
+						delete_transient('wc_layered_nav_counts_pa_' . $attribute->attribute_name);
429 429
 					}
430 430
 				}
431 431
 
432
-				WC_Cache_Helper::get_transient_version( 'shipping', true );
433
-				$message = __( 'Product transients cleared', 'woocommerce' );
432
+				WC_Cache_Helper::get_transient_version('shipping', true);
433
+				$message = __('Product transients cleared', 'woocommerce');
434 434
 				break;
435 435
 
436 436
 			case 'clear_expired_transients':
437 437
 				/* translators: %d: amount of expired transients */
438
-				$message = sprintf( __( '%d transients rows cleared', 'woocommerce' ), wc_delete_expired_transients() );
438
+				$message = sprintf(__('%d transients rows cleared', 'woocommerce'), wc_delete_expired_transients());
439 439
 				break;
440 440
 
441 441
 			case 'delete_orphaned_variations':
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
 					)
450 450
 				);
451 451
 				/* translators: %d: amount of orphaned variations */
452
-				$message = sprintf( __( '%d orphaned variations deleted', 'woocommerce' ), $result );
452
+				$message = sprintf(__('%d orphaned variations deleted', 'woocommerce'), $result);
453 453
 				break;
454 454
 
455 455
 			case 'clear_expired_download_permissions':
@@ -459,25 +459,25 @@  discard block
 block discarded – undo
459 459
 						$wpdb->prepare(
460 460
 							"DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions
461 461
 							WHERE ( downloads_remaining != '' AND downloads_remaining = 0 ) OR ( access_expires IS NOT NULL AND access_expires < %s )",
462
-							date( 'Y-m-d', current_time( 'timestamp' ) )
462
+							date('Y-m-d', current_time('timestamp'))
463 463
 						)
464 464
 					)
465 465
 				);
466 466
 				/* translators: %d: amount of permissions */
467
-				$message = sprintf( __( '%d permissions deleted', 'woocommerce' ), $result );
467
+				$message = sprintf(__('%d permissions deleted', 'woocommerce'), $result);
468 468
 				break;
469 469
 
470 470
 			case 'regenerate_product_lookup_tables':
471
-				if ( ! wc_update_product_lookup_tables_is_running() ) {
471
+				if ( ! wc_update_product_lookup_tables_is_running()) {
472 472
 					wc_update_product_lookup_tables();
473 473
 				}
474
-				$message = __( 'Lookup tables are regenerating', 'woocommerce' );
474
+				$message = __('Lookup tables are regenerating', 'woocommerce');
475 475
 				break;
476 476
 			case 'reset_roles':
477 477
 				// Remove then re-add caps and roles.
478 478
 				WC_Install::remove_roles();
479 479
 				WC_Install::create_roles();
480
-				$message = __( 'Roles successfully reset', 'woocommerce' );
480
+				$message = __('Roles successfully reset', 'woocommerce');
481 481
 				break;
482 482
 
483 483
 			case 'recount_terms':
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 						'fields'     => 'id=>parent',
489 489
 					)
490 490
 				);
491
-				_wc_term_recount( $product_cats, get_taxonomy( 'product_cat' ), true, false );
491
+				_wc_term_recount($product_cats, get_taxonomy('product_cat'), true, false);
492 492
 				$product_tags = get_terms(
493 493
 					'product_tag',
494 494
 					array(
@@ -496,61 +496,61 @@  discard block
 block discarded – undo
496 496
 						'fields'     => 'id=>parent',
497 497
 					)
498 498
 				);
499
-				_wc_term_recount( $product_tags, get_taxonomy( 'product_tag' ), true, false );
500
-				$message = __( 'Terms successfully recounted', 'woocommerce' );
499
+				_wc_term_recount($product_tags, get_taxonomy('product_tag'), true, false);
500
+				$message = __('Terms successfully recounted', 'woocommerce');
501 501
 				break;
502 502
 
503 503
 			case 'clear_sessions':
504
-				$wpdb->query( "TRUNCATE {$wpdb->prefix}woocommerce_sessions" );
505
-				$result = absint( $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key='_woocommerce_persistent_cart_" . get_current_blog_id() . "';" ) ); // WPCS: unprepared SQL ok.
504
+				$wpdb->query("TRUNCATE {$wpdb->prefix}woocommerce_sessions");
505
+				$result = absint($wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key='_woocommerce_persistent_cart_" . get_current_blog_id() . "';")); // WPCS: unprepared SQL ok.
506 506
 				wp_cache_flush();
507 507
 				/* translators: %d: amount of sessions */
508
-				$message = sprintf( __( 'Deleted all active sessions, and %d saved carts.', 'woocommerce' ), absint( $result ) );
508
+				$message = sprintf(__('Deleted all active sessions, and %d saved carts.', 'woocommerce'), absint($result));
509 509
 				break;
510 510
 
511 511
 			case 'install_pages':
512 512
 				WC_Install::create_pages();
513
-				$message = __( 'All missing WooCommerce pages successfully installed', 'woocommerce' );
513
+				$message = __('All missing WooCommerce pages successfully installed', 'woocommerce');
514 514
 				break;
515 515
 
516 516
 			case 'delete_taxes':
517
-				$wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rates;" );
518
-				$wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations;" );
519
-				WC_Cache_Helper::incr_cache_prefix( 'taxes' );
520
-				$message = __( 'Tax rates successfully deleted', 'woocommerce' );
517
+				$wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rates;");
518
+				$wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations;");
519
+				WC_Cache_Helper::incr_cache_prefix('taxes');
520
+				$message = __('Tax rates successfully deleted', 'woocommerce');
521 521
 				break;
522 522
 
523 523
 			case 'regenerate_thumbnails':
524 524
 				WC_Regenerate_Images::queue_image_regeneration();
525
-				$message = __( 'Thumbnail regeneration has been scheduled to run in the background.', 'woocommerce' );
525
+				$message = __('Thumbnail regeneration has been scheduled to run in the background.', 'woocommerce');
526 526
 				break;
527 527
 
528 528
 			case 'db_update_routine':
529 529
 				$blog_id = get_current_blog_id();
530 530
 				// Used to fire an action added in WP_Background_Process::_construct() that calls WP_Background_Process::handle_cron_healthcheck().
531 531
 				// This method will make sure the database updates are executed even if cron is disabled. Nothing will happen if the updates are already running.
532
-				do_action( 'wp_' . $blog_id . '_wc_updater_cron' );
533
-				$message = __( 'Database upgrade routine has been scheduled to run in the background.', 'woocommerce' );
532
+				do_action('wp_' . $blog_id . '_wc_updater_cron');
533
+				$message = __('Database upgrade routine has been scheduled to run in the background.', 'woocommerce');
534 534
 				break;
535 535
 
536 536
 			default:
537 537
 				$tools = $this->get_tools();
538
-				if ( isset( $tools[ $tool ]['callback'] ) ) {
539
-					$callback = $tools[ $tool ]['callback'];
540
-					$return   = call_user_func( $callback );
541
-					if ( is_string( $return ) ) {
538
+				if (isset($tools[$tool]['callback'])) {
539
+					$callback = $tools[$tool]['callback'];
540
+					$return   = call_user_func($callback);
541
+					if (is_string($return)) {
542 542
 						$message = $return;
543
-					} elseif ( false === $return ) {
544
-						$callback_string = is_array( $callback ) ? get_class( $callback[0] ) . '::' . $callback[1] : $callback;
543
+					} elseif (false === $return) {
544
+						$callback_string = is_array($callback) ? get_class($callback[0]) . '::' . $callback[1] : $callback;
545 545
 						$ran             = false;
546 546
 						/* translators: %s: callback string */
547
-						$message = sprintf( __( 'There was an error calling %s', 'woocommerce' ), $callback_string );
547
+						$message = sprintf(__('There was an error calling %s', 'woocommerce'), $callback_string);
548 548
 					} else {
549
-						$message = __( 'Tool ran.', 'woocommerce' );
549
+						$message = __('Tool ran.', 'woocommerce');
550 550
 					}
551 551
 				} else {
552 552
 					$ran     = false;
553
-					$message = __( 'There was an error calling this tool. There is no callback present.', 'woocommerce' );
553
+					$message = __('There was an error calling this tool. There is no callback present.', 'woocommerce');
554 554
 				}
555 555
 				break;
556 556
 		}
Please login to merge, or discard this patch.
src/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php 1 patch
Spacing   +147 added lines, -147 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 Refunds controller class.
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * Order refunds actions.
51 51
 	 */
52 52
 	public function __construct() {
53
-		add_filter( "woocommerce_rest_{$this->post_type}_object_trashable", '__return_false' );
53
+		add_filter("woocommerce_rest_{$this->post_type}_object_trashable", '__return_false');
54 54
 	}
55 55
 
56 56
 	/**
@@ -61,23 +61,23 @@  discard block
 block discarded – undo
61 61
 			$this->namespace, '/' . $this->rest_base, array(
62 62
 				'args'   => array(
63 63
 					'order_id' => array(
64
-						'description' => __( 'The order ID.', 'woocommerce' ),
64
+						'description' => __('The order ID.', 'woocommerce'),
65 65
 						'type'        => 'integer',
66 66
 					),
67 67
 				),
68 68
 				array(
69 69
 					'methods'             => WP_REST_Server::READABLE,
70
-					'callback'            => array( $this, 'get_items' ),
71
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
70
+					'callback'            => array($this, 'get_items'),
71
+					'permission_callback' => array($this, 'get_items_permissions_check'),
72 72
 					'args'                => $this->get_collection_params(),
73 73
 				),
74 74
 				array(
75 75
 					'methods'             => WP_REST_Server::CREATABLE,
76
-					'callback'            => array( $this, 'create_item' ),
77
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
78
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
76
+					'callback'            => array($this, 'create_item'),
77
+					'permission_callback' => array($this, 'create_item_permissions_check'),
78
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
79 79
 				),
80
-				'schema' => array( $this, 'get_public_item_schema' ),
80
+				'schema' => array($this, 'get_public_item_schema'),
81 81
 			)
82 82
 		);
83 83
 
@@ -85,35 +85,35 @@  discard block
 block discarded – undo
85 85
 			$this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
86 86
 				'args'   => array(
87 87
 					'order_id' => array(
88
-						'description' => __( 'The order ID.', 'woocommerce' ),
88
+						'description' => __('The order ID.', 'woocommerce'),
89 89
 						'type'        => 'integer',
90 90
 					),
91 91
 					'id'       => array(
92
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
92
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
93 93
 						'type'        => 'integer',
94 94
 					),
95 95
 				),
96 96
 				array(
97 97
 					'methods'             => WP_REST_Server::READABLE,
98
-					'callback'            => array( $this, 'get_item' ),
99
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
98
+					'callback'            => array($this, 'get_item'),
99
+					'permission_callback' => array($this, 'get_item_permissions_check'),
100 100
 					'args'                => array(
101
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
101
+						'context' => $this->get_context_param(array('default' => 'view')),
102 102
 					),
103 103
 				),
104 104
 				array(
105 105
 					'methods'             => WP_REST_Server::DELETABLE,
106
-					'callback'            => array( $this, 'delete_item' ),
107
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
106
+					'callback'            => array($this, 'delete_item'),
107
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
108 108
 					'args'                => array(
109 109
 						'force' => array(
110 110
 							'default'     => true,
111 111
 							'type'        => 'boolean',
112
-							'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
112
+							'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
113 113
 						),
114 114
 					),
115 115
 				),
116
-				'schema' => array( $this, 'get_public_item_schema' ),
116
+				'schema' => array($this, 'get_public_item_schema'),
117 117
 			)
118 118
 		);
119 119
 	}
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
 	 * @param  int $id Object ID.
126 126
 	 * @return WC_Data
127 127
 	 */
128
-	protected function get_object( $id ) {
129
-		return wc_get_order( $id );
128
+	protected function get_object($id) {
129
+		return wc_get_order($id);
130 130
 	}
131 131
 
132 132
 	/**
@@ -136,27 +136,27 @@  discard block
 block discarded – undo
136 136
 	 * @param  WC_Data $object WC_Data instance.
137 137
 	 * @return array
138 138
 	 */
139
-	protected function get_formatted_item_data( $object ) {
139
+	protected function get_formatted_item_data($object) {
140 140
 		$data              = $object->get_data();
141
-		$format_decimal    = array( 'amount' );
142
-		$format_date       = array( 'date_created' );
143
-		$format_line_items = array( 'line_items' );
141
+		$format_decimal    = array('amount');
142
+		$format_date       = array('date_created');
143
+		$format_line_items = array('line_items');
144 144
 
145 145
 		// Format decimal values.
146
-		foreach ( $format_decimal as $key ) {
147
-			$data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] );
146
+		foreach ($format_decimal as $key) {
147
+			$data[$key] = wc_format_decimal($data[$key], $this->request['dp']);
148 148
 		}
149 149
 
150 150
 		// Format date values.
151
-		foreach ( $format_date as $key ) {
152
-			$datetime              = $data[ $key ];
153
-			$data[ $key ]          = wc_rest_prepare_date_response( $datetime, false );
154
-			$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
151
+		foreach ($format_date as $key) {
152
+			$datetime              = $data[$key];
153
+			$data[$key]          = wc_rest_prepare_date_response($datetime, false);
154
+			$data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime);
155 155
 		}
156 156
 
157 157
 		// Format line items.
158
-		foreach ( $format_line_items as $key ) {
159
-			$data[ $key ] = array_values( array_map( array( $this, 'get_order_item_data' ), $data[ $key ] ) );
158
+		foreach ($format_line_items as $key) {
159
+			$data[$key] = array_values(array_map(array($this, 'get_order_item_data'), $data[$key]));
160 160
 		}
161 161
 
162 162
 		return array(
@@ -182,28 +182,28 @@  discard block
 block discarded – undo
182 182
 	 *
183 183
 	 * @return WP_Error|WP_REST_Response
184 184
 	 */
185
-	public function prepare_object_for_response( $object, $request ) {
185
+	public function prepare_object_for_response($object, $request) {
186 186
 		$this->request       = $request;
187
-		$this->request['dp'] = is_null( $this->request['dp'] ) ? wc_get_price_decimals() : absint( $this->request['dp'] );
188
-		$order               = wc_get_order( (int) $request['order_id'] );
187
+		$this->request['dp'] = is_null($this->request['dp']) ? wc_get_price_decimals() : absint($this->request['dp']);
188
+		$order               = wc_get_order((int) $request['order_id']);
189 189
 
190
-		if ( ! $order ) {
191
-			return new WP_Error( 'woocommerce_rest_invalid_order_id', __( 'Invalid order ID.', 'woocommerce' ), 404 );
190
+		if ( ! $order) {
191
+			return new WP_Error('woocommerce_rest_invalid_order_id', __('Invalid order ID.', 'woocommerce'), 404);
192 192
 		}
193 193
 
194
-		if ( ! $object || $object->get_parent_id() !== $order->get_id() ) {
195
-			return new WP_Error( 'woocommerce_rest_invalid_order_refund_id', __( 'Invalid order refund ID.', 'woocommerce' ), 404 );
194
+		if ( ! $object || $object->get_parent_id() !== $order->get_id()) {
195
+			return new WP_Error('woocommerce_rest_invalid_order_refund_id', __('Invalid order refund ID.', 'woocommerce'), 404);
196 196
 		}
197 197
 
198
-		$data    = $this->get_formatted_item_data( $object );
199
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
200
-		$data    = $this->add_additional_fields_to_object( $data, $request );
201
-		$data    = $this->filter_response_by_context( $data, $context );
198
+		$data    = $this->get_formatted_item_data($object);
199
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
200
+		$data    = $this->add_additional_fields_to_object($data, $request);
201
+		$data    = $this->filter_response_by_context($data, $context);
202 202
 
203 203
 		// Wrap the data in a response object.
204
-		$response = rest_ensure_response( $data );
204
+		$response = rest_ensure_response($data);
205 205
 
206
-		$response->add_links( $this->prepare_links( $object, $request ) );
206
+		$response->add_links($this->prepare_links($object, $request));
207 207
 
208 208
 		/**
209 209
 		 * Filter the data for a response.
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 		 * @param WC_Data          $object   Object data.
216 216
 		 * @param WP_REST_Request  $request  Request object.
217 217
 		 */
218
-		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
218
+		return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request);
219 219
 	}
220 220
 
221 221
 	/**
@@ -225,17 +225,17 @@  discard block
 block discarded – undo
225 225
 	 * @param WP_REST_Request $request Request object.
226 226
 	 * @return array                   Links for the given post.
227 227
 	 */
228
-	protected function prepare_links( $object, $request ) {
229
-		$base  = str_replace( '(?P<order_id>[\d]+)', $object->get_parent_id(), $this->rest_base );
228
+	protected function prepare_links($object, $request) {
229
+		$base  = str_replace('(?P<order_id>[\d]+)', $object->get_parent_id(), $this->rest_base);
230 230
 		$links = array(
231 231
 			'self'       => array(
232
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $object->get_id() ) ),
232
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $object->get_id())),
233 233
 			),
234 234
 			'collection' => array(
235
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
235
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)),
236 236
 			),
237 237
 			'up'         => array(
238
-				'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $object->get_parent_id() ) ),
238
+				'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $object->get_parent_id())),
239 239
 			),
240 240
 		);
241 241
 
@@ -249,11 +249,11 @@  discard block
 block discarded – undo
249 249
 	 * @param  WP_REST_Request $request Full details about the request.
250 250
 	 * @return array
251 251
 	 */
252
-	protected function prepare_objects_query( $request ) {
253
-		$args = parent::prepare_objects_query( $request );
252
+	protected function prepare_objects_query($request) {
253
+		$args = parent::prepare_objects_query($request);
254 254
 
255
-		$args['post_status']     = array_keys( wc_get_order_statuses() );
256
-		$args['post_parent__in'] = array( absint( $request['order_id'] ) );
255
+		$args['post_status']     = array_keys(wc_get_order_statuses());
256
+		$args['post_parent__in'] = array(absint($request['order_id']));
257 257
 
258 258
 		return $args;
259 259
 	}
@@ -266,15 +266,15 @@  discard block
 block discarded – undo
266 266
 	 * @param  bool            $creating If is creating a new object.
267 267
 	 * @return WP_Error|WC_Data The prepared item, or WP_Error object on failure.
268 268
 	 */
269
-	protected function prepare_object_for_database( $request, $creating = false ) {
270
-		$order = wc_get_order( (int) $request['order_id'] );
269
+	protected function prepare_object_for_database($request, $creating = false) {
270
+		$order = wc_get_order((int) $request['order_id']);
271 271
 
272
-		if ( ! $order ) {
273
-			return new WP_Error( 'woocommerce_rest_invalid_order_id', __( 'Invalid order ID.', 'woocommerce' ), 404 );
272
+		if ( ! $order) {
273
+			return new WP_Error('woocommerce_rest_invalid_order_id', __('Invalid order ID.', 'woocommerce'), 404);
274 274
 		}
275 275
 
276
-		if ( 0 > $request['amount'] ) {
277
-			return new WP_Error( 'woocommerce_rest_invalid_order_refund', __( 'Refund amount must be greater than zero.', 'woocommerce' ), 400 );
276
+		if (0 > $request['amount']) {
277
+			return new WP_Error('woocommerce_rest_invalid_order_refund', __('Refund amount must be greater than zero.', 'woocommerce'), 400);
278 278
 		}
279 279
 
280 280
 		// Create the refund.
@@ -282,23 +282,23 @@  discard block
 block discarded – undo
282 282
 			array(
283 283
 				'order_id'       => $order->get_id(),
284 284
 				'amount'         => $request['amount'],
285
-				'reason'         => empty( $request['reason'] ) ? null : $request['reason'],
286
-				'refund_payment' => is_bool( $request['api_refund'] ) ? $request['api_refund'] : true,
285
+				'reason'         => empty($request['reason']) ? null : $request['reason'],
286
+				'refund_payment' => is_bool($request['api_refund']) ? $request['api_refund'] : true,
287 287
 				'restock_items'  => true,
288 288
 			)
289 289
 		);
290 290
 
291
-		if ( is_wp_error( $refund ) ) {
292
-			return new WP_Error( 'woocommerce_rest_cannot_create_order_refund', $refund->get_error_message(), 500 );
291
+		if (is_wp_error($refund)) {
292
+			return new WP_Error('woocommerce_rest_cannot_create_order_refund', $refund->get_error_message(), 500);
293 293
 		}
294 294
 
295
-		if ( ! $refund ) {
296
-			return new WP_Error( 'woocommerce_rest_cannot_create_order_refund', __( 'Cannot create order refund, please try again.', 'woocommerce' ), 500 );
295
+		if ( ! $refund) {
296
+			return new WP_Error('woocommerce_rest_cannot_create_order_refund', __('Cannot create order refund, please try again.', 'woocommerce'), 500);
297 297
 		}
298 298
 
299
-		if ( ! empty( $request['meta_data'] ) && is_array( $request['meta_data'] ) ) {
300
-			foreach ( $request['meta_data'] as $meta ) {
301
-				$refund->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
299
+		if ( ! empty($request['meta_data']) && is_array($request['meta_data'])) {
300
+			foreach ($request['meta_data'] as $meta) {
301
+				$refund->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
302 302
 			}
303 303
 			$refund->save_meta_data();
304 304
 		}
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 		 * @param WP_REST_Request $request  Request object.
314 314
 		 * @param bool            $creating If is creating a new object.
315 315
 		 */
316
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $refund, $request, $creating );
316
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $refund, $request, $creating);
317 317
 	}
318 318
 
319 319
 	/**
@@ -324,19 +324,19 @@  discard block
 block discarded – undo
324 324
 	 * @param  bool            $creating If is creating a new object.
325 325
 	 * @return WC_Data|WP_Error
326 326
 	 */
327
-	protected function save_object( $request, $creating = false ) {
327
+	protected function save_object($request, $creating = false) {
328 328
 		try {
329
-			$object = $this->prepare_object_for_database( $request, $creating );
329
+			$object = $this->prepare_object_for_database($request, $creating);
330 330
 
331
-			if ( is_wp_error( $object ) ) {
331
+			if (is_wp_error($object)) {
332 332
 				return $object;
333 333
 			}
334 334
 
335
-			return $this->get_object( $object->get_id() );
336
-		} catch ( WC_Data_Exception $e ) {
337
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
338
-		} catch ( WC_REST_Exception $e ) {
339
-			return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
335
+			return $this->get_object($object->get_id());
336
+		} catch (WC_Data_Exception $e) {
337
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData());
338
+		} catch (WC_REST_Exception $e) {
339
+			return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
340 340
 		}
341 341
 	}
342 342
 
@@ -352,221 +352,221 @@  discard block
 block discarded – undo
352 352
 			'type'       => 'object',
353 353
 			'properties' => array(
354 354
 				'id'               => array(
355
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
355
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
356 356
 					'type'        => 'integer',
357
-					'context'     => array( 'view', 'edit' ),
357
+					'context'     => array('view', 'edit'),
358 358
 					'readonly'    => true,
359 359
 				),
360 360
 				'date_created'     => array(
361
-					'description' => __( "The date the order refund was created, in the site's timezone.", 'woocommerce' ),
361
+					'description' => __("The date the order refund was created, in the site's timezone.", 'woocommerce'),
362 362
 					'type'        => 'date-time',
363
-					'context'     => array( 'view', 'edit' ),
363
+					'context'     => array('view', 'edit'),
364 364
 					'readonly'    => true,
365 365
 				),
366 366
 				'date_created_gmt' => array(
367
-					'description' => __( 'The date the order refund was created, as GMT.', 'woocommerce' ),
367
+					'description' => __('The date the order refund was created, as GMT.', 'woocommerce'),
368 368
 					'type'        => 'date-time',
369
-					'context'     => array( 'view', 'edit' ),
369
+					'context'     => array('view', 'edit'),
370 370
 					'readonly'    => true,
371 371
 				),
372 372
 				'amount'           => array(
373
-					'description' => __( 'Refund amount.', 'woocommerce' ),
373
+					'description' => __('Refund amount.', 'woocommerce'),
374 374
 					'type'        => 'string',
375
-					'context'     => array( 'view', 'edit' ),
375
+					'context'     => array('view', 'edit'),
376 376
 				),
377 377
 				'reason'           => array(
378
-					'description' => __( 'Reason for refund.', 'woocommerce' ),
378
+					'description' => __('Reason for refund.', 'woocommerce'),
379 379
 					'type'        => 'string',
380
-					'context'     => array( 'view', 'edit' ),
380
+					'context'     => array('view', 'edit'),
381 381
 				),
382 382
 				'refunded_by'      => array(
383
-					'description' => __( 'User ID of user who created the refund.', 'woocommerce' ),
383
+					'description' => __('User ID of user who created the refund.', 'woocommerce'),
384 384
 					'type'        => 'integer',
385
-					'context'     => array( 'view', 'edit' ),
385
+					'context'     => array('view', 'edit'),
386 386
 				),
387 387
 				'refunded_payment' => array(
388
-					'description' => __( 'If the payment was refunded via the API.', 'woocommerce' ),
388
+					'description' => __('If the payment was refunded via the API.', 'woocommerce'),
389 389
 					'type'        => 'boolean',
390
-					'context'     => array( 'view' ),
390
+					'context'     => array('view'),
391 391
 					'readonly'    => true,
392 392
 				),
393 393
 				'meta_data'        => array(
394
-					'description' => __( 'Meta data.', 'woocommerce' ),
394
+					'description' => __('Meta data.', 'woocommerce'),
395 395
 					'type'        => 'array',
396
-					'context'     => array( 'view', 'edit' ),
396
+					'context'     => array('view', 'edit'),
397 397
 					'items'       => array(
398 398
 						'type'       => 'object',
399 399
 						'properties' => array(
400 400
 							'id'    => array(
401
-								'description' => __( 'Meta ID.', 'woocommerce' ),
401
+								'description' => __('Meta ID.', 'woocommerce'),
402 402
 								'type'        => 'integer',
403
-								'context'     => array( 'view', 'edit' ),
403
+								'context'     => array('view', 'edit'),
404 404
 								'readonly'    => true,
405 405
 							),
406 406
 							'key'   => array(
407
-								'description' => __( 'Meta key.', 'woocommerce' ),
407
+								'description' => __('Meta key.', 'woocommerce'),
408 408
 								'type'        => 'string',
409
-								'context'     => array( 'view', 'edit' ),
409
+								'context'     => array('view', 'edit'),
410 410
 							),
411 411
 							'value' => array(
412
-								'description' => __( 'Meta value.', 'woocommerce' ),
412
+								'description' => __('Meta value.', 'woocommerce'),
413 413
 								'type'        => 'mixed',
414
-								'context'     => array( 'view', 'edit' ),
414
+								'context'     => array('view', 'edit'),
415 415
 							),
416 416
 						),
417 417
 					),
418 418
 				),
419 419
 				'line_items'       => array(
420
-					'description' => __( 'Line items data.', 'woocommerce' ),
420
+					'description' => __('Line items data.', 'woocommerce'),
421 421
 					'type'        => 'array',
422
-					'context'     => array( 'view', 'edit' ),
422
+					'context'     => array('view', 'edit'),
423 423
 					'readonly'    => true,
424 424
 					'items'       => array(
425 425
 						'type'       => 'object',
426 426
 						'properties' => array(
427 427
 							'id'           => array(
428
-								'description' => __( 'Item ID.', 'woocommerce' ),
428
+								'description' => __('Item ID.', 'woocommerce'),
429 429
 								'type'        => 'integer',
430
-								'context'     => array( 'view', 'edit' ),
430
+								'context'     => array('view', 'edit'),
431 431
 								'readonly'    => true,
432 432
 							),
433 433
 							'name'         => array(
434
-								'description' => __( 'Product name.', 'woocommerce' ),
434
+								'description' => __('Product name.', 'woocommerce'),
435 435
 								'type'        => 'mixed',
436
-								'context'     => array( 'view', 'edit' ),
436
+								'context'     => array('view', 'edit'),
437 437
 								'readonly'    => true,
438 438
 							),
439 439
 							'product_id'   => array(
440
-								'description' => __( 'Product ID.', 'woocommerce' ),
440
+								'description' => __('Product ID.', 'woocommerce'),
441 441
 								'type'        => 'mixed',
442
-								'context'     => array( 'view', 'edit' ),
442
+								'context'     => array('view', 'edit'),
443 443
 								'readonly'    => true,
444 444
 							),
445 445
 							'variation_id' => array(
446
-								'description' => __( 'Variation ID, if applicable.', 'woocommerce' ),
446
+								'description' => __('Variation ID, if applicable.', 'woocommerce'),
447 447
 								'type'        => 'integer',
448
-								'context'     => array( 'view', 'edit' ),
448
+								'context'     => array('view', 'edit'),
449 449
 								'readonly'    => true,
450 450
 							),
451 451
 							'quantity'     => array(
452
-								'description' => __( 'Quantity ordered.', 'woocommerce' ),
452
+								'description' => __('Quantity ordered.', 'woocommerce'),
453 453
 								'type'        => 'integer',
454
-								'context'     => array( 'view', 'edit' ),
454
+								'context'     => array('view', 'edit'),
455 455
 								'readonly'    => true,
456 456
 							),
457 457
 							'tax_class'    => array(
458
-								'description' => __( 'Tax class of product.', 'woocommerce' ),
458
+								'description' => __('Tax class of product.', 'woocommerce'),
459 459
 								'type'        => 'string',
460
-								'context'     => array( 'view', 'edit' ),
460
+								'context'     => array('view', 'edit'),
461 461
 								'readonly'    => true,
462 462
 							),
463 463
 							'subtotal'     => array(
464
-								'description' => __( 'Line subtotal (before discounts).', 'woocommerce' ),
464
+								'description' => __('Line subtotal (before discounts).', 'woocommerce'),
465 465
 								'type'        => 'string',
466
-								'context'     => array( 'view', 'edit' ),
466
+								'context'     => array('view', 'edit'),
467 467
 								'readonly'    => true,
468 468
 							),
469 469
 							'subtotal_tax' => array(
470
-								'description' => __( 'Line subtotal tax (before discounts).', 'woocommerce' ),
470
+								'description' => __('Line subtotal tax (before discounts).', 'woocommerce'),
471 471
 								'type'        => 'string',
472
-								'context'     => array( 'view', 'edit' ),
472
+								'context'     => array('view', 'edit'),
473 473
 								'readonly'    => true,
474 474
 							),
475 475
 							'total'        => array(
476
-								'description' => __( 'Line total (after discounts).', 'woocommerce' ),
476
+								'description' => __('Line total (after discounts).', 'woocommerce'),
477 477
 								'type'        => 'string',
478
-								'context'     => array( 'view', 'edit' ),
478
+								'context'     => array('view', 'edit'),
479 479
 								'readonly'    => true,
480 480
 							),
481 481
 							'total_tax'    => array(
482
-								'description' => __( 'Line total tax (after discounts).', 'woocommerce' ),
482
+								'description' => __('Line total tax (after discounts).', 'woocommerce'),
483 483
 								'type'        => 'string',
484
-								'context'     => array( 'view', 'edit' ),
484
+								'context'     => array('view', 'edit'),
485 485
 								'readonly'    => true,
486 486
 							),
487 487
 							'taxes'        => array(
488
-								'description' => __( 'Line taxes.', 'woocommerce' ),
488
+								'description' => __('Line taxes.', 'woocommerce'),
489 489
 								'type'        => 'array',
490
-								'context'     => array( 'view', 'edit' ),
490
+								'context'     => array('view', 'edit'),
491 491
 								'readonly'    => true,
492 492
 								'items'       => array(
493 493
 									'type'       => 'object',
494 494
 									'properties' => array(
495 495
 										'id'       => array(
496
-											'description' => __( 'Tax rate ID.', 'woocommerce' ),
496
+											'description' => __('Tax rate ID.', 'woocommerce'),
497 497
 											'type'        => 'integer',
498
-											'context'     => array( 'view', 'edit' ),
498
+											'context'     => array('view', 'edit'),
499 499
 											'readonly'    => true,
500 500
 										),
501 501
 										'total'    => array(
502
-											'description' => __( 'Tax total.', 'woocommerce' ),
502
+											'description' => __('Tax total.', 'woocommerce'),
503 503
 											'type'        => 'string',
504
-											'context'     => array( 'view', 'edit' ),
504
+											'context'     => array('view', 'edit'),
505 505
 											'readonly'    => true,
506 506
 										),
507 507
 										'subtotal' => array(
508
-											'description' => __( 'Tax subtotal.', 'woocommerce' ),
508
+											'description' => __('Tax subtotal.', 'woocommerce'),
509 509
 											'type'        => 'string',
510
-											'context'     => array( 'view', 'edit' ),
510
+											'context'     => array('view', 'edit'),
511 511
 											'readonly'    => true,
512 512
 										),
513 513
 									),
514 514
 								),
515 515
 							),
516 516
 							'meta_data'    => array(
517
-								'description' => __( 'Meta data.', 'woocommerce' ),
517
+								'description' => __('Meta data.', 'woocommerce'),
518 518
 								'type'        => 'array',
519
-								'context'     => array( 'view', 'edit' ),
519
+								'context'     => array('view', 'edit'),
520 520
 								'readonly'    => true,
521 521
 								'items'       => array(
522 522
 									'type'       => 'object',
523 523
 									'properties' => array(
524 524
 										'id'    => array(
525
-											'description' => __( 'Meta ID.', 'woocommerce' ),
525
+											'description' => __('Meta ID.', 'woocommerce'),
526 526
 											'type'        => 'integer',
527
-											'context'     => array( 'view', 'edit' ),
527
+											'context'     => array('view', 'edit'),
528 528
 											'readonly'    => true,
529 529
 										),
530 530
 										'key'   => array(
531
-											'description' => __( 'Meta key.', 'woocommerce' ),
531
+											'description' => __('Meta key.', 'woocommerce'),
532 532
 											'type'        => 'string',
533
-											'context'     => array( 'view', 'edit' ),
533
+											'context'     => array('view', 'edit'),
534 534
 											'readonly'    => true,
535 535
 										),
536 536
 										'value' => array(
537
-											'description' => __( 'Meta value.', 'woocommerce' ),
537
+											'description' => __('Meta value.', 'woocommerce'),
538 538
 											'type'        => 'mixed',
539
-											'context'     => array( 'view', 'edit' ),
539
+											'context'     => array('view', 'edit'),
540 540
 											'readonly'    => true,
541 541
 										),
542 542
 									),
543 543
 								),
544 544
 							),
545 545
 							'sku'          => array(
546
-								'description' => __( 'Product SKU.', 'woocommerce' ),
546
+								'description' => __('Product SKU.', 'woocommerce'),
547 547
 								'type'        => 'string',
548
-								'context'     => array( 'view', 'edit' ),
548
+								'context'     => array('view', 'edit'),
549 549
 								'readonly'    => true,
550 550
 							),
551 551
 							'price'        => array(
552
-								'description' => __( 'Product price.', 'woocommerce' ),
552
+								'description' => __('Product price.', 'woocommerce'),
553 553
 								'type'        => 'number',
554
-								'context'     => array( 'view', 'edit' ),
554
+								'context'     => array('view', 'edit'),
555 555
 								'readonly'    => true,
556 556
 							),
557 557
 						),
558 558
 					),
559 559
 				),
560 560
 				'api_refund'       => array(
561
-					'description' => __( 'When true, the payment gateway API is used to generate the refund.', 'woocommerce' ),
561
+					'description' => __('When true, the payment gateway API is used to generate the refund.', 'woocommerce'),
562 562
 					'type'        => 'boolean',
563
-					'context'     => array( 'edit' ),
563
+					'context'     => array('edit'),
564 564
 					'default'     => true,
565 565
 				),
566 566
 			),
567 567
 		);
568 568
 
569
-		return $this->add_additional_fields_schema( $schema );
569
+		return $this->add_additional_fields_schema($schema);
570 570
 	}
571 571
 
572 572
 	/**
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 	public function get_collection_params() {
578 578
 		$params = parent::get_collection_params();
579 579
 
580
-		unset( $params['status'], $params['customer'], $params['product'] );
580
+		unset($params['status'], $params['customer'], $params['product']);
581 581
 
582 582
 		return $params;
583 583
 	}
Please login to merge, or discard this patch.
src/Controllers/Version2/class-wc-rest-customers-v2-controller.php 1 patch
Spacing   +105 added lines, -105 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.
@@ -32,15 +32,15 @@  discard block
 block discarded – undo
32 32
 	 * @param  WC_Data $object WC_Data instance.
33 33
 	 * @return array
34 34
 	 */
35
-	protected function get_formatted_item_data( $object ) {
35
+	protected function get_formatted_item_data($object) {
36 36
 		$data        = $object->get_data();
37
-		$format_date = array( 'date_created', 'date_modified' );
37
+		$format_date = array('date_created', 'date_modified');
38 38
 
39 39
 		// Format date values.
40
-		foreach ( $format_date as $key ) {
41
-			$datetime              = $data[ $key ];
42
-			$data[ $key ]          = wc_rest_prepare_date_response( $datetime, false );
43
-			$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
40
+		foreach ($format_date as $key) {
41
+			$datetime              = $data[$key];
42
+			$data[$key]          = wc_rest_prepare_date_response($datetime, false);
43
+			$data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime);
44 44
 		}
45 45
 
46 46
 		return array(
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
 	 * @param  WP_REST_Request $request   Request object.
72 72
 	 * @return WP_REST_Response $response  Response data.
73 73
 	 */
74
-	public function prepare_item_for_response( $user_data, $request ) {
75
-		$customer = new WC_Customer( $user_data->ID );
76
-		$data     = $this->get_formatted_item_data( $customer );
77
-		$context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
78
-		$data     = $this->add_additional_fields_to_object( $data, $request );
79
-		$data     = $this->filter_response_by_context( $data, $context );
80
-		$response = rest_ensure_response( $data );
81
-		$response->add_links( $this->prepare_links( $user_data ) );
74
+	public function prepare_item_for_response($user_data, $request) {
75
+		$customer = new WC_Customer($user_data->ID);
76
+		$data     = $this->get_formatted_item_data($customer);
77
+		$context  = ! empty($request['context']) ? $request['context'] : 'view';
78
+		$data     = $this->add_additional_fields_to_object($data, $request);
79
+		$data     = $this->filter_response_by_context($data, $context);
80
+		$response = rest_ensure_response($data);
81
+		$response->add_links($this->prepare_links($user_data));
82 82
 
83 83
 		/**
84 84
 		 * Filter customer data returned from the REST API.
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 		 * @param WP_User          $user_data  User object used to create response.
88 88
 		 * @param WP_REST_Request  $request    Request object.
89 89
 		 */
90
-		return apply_filters( 'woocommerce_rest_prepare_customer', $response, $user_data, $request );
90
+		return apply_filters('woocommerce_rest_prepare_customer', $response, $user_data, $request);
91 91
 	}
92 92
 
93 93
 	/**
@@ -96,14 +96,14 @@  discard block
 block discarded – undo
96 96
 	 * @param WC_Customer     $customer Customer data.
97 97
 	 * @param WP_REST_Request $request  Request data.
98 98
 	 */
99
-	protected function update_customer_meta_fields( $customer, $request ) {
100
-		parent::update_customer_meta_fields( $customer, $request );
99
+	protected function update_customer_meta_fields($customer, $request) {
100
+		parent::update_customer_meta_fields($customer, $request);
101 101
 
102 102
 		// Meta data.
103
-		if ( isset( $request['meta_data'] ) ) {
104
-			if ( is_array( $request['meta_data'] ) ) {
105
-				foreach ( $request['meta_data'] as $meta ) {
106
-					$customer->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
103
+		if (isset($request['meta_data'])) {
104
+			if (is_array($request['meta_data'])) {
105
+				foreach ($request['meta_data'] as $meta) {
106
+					$customer->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
107 107
 				}
108 108
 			}
109 109
 		}
@@ -121,237 +121,237 @@  discard block
 block discarded – undo
121 121
 			'type'       => 'object',
122 122
 			'properties' => array(
123 123
 				'id'                 => array(
124
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
124
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
125 125
 					'type'        => 'integer',
126
-					'context'     => array( 'view', 'edit' ),
126
+					'context'     => array('view', 'edit'),
127 127
 					'readonly'    => true,
128 128
 				),
129 129
 				'date_created'       => array(
130
-					'description' => __( "The date the customer was created, in the site's timezone.", 'woocommerce' ),
130
+					'description' => __("The date the customer was created, in the site's timezone.", 'woocommerce'),
131 131
 					'type'        => 'date-time',
132
-					'context'     => array( 'view', 'edit' ),
132
+					'context'     => array('view', 'edit'),
133 133
 					'readonly'    => true,
134 134
 				),
135 135
 				'date_created_gmt'   => array(
136
-					'description' => __( 'The date the order was created, as GMT.', 'woocommerce' ),
136
+					'description' => __('The date the order was created, as GMT.', 'woocommerce'),
137 137
 					'type'        => 'date-time',
138
-					'context'     => array( 'view', 'edit' ),
138
+					'context'     => array('view', 'edit'),
139 139
 					'readonly'    => true,
140 140
 				),
141 141
 				'date_modified'      => array(
142
-					'description' => __( "The date the customer was last modified, in the site's timezone.", 'woocommerce' ),
142
+					'description' => __("The date the customer was last modified, in the site's timezone.", 'woocommerce'),
143 143
 					'type'        => 'date-time',
144
-					'context'     => array( 'view', 'edit' ),
144
+					'context'     => array('view', 'edit'),
145 145
 					'readonly'    => true,
146 146
 				),
147 147
 				'date_modified_gmt'  => array(
148
-					'description' => __( 'The date the customer was last modified, as GMT.', 'woocommerce' ),
148
+					'description' => __('The date the customer was last modified, as GMT.', 'woocommerce'),
149 149
 					'type'        => 'date-time',
150
-					'context'     => array( 'view', 'edit' ),
150
+					'context'     => array('view', 'edit'),
151 151
 					'readonly'    => true,
152 152
 				),
153 153
 				'email'              => array(
154
-					'description' => __( 'The email address for the customer.', 'woocommerce' ),
154
+					'description' => __('The email address for the customer.', 'woocommerce'),
155 155
 					'type'        => 'string',
156 156
 					'format'      => 'email',
157
-					'context'     => array( 'view', 'edit' ),
157
+					'context'     => array('view', 'edit'),
158 158
 				),
159 159
 				'first_name'         => array(
160
-					'description' => __( 'Customer first name.', 'woocommerce' ),
160
+					'description' => __('Customer first name.', 'woocommerce'),
161 161
 					'type'        => 'string',
162
-					'context'     => array( 'view', 'edit' ),
162
+					'context'     => array('view', 'edit'),
163 163
 					'arg_options' => array(
164 164
 						'sanitize_callback' => 'sanitize_text_field',
165 165
 					),
166 166
 				),
167 167
 				'last_name'          => array(
168
-					'description' => __( 'Customer last name.', 'woocommerce' ),
168
+					'description' => __('Customer last name.', 'woocommerce'),
169 169
 					'type'        => 'string',
170
-					'context'     => array( 'view', 'edit' ),
170
+					'context'     => array('view', 'edit'),
171 171
 					'arg_options' => array(
172 172
 						'sanitize_callback' => 'sanitize_text_field',
173 173
 					),
174 174
 				),
175 175
 				'role'               => array(
176
-					'description' => __( 'Customer role.', 'woocommerce' ),
176
+					'description' => __('Customer role.', 'woocommerce'),
177 177
 					'type'        => 'string',
178
-					'context'     => array( 'view', 'edit' ),
178
+					'context'     => array('view', 'edit'),
179 179
 					'readonly'    => true,
180 180
 				),
181 181
 				'username'           => array(
182
-					'description' => __( 'Customer login name.', 'woocommerce' ),
182
+					'description' => __('Customer login name.', 'woocommerce'),
183 183
 					'type'        => 'string',
184
-					'context'     => array( 'view', 'edit' ),
184
+					'context'     => array('view', 'edit'),
185 185
 					'arg_options' => array(
186 186
 						'sanitize_callback' => 'sanitize_user',
187 187
 					),
188 188
 				),
189 189
 				'password'           => array(
190
-					'description' => __( 'Customer password.', 'woocommerce' ),
190
+					'description' => __('Customer password.', 'woocommerce'),
191 191
 					'type'        => 'string',
192
-					'context'     => array( 'edit' ),
192
+					'context'     => array('edit'),
193 193
 				),
194 194
 				'billing'            => array(
195
-					'description' => __( 'List of billing address data.', 'woocommerce' ),
195
+					'description' => __('List of billing address data.', 'woocommerce'),
196 196
 					'type'        => 'object',
197
-					'context'     => array( 'view', 'edit' ),
197
+					'context'     => array('view', 'edit'),
198 198
 					'properties'  => array(
199 199
 						'first_name' => array(
200
-							'description' => __( 'First name.', 'woocommerce' ),
200
+							'description' => __('First name.', 'woocommerce'),
201 201
 							'type'        => 'string',
202
-							'context'     => array( 'view', 'edit' ),
202
+							'context'     => array('view', 'edit'),
203 203
 						),
204 204
 						'last_name'  => array(
205
-							'description' => __( 'Last name.', 'woocommerce' ),
205
+							'description' => __('Last name.', 'woocommerce'),
206 206
 							'type'        => 'string',
207
-							'context'     => array( 'view', 'edit' ),
207
+							'context'     => array('view', 'edit'),
208 208
 						),
209 209
 						'company'    => array(
210
-							'description' => __( 'Company name.', 'woocommerce' ),
210
+							'description' => __('Company name.', 'woocommerce'),
211 211
 							'type'        => 'string',
212
-							'context'     => array( 'view', 'edit' ),
212
+							'context'     => array('view', 'edit'),
213 213
 						),
214 214
 						'address_1'  => array(
215
-							'description' => __( 'Address line 1', 'woocommerce' ),
215
+							'description' => __('Address line 1', 'woocommerce'),
216 216
 							'type'        => 'string',
217
-							'context'     => array( 'view', 'edit' ),
217
+							'context'     => array('view', 'edit'),
218 218
 						),
219 219
 						'address_2'  => array(
220
-							'description' => __( 'Address line 2', 'woocommerce' ),
220
+							'description' => __('Address line 2', 'woocommerce'),
221 221
 							'type'        => 'string',
222
-							'context'     => array( 'view', 'edit' ),
222
+							'context'     => array('view', 'edit'),
223 223
 						),
224 224
 						'city'       => array(
225
-							'description' => __( 'City name.', 'woocommerce' ),
225
+							'description' => __('City name.', 'woocommerce'),
226 226
 							'type'        => 'string',
227
-							'context'     => array( 'view', 'edit' ),
227
+							'context'     => array('view', 'edit'),
228 228
 						),
229 229
 						'state'      => array(
230
-							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
230
+							'description' => __('ISO code or name of the state, province or district.', 'woocommerce'),
231 231
 							'type'        => 'string',
232
-							'context'     => array( 'view', 'edit' ),
232
+							'context'     => array('view', 'edit'),
233 233
 						),
234 234
 						'postcode'   => array(
235
-							'description' => __( 'Postal code.', 'woocommerce' ),
235
+							'description' => __('Postal code.', 'woocommerce'),
236 236
 							'type'        => 'string',
237
-							'context'     => array( 'view', 'edit' ),
237
+							'context'     => array('view', 'edit'),
238 238
 						),
239 239
 						'country'    => array(
240
-							'description' => __( 'ISO code of the country.', 'woocommerce' ),
240
+							'description' => __('ISO code of the country.', 'woocommerce'),
241 241
 							'type'        => 'string',
242
-							'context'     => array( 'view', 'edit' ),
242
+							'context'     => array('view', 'edit'),
243 243
 						),
244 244
 						'email'      => array(
245
-							'description' => __( 'Email address.', 'woocommerce' ),
245
+							'description' => __('Email address.', 'woocommerce'),
246 246
 							'type'        => 'string',
247 247
 							'format'      => 'email',
248
-							'context'     => array( 'view', 'edit' ),
248
+							'context'     => array('view', 'edit'),
249 249
 						),
250 250
 						'phone'      => array(
251
-							'description' => __( 'Phone number.', 'woocommerce' ),
251
+							'description' => __('Phone number.', 'woocommerce'),
252 252
 							'type'        => 'string',
253
-							'context'     => array( 'view', 'edit' ),
253
+							'context'     => array('view', 'edit'),
254 254
 						),
255 255
 					),
256 256
 				),
257 257
 				'shipping'           => array(
258
-					'description' => __( 'List of shipping address data.', 'woocommerce' ),
258
+					'description' => __('List of shipping address data.', 'woocommerce'),
259 259
 					'type'        => 'object',
260
-					'context'     => array( 'view', 'edit' ),
260
+					'context'     => array('view', 'edit'),
261 261
 					'properties'  => array(
262 262
 						'first_name' => array(
263
-							'description' => __( 'First name.', 'woocommerce' ),
263
+							'description' => __('First name.', 'woocommerce'),
264 264
 							'type'        => 'string',
265
-							'context'     => array( 'view', 'edit' ),
265
+							'context'     => array('view', 'edit'),
266 266
 						),
267 267
 						'last_name'  => array(
268
-							'description' => __( 'Last name.', 'woocommerce' ),
268
+							'description' => __('Last name.', 'woocommerce'),
269 269
 							'type'        => 'string',
270
-							'context'     => array( 'view', 'edit' ),
270
+							'context'     => array('view', 'edit'),
271 271
 						),
272 272
 						'company'    => array(
273
-							'description' => __( 'Company name.', 'woocommerce' ),
273
+							'description' => __('Company name.', 'woocommerce'),
274 274
 							'type'        => 'string',
275
-							'context'     => array( 'view', 'edit' ),
275
+							'context'     => array('view', 'edit'),
276 276
 						),
277 277
 						'address_1'  => array(
278
-							'description' => __( 'Address line 1', 'woocommerce' ),
278
+							'description' => __('Address line 1', 'woocommerce'),
279 279
 							'type'        => 'string',
280
-							'context'     => array( 'view', 'edit' ),
280
+							'context'     => array('view', 'edit'),
281 281
 						),
282 282
 						'address_2'  => array(
283
-							'description' => __( 'Address line 2', 'woocommerce' ),
283
+							'description' => __('Address line 2', 'woocommerce'),
284 284
 							'type'        => 'string',
285
-							'context'     => array( 'view', 'edit' ),
285
+							'context'     => array('view', 'edit'),
286 286
 						),
287 287
 						'city'       => array(
288
-							'description' => __( 'City name.', 'woocommerce' ),
288
+							'description' => __('City name.', 'woocommerce'),
289 289
 							'type'        => 'string',
290
-							'context'     => array( 'view', 'edit' ),
290
+							'context'     => array('view', 'edit'),
291 291
 						),
292 292
 						'state'      => array(
293
-							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
293
+							'description' => __('ISO code or name of the state, province or district.', 'woocommerce'),
294 294
 							'type'        => 'string',
295
-							'context'     => array( 'view', 'edit' ),
295
+							'context'     => array('view', 'edit'),
296 296
 						),
297 297
 						'postcode'   => array(
298
-							'description' => __( 'Postal code.', 'woocommerce' ),
298
+							'description' => __('Postal code.', 'woocommerce'),
299 299
 							'type'        => 'string',
300
-							'context'     => array( 'view', 'edit' ),
300
+							'context'     => array('view', 'edit'),
301 301
 						),
302 302
 						'country'    => array(
303
-							'description' => __( 'ISO code of the country.', 'woocommerce' ),
303
+							'description' => __('ISO code of the country.', 'woocommerce'),
304 304
 							'type'        => 'string',
305
-							'context'     => array( 'view', 'edit' ),
305
+							'context'     => array('view', 'edit'),
306 306
 						),
307 307
 					),
308 308
 				),
309 309
 				'is_paying_customer' => array(
310
-					'description' => __( 'Is the customer a paying customer?', 'woocommerce' ),
310
+					'description' => __('Is the customer a paying customer?', 'woocommerce'),
311 311
 					'type'        => 'bool',
312
-					'context'     => array( 'view', 'edit' ),
312
+					'context'     => array('view', 'edit'),
313 313
 					'readonly'    => true,
314 314
 				),
315 315
 				'orders_count'       => array(
316
-					'description' => __( 'Quantity of orders made by the customer.', 'woocommerce' ),
316
+					'description' => __('Quantity of orders made by the customer.', 'woocommerce'),
317 317
 					'type'        => 'integer',
318
-					'context'     => array( 'view', 'edit' ),
318
+					'context'     => array('view', 'edit'),
319 319
 					'readonly'    => true,
320 320
 				),
321 321
 				'total_spent'        => array(
322
-					'description' => __( 'Total amount spent.', 'woocommerce' ),
322
+					'description' => __('Total amount spent.', 'woocommerce'),
323 323
 					'type'        => 'string',
324
-					'context'     => array( 'view', 'edit' ),
324
+					'context'     => array('view', 'edit'),
325 325
 					'readonly'    => true,
326 326
 				),
327 327
 				'avatar_url'         => array(
328
-					'description' => __( 'Avatar URL.', 'woocommerce' ),
328
+					'description' => __('Avatar URL.', 'woocommerce'),
329 329
 					'type'        => 'string',
330
-					'context'     => array( 'view', 'edit' ),
330
+					'context'     => array('view', 'edit'),
331 331
 					'readonly'    => true,
332 332
 				),
333 333
 				'meta_data'          => array(
334
-					'description' => __( 'Meta data.', 'woocommerce' ),
334
+					'description' => __('Meta data.', 'woocommerce'),
335 335
 					'type'        => 'array',
336
-					'context'     => array( 'view', 'edit' ),
336
+					'context'     => array('view', 'edit'),
337 337
 					'items'       => array(
338 338
 						'type'       => 'object',
339 339
 						'properties' => array(
340 340
 							'id'    => array(
341
-								'description' => __( 'Meta ID.', 'woocommerce' ),
341
+								'description' => __('Meta ID.', 'woocommerce'),
342 342
 								'type'        => 'integer',
343
-								'context'     => array( 'view', 'edit' ),
343
+								'context'     => array('view', 'edit'),
344 344
 								'readonly'    => true,
345 345
 							),
346 346
 							'key'   => array(
347
-								'description' => __( 'Meta key.', 'woocommerce' ),
347
+								'description' => __('Meta key.', 'woocommerce'),
348 348
 								'type'        => 'string',
349
-								'context'     => array( 'view', 'edit' ),
349
+								'context'     => array('view', 'edit'),
350 350
 							),
351 351
 							'value' => array(
352
-								'description' => __( 'Meta value.', 'woocommerce' ),
352
+								'description' => __('Meta value.', 'woocommerce'),
353 353
 								'type'        => 'mixed',
354
-								'context'     => array( 'view', 'edit' ),
354
+								'context'     => array('view', 'edit'),
355 355
 							),
356 356
 						),
357 357
 					),
@@ -359,6 +359,6 @@  discard block
 block discarded – undo
359 359
 			),
360 360
 		);
361 361
 
362
-		return $this->add_additional_fields_schema( $schema );
362
+		return $this->add_additional_fields_schema($schema);
363 363
 	}
364 364
 }
Please login to merge, or discard this patch.
src/Controllers/Version2/class-wc-rest-tax-classes-v2-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 Tax Classes controller class.
Please login to merge, or discard this patch.
src/Controllers/Version2/class-wc-rest-coupons-v2-controller.php 1 patch
Spacing   +137 added lines, -137 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 Coupons controller class.
@@ -47,25 +47,25 @@  discard block
 block discarded – undo
47 47
 			$this->namespace, '/' . $this->rest_base, array(
48 48
 				array(
49 49
 					'methods'             => WP_REST_Server::READABLE,
50
-					'callback'            => array( $this, 'get_items' ),
51
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
50
+					'callback'            => array($this, 'get_items'),
51
+					'permission_callback' => array($this, 'get_items_permissions_check'),
52 52
 					'args'                => $this->get_collection_params(),
53 53
 				),
54 54
 				array(
55 55
 					'methods'             => WP_REST_Server::CREATABLE,
56
-					'callback'            => array( $this, 'create_item' ),
57
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
56
+					'callback'            => array($this, 'create_item'),
57
+					'permission_callback' => array($this, 'create_item_permissions_check'),
58 58
 					'args'                => array_merge(
59
-						$this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
59
+						$this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array(
60 60
 							'code' => array(
61
-								'description' => __( 'Coupon code.', 'woocommerce' ),
61
+								'description' => __('Coupon code.', 'woocommerce'),
62 62
 								'required'    => true,
63 63
 								'type'        => 'string',
64 64
 							),
65 65
 						)
66 66
 					),
67 67
 				),
68
-				'schema' => array( $this, 'get_public_item_schema' ),
68
+				'schema' => array($this, 'get_public_item_schema'),
69 69
 			)
70 70
 		);
71 71
 
@@ -73,37 +73,37 @@  discard block
 block discarded – undo
73 73
 			$this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
74 74
 				'args'   => array(
75 75
 					'id' => array(
76
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
76
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
77 77
 						'type'        => 'integer',
78 78
 					),
79 79
 				),
80 80
 				array(
81 81
 					'methods'             => WP_REST_Server::READABLE,
82
-					'callback'            => array( $this, 'get_item' ),
83
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
82
+					'callback'            => array($this, 'get_item'),
83
+					'permission_callback' => array($this, 'get_item_permissions_check'),
84 84
 					'args'                => array(
85
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
85
+						'context' => $this->get_context_param(array('default' => 'view')),
86 86
 					),
87 87
 				),
88 88
 				array(
89 89
 					'methods'             => WP_REST_Server::EDITABLE,
90
-					'callback'            => array( $this, 'update_item' ),
91
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
92
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
90
+					'callback'            => array($this, 'update_item'),
91
+					'permission_callback' => array($this, 'update_item_permissions_check'),
92
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
93 93
 				),
94 94
 				array(
95 95
 					'methods'             => WP_REST_Server::DELETABLE,
96
-					'callback'            => array( $this, 'delete_item' ),
97
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
96
+					'callback'            => array($this, 'delete_item'),
97
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
98 98
 					'args'                => array(
99 99
 						'force' => array(
100 100
 							'default'     => false,
101 101
 							'type'        => 'boolean',
102
-							'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
102
+							'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'),
103 103
 						),
104 104
 					),
105 105
 				),
106
-				'schema' => array( $this, 'get_public_item_schema' ),
106
+				'schema' => array($this, 'get_public_item_schema'),
107 107
 			)
108 108
 		);
109 109
 
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
111 111
 			$this->namespace, '/' . $this->rest_base . '/batch', array(
112 112
 				array(
113 113
 					'methods'             => WP_REST_Server::EDITABLE,
114
-					'callback'            => array( $this, 'batch_items' ),
115
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
116
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
114
+					'callback'            => array($this, 'batch_items'),
115
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
116
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
117 117
 				),
118
-				'schema' => array( $this, 'get_public_batch_schema' ),
118
+				'schema' => array($this, 'get_public_batch_schema'),
119 119
 			)
120 120
 		);
121 121
 	}
@@ -127,8 +127,8 @@  discard block
 block discarded – undo
127 127
 	 * @param  int $id Object ID.
128 128
 	 * @return WC_Data
129 129
 	 */
130
-	protected function get_object( $id ) {
131
-		return new WC_Coupon( $id );
130
+	protected function get_object($id) {
131
+		return new WC_Coupon($id);
132 132
 	}
133 133
 
134 134
 	/**
@@ -138,28 +138,28 @@  discard block
 block discarded – undo
138 138
 	 * @param  WC_Data $object WC_Data instance.
139 139
 	 * @return array
140 140
 	 */
141
-	protected function get_formatted_item_data( $object ) {
141
+	protected function get_formatted_item_data($object) {
142 142
 		$data = $object->get_data();
143 143
 
144
-		$format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' );
145
-		$format_date    = array( 'date_created', 'date_modified', 'date_expires' );
146
-		$format_null    = array( 'usage_limit', 'usage_limit_per_user', 'limit_usage_to_x_items' );
144
+		$format_decimal = array('amount', 'minimum_amount', 'maximum_amount');
145
+		$format_date    = array('date_created', 'date_modified', 'date_expires');
146
+		$format_null    = array('usage_limit', 'usage_limit_per_user', 'limit_usage_to_x_items');
147 147
 
148 148
 		// Format decimal values.
149
-		foreach ( $format_decimal as $key ) {
150
-			$data[ $key ] = wc_format_decimal( $data[ $key ], 2 );
149
+		foreach ($format_decimal as $key) {
150
+			$data[$key] = wc_format_decimal($data[$key], 2);
151 151
 		}
152 152
 
153 153
 		// Format date values.
154
-		foreach ( $format_date as $key ) {
155
-			$datetime              = $data[ $key ];
156
-			$data[ $key ]          = wc_rest_prepare_date_response( $datetime, false );
157
-			$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
154
+		foreach ($format_date as $key) {
155
+			$datetime              = $data[$key];
156
+			$data[$key]          = wc_rest_prepare_date_response($datetime, false);
157
+			$data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime);
158 158
 		}
159 159
 
160 160
 		// Format null values.
161
-		foreach ( $format_null as $key ) {
162
-			$data[ $key ] = $data[ $key ] ? $data[ $key ] : null;
161
+		foreach ($format_null as $key) {
162
+			$data[$key] = $data[$key] ? $data[$key] : null;
163 163
 		}
164 164
 
165 165
 		return array(
@@ -201,13 +201,13 @@  discard block
 block discarded – undo
201 201
 	 * @param  WP_REST_Request $request Request object.
202 202
 	 * @return WP_REST_Response
203 203
 	 */
204
-	public function prepare_object_for_response( $object, $request ) {
205
-		$data     = $this->get_formatted_item_data( $object );
206
-		$context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
207
-		$data     = $this->add_additional_fields_to_object( $data, $request );
208
-		$data     = $this->filter_response_by_context( $data, $context );
209
-		$response = rest_ensure_response( $data );
210
-		$response->add_links( $this->prepare_links( $object, $request ) );
204
+	public function prepare_object_for_response($object, $request) {
205
+		$data     = $this->get_formatted_item_data($object);
206
+		$context  = ! empty($request['context']) ? $request['context'] : 'view';
207
+		$data     = $this->add_additional_fields_to_object($data, $request);
208
+		$data     = $this->filter_response_by_context($data, $context);
209
+		$response = rest_ensure_response($data);
210
+		$response->add_links($this->prepare_links($object, $request));
211 211
 
212 212
 		/**
213 213
 		 * Filter the data for a response.
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 		 * @param WC_Data          $object   Object data.
220 220
 		 * @param WP_REST_Request  $request  Request object.
221 221
 		 */
222
-		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
222
+		return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request);
223 223
 	}
224 224
 
225 225
 	/**
@@ -229,12 +229,12 @@  discard block
 block discarded – undo
229 229
 	 * @param  WP_REST_Request $request Full details about the request.
230 230
 	 * @return array
231 231
 	 */
232
-	protected function prepare_objects_query( $request ) {
233
-		$args = parent::prepare_objects_query( $request );
232
+	protected function prepare_objects_query($request) {
233
+		$args = parent::prepare_objects_query($request);
234 234
 
235
-		if ( ! empty( $request['code'] ) ) {
236
-			$id               = wc_get_coupon_id_by_code( $request['code'] );
237
-			$args['post__in'] = array( $id );
235
+		if ( ! empty($request['code'])) {
236
+			$id               = wc_get_coupon_id_by_code($request['code']);
237
+			$args['post__in'] = array($id);
238 238
 		}
239 239
 
240 240
 		// Get only ids.
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
 	 * @param  array $schema Schema.
250 250
 	 * @return bool
251 251
 	 */
252
-	protected function filter_writable_props( $schema ) {
253
-		return empty( $schema['readonly'] );
252
+	protected function filter_writable_props($schema) {
253
+		return empty($schema['readonly']);
254 254
 	}
255 255
 
256 256
 	/**
@@ -260,47 +260,47 @@  discard block
 block discarded – undo
260 260
 	 * @param  bool            $creating If is creating a new object.
261 261
 	 * @return WP_Error|WC_Data
262 262
 	 */
263
-	protected function prepare_object_for_database( $request, $creating = false ) {
264
-		$id        = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
265
-		$coupon    = new WC_Coupon( $id );
263
+	protected function prepare_object_for_database($request, $creating = false) {
264
+		$id        = isset($request['id']) ? absint($request['id']) : 0;
265
+		$coupon    = new WC_Coupon($id);
266 266
 		$schema    = $this->get_item_schema();
267
-		$data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) );
267
+		$data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props')));
268 268
 
269 269
 		// Validate required POST fields.
270
-		if ( $creating && empty( $request['code'] ) ) {
271
-			return new WP_Error( 'woocommerce_rest_empty_coupon_code', sprintf( __( 'The coupon code cannot be empty.', 'woocommerce' ), 'code' ), array( 'status' => 400 ) );
270
+		if ($creating && empty($request['code'])) {
271
+			return new WP_Error('woocommerce_rest_empty_coupon_code', sprintf(__('The coupon code cannot be empty.', 'woocommerce'), 'code'), array('status' => 400));
272 272
 		}
273 273
 
274 274
 		// Handle all writable props.
275
-		foreach ( $data_keys as $key ) {
276
-			$value = $request[ $key ];
275
+		foreach ($data_keys as $key) {
276
+			$value = $request[$key];
277 277
 
278
-			if ( ! is_null( $value ) ) {
279
-				switch ( $key ) {
278
+			if ( ! is_null($value)) {
279
+				switch ($key) {
280 280
 					case 'code':
281
-						$coupon_code  = wc_format_coupon_code( $value );
281
+						$coupon_code  = wc_format_coupon_code($value);
282 282
 						$id           = $coupon->get_id() ? $coupon->get_id() : 0;
283
-						$id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id );
283
+						$id_from_code = wc_get_coupon_id_by_code($coupon_code, $id);
284 284
 
285
-						if ( $id_from_code ) {
286
-							return new WP_Error( 'woocommerce_rest_coupon_code_already_exists', __( 'The coupon code already exists', 'woocommerce' ), array( 'status' => 400 ) );
285
+						if ($id_from_code) {
286
+							return new WP_Error('woocommerce_rest_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'), array('status' => 400));
287 287
 						}
288 288
 
289
-						$coupon->set_code( $coupon_code );
289
+						$coupon->set_code($coupon_code);
290 290
 						break;
291 291
 					case 'meta_data':
292
-						if ( is_array( $value ) ) {
293
-							foreach ( $value as $meta ) {
294
-								$coupon->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
292
+						if (is_array($value)) {
293
+							foreach ($value as $meta) {
294
+								$coupon->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
295 295
 							}
296 296
 						}
297 297
 						break;
298 298
 					case 'description':
299
-						$coupon->set_description( wp_filter_post_kses( $value ) );
299
+						$coupon->set_description(wp_filter_post_kses($value));
300 300
 						break;
301 301
 					default:
302
-						if ( is_callable( array( $coupon, "set_{$key}" ) ) ) {
303
-							$coupon->{"set_{$key}"}( $value );
302
+						if (is_callable(array($coupon, "set_{$key}"))) {
303
+							$coupon->{"set_{$key}"}($value);
304 304
 						}
305 305
 						break;
306 306
 				}
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 		 * @param WP_REST_Request $request  Request object.
318 318
 		 * @param bool            $creating If is creating a new object.
319 319
 		 */
320
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating );
320
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating);
321 321
 	}
322 322
 
323 323
 	/**
@@ -332,194 +332,194 @@  discard block
 block discarded – undo
332 332
 			'type'       => 'object',
333 333
 			'properties' => array(
334 334
 				'id'                          => array(
335
-					'description' => __( 'Unique identifier for the object.', 'woocommerce' ),
335
+					'description' => __('Unique identifier for the object.', 'woocommerce'),
336 336
 					'type'        => 'integer',
337
-					'context'     => array( 'view', 'edit' ),
337
+					'context'     => array('view', 'edit'),
338 338
 					'readonly'    => true,
339 339
 				),
340 340
 				'code'                        => array(
341
-					'description' => __( 'Coupon code.', 'woocommerce' ),
341
+					'description' => __('Coupon code.', 'woocommerce'),
342 342
 					'type'        => 'string',
343
-					'context'     => array( 'view', 'edit' ),
343
+					'context'     => array('view', 'edit'),
344 344
 				),
345 345
 				'amount'                      => array(
346
-					'description' => __( 'The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce' ),
346
+					'description' => __('The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce'),
347 347
 					'type'        => 'string',
348
-					'context'     => array( 'view', 'edit' ),
348
+					'context'     => array('view', 'edit'),
349 349
 				),
350 350
 				'date_created'                => array(
351
-					'description' => __( "The date the coupon was created, in the site's timezone.", 'woocommerce' ),
351
+					'description' => __("The date the coupon was created, in the site's timezone.", 'woocommerce'),
352 352
 					'type'        => 'date-time',
353
-					'context'     => array( 'view', 'edit' ),
353
+					'context'     => array('view', 'edit'),
354 354
 					'readonly'    => true,
355 355
 				),
356 356
 				'date_created_gmt'            => array(
357
-					'description' => __( 'The date the coupon was created, as GMT.', 'woocommerce' ),
357
+					'description' => __('The date the coupon was created, as GMT.', 'woocommerce'),
358 358
 					'type'        => 'date-time',
359
-					'context'     => array( 'view', 'edit' ),
359
+					'context'     => array('view', 'edit'),
360 360
 					'readonly'    => true,
361 361
 				),
362 362
 				'date_modified'               => array(
363
-					'description' => __( "The date the coupon was last modified, in the site's timezone.", 'woocommerce' ),
363
+					'description' => __("The date the coupon was last modified, in the site's timezone.", 'woocommerce'),
364 364
 					'type'        => 'date-time',
365
-					'context'     => array( 'view', 'edit' ),
365
+					'context'     => array('view', 'edit'),
366 366
 					'readonly'    => true,
367 367
 				),
368 368
 				'date_modified_gmt'           => array(
369
-					'description' => __( 'The date the coupon was last modified, as GMT.', 'woocommerce' ),
369
+					'description' => __('The date the coupon was last modified, as GMT.', 'woocommerce'),
370 370
 					'type'        => 'date-time',
371
-					'context'     => array( 'view', 'edit' ),
371
+					'context'     => array('view', 'edit'),
372 372
 					'readonly'    => true,
373 373
 				),
374 374
 				'discount_type'               => array(
375
-					'description' => __( 'Determines the type of discount that will be applied.', 'woocommerce' ),
375
+					'description' => __('Determines the type of discount that will be applied.', 'woocommerce'),
376 376
 					'type'        => 'string',
377 377
 					'default'     => 'fixed_cart',
378
-					'enum'        => array_keys( wc_get_coupon_types() ),
379
-					'context'     => array( 'view', 'edit' ),
378
+					'enum'        => array_keys(wc_get_coupon_types()),
379
+					'context'     => array('view', 'edit'),
380 380
 				),
381 381
 				'description'                 => array(
382
-					'description' => __( 'Coupon description.', 'woocommerce' ),
382
+					'description' => __('Coupon description.', 'woocommerce'),
383 383
 					'type'        => 'string',
384
-					'context'     => array( 'view', 'edit' ),
384
+					'context'     => array('view', 'edit'),
385 385
 				),
386 386
 				'date_expires'                => array(
387
-					'description' => __( "The date the coupon expires, in the site's timezone.", 'woocommerce' ),
387
+					'description' => __("The date the coupon expires, in the site's timezone.", 'woocommerce'),
388 388
 					'type'        => 'string',
389
-					'context'     => array( 'view', 'edit' ),
389
+					'context'     => array('view', 'edit'),
390 390
 				),
391 391
 				'date_expires_gmt'            => array(
392
-					'description' => __( 'The date the coupon expires, as GMT.', 'woocommerce' ),
392
+					'description' => __('The date the coupon expires, as GMT.', 'woocommerce'),
393 393
 					'type'        => 'string',
394
-					'context'     => array( 'view', 'edit' ),
394
+					'context'     => array('view', 'edit'),
395 395
 				),
396 396
 				'usage_count'                 => array(
397
-					'description' => __( 'Number of times the coupon has been used already.', 'woocommerce' ),
397
+					'description' => __('Number of times the coupon has been used already.', 'woocommerce'),
398 398
 					'type'        => 'integer',
399
-					'context'     => array( 'view', 'edit' ),
399
+					'context'     => array('view', 'edit'),
400 400
 					'readonly'    => true,
401 401
 				),
402 402
 				'individual_use'              => array(
403
-					'description' => __( 'If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce' ),
403
+					'description' => __('If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce'),
404 404
 					'type'        => 'boolean',
405 405
 					'default'     => false,
406
-					'context'     => array( 'view', 'edit' ),
406
+					'context'     => array('view', 'edit'),
407 407
 				),
408 408
 				'product_ids'                 => array(
409
-					'description' => __( 'List of product IDs the coupon can be used on.', 'woocommerce' ),
409
+					'description' => __('List of product IDs the coupon can be used on.', 'woocommerce'),
410 410
 					'type'        => 'array',
411 411
 					'items'       => array(
412 412
 						'type' => 'integer',
413 413
 					),
414
-					'context'     => array( 'view', 'edit' ),
414
+					'context'     => array('view', 'edit'),
415 415
 				),
416 416
 				'excluded_product_ids'        => array(
417
-					'description' => __( 'List of product IDs the coupon cannot be used on.', 'woocommerce' ),
417
+					'description' => __('List of product IDs the coupon cannot be used on.', 'woocommerce'),
418 418
 					'type'        => 'array',
419 419
 					'items'       => array(
420 420
 						'type' => 'integer',
421 421
 					),
422
-					'context'     => array( 'view', 'edit' ),
422
+					'context'     => array('view', 'edit'),
423 423
 				),
424 424
 				'usage_limit'                 => array(
425
-					'description' => __( 'How many times the coupon can be used in total.', 'woocommerce' ),
425
+					'description' => __('How many times the coupon can be used in total.', 'woocommerce'),
426 426
 					'type'        => 'integer',
427
-					'context'     => array( 'view', 'edit' ),
427
+					'context'     => array('view', 'edit'),
428 428
 				),
429 429
 				'usage_limit_per_user'        => array(
430
-					'description' => __( 'How many times the coupon can be used per customer.', 'woocommerce' ),
430
+					'description' => __('How many times the coupon can be used per customer.', 'woocommerce'),
431 431
 					'type'        => 'integer',
432
-					'context'     => array( 'view', 'edit' ),
432
+					'context'     => array('view', 'edit'),
433 433
 				),
434 434
 				'limit_usage_to_x_items'      => array(
435
-					'description' => __( 'Max number of items in the cart the coupon can be applied to.', 'woocommerce' ),
435
+					'description' => __('Max number of items in the cart the coupon can be applied to.', 'woocommerce'),
436 436
 					'type'        => 'integer',
437
-					'context'     => array( 'view', 'edit' ),
437
+					'context'     => array('view', 'edit'),
438 438
 				),
439 439
 				'free_shipping'               => array(
440
-					'description' => __( 'If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce' ),
440
+					'description' => __('If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce'),
441 441
 					'type'        => 'boolean',
442 442
 					'default'     => false,
443
-					'context'     => array( 'view', 'edit' ),
443
+					'context'     => array('view', 'edit'),
444 444
 				),
445 445
 				'product_categories'          => array(
446
-					'description' => __( 'List of category IDs the coupon applies to.', 'woocommerce' ),
446
+					'description' => __('List of category IDs the coupon applies to.', 'woocommerce'),
447 447
 					'type'        => 'array',
448 448
 					'items'       => array(
449 449
 						'type' => 'integer',
450 450
 					),
451
-					'context'     => array( 'view', 'edit' ),
451
+					'context'     => array('view', 'edit'),
452 452
 				),
453 453
 				'excluded_product_categories' => array(
454
-					'description' => __( 'List of category IDs the coupon does not apply to.', 'woocommerce' ),
454
+					'description' => __('List of category IDs the coupon does not apply to.', 'woocommerce'),
455 455
 					'type'        => 'array',
456 456
 					'items'       => array(
457 457
 						'type' => 'integer',
458 458
 					),
459
-					'context'     => array( 'view', 'edit' ),
459
+					'context'     => array('view', 'edit'),
460 460
 				),
461 461
 				'exclude_sale_items'          => array(
462
-					'description' => __( 'If true, this coupon will not be applied to items that have sale prices.', 'woocommerce' ),
462
+					'description' => __('If true, this coupon will not be applied to items that have sale prices.', 'woocommerce'),
463 463
 					'type'        => 'boolean',
464 464
 					'default'     => false,
465
-					'context'     => array( 'view', 'edit' ),
465
+					'context'     => array('view', 'edit'),
466 466
 				),
467 467
 				'minimum_amount'              => array(
468
-					'description' => __( 'Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce' ),
468
+					'description' => __('Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce'),
469 469
 					'type'        => 'string',
470
-					'context'     => array( 'view', 'edit' ),
470
+					'context'     => array('view', 'edit'),
471 471
 				),
472 472
 				'maximum_amount'              => array(
473
-					'description' => __( 'Maximum order amount allowed when using the coupon.', 'woocommerce' ),
473
+					'description' => __('Maximum order amount allowed when using the coupon.', 'woocommerce'),
474 474
 					'type'        => 'string',
475
-					'context'     => array( 'view', 'edit' ),
475
+					'context'     => array('view', 'edit'),
476 476
 				),
477 477
 				'email_restrictions'          => array(
478
-					'description' => __( 'List of email addresses that can use this coupon.', 'woocommerce' ),
478
+					'description' => __('List of email addresses that can use this coupon.', 'woocommerce'),
479 479
 					'type'        => 'array',
480 480
 					'items'       => array(
481 481
 						'type' => 'string',
482 482
 					),
483
-					'context'     => array( 'view', 'edit' ),
483
+					'context'     => array('view', 'edit'),
484 484
 				),
485 485
 				'used_by'                     => array(
486
-					'description' => __( 'List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce' ),
486
+					'description' => __('List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce'),
487 487
 					'type'        => 'array',
488 488
 					'items'       => array(
489 489
 						'type' => 'integer',
490 490
 					),
491
-					'context'     => array( 'view', 'edit' ),
491
+					'context'     => array('view', 'edit'),
492 492
 					'readonly'    => true,
493 493
 				),
494 494
 				'meta_data'                   => array(
495
-					'description' => __( 'Meta data.', 'woocommerce' ),
495
+					'description' => __('Meta data.', 'woocommerce'),
496 496
 					'type'        => 'array',
497
-					'context'     => array( 'view', 'edit' ),
497
+					'context'     => array('view', 'edit'),
498 498
 					'items'       => array(
499 499
 						'type'       => 'object',
500 500
 						'properties' => array(
501 501
 							'id'    => array(
502
-								'description' => __( 'Meta ID.', 'woocommerce' ),
502
+								'description' => __('Meta ID.', 'woocommerce'),
503 503
 								'type'        => 'integer',
504
-								'context'     => array( 'view', 'edit' ),
504
+								'context'     => array('view', 'edit'),
505 505
 								'readonly'    => true,
506 506
 							),
507 507
 							'key'   => array(
508
-								'description' => __( 'Meta key.', 'woocommerce' ),
508
+								'description' => __('Meta key.', 'woocommerce'),
509 509
 								'type'        => 'string',
510
-								'context'     => array( 'view', 'edit' ),
510
+								'context'     => array('view', 'edit'),
511 511
 							),
512 512
 							'value' => array(
513
-								'description' => __( 'Meta value.', 'woocommerce' ),
513
+								'description' => __('Meta value.', 'woocommerce'),
514 514
 								'type'        => 'mixed',
515
-								'context'     => array( 'view', 'edit' ),
515
+								'context'     => array('view', 'edit'),
516 516
 							),
517 517
 						),
518 518
 					),
519 519
 				),
520 520
 			),
521 521
 		);
522
-		return $this->add_additional_fields_schema( $schema );
522
+		return $this->add_additional_fields_schema($schema);
523 523
 	}
524 524
 
525 525
 	/**
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 		$params = parent::get_collection_params();
532 532
 
533 533
 		$params['code'] = array(
534
-			'description'       => __( 'Limit result set to resources with a specific code.', 'woocommerce' ),
534
+			'description'       => __('Limit result set to resources with a specific code.', 'woocommerce'),
535 535
 			'type'              => 'string',
536 536
 			'sanitize_callback' => 'sanitize_text_field',
537 537
 			'validate_callback' => 'rest_validate_request_arg',
Please login to merge, or discard this patch.