@@ -8,7 +8,7 @@ discard block |
||
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,7 +32,7 @@ discard block |
||
32 | 32 | * @param WP_REST_Request $request Request object. |
33 | 33 | * @return WP_REST_Response $response Response data. |
34 | 34 | */ |
35 | - public function prepare_item_for_response( $download, $request ) { |
|
35 | + public function prepare_item_for_response($download, $request) { |
|
36 | 36 | $data = array( |
37 | 37 | 'download_id' => $download->download_id, |
38 | 38 | 'download_url' => $download->download_url, |
@@ -42,19 +42,19 @@ discard block |
||
42 | 42 | 'order_id' => $download->order_id, |
43 | 43 | 'order_key' => $download->order_key, |
44 | 44 | 'downloads_remaining' => '' === $download->downloads_remaining ? 'unlimited' : $download->downloads_remaining, |
45 | - 'access_expires' => $download->access_expires ? wc_rest_prepare_date_response( $download->access_expires ) : 'never', |
|
46 | - 'access_expires_gmt' => $download->access_expires ? wc_rest_prepare_date_response( get_gmt_from_date( $download->access_expires ) ) : 'never', |
|
45 | + 'access_expires' => $download->access_expires ? wc_rest_prepare_date_response($download->access_expires) : 'never', |
|
46 | + 'access_expires_gmt' => $download->access_expires ? wc_rest_prepare_date_response(get_gmt_from_date($download->access_expires)) : 'never', |
|
47 | 47 | 'file' => $download->file, |
48 | 48 | ); |
49 | 49 | |
50 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
51 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
52 | - $data = $this->filter_response_by_context( $data, $context ); |
|
50 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
51 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
52 | + $data = $this->filter_response_by_context($data, $context); |
|
53 | 53 | |
54 | 54 | // Wrap the data in a response object. |
55 | - $response = rest_ensure_response( $data ); |
|
55 | + $response = rest_ensure_response($data); |
|
56 | 56 | |
57 | - $response->add_links( $this->prepare_links( $download, $request ) ); |
|
57 | + $response->add_links($this->prepare_links($download, $request)); |
|
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Filter customer download data returned from the REST API. |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param stdClass $download Download object used to create response. |
64 | 64 | * @param WP_REST_Request $request Request object. |
65 | 65 | */ |
66 | - return apply_filters( 'woocommerce_rest_prepare_customer_download', $response, $download, $request ); |
|
66 | + return apply_filters('woocommerce_rest_prepare_customer_download', $response, $download, $request); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -78,81 +78,81 @@ discard block |
||
78 | 78 | 'type' => 'object', |
79 | 79 | 'properties' => array( |
80 | 80 | 'download_id' => array( |
81 | - 'description' => __( 'Download ID.', 'woocommerce' ), |
|
81 | + 'description' => __('Download ID.', 'woocommerce'), |
|
82 | 82 | 'type' => 'string', |
83 | - 'context' => array( 'view' ), |
|
83 | + 'context' => array('view'), |
|
84 | 84 | 'readonly' => true, |
85 | 85 | ), |
86 | 86 | 'download_url' => array( |
87 | - 'description' => __( 'Download file URL.', 'woocommerce' ), |
|
87 | + 'description' => __('Download file URL.', 'woocommerce'), |
|
88 | 88 | 'type' => 'string', |
89 | - 'context' => array( 'view' ), |
|
89 | + 'context' => array('view'), |
|
90 | 90 | 'readonly' => true, |
91 | 91 | ), |
92 | 92 | 'product_id' => array( |
93 | - 'description' => __( 'Downloadable product ID.', 'woocommerce' ), |
|
93 | + 'description' => __('Downloadable product ID.', 'woocommerce'), |
|
94 | 94 | 'type' => 'integer', |
95 | - 'context' => array( 'view' ), |
|
95 | + 'context' => array('view'), |
|
96 | 96 | 'readonly' => true, |
97 | 97 | ), |
98 | 98 | 'product_name' => array( |
99 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
99 | + 'description' => __('Product name.', 'woocommerce'), |
|
100 | 100 | 'type' => 'string', |
101 | - 'context' => array( 'view' ), |
|
101 | + 'context' => array('view'), |
|
102 | 102 | 'readonly' => true, |
103 | 103 | ), |
104 | 104 | 'download_name' => array( |
105 | - 'description' => __( 'Downloadable file name.', 'woocommerce' ), |
|
105 | + 'description' => __('Downloadable file name.', 'woocommerce'), |
|
106 | 106 | 'type' => 'string', |
107 | - 'context' => array( 'view' ), |
|
107 | + 'context' => array('view'), |
|
108 | 108 | 'readonly' => true, |
109 | 109 | ), |
110 | 110 | 'order_id' => array( |
111 | - 'description' => __( 'Order ID.', 'woocommerce' ), |
|
111 | + 'description' => __('Order ID.', 'woocommerce'), |
|
112 | 112 | 'type' => 'integer', |
113 | - 'context' => array( 'view' ), |
|
113 | + 'context' => array('view'), |
|
114 | 114 | 'readonly' => true, |
115 | 115 | ), |
116 | 116 | 'order_key' => array( |
117 | - 'description' => __( 'Order key.', 'woocommerce' ), |
|
117 | + 'description' => __('Order key.', 'woocommerce'), |
|
118 | 118 | 'type' => 'string', |
119 | - 'context' => array( 'view' ), |
|
119 | + 'context' => array('view'), |
|
120 | 120 | 'readonly' => true, |
121 | 121 | ), |
122 | 122 | 'downloads_remaining' => array( |
123 | - 'description' => __( 'Number of downloads remaining.', 'woocommerce' ), |
|
123 | + 'description' => __('Number of downloads remaining.', 'woocommerce'), |
|
124 | 124 | 'type' => 'string', |
125 | - 'context' => array( 'view' ), |
|
125 | + 'context' => array('view'), |
|
126 | 126 | 'readonly' => true, |
127 | 127 | ), |
128 | 128 | 'access_expires' => array( |
129 | - 'description' => __( "The date when download access expires, in the site's timezone.", 'woocommerce' ), |
|
129 | + 'description' => __("The date when download access expires, in the site's timezone.", 'woocommerce'), |
|
130 | 130 | 'type' => 'string', |
131 | - 'context' => array( 'view' ), |
|
131 | + 'context' => array('view'), |
|
132 | 132 | 'readonly' => true, |
133 | 133 | ), |
134 | 134 | 'access_expires_gmt' => array( |
135 | - 'description' => __( 'The date when download access expires, as GMT.', 'woocommerce' ), |
|
135 | + 'description' => __('The date when download access expires, as GMT.', 'woocommerce'), |
|
136 | 136 | 'type' => 'string', |
137 | - 'context' => array( 'view' ), |
|
137 | + 'context' => array('view'), |
|
138 | 138 | 'readonly' => true, |
139 | 139 | ), |
140 | 140 | 'file' => array( |
141 | - 'description' => __( 'File details.', 'woocommerce' ), |
|
141 | + 'description' => __('File details.', 'woocommerce'), |
|
142 | 142 | 'type' => 'object', |
143 | - 'context' => array( 'view' ), |
|
143 | + 'context' => array('view'), |
|
144 | 144 | 'readonly' => true, |
145 | 145 | 'properties' => array( |
146 | 146 | 'name' => array( |
147 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
147 | + 'description' => __('File name.', 'woocommerce'), |
|
148 | 148 | 'type' => 'string', |
149 | - 'context' => array( 'view' ), |
|
149 | + 'context' => array('view'), |
|
150 | 150 | 'readonly' => true, |
151 | 151 | ), |
152 | 152 | 'file' => array( |
153 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
153 | + 'description' => __('File URL.', 'woocommerce'), |
|
154 | 154 | 'type' => 'string', |
155 | - 'context' => array( 'view' ), |
|
155 | + 'context' => array('view'), |
|
156 | 156 | 'readonly' => true, |
157 | 157 | ), |
158 | 158 | ), |
@@ -160,6 +160,6 @@ discard block |
||
160 | 160 | ), |
161 | 161 | ); |
162 | 162 | |
163 | - return $this->add_additional_fields_schema( $schema ); |
|
163 | + return $this->add_additional_fields_schema($schema); |
|
164 | 164 | } |
165 | 165 | } |
@@ -8,7 +8,7 @@ discard block |
||
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 Setting Options controller class. |
@@ -42,16 +42,16 @@ discard block |
||
42 | 42 | $this->namespace, '/' . $this->rest_base, array( |
43 | 43 | 'args' => array( |
44 | 44 | 'group' => array( |
45 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
45 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
46 | 46 | 'type' => 'string', |
47 | 47 | ), |
48 | 48 | ), |
49 | 49 | array( |
50 | 50 | 'methods' => WP_REST_Server::READABLE, |
51 | - 'callback' => array( $this, 'get_items' ), |
|
52 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
51 | + 'callback' => array($this, 'get_items'), |
|
52 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
53 | 53 | ), |
54 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
54 | + 'schema' => array($this, 'get_public_item_schema'), |
|
55 | 55 | ) |
56 | 56 | ); |
57 | 57 | |
@@ -59,17 +59,17 @@ discard block |
||
59 | 59 | $this->namespace, '/' . $this->rest_base . '/batch', array( |
60 | 60 | 'args' => array( |
61 | 61 | 'group' => array( |
62 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
62 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
63 | 63 | 'type' => 'string', |
64 | 64 | ), |
65 | 65 | ), |
66 | 66 | array( |
67 | 67 | 'methods' => WP_REST_Server::EDITABLE, |
68 | - 'callback' => array( $this, 'batch_items' ), |
|
69 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
70 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
68 | + 'callback' => array($this, 'batch_items'), |
|
69 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
70 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
71 | 71 | ), |
72 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
72 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
73 | 73 | ) |
74 | 74 | ); |
75 | 75 | |
@@ -77,26 +77,26 @@ discard block |
||
77 | 77 | $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array( |
78 | 78 | 'args' => array( |
79 | 79 | 'group' => array( |
80 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
80 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
81 | 81 | 'type' => 'string', |
82 | 82 | ), |
83 | 83 | 'id' => array( |
84 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
84 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
85 | 85 | 'type' => 'string', |
86 | 86 | ), |
87 | 87 | ), |
88 | 88 | array( |
89 | 89 | 'methods' => WP_REST_Server::READABLE, |
90 | - 'callback' => array( $this, 'get_item' ), |
|
91 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
90 | + 'callback' => array($this, 'get_item'), |
|
91 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
92 | 92 | ), |
93 | 93 | array( |
94 | 94 | 'methods' => WP_REST_Server::EDITABLE, |
95 | - 'callback' => array( $this, 'update_item' ), |
|
96 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
97 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
95 | + 'callback' => array($this, 'update_item'), |
|
96 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
97 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
98 | 98 | ), |
99 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
99 | + 'schema' => array($this, 'get_public_item_schema'), |
|
100 | 100 | ) |
101 | 101 | ); |
102 | 102 | } |
@@ -108,16 +108,16 @@ discard block |
||
108 | 108 | * @param WP_REST_Request $request Request data. |
109 | 109 | * @return WP_Error|WP_REST_Response |
110 | 110 | */ |
111 | - public function get_item( $request ) { |
|
112 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
111 | + public function get_item($request) { |
|
112 | + $setting = $this->get_setting($request['group_id'], $request['id']); |
|
113 | 113 | |
114 | - if ( is_wp_error( $setting ) ) { |
|
114 | + if (is_wp_error($setting)) { |
|
115 | 115 | return $setting; |
116 | 116 | } |
117 | 117 | |
118 | - $response = $this->prepare_item_for_response( $setting, $request ); |
|
118 | + $response = $this->prepare_item_for_response($setting, $request); |
|
119 | 119 | |
120 | - return rest_ensure_response( $response ); |
|
120 | + return rest_ensure_response($response); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,24 +127,24 @@ discard block |
||
127 | 127 | * @param WP_REST_Request $request Request data. |
128 | 128 | * @return WP_Error|WP_REST_Response |
129 | 129 | */ |
130 | - public function get_items( $request ) { |
|
131 | - $settings = $this->get_group_settings( $request['group_id'] ); |
|
130 | + public function get_items($request) { |
|
131 | + $settings = $this->get_group_settings($request['group_id']); |
|
132 | 132 | |
133 | - if ( is_wp_error( $settings ) ) { |
|
133 | + if (is_wp_error($settings)) { |
|
134 | 134 | return $settings; |
135 | 135 | } |
136 | 136 | |
137 | 137 | $data = array(); |
138 | 138 | |
139 | - foreach ( $settings as $setting_obj ) { |
|
140 | - $setting = $this->prepare_item_for_response( $setting_obj, $request ); |
|
141 | - $setting = $this->prepare_response_for_collection( $setting ); |
|
142 | - if ( $this->is_setting_type_valid( $setting['type'] ) ) { |
|
139 | + foreach ($settings as $setting_obj) { |
|
140 | + $setting = $this->prepare_item_for_response($setting_obj, $request); |
|
141 | + $setting = $this->prepare_response_for_collection($setting); |
|
142 | + if ($this->is_setting_type_valid($setting['type'])) { |
|
143 | 143 | $data[] = $setting; |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | - return rest_ensure_response( $data ); |
|
147 | + return rest_ensure_response($data); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -154,35 +154,35 @@ discard block |
||
154 | 154 | * @param string $group_id Group ID. |
155 | 155 | * @return array|WP_Error |
156 | 156 | */ |
157 | - public function get_group_settings( $group_id ) { |
|
158 | - if ( empty( $group_id ) ) { |
|
159 | - return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
157 | + public function get_group_settings($group_id) { |
|
158 | + if (empty($group_id)) { |
|
159 | + return new WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404)); |
|
160 | 160 | } |
161 | 161 | |
162 | - $settings = apply_filters( 'woocommerce_settings-' . $group_id, array() ); |
|
162 | + $settings = apply_filters('woocommerce_settings-' . $group_id, array()); |
|
163 | 163 | |
164 | - if ( empty( $settings ) ) { |
|
165 | - return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
164 | + if (empty($settings)) { |
|
165 | + return new WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404)); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | $filtered_settings = array(); |
169 | - foreach ( $settings as $setting ) { |
|
169 | + foreach ($settings as $setting) { |
|
170 | 170 | $option_key = $setting['option_key']; |
171 | - $setting = $this->filter_setting( $setting ); |
|
172 | - $default = isset( $setting['default'] ) ? $setting['default'] : ''; |
|
171 | + $setting = $this->filter_setting($setting); |
|
172 | + $default = isset($setting['default']) ? $setting['default'] : ''; |
|
173 | 173 | // Get the option value. |
174 | - if ( is_array( $option_key ) ) { |
|
175 | - $option = get_option( $option_key[0] ); |
|
176 | - $setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default; |
|
174 | + if (is_array($option_key)) { |
|
175 | + $option = get_option($option_key[0]); |
|
176 | + $setting['value'] = isset($option[$option_key[1]]) ? $option[$option_key[1]] : $default; |
|
177 | 177 | } else { |
178 | - $admin_setting_value = WC_Admin_Settings::get_option( $option_key, $default ); |
|
178 | + $admin_setting_value = WC_Admin_Settings::get_option($option_key, $default); |
|
179 | 179 | $setting['value'] = $admin_setting_value; |
180 | 180 | } |
181 | 181 | |
182 | - if ( 'multi_select_countries' === $setting['type'] ) { |
|
182 | + if ('multi_select_countries' === $setting['type']) { |
|
183 | 183 | $setting['options'] = WC()->countries->get_countries(); |
184 | 184 | $setting['type'] = 'multiselect'; |
185 | - } elseif ( 'single_select_country' === $setting['type'] ) { |
|
185 | + } elseif ('single_select_country' === $setting['type']) { |
|
186 | 186 | $setting['type'] = 'select'; |
187 | 187 | $setting['options'] = $this->get_countries_and_states(); |
188 | 188 | } |
@@ -201,20 +201,20 @@ discard block |
||
201 | 201 | */ |
202 | 202 | private function get_countries_and_states() { |
203 | 203 | $countries = WC()->countries->get_countries(); |
204 | - if ( ! $countries ) { |
|
204 | + if ( ! $countries) { |
|
205 | 205 | return array(); |
206 | 206 | } |
207 | 207 | |
208 | 208 | $output = array(); |
209 | 209 | |
210 | - foreach ( $countries as $key => $value ) { |
|
211 | - $states = WC()->countries->get_states( $key ); |
|
212 | - if ( $states ) { |
|
213 | - foreach ( $states as $state_key => $state_value ) { |
|
214 | - $output[ $key . ':' . $state_key ] = $value . ' - ' . $state_value; |
|
210 | + foreach ($countries as $key => $value) { |
|
211 | + $states = WC()->countries->get_states($key); |
|
212 | + if ($states) { |
|
213 | + foreach ($states as $state_key => $state_value) { |
|
214 | + $output[$key . ':' . $state_key] = $value . ' - ' . $state_value; |
|
215 | 215 | } |
216 | 216 | } else { |
217 | - $output[ $key ] = $value; |
|
217 | + $output[$key] = $value; |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
@@ -229,27 +229,27 @@ discard block |
||
229 | 229 | * @param string $setting_id Setting ID. |
230 | 230 | * @return stdClass|WP_Error |
231 | 231 | */ |
232 | - public function get_setting( $group_id, $setting_id ) { |
|
233 | - if ( empty( $setting_id ) ) { |
|
234 | - return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
232 | + public function get_setting($group_id, $setting_id) { |
|
233 | + if (empty($setting_id)) { |
|
234 | + return new WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
235 | 235 | } |
236 | 236 | |
237 | - $settings = $this->get_group_settings( $group_id ); |
|
237 | + $settings = $this->get_group_settings($group_id); |
|
238 | 238 | |
239 | - if ( is_wp_error( $settings ) ) { |
|
239 | + if (is_wp_error($settings)) { |
|
240 | 240 | return $settings; |
241 | 241 | } |
242 | 242 | |
243 | - $array_key = array_keys( wp_list_pluck( $settings, 'id' ), $setting_id ); |
|
243 | + $array_key = array_keys(wp_list_pluck($settings, 'id'), $setting_id); |
|
244 | 244 | |
245 | - if ( empty( $array_key ) ) { |
|
246 | - return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
245 | + if (empty($array_key)) { |
|
246 | + return new WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
247 | 247 | } |
248 | 248 | |
249 | - $setting = $settings[ $array_key[0] ]; |
|
249 | + $setting = $settings[$array_key[0]]; |
|
250 | 250 | |
251 | - if ( ! $this->is_setting_type_valid( $setting['type'] ) ) { |
|
252 | - return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
251 | + if ( ! $this->is_setting_type_valid($setting['type'])) { |
|
252 | + return new WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | return $setting; |
@@ -262,24 +262,24 @@ discard block |
||
262 | 262 | * @param WP_REST_Request $request Full details about the request. |
263 | 263 | * @return array Of WP_Error or WP_REST_Response. |
264 | 264 | */ |
265 | - public function batch_items( $request ) { |
|
265 | + public function batch_items($request) { |
|
266 | 266 | // Get the request params. |
267 | - $items = array_filter( $request->get_params() ); |
|
267 | + $items = array_filter($request->get_params()); |
|
268 | 268 | |
269 | 269 | /* |
270 | 270 | * Since our batch settings update is group-specific and matches based on the route, |
271 | 271 | * we inject the URL parameters (containing group) into the batch items |
272 | 272 | */ |
273 | - if ( ! empty( $items['update'] ) ) { |
|
273 | + if ( ! empty($items['update'])) { |
|
274 | 274 | $to_update = array(); |
275 | - foreach ( $items['update'] as $item ) { |
|
276 | - $to_update[] = array_merge( $request->get_url_params(), $item ); |
|
275 | + foreach ($items['update'] as $item) { |
|
276 | + $to_update[] = array_merge($request->get_url_params(), $item); |
|
277 | 277 | } |
278 | - $request = new WP_REST_Request( $request->get_method() ); |
|
279 | - $request->set_body_params( array( 'update' => $to_update ) ); |
|
278 | + $request = new WP_REST_Request($request->get_method()); |
|
279 | + $request->set_body_params(array('update' => $to_update)); |
|
280 | 280 | } |
281 | 281 | |
282 | - return parent::batch_items( $request ); |
|
282 | + return parent::batch_items($request); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -289,39 +289,39 @@ discard block |
||
289 | 289 | * @param WP_REST_Request $request Request data. |
290 | 290 | * @return WP_Error|WP_REST_Response |
291 | 291 | */ |
292 | - public function update_item( $request ) { |
|
293 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
292 | + public function update_item($request) { |
|
293 | + $setting = $this->get_setting($request['group_id'], $request['id']); |
|
294 | 294 | |
295 | - if ( is_wp_error( $setting ) ) { |
|
295 | + if (is_wp_error($setting)) { |
|
296 | 296 | return $setting; |
297 | 297 | } |
298 | 298 | |
299 | - if ( is_callable( array( $this, 'validate_setting_' . $setting['type'] . '_field' ) ) ) { |
|
300 | - $value = $this->{'validate_setting_' . $setting['type'] . '_field'}( $request['value'], $setting ); |
|
299 | + if (is_callable(array($this, 'validate_setting_' . $setting['type'] . '_field'))) { |
|
300 | + $value = $this->{'validate_setting_' . $setting['type'] . '_field'}($request['value'], $setting); |
|
301 | 301 | } else { |
302 | - $value = $this->validate_setting_text_field( $request['value'], $setting ); |
|
302 | + $value = $this->validate_setting_text_field($request['value'], $setting); |
|
303 | 303 | } |
304 | 304 | |
305 | - if ( is_wp_error( $value ) ) { |
|
305 | + if (is_wp_error($value)) { |
|
306 | 306 | return $value; |
307 | 307 | } |
308 | 308 | |
309 | - if ( is_array( $setting['option_key'] ) ) { |
|
309 | + if (is_array($setting['option_key'])) { |
|
310 | 310 | $setting['value'] = $value; |
311 | 311 | $option_key = $setting['option_key']; |
312 | - $prev = get_option( $option_key[0] ); |
|
313 | - $prev[ $option_key[1] ] = $request['value']; |
|
314 | - update_option( $option_key[0], $prev ); |
|
312 | + $prev = get_option($option_key[0]); |
|
313 | + $prev[$option_key[1]] = $request['value']; |
|
314 | + update_option($option_key[0], $prev); |
|
315 | 315 | } else { |
316 | 316 | $update_data = array(); |
317 | - $update_data[ $setting['option_key'] ] = $value; |
|
317 | + $update_data[$setting['option_key']] = $value; |
|
318 | 318 | $setting['value'] = $value; |
319 | - WC_Admin_Settings::save_fields( array( $setting ), $update_data ); |
|
319 | + WC_Admin_Settings::save_fields(array($setting), $update_data); |
|
320 | 320 | } |
321 | 321 | |
322 | - $response = $this->prepare_item_for_response( $setting, $request ); |
|
322 | + $response = $this->prepare_item_for_response($setting, $request); |
|
323 | 323 | |
324 | - return rest_ensure_response( $response ); |
|
324 | + return rest_ensure_response($response); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | /** |
@@ -332,13 +332,13 @@ discard block |
||
332 | 332 | * @param WP_REST_Request $request Request object. |
333 | 333 | * @return WP_REST_Response $response Response data. |
334 | 334 | */ |
335 | - public function prepare_item_for_response( $item, $request ) { |
|
336 | - unset( $item['option_key'] ); |
|
337 | - $data = $this->filter_setting( $item ); |
|
338 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
339 | - $data = $this->filter_response_by_context( $data, empty( $request['context'] ) ? 'view' : $request['context'] ); |
|
340 | - $response = rest_ensure_response( $data ); |
|
341 | - $response->add_links( $this->prepare_links( $data['id'], $request['group_id'] ) ); |
|
335 | + public function prepare_item_for_response($item, $request) { |
|
336 | + unset($item['option_key']); |
|
337 | + $data = $this->filter_setting($item); |
|
338 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
339 | + $data = $this->filter_response_by_context($data, empty($request['context']) ? 'view' : $request['context']); |
|
340 | + $response = rest_ensure_response($data); |
|
341 | + $response->add_links($this->prepare_links($data['id'], $request['group_id'])); |
|
342 | 342 | return $response; |
343 | 343 | } |
344 | 344 | |
@@ -350,14 +350,14 @@ discard block |
||
350 | 350 | * @param string $group_id Group ID. |
351 | 351 | * @return array Links for the given setting. |
352 | 352 | */ |
353 | - protected function prepare_links( $setting_id, $group_id ) { |
|
354 | - $base = str_replace( '(?P<group_id>[\w-]+)', $group_id, $this->rest_base ); |
|
353 | + protected function prepare_links($setting_id, $group_id) { |
|
354 | + $base = str_replace('(?P<group_id>[\w-]+)', $group_id, $this->rest_base); |
|
355 | 355 | $links = array( |
356 | 356 | 'self' => array( |
357 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $base, $setting_id ) ), |
|
357 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $base, $setting_id)), |
|
358 | 358 | ), |
359 | 359 | 'collection' => array( |
360 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
360 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
361 | 361 | ), |
362 | 362 | ); |
363 | 363 | |
@@ -371,9 +371,9 @@ discard block |
||
371 | 371 | * @param WP_REST_Request $request Full data about the request. |
372 | 372 | * @return WP_Error|boolean |
373 | 373 | */ |
374 | - public function get_items_permissions_check( $request ) { |
|
375 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
376 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
374 | + public function get_items_permissions_check($request) { |
|
375 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
376 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | return true; |
@@ -386,9 +386,9 @@ discard block |
||
386 | 386 | * @param WP_REST_Request $request Full data about the request. |
387 | 387 | * @return WP_Error|boolean |
388 | 388 | */ |
389 | - public function update_items_permissions_check( $request ) { |
|
390 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
391 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
389 | + public function update_items_permissions_check($request) { |
|
390 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
391 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | return true; |
@@ -402,18 +402,18 @@ discard block |
||
402 | 402 | * @param array $setting Settings. |
403 | 403 | * @return array |
404 | 404 | */ |
405 | - public function filter_setting( $setting ) { |
|
405 | + public function filter_setting($setting) { |
|
406 | 406 | $setting = array_intersect_key( |
407 | 407 | $setting, |
408 | - array_flip( array_filter( array_keys( $setting ), array( $this, 'allowed_setting_keys' ) ) ) |
|
408 | + array_flip(array_filter(array_keys($setting), array($this, 'allowed_setting_keys'))) |
|
409 | 409 | ); |
410 | 410 | |
411 | - if ( empty( $setting['options'] ) ) { |
|
412 | - unset( $setting['options'] ); |
|
411 | + if (empty($setting['options'])) { |
|
412 | + unset($setting['options']); |
|
413 | 413 | } |
414 | 414 | |
415 | - if ( 'image_width' === $setting['type'] ) { |
|
416 | - $setting = $this->cast_image_width( $setting ); |
|
415 | + if ('image_width' === $setting['type']) { |
|
416 | + $setting = $this->cast_image_width($setting); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | return $setting; |
@@ -428,12 +428,12 @@ discard block |
||
428 | 428 | * @param array $setting Settings. |
429 | 429 | * @return array |
430 | 430 | */ |
431 | - public function cast_image_width( $setting ) { |
|
432 | - foreach ( array( 'default', 'value' ) as $key ) { |
|
433 | - if ( isset( $setting[ $key ] ) ) { |
|
434 | - $setting[ $key ]['width'] = intval( $setting[ $key ]['width'] ); |
|
435 | - $setting[ $key ]['height'] = intval( $setting[ $key ]['height'] ); |
|
436 | - $setting[ $key ]['crop'] = (bool) $setting[ $key ]['crop']; |
|
431 | + public function cast_image_width($setting) { |
|
432 | + foreach (array('default', 'value') as $key) { |
|
433 | + if (isset($setting[$key])) { |
|
434 | + $setting[$key]['width'] = intval($setting[$key]['width']); |
|
435 | + $setting[$key]['height'] = intval($setting[$key]['height']); |
|
436 | + $setting[$key]['crop'] = (bool) $setting[$key]['crop']; |
|
437 | 437 | } |
438 | 438 | } |
439 | 439 | return $setting; |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | * @param string $key Key to check. |
447 | 447 | * @return boolean |
448 | 448 | */ |
449 | - public function allowed_setting_keys( $key ) { |
|
449 | + public function allowed_setting_keys($key) { |
|
450 | 450 | return in_array( |
451 | 451 | $key, array( |
452 | 452 | 'id', |
@@ -470,20 +470,20 @@ discard block |
||
470 | 470 | * @param string $type Type. |
471 | 471 | * @return bool |
472 | 472 | */ |
473 | - public function is_setting_type_valid( $type ) { |
|
473 | + public function is_setting_type_valid($type) { |
|
474 | 474 | return in_array( |
475 | 475 | $type, array( |
476 | - 'text', // Validates with validate_setting_text_field. |
|
477 | - 'email', // Validates with validate_setting_text_field. |
|
478 | - 'number', // Validates with validate_setting_text_field. |
|
479 | - 'color', // Validates with validate_setting_text_field. |
|
480 | - 'password', // Validates with validate_setting_text_field. |
|
481 | - 'textarea', // Validates with validate_setting_textarea_field. |
|
482 | - 'select', // Validates with validate_setting_select_field. |
|
483 | - 'multiselect', // Validates with validate_setting_multiselect_field. |
|
484 | - 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
485 | - 'checkbox', // Validates with validate_setting_checkbox_field. |
|
486 | - 'image_width', // Validates with validate_setting_image_width_field. |
|
476 | + 'text', // Validates with validate_setting_text_field. |
|
477 | + 'email', // Validates with validate_setting_text_field. |
|
478 | + 'number', // Validates with validate_setting_text_field. |
|
479 | + 'color', // Validates with validate_setting_text_field. |
|
480 | + 'password', // Validates with validate_setting_text_field. |
|
481 | + 'textarea', // Validates with validate_setting_textarea_field. |
|
482 | + 'select', // Validates with validate_setting_select_field. |
|
483 | + 'multiselect', // Validates with validate_setting_multiselect_field. |
|
484 | + 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
485 | + 'checkbox', // Validates with validate_setting_checkbox_field. |
|
486 | + 'image_width', // Validates with validate_setting_image_width_field. |
|
487 | 487 | 'thumbnail_cropping', // Validates with validate_setting_text_field. |
488 | 488 | ) |
489 | 489 | ); |
@@ -502,80 +502,80 @@ discard block |
||
502 | 502 | 'type' => 'object', |
503 | 503 | 'properties' => array( |
504 | 504 | 'id' => array( |
505 | - 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ), |
|
505 | + 'description' => __('A unique identifier for the setting.', 'woocommerce'), |
|
506 | 506 | 'type' => 'string', |
507 | 507 | 'arg_options' => array( |
508 | 508 | 'sanitize_callback' => 'sanitize_title', |
509 | 509 | ), |
510 | - 'context' => array( 'view', 'edit' ), |
|
510 | + 'context' => array('view', 'edit'), |
|
511 | 511 | 'readonly' => true, |
512 | 512 | ), |
513 | 513 | 'label' => array( |
514 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
514 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
515 | 515 | 'type' => 'string', |
516 | 516 | 'arg_options' => array( |
517 | 517 | 'sanitize_callback' => 'sanitize_text_field', |
518 | 518 | ), |
519 | - 'context' => array( 'view', 'edit' ), |
|
519 | + 'context' => array('view', 'edit'), |
|
520 | 520 | 'readonly' => true, |
521 | 521 | ), |
522 | 522 | 'description' => array( |
523 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
523 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
524 | 524 | 'type' => 'string', |
525 | 525 | 'arg_options' => array( |
526 | 526 | 'sanitize_callback' => 'sanitize_text_field', |
527 | 527 | ), |
528 | - 'context' => array( 'view', 'edit' ), |
|
528 | + 'context' => array('view', 'edit'), |
|
529 | 529 | 'readonly' => true, |
530 | 530 | ), |
531 | 531 | 'value' => array( |
532 | - 'description' => __( 'Setting value.', 'woocommerce' ), |
|
532 | + 'description' => __('Setting value.', 'woocommerce'), |
|
533 | 533 | 'type' => 'mixed', |
534 | - 'context' => array( 'view', 'edit' ), |
|
534 | + 'context' => array('view', 'edit'), |
|
535 | 535 | ), |
536 | 536 | 'default' => array( |
537 | - 'description' => __( 'Default value for the setting.', 'woocommerce' ), |
|
537 | + 'description' => __('Default value for the setting.', 'woocommerce'), |
|
538 | 538 | 'type' => 'mixed', |
539 | - 'context' => array( 'view', 'edit' ), |
|
539 | + 'context' => array('view', 'edit'), |
|
540 | 540 | 'readonly' => true, |
541 | 541 | ), |
542 | 542 | 'tip' => array( |
543 | - 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ), |
|
543 | + 'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'), |
|
544 | 544 | 'type' => 'string', |
545 | 545 | 'arg_options' => array( |
546 | 546 | 'sanitize_callback' => 'sanitize_text_field', |
547 | 547 | ), |
548 | - 'context' => array( 'view', 'edit' ), |
|
548 | + 'context' => array('view', 'edit'), |
|
549 | 549 | 'readonly' => true, |
550 | 550 | ), |
551 | 551 | 'placeholder' => array( |
552 | - 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ), |
|
552 | + 'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'), |
|
553 | 553 | 'type' => 'string', |
554 | 554 | 'arg_options' => array( |
555 | 555 | 'sanitize_callback' => 'sanitize_text_field', |
556 | 556 | ), |
557 | - 'context' => array( 'view', 'edit' ), |
|
557 | + 'context' => array('view', 'edit'), |
|
558 | 558 | 'readonly' => true, |
559 | 559 | ), |
560 | 560 | 'type' => array( |
561 | - 'description' => __( 'Type of setting.', 'woocommerce' ), |
|
561 | + 'description' => __('Type of setting.', 'woocommerce'), |
|
562 | 562 | 'type' => 'string', |
563 | 563 | 'arg_options' => array( |
564 | 564 | 'sanitize_callback' => 'sanitize_text_field', |
565 | 565 | ), |
566 | - 'context' => array( 'view', 'edit' ), |
|
567 | - 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox', 'thumbnail_cropping' ), |
|
566 | + 'context' => array('view', 'edit'), |
|
567 | + 'enum' => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox', 'thumbnail_cropping'), |
|
568 | 568 | 'readonly' => true, |
569 | 569 | ), |
570 | 570 | 'options' => array( |
571 | - 'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ), |
|
571 | + 'description' => __('Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce'), |
|
572 | 572 | 'type' => 'object', |
573 | - 'context' => array( 'view', 'edit' ), |
|
573 | + 'context' => array('view', 'edit'), |
|
574 | 574 | 'readonly' => true, |
575 | 575 | ), |
576 | 576 | ), |
577 | 577 | ); |
578 | 578 | |
579 | - return $this->add_additional_fields_schema( $schema ); |
|
579 | + return $this->add_additional_fields_schema($schema); |
|
580 | 580 | } |
581 | 581 | } |
@@ -8,7 +8,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -8,7 +8,7 @@ |
||
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. |
@@ -8,7 +8,7 @@ |
||
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. |
@@ -8,7 +8,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -8,7 +8,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -8,7 +8,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -8,7 +8,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |