@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * Constructor. |
| 39 | 39 | */ |
| 40 | 40 | public function __construct() { |
| 41 | - add_filter( 'woocommerce_reports_products_stats_select_query', array( $this, 'set_default_report_data' ) ); |
|
| 41 | + add_filter('woocommerce_reports_products_stats_select_query', array($this, 'set_default_report_data')); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param \WP_REST_Request $request Request data. |
| 48 | 48 | * @return array|\WP_Error |
| 49 | 49 | */ |
| 50 | - public function get_items( $request ) { |
|
| 50 | + public function get_items($request) { |
|
| 51 | 51 | $query_args = array( |
| 52 | 52 | 'fields' => array( |
| 53 | 53 | 'items_sold', |
@@ -58,53 +58,53 @@ discard block |
||
| 58 | 58 | ), |
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | - $registered = array_keys( $this->get_collection_params() ); |
|
| 62 | - foreach ( $registered as $param_name ) { |
|
| 63 | - if ( isset( $request[ $param_name ] ) ) { |
|
| 64 | - if ( isset( $this->param_mapping[ $param_name ] ) ) { |
|
| 65 | - $query_args[ $this->param_mapping[ $param_name ] ] = $request[ $param_name ]; |
|
| 61 | + $registered = array_keys($this->get_collection_params()); |
|
| 62 | + foreach ($registered as $param_name) { |
|
| 63 | + if (isset($request[$param_name])) { |
|
| 64 | + if (isset($this->param_mapping[$param_name])) { |
|
| 65 | + $query_args[$this->param_mapping[$param_name]] = $request[$param_name]; |
|
| 66 | 66 | } else { |
| 67 | - $query_args[ $param_name ] = $request[ $param_name ]; |
|
| 67 | + $query_args[$param_name] = $request[$param_name]; |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $query = new \WC_Admin_Reports_Products_Stats_Query( $query_args ); |
|
| 72 | + $query = new \WC_Admin_Reports_Products_Stats_Query($query_args); |
|
| 73 | 73 | try { |
| 74 | 74 | $report_data = $query->get_data(); |
| 75 | - } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { |
|
| 76 | - return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
| 75 | + } catch (\WC_Admin_Reports_Parameter_Exception $e) { |
|
| 76 | + return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | $out_data = array( |
| 80 | - 'totals' => get_object_vars( $report_data->totals ), |
|
| 80 | + 'totals' => get_object_vars($report_data->totals), |
|
| 81 | 81 | 'intervals' => array(), |
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | - foreach ( $report_data->intervals as $interval_data ) { |
|
| 85 | - $item = $this->prepare_item_for_response( $interval_data, $request ); |
|
| 86 | - $out_data['intervals'][] = $this->prepare_response_for_collection( $item ); |
|
| 84 | + foreach ($report_data->intervals as $interval_data) { |
|
| 85 | + $item = $this->prepare_item_for_response($interval_data, $request); |
|
| 86 | + $out_data['intervals'][] = $this->prepare_response_for_collection($item); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - $response = rest_ensure_response( $out_data ); |
|
| 90 | - $response->header( 'X-WP-Total', (int) $report_data->total ); |
|
| 91 | - $response->header( 'X-WP-TotalPages', (int) $report_data->pages ); |
|
| 89 | + $response = rest_ensure_response($out_data); |
|
| 90 | + $response->header('X-WP-Total', (int) $report_data->total); |
|
| 91 | + $response->header('X-WP-TotalPages', (int) $report_data->pages); |
|
| 92 | 92 | |
| 93 | 93 | $page = $report_data->page_no; |
| 94 | 94 | $max_pages = $report_data->pages; |
| 95 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 96 | - if ( $page > 1 ) { |
|
| 95 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 96 | + if ($page > 1) { |
|
| 97 | 97 | $prev_page = $page - 1; |
| 98 | - if ( $prev_page > $max_pages ) { |
|
| 98 | + if ($prev_page > $max_pages) { |
|
| 99 | 99 | $prev_page = $max_pages; |
| 100 | 100 | } |
| 101 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 102 | - $response->link_header( 'prev', $prev_link ); |
|
| 101 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 102 | + $response->link_header('prev', $prev_link); |
|
| 103 | 103 | } |
| 104 | - if ( $max_pages > $page ) { |
|
| 104 | + if ($max_pages > $page) { |
|
| 105 | 105 | $next_page = $page + 1; |
| 106 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 107 | - $response->link_header( 'next', $next_link ); |
|
| 106 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 107 | + $response->link_header('next', $next_link); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | return $response; |
@@ -117,15 +117,15 @@ discard block |
||
| 117 | 117 | * @param \WP_REST_Request $request Request object. |
| 118 | 118 | * @return \WP_REST_Response |
| 119 | 119 | */ |
| 120 | - public function prepare_item_for_response( $report, $request ) { |
|
| 120 | + public function prepare_item_for_response($report, $request) { |
|
| 121 | 121 | $data = $report; |
| 122 | 122 | |
| 123 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 124 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 125 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 123 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 124 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 125 | + $data = $this->filter_response_by_context($data, $context); |
|
| 126 | 126 | |
| 127 | 127 | // Wrap the data in a response object. |
| 128 | - $response = rest_ensure_response( $data ); |
|
| 128 | + $response = rest_ensure_response($data); |
|
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | 131 | * Filter a report returned from the API. |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @param object $report The original report object. |
| 137 | 137 | * @param \WP_REST_Request $request Request used to generate the response. |
| 138 | 138 | */ |
| 139 | - return apply_filters( 'woocommerce_rest_prepare_report_products_stats', $response, $report, $request ); |
|
| 139 | + return apply_filters('woocommerce_rest_prepare_report_products_stats', $response, $report, $request); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -147,53 +147,53 @@ discard block |
||
| 147 | 147 | public function get_item_schema() { |
| 148 | 148 | $data_values = array( |
| 149 | 149 | 'items_sold' => array( |
| 150 | - 'description' => __( 'Number of items sold.', 'woocommerce' ), |
|
| 150 | + 'description' => __('Number of items sold.', 'woocommerce'), |
|
| 151 | 151 | 'type' => 'integer', |
| 152 | - 'context' => array( 'view', 'edit' ), |
|
| 152 | + 'context' => array('view', 'edit'), |
|
| 153 | 153 | 'readonly' => true, |
| 154 | 154 | 'indicator' => true, |
| 155 | 155 | ), |
| 156 | 156 | 'net_revenue' => array( |
| 157 | - 'description' => __( 'Net revenue.', 'woocommerce' ), |
|
| 157 | + 'description' => __('Net revenue.', 'woocommerce'), |
|
| 158 | 158 | 'type' => 'number', |
| 159 | - 'context' => array( 'view', 'edit' ), |
|
| 159 | + 'context' => array('view', 'edit'), |
|
| 160 | 160 | 'readonly' => true, |
| 161 | 161 | 'format' => 'currency', |
| 162 | 162 | ), |
| 163 | 163 | 'orders_count' => array( |
| 164 | - 'description' => __( 'Number of orders.', 'woocommerce' ), |
|
| 164 | + 'description' => __('Number of orders.', 'woocommerce'), |
|
| 165 | 165 | 'type' => 'integer', |
| 166 | - 'context' => array( 'view', 'edit' ), |
|
| 166 | + 'context' => array('view', 'edit'), |
|
| 167 | 167 | 'readonly' => true, |
| 168 | 168 | ), |
| 169 | 169 | ); |
| 170 | 170 | |
| 171 | 171 | $segments = array( |
| 172 | 172 | 'segments' => array( |
| 173 | - 'description' => __( 'Reports data grouped by segment condition.', 'woocommerce' ), |
|
| 173 | + 'description' => __('Reports data grouped by segment condition.', 'woocommerce'), |
|
| 174 | 174 | 'type' => 'array', |
| 175 | - 'context' => array( 'view', 'edit' ), |
|
| 175 | + 'context' => array('view', 'edit'), |
|
| 176 | 176 | 'readonly' => true, |
| 177 | 177 | 'items' => array( |
| 178 | 178 | 'type' => 'object', |
| 179 | 179 | 'properties' => array( |
| 180 | 180 | 'segment_id' => array( |
| 181 | - 'description' => __( 'Segment identificator.', 'woocommerce' ), |
|
| 181 | + 'description' => __('Segment identificator.', 'woocommerce'), |
|
| 182 | 182 | 'type' => 'integer', |
| 183 | - 'context' => array( 'view', 'edit' ), |
|
| 183 | + 'context' => array('view', 'edit'), |
|
| 184 | 184 | 'readonly' => true, |
| 185 | 185 | ), |
| 186 | 186 | 'segment_label' => array( |
| 187 | - 'description' => __( 'Human readable segment label, either product or variation name.', 'woocommerce' ), |
|
| 187 | + 'description' => __('Human readable segment label, either product or variation name.', 'woocommerce'), |
|
| 188 | 188 | 'type' => 'string', |
| 189 | - 'context' => array( 'view', 'edit' ), |
|
| 189 | + 'context' => array('view', 'edit'), |
|
| 190 | 190 | 'readonly' => true, |
| 191 | - 'enum' => array( 'day', 'week', 'month', 'year' ), |
|
| 191 | + 'enum' => array('day', 'week', 'month', 'year'), |
|
| 192 | 192 | ), |
| 193 | 193 | 'subtotals' => array( |
| 194 | - 'description' => __( 'Interval subtotals.', 'woocommerce' ), |
|
| 194 | + 'description' => __('Interval subtotals.', 'woocommerce'), |
|
| 195 | 195 | 'type' => 'object', |
| 196 | - 'context' => array( 'view', 'edit' ), |
|
| 196 | + 'context' => array('view', 'edit'), |
|
| 197 | 197 | 'readonly' => true, |
| 198 | 198 | 'properties' => $data_values, |
| 199 | 199 | ), |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | ), |
| 203 | 203 | ); |
| 204 | 204 | |
| 205 | - $totals = array_merge( $data_values, $segments ); |
|
| 205 | + $totals = array_merge($data_values, $segments); |
|
| 206 | 206 | |
| 207 | 207 | $schema = array( |
| 208 | 208 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
@@ -210,55 +210,55 @@ discard block |
||
| 210 | 210 | 'type' => 'object', |
| 211 | 211 | 'properties' => array( |
| 212 | 212 | 'totals' => array( |
| 213 | - 'description' => __( 'Totals data.', 'woocommerce' ), |
|
| 213 | + 'description' => __('Totals data.', 'woocommerce'), |
|
| 214 | 214 | 'type' => 'object', |
| 215 | - 'context' => array( 'view', 'edit' ), |
|
| 215 | + 'context' => array('view', 'edit'), |
|
| 216 | 216 | 'readonly' => true, |
| 217 | 217 | 'properties' => $totals, |
| 218 | 218 | ), |
| 219 | 219 | 'intervals' => array( |
| 220 | - 'description' => __( 'Reports data grouped by intervals.', 'woocommerce' ), |
|
| 220 | + 'description' => __('Reports data grouped by intervals.', 'woocommerce'), |
|
| 221 | 221 | 'type' => 'array', |
| 222 | - 'context' => array( 'view', 'edit' ), |
|
| 222 | + 'context' => array('view', 'edit'), |
|
| 223 | 223 | 'readonly' => true, |
| 224 | 224 | 'items' => array( |
| 225 | 225 | 'type' => 'object', |
| 226 | 226 | 'properties' => array( |
| 227 | 227 | 'interval' => array( |
| 228 | - 'description' => __( 'Type of interval.', 'woocommerce' ), |
|
| 228 | + 'description' => __('Type of interval.', 'woocommerce'), |
|
| 229 | 229 | 'type' => 'string', |
| 230 | - 'context' => array( 'view', 'edit' ), |
|
| 230 | + 'context' => array('view', 'edit'), |
|
| 231 | 231 | 'readonly' => true, |
| 232 | - 'enum' => array( 'day', 'week', 'month', 'year' ), |
|
| 232 | + 'enum' => array('day', 'week', 'month', 'year'), |
|
| 233 | 233 | ), |
| 234 | 234 | 'date_start' => array( |
| 235 | - 'description' => __( "The date the report start, in the site's timezone.", 'woocommerce' ), |
|
| 235 | + 'description' => __("The date the report start, in the site's timezone.", 'woocommerce'), |
|
| 236 | 236 | 'type' => 'date-time', |
| 237 | - 'context' => array( 'view', 'edit' ), |
|
| 237 | + 'context' => array('view', 'edit'), |
|
| 238 | 238 | 'readonly' => true, |
| 239 | 239 | ), |
| 240 | 240 | 'date_start_gmt' => array( |
| 241 | - 'description' => __( 'The date the report start, as GMT.', 'woocommerce' ), |
|
| 241 | + 'description' => __('The date the report start, as GMT.', 'woocommerce'), |
|
| 242 | 242 | 'type' => 'date-time', |
| 243 | - 'context' => array( 'view', 'edit' ), |
|
| 243 | + 'context' => array('view', 'edit'), |
|
| 244 | 244 | 'readonly' => true, |
| 245 | 245 | ), |
| 246 | 246 | 'date_end' => array( |
| 247 | - 'description' => __( "The date the report end, in the site's timezone.", 'woocommerce' ), |
|
| 247 | + 'description' => __("The date the report end, in the site's timezone.", 'woocommerce'), |
|
| 248 | 248 | 'type' => 'date-time', |
| 249 | - 'context' => array( 'view', 'edit' ), |
|
| 249 | + 'context' => array('view', 'edit'), |
|
| 250 | 250 | 'readonly' => true, |
| 251 | 251 | ), |
| 252 | 252 | 'date_end_gmt' => array( |
| 253 | - 'description' => __( 'The date the report end, as GMT.', 'woocommerce' ), |
|
| 253 | + 'description' => __('The date the report end, as GMT.', 'woocommerce'), |
|
| 254 | 254 | 'type' => 'date-time', |
| 255 | - 'context' => array( 'view', 'edit' ), |
|
| 255 | + 'context' => array('view', 'edit'), |
|
| 256 | 256 | 'readonly' => true, |
| 257 | 257 | ), |
| 258 | 258 | 'subtotals' => array( |
| 259 | - 'description' => __( 'Interval subtotals.', 'woocommerce' ), |
|
| 259 | + 'description' => __('Interval subtotals.', 'woocommerce'), |
|
| 260 | 260 | 'type' => 'object', |
| 261 | - 'context' => array( 'view', 'edit' ), |
|
| 261 | + 'context' => array('view', 'edit'), |
|
| 262 | 262 | 'readonly' => true, |
| 263 | 263 | 'properties' => $totals, |
| 264 | 264 | ), |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | ), |
| 269 | 269 | ); |
| 270 | 270 | |
| 271 | - return $this->add_additional_fields_schema( $schema ); |
|
| 271 | + return $this->add_additional_fields_schema($schema); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -277,8 +277,8 @@ discard block |
||
| 277 | 277 | * @param Mixed $results Report data. |
| 278 | 278 | * @return object |
| 279 | 279 | */ |
| 280 | - public function set_default_report_data( $results ) { |
|
| 281 | - if ( empty( $results ) ) { |
|
| 280 | + public function set_default_report_data($results) { |
|
| 281 | + if (empty($results)) { |
|
| 282 | 282 | $results = new \stdClass(); |
| 283 | 283 | $results->total = 0; |
| 284 | 284 | $results->totals = new \stdClass(); |
@@ -299,17 +299,17 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | public function get_collection_params() { |
| 301 | 301 | $params = array(); |
| 302 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 302 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 303 | 303 | $params['page'] = array( |
| 304 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 304 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 305 | 305 | 'type' => 'integer', |
| 306 | 306 | 'default' => 1, |
| 307 | 307 | 'sanitize_callback' => 'absint', |
| 308 | 308 | 'validate_callback' => 'rest_validate_request_arg', |
| 309 | 309 | 'minimum' => 1, |
| 310 | 310 | ); |
| 311 | - $params['per_page'] = array( |
|
| 312 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 311 | + $params['per_page'] = array( |
|
| 312 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 313 | 313 | 'type' => 'integer', |
| 314 | 314 | 'default' => 10, |
| 315 | 315 | 'minimum' => 1, |
@@ -317,27 +317,27 @@ discard block |
||
| 317 | 317 | 'sanitize_callback' => 'absint', |
| 318 | 318 | 'validate_callback' => 'rest_validate_request_arg', |
| 319 | 319 | ); |
| 320 | - $params['after'] = array( |
|
| 321 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 320 | + $params['after'] = array( |
|
| 321 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 322 | 322 | 'type' => 'string', |
| 323 | 323 | 'format' => 'date-time', |
| 324 | 324 | 'validate_callback' => 'rest_validate_request_arg', |
| 325 | 325 | ); |
| 326 | - $params['before'] = array( |
|
| 327 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 326 | + $params['before'] = array( |
|
| 327 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 328 | 328 | 'type' => 'string', |
| 329 | 329 | 'format' => 'date-time', |
| 330 | 330 | 'validate_callback' => 'rest_validate_request_arg', |
| 331 | 331 | ); |
| 332 | - $params['order'] = array( |
|
| 333 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 332 | + $params['order'] = array( |
|
| 333 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 334 | 334 | 'type' => 'string', |
| 335 | 335 | 'default' => 'desc', |
| 336 | - 'enum' => array( 'asc', 'desc' ), |
|
| 336 | + 'enum' => array('asc', 'desc'), |
|
| 337 | 337 | 'validate_callback' => 'rest_validate_request_arg', |
| 338 | 338 | ); |
| 339 | - $params['orderby'] = array( |
|
| 340 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 339 | + $params['orderby'] = array( |
|
| 340 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 341 | 341 | 'type' => 'string', |
| 342 | 342 | 'default' => 'date', |
| 343 | 343 | 'enum' => array( |
@@ -353,8 +353,8 @@ discard block |
||
| 353 | 353 | ), |
| 354 | 354 | 'validate_callback' => 'rest_validate_request_arg', |
| 355 | 355 | ); |
| 356 | - $params['interval'] = array( |
|
| 357 | - 'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ), |
|
| 356 | + $params['interval'] = array( |
|
| 357 | + 'description' => __('Time interval to use for buckets in the returned data.', 'woocommerce'), |
|
| 358 | 358 | 'type' => 'string', |
| 359 | 359 | 'default' => 'week', |
| 360 | 360 | 'enum' => array( |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | 'validate_callback' => 'rest_validate_request_arg', |
| 369 | 369 | ); |
| 370 | 370 | $params['categories'] = array( |
| 371 | - 'description' => __( 'Limit result to items from the specified categories.', 'woocommerce' ), |
|
| 371 | + 'description' => __('Limit result to items from the specified categories.', 'woocommerce'), |
|
| 372 | 372 | 'type' => 'array', |
| 373 | 373 | 'sanitize_callback' => 'wp_parse_id_list', |
| 374 | 374 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -376,8 +376,8 @@ discard block |
||
| 376 | 376 | 'type' => 'integer', |
| 377 | 377 | ), |
| 378 | 378 | ); |
| 379 | - $params['products'] = array( |
|
| 380 | - 'description' => __( 'Limit result to items with specified product ids.', 'woocommerce' ), |
|
| 379 | + $params['products'] = array( |
|
| 380 | + 'description' => __('Limit result to items with specified product ids.', 'woocommerce'), |
|
| 381 | 381 | 'type' => 'array', |
| 382 | 382 | 'sanitize_callback' => 'wp_parse_id_list', |
| 383 | 383 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | ), |
| 387 | 387 | ); |
| 388 | 388 | $params['variations'] = array( |
| 389 | - 'description' => __( 'Limit result to items with specified variation ids.', 'woocommerce' ), |
|
| 389 | + 'description' => __('Limit result to items with specified variation ids.', 'woocommerce'), |
|
| 390 | 390 | 'type' => 'array', |
| 391 | 391 | 'sanitize_callback' => 'wp_parse_id_list', |
| 392 | 392 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -394,8 +394,8 @@ discard block |
||
| 394 | 394 | 'type' => 'integer', |
| 395 | 395 | ), |
| 396 | 396 | ); |
| 397 | - $params['segmentby'] = array( |
|
| 398 | - 'description' => __( 'Segment the response by additional constraint.', 'woocommerce' ), |
|
| 397 | + $params['segmentby'] = array( |
|
| 398 | + 'description' => __('Segment the response by additional constraint.', 'woocommerce'), |
|
| 399 | 399 | 'type' => 'string', |
| 400 | 400 | 'enum' => array( |
| 401 | 401 | 'product', |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | array( |
| 36 | 36 | array( |
| 37 | 37 | 'methods' => \WP_REST_Server::EDITABLE, |
| 38 | - 'callback' => array( $this, 'import_items' ), |
|
| 39 | - 'permission_callback' => array( $this, 'import_permissions_check' ), |
|
| 38 | + 'callback' => array($this, 'import_items'), |
|
| 39 | + 'permission_callback' => array($this, 'import_permissions_check'), |
|
| 40 | 40 | 'args' => $this->get_import_collection_params(), |
| 41 | 41 | ), |
| 42 | - 'schema' => array( $this, 'get_import_public_schema' ), |
|
| 42 | + 'schema' => array($this, 'get_import_public_schema'), |
|
| 43 | 43 | ) |
| 44 | 44 | ); |
| 45 | 45 | register_rest_route( |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | array( |
| 49 | 49 | array( |
| 50 | 50 | 'methods' => \WP_REST_Server::EDITABLE, |
| 51 | - 'callback' => array( $this, 'cancel_import' ), |
|
| 52 | - 'permission_callback' => array( $this, 'import_permissions_check' ), |
|
| 51 | + 'callback' => array($this, 'cancel_import'), |
|
| 52 | + 'permission_callback' => array($this, 'import_permissions_check'), |
|
| 53 | 53 | ), |
| 54 | - 'schema' => array( $this, 'get_import_public_schema' ), |
|
| 54 | + 'schema' => array($this, 'get_import_public_schema'), |
|
| 55 | 55 | ) |
| 56 | 56 | ); |
| 57 | 57 | register_rest_route( |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | array( |
| 61 | 61 | array( |
| 62 | 62 | 'methods' => \WP_REST_Server::EDITABLE, |
| 63 | - 'callback' => array( $this, 'delete_imported_items' ), |
|
| 64 | - 'permission_callback' => array( $this, 'import_permissions_check' ), |
|
| 63 | + 'callback' => array($this, 'delete_imported_items'), |
|
| 64 | + 'permission_callback' => array($this, 'import_permissions_check'), |
|
| 65 | 65 | ), |
| 66 | - 'schema' => array( $this, 'get_import_public_schema' ), |
|
| 66 | + 'schema' => array($this, 'get_import_public_schema'), |
|
| 67 | 67 | ) |
| 68 | 68 | ); |
| 69 | 69 | register_rest_route( |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | array( |
| 73 | 73 | array( |
| 74 | 74 | 'methods' => \WP_REST_Server::READABLE, |
| 75 | - 'callback' => array( $this, 'get_import_status' ), |
|
| 76 | - 'permission_callback' => array( $this, 'import_permissions_check' ), |
|
| 75 | + 'callback' => array($this, 'get_import_status'), |
|
| 76 | + 'permission_callback' => array($this, 'import_permissions_check'), |
|
| 77 | 77 | ), |
| 78 | - 'schema' => array( $this, 'get_import_public_schema' ), |
|
| 78 | + 'schema' => array($this, 'get_import_public_schema'), |
|
| 79 | 79 | ) |
| 80 | 80 | ); |
| 81 | 81 | register_rest_route( |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | array( |
| 85 | 85 | array( |
| 86 | 86 | 'methods' => \WP_REST_Server::READABLE, |
| 87 | - 'callback' => array( $this, 'get_import_totals' ), |
|
| 88 | - 'permission_callback' => array( $this, 'import_permissions_check' ), |
|
| 87 | + 'callback' => array($this, 'get_import_totals'), |
|
| 88 | + 'permission_callback' => array($this, 'import_permissions_check'), |
|
| 89 | 89 | 'args' => $this->get_import_collection_params(), |
| 90 | 90 | ), |
| 91 | - 'schema' => array( $this, 'get_import_public_schema' ), |
|
| 91 | + 'schema' => array($this, 'get_import_public_schema'), |
|
| 92 | 92 | ) |
| 93 | 93 | ); |
| 94 | 94 | } |
@@ -99,9 +99,9 @@ discard block |
||
| 99 | 99 | * @param \WP_REST_Request $request Full data about the request. |
| 100 | 100 | * @return \WP_Error|bool |
| 101 | 101 | */ |
| 102 | - public function import_permissions_check( $request ) { |
|
| 103 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
| 104 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 102 | + public function import_permissions_check($request) { |
|
| 103 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
| 104 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 105 | 105 | } |
| 106 | 106 | return true; |
| 107 | 107 | } |
@@ -112,11 +112,11 @@ discard block |
||
| 112 | 112 | * @param \WP_REST_Request $request Request data. |
| 113 | 113 | * @return \WP_Error\WP_REST_Response |
| 114 | 114 | */ |
| 115 | - public function import_items( $request ) { |
|
| 116 | - $query_args = $this->prepare_objects_query( $request ); |
|
| 117 | - $import = \WC_Admin_Reports_Sync::regenerate_report_data( $query_args['days'], $query_args['skip_existing'] ); |
|
| 115 | + public function import_items($request) { |
|
| 116 | + $query_args = $this->prepare_objects_query($request); |
|
| 117 | + $import = \WC_Admin_Reports_Sync::regenerate_report_data($query_args['days'], $query_args['skip_existing']); |
|
| 118 | 118 | |
| 119 | - if ( is_wp_error( $import ) ) { |
|
| 119 | + if (is_wp_error($import)) { |
|
| 120 | 120 | $result = array( |
| 121 | 121 | 'status' => 'error', |
| 122 | 122 | 'message' => $import->get_error_message(), |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | ); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - $response = $this->prepare_item_for_response( $result, $request ); |
|
| 132 | - $data = $this->prepare_response_for_collection( $response ); |
|
| 131 | + $response = $this->prepare_item_for_response($result, $request); |
|
| 132 | + $data = $this->prepare_response_for_collection($response); |
|
| 133 | 133 | |
| 134 | - return rest_ensure_response( $data ); |
|
| 134 | + return rest_ensure_response($data); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @param \WP_REST_Request $request Request data. |
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | - protected function prepare_objects_query( $request ) { |
|
| 143 | + protected function prepare_objects_query($request) { |
|
| 144 | 144 | $args = array(); |
| 145 | 145 | $args['skip_existing'] = $request['skip_existing']; |
| 146 | 146 | $args['days'] = $request['days']; |
@@ -155,10 +155,10 @@ discard block |
||
| 155 | 155 | * @param \WP_REST_Request $request Request object. |
| 156 | 156 | * @return \WP_REST_Response $response Response data. |
| 157 | 157 | */ |
| 158 | - public function prepare_item_for_response( $item, $request ) { |
|
| 159 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
| 160 | - $data = $this->filter_response_by_context( $data, 'view' ); |
|
| 161 | - $response = rest_ensure_response( $data ); |
|
| 158 | + public function prepare_item_for_response($item, $request) { |
|
| 159 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
| 160 | + $data = $this->filter_response_by_context($data, 'view'); |
|
| 161 | + $response = rest_ensure_response($data); |
|
| 162 | 162 | |
| 163 | 163 | /** |
| 164 | 164 | * Filter the list returned from the API. |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @param array $item The original item. |
| 168 | 168 | * @param \WP_REST_Request $request Request used to generate the response. |
| 169 | 169 | */ |
| 170 | - return apply_filters( 'woocommerce_rest_prepare_reports_import', $response, $item, $request ); |
|
| 170 | + return apply_filters('woocommerce_rest_prepare_reports_import', $response, $item, $request); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -178,14 +178,14 @@ discard block |
||
| 178 | 178 | public function get_import_collection_params() { |
| 179 | 179 | $params = array(); |
| 180 | 180 | $params['days'] = array( |
| 181 | - 'description' => __( 'Number of days to import.', 'woocommerce' ), |
|
| 181 | + 'description' => __('Number of days to import.', 'woocommerce'), |
|
| 182 | 182 | 'type' => 'integer', |
| 183 | 183 | 'sanitize_callback' => 'absint', |
| 184 | 184 | 'validate_callback' => 'rest_validate_request_arg', |
| 185 | 185 | 'minimum' => 1, |
| 186 | 186 | ); |
| 187 | 187 | $params['skip_existing'] = array( |
| 188 | - 'description' => __( 'Skip importing existing order data.', 'woocommerce' ), |
|
| 188 | + 'description' => __('Skip importing existing order data.', 'woocommerce'), |
|
| 189 | 189 | 'type' => 'boolean', |
| 190 | 190 | 'default' => false, |
| 191 | 191 | 'sanitize_callback' => 'wc_string_to_bool', |
@@ -206,21 +206,21 @@ discard block |
||
| 206 | 206 | 'type' => 'object', |
| 207 | 207 | 'properties' => array( |
| 208 | 208 | 'status' => array( |
| 209 | - 'description' => __( 'Regeneration status.', 'woocommerce' ), |
|
| 209 | + 'description' => __('Regeneration status.', 'woocommerce'), |
|
| 210 | 210 | 'type' => 'string', |
| 211 | - 'context' => array( 'view', 'edit' ), |
|
| 211 | + 'context' => array('view', 'edit'), |
|
| 212 | 212 | 'readonly' => true, |
| 213 | 213 | ), |
| 214 | 214 | 'message' => array( |
| 215 | - 'description' => __( 'Regenerate data message.', 'woocommerce' ), |
|
| 215 | + 'description' => __('Regenerate data message.', 'woocommerce'), |
|
| 216 | 216 | 'type' => 'string', |
| 217 | - 'context' => array( 'view', 'edit' ), |
|
| 217 | + 'context' => array('view', 'edit'), |
|
| 218 | 218 | 'readonly' => true, |
| 219 | 219 | ), |
| 220 | 220 | ), |
| 221 | 221 | ); |
| 222 | 222 | |
| 223 | - return $this->add_additional_fields_schema( $schema ); |
|
| 223 | + return $this->add_additional_fields_schema($schema); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -229,18 +229,18 @@ discard block |
||
| 229 | 229 | * @param \WP_REST_Request $request Request data. |
| 230 | 230 | * @return \WP_Error\WP_REST_Response |
| 231 | 231 | */ |
| 232 | - public function cancel_import( $request ) { |
|
| 232 | + public function cancel_import($request) { |
|
| 233 | 233 | \WC_Admin_Reports_Sync::clear_queued_actions(); |
| 234 | 234 | |
| 235 | 235 | $result = array( |
| 236 | 236 | 'status' => 'success', |
| 237 | - 'message' => __( 'All pending and in-progress import actions have been cancelled.', 'woocommerce' ), |
|
| 237 | + 'message' => __('All pending and in-progress import actions have been cancelled.', 'woocommerce'), |
|
| 238 | 238 | ); |
| 239 | 239 | |
| 240 | - $response = $this->prepare_item_for_response( $result, $request ); |
|
| 241 | - $data = $this->prepare_response_for_collection( $response ); |
|
| 240 | + $response = $this->prepare_item_for_response($result, $request); |
|
| 241 | + $data = $this->prepare_response_for_collection($response); |
|
| 242 | 242 | |
| 243 | - return rest_ensure_response( $data ); |
|
| 243 | + return rest_ensure_response($data); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -249,10 +249,10 @@ discard block |
||
| 249 | 249 | * @param \WP_REST_Request $request Request data. |
| 250 | 250 | * @return \WP_Error\WP_REST_Response |
| 251 | 251 | */ |
| 252 | - public function delete_imported_items( $request ) { |
|
| 252 | + public function delete_imported_items($request) { |
|
| 253 | 253 | $delete = \WC_Admin_Reports_Sync::delete_report_data(); |
| 254 | 254 | |
| 255 | - if ( is_wp_error( $delete ) ) { |
|
| 255 | + if (is_wp_error($delete)) { |
|
| 256 | 256 | $result = array( |
| 257 | 257 | 'status' => 'error', |
| 258 | 258 | 'message' => $delete->get_error_message(), |
@@ -264,10 +264,10 @@ discard block |
||
| 264 | 264 | ); |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - $response = $this->prepare_item_for_response( $result, $request ); |
|
| 268 | - $data = $this->prepare_response_for_collection( $response ); |
|
| 267 | + $response = $this->prepare_item_for_response($result, $request); |
|
| 268 | + $data = $this->prepare_response_for_collection($response); |
|
| 269 | 269 | |
| 270 | - return rest_ensure_response( $data ); |
|
| 270 | + return rest_ensure_response($data); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -276,20 +276,20 @@ discard block |
||
| 276 | 276 | * @param \WP_REST_Request $request Request data. |
| 277 | 277 | * @return \WP_Error\WP_REST_Response |
| 278 | 278 | */ |
| 279 | - public function get_import_status( $request ) { |
|
| 279 | + public function get_import_status($request) { |
|
| 280 | 280 | $result = array( |
| 281 | 281 | 'is_importing' => \WC_Admin_Reports_Sync::is_importing(), |
| 282 | - 'customers_total' => get_option( 'wc_admin_import_customers_total', 0 ), |
|
| 283 | - 'customers_count' => get_option( 'wc_admin_import_customers_count', 0 ), |
|
| 284 | - 'orders_total' => get_option( 'wc_admin_import_orders_total', 0 ), |
|
| 285 | - 'orders_count' => get_option( 'wc_admin_import_orders_count', 0 ), |
|
| 286 | - 'imported_from' => get_option( 'wc_admin_imported_from_date', false ), |
|
| 282 | + 'customers_total' => get_option('wc_admin_import_customers_total', 0), |
|
| 283 | + 'customers_count' => get_option('wc_admin_import_customers_count', 0), |
|
| 284 | + 'orders_total' => get_option('wc_admin_import_orders_total', 0), |
|
| 285 | + 'orders_count' => get_option('wc_admin_import_orders_count', 0), |
|
| 286 | + 'imported_from' => get_option('wc_admin_imported_from_date', false), |
|
| 287 | 287 | ); |
| 288 | 288 | |
| 289 | - $response = $this->prepare_item_for_response( $result, $request ); |
|
| 290 | - $data = $this->prepare_response_for_collection( $response ); |
|
| 289 | + $response = $this->prepare_item_for_response($result, $request); |
|
| 290 | + $data = $this->prepare_response_for_collection($response); |
|
| 291 | 291 | |
| 292 | - return rest_ensure_response( $data ); |
|
| 292 | + return rest_ensure_response($data); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -298,13 +298,13 @@ discard block |
||
| 298 | 298 | * @param \WP_REST_Request $request Request data. |
| 299 | 299 | * @return \WP_Error\WP_REST_Response |
| 300 | 300 | */ |
| 301 | - public function get_import_totals( $request ) { |
|
| 302 | - $query_args = $this->prepare_objects_query( $request ); |
|
| 303 | - $totals = \WC_Admin_Reports_Sync::get_import_totals( $query_args['days'], $query_args['skip_existing'] ); |
|
| 301 | + public function get_import_totals($request) { |
|
| 302 | + $query_args = $this->prepare_objects_query($request); |
|
| 303 | + $totals = \WC_Admin_Reports_Sync::get_import_totals($query_args['days'], $query_args['skip_existing']); |
|
| 304 | 304 | |
| 305 | - $response = $this->prepare_item_for_response( $totals, $request ); |
|
| 306 | - $data = $this->prepare_response_for_collection( $response ); |
|
| 305 | + $response = $this->prepare_item_for_response($totals, $request); |
|
| 306 | + $data = $this->prepare_response_for_collection($response); |
|
| 307 | 307 | |
| 308 | - return rest_ensure_response( $data ); |
|
| 308 | + return rest_ensure_response($data); |
|
| 309 | 309 | } |
| 310 | 310 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param array $request Request array. |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - protected function prepare_reports_query( $request ) { |
|
| 34 | + protected function prepare_reports_query($request) { |
|
| 35 | 35 | $args = array(); |
| 36 | 36 | $args['before'] = $request['before']; |
| 37 | 37 | $args['after'] = $request['after']; |
@@ -50,37 +50,37 @@ discard block |
||
| 50 | 50 | * @param \WP_REST_Request $request Request data. |
| 51 | 51 | * @return array|\WP_Error |
| 52 | 52 | */ |
| 53 | - public function get_items( $request ) { |
|
| 54 | - $query_args = $this->prepare_reports_query( $request ); |
|
| 55 | - $taxes_query = new \WC_Admin_Reports_Taxes_Query( $query_args ); |
|
| 53 | + public function get_items($request) { |
|
| 54 | + $query_args = $this->prepare_reports_query($request); |
|
| 55 | + $taxes_query = new \WC_Admin_Reports_Taxes_Query($query_args); |
|
| 56 | 56 | $report_data = $taxes_query->get_data(); |
| 57 | 57 | |
| 58 | 58 | $data = array(); |
| 59 | 59 | |
| 60 | - foreach ( $report_data->data as $tax_data ) { |
|
| 61 | - $item = $this->prepare_item_for_response( (object) $tax_data, $request ); |
|
| 62 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 60 | + foreach ($report_data->data as $tax_data) { |
|
| 61 | + $item = $this->prepare_item_for_response((object) $tax_data, $request); |
|
| 62 | + $data[] = $this->prepare_response_for_collection($item); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - $response = rest_ensure_response( $data ); |
|
| 66 | - $response->header( 'X-WP-Total', (int) $report_data->total ); |
|
| 67 | - $response->header( 'X-WP-TotalPages', (int) $report_data->pages ); |
|
| 65 | + $response = rest_ensure_response($data); |
|
| 66 | + $response->header('X-WP-Total', (int) $report_data->total); |
|
| 67 | + $response->header('X-WP-TotalPages', (int) $report_data->pages); |
|
| 68 | 68 | |
| 69 | 69 | $page = $report_data->page_no; |
| 70 | 70 | $max_pages = $report_data->pages; |
| 71 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 72 | - if ( $page > 1 ) { |
|
| 71 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 72 | + if ($page > 1) { |
|
| 73 | 73 | $prev_page = $page - 1; |
| 74 | - if ( $prev_page > $max_pages ) { |
|
| 74 | + if ($prev_page > $max_pages) { |
|
| 75 | 75 | $prev_page = $max_pages; |
| 76 | 76 | } |
| 77 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 78 | - $response->link_header( 'prev', $prev_link ); |
|
| 77 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 78 | + $response->link_header('prev', $prev_link); |
|
| 79 | 79 | } |
| 80 | - if ( $max_pages > $page ) { |
|
| 80 | + if ($max_pages > $page) { |
|
| 81 | 81 | $next_page = $page + 1; |
| 82 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 83 | - $response->link_header( 'next', $next_link ); |
|
| 82 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 83 | + $response->link_header('next', $next_link); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | return $response; |
@@ -93,14 +93,14 @@ discard block |
||
| 93 | 93 | * @param \WP_REST_Request $request Request object. |
| 94 | 94 | * @return \WP_REST_Response |
| 95 | 95 | */ |
| 96 | - public function prepare_item_for_response( $report, $request ) { |
|
| 97 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 98 | - $report = $this->add_additional_fields_to_object( $report, $request ); |
|
| 99 | - $report = $this->filter_response_by_context( $report, $context ); |
|
| 96 | + public function prepare_item_for_response($report, $request) { |
|
| 97 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 98 | + $report = $this->add_additional_fields_to_object($report, $request); |
|
| 99 | + $report = $this->filter_response_by_context($report, $context); |
|
| 100 | 100 | |
| 101 | 101 | // Wrap the data in a response object. |
| 102 | - $response = rest_ensure_response( $report ); |
|
| 103 | - $response->add_links( $this->prepare_links( $report ) ); |
|
| 102 | + $response = rest_ensure_response($report); |
|
| 103 | + $response->add_links($this->prepare_links($report)); |
|
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | 106 | * Filter a report returned from the API. |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @param object $report The original report object. |
| 112 | 112 | * @param \WP_REST_Request $request Request used to generate the response. |
| 113 | 113 | */ |
| 114 | - return apply_filters( 'woocommerce_rest_prepare_report_taxes', $response, $report, $request ); |
|
| 114 | + return apply_filters('woocommerce_rest_prepare_report_taxes', $response, $report, $request); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | * @param WC_Reports_Query $object Object data. |
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | - protected function prepare_links( $object ) { |
|
| 123 | + protected function prepare_links($object) { |
|
| 124 | 124 | $links = array( |
| 125 | 125 | 'tax' => array( |
| 126 | - 'href' => rest_url( sprintf( '/%s/taxes/%d', $this->namespace, $object->tax_rate_id ) ), |
|
| 126 | + 'href' => rest_url(sprintf('/%s/taxes/%d', $this->namespace, $object->tax_rate_id)), |
|
| 127 | 127 | ), |
| 128 | 128 | ); |
| 129 | 129 | |
@@ -142,69 +142,69 @@ discard block |
||
| 142 | 142 | 'type' => 'object', |
| 143 | 143 | 'properties' => array( |
| 144 | 144 | 'tax_rate_id' => array( |
| 145 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
| 145 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
| 146 | 146 | 'type' => 'integer', |
| 147 | - 'context' => array( 'view', 'edit' ), |
|
| 147 | + 'context' => array('view', 'edit'), |
|
| 148 | 148 | 'readonly' => true, |
| 149 | 149 | ), |
| 150 | 150 | 'name' => array( |
| 151 | - 'description' => __( 'Tax rate name.', 'woocommerce' ), |
|
| 151 | + 'description' => __('Tax rate name.', 'woocommerce'), |
|
| 152 | 152 | 'type' => 'string', |
| 153 | - 'context' => array( 'view', 'edit' ), |
|
| 153 | + 'context' => array('view', 'edit'), |
|
| 154 | 154 | 'readonly' => true, |
| 155 | 155 | ), |
| 156 | 156 | 'tax_rate' => array( |
| 157 | - 'description' => __( 'Tax rate.', 'woocommerce' ), |
|
| 157 | + 'description' => __('Tax rate.', 'woocommerce'), |
|
| 158 | 158 | 'type' => 'number', |
| 159 | - 'context' => array( 'view', 'edit' ), |
|
| 159 | + 'context' => array('view', 'edit'), |
|
| 160 | 160 | 'readonly' => true, |
| 161 | 161 | ), |
| 162 | 162 | 'country' => array( |
| 163 | - 'description' => __( 'Country.', 'woocommerce' ), |
|
| 163 | + 'description' => __('Country.', 'woocommerce'), |
|
| 164 | 164 | 'type' => 'string', |
| 165 | - 'context' => array( 'view', 'edit' ), |
|
| 165 | + 'context' => array('view', 'edit'), |
|
| 166 | 166 | 'readonly' => true, |
| 167 | 167 | ), |
| 168 | 168 | 'state' => array( |
| 169 | - 'description' => __( 'State.', 'woocommerce' ), |
|
| 169 | + 'description' => __('State.', 'woocommerce'), |
|
| 170 | 170 | 'type' => 'string', |
| 171 | - 'context' => array( 'view', 'edit' ), |
|
| 171 | + 'context' => array('view', 'edit'), |
|
| 172 | 172 | 'readonly' => true, |
| 173 | 173 | ), |
| 174 | 174 | 'priority' => array( |
| 175 | - 'description' => __( 'Priority.', 'woocommerce' ), |
|
| 175 | + 'description' => __('Priority.', 'woocommerce'), |
|
| 176 | 176 | 'type' => 'integer', |
| 177 | - 'context' => array( 'view', 'edit' ), |
|
| 177 | + 'context' => array('view', 'edit'), |
|
| 178 | 178 | 'readonly' => true, |
| 179 | 179 | ), |
| 180 | 180 | 'total_tax' => array( |
| 181 | - 'description' => __( 'Total tax.', 'woocommerce' ), |
|
| 181 | + 'description' => __('Total tax.', 'woocommerce'), |
|
| 182 | 182 | 'type' => 'number', |
| 183 | - 'context' => array( 'view', 'edit' ), |
|
| 183 | + 'context' => array('view', 'edit'), |
|
| 184 | 184 | 'readonly' => true, |
| 185 | 185 | ), |
| 186 | 186 | 'order_tax' => array( |
| 187 | - 'description' => __( 'Order tax.', 'woocommerce' ), |
|
| 187 | + 'description' => __('Order tax.', 'woocommerce'), |
|
| 188 | 188 | 'type' => 'number', |
| 189 | - 'context' => array( 'view', 'edit' ), |
|
| 189 | + 'context' => array('view', 'edit'), |
|
| 190 | 190 | 'readonly' => true, |
| 191 | 191 | ), |
| 192 | 192 | 'shipping_tax' => array( |
| 193 | - 'description' => __( 'Shipping tax.', 'woocommerce' ), |
|
| 193 | + 'description' => __('Shipping tax.', 'woocommerce'), |
|
| 194 | 194 | 'type' => 'number', |
| 195 | - 'context' => array( 'view', 'edit' ), |
|
| 195 | + 'context' => array('view', 'edit'), |
|
| 196 | 196 | 'readonly' => true, |
| 197 | 197 | ), |
| 198 | 198 | 'orders_count' => array( |
| 199 | - 'description' => __( 'Amount of orders.', 'woocommerce' ), |
|
| 199 | + 'description' => __('Amount of orders.', 'woocommerce'), |
|
| 200 | 200 | 'type' => 'integer', |
| 201 | - 'context' => array( 'view', 'edit' ), |
|
| 201 | + 'context' => array('view', 'edit'), |
|
| 202 | 202 | 'readonly' => true, |
| 203 | 203 | ), |
| 204 | 204 | ), |
| 205 | 205 | ); |
| 206 | 206 | |
| 207 | - return $this->add_additional_fields_schema( $schema ); |
|
| 207 | + return $this->add_additional_fields_schema($schema); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -214,9 +214,9 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | public function get_collection_params() { |
| 216 | 216 | $params = array(); |
| 217 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 217 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 218 | 218 | $params['page'] = array( |
| 219 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 219 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 220 | 220 | 'type' => 'integer', |
| 221 | 221 | 'default' => 1, |
| 222 | 222 | 'sanitize_callback' => 'absint', |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | 'minimum' => 1, |
| 225 | 225 | ); |
| 226 | 226 | $params['per_page'] = array( |
| 227 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 227 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 228 | 228 | 'type' => 'integer', |
| 229 | 229 | 'default' => 10, |
| 230 | 230 | 'minimum' => 1, |
@@ -232,27 +232,27 @@ discard block |
||
| 232 | 232 | 'sanitize_callback' => 'absint', |
| 233 | 233 | 'validate_callback' => 'rest_validate_request_arg', |
| 234 | 234 | ); |
| 235 | - $params['after'] = array( |
|
| 236 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 235 | + $params['after'] = array( |
|
| 236 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 237 | 237 | 'type' => 'string', |
| 238 | 238 | 'format' => 'date-time', |
| 239 | 239 | 'validate_callback' => 'rest_validate_request_arg', |
| 240 | 240 | ); |
| 241 | - $params['before'] = array( |
|
| 242 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 241 | + $params['before'] = array( |
|
| 242 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 243 | 243 | 'type' => 'string', |
| 244 | 244 | 'format' => 'date-time', |
| 245 | 245 | 'validate_callback' => 'rest_validate_request_arg', |
| 246 | 246 | ); |
| 247 | - $params['order'] = array( |
|
| 248 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 247 | + $params['order'] = array( |
|
| 248 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 249 | 249 | 'type' => 'string', |
| 250 | 250 | 'default' => 'desc', |
| 251 | - 'enum' => array( 'asc', 'desc' ), |
|
| 251 | + 'enum' => array('asc', 'desc'), |
|
| 252 | 252 | 'validate_callback' => 'rest_validate_request_arg', |
| 253 | 253 | ); |
| 254 | - $params['orderby'] = array( |
|
| 255 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 254 | + $params['orderby'] = array( |
|
| 255 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 256 | 256 | 'type' => 'string', |
| 257 | 257 | 'default' => 'tax_rate_id', |
| 258 | 258 | 'enum' => array( |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | ), |
| 268 | 268 | 'validate_callback' => 'rest_validate_request_arg', |
| 269 | 269 | ); |
| 270 | - $params['taxes'] = array( |
|
| 271 | - 'description' => __( 'Limit result set to items assigned one or more tax rates.', 'woocommerce' ), |
|
| 270 | + $params['taxes'] = array( |
|
| 271 | + 'description' => __('Limit result set to items assigned one or more tax rates.', 'woocommerce'), |
|
| 272 | 272 | 'type' => 'array', |
| 273 | 273 | 'sanitize_callback' => 'wp_parse_id_list', |
| 274 | 274 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -31,45 +31,45 @@ discard block |
||
| 31 | 31 | * @param \WP_REST_Request $request Request data. |
| 32 | 32 | * @return array|\WP_Error |
| 33 | 33 | */ |
| 34 | - public function get_items( $request ) { |
|
| 34 | + public function get_items($request) { |
|
| 35 | 35 | $args = array(); |
| 36 | - $registered = array_keys( $this->get_collection_params() ); |
|
| 37 | - foreach ( $registered as $param_name ) { |
|
| 38 | - if ( isset( $request[ $param_name ] ) ) { |
|
| 39 | - $args[ $param_name ] = $request[ $param_name ]; |
|
| 36 | + $registered = array_keys($this->get_collection_params()); |
|
| 37 | + foreach ($registered as $param_name) { |
|
| 38 | + if (isset($request[$param_name])) { |
|
| 39 | + $args[$param_name] = $request[$param_name]; |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - $reports = new \WC_Admin_Reports_Downloads_Query( $args ); |
|
| 43 | + $reports = new \WC_Admin_Reports_Downloads_Query($args); |
|
| 44 | 44 | $downloads_data = $reports->get_data(); |
| 45 | 45 | |
| 46 | 46 | $data = array(); |
| 47 | 47 | |
| 48 | - foreach ( $downloads_data->data as $download_data ) { |
|
| 49 | - $item = $this->prepare_item_for_response( $download_data, $request ); |
|
| 50 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 48 | + foreach ($downloads_data->data as $download_data) { |
|
| 49 | + $item = $this->prepare_item_for_response($download_data, $request); |
|
| 50 | + $data[] = $this->prepare_response_for_collection($item); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - $response = rest_ensure_response( $data ); |
|
| 53 | + $response = rest_ensure_response($data); |
|
| 54 | 54 | |
| 55 | - $response->header( 'X-WP-Total', (int) $downloads_data->total ); |
|
| 56 | - $response->header( 'X-WP-TotalPages', (int) $downloads_data->pages ); |
|
| 55 | + $response->header('X-WP-Total', (int) $downloads_data->total); |
|
| 56 | + $response->header('X-WP-TotalPages', (int) $downloads_data->pages); |
|
| 57 | 57 | |
| 58 | 58 | $page = $downloads_data->page_no; |
| 59 | 59 | $max_pages = $downloads_data->pages; |
| 60 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 61 | - if ( $page > 1 ) { |
|
| 60 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 61 | + if ($page > 1) { |
|
| 62 | 62 | $prev_page = $page - 1; |
| 63 | - if ( $prev_page > $max_pages ) { |
|
| 63 | + if ($prev_page > $max_pages) { |
|
| 64 | 64 | $prev_page = $max_pages; |
| 65 | 65 | } |
| 66 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 67 | - $response->link_header( 'prev', $prev_link ); |
|
| 66 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 67 | + $response->link_header('prev', $prev_link); |
|
| 68 | 68 | } |
| 69 | - if ( $max_pages > $page ) { |
|
| 69 | + if ($max_pages > $page) { |
|
| 70 | 70 | $next_page = $page + 1; |
| 71 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 72 | - $response->link_header( 'next', $next_link ); |
|
| 71 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 72 | + $response->link_header('next', $next_link); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | return $response; |
@@ -82,30 +82,30 @@ discard block |
||
| 82 | 82 | * @param \WP_REST_Request $request Request object. |
| 83 | 83 | * @return \WP_REST_Response |
| 84 | 84 | */ |
| 85 | - public function prepare_item_for_response( $report, $request ) { |
|
| 85 | + public function prepare_item_for_response($report, $request) { |
|
| 86 | 86 | $data = $report; |
| 87 | 87 | |
| 88 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 89 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 90 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 88 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 89 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 90 | + $data = $this->filter_response_by_context($data, $context); |
|
| 91 | 91 | |
| 92 | 92 | // Wrap the data in a response object. |
| 93 | - $response = rest_ensure_response( $data ); |
|
| 94 | - $response->add_links( $this->prepare_links( $report ) ); |
|
| 93 | + $response = rest_ensure_response($data); |
|
| 94 | + $response->add_links($this->prepare_links($report)); |
|
| 95 | 95 | |
| 96 | - $response->data['date'] = get_date_from_gmt( $data['date_gmt'], 'Y-m-d H:i:s' ); |
|
| 96 | + $response->data['date'] = get_date_from_gmt($data['date_gmt'], 'Y-m-d H:i:s'); |
|
| 97 | 97 | |
| 98 | 98 | // Figure out file name. |
| 99 | 99 | // Matches https://github.com/woocommerce/woocommerce/blob/4be0018c092e617c5d2b8c46b800eb71ece9ddef/includes/class-wc-download-handler.php#L197. |
| 100 | - $product_id = intval( $data['product_id'] ); |
|
| 101 | - $_product = wc_get_product( $product_id ); |
|
| 102 | - $file_path = $_product->get_file_download_path( $data['download_id'] ); |
|
| 103 | - $filename = basename( $file_path ); |
|
| 104 | - $response->data['file_name'] = apply_filters( 'woocommerce_file_download_filename', $filename, $product_id ); |
|
| 100 | + $product_id = intval($data['product_id']); |
|
| 101 | + $_product = wc_get_product($product_id); |
|
| 102 | + $file_path = $_product->get_file_download_path($data['download_id']); |
|
| 103 | + $filename = basename($file_path); |
|
| 104 | + $response->data['file_name'] = apply_filters('woocommerce_file_download_filename', $filename, $product_id); |
|
| 105 | 105 | $response->data['file_path'] = $file_path; |
| 106 | - $customer = new \WC_Customer( $data['user_id'] ); |
|
| 106 | + $customer = new \WC_Customer($data['user_id']); |
|
| 107 | 107 | $response->data['username'] = $customer->get_username(); |
| 108 | - $response->data['order_number'] = $this->get_order_number( $data['order_id'] ); |
|
| 108 | + $response->data['order_number'] = $this->get_order_number($data['order_id']); |
|
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | 111 | * Filter a report returned from the API. |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * @param object $report The original report object. |
| 117 | 117 | * @param \WP_REST_Request $request Request used to generate the response. |
| 118 | 118 | */ |
| 119 | - return apply_filters( 'woocommerce_rest_prepare_report_downloads', $response, $report, $request ); |
|
| 119 | + return apply_filters('woocommerce_rest_prepare_report_downloads', $response, $report, $request); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -125,10 +125,10 @@ discard block |
||
| 125 | 125 | * @param Array $object Object data. |
| 126 | 126 | * @return array Links for the given post. |
| 127 | 127 | */ |
| 128 | - protected function prepare_links( $object ) { |
|
| 128 | + protected function prepare_links($object) { |
|
| 129 | 129 | $links = array( |
| 130 | 130 | 'product' => array( |
| 131 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, 'products', $object['product_id'] ) ), |
|
| 131 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, 'products', $object['product_id'])), |
|
| 132 | 132 | 'embeddable' => true, |
| 133 | 133 | ), |
| 134 | 134 | ); |
@@ -150,85 +150,85 @@ discard block |
||
| 150 | 150 | 'id' => array( |
| 151 | 151 | 'type' => 'integer', |
| 152 | 152 | 'readonly' => true, |
| 153 | - 'context' => array( 'view', 'edit' ), |
|
| 154 | - 'description' => __( 'ID.', 'woocommerce' ), |
|
| 153 | + 'context' => array('view', 'edit'), |
|
| 154 | + 'description' => __('ID.', 'woocommerce'), |
|
| 155 | 155 | ), |
| 156 | 156 | 'product_id' => array( |
| 157 | 157 | 'type' => 'integer', |
| 158 | 158 | 'readonly' => true, |
| 159 | - 'context' => array( 'view', 'edit' ), |
|
| 160 | - 'description' => __( 'Product ID.', 'woocommerce' ), |
|
| 159 | + 'context' => array('view', 'edit'), |
|
| 160 | + 'description' => __('Product ID.', 'woocommerce'), |
|
| 161 | 161 | ), |
| 162 | 162 | 'date' => array( |
| 163 | - 'description' => __( "The date of the download, in the site's timezone.", 'woocommerce' ), |
|
| 163 | + 'description' => __("The date of the download, in the site's timezone.", 'woocommerce'), |
|
| 164 | 164 | 'type' => 'date-time', |
| 165 | - 'context' => array( 'view', 'edit' ), |
|
| 165 | + 'context' => array('view', 'edit'), |
|
| 166 | 166 | 'readonly' => true, |
| 167 | 167 | ), |
| 168 | 168 | 'date_gmt' => array( |
| 169 | - 'description' => __( 'The date of the download, as GMT.', 'woocommerce' ), |
|
| 169 | + 'description' => __('The date of the download, as GMT.', 'woocommerce'), |
|
| 170 | 170 | 'type' => 'date-time', |
| 171 | - 'context' => array( 'view', 'edit' ), |
|
| 171 | + 'context' => array('view', 'edit'), |
|
| 172 | 172 | 'readonly' => true, |
| 173 | 173 | ), |
| 174 | 174 | 'download_id' => array( |
| 175 | 175 | 'type' => 'string', |
| 176 | 176 | 'readonly' => true, |
| 177 | - 'context' => array( 'view', 'edit' ), |
|
| 178 | - 'description' => __( 'Download ID.', 'woocommerce' ), |
|
| 177 | + 'context' => array('view', 'edit'), |
|
| 178 | + 'description' => __('Download ID.', 'woocommerce'), |
|
| 179 | 179 | ), |
| 180 | 180 | 'file_name' => array( |
| 181 | 181 | 'type' => 'string', |
| 182 | 182 | 'readonly' => true, |
| 183 | - 'context' => array( 'view', 'edit' ), |
|
| 184 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
| 183 | + 'context' => array('view', 'edit'), |
|
| 184 | + 'description' => __('File name.', 'woocommerce'), |
|
| 185 | 185 | ), |
| 186 | 186 | 'file_path' => array( |
| 187 | 187 | 'type' => 'string', |
| 188 | 188 | 'readonly' => true, |
| 189 | - 'context' => array( 'view', 'edit' ), |
|
| 190 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
| 189 | + 'context' => array('view', 'edit'), |
|
| 190 | + 'description' => __('File URL.', 'woocommerce'), |
|
| 191 | 191 | ), |
| 192 | 192 | 'product_id' => array( |
| 193 | 193 | 'type' => 'integer', |
| 194 | 194 | 'readonly' => true, |
| 195 | - 'context' => array( 'view', 'edit' ), |
|
| 196 | - 'description' => __( 'Product ID.', 'woocommerce' ), |
|
| 195 | + 'context' => array('view', 'edit'), |
|
| 196 | + 'description' => __('Product ID.', 'woocommerce'), |
|
| 197 | 197 | ), |
| 198 | 198 | 'order_id' => array( |
| 199 | 199 | 'type' => 'integer', |
| 200 | 200 | 'readonly' => true, |
| 201 | - 'context' => array( 'view', 'edit' ), |
|
| 202 | - 'description' => __( 'Order ID.', 'woocommerce' ), |
|
| 201 | + 'context' => array('view', 'edit'), |
|
| 202 | + 'description' => __('Order ID.', 'woocommerce'), |
|
| 203 | 203 | ), |
| 204 | 204 | 'order_number' => array( |
| 205 | 205 | 'type' => 'string', |
| 206 | 206 | 'readonly' => true, |
| 207 | - 'context' => array( 'view', 'edit' ), |
|
| 208 | - 'description' => __( 'Order Number.', 'woocommerce' ), |
|
| 207 | + 'context' => array('view', 'edit'), |
|
| 208 | + 'description' => __('Order Number.', 'woocommerce'), |
|
| 209 | 209 | ), |
| 210 | 210 | 'user_id' => array( |
| 211 | 211 | 'type' => 'integer', |
| 212 | 212 | 'readonly' => true, |
| 213 | - 'context' => array( 'view', 'edit' ), |
|
| 214 | - 'description' => __( 'User ID for the downloader.', 'woocommerce' ), |
|
| 213 | + 'context' => array('view', 'edit'), |
|
| 214 | + 'description' => __('User ID for the downloader.', 'woocommerce'), |
|
| 215 | 215 | ), |
| 216 | 216 | 'username' => array( |
| 217 | 217 | 'type' => 'string', |
| 218 | 218 | 'readonly' => true, |
| 219 | - 'context' => array( 'view', 'edit' ), |
|
| 220 | - 'description' => __( 'User name of the downloader.', 'woocommerce' ), |
|
| 219 | + 'context' => array('view', 'edit'), |
|
| 220 | + 'description' => __('User name of the downloader.', 'woocommerce'), |
|
| 221 | 221 | ), |
| 222 | 222 | 'ip_address' => array( |
| 223 | 223 | 'type' => 'string', |
| 224 | 224 | 'readonly' => true, |
| 225 | - 'context' => array( 'view', 'edit' ), |
|
| 226 | - 'description' => __( 'IP address for the downloader.', 'woocommerce' ), |
|
| 225 | + 'context' => array('view', 'edit'), |
|
| 226 | + 'description' => __('IP address for the downloader.', 'woocommerce'), |
|
| 227 | 227 | ), |
| 228 | 228 | ), |
| 229 | 229 | ); |
| 230 | 230 | |
| 231 | - return $this->add_additional_fields_schema( $schema ); |
|
| 231 | + return $this->add_additional_fields_schema($schema); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
@@ -238,17 +238,17 @@ discard block |
||
| 238 | 238 | */ |
| 239 | 239 | public function get_collection_params() { |
| 240 | 240 | $params = array(); |
| 241 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 241 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 242 | 242 | $params['page'] = array( |
| 243 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 243 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 244 | 244 | 'type' => 'integer', |
| 245 | 245 | 'default' => 1, |
| 246 | 246 | 'sanitize_callback' => 'absint', |
| 247 | 247 | 'validate_callback' => 'rest_validate_request_arg', |
| 248 | 248 | 'minimum' => 1, |
| 249 | 249 | ); |
| 250 | - $params['per_page'] = array( |
|
| 251 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 250 | + $params['per_page'] = array( |
|
| 251 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 252 | 252 | 'type' => 'integer', |
| 253 | 253 | 'default' => 10, |
| 254 | 254 | 'minimum' => 1, |
@@ -256,27 +256,27 @@ discard block |
||
| 256 | 256 | 'sanitize_callback' => 'absint', |
| 257 | 257 | 'validate_callback' => 'rest_validate_request_arg', |
| 258 | 258 | ); |
| 259 | - $params['after'] = array( |
|
| 260 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 259 | + $params['after'] = array( |
|
| 260 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 261 | 261 | 'type' => 'string', |
| 262 | 262 | 'format' => 'date-time', |
| 263 | 263 | 'validate_callback' => 'rest_validate_request_arg', |
| 264 | 264 | ); |
| 265 | - $params['before'] = array( |
|
| 266 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 265 | + $params['before'] = array( |
|
| 266 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 267 | 267 | 'type' => 'string', |
| 268 | 268 | 'format' => 'date-time', |
| 269 | 269 | 'validate_callback' => 'rest_validate_request_arg', |
| 270 | 270 | ); |
| 271 | - $params['order'] = array( |
|
| 272 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 271 | + $params['order'] = array( |
|
| 272 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 273 | 273 | 'type' => 'string', |
| 274 | 274 | 'default' => 'desc', |
| 275 | - 'enum' => array( 'asc', 'desc' ), |
|
| 275 | + 'enum' => array('asc', 'desc'), |
|
| 276 | 276 | 'validate_callback' => 'rest_validate_request_arg', |
| 277 | 277 | ); |
| 278 | - $params['orderby'] = array( |
|
| 279 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 278 | + $params['orderby'] = array( |
|
| 279 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 280 | 280 | 'type' => 'string', |
| 281 | 281 | 'default' => 'date', |
| 282 | 282 | 'enum' => array( |
@@ -285,8 +285,8 @@ discard block |
||
| 285 | 285 | ), |
| 286 | 286 | 'validate_callback' => 'rest_validate_request_arg', |
| 287 | 287 | ); |
| 288 | - $params['match'] = array( |
|
| 289 | - 'description' => __( 'Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: products, orders, username, ip_address.', 'woocommerce' ), |
|
| 288 | + $params['match'] = array( |
|
| 289 | + 'description' => __('Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: products, orders, username, ip_address.', 'woocommerce'), |
|
| 290 | 290 | 'type' => 'string', |
| 291 | 291 | 'default' => 'all', |
| 292 | 292 | 'enum' => array( |
@@ -295,8 +295,8 @@ discard block |
||
| 295 | 295 | ), |
| 296 | 296 | 'validate_callback' => 'rest_validate_request_arg', |
| 297 | 297 | ); |
| 298 | - $params['product_includes'] = array( |
|
| 299 | - 'description' => __( 'Limit result set to items that have the specified product(s) assigned.', 'woocommerce' ), |
|
| 298 | + $params['product_includes'] = array( |
|
| 299 | + 'description' => __('Limit result set to items that have the specified product(s) assigned.', 'woocommerce'), |
|
| 300 | 300 | 'type' => 'array', |
| 301 | 301 | 'items' => array( |
| 302 | 302 | 'type' => 'integer', |
@@ -305,8 +305,8 @@ discard block |
||
| 305 | 305 | 'sanitize_callback' => 'wp_parse_id_list', |
| 306 | 306 | 'validate_callback' => 'rest_validate_request_arg', |
| 307 | 307 | ); |
| 308 | - $params['product_excludes'] = array( |
|
| 309 | - 'description' => __( 'Limit result set to items that don\'t have the specified product(s) assigned.', 'woocommerce' ), |
|
| 308 | + $params['product_excludes'] = array( |
|
| 309 | + 'description' => __('Limit result set to items that don\'t have the specified product(s) assigned.', 'woocommerce'), |
|
| 310 | 310 | 'type' => 'array', |
| 311 | 311 | 'items' => array( |
| 312 | 312 | 'type' => 'integer', |
@@ -315,8 +315,8 @@ discard block |
||
| 315 | 315 | 'validate_callback' => 'rest_validate_request_arg', |
| 316 | 316 | 'sanitize_callback' => 'wp_parse_id_list', |
| 317 | 317 | ); |
| 318 | - $params['order_includes'] = array( |
|
| 319 | - 'description' => __( 'Limit result set to items that have the specified order ids.', 'woocommerce' ), |
|
| 318 | + $params['order_includes'] = array( |
|
| 319 | + 'description' => __('Limit result set to items that have the specified order ids.', 'woocommerce'), |
|
| 320 | 320 | 'type' => 'array', |
| 321 | 321 | 'sanitize_callback' => 'wp_parse_id_list', |
| 322 | 322 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -324,8 +324,8 @@ discard block |
||
| 324 | 324 | 'type' => 'integer', |
| 325 | 325 | ), |
| 326 | 326 | ); |
| 327 | - $params['order_excludes'] = array( |
|
| 328 | - 'description' => __( 'Limit result set to items that don\'t have the specified order ids.', 'woocommerce' ), |
|
| 327 | + $params['order_excludes'] = array( |
|
| 328 | + 'description' => __('Limit result set to items that don\'t have the specified order ids.', 'woocommerce'), |
|
| 329 | 329 | 'type' => 'array', |
| 330 | 330 | 'sanitize_callback' => 'wp_parse_id_list', |
| 331 | 331 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -333,8 +333,8 @@ discard block |
||
| 333 | 333 | 'type' => 'integer', |
| 334 | 334 | ), |
| 335 | 335 | ); |
| 336 | - $params['customer_includes'] = array( |
|
| 337 | - 'description' => __( 'Limit response to objects that have the specified user ids.', 'woocommerce' ), |
|
| 336 | + $params['customer_includes'] = array( |
|
| 337 | + 'description' => __('Limit response to objects that have the specified user ids.', 'woocommerce'), |
|
| 338 | 338 | 'type' => 'array', |
| 339 | 339 | 'sanitize_callback' => 'wp_parse_id_list', |
| 340 | 340 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -342,8 +342,8 @@ discard block |
||
| 342 | 342 | 'type' => 'integer', |
| 343 | 343 | ), |
| 344 | 344 | ); |
| 345 | - $params['customer_excludes'] = array( |
|
| 346 | - 'description' => __( 'Limit response to objects that don\'t have the specified user ids.', 'woocommerce' ), |
|
| 345 | + $params['customer_excludes'] = array( |
|
| 346 | + 'description' => __('Limit response to objects that don\'t have the specified user ids.', 'woocommerce'), |
|
| 347 | 347 | 'type' => 'array', |
| 348 | 348 | 'sanitize_callback' => 'wp_parse_id_list', |
| 349 | 349 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | ), |
| 353 | 353 | ); |
| 354 | 354 | $params['ip_address_includes'] = array( |
| 355 | - 'description' => __( 'Limit response to objects that have a specified ip address.', 'woocommerce' ), |
|
| 355 | + 'description' => __('Limit response to objects that have a specified ip address.', 'woocommerce'), |
|
| 356 | 356 | 'type' => 'array', |
| 357 | 357 | 'validate_callback' => 'rest_validate_request_arg', |
| 358 | 358 | 'items' => array( |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | ); |
| 362 | 362 | |
| 363 | 363 | $params['ip_address_excludes'] = array( |
| 364 | - 'description' => __( 'Limit response to objects that don\'t have a specified ip address.', 'woocommerce' ), |
|
| 364 | + 'description' => __('Limit response to objects that don\'t have a specified ip address.', 'woocommerce'), |
|
| 365 | 365 | 'type' => 'array', |
| 366 | 366 | 'validate_callback' => 'rest_validate_request_arg', |
| 367 | 367 | 'items' => array( |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param array $request Request array. |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - protected function prepare_reports_query( $request ) { |
|
| 34 | + protected function prepare_reports_query($request) { |
|
| 35 | 35 | $args = array(); |
| 36 | 36 | $args['before'] = $request['before']; |
| 37 | 37 | $args['after'] = $request['after']; |
@@ -62,44 +62,44 @@ discard block |
||
| 62 | 62 | * @param \WP_REST_Request $request Request data. |
| 63 | 63 | * @return array|\WP_Error |
| 64 | 64 | */ |
| 65 | - public function get_items( $request ) { |
|
| 66 | - $query_args = $this->prepare_reports_query( $request ); |
|
| 67 | - $orders_query = new \WC_Admin_Reports_Orders_Stats_Query( $query_args ); |
|
| 65 | + public function get_items($request) { |
|
| 66 | + $query_args = $this->prepare_reports_query($request); |
|
| 67 | + $orders_query = new \WC_Admin_Reports_Orders_Stats_Query($query_args); |
|
| 68 | 68 | try { |
| 69 | 69 | $report_data = $orders_query->get_data(); |
| 70 | - } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { |
|
| 71 | - return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
| 70 | + } catch (\WC_Admin_Reports_Parameter_Exception $e) { |
|
| 71 | + return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $out_data = array( |
| 75 | - 'totals' => get_object_vars( $report_data->totals ), |
|
| 75 | + 'totals' => get_object_vars($report_data->totals), |
|
| 76 | 76 | 'intervals' => array(), |
| 77 | 77 | ); |
| 78 | 78 | |
| 79 | - foreach ( $report_data->intervals as $interval_data ) { |
|
| 80 | - $item = $this->prepare_item_for_response( $interval_data, $request ); |
|
| 81 | - $out_data['intervals'][] = $this->prepare_response_for_collection( $item ); |
|
| 79 | + foreach ($report_data->intervals as $interval_data) { |
|
| 80 | + $item = $this->prepare_item_for_response($interval_data, $request); |
|
| 81 | + $out_data['intervals'][] = $this->prepare_response_for_collection($item); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - $response = rest_ensure_response( $out_data ); |
|
| 85 | - $response->header( 'X-WP-Total', (int) $report_data->total ); |
|
| 86 | - $response->header( 'X-WP-TotalPages', (int) $report_data->pages ); |
|
| 84 | + $response = rest_ensure_response($out_data); |
|
| 85 | + $response->header('X-WP-Total', (int) $report_data->total); |
|
| 86 | + $response->header('X-WP-TotalPages', (int) $report_data->pages); |
|
| 87 | 87 | |
| 88 | 88 | $page = $report_data->page_no; |
| 89 | 89 | $max_pages = $report_data->pages; |
| 90 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 91 | - if ( $page > 1 ) { |
|
| 90 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 91 | + if ($page > 1) { |
|
| 92 | 92 | $prev_page = $page - 1; |
| 93 | - if ( $prev_page > $max_pages ) { |
|
| 93 | + if ($prev_page > $max_pages) { |
|
| 94 | 94 | $prev_page = $max_pages; |
| 95 | 95 | } |
| 96 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 97 | - $response->link_header( 'prev', $prev_link ); |
|
| 96 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 97 | + $response->link_header('prev', $prev_link); |
|
| 98 | 98 | } |
| 99 | - if ( $max_pages > $page ) { |
|
| 99 | + if ($max_pages > $page) { |
|
| 100 | 100 | $next_page = $page + 1; |
| 101 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 102 | - $response->link_header( 'next', $next_link ); |
|
| 101 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 102 | + $response->link_header('next', $next_link); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | return $response; |
@@ -112,15 +112,15 @@ discard block |
||
| 112 | 112 | * @param \WP_REST_Request $request Request object. |
| 113 | 113 | * @return \WP_REST_Response |
| 114 | 114 | */ |
| 115 | - public function prepare_item_for_response( $report, $request ) { |
|
| 115 | + public function prepare_item_for_response($report, $request) { |
|
| 116 | 116 | $data = $report; |
| 117 | 117 | |
| 118 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 119 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 120 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 118 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 119 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 120 | + $data = $this->filter_response_by_context($data, $context); |
|
| 121 | 121 | |
| 122 | 122 | // Wrap the data in a response object. |
| 123 | - $response = rest_ensure_response( $data ); |
|
| 123 | + $response = rest_ensure_response($data); |
|
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | 126 | * Filter a report returned from the API. |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * @param object $report The original report object. |
| 132 | 132 | * @param \WP_REST_Request $request Request used to generate the response. |
| 133 | 133 | */ |
| 134 | - return apply_filters( 'woocommerce_rest_prepare_report_orders_stats', $response, $report, $request ); |
|
| 134 | + return apply_filters('woocommerce_rest_prepare_report_orders_stats', $response, $report, $request); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -142,90 +142,90 @@ discard block |
||
| 142 | 142 | public function get_item_schema() { |
| 143 | 143 | $data_values = array( |
| 144 | 144 | 'net_revenue' => array( |
| 145 | - 'description' => __( 'Net revenue.', 'woocommerce' ), |
|
| 145 | + 'description' => __('Net revenue.', 'woocommerce'), |
|
| 146 | 146 | 'type' => 'number', |
| 147 | - 'context' => array( 'view', 'edit' ), |
|
| 147 | + 'context' => array('view', 'edit'), |
|
| 148 | 148 | 'readonly' => true, |
| 149 | 149 | 'format' => 'currency', |
| 150 | 150 | ), |
| 151 | 151 | 'orders_count' => array( |
| 152 | - 'description' => __( 'Amount of orders', 'woocommerce' ), |
|
| 152 | + 'description' => __('Amount of orders', 'woocommerce'), |
|
| 153 | 153 | 'type' => 'integer', |
| 154 | - 'context' => array( 'view', 'edit' ), |
|
| 154 | + 'context' => array('view', 'edit'), |
|
| 155 | 155 | 'readonly' => true, |
| 156 | 156 | 'indicator' => true, |
| 157 | 157 | ), |
| 158 | 158 | 'avg_order_value' => array( |
| 159 | - 'description' => __( 'Average order value.', 'woocommerce' ), |
|
| 159 | + 'description' => __('Average order value.', 'woocommerce'), |
|
| 160 | 160 | 'type' => 'number', |
| 161 | - 'context' => array( 'view', 'edit' ), |
|
| 161 | + 'context' => array('view', 'edit'), |
|
| 162 | 162 | 'readonly' => true, |
| 163 | 163 | 'indicator' => true, |
| 164 | 164 | 'format' => 'currency', |
| 165 | 165 | ), |
| 166 | 166 | 'avg_items_per_order' => array( |
| 167 | - 'description' => __( 'Average items per order', 'woocommerce' ), |
|
| 167 | + 'description' => __('Average items per order', 'woocommerce'), |
|
| 168 | 168 | 'type' => 'number', |
| 169 | - 'context' => array( 'view', 'edit' ), |
|
| 169 | + 'context' => array('view', 'edit'), |
|
| 170 | 170 | 'readonly' => true, |
| 171 | 171 | ), |
| 172 | 172 | 'num_items_sold' => array( |
| 173 | - 'description' => __( 'Number of items sold', 'woocommerce' ), |
|
| 173 | + 'description' => __('Number of items sold', 'woocommerce'), |
|
| 174 | 174 | 'type' => 'integer', |
| 175 | - 'context' => array( 'view', 'edit' ), |
|
| 175 | + 'context' => array('view', 'edit'), |
|
| 176 | 176 | 'readonly' => true, |
| 177 | 177 | ), |
| 178 | 178 | 'coupons' => array( |
| 179 | - 'description' => __( 'Amount discounted by coupons.', 'woocommerce' ), |
|
| 179 | + 'description' => __('Amount discounted by coupons.', 'woocommerce'), |
|
| 180 | 180 | 'type' => 'number', |
| 181 | - 'context' => array( 'view', 'edit' ), |
|
| 181 | + 'context' => array('view', 'edit'), |
|
| 182 | 182 | 'readonly' => true, |
| 183 | 183 | ), |
| 184 | 184 | 'coupons_count' => array( |
| 185 | - 'description' => __( 'Unique coupons count.', 'woocommerce' ), |
|
| 185 | + 'description' => __('Unique coupons count.', 'woocommerce'), |
|
| 186 | 186 | 'type' => 'number', |
| 187 | - 'context' => array( 'view', 'edit' ), |
|
| 187 | + 'context' => array('view', 'edit'), |
|
| 188 | 188 | 'readonly' => true, |
| 189 | 189 | ), |
| 190 | 190 | 'num_returning_customers' => array( |
| 191 | - 'description' => __( 'Number of orders done by returning customers', 'woocommerce' ), |
|
| 191 | + 'description' => __('Number of orders done by returning customers', 'woocommerce'), |
|
| 192 | 192 | 'type' => 'integer', |
| 193 | - 'context' => array( 'view', 'edit' ), |
|
| 193 | + 'context' => array('view', 'edit'), |
|
| 194 | 194 | 'readonly' => true, |
| 195 | 195 | ), |
| 196 | 196 | 'num_new_customers' => array( |
| 197 | - 'description' => __( 'Number of orders done by new customers', 'woocommerce' ), |
|
| 197 | + 'description' => __('Number of orders done by new customers', 'woocommerce'), |
|
| 198 | 198 | 'type' => 'integer', |
| 199 | - 'context' => array( 'view', 'edit' ), |
|
| 199 | + 'context' => array('view', 'edit'), |
|
| 200 | 200 | 'readonly' => true, |
| 201 | 201 | ), |
| 202 | 202 | 'products' => array( |
| 203 | - 'description' => __( 'Number of distinct products sold.', 'woocommerce' ), |
|
| 203 | + 'description' => __('Number of distinct products sold.', 'woocommerce'), |
|
| 204 | 204 | 'type' => 'number', |
| 205 | - 'context' => array( 'view', 'edit' ), |
|
| 205 | + 'context' => array('view', 'edit'), |
|
| 206 | 206 | 'readonly' => true, |
| 207 | 207 | ), |
| 208 | 208 | ); |
| 209 | 209 | |
| 210 | 210 | $segments = array( |
| 211 | 211 | 'segments' => array( |
| 212 | - 'description' => __( 'Reports data grouped by segment condition.', 'woocommerce' ), |
|
| 212 | + 'description' => __('Reports data grouped by segment condition.', 'woocommerce'), |
|
| 213 | 213 | 'type' => 'array', |
| 214 | - 'context' => array( 'view', 'edit' ), |
|
| 214 | + 'context' => array('view', 'edit'), |
|
| 215 | 215 | 'readonly' => true, |
| 216 | 216 | 'items' => array( |
| 217 | 217 | 'type' => 'object', |
| 218 | 218 | 'properties' => array( |
| 219 | 219 | 'segment_id' => array( |
| 220 | - 'description' => __( 'Segment identificator.', 'woocommerce' ), |
|
| 220 | + 'description' => __('Segment identificator.', 'woocommerce'), |
|
| 221 | 221 | 'type' => 'integer', |
| 222 | - 'context' => array( 'view', 'edit' ), |
|
| 222 | + 'context' => array('view', 'edit'), |
|
| 223 | 223 | 'readonly' => true, |
| 224 | 224 | ), |
| 225 | 225 | 'subtotals' => array( |
| 226 | - 'description' => __( 'Interval subtotals.', 'woocommerce' ), |
|
| 226 | + 'description' => __('Interval subtotals.', 'woocommerce'), |
|
| 227 | 227 | 'type' => 'object', |
| 228 | - 'context' => array( 'view', 'edit' ), |
|
| 228 | + 'context' => array('view', 'edit'), |
|
| 229 | 229 | 'readonly' => true, |
| 230 | 230 | 'properties' => $data_values, |
| 231 | 231 | ), |
@@ -234,12 +234,12 @@ discard block |
||
| 234 | 234 | ), |
| 235 | 235 | ); |
| 236 | 236 | |
| 237 | - $totals = array_merge( $data_values, $segments ); |
|
| 237 | + $totals = array_merge($data_values, $segments); |
|
| 238 | 238 | |
| 239 | 239 | // Products is not shown in intervals. |
| 240 | - unset( $data_values['products'] ); |
|
| 240 | + unset($data_values['products']); |
|
| 241 | 241 | |
| 242 | - $intervals = array_merge( $data_values, $segments ); |
|
| 242 | + $intervals = array_merge($data_values, $segments); |
|
| 243 | 243 | |
| 244 | 244 | $schema = array( |
| 245 | 245 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
@@ -247,55 +247,55 @@ discard block |
||
| 247 | 247 | 'type' => 'object', |
| 248 | 248 | 'properties' => array( |
| 249 | 249 | 'totals' => array( |
| 250 | - 'description' => __( 'Totals data.', 'woocommerce' ), |
|
| 250 | + 'description' => __('Totals data.', 'woocommerce'), |
|
| 251 | 251 | 'type' => 'object', |
| 252 | - 'context' => array( 'view', 'edit' ), |
|
| 252 | + 'context' => array('view', 'edit'), |
|
| 253 | 253 | 'readonly' => true, |
| 254 | 254 | 'properties' => $totals, |
| 255 | 255 | ), |
| 256 | 256 | 'intervals' => array( |
| 257 | - 'description' => __( 'Reports data grouped by intervals.', 'woocommerce' ), |
|
| 257 | + 'description' => __('Reports data grouped by intervals.', 'woocommerce'), |
|
| 258 | 258 | 'type' => 'array', |
| 259 | - 'context' => array( 'view', 'edit' ), |
|
| 259 | + 'context' => array('view', 'edit'), |
|
| 260 | 260 | 'readonly' => true, |
| 261 | 261 | 'items' => array( |
| 262 | 262 | 'type' => 'object', |
| 263 | 263 | 'properties' => array( |
| 264 | 264 | 'interval' => array( |
| 265 | - 'description' => __( 'Type of interval.', 'woocommerce' ), |
|
| 265 | + 'description' => __('Type of interval.', 'woocommerce'), |
|
| 266 | 266 | 'type' => 'string', |
| 267 | - 'context' => array( 'view', 'edit' ), |
|
| 267 | + 'context' => array('view', 'edit'), |
|
| 268 | 268 | 'readonly' => true, |
| 269 | - 'enum' => array( 'day', 'week', 'month', 'year' ), |
|
| 269 | + 'enum' => array('day', 'week', 'month', 'year'), |
|
| 270 | 270 | ), |
| 271 | 271 | 'date_start' => array( |
| 272 | - 'description' => __( "The date the report start, in the site's timezone.", 'woocommerce' ), |
|
| 272 | + 'description' => __("The date the report start, in the site's timezone.", 'woocommerce'), |
|
| 273 | 273 | 'type' => 'date-time', |
| 274 | - 'context' => array( 'view', 'edit' ), |
|
| 274 | + 'context' => array('view', 'edit'), |
|
| 275 | 275 | 'readonly' => true, |
| 276 | 276 | ), |
| 277 | 277 | 'date_start_gmt' => array( |
| 278 | - 'description' => __( 'The date the report start, as GMT.', 'woocommerce' ), |
|
| 278 | + 'description' => __('The date the report start, as GMT.', 'woocommerce'), |
|
| 279 | 279 | 'type' => 'date-time', |
| 280 | - 'context' => array( 'view', 'edit' ), |
|
| 280 | + 'context' => array('view', 'edit'), |
|
| 281 | 281 | 'readonly' => true, |
| 282 | 282 | ), |
| 283 | 283 | 'date_end' => array( |
| 284 | - 'description' => __( "The date the report end, in the site's timezone.", 'woocommerce' ), |
|
| 284 | + 'description' => __("The date the report end, in the site's timezone.", 'woocommerce'), |
|
| 285 | 285 | 'type' => 'date-time', |
| 286 | - 'context' => array( 'view', 'edit' ), |
|
| 286 | + 'context' => array('view', 'edit'), |
|
| 287 | 287 | 'readonly' => true, |
| 288 | 288 | ), |
| 289 | 289 | 'date_end_gmt' => array( |
| 290 | - 'description' => __( 'The date the report end, as GMT.', 'woocommerce' ), |
|
| 290 | + 'description' => __('The date the report end, as GMT.', 'woocommerce'), |
|
| 291 | 291 | 'type' => 'date-time', |
| 292 | - 'context' => array( 'view', 'edit' ), |
|
| 292 | + 'context' => array('view', 'edit'), |
|
| 293 | 293 | 'readonly' => true, |
| 294 | 294 | ), |
| 295 | 295 | 'subtotals' => array( |
| 296 | - 'description' => __( 'Interval subtotals.', 'woocommerce' ), |
|
| 296 | + 'description' => __('Interval subtotals.', 'woocommerce'), |
|
| 297 | 297 | 'type' => 'object', |
| 298 | - 'context' => array( 'view', 'edit' ), |
|
| 298 | + 'context' => array('view', 'edit'), |
|
| 299 | 299 | 'readonly' => true, |
| 300 | 300 | 'properties' => $intervals, |
| 301 | 301 | ), |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | ), |
| 306 | 306 | ); |
| 307 | 307 | |
| 308 | - return $this->add_additional_fields_schema( $schema ); |
|
| 308 | + return $this->add_additional_fields_schema($schema); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -315,17 +315,17 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | public function get_collection_params() { |
| 317 | 317 | $params = array(); |
| 318 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 318 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 319 | 319 | $params['page'] = array( |
| 320 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 320 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 321 | 321 | 'type' => 'integer', |
| 322 | 322 | 'default' => 1, |
| 323 | 323 | 'sanitize_callback' => 'absint', |
| 324 | 324 | 'validate_callback' => 'rest_validate_request_arg', |
| 325 | 325 | 'minimum' => 1, |
| 326 | 326 | ); |
| 327 | - $params['per_page'] = array( |
|
| 328 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 327 | + $params['per_page'] = array( |
|
| 328 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 329 | 329 | 'type' => 'integer', |
| 330 | 330 | 'default' => 10, |
| 331 | 331 | 'minimum' => 1, |
@@ -333,27 +333,27 @@ discard block |
||
| 333 | 333 | 'sanitize_callback' => 'absint', |
| 334 | 334 | 'validate_callback' => 'rest_validate_request_arg', |
| 335 | 335 | ); |
| 336 | - $params['after'] = array( |
|
| 337 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 336 | + $params['after'] = array( |
|
| 337 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 338 | 338 | 'type' => 'string', |
| 339 | 339 | 'format' => 'date-time', |
| 340 | 340 | 'validate_callback' => 'rest_validate_request_arg', |
| 341 | 341 | ); |
| 342 | - $params['before'] = array( |
|
| 343 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 342 | + $params['before'] = array( |
|
| 343 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 344 | 344 | 'type' => 'string', |
| 345 | 345 | 'format' => 'date-time', |
| 346 | 346 | 'validate_callback' => 'rest_validate_request_arg', |
| 347 | 347 | ); |
| 348 | - $params['order'] = array( |
|
| 349 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 348 | + $params['order'] = array( |
|
| 349 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 350 | 350 | 'type' => 'string', |
| 351 | 351 | 'default' => 'desc', |
| 352 | - 'enum' => array( 'asc', 'desc' ), |
|
| 352 | + 'enum' => array('asc', 'desc'), |
|
| 353 | 353 | 'validate_callback' => 'rest_validate_request_arg', |
| 354 | 354 | ); |
| 355 | - $params['orderby'] = array( |
|
| 356 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 355 | + $params['orderby'] = array( |
|
| 356 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 357 | 357 | 'type' => 'string', |
| 358 | 358 | 'default' => 'date', |
| 359 | 359 | 'enum' => array( |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | ), |
| 365 | 365 | 'validate_callback' => 'rest_validate_request_arg', |
| 366 | 366 | ); |
| 367 | - $params['interval'] = array( |
|
| 368 | - 'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ), |
|
| 367 | + $params['interval'] = array( |
|
| 368 | + 'description' => __('Time interval to use for buckets in the returned data.', 'woocommerce'), |
|
| 369 | 369 | 'type' => 'string', |
| 370 | 370 | 'default' => 'week', |
| 371 | 371 | 'enum' => array( |
@@ -378,8 +378,8 @@ discard block |
||
| 378 | 378 | ), |
| 379 | 379 | 'validate_callback' => 'rest_validate_request_arg', |
| 380 | 380 | ); |
| 381 | - $params['match'] = array( |
|
| 382 | - 'description' => __( 'Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce' ), |
|
| 381 | + $params['match'] = array( |
|
| 382 | + 'description' => __('Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce'), |
|
| 383 | 383 | 'type' => 'string', |
| 384 | 384 | 'default' => 'all', |
| 385 | 385 | 'enum' => array( |
@@ -388,8 +388,8 @@ discard block |
||
| 388 | 388 | ), |
| 389 | 389 | 'validate_callback' => 'rest_validate_request_arg', |
| 390 | 390 | ); |
| 391 | - $params['status_is'] = array( |
|
| 392 | - 'description' => __( 'Limit result set to items that have the specified order status.', 'woocommerce' ), |
|
| 391 | + $params['status_is'] = array( |
|
| 392 | + 'description' => __('Limit result set to items that have the specified order status.', 'woocommerce'), |
|
| 393 | 393 | 'type' => 'array', |
| 394 | 394 | 'sanitize_callback' => 'wp_parse_slug_list', |
| 395 | 395 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -399,8 +399,8 @@ discard block |
||
| 399 | 399 | 'type' => 'string', |
| 400 | 400 | ), |
| 401 | 401 | ); |
| 402 | - $params['status_is_not'] = array( |
|
| 403 | - 'description' => __( 'Limit result set to items that don\'t have the specified order status.', 'woocommerce' ), |
|
| 402 | + $params['status_is_not'] = array( |
|
| 403 | + 'description' => __('Limit result set to items that don\'t have the specified order status.', 'woocommerce'), |
|
| 404 | 404 | 'type' => 'array', |
| 405 | 405 | 'sanitize_callback' => 'wp_parse_slug_list', |
| 406 | 406 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | ), |
| 411 | 411 | ); |
| 412 | 412 | $params['product_includes'] = array( |
| 413 | - 'description' => __( 'Limit result set to items that have the specified product(s) assigned.', 'woocommerce' ), |
|
| 413 | + 'description' => __('Limit result set to items that have the specified product(s) assigned.', 'woocommerce'), |
|
| 414 | 414 | 'type' => 'array', |
| 415 | 415 | 'items' => array( |
| 416 | 416 | 'type' => 'integer', |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | |
| 421 | 421 | ); |
| 422 | 422 | $params['product_excludes'] = array( |
| 423 | - 'description' => __( 'Limit result set to items that don\'t have the specified product(s) assigned.', 'woocommerce' ), |
|
| 423 | + 'description' => __('Limit result set to items that don\'t have the specified product(s) assigned.', 'woocommerce'), |
|
| 424 | 424 | 'type' => 'array', |
| 425 | 425 | 'items' => array( |
| 426 | 426 | 'type' => 'integer', |
@@ -428,8 +428,8 @@ discard block |
||
| 428 | 428 | 'default' => array(), |
| 429 | 429 | 'sanitize_callback' => 'wp_parse_id_list', |
| 430 | 430 | ); |
| 431 | - $params['coupon_includes'] = array( |
|
| 432 | - 'description' => __( 'Limit result set to items that have the specified coupon(s) assigned.', 'woocommerce' ), |
|
| 431 | + $params['coupon_includes'] = array( |
|
| 432 | + 'description' => __('Limit result set to items that have the specified coupon(s) assigned.', 'woocommerce'), |
|
| 433 | 433 | 'type' => 'array', |
| 434 | 434 | 'items' => array( |
| 435 | 435 | 'type' => 'integer', |
@@ -437,8 +437,8 @@ discard block |
||
| 437 | 437 | 'default' => array(), |
| 438 | 438 | 'sanitize_callback' => 'wp_parse_id_list', |
| 439 | 439 | ); |
| 440 | - $params['coupon_excludes'] = array( |
|
| 441 | - 'description' => __( 'Limit result set to items that don\'t have the specified coupon(s) assigned.', 'woocommerce' ), |
|
| 440 | + $params['coupon_excludes'] = array( |
|
| 441 | + 'description' => __('Limit result set to items that don\'t have the specified coupon(s) assigned.', 'woocommerce'), |
|
| 442 | 442 | 'type' => 'array', |
| 443 | 443 | 'items' => array( |
| 444 | 444 | 'type' => 'integer', |
@@ -446,8 +446,8 @@ discard block |
||
| 446 | 446 | 'default' => array(), |
| 447 | 447 | 'sanitize_callback' => 'wp_parse_id_list', |
| 448 | 448 | ); |
| 449 | - $params['customer'] = array( |
|
| 450 | - 'description' => __( 'Limit result set to items that don\'t have the specified coupon(s) assigned.', 'woocommerce' ), |
|
| 449 | + $params['customer'] = array( |
|
| 450 | + 'description' => __('Limit result set to items that don\'t have the specified coupon(s) assigned.', 'woocommerce'), |
|
| 451 | 451 | 'type' => 'string', |
| 452 | 452 | 'enum' => array( |
| 453 | 453 | 'new', |
@@ -455,8 +455,8 @@ discard block |
||
| 455 | 455 | ), |
| 456 | 456 | 'validate_callback' => 'rest_validate_request_arg', |
| 457 | 457 | ); |
| 458 | - $params['refunds'] = array( |
|
| 459 | - 'description' => __( 'Limit result set to specific types of refunds.', 'woocommerce' ), |
|
| 458 | + $params['refunds'] = array( |
|
| 459 | + 'description' => __('Limit result set to specific types of refunds.', 'woocommerce'), |
|
| 460 | 460 | 'type' => 'string', |
| 461 | 461 | 'default' => '', |
| 462 | 462 | 'enum' => array( |
@@ -468,8 +468,8 @@ discard block |
||
| 468 | 468 | ), |
| 469 | 469 | 'validate_callback' => 'rest_validate_request_arg', |
| 470 | 470 | ); |
| 471 | - $params['segmentby'] = array( |
|
| 472 | - 'description' => __( 'Segment the response by additional constraint.', 'woocommerce' ), |
|
| 471 | + $params['segmentby'] = array( |
|
| 472 | + 'description' => __('Segment the response by additional constraint.', 'woocommerce'), |
|
| 473 | 473 | 'type' => 'string', |
| 474 | 474 | 'enum' => array( |
| 475 | 475 | 'product', |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Reports; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; |
| 15 | 15 | |
@@ -41,48 +41,48 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return array|\WP_Error |
| 43 | 43 | */ |
| 44 | - public function get_items( $request ) { |
|
| 44 | + public function get_items($request) { |
|
| 45 | 45 | $args = array(); |
| 46 | - $registered = array_keys( $this->get_collection_params() ); |
|
| 47 | - foreach ( $registered as $param_name ) { |
|
| 48 | - if ( isset( $request[ $param_name ] ) ) { |
|
| 49 | - if ( isset( $this->param_mapping[ $param_name ] ) ) { |
|
| 50 | - $args[ $this->param_mapping[ $param_name ] ] = $request[ $param_name ]; |
|
| 46 | + $registered = array_keys($this->get_collection_params()); |
|
| 47 | + foreach ($registered as $param_name) { |
|
| 48 | + if (isset($request[$param_name])) { |
|
| 49 | + if (isset($this->param_mapping[$param_name])) { |
|
| 50 | + $args[$this->param_mapping[$param_name]] = $request[$param_name]; |
|
| 51 | 51 | } else { |
| 52 | - $args[ $param_name ] = $request[ $param_name ]; |
|
| 52 | + $args[$param_name] = $request[$param_name]; |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $reports = new \WC_Admin_Reports_Variations_Query( $args ); |
|
| 57 | + $reports = new \WC_Admin_Reports_Variations_Query($args); |
|
| 58 | 58 | $products_data = $reports->get_data(); |
| 59 | 59 | |
| 60 | 60 | $data = array(); |
| 61 | 61 | |
| 62 | - foreach ( $products_data->data as $product_data ) { |
|
| 63 | - $item = $this->prepare_item_for_response( $product_data, $request ); |
|
| 64 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 62 | + foreach ($products_data->data as $product_data) { |
|
| 63 | + $item = $this->prepare_item_for_response($product_data, $request); |
|
| 64 | + $data[] = $this->prepare_response_for_collection($item); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - $response = rest_ensure_response( $data ); |
|
| 68 | - $response->header( 'X-WP-Total', (int) $products_data->total ); |
|
| 69 | - $response->header( 'X-WP-TotalPages', (int) $products_data->pages ); |
|
| 67 | + $response = rest_ensure_response($data); |
|
| 68 | + $response->header('X-WP-Total', (int) $products_data->total); |
|
| 69 | + $response->header('X-WP-TotalPages', (int) $products_data->pages); |
|
| 70 | 70 | |
| 71 | 71 | $page = $products_data->page_no; |
| 72 | 72 | $max_pages = $products_data->pages; |
| 73 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 74 | - if ( $page > 1 ) { |
|
| 73 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 74 | + if ($page > 1) { |
|
| 75 | 75 | $prev_page = $page - 1; |
| 76 | - if ( $prev_page > $max_pages ) { |
|
| 76 | + if ($prev_page > $max_pages) { |
|
| 77 | 77 | $prev_page = $max_pages; |
| 78 | 78 | } |
| 79 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 80 | - $response->link_header( 'prev', $prev_link ); |
|
| 79 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 80 | + $response->link_header('prev', $prev_link); |
|
| 81 | 81 | } |
| 82 | - if ( $max_pages > $page ) { |
|
| 82 | + if ($max_pages > $page) { |
|
| 83 | 83 | $next_page = $page + 1; |
| 84 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 85 | - $response->link_header( 'next', $next_link ); |
|
| 84 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 85 | + $response->link_header('next', $next_link); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | return $response; |
@@ -95,16 +95,16 @@ discard block |
||
| 95 | 95 | * @param \WP_REST_Request $request Request object. |
| 96 | 96 | * @return \WP_REST_Response |
| 97 | 97 | */ |
| 98 | - public function prepare_item_for_response( $report, $request ) { |
|
| 98 | + public function prepare_item_for_response($report, $request) { |
|
| 99 | 99 | $data = $report; |
| 100 | 100 | |
| 101 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 102 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 103 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 101 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 102 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 103 | + $data = $this->filter_response_by_context($data, $context); |
|
| 104 | 104 | |
| 105 | 105 | // Wrap the data in a response object. |
| 106 | - $response = rest_ensure_response( $data ); |
|
| 107 | - $response->add_links( $this->prepare_links( $report ) ); |
|
| 106 | + $response = rest_ensure_response($data); |
|
| 107 | + $response->add_links($this->prepare_links($report)); |
|
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | 110 | * Filter a report returned from the API. |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @param object $report The original report object. |
| 116 | 116 | * @param \WP_REST_Request $request Request used to generate the response. |
| 117 | 117 | */ |
| 118 | - return apply_filters( 'woocommerce_rest_prepare_report_variations', $response, $report, $request ); |
|
| 118 | + return apply_filters('woocommerce_rest_prepare_report_variations', $response, $report, $request); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -124,13 +124,13 @@ discard block |
||
| 124 | 124 | * @param array $object Object data. |
| 125 | 125 | * @return array Links for the given post. |
| 126 | 126 | */ |
| 127 | - protected function prepare_links( $object ) { |
|
| 127 | + protected function prepare_links($object) { |
|
| 128 | 128 | $links = array( |
| 129 | 129 | 'product' => array( |
| 130 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, 'products', $object['product_id'] ) ), |
|
| 130 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, 'products', $object['product_id'])), |
|
| 131 | 131 | ), |
| 132 | 132 | 'variation' => array( |
| 133 | - 'href' => rest_url( sprintf( '/%s/%s/%d/%s/%d', $this->namespace, 'products', $object['product_id'], 'variation', $object['variation_id'] ) ), |
|
| 133 | + 'href' => rest_url(sprintf('/%s/%s/%d/%s/%d', $this->namespace, 'products', $object['product_id'], 'variation', $object['variation_id'])), |
|
| 134 | 134 | ), |
| 135 | 135 | ); |
| 136 | 136 | |
@@ -151,87 +151,87 @@ discard block |
||
| 151 | 151 | 'product_id' => array( |
| 152 | 152 | 'type' => 'integer', |
| 153 | 153 | 'readonly' => true, |
| 154 | - 'context' => array( 'view', 'edit' ), |
|
| 155 | - 'description' => __( 'Product ID.', 'woocommerce' ), |
|
| 154 | + 'context' => array('view', 'edit'), |
|
| 155 | + 'description' => __('Product ID.', 'woocommerce'), |
|
| 156 | 156 | ), |
| 157 | 157 | 'variation_id' => array( |
| 158 | 158 | 'type' => 'integer', |
| 159 | 159 | 'readonly' => true, |
| 160 | - 'context' => array( 'view', 'edit' ), |
|
| 161 | - 'description' => __( 'Product ID.', 'woocommerce' ), |
|
| 160 | + 'context' => array('view', 'edit'), |
|
| 161 | + 'description' => __('Product ID.', 'woocommerce'), |
|
| 162 | 162 | ), |
| 163 | 163 | 'items_sold' => array( |
| 164 | 164 | 'type' => 'integer', |
| 165 | 165 | 'readonly' => true, |
| 166 | - 'context' => array( 'view', 'edit' ), |
|
| 167 | - 'description' => __( 'Number of items sold.', 'woocommerce' ), |
|
| 166 | + 'context' => array('view', 'edit'), |
|
| 167 | + 'description' => __('Number of items sold.', 'woocommerce'), |
|
| 168 | 168 | ), |
| 169 | 169 | 'net_revenue' => array( |
| 170 | 170 | 'type' => 'number', |
| 171 | 171 | 'readonly' => true, |
| 172 | - 'context' => array( 'view', 'edit' ), |
|
| 173 | - 'description' => __( 'Total net revenue of all items sold.', 'woocommerce' ), |
|
| 172 | + 'context' => array('view', 'edit'), |
|
| 173 | + 'description' => __('Total net revenue of all items sold.', 'woocommerce'), |
|
| 174 | 174 | ), |
| 175 | 175 | 'orders_count' => array( |
| 176 | 176 | 'type' => 'integer', |
| 177 | 177 | 'readonly' => true, |
| 178 | - 'context' => array( 'view', 'edit' ), |
|
| 179 | - 'description' => __( 'Number of orders product appeared in.', 'woocommerce' ), |
|
| 178 | + 'context' => array('view', 'edit'), |
|
| 179 | + 'description' => __('Number of orders product appeared in.', 'woocommerce'), |
|
| 180 | 180 | ), |
| 181 | 181 | 'extended_info' => array( |
| 182 | 182 | 'name' => array( |
| 183 | 183 | 'type' => 'string', |
| 184 | 184 | 'readonly' => true, |
| 185 | - 'context' => array( 'view', 'edit' ), |
|
| 186 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
| 185 | + 'context' => array('view', 'edit'), |
|
| 186 | + 'description' => __('Product name.', 'woocommerce'), |
|
| 187 | 187 | ), |
| 188 | 188 | 'price' => array( |
| 189 | 189 | 'type' => 'number', |
| 190 | 190 | 'readonly' => true, |
| 191 | - 'context' => array( 'view', 'edit' ), |
|
| 192 | - 'description' => __( 'Product price.', 'woocommerce' ), |
|
| 191 | + 'context' => array('view', 'edit'), |
|
| 192 | + 'description' => __('Product price.', 'woocommerce'), |
|
| 193 | 193 | ), |
| 194 | 194 | 'image' => array( |
| 195 | 195 | 'type' => 'string', |
| 196 | 196 | 'readonly' => true, |
| 197 | - 'context' => array( 'view', 'edit' ), |
|
| 198 | - 'description' => __( 'Product image.', 'woocommerce' ), |
|
| 197 | + 'context' => array('view', 'edit'), |
|
| 198 | + 'description' => __('Product image.', 'woocommerce'), |
|
| 199 | 199 | ), |
| 200 | 200 | 'permalink' => array( |
| 201 | 201 | 'type' => 'string', |
| 202 | 202 | 'readonly' => true, |
| 203 | - 'context' => array( 'view', 'edit' ), |
|
| 204 | - 'description' => __( 'Product link.', 'woocommerce' ), |
|
| 203 | + 'context' => array('view', 'edit'), |
|
| 204 | + 'description' => __('Product link.', 'woocommerce'), |
|
| 205 | 205 | ), |
| 206 | 206 | 'attributes' => array( |
| 207 | 207 | 'type' => 'array', |
| 208 | 208 | 'readonly' => true, |
| 209 | - 'context' => array( 'view', 'edit' ), |
|
| 210 | - 'description' => __( 'Product attributes.', 'woocommerce' ), |
|
| 209 | + 'context' => array('view', 'edit'), |
|
| 210 | + 'description' => __('Product attributes.', 'woocommerce'), |
|
| 211 | 211 | ), |
| 212 | 212 | 'stock_status' => array( |
| 213 | 213 | 'type' => 'string', |
| 214 | 214 | 'readonly' => true, |
| 215 | - 'context' => array( 'view', 'edit' ), |
|
| 216 | - 'description' => __( 'Product inventory status.', 'woocommerce' ), |
|
| 215 | + 'context' => array('view', 'edit'), |
|
| 216 | + 'description' => __('Product inventory status.', 'woocommerce'), |
|
| 217 | 217 | ), |
| 218 | 218 | 'stock_quantity' => array( |
| 219 | 219 | 'type' => 'integer', |
| 220 | 220 | 'readonly' => true, |
| 221 | - 'context' => array( 'view', 'edit' ), |
|
| 222 | - 'description' => __( 'Product inventory quantity.', 'woocommerce' ), |
|
| 221 | + 'context' => array('view', 'edit'), |
|
| 222 | + 'description' => __('Product inventory quantity.', 'woocommerce'), |
|
| 223 | 223 | ), |
| 224 | 224 | 'low_stock_amount' => array( |
| 225 | 225 | 'type' => 'integer', |
| 226 | 226 | 'readonly' => true, |
| 227 | - 'context' => array( 'view', 'edit' ), |
|
| 228 | - 'description' => __( 'Product inventory threshold for low stock.', 'woocommerce' ), |
|
| 227 | + 'context' => array('view', 'edit'), |
|
| 228 | + 'description' => __('Product inventory threshold for low stock.', 'woocommerce'), |
|
| 229 | 229 | ), |
| 230 | 230 | ), |
| 231 | 231 | ), |
| 232 | 232 | ); |
| 233 | 233 | |
| 234 | - return $this->add_additional_fields_schema( $schema ); |
|
| 234 | + return $this->add_additional_fields_schema($schema); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -241,17 +241,17 @@ discard block |
||
| 241 | 241 | */ |
| 242 | 242 | public function get_collection_params() { |
| 243 | 243 | $params = array(); |
| 244 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 244 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 245 | 245 | $params['page'] = array( |
| 246 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 246 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 247 | 247 | 'type' => 'integer', |
| 248 | 248 | 'default' => 1, |
| 249 | 249 | 'sanitize_callback' => 'absint', |
| 250 | 250 | 'validate_callback' => 'rest_validate_request_arg', |
| 251 | 251 | 'minimum' => 1, |
| 252 | 252 | ); |
| 253 | - $params['per_page'] = array( |
|
| 254 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 253 | + $params['per_page'] = array( |
|
| 254 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 255 | 255 | 'type' => 'integer', |
| 256 | 256 | 'default' => 10, |
| 257 | 257 | 'minimum' => 1, |
@@ -259,27 +259,27 @@ discard block |
||
| 259 | 259 | 'sanitize_callback' => 'absint', |
| 260 | 260 | 'validate_callback' => 'rest_validate_request_arg', |
| 261 | 261 | ); |
| 262 | - $params['after'] = array( |
|
| 263 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 262 | + $params['after'] = array( |
|
| 263 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 264 | 264 | 'type' => 'string', |
| 265 | 265 | 'format' => 'date-time', |
| 266 | 266 | 'validate_callback' => 'rest_validate_request_arg', |
| 267 | 267 | ); |
| 268 | - $params['before'] = array( |
|
| 269 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 268 | + $params['before'] = array( |
|
| 269 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 270 | 270 | 'type' => 'string', |
| 271 | 271 | 'format' => 'date-time', |
| 272 | 272 | 'validate_callback' => 'rest_validate_request_arg', |
| 273 | 273 | ); |
| 274 | - $params['order'] = array( |
|
| 275 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 274 | + $params['order'] = array( |
|
| 275 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 276 | 276 | 'type' => 'string', |
| 277 | 277 | 'default' => 'desc', |
| 278 | - 'enum' => array( 'asc', 'desc' ), |
|
| 278 | + 'enum' => array('asc', 'desc'), |
|
| 279 | 279 | 'validate_callback' => 'rest_validate_request_arg', |
| 280 | 280 | ); |
| 281 | - $params['orderby'] = array( |
|
| 282 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 281 | + $params['orderby'] = array( |
|
| 282 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 283 | 283 | 'type' => 'string', |
| 284 | 284 | 'default' => 'date', |
| 285 | 285 | 'enum' => array( |
@@ -291,8 +291,8 @@ discard block |
||
| 291 | 291 | ), |
| 292 | 292 | 'validate_callback' => 'rest_validate_request_arg', |
| 293 | 293 | ); |
| 294 | - $params['products'] = array( |
|
| 295 | - 'description' => __( 'Limit result to items with specified product ids.', 'woocommerce' ), |
|
| 294 | + $params['products'] = array( |
|
| 295 | + 'description' => __('Limit result to items with specified product ids.', 'woocommerce'), |
|
| 296 | 296 | 'type' => 'array', |
| 297 | 297 | 'sanitize_callback' => 'wp_parse_id_list', |
| 298 | 298 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -300,8 +300,8 @@ discard block |
||
| 300 | 300 | 'type' => 'integer', |
| 301 | 301 | ), |
| 302 | 302 | ); |
| 303 | - $params['variations'] = array( |
|
| 304 | - 'description' => __( 'Limit result to items with specified variation ids.', 'woocommerce' ), |
|
| 303 | + $params['variations'] = array( |
|
| 304 | + 'description' => __('Limit result to items with specified variation ids.', 'woocommerce'), |
|
| 305 | 305 | 'type' => 'array', |
| 306 | 306 | 'sanitize_callback' => 'wp_parse_id_list', |
| 307 | 307 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | ), |
| 311 | 311 | ); |
| 312 | 312 | $params['extended_info'] = array( |
| 313 | - 'description' => __( 'Add additional piece of info about each product to the report.', 'woocommerce' ), |
|
| 313 | + 'description' => __('Add additional piece of info about each product to the report.', 'woocommerce'), |
|
| 314 | 314 | 'type' => 'boolean', |
| 315 | 315 | 'default' => false, |
| 316 | 316 | 'sanitize_callback' => 'wc_string_to_bool', |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API Coupons controller class. |
@@ -35,10 +35,10 @@ discard block |
||
| 35 | 35 | array( |
| 36 | 36 | array( |
| 37 | 37 | 'methods' => \WP_REST_Server::READABLE, |
| 38 | - 'callback' => array( $this, 'get_items' ), |
|
| 39 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 38 | + 'callback' => array($this, 'get_items'), |
|
| 39 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 40 | 40 | ), |
| 41 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 41 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 42 | 42 | ), |
| 43 | 43 | true |
| 44 | 44 | ); |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | * @param \WP_REST_Request $request Full details about the request. |
| 51 | 51 | * @return \WP_Error|boolean |
| 52 | 52 | */ |
| 53 | - public function get_items_permissions_check( $request ) { |
|
| 54 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
| 55 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 53 | + public function get_items_permissions_check($request) { |
|
| 54 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
| 55 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | return true; |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | * @param \WP_REST_Request $request Full details about the request. |
| 65 | 65 | * @return \WP_Error|boolean |
| 66 | 66 | */ |
| 67 | - public function get_item_permissions_check( $request ) { |
|
| 68 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
| 69 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 67 | + public function get_item_permissions_check($request) { |
|
| 68 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
| 69 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | return true; |
@@ -79,33 +79,33 @@ discard block |
||
| 79 | 79 | * @param \WP_REST_Request $request Request data. |
| 80 | 80 | * @return \WP_Error\WP_REST_Response |
| 81 | 81 | */ |
| 82 | - public function get_items( $request ) { |
|
| 82 | + public function get_items($request) { |
|
| 83 | 83 | $data = array(); |
| 84 | 84 | $resources = array( |
| 85 | 85 | array( |
| 86 | 86 | 'slug' => 'continents', |
| 87 | - 'description' => __( 'List of supported continents, countries, and states.', 'woocommerce' ), |
|
| 87 | + 'description' => __('List of supported continents, countries, and states.', 'woocommerce'), |
|
| 88 | 88 | ), |
| 89 | 89 | array( |
| 90 | 90 | 'slug' => 'countries', |
| 91 | - 'description' => __( 'List of supported states in a given country.', 'woocommerce' ), |
|
| 91 | + 'description' => __('List of supported states in a given country.', 'woocommerce'), |
|
| 92 | 92 | ), |
| 93 | 93 | array( |
| 94 | 94 | 'slug' => 'currencies', |
| 95 | - 'description' => __( 'List of supported currencies.', 'woocommerce' ), |
|
| 95 | + 'description' => __('List of supported currencies.', 'woocommerce'), |
|
| 96 | 96 | ), |
| 97 | 97 | array( |
| 98 | 98 | 'slug' => 'download-ips', |
| 99 | - 'description' => __( 'An endpoint used for searching download logs for a specific IP address.', 'woocommerce' ), |
|
| 99 | + 'description' => __('An endpoint used for searching download logs for a specific IP address.', 'woocommerce'), |
|
| 100 | 100 | ), |
| 101 | 101 | ); |
| 102 | 102 | |
| 103 | - foreach ( $resources as $resource ) { |
|
| 104 | - $item = $this->prepare_item_for_response( (object) $resource, $request ); |
|
| 105 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 103 | + foreach ($resources as $resource) { |
|
| 104 | + $item = $this->prepare_item_for_response((object) $resource, $request); |
|
| 105 | + $data[] = $this->prepare_response_for_collection($item); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - return rest_ensure_response( $data ); |
|
| 108 | + return rest_ensure_response($data); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -115,18 +115,18 @@ discard block |
||
| 115 | 115 | * @param \WP_REST_Request $request Request object. |
| 116 | 116 | * @return \WP_REST_Response $response Response data. |
| 117 | 117 | */ |
| 118 | - public function prepare_item_for_response( $resource, $request ) { |
|
| 118 | + public function prepare_item_for_response($resource, $request) { |
|
| 119 | 119 | $data = array( |
| 120 | 120 | 'slug' => $resource->slug, |
| 121 | 121 | 'description' => $resource->description, |
| 122 | 122 | ); |
| 123 | 123 | |
| 124 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 125 | - $data = $this->filter_response_by_context( $data, 'view' ); |
|
| 124 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 125 | + $data = $this->filter_response_by_context($data, 'view'); |
|
| 126 | 126 | |
| 127 | 127 | // Wrap the data in a response object. |
| 128 | - $response = rest_ensure_response( $data ); |
|
| 129 | - $response->add_links( $this->prepare_links( $resource ) ); |
|
| 128 | + $response = rest_ensure_response($data); |
|
| 129 | + $response->add_links($this->prepare_links($resource)); |
|
| 130 | 130 | |
| 131 | 131 | return $response; |
| 132 | 132 | } |
@@ -137,13 +137,13 @@ discard block |
||
| 137 | 137 | * @param object $item Data object. |
| 138 | 138 | * @return array Links for the given country. |
| 139 | 139 | */ |
| 140 | - protected function prepare_links( $item ) { |
|
| 140 | + protected function prepare_links($item) { |
|
| 141 | 141 | $links = array( |
| 142 | 142 | 'self' => array( |
| 143 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $item->slug ) ), |
|
| 143 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $item->slug)), |
|
| 144 | 144 | ), |
| 145 | 145 | 'collection' => array( |
| 146 | - 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), |
|
| 146 | + 'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)), |
|
| 147 | 147 | ), |
| 148 | 148 | ); |
| 149 | 149 | |
@@ -163,20 +163,20 @@ discard block |
||
| 163 | 163 | 'type' => 'object', |
| 164 | 164 | 'properties' => array( |
| 165 | 165 | 'slug' => array( |
| 166 | - 'description' => __( 'Data resource ID.', 'woocommerce' ), |
|
| 166 | + 'description' => __('Data resource ID.', 'woocommerce'), |
|
| 167 | 167 | 'type' => 'string', |
| 168 | - 'context' => array( 'view' ), |
|
| 168 | + 'context' => array('view'), |
|
| 169 | 169 | 'readonly' => true, |
| 170 | 170 | ), |
| 171 | 171 | 'description' => array( |
| 172 | - 'description' => __( 'Data resource description.', 'woocommerce' ), |
|
| 172 | + 'description' => __('Data resource description.', 'woocommerce'), |
|
| 173 | 173 | 'type' => 'string', |
| 174 | - 'context' => array( 'view' ), |
|
| 174 | + 'context' => array('view'), |
|
| 175 | 175 | 'readonly' => true, |
| 176 | 176 | ), |
| 177 | 177 | ), |
| 178 | 178 | ); |
| 179 | 179 | |
| 180 | - return $this->add_additional_fields_schema( $schema ); |
|
| 180 | + return $this->add_additional_fields_schema($schema); |
|
| 181 | 181 | } |
| 182 | 182 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API Product Attribute Terms controller class. |
@@ -33,32 +33,32 @@ discard block |
||
| 33 | 33 | array( |
| 34 | 34 | 'args' => array( |
| 35 | 35 | 'attribute_id' => array( |
| 36 | - 'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ), |
|
| 36 | + 'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'), |
|
| 37 | 37 | 'type' => 'integer', |
| 38 | 38 | ), |
| 39 | 39 | ), |
| 40 | 40 | array( |
| 41 | 41 | 'methods' => \WP_REST_Server::READABLE, |
| 42 | - 'callback' => array( $this, 'get_items' ), |
|
| 43 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 42 | + 'callback' => array($this, 'get_items'), |
|
| 43 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 44 | 44 | 'args' => $this->get_collection_params(), |
| 45 | 45 | ), |
| 46 | 46 | array( |
| 47 | 47 | 'methods' => \WP_REST_Server::CREATABLE, |
| 48 | - 'callback' => array( $this, 'create_item' ), |
|
| 49 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
| 48 | + 'callback' => array($this, 'create_item'), |
|
| 49 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
| 50 | 50 | 'args' => array_merge( |
| 51 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
| 51 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
| 52 | 52 | array( |
| 53 | 53 | 'name' => array( |
| 54 | 54 | 'type' => 'string', |
| 55 | - 'description' => __( 'Name for the resource.', 'woocommerce' ), |
|
| 55 | + 'description' => __('Name for the resource.', 'woocommerce'), |
|
| 56 | 56 | 'required' => true, |
| 57 | 57 | ), |
| 58 | 58 | ) |
| 59 | 59 | ), |
| 60 | 60 | ), |
| 61 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 61 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 62 | 62 | ), |
| 63 | 63 | true |
| 64 | 64 | ); |
@@ -69,41 +69,41 @@ discard block |
||
| 69 | 69 | array( |
| 70 | 70 | 'args' => array( |
| 71 | 71 | 'id' => array( |
| 72 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 72 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 73 | 73 | 'type' => 'integer', |
| 74 | 74 | ), |
| 75 | 75 | 'attribute_id' => array( |
| 76 | - 'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ), |
|
| 76 | + 'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'), |
|
| 77 | 77 | 'type' => 'integer', |
| 78 | 78 | ), |
| 79 | 79 | ), |
| 80 | 80 | array( |
| 81 | 81 | 'methods' => \WP_REST_Server::READABLE, |
| 82 | - 'callback' => array( $this, 'get_item' ), |
|
| 83 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 82 | + 'callback' => array($this, 'get_item'), |
|
| 83 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 84 | 84 | 'args' => array( |
| 85 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 85 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 86 | 86 | ), |
| 87 | 87 | ), |
| 88 | 88 | array( |
| 89 | 89 | 'methods' => \WP_REST_Server::EDITABLE, |
| 90 | - 'callback' => array( $this, 'update_item' ), |
|
| 91 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
| 92 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
| 90 | + 'callback' => array($this, 'update_item'), |
|
| 91 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
| 92 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
| 93 | 93 | ), |
| 94 | 94 | array( |
| 95 | 95 | 'methods' => \WP_REST_Server::DELETABLE, |
| 96 | - 'callback' => array( $this, 'delete_item' ), |
|
| 97 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
| 96 | + 'callback' => array($this, 'delete_item'), |
|
| 97 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
| 98 | 98 | 'args' => array( |
| 99 | 99 | 'force' => array( |
| 100 | 100 | 'default' => false, |
| 101 | 101 | 'type' => 'boolean', |
| 102 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
| 102 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
| 103 | 103 | ), |
| 104 | 104 | ), |
| 105 | 105 | ), |
| 106 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 106 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 107 | 107 | ), |
| 108 | 108 | true |
| 109 | 109 | ); |
@@ -114,17 +114,17 @@ discard block |
||
| 114 | 114 | array( |
| 115 | 115 | 'args' => array( |
| 116 | 116 | 'attribute_id' => array( |
| 117 | - 'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ), |
|
| 117 | + 'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'), |
|
| 118 | 118 | 'type' => 'integer', |
| 119 | 119 | ), |
| 120 | 120 | ), |
| 121 | 121 | array( |
| 122 | 122 | 'methods' => \WP_REST_Server::EDITABLE, |
| 123 | - 'callback' => array( $this, 'batch_items' ), |
|
| 124 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
| 125 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
| 123 | + 'callback' => array($this, 'batch_items'), |
|
| 124 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
| 125 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
| 126 | 126 | ), |
| 127 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
| 127 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
| 128 | 128 | ), |
| 129 | 129 | true |
| 130 | 130 | ); |
@@ -137,9 +137,9 @@ discard block |
||
| 137 | 137 | * @param \WP_REST_Request $request Request params. |
| 138 | 138 | * @return \WP_REST_Response $response |
| 139 | 139 | */ |
| 140 | - public function prepare_item_for_response( $item, $request ) { |
|
| 140 | + public function prepare_item_for_response($item, $request) { |
|
| 141 | 141 | // Get term order. |
| 142 | - $menu_order = get_term_meta( $item->term_id, 'order_' . $this->taxonomy, true ); |
|
| 142 | + $menu_order = get_term_meta($item->term_id, 'order_' . $this->taxonomy, true); |
|
| 143 | 143 | |
| 144 | 144 | $data = array( |
| 145 | 145 | 'id' => (int) $item->term_id, |
@@ -150,13 +150,13 @@ discard block |
||
| 150 | 150 | 'count' => (int) $item->count, |
| 151 | 151 | ); |
| 152 | 152 | |
| 153 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 154 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 155 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 153 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 154 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 155 | + $data = $this->filter_response_by_context($data, $context); |
|
| 156 | 156 | |
| 157 | - $response = rest_ensure_response( $data ); |
|
| 157 | + $response = rest_ensure_response($data); |
|
| 158 | 158 | |
| 159 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
| 159 | + $response->add_links($this->prepare_links($item, $request)); |
|
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | 162 | * Filter a term item returned from the API. |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @param object $item The original term object. |
| 168 | 168 | * @param \WP_REST_Request $request Request used to generate the response. |
| 169 | 169 | */ |
| 170 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
| 170 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -177,10 +177,10 @@ discard block |
||
| 177 | 177 | * @param \WP_REST_Request $request Request params. |
| 178 | 178 | * @return bool|\WP_Error |
| 179 | 179 | */ |
| 180 | - protected function update_term_meta_fields( $term, $request ) { |
|
| 180 | + protected function update_term_meta_fields($term, $request) { |
|
| 181 | 181 | $id = (int) $term->term_id; |
| 182 | 182 | |
| 183 | - update_term_meta( $id, 'order_' . $this->taxonomy, $request['menu_order'] ); |
|
| 183 | + update_term_meta($id, 'order_' . $this->taxonomy, $request['menu_order']); |
|
| 184 | 184 | |
| 185 | 185 | return true; |
| 186 | 186 | } |
@@ -197,49 +197,49 @@ discard block |
||
| 197 | 197 | 'type' => 'object', |
| 198 | 198 | 'properties' => array( |
| 199 | 199 | 'id' => array( |
| 200 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 200 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 201 | 201 | 'type' => 'integer', |
| 202 | - 'context' => array( 'view', 'edit' ), |
|
| 202 | + 'context' => array('view', 'edit'), |
|
| 203 | 203 | 'readonly' => true, |
| 204 | 204 | ), |
| 205 | 205 | 'name' => array( |
| 206 | - 'description' => __( 'Term name.', 'woocommerce' ), |
|
| 206 | + 'description' => __('Term name.', 'woocommerce'), |
|
| 207 | 207 | 'type' => 'string', |
| 208 | - 'context' => array( 'view', 'edit' ), |
|
| 208 | + 'context' => array('view', 'edit'), |
|
| 209 | 209 | 'arg_options' => array( |
| 210 | 210 | 'sanitize_callback' => 'sanitize_text_field', |
| 211 | 211 | ), |
| 212 | 212 | ), |
| 213 | 213 | 'slug' => array( |
| 214 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
| 214 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
| 215 | 215 | 'type' => 'string', |
| 216 | - 'context' => array( 'view', 'edit' ), |
|
| 216 | + 'context' => array('view', 'edit'), |
|
| 217 | 217 | 'arg_options' => array( |
| 218 | 218 | 'sanitize_callback' => 'sanitize_title', |
| 219 | 219 | ), |
| 220 | 220 | ), |
| 221 | 221 | 'description' => array( |
| 222 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
| 222 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
| 223 | 223 | 'type' => 'string', |
| 224 | - 'context' => array( 'view', 'edit' ), |
|
| 224 | + 'context' => array('view', 'edit'), |
|
| 225 | 225 | 'arg_options' => array( |
| 226 | 226 | 'sanitize_callback' => 'wp_filter_post_kses', |
| 227 | 227 | ), |
| 228 | 228 | ), |
| 229 | 229 | 'menu_order' => array( |
| 230 | - 'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ), |
|
| 230 | + 'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'), |
|
| 231 | 231 | 'type' => 'integer', |
| 232 | - 'context' => array( 'view', 'edit' ), |
|
| 232 | + 'context' => array('view', 'edit'), |
|
| 233 | 233 | ), |
| 234 | 234 | 'count' => array( |
| 235 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
| 235 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
| 236 | 236 | 'type' => 'integer', |
| 237 | - 'context' => array( 'view', 'edit' ), |
|
| 237 | + 'context' => array('view', 'edit'), |
|
| 238 | 238 | 'readonly' => true, |
| 239 | 239 | ), |
| 240 | 240 | ), |
| 241 | 241 | ); |
| 242 | 242 | |
| 243 | - return $this->add_additional_fields_schema( $schema ); |
|
| 243 | + return $this->add_additional_fields_schema($schema); |
|
| 244 | 244 | } |
| 245 | 245 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API Setting Options controller class. |
@@ -35,16 +35,16 @@ discard block |
||
| 35 | 35 | array( |
| 36 | 36 | 'args' => array( |
| 37 | 37 | 'group' => array( |
| 38 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
| 38 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
| 39 | 39 | 'type' => 'string', |
| 40 | 40 | ), |
| 41 | 41 | ), |
| 42 | 42 | array( |
| 43 | 43 | 'methods' => \WP_REST_Server::READABLE, |
| 44 | - 'callback' => array( $this, 'get_items' ), |
|
| 45 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 44 | + 'callback' => array($this, 'get_items'), |
|
| 45 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 46 | 46 | ), |
| 47 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 47 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 48 | 48 | ), |
| 49 | 49 | true |
| 50 | 50 | ); |
@@ -55,17 +55,17 @@ discard block |
||
| 55 | 55 | array( |
| 56 | 56 | 'args' => array( |
| 57 | 57 | 'group' => array( |
| 58 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
| 58 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
| 59 | 59 | 'type' => 'string', |
| 60 | 60 | ), |
| 61 | 61 | ), |
| 62 | 62 | array( |
| 63 | 63 | 'methods' => \WP_REST_Server::EDITABLE, |
| 64 | - 'callback' => array( $this, 'batch_items' ), |
|
| 65 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
| 66 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
| 64 | + 'callback' => array($this, 'batch_items'), |
|
| 65 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
| 66 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
| 67 | 67 | ), |
| 68 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
| 68 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
| 69 | 69 | ), |
| 70 | 70 | true |
| 71 | 71 | ); |
@@ -76,26 +76,26 @@ discard block |
||
| 76 | 76 | array( |
| 77 | 77 | 'args' => array( |
| 78 | 78 | 'group' => array( |
| 79 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
| 79 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
| 80 | 80 | 'type' => 'string', |
| 81 | 81 | ), |
| 82 | 82 | 'id' => array( |
| 83 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 83 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 84 | 84 | 'type' => 'string', |
| 85 | 85 | ), |
| 86 | 86 | ), |
| 87 | 87 | array( |
| 88 | 88 | 'methods' => \WP_REST_Server::READABLE, |
| 89 | - 'callback' => array( $this, 'get_item' ), |
|
| 90 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 89 | + 'callback' => array($this, 'get_item'), |
|
| 90 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 91 | 91 | ), |
| 92 | 92 | array( |
| 93 | 93 | 'methods' => \WP_REST_Server::EDITABLE, |
| 94 | - 'callback' => array( $this, 'update_item' ), |
|
| 95 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
| 96 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
| 94 | + 'callback' => array($this, 'update_item'), |
|
| 95 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
| 96 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
| 97 | 97 | ), |
| 98 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 98 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 99 | 99 | ), |
| 100 | 100 | true |
| 101 | 101 | ); |
@@ -108,16 +108,16 @@ discard block |
||
| 108 | 108 | * @param \WP_REST_Request $request Request data. |
| 109 | 109 | * @return \WP_Error\WP_REST_Response |
| 110 | 110 | */ |
| 111 | - public function get_item( $request ) { |
|
| 112 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
| 111 | + public function get_item($request) { |
|
| 112 | + $setting = $this->get_setting($request['group_id'], $request['id']); |
|
| 113 | 113 | |
| 114 | - if ( is_wp_error( $setting ) ) { |
|
| 114 | + if (is_wp_error($setting)) { |
|
| 115 | 115 | return $setting; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - $response = $this->prepare_item_for_response( $setting, $request ); |
|
| 118 | + $response = $this->prepare_item_for_response($setting, $request); |
|
| 119 | 119 | |
| 120 | - return rest_ensure_response( $response ); |
|
| 120 | + return rest_ensure_response($response); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -127,24 +127,24 @@ discard block |
||
| 127 | 127 | * @param \WP_REST_Request $request Request data. |
| 128 | 128 | * @return \WP_Error\WP_REST_Response |
| 129 | 129 | */ |
| 130 | - public function get_items( $request ) { |
|
| 131 | - $settings = $this->get_group_settings( $request['group_id'] ); |
|
| 130 | + public function get_items($request) { |
|
| 131 | + $settings = $this->get_group_settings($request['group_id']); |
|
| 132 | 132 | |
| 133 | - if ( is_wp_error( $settings ) ) { |
|
| 133 | + if (is_wp_error($settings)) { |
|
| 134 | 134 | return $settings; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | $data = array(); |
| 138 | 138 | |
| 139 | - foreach ( $settings as $setting_obj ) { |
|
| 140 | - $setting = $this->prepare_item_for_response( $setting_obj, $request ); |
|
| 141 | - $setting = $this->prepare_response_for_collection( $setting ); |
|
| 142 | - if ( $this->is_setting_type_valid( $setting['type'] ) ) { |
|
| 139 | + foreach ($settings as $setting_obj) { |
|
| 140 | + $setting = $this->prepare_item_for_response($setting_obj, $request); |
|
| 141 | + $setting = $this->prepare_response_for_collection($setting); |
|
| 142 | + if ($this->is_setting_type_valid($setting['type'])) { |
|
| 143 | 143 | $data[] = $setting; |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - return rest_ensure_response( $data ); |
|
| 147 | + return rest_ensure_response($data); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -153,39 +153,39 @@ discard block |
||
| 153 | 153 | * @param string $group_id Group ID. |
| 154 | 154 | * @return array|\WP_Error |
| 155 | 155 | */ |
| 156 | - public function get_group_settings( $group_id ) { |
|
| 157 | - if ( empty( $group_id ) ) { |
|
| 158 | - return new \WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 156 | + public function get_group_settings($group_id) { |
|
| 157 | + if (empty($group_id)) { |
|
| 158 | + return new \WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404)); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - $settings = apply_filters( 'woocommerce_settings-' . $group_id, array() ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 161 | + $settings = apply_filters('woocommerce_settings-' . $group_id, array()); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 162 | 162 | |
| 163 | - if ( empty( $settings ) ) { |
|
| 164 | - return new \WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 163 | + if (empty($settings)) { |
|
| 164 | + return new \WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404)); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $filtered_settings = array(); |
| 168 | - foreach ( $settings as $setting ) { |
|
| 168 | + foreach ($settings as $setting) { |
|
| 169 | 169 | $option_key = $setting['option_key']; |
| 170 | - $setting = $this->filter_setting( $setting ); |
|
| 171 | - $default = isset( $setting['default'] ) ? $setting['default'] : ''; |
|
| 170 | + $setting = $this->filter_setting($setting); |
|
| 171 | + $default = isset($setting['default']) ? $setting['default'] : ''; |
|
| 172 | 172 | // Get the option value. |
| 173 | - if ( is_array( $option_key ) ) { |
|
| 174 | - $option = get_option( $option_key[0] ); |
|
| 175 | - $setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default; |
|
| 173 | + if (is_array($option_key)) { |
|
| 174 | + $option = get_option($option_key[0]); |
|
| 175 | + $setting['value'] = isset($option[$option_key[1]]) ? $option[$option_key[1]] : $default; |
|
| 176 | 176 | } else { |
| 177 | - $admin_setting_value = \WC_Admin_Settings::get_option( $option_key, $default ); |
|
| 177 | + $admin_setting_value = \WC_Admin_Settings::get_option($option_key, $default); |
|
| 178 | 178 | $setting['value'] = $admin_setting_value; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - if ( 'multi_select_countries' === $setting['type'] ) { |
|
| 181 | + if ('multi_select_countries' === $setting['type']) { |
|
| 182 | 182 | $setting['options'] = WC()->countries->get_countries(); |
| 183 | 183 | $setting['type'] = 'multiselect'; |
| 184 | - } elseif ( 'single_select_country' === $setting['type'] ) { |
|
| 184 | + } elseif ('single_select_country' === $setting['type']) { |
|
| 185 | 185 | $setting['type'] = 'select'; |
| 186 | 186 | $setting['options'] = $this->get_countries_and_states(); |
| 187 | - } elseif ( 'single_select_page' === $setting['type'] ) { |
|
| 188 | - $pages = get_pages( |
|
| 187 | + } elseif ('single_select_page' === $setting['type']) { |
|
| 188 | + $pages = get_pages( |
|
| 189 | 189 | array( |
| 190 | 190 | 'sort_column' => 'menu_order', |
| 191 | 191 | 'sort_order' => 'ASC', |
@@ -193,8 +193,8 @@ discard block |
||
| 193 | 193 | ) |
| 194 | 194 | ); |
| 195 | 195 | $options = array(); |
| 196 | - foreach ( $pages as $page ) { |
|
| 197 | - $options[ $page->ID ] = ! empty( $page->post_title ) ? $page->post_title : '#' . $page->ID; |
|
| 196 | + foreach ($pages as $page) { |
|
| 197 | + $options[$page->ID] = ! empty($page->post_title) ? $page->post_title : '#' . $page->ID; |
|
| 198 | 198 | } |
| 199 | 199 | $setting['type'] = 'select'; |
| 200 | 200 | $setting['options'] = $options; |
@@ -214,19 +214,19 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | private function get_countries_and_states() { |
| 216 | 216 | $countries = WC()->countries->get_countries(); |
| 217 | - if ( ! $countries ) { |
|
| 217 | + if ( ! $countries) { |
|
| 218 | 218 | return array(); |
| 219 | 219 | } |
| 220 | 220 | $output = array(); |
| 221 | - foreach ( $countries as $key => $value ) { |
|
| 222 | - $states = WC()->countries->get_states( $key ); |
|
| 221 | + foreach ($countries as $key => $value) { |
|
| 222 | + $states = WC()->countries->get_states($key); |
|
| 223 | 223 | |
| 224 | - if ( $states ) { |
|
| 225 | - foreach ( $states as $state_key => $state_value ) { |
|
| 226 | - $output[ $key . ':' . $state_key ] = $value . ' - ' . $state_value; |
|
| 224 | + if ($states) { |
|
| 225 | + foreach ($states as $state_key => $state_value) { |
|
| 226 | + $output[$key . ':' . $state_key] = $value . ' - ' . $state_value; |
|
| 227 | 227 | } |
| 228 | 228 | } else { |
| 229 | - $output[ $key ] = $value; |
|
| 229 | + $output[$key] = $value; |
|
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | return $output; |
@@ -240,30 +240,30 @@ discard block |
||
| 240 | 240 | * @param string $setting_id Setting ID. |
| 241 | 241 | * @return stdClass|\WP_Error |
| 242 | 242 | */ |
| 243 | - public function get_setting( $group_id, $setting_id ) { |
|
| 244 | - if ( empty( $setting_id ) ) { |
|
| 245 | - return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 243 | + public function get_setting($group_id, $setting_id) { |
|
| 244 | + if (empty($setting_id)) { |
|
| 245 | + return new \WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - $settings = $this->get_group_settings( $group_id ); |
|
| 248 | + $settings = $this->get_group_settings($group_id); |
|
| 249 | 249 | |
| 250 | - if ( is_wp_error( $settings ) ) { |
|
| 250 | + if (is_wp_error($settings)) { |
|
| 251 | 251 | return $settings; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - $array_key = array_keys( wp_list_pluck( $settings, 'id' ), $setting_id ); |
|
| 254 | + $array_key = array_keys(wp_list_pluck($settings, 'id'), $setting_id); |
|
| 255 | 255 | |
| 256 | - if ( empty( $array_key ) ) { |
|
| 257 | - return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 256 | + if (empty($array_key)) { |
|
| 257 | + return new \WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - $setting = $settings[ $array_key[0] ]; |
|
| 260 | + $setting = $settings[$array_key[0]]; |
|
| 261 | 261 | |
| 262 | - if ( ! $this->is_setting_type_valid( $setting['type'] ) ) { |
|
| 263 | - return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 262 | + if ( ! $this->is_setting_type_valid($setting['type'])) { |
|
| 263 | + return new \WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - if ( is_wp_error( $setting ) ) { |
|
| 266 | + if (is_wp_error($setting)) { |
|
| 267 | 267 | return $setting; |
| 268 | 268 | } |
| 269 | 269 | |
@@ -279,24 +279,24 @@ discard block |
||
| 279 | 279 | * @param \WP_REST_Request $request Full details about the request. |
| 280 | 280 | * @return array Of \WP_Error or \WP_REST_Response. |
| 281 | 281 | */ |
| 282 | - public function batch_items( $request ) { |
|
| 282 | + public function batch_items($request) { |
|
| 283 | 283 | // Get the request params. |
| 284 | - $items = array_filter( $request->get_params() ); |
|
| 284 | + $items = array_filter($request->get_params()); |
|
| 285 | 285 | |
| 286 | 286 | /* |
| 287 | 287 | * Since our batch settings update is group-specific and matches based on the route, |
| 288 | 288 | * we inject the URL parameters (containing group) into the batch items |
| 289 | 289 | */ |
| 290 | - if ( ! empty( $items['update'] ) ) { |
|
| 290 | + if ( ! empty($items['update'])) { |
|
| 291 | 291 | $to_update = array(); |
| 292 | - foreach ( $items['update'] as $item ) { |
|
| 293 | - $to_update[] = array_merge( $request->get_url_params(), $item ); |
|
| 292 | + foreach ($items['update'] as $item) { |
|
| 293 | + $to_update[] = array_merge($request->get_url_params(), $item); |
|
| 294 | 294 | } |
| 295 | - $request = new \WP_REST_Request( $request->get_method() ); |
|
| 296 | - $request->set_body_params( array( 'update' => $to_update ) ); |
|
| 295 | + $request = new \WP_REST_Request($request->get_method()); |
|
| 296 | + $request->set_body_params(array('update' => $to_update)); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - return parent::batch_items( $request ); |
|
| 299 | + return parent::batch_items($request); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -306,39 +306,39 @@ discard block |
||
| 306 | 306 | * @param \WP_REST_Request $request Request data. |
| 307 | 307 | * @return \WP_Error\WP_REST_Response |
| 308 | 308 | */ |
| 309 | - public function update_item( $request ) { |
|
| 310 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
| 309 | + public function update_item($request) { |
|
| 310 | + $setting = $this->get_setting($request['group_id'], $request['id']); |
|
| 311 | 311 | |
| 312 | - if ( is_wp_error( $setting ) ) { |
|
| 312 | + if (is_wp_error($setting)) { |
|
| 313 | 313 | return $setting; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - if ( is_callable( array( $this, 'validate_setting_' . $setting['type'] . '_field' ) ) ) { |
|
| 317 | - $value = $this->{'validate_setting_' . $setting['type'] . '_field'}( $request['value'], $setting ); |
|
| 316 | + if (is_callable(array($this, 'validate_setting_' . $setting['type'] . '_field'))) { |
|
| 317 | + $value = $this->{'validate_setting_' . $setting['type'] . '_field'}($request['value'], $setting); |
|
| 318 | 318 | } else { |
| 319 | - $value = $this->validate_setting_text_field( $request['value'], $setting ); |
|
| 319 | + $value = $this->validate_setting_text_field($request['value'], $setting); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - if ( is_wp_error( $value ) ) { |
|
| 322 | + if (is_wp_error($value)) { |
|
| 323 | 323 | return $value; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - if ( is_array( $setting['option_key'] ) ) { |
|
| 326 | + if (is_array($setting['option_key'])) { |
|
| 327 | 327 | $setting['value'] = $value; |
| 328 | 328 | $option_key = $setting['option_key']; |
| 329 | - $prev = get_option( $option_key[0] ); |
|
| 330 | - $prev[ $option_key[1] ] = $request['value']; |
|
| 331 | - update_option( $option_key[0], $prev ); |
|
| 329 | + $prev = get_option($option_key[0]); |
|
| 330 | + $prev[$option_key[1]] = $request['value']; |
|
| 331 | + update_option($option_key[0], $prev); |
|
| 332 | 332 | } else { |
| 333 | 333 | $update_data = array(); |
| 334 | - $update_data[ $setting['option_key'] ] = $value; |
|
| 334 | + $update_data[$setting['option_key']] = $value; |
|
| 335 | 335 | $setting['value'] = $value; |
| 336 | - \WC_Admin_Settings::save_fields( array( $setting ), $update_data ); |
|
| 336 | + \WC_Admin_Settings::save_fields(array($setting), $update_data); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - $response = $this->prepare_item_for_response( $setting, $request ); |
|
| 339 | + $response = $this->prepare_item_for_response($setting, $request); |
|
| 340 | 340 | |
| 341 | - return rest_ensure_response( $response ); |
|
| 341 | + return rest_ensure_response($response); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -349,13 +349,13 @@ discard block |
||
| 349 | 349 | * @param \WP_REST_Request $request Request object. |
| 350 | 350 | * @return \WP_REST_Response $response Response data. |
| 351 | 351 | */ |
| 352 | - public function prepare_item_for_response( $item, $request ) { |
|
| 353 | - unset( $item['option_key'] ); |
|
| 354 | - $data = $this->filter_setting( $item ); |
|
| 355 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 356 | - $data = $this->filter_response_by_context( $data, empty( $request['context'] ) ? 'view' : $request['context'] ); |
|
| 357 | - $response = rest_ensure_response( $data ); |
|
| 358 | - $response->add_links( $this->prepare_links( $data['id'], $request['group_id'] ) ); |
|
| 352 | + public function prepare_item_for_response($item, $request) { |
|
| 353 | + unset($item['option_key']); |
|
| 354 | + $data = $this->filter_setting($item); |
|
| 355 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 356 | + $data = $this->filter_response_by_context($data, empty($request['context']) ? 'view' : $request['context']); |
|
| 357 | + $response = rest_ensure_response($data); |
|
| 358 | + $response->add_links($this->prepare_links($data['id'], $request['group_id'])); |
|
| 359 | 359 | return $response; |
| 360 | 360 | } |
| 361 | 361 | |
@@ -367,14 +367,14 @@ discard block |
||
| 367 | 367 | * @param string $group_id Group ID. |
| 368 | 368 | * @return array Links for the given setting. |
| 369 | 369 | */ |
| 370 | - protected function prepare_links( $setting_id, $group_id ) { |
|
| 371 | - $base = str_replace( '(?P<group_id>[\w-]+)', $group_id, $this->rest_base ); |
|
| 370 | + protected function prepare_links($setting_id, $group_id) { |
|
| 371 | + $base = str_replace('(?P<group_id>[\w-]+)', $group_id, $this->rest_base); |
|
| 372 | 372 | $links = array( |
| 373 | 373 | 'self' => array( |
| 374 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $base, $setting_id ) ), |
|
| 374 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $base, $setting_id)), |
|
| 375 | 375 | ), |
| 376 | 376 | 'collection' => array( |
| 377 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
| 377 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
| 378 | 378 | ), |
| 379 | 379 | ); |
| 380 | 380 | |
@@ -388,9 +388,9 @@ discard block |
||
| 388 | 388 | * @param \WP_REST_Request $request Full data about the request. |
| 389 | 389 | * @return \WP_Error|boolean |
| 390 | 390 | */ |
| 391 | - public function get_items_permissions_check( $request ) { |
|
| 392 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
| 393 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 391 | + public function get_items_permissions_check($request) { |
|
| 392 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
| 393 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | return true; |
@@ -403,9 +403,9 @@ discard block |
||
| 403 | 403 | * @param \WP_REST_Request $request Full data about the request. |
| 404 | 404 | * @return \WP_Error|boolean |
| 405 | 405 | */ |
| 406 | - public function update_items_permissions_check( $request ) { |
|
| 407 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
| 408 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 406 | + public function update_items_permissions_check($request) { |
|
| 407 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
| 408 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | return true; |
@@ -419,18 +419,18 @@ discard block |
||
| 419 | 419 | * @param array $setting Settings. |
| 420 | 420 | * @return array |
| 421 | 421 | */ |
| 422 | - public function filter_setting( $setting ) { |
|
| 422 | + public function filter_setting($setting) { |
|
| 423 | 423 | $setting = array_intersect_key( |
| 424 | 424 | $setting, |
| 425 | - array_flip( array_filter( array_keys( $setting ), array( $this, 'allowed_setting_keys' ) ) ) |
|
| 425 | + array_flip(array_filter(array_keys($setting), array($this, 'allowed_setting_keys'))) |
|
| 426 | 426 | ); |
| 427 | 427 | |
| 428 | - if ( empty( $setting['options'] ) ) { |
|
| 429 | - unset( $setting['options'] ); |
|
| 428 | + if (empty($setting['options'])) { |
|
| 429 | + unset($setting['options']); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - if ( 'image_width' === $setting['type'] ) { |
|
| 433 | - $setting = $this->cast_image_width( $setting ); |
|
| 432 | + if ('image_width' === $setting['type']) { |
|
| 433 | + $setting = $this->cast_image_width($setting); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | return $setting; |
@@ -445,12 +445,12 @@ discard block |
||
| 445 | 445 | * @param array $setting Settings. |
| 446 | 446 | * @return array |
| 447 | 447 | */ |
| 448 | - public function cast_image_width( $setting ) { |
|
| 449 | - foreach ( array( 'default', 'value' ) as $key ) { |
|
| 450 | - if ( isset( $setting[ $key ] ) ) { |
|
| 451 | - $setting[ $key ]['width'] = intval( $setting[ $key ]['width'] ); |
|
| 452 | - $setting[ $key ]['height'] = intval( $setting[ $key ]['height'] ); |
|
| 453 | - $setting[ $key ]['crop'] = (bool) $setting[ $key ]['crop']; |
|
| 448 | + public function cast_image_width($setting) { |
|
| 449 | + foreach (array('default', 'value') as $key) { |
|
| 450 | + if (isset($setting[$key])) { |
|
| 451 | + $setting[$key]['width'] = intval($setting[$key]['width']); |
|
| 452 | + $setting[$key]['height'] = intval($setting[$key]['height']); |
|
| 453 | + $setting[$key]['crop'] = (bool) $setting[$key]['crop']; |
|
| 454 | 454 | } |
| 455 | 455 | } |
| 456 | 456 | return $setting; |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | * @param string $key Key to check. |
| 463 | 463 | * @return boolean |
| 464 | 464 | */ |
| 465 | - public function allowed_setting_keys( $key ) { |
|
| 465 | + public function allowed_setting_keys($key) { |
|
| 466 | 466 | return in_array( |
| 467 | 467 | $key, array( |
| 468 | 468 | 'id', |
@@ -487,20 +487,20 @@ discard block |
||
| 487 | 487 | * @param string $type Type. |
| 488 | 488 | * @return bool |
| 489 | 489 | */ |
| 490 | - public function is_setting_type_valid( $type ) { |
|
| 490 | + public function is_setting_type_valid($type) { |
|
| 491 | 491 | return in_array( |
| 492 | 492 | $type, array( |
| 493 | - 'text', // Validates with validate_setting_text_field. |
|
| 494 | - 'email', // Validates with validate_setting_text_field. |
|
| 495 | - 'number', // Validates with validate_setting_text_field. |
|
| 496 | - 'color', // Validates with validate_setting_text_field. |
|
| 497 | - 'password', // Validates with validate_setting_text_field. |
|
| 498 | - 'textarea', // Validates with validate_setting_textarea_field. |
|
| 499 | - 'select', // Validates with validate_setting_select_field. |
|
| 500 | - 'multiselect', // Validates with validate_setting_multiselect_field. |
|
| 501 | - 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
| 502 | - 'checkbox', // Validates with validate_setting_checkbox_field. |
|
| 503 | - 'image_width', // Validates with validate_setting_image_width_field. |
|
| 493 | + 'text', // Validates with validate_setting_text_field. |
|
| 494 | + 'email', // Validates with validate_setting_text_field. |
|
| 495 | + 'number', // Validates with validate_setting_text_field. |
|
| 496 | + 'color', // Validates with validate_setting_text_field. |
|
| 497 | + 'password', // Validates with validate_setting_text_field. |
|
| 498 | + 'textarea', // Validates with validate_setting_textarea_field. |
|
| 499 | + 'select', // Validates with validate_setting_select_field. |
|
| 500 | + 'multiselect', // Validates with validate_setting_multiselect_field. |
|
| 501 | + 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
| 502 | + 'checkbox', // Validates with validate_setting_checkbox_field. |
|
| 503 | + 'image_width', // Validates with validate_setting_image_width_field. |
|
| 504 | 504 | 'thumbnail_cropping', // Validates with validate_setting_text_field. |
| 505 | 505 | ) |
| 506 | 506 | ); |
@@ -518,89 +518,89 @@ discard block |
||
| 518 | 518 | 'type' => 'object', |
| 519 | 519 | 'properties' => array( |
| 520 | 520 | 'id' => array( |
| 521 | - 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ), |
|
| 521 | + 'description' => __('A unique identifier for the setting.', 'woocommerce'), |
|
| 522 | 522 | 'type' => 'string', |
| 523 | 523 | 'arg_options' => array( |
| 524 | 524 | 'sanitize_callback' => 'sanitize_title', |
| 525 | 525 | ), |
| 526 | - 'context' => array( 'view', 'edit' ), |
|
| 526 | + 'context' => array('view', 'edit'), |
|
| 527 | 527 | 'readonly' => true, |
| 528 | 528 | ), |
| 529 | 529 | 'group_id' => array( |
| 530 | - 'description' => __( 'An identifier for the group this setting belongs to.', 'woocommerce' ), |
|
| 530 | + 'description' => __('An identifier for the group this setting belongs to.', 'woocommerce'), |
|
| 531 | 531 | 'type' => 'string', |
| 532 | 532 | 'arg_options' => array( |
| 533 | 533 | 'sanitize_callback' => 'sanitize_title', |
| 534 | 534 | ), |
| 535 | - 'context' => array( 'view', 'edit' ), |
|
| 535 | + 'context' => array('view', 'edit'), |
|
| 536 | 536 | 'readonly' => true, |
| 537 | 537 | ), |
| 538 | 538 | 'label' => array( |
| 539 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
| 539 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
| 540 | 540 | 'type' => 'string', |
| 541 | 541 | 'arg_options' => array( |
| 542 | 542 | 'sanitize_callback' => 'sanitize_text_field', |
| 543 | 543 | ), |
| 544 | - 'context' => array( 'view', 'edit' ), |
|
| 544 | + 'context' => array('view', 'edit'), |
|
| 545 | 545 | 'readonly' => true, |
| 546 | 546 | ), |
| 547 | 547 | 'description' => array( |
| 548 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
| 548 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
| 549 | 549 | 'type' => 'string', |
| 550 | 550 | 'arg_options' => array( |
| 551 | 551 | 'sanitize_callback' => 'sanitize_text_field', |
| 552 | 552 | ), |
| 553 | - 'context' => array( 'view', 'edit' ), |
|
| 553 | + 'context' => array('view', 'edit'), |
|
| 554 | 554 | 'readonly' => true, |
| 555 | 555 | ), |
| 556 | 556 | 'value' => array( |
| 557 | - 'description' => __( 'Setting value.', 'woocommerce' ), |
|
| 557 | + 'description' => __('Setting value.', 'woocommerce'), |
|
| 558 | 558 | 'type' => 'mixed', |
| 559 | - 'context' => array( 'view', 'edit' ), |
|
| 559 | + 'context' => array('view', 'edit'), |
|
| 560 | 560 | ), |
| 561 | 561 | 'default' => array( |
| 562 | - 'description' => __( 'Default value for the setting.', 'woocommerce' ), |
|
| 562 | + 'description' => __('Default value for the setting.', 'woocommerce'), |
|
| 563 | 563 | 'type' => 'mixed', |
| 564 | - 'context' => array( 'view', 'edit' ), |
|
| 564 | + 'context' => array('view', 'edit'), |
|
| 565 | 565 | 'readonly' => true, |
| 566 | 566 | ), |
| 567 | 567 | 'tip' => array( |
| 568 | - 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ), |
|
| 568 | + 'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'), |
|
| 569 | 569 | 'type' => 'string', |
| 570 | 570 | 'arg_options' => array( |
| 571 | 571 | 'sanitize_callback' => 'sanitize_text_field', |
| 572 | 572 | ), |
| 573 | - 'context' => array( 'view', 'edit' ), |
|
| 573 | + 'context' => array('view', 'edit'), |
|
| 574 | 574 | 'readonly' => true, |
| 575 | 575 | ), |
| 576 | 576 | 'placeholder' => array( |
| 577 | - 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ), |
|
| 577 | + 'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'), |
|
| 578 | 578 | 'type' => 'string', |
| 579 | 579 | 'arg_options' => array( |
| 580 | 580 | 'sanitize_callback' => 'sanitize_text_field', |
| 581 | 581 | ), |
| 582 | - 'context' => array( 'view', 'edit' ), |
|
| 582 | + 'context' => array('view', 'edit'), |
|
| 583 | 583 | 'readonly' => true, |
| 584 | 584 | ), |
| 585 | 585 | 'type' => array( |
| 586 | - 'description' => __( 'Type of setting.', 'woocommerce' ), |
|
| 586 | + 'description' => __('Type of setting.', 'woocommerce'), |
|
| 587 | 587 | 'type' => 'string', |
| 588 | 588 | 'arg_options' => array( |
| 589 | 589 | 'sanitize_callback' => 'sanitize_text_field', |
| 590 | 590 | ), |
| 591 | - 'context' => array( 'view', 'edit' ), |
|
| 592 | - 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ), |
|
| 591 | + 'context' => array('view', 'edit'), |
|
| 592 | + 'enum' => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'), |
|
| 593 | 593 | 'readonly' => true, |
| 594 | 594 | ), |
| 595 | 595 | 'options' => array( |
| 596 | - 'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ), |
|
| 596 | + 'description' => __('Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce'), |
|
| 597 | 597 | 'type' => 'object', |
| 598 | - 'context' => array( 'view', 'edit' ), |
|
| 598 | + 'context' => array('view', 'edit'), |
|
| 599 | 599 | 'readonly' => true, |
| 600 | 600 | ), |
| 601 | 601 | ), |
| 602 | 602 | ); |
| 603 | 603 | |
| 604 | - return $this->add_additional_fields_schema( $schema ); |
|
| 604 | + return $this->add_additional_fields_schema($schema); |
|
| 605 | 605 | } |
| 606 | 606 | } |