@@ -8,7 +8,7 @@ |
||
| 8 | 8 | * @since 2.6.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * REST API Taxes controller class. |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @version 3.3.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if ( ! defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
@@ -39,26 +39,26 @@ discard block |
||
| 39 | 39 | array( |
| 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 | ); |
| 64 | 64 | |
@@ -68,37 +68,37 @@ discard block |
||
| 68 | 68 | array( |
| 69 | 69 | 'args' => array( |
| 70 | 70 | 'id' => array( |
| 71 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 71 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 72 | 72 | 'type' => 'integer', |
| 73 | 73 | ), |
| 74 | 74 | ), |
| 75 | 75 | array( |
| 76 | 76 | 'methods' => WP_REST_Server::READABLE, |
| 77 | - 'callback' => array( $this, 'get_item' ), |
|
| 78 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 77 | + 'callback' => array($this, 'get_item'), |
|
| 78 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 79 | 79 | 'args' => array( |
| 80 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 80 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 81 | 81 | ), |
| 82 | 82 | ), |
| 83 | 83 | array( |
| 84 | 84 | 'methods' => WP_REST_Server::EDITABLE, |
| 85 | - 'callback' => array( $this, 'update_item' ), |
|
| 86 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
| 87 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
| 85 | + 'callback' => array($this, 'update_item'), |
|
| 86 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
| 87 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
| 88 | 88 | ), |
| 89 | 89 | array( |
| 90 | 90 | 'methods' => WP_REST_Server::DELETABLE, |
| 91 | - 'callback' => array( $this, 'delete_item' ), |
|
| 92 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
| 91 | + 'callback' => array($this, 'delete_item'), |
|
| 92 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
| 93 | 93 | 'args' => array( |
| 94 | 94 | 'force' => array( |
| 95 | 95 | 'default' => false, |
| 96 | 96 | 'type' => 'boolean', |
| 97 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
| 97 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
| 98 | 98 | ), |
| 99 | 99 | ), |
| 100 | 100 | ), |
| 101 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 101 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 102 | 102 | ) |
| 103 | 103 | ); |
| 104 | 104 | |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | array( |
| 109 | 109 | array( |
| 110 | 110 | 'methods' => WP_REST_Server::EDITABLE, |
| 111 | - 'callback' => array( $this, 'batch_items' ), |
|
| 112 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
| 113 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
| 111 | + 'callback' => array($this, 'batch_items'), |
|
| 112 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
| 113 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
| 114 | 114 | ), |
| 115 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
| 115 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
| 116 | 116 | ) |
| 117 | 117 | ); |
| 118 | 118 | } |
@@ -123,14 +123,14 @@ discard block |
||
| 123 | 123 | * @param WP_REST_Request $request Full details about the request. |
| 124 | 124 | * @return WP_Error|boolean |
| 125 | 125 | */ |
| 126 | - public function get_items_permissions_check( $request ) { |
|
| 127 | - $permissions = $this->check_permissions( $request, 'read' ); |
|
| 128 | - if ( is_wp_error( $permissions ) ) { |
|
| 126 | + public function get_items_permissions_check($request) { |
|
| 127 | + $permissions = $this->check_permissions($request, 'read'); |
|
| 128 | + if (is_wp_error($permissions)) { |
|
| 129 | 129 | return $permissions; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if ( ! $permissions ) { |
|
| 133 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 132 | + if ( ! $permissions) { |
|
| 133 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | return true; |
@@ -142,14 +142,14 @@ discard block |
||
| 142 | 142 | * @param WP_REST_Request $request Full details about the request. |
| 143 | 143 | * @return WP_Error|boolean |
| 144 | 144 | */ |
| 145 | - public function create_item_permissions_check( $request ) { |
|
| 146 | - $permissions = $this->check_permissions( $request, 'create' ); |
|
| 147 | - if ( is_wp_error( $permissions ) ) { |
|
| 145 | + public function create_item_permissions_check($request) { |
|
| 146 | + $permissions = $this->check_permissions($request, 'create'); |
|
| 147 | + if (is_wp_error($permissions)) { |
|
| 148 | 148 | return $permissions; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if ( ! $permissions ) { |
|
| 152 | - return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 151 | + if ( ! $permissions) { |
|
| 152 | + return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | return true; |
@@ -161,14 +161,14 @@ discard block |
||
| 161 | 161 | * @param WP_REST_Request $request Full details about the request. |
| 162 | 162 | * @return WP_Error|boolean |
| 163 | 163 | */ |
| 164 | - public function get_item_permissions_check( $request ) { |
|
| 165 | - $permissions = $this->check_permissions( $request, 'read' ); |
|
| 166 | - if ( is_wp_error( $permissions ) ) { |
|
| 164 | + public function get_item_permissions_check($request) { |
|
| 165 | + $permissions = $this->check_permissions($request, 'read'); |
|
| 166 | + if (is_wp_error($permissions)) { |
|
| 167 | 167 | return $permissions; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - if ( ! $permissions ) { |
|
| 171 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 170 | + if ( ! $permissions) { |
|
| 171 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | return true; |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | * @param WP_REST_Request $request Full details about the request. |
| 181 | 181 | * @return WP_Error|boolean |
| 182 | 182 | */ |
| 183 | - public function update_item_permissions_check( $request ) { |
|
| 184 | - $permissions = $this->check_permissions( $request, 'edit' ); |
|
| 185 | - if ( is_wp_error( $permissions ) ) { |
|
| 183 | + public function update_item_permissions_check($request) { |
|
| 184 | + $permissions = $this->check_permissions($request, 'edit'); |
|
| 185 | + if (is_wp_error($permissions)) { |
|
| 186 | 186 | return $permissions; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if ( ! $permissions ) { |
|
| 190 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 189 | + if ( ! $permissions) { |
|
| 190 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | return true; |
@@ -199,14 +199,14 @@ discard block |
||
| 199 | 199 | * @param WP_REST_Request $request Full details about the request. |
| 200 | 200 | * @return WP_Error|boolean |
| 201 | 201 | */ |
| 202 | - public function delete_item_permissions_check( $request ) { |
|
| 203 | - $permissions = $this->check_permissions( $request, 'delete' ); |
|
| 204 | - if ( is_wp_error( $permissions ) ) { |
|
| 202 | + public function delete_item_permissions_check($request) { |
|
| 203 | + $permissions = $this->check_permissions($request, 'delete'); |
|
| 204 | + if (is_wp_error($permissions)) { |
|
| 205 | 205 | return $permissions; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - if ( ! $permissions ) { |
|
| 209 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 208 | + if ( ! $permissions) { |
|
| 209 | + return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | return true; |
@@ -218,14 +218,14 @@ discard block |
||
| 218 | 218 | * @param WP_REST_Request $request Full details about the request. |
| 219 | 219 | * @return boolean|WP_Error |
| 220 | 220 | */ |
| 221 | - public function batch_items_permissions_check( $request ) { |
|
| 222 | - $permissions = $this->check_permissions( $request, 'batch' ); |
|
| 223 | - if ( is_wp_error( $permissions ) ) { |
|
| 221 | + public function batch_items_permissions_check($request) { |
|
| 222 | + $permissions = $this->check_permissions($request, 'batch'); |
|
| 223 | + if (is_wp_error($permissions)) { |
|
| 224 | 224 | return $permissions; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - if ( ! $permissions ) { |
|
| 228 | - return new WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 227 | + if ( ! $permissions) { |
|
| 228 | + return new WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | return true; |
@@ -238,26 +238,26 @@ discard block |
||
| 238 | 238 | * @param string $context Request context. |
| 239 | 239 | * @return bool|WP_Error |
| 240 | 240 | */ |
| 241 | - protected function check_permissions( $request, $context = 'read' ) { |
|
| 241 | + protected function check_permissions($request, $context = 'read') { |
|
| 242 | 242 | // Get taxonomy. |
| 243 | - $taxonomy = $this->get_taxonomy( $request ); |
|
| 244 | - if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) { |
|
| 245 | - return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Taxonomy does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 243 | + $taxonomy = $this->get_taxonomy($request); |
|
| 244 | + if ( ! $taxonomy || ! taxonomy_exists($taxonomy)) { |
|
| 245 | + return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Taxonomy does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // Check permissions for a single term. |
| 249 | - $id = intval( $request['id'] ); |
|
| 250 | - if ( $id ) { |
|
| 251 | - $term = get_term( $id, $taxonomy ); |
|
| 249 | + $id = intval($request['id']); |
|
| 250 | + if ($id) { |
|
| 251 | + $term = get_term($id, $taxonomy); |
|
| 252 | 252 | |
| 253 | - if ( is_wp_error( $term ) || ! $term || $term->taxonomy !== $taxonomy ) { |
|
| 254 | - return new WP_Error( 'woocommerce_rest_term_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 253 | + if (is_wp_error($term) || ! $term || $term->taxonomy !== $taxonomy) { |
|
| 254 | + return new WP_Error('woocommerce_rest_term_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - return wc_rest_check_product_term_permissions( $taxonomy, $context, $term->term_id ); |
|
| 257 | + return wc_rest_check_product_term_permissions($taxonomy, $context, $term->term_id); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - return wc_rest_check_product_term_permissions( $taxonomy, $context ); |
|
| 260 | + return wc_rest_check_product_term_permissions($taxonomy, $context); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -266,8 +266,8 @@ discard block |
||
| 266 | 266 | * @param WP_REST_Request $request Full details about the request. |
| 267 | 267 | * @return WP_REST_Response|WP_Error |
| 268 | 268 | */ |
| 269 | - public function get_items( $request ) { |
|
| 270 | - $taxonomy = $this->get_taxonomy( $request ); |
|
| 269 | + public function get_items($request) { |
|
| 270 | + $taxonomy = $this->get_taxonomy($request); |
|
| 271 | 271 | $prepared_args = array( |
| 272 | 272 | 'exclude' => $request['exclude'], |
| 273 | 273 | 'include' => $request['include'], |
@@ -280,20 +280,20 @@ discard block |
||
| 280 | 280 | 'slug' => $request['slug'], |
| 281 | 281 | ); |
| 282 | 282 | |
| 283 | - if ( ! empty( $request['offset'] ) ) { |
|
| 283 | + if ( ! empty($request['offset'])) { |
|
| 284 | 284 | $prepared_args['offset'] = $request['offset']; |
| 285 | 285 | } else { |
| 286 | - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; |
|
| 286 | + $prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number']; |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - $taxonomy_obj = get_taxonomy( $taxonomy ); |
|
| 289 | + $taxonomy_obj = get_taxonomy($taxonomy); |
|
| 290 | 290 | |
| 291 | - if ( $taxonomy_obj->hierarchical && isset( $request['parent'] ) ) { |
|
| 292 | - if ( 0 === $request['parent'] ) { |
|
| 291 | + if ($taxonomy_obj->hierarchical && isset($request['parent'])) { |
|
| 292 | + if (0 === $request['parent']) { |
|
| 293 | 293 | // Only query top-level terms. |
| 294 | 294 | $prepared_args['parent'] = 0; |
| 295 | 295 | } else { |
| 296 | - if ( $request['parent'] ) { |
|
| 296 | + if ($request['parent']) { |
|
| 297 | 297 | $prepared_args['parent'] = $request['parent']; |
| 298 | 298 | } |
| 299 | 299 | } |
@@ -311,60 +311,60 @@ discard block |
||
| 311 | 311 | * passed to get_terms. |
| 312 | 312 | * @param WP_REST_Request $request The current request. |
| 313 | 313 | */ |
| 314 | - $prepared_args = apply_filters( "woocommerce_rest_{$taxonomy}_query", $prepared_args, $request ); |
|
| 314 | + $prepared_args = apply_filters("woocommerce_rest_{$taxonomy}_query", $prepared_args, $request); |
|
| 315 | 315 | |
| 316 | - if ( ! empty( $prepared_args['product'] ) ) { |
|
| 317 | - $query_result = $this->get_terms_for_product( $prepared_args, $request ); |
|
| 316 | + if ( ! empty($prepared_args['product'])) { |
|
| 317 | + $query_result = $this->get_terms_for_product($prepared_args, $request); |
|
| 318 | 318 | $total_terms = $this->total_terms; |
| 319 | 319 | } else { |
| 320 | - $query_result = get_terms( $taxonomy, $prepared_args ); |
|
| 320 | + $query_result = get_terms($taxonomy, $prepared_args); |
|
| 321 | 321 | |
| 322 | 322 | $count_args = $prepared_args; |
| 323 | - unset( $count_args['number'] ); |
|
| 324 | - unset( $count_args['offset'] ); |
|
| 325 | - $total_terms = wp_count_terms( $taxonomy, $count_args ); |
|
| 323 | + unset($count_args['number']); |
|
| 324 | + unset($count_args['offset']); |
|
| 325 | + $total_terms = wp_count_terms($taxonomy, $count_args); |
|
| 326 | 326 | |
| 327 | 327 | // Ensure we don't return results when offset is out of bounds. |
| 328 | 328 | // See https://core.trac.wordpress.org/ticket/35935. |
| 329 | - if ( $prepared_args['offset'] && $prepared_args['offset'] >= $total_terms ) { |
|
| 329 | + if ($prepared_args['offset'] && $prepared_args['offset'] >= $total_terms) { |
|
| 330 | 330 | $query_result = array(); |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | // wp_count_terms can return a falsy value when the term has no children. |
| 334 | - if ( ! $total_terms ) { |
|
| 334 | + if ( ! $total_terms) { |
|
| 335 | 335 | $total_terms = 0; |
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | $response = array(); |
| 339 | - foreach ( $query_result as $term ) { |
|
| 340 | - $data = $this->prepare_item_for_response( $term, $request ); |
|
| 341 | - $response[] = $this->prepare_response_for_collection( $data ); |
|
| 339 | + foreach ($query_result as $term) { |
|
| 340 | + $data = $this->prepare_item_for_response($term, $request); |
|
| 341 | + $response[] = $this->prepare_response_for_collection($data); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - $response = rest_ensure_response( $response ); |
|
| 344 | + $response = rest_ensure_response($response); |
|
| 345 | 345 | |
| 346 | 346 | // Store pagination values for headers then unset for count query. |
| 347 | 347 | $per_page = (int) $prepared_args['number']; |
| 348 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
| 348 | + $page = ceil((((int) $prepared_args['offset']) / $per_page) + 1); |
|
| 349 | 349 | |
| 350 | - $response->header( 'X-WP-Total', (int) $total_terms ); |
|
| 351 | - $max_pages = ceil( $total_terms / $per_page ); |
|
| 352 | - $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
| 350 | + $response->header('X-WP-Total', (int) $total_terms); |
|
| 351 | + $max_pages = ceil($total_terms / $per_page); |
|
| 352 | + $response->header('X-WP-TotalPages', (int) $max_pages); |
|
| 353 | 353 | |
| 354 | - $base = str_replace( '(?P<attribute_id>[\d]+)', $request['attribute_id'], $this->rest_base ); |
|
| 355 | - $base = add_query_arg( $request->get_query_params(), rest_url( '/' . $this->namespace . '/' . $base ) ); |
|
| 356 | - if ( $page > 1 ) { |
|
| 354 | + $base = str_replace('(?P<attribute_id>[\d]+)', $request['attribute_id'], $this->rest_base); |
|
| 355 | + $base = add_query_arg($request->get_query_params(), rest_url('/' . $this->namespace . '/' . $base)); |
|
| 356 | + if ($page > 1) { |
|
| 357 | 357 | $prev_page = $page - 1; |
| 358 | - if ( $prev_page > $max_pages ) { |
|
| 358 | + if ($prev_page > $max_pages) { |
|
| 359 | 359 | $prev_page = $max_pages; |
| 360 | 360 | } |
| 361 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 362 | - $response->link_header( 'prev', $prev_link ); |
|
| 361 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 362 | + $response->link_header('prev', $prev_link); |
|
| 363 | 363 | } |
| 364 | - if ( $max_pages > $page ) { |
|
| 364 | + if ($max_pages > $page) { |
|
| 365 | 365 | $next_page = $page + 1; |
| 366 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 367 | - $response->link_header( 'next', $next_link ); |
|
| 366 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 367 | + $response->link_header('next', $next_link); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | return $response; |
@@ -376,47 +376,47 @@ discard block |
||
| 376 | 376 | * @param WP_REST_Request $request Full details about the request. |
| 377 | 377 | * @return WP_REST_Request|WP_Error |
| 378 | 378 | */ |
| 379 | - public function create_item( $request ) { |
|
| 380 | - $taxonomy = $this->get_taxonomy( $request ); |
|
| 379 | + public function create_item($request) { |
|
| 380 | + $taxonomy = $this->get_taxonomy($request); |
|
| 381 | 381 | $name = $request['name']; |
| 382 | 382 | $args = array(); |
| 383 | 383 | $schema = $this->get_item_schema(); |
| 384 | 384 | |
| 385 | - if ( ! empty( $schema['properties']['description'] ) && isset( $request['description'] ) ) { |
|
| 385 | + if ( ! empty($schema['properties']['description']) && isset($request['description'])) { |
|
| 386 | 386 | $args['description'] = $request['description']; |
| 387 | 387 | } |
| 388 | - if ( isset( $request['slug'] ) ) { |
|
| 388 | + if (isset($request['slug'])) { |
|
| 389 | 389 | $args['slug'] = $request['slug']; |
| 390 | 390 | } |
| 391 | - if ( isset( $request['parent'] ) ) { |
|
| 392 | - if ( ! is_taxonomy_hierarchical( $taxonomy ) ) { |
|
| 393 | - return new WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 391 | + if (isset($request['parent'])) { |
|
| 392 | + if ( ! is_taxonomy_hierarchical($taxonomy)) { |
|
| 393 | + return new WP_Error('woocommerce_rest_taxonomy_not_hierarchical', __('Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce'), array('status' => 400)); |
|
| 394 | 394 | } |
| 395 | 395 | $args['parent'] = $request['parent']; |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | - $term = wp_insert_term( $name, $taxonomy, $args ); |
|
| 399 | - if ( is_wp_error( $term ) ) { |
|
| 400 | - $error_data = array( 'status' => 400 ); |
|
| 398 | + $term = wp_insert_term($name, $taxonomy, $args); |
|
| 399 | + if (is_wp_error($term)) { |
|
| 400 | + $error_data = array('status' => 400); |
|
| 401 | 401 | |
| 402 | 402 | // If we're going to inform the client that the term exists, |
| 403 | 403 | // give them the identifier they can actually use. |
| 404 | - $term_id = $term->get_error_data( 'term_exists' ); |
|
| 405 | - if ( $term_id ) { |
|
| 404 | + $term_id = $term->get_error_data('term_exists'); |
|
| 405 | + if ($term_id) { |
|
| 406 | 406 | $error_data['resource_id'] = $term_id; |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - return new WP_Error( $term->get_error_code(), $term->get_error_message(), $error_data ); |
|
| 409 | + return new WP_Error($term->get_error_code(), $term->get_error_message(), $error_data); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - $term = get_term( $term['term_id'], $taxonomy ); |
|
| 412 | + $term = get_term($term['term_id'], $taxonomy); |
|
| 413 | 413 | |
| 414 | - $this->update_additional_fields_for_object( $term, $request ); |
|
| 414 | + $this->update_additional_fields_for_object($term, $request); |
|
| 415 | 415 | |
| 416 | 416 | // Add term data. |
| 417 | - $meta_fields = $this->update_term_meta_fields( $term, $request ); |
|
| 418 | - if ( is_wp_error( $meta_fields ) ) { |
|
| 419 | - wp_delete_term( $term->term_id, $taxonomy ); |
|
| 417 | + $meta_fields = $this->update_term_meta_fields($term, $request); |
|
| 418 | + if (is_wp_error($meta_fields)) { |
|
| 419 | + wp_delete_term($term->term_id, $taxonomy); |
|
| 420 | 420 | |
| 421 | 421 | return $meta_fields; |
| 422 | 422 | } |
@@ -428,19 +428,19 @@ discard block |
||
| 428 | 428 | * @param WP_REST_Request $request Request object. |
| 429 | 429 | * @param boolean $creating True when creating term, false when updating. |
| 430 | 430 | */ |
| 431 | - do_action( "woocommerce_rest_insert_{$taxonomy}", $term, $request, true ); |
|
| 431 | + do_action("woocommerce_rest_insert_{$taxonomy}", $term, $request, true); |
|
| 432 | 432 | |
| 433 | - $request->set_param( 'context', 'edit' ); |
|
| 434 | - $response = $this->prepare_item_for_response( $term, $request ); |
|
| 435 | - $response = rest_ensure_response( $response ); |
|
| 436 | - $response->set_status( 201 ); |
|
| 433 | + $request->set_param('context', 'edit'); |
|
| 434 | + $response = $this->prepare_item_for_response($term, $request); |
|
| 435 | + $response = rest_ensure_response($response); |
|
| 436 | + $response->set_status(201); |
|
| 437 | 437 | |
| 438 | 438 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
| 439 | - if ( ! empty( $request['attribute_id'] ) ) { |
|
| 440 | - $base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base ); |
|
| 439 | + if ( ! empty($request['attribute_id'])) { |
|
| 440 | + $base = str_replace('(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base); |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | - $response->header( 'Location', rest_url( $base . '/' . $term->term_id ) ); |
|
| 443 | + $response->header('Location', rest_url($base . '/' . $term->term_id)); |
|
| 444 | 444 | |
| 445 | 445 | return $response; |
| 446 | 446 | } |
@@ -451,17 +451,17 @@ discard block |
||
| 451 | 451 | * @param WP_REST_Request $request Full details about the request. |
| 452 | 452 | * @return WP_REST_Request|WP_Error |
| 453 | 453 | */ |
| 454 | - public function get_item( $request ) { |
|
| 455 | - $taxonomy = $this->get_taxonomy( $request ); |
|
| 456 | - $term = get_term( (int) $request['id'], $taxonomy ); |
|
| 454 | + public function get_item($request) { |
|
| 455 | + $taxonomy = $this->get_taxonomy($request); |
|
| 456 | + $term = get_term((int) $request['id'], $taxonomy); |
|
| 457 | 457 | |
| 458 | - if ( is_wp_error( $term ) ) { |
|
| 458 | + if (is_wp_error($term)) { |
|
| 459 | 459 | return $term; |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | - $response = $this->prepare_item_for_response( $term, $request ); |
|
| 462 | + $response = $this->prepare_item_for_response($term, $request); |
|
| 463 | 463 | |
| 464 | - return rest_ensure_response( $response ); |
|
| 464 | + return rest_ensure_response($response); |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -470,43 +470,43 @@ discard block |
||
| 470 | 470 | * @param WP_REST_Request $request Full details about the request. |
| 471 | 471 | * @return WP_REST_Request|WP_Error |
| 472 | 472 | */ |
| 473 | - public function update_item( $request ) { |
|
| 474 | - $taxonomy = $this->get_taxonomy( $request ); |
|
| 475 | - $term = get_term( (int) $request['id'], $taxonomy ); |
|
| 473 | + public function update_item($request) { |
|
| 474 | + $taxonomy = $this->get_taxonomy($request); |
|
| 475 | + $term = get_term((int) $request['id'], $taxonomy); |
|
| 476 | 476 | $schema = $this->get_item_schema(); |
| 477 | 477 | $prepared_args = array(); |
| 478 | 478 | |
| 479 | - if ( isset( $request['name'] ) ) { |
|
| 479 | + if (isset($request['name'])) { |
|
| 480 | 480 | $prepared_args['name'] = $request['name']; |
| 481 | 481 | } |
| 482 | - if ( ! empty( $schema['properties']['description'] ) && isset( $request['description'] ) ) { |
|
| 482 | + if ( ! empty($schema['properties']['description']) && isset($request['description'])) { |
|
| 483 | 483 | $prepared_args['description'] = $request['description']; |
| 484 | 484 | } |
| 485 | - if ( isset( $request['slug'] ) ) { |
|
| 485 | + if (isset($request['slug'])) { |
|
| 486 | 486 | $prepared_args['slug'] = $request['slug']; |
| 487 | 487 | } |
| 488 | - if ( isset( $request['parent'] ) ) { |
|
| 489 | - if ( ! is_taxonomy_hierarchical( $taxonomy ) ) { |
|
| 490 | - return new WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 488 | + if (isset($request['parent'])) { |
|
| 489 | + if ( ! is_taxonomy_hierarchical($taxonomy)) { |
|
| 490 | + return new WP_Error('woocommerce_rest_taxonomy_not_hierarchical', __('Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce'), array('status' => 400)); |
|
| 491 | 491 | } |
| 492 | 492 | $prepared_args['parent'] = $request['parent']; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | // Only update the term if we haz something to update. |
| 496 | - if ( ! empty( $prepared_args ) ) { |
|
| 497 | - $update = wp_update_term( $term->term_id, $term->taxonomy, $prepared_args ); |
|
| 498 | - if ( is_wp_error( $update ) ) { |
|
| 496 | + if ( ! empty($prepared_args)) { |
|
| 497 | + $update = wp_update_term($term->term_id, $term->taxonomy, $prepared_args); |
|
| 498 | + if (is_wp_error($update)) { |
|
| 499 | 499 | return $update; |
| 500 | 500 | } |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | - $term = get_term( (int) $request['id'], $taxonomy ); |
|
| 503 | + $term = get_term((int) $request['id'], $taxonomy); |
|
| 504 | 504 | |
| 505 | - $this->update_additional_fields_for_object( $term, $request ); |
|
| 505 | + $this->update_additional_fields_for_object($term, $request); |
|
| 506 | 506 | |
| 507 | 507 | // Update term data. |
| 508 | - $meta_fields = $this->update_term_meta_fields( $term, $request ); |
|
| 509 | - if ( is_wp_error( $meta_fields ) ) { |
|
| 508 | + $meta_fields = $this->update_term_meta_fields($term, $request); |
|
| 509 | + if (is_wp_error($meta_fields)) { |
|
| 510 | 510 | return $meta_fields; |
| 511 | 511 | } |
| 512 | 512 | |
@@ -517,11 +517,11 @@ discard block |
||
| 517 | 517 | * @param WP_REST_Request $request Request object. |
| 518 | 518 | * @param boolean $creating True when creating term, false when updating. |
| 519 | 519 | */ |
| 520 | - do_action( "woocommerce_rest_insert_{$taxonomy}", $term, $request, false ); |
|
| 520 | + do_action("woocommerce_rest_insert_{$taxonomy}", $term, $request, false); |
|
| 521 | 521 | |
| 522 | - $request->set_param( 'context', 'edit' ); |
|
| 523 | - $response = $this->prepare_item_for_response( $term, $request ); |
|
| 524 | - return rest_ensure_response( $response ); |
|
| 522 | + $request->set_param('context', 'edit'); |
|
| 523 | + $response = $this->prepare_item_for_response($term, $request); |
|
| 524 | + return rest_ensure_response($response); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | /** |
@@ -530,30 +530,30 @@ discard block |
||
| 530 | 530 | * @param WP_REST_Request $request Full details about the request. |
| 531 | 531 | * @return WP_REST_Response|WP_Error |
| 532 | 532 | */ |
| 533 | - public function delete_item( $request ) { |
|
| 534 | - $taxonomy = $this->get_taxonomy( $request ); |
|
| 535 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 533 | + public function delete_item($request) { |
|
| 534 | + $taxonomy = $this->get_taxonomy($request); |
|
| 535 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
| 536 | 536 | |
| 537 | 537 | // We don't support trashing for this type, error out. |
| 538 | - if ( ! $force ) { |
|
| 539 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Resource does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
| 538 | + if ( ! $force) { |
|
| 539 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Resource does not support trashing.', 'woocommerce'), array('status' => 501)); |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | - $term = get_term( (int) $request['id'], $taxonomy ); |
|
| 542 | + $term = get_term((int) $request['id'], $taxonomy); |
|
| 543 | 543 | // Get default category id. |
| 544 | - $default_category_id = absint( get_option( 'default_product_cat', 0 ) ); |
|
| 544 | + $default_category_id = absint(get_option('default_product_cat', 0)); |
|
| 545 | 545 | |
| 546 | 546 | // Prevent deleting the default product category. |
| 547 | - if ( $default_category_id === (int) $request['id'] ) { |
|
| 548 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Default product category cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 547 | + if ($default_category_id === (int) $request['id']) { |
|
| 548 | + return new WP_Error('woocommerce_rest_cannot_delete', __('Default product category cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | - $request->set_param( 'context', 'edit' ); |
|
| 552 | - $response = $this->prepare_item_for_response( $term, $request ); |
|
| 551 | + $request->set_param('context', 'edit'); |
|
| 552 | + $response = $this->prepare_item_for_response($term, $request); |
|
| 553 | 553 | |
| 554 | - $retval = wp_delete_term( $term->term_id, $term->taxonomy ); |
|
| 555 | - if ( ! $retval ) { |
|
| 556 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 554 | + $retval = wp_delete_term($term->term_id, $term->taxonomy); |
|
| 555 | + if ( ! $retval) { |
|
| 556 | + return new WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | /** |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | * @param WP_REST_Response $response The response data. |
| 564 | 564 | * @param WP_REST_Request $request The request sent to the API. |
| 565 | 565 | */ |
| 566 | - do_action( "woocommerce_rest_delete_{$taxonomy}", $term, $response, $request ); |
|
| 566 | + do_action("woocommerce_rest_delete_{$taxonomy}", $term, $response, $request); |
|
| 567 | 567 | |
| 568 | 568 | return $response; |
| 569 | 569 | } |
@@ -575,27 +575,27 @@ discard block |
||
| 575 | 575 | * @param WP_REST_Request $request Full details about the request. |
| 576 | 576 | * @return array Links for the given term. |
| 577 | 577 | */ |
| 578 | - protected function prepare_links( $term, $request ) { |
|
| 578 | + protected function prepare_links($term, $request) { |
|
| 579 | 579 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
| 580 | 580 | |
| 581 | - if ( ! empty( $request['attribute_id'] ) ) { |
|
| 582 | - $base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base ); |
|
| 581 | + if ( ! empty($request['attribute_id'])) { |
|
| 582 | + $base = str_replace('(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | $links = array( |
| 586 | 586 | 'self' => array( |
| 587 | - 'href' => rest_url( trailingslashit( $base ) . $term->term_id ), |
|
| 587 | + 'href' => rest_url(trailingslashit($base) . $term->term_id), |
|
| 588 | 588 | ), |
| 589 | 589 | 'collection' => array( |
| 590 | - 'href' => rest_url( $base ), |
|
| 590 | + 'href' => rest_url($base), |
|
| 591 | 591 | ), |
| 592 | 592 | ); |
| 593 | 593 | |
| 594 | - if ( $term->parent ) { |
|
| 595 | - $parent_term = get_term( (int) $term->parent, $term->taxonomy ); |
|
| 596 | - if ( $parent_term ) { |
|
| 594 | + if ($term->parent) { |
|
| 595 | + $parent_term = get_term((int) $term->parent, $term->taxonomy); |
|
| 596 | + if ($parent_term) { |
|
| 597 | 597 | $links['up'] = array( |
| 598 | - 'href' => rest_url( trailingslashit( $base ) . $parent_term->term_id ), |
|
| 598 | + 'href' => rest_url(trailingslashit($base) . $parent_term->term_id), |
|
| 599 | 599 | ); |
| 600 | 600 | } |
| 601 | 601 | } |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | * @param WP_REST_Request $request Full details about the request. |
| 611 | 611 | * @return bool|WP_Error |
| 612 | 612 | */ |
| 613 | - protected function update_term_meta_fields( $term, $request ) { |
|
| 613 | + protected function update_term_meta_fields($term, $request) { |
|
| 614 | 614 | return true; |
| 615 | 615 | } |
| 616 | 616 | |
@@ -626,19 +626,19 @@ discard block |
||
| 626 | 626 | * @param WP_REST_Request $request Full details about the request. |
| 627 | 627 | * @return array List of term objects. (Total count in `$this->total_terms`). |
| 628 | 628 | */ |
| 629 | - protected function get_terms_for_product( $prepared_args, $request ) { |
|
| 630 | - $taxonomy = $this->get_taxonomy( $request ); |
|
| 629 | + protected function get_terms_for_product($prepared_args, $request) { |
|
| 630 | + $taxonomy = $this->get_taxonomy($request); |
|
| 631 | 631 | |
| 632 | - $query_result = get_the_terms( $prepared_args['product'], $taxonomy ); |
|
| 633 | - if ( empty( $query_result ) ) { |
|
| 632 | + $query_result = get_the_terms($prepared_args['product'], $taxonomy); |
|
| 633 | + if (empty($query_result)) { |
|
| 634 | 634 | $this->total_terms = 0; |
| 635 | 635 | return array(); |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | // get_items() verifies that we don't have `include` set, and default. |
| 639 | 639 | // ordering is by `name`. |
| 640 | - if ( ! in_array( $prepared_args['orderby'], array( 'name', 'none', 'include' ), true ) ) { |
|
| 641 | - switch ( $prepared_args['orderby'] ) { |
|
| 640 | + if ( ! in_array($prepared_args['orderby'], array('name', 'none', 'include'), true)) { |
|
| 641 | + switch ($prepared_args['orderby']) { |
|
| 642 | 642 | case 'id': |
| 643 | 643 | $this->sort_column = 'term_id'; |
| 644 | 644 | break; |
@@ -649,15 +649,15 @@ discard block |
||
| 649 | 649 | $this->sort_column = $prepared_args['orderby']; |
| 650 | 650 | break; |
| 651 | 651 | } |
| 652 | - usort( $query_result, array( $this, 'compare_terms' ) ); |
|
| 652 | + usort($query_result, array($this, 'compare_terms')); |
|
| 653 | 653 | } |
| 654 | - if ( strtolower( $prepared_args['order'] ) !== 'asc' ) { |
|
| 655 | - $query_result = array_reverse( $query_result ); |
|
| 654 | + if (strtolower($prepared_args['order']) !== 'asc') { |
|
| 655 | + $query_result = array_reverse($query_result); |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | // Pagination. |
| 659 | - $this->total_terms = count( $query_result ); |
|
| 660 | - $query_result = array_slice( $query_result, $prepared_args['offset'], $prepared_args['number'] ); |
|
| 659 | + $this->total_terms = count($query_result); |
|
| 660 | + $query_result = array_slice($query_result, $prepared_args['offset'], $prepared_args['number']); |
|
| 661 | 661 | |
| 662 | 662 | return $query_result; |
| 663 | 663 | } |
@@ -671,16 +671,16 @@ discard block |
||
| 671 | 671 | * @param stdClass $right Term object. |
| 672 | 672 | * @return int <0 if left is higher "priority" than right, 0 if equal, >0 if right is higher "priority" than left. |
| 673 | 673 | */ |
| 674 | - protected function compare_terms( $left, $right ) { |
|
| 674 | + protected function compare_terms($left, $right) { |
|
| 675 | 675 | $col = $this->sort_column; |
| 676 | 676 | $left_val = $left->$col; |
| 677 | 677 | $right_val = $right->$col; |
| 678 | 678 | |
| 679 | - if ( is_int( $left_val ) && is_int( $right_val ) ) { |
|
| 679 | + if (is_int($left_val) && is_int($right_val)) { |
|
| 680 | 680 | return $left_val - $right_val; |
| 681 | 681 | } |
| 682 | 682 | |
| 683 | - return strcmp( $left_val, $right_val ); |
|
| 683 | + return strcmp($left_val, $right_val); |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | /** |
@@ -691,8 +691,8 @@ discard block |
||
| 691 | 691 | public function get_collection_params() { |
| 692 | 692 | $params = parent::get_collection_params(); |
| 693 | 693 | |
| 694 | - if ( '' !== $this->taxonomy && taxonomy_exists( $this->taxonomy ) ) { |
|
| 695 | - $taxonomy = get_taxonomy( $this->taxonomy ); |
|
| 694 | + if ('' !== $this->taxonomy && taxonomy_exists($this->taxonomy)) { |
|
| 695 | + $taxonomy = get_taxonomy($this->taxonomy); |
|
| 696 | 696 | } else { |
| 697 | 697 | $taxonomy = new stdClass(); |
| 698 | 698 | $taxonomy->hierarchical = true; |
@@ -701,7 +701,7 @@ discard block |
||
| 701 | 701 | $params['context']['default'] = 'view'; |
| 702 | 702 | |
| 703 | 703 | $params['exclude'] = array( |
| 704 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
|
| 704 | + 'description' => __('Ensure result set excludes specific IDs.', 'woocommerce'), |
|
| 705 | 705 | 'type' => 'array', |
| 706 | 706 | 'items' => array( |
| 707 | 707 | 'type' => 'integer', |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | 'sanitize_callback' => 'wp_parse_id_list', |
| 711 | 711 | ); |
| 712 | 712 | $params['include'] = array( |
| 713 | - 'description' => __( 'Limit result set to specific ids.', 'woocommerce' ), |
|
| 713 | + 'description' => __('Limit result set to specific ids.', 'woocommerce'), |
|
| 714 | 714 | 'type' => 'array', |
| 715 | 715 | 'items' => array( |
| 716 | 716 | 'type' => 'integer', |
@@ -718,16 +718,16 @@ discard block |
||
| 718 | 718 | 'default' => array(), |
| 719 | 719 | 'sanitize_callback' => 'wp_parse_id_list', |
| 720 | 720 | ); |
| 721 | - if ( ! $taxonomy->hierarchical ) { |
|
| 721 | + if ( ! $taxonomy->hierarchical) { |
|
| 722 | 722 | $params['offset'] = array( |
| 723 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
| 723 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
| 724 | 724 | 'type' => 'integer', |
| 725 | 725 | 'sanitize_callback' => 'absint', |
| 726 | 726 | 'validate_callback' => 'rest_validate_request_arg', |
| 727 | 727 | ); |
| 728 | 728 | } |
| 729 | - $params['order'] = array( |
|
| 730 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 729 | + $params['order'] = array( |
|
| 730 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 731 | 731 | 'type' => 'string', |
| 732 | 732 | 'sanitize_callback' => 'sanitize_key', |
| 733 | 733 | 'default' => 'asc', |
@@ -737,8 +737,8 @@ discard block |
||
| 737 | 737 | ), |
| 738 | 738 | 'validate_callback' => 'rest_validate_request_arg', |
| 739 | 739 | ); |
| 740 | - $params['orderby'] = array( |
|
| 741 | - 'description' => __( 'Sort collection by resource attribute.', 'woocommerce' ), |
|
| 740 | + $params['orderby'] = array( |
|
| 741 | + 'description' => __('Sort collection by resource attribute.', 'woocommerce'), |
|
| 742 | 742 | 'type' => 'string', |
| 743 | 743 | 'sanitize_callback' => 'sanitize_key', |
| 744 | 744 | 'default' => 'name', |
@@ -754,27 +754,27 @@ discard block |
||
| 754 | 754 | 'validate_callback' => 'rest_validate_request_arg', |
| 755 | 755 | ); |
| 756 | 756 | $params['hide_empty'] = array( |
| 757 | - 'description' => __( 'Whether to hide resources not assigned to any products.', 'woocommerce' ), |
|
| 757 | + 'description' => __('Whether to hide resources not assigned to any products.', 'woocommerce'), |
|
| 758 | 758 | 'type' => 'boolean', |
| 759 | 759 | 'default' => false, |
| 760 | 760 | 'validate_callback' => 'rest_validate_request_arg', |
| 761 | 761 | ); |
| 762 | - if ( $taxonomy->hierarchical ) { |
|
| 762 | + if ($taxonomy->hierarchical) { |
|
| 763 | 763 | $params['parent'] = array( |
| 764 | - 'description' => __( 'Limit result set to resources assigned to a specific parent.', 'woocommerce' ), |
|
| 764 | + 'description' => __('Limit result set to resources assigned to a specific parent.', 'woocommerce'), |
|
| 765 | 765 | 'type' => 'integer', |
| 766 | 766 | 'sanitize_callback' => 'absint', |
| 767 | 767 | 'validate_callback' => 'rest_validate_request_arg', |
| 768 | 768 | ); |
| 769 | 769 | } |
| 770 | 770 | $params['product'] = array( |
| 771 | - 'description' => __( 'Limit result set to resources assigned to a specific product.', 'woocommerce' ), |
|
| 771 | + 'description' => __('Limit result set to resources assigned to a specific product.', 'woocommerce'), |
|
| 772 | 772 | 'type' => 'integer', |
| 773 | 773 | 'default' => null, |
| 774 | 774 | 'validate_callback' => 'rest_validate_request_arg', |
| 775 | 775 | ); |
| 776 | - $params['slug'] = array( |
|
| 777 | - 'description' => __( 'Limit result set to resources with a specific slug.', 'woocommerce' ), |
|
| 776 | + $params['slug'] = array( |
|
| 777 | + 'description' => __('Limit result set to resources with a specific slug.', 'woocommerce'), |
|
| 778 | 778 | 'type' => 'string', |
| 779 | 779 | 'validate_callback' => 'rest_validate_request_arg', |
| 780 | 780 | ); |
@@ -788,15 +788,15 @@ discard block |
||
| 788 | 788 | * @param WP_REST_Request $request Full details about the request. |
| 789 | 789 | * @return int|WP_Error |
| 790 | 790 | */ |
| 791 | - protected function get_taxonomy( $request ) { |
|
| 791 | + protected function get_taxonomy($request) { |
|
| 792 | 792 | // Check if taxonomy is defined. |
| 793 | 793 | // Prevents check for attribute taxonomy more than one time for each query. |
| 794 | - if ( '' !== $this->taxonomy ) { |
|
| 794 | + if ('' !== $this->taxonomy) { |
|
| 795 | 795 | return $this->taxonomy; |
| 796 | 796 | } |
| 797 | 797 | |
| 798 | - if ( ! empty( $request['attribute_id'] ) ) { |
|
| 799 | - $taxonomy = wc_attribute_taxonomy_name_by_id( (int) $request['attribute_id'] ); |
|
| 798 | + if ( ! empty($request['attribute_id'])) { |
|
| 799 | + $taxonomy = wc_attribute_taxonomy_name_by_id((int) $request['attribute_id']); |
|
| 800 | 800 | |
| 801 | 801 | $this->taxonomy = $taxonomy; |
| 802 | 802 | } |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | * @since 2.6.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * REST API Product Tags controller class. |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | * @since 2.6.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * REST API Product Attributes controller class. |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @since 3.5.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * REST API Product Reviews Controller Class. |
@@ -40,40 +40,40 @@ discard block |
||
| 40 | 40 | $this->namespace, '/' . $this->rest_base, array( |
| 41 | 41 | array( |
| 42 | 42 | 'methods' => WP_REST_Server::READABLE, |
| 43 | - 'callback' => array( $this, 'get_items' ), |
|
| 44 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 43 | + 'callback' => array($this, 'get_items'), |
|
| 44 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 45 | 45 | 'args' => $this->get_collection_params(), |
| 46 | 46 | ), |
| 47 | 47 | array( |
| 48 | 48 | 'methods' => WP_REST_Server::CREATABLE, |
| 49 | - 'callback' => array( $this, 'create_item' ), |
|
| 50 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
| 49 | + 'callback' => array($this, 'create_item'), |
|
| 50 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
| 51 | 51 | 'args' => array_merge( |
| 52 | - $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
| 52 | + $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
| 53 | 53 | 'product_id' => array( |
| 54 | 54 | 'required' => true, |
| 55 | - 'description' => __( 'Unique identifier for the product.', 'woocommerce' ), |
|
| 55 | + 'description' => __('Unique identifier for the product.', 'woocommerce'), |
|
| 56 | 56 | 'type' => 'integer', |
| 57 | 57 | ), |
| 58 | 58 | 'review' => array( |
| 59 | 59 | 'required' => true, |
| 60 | 60 | 'type' => 'string', |
| 61 | - 'description' => __( 'Review content.', 'woocommerce' ), |
|
| 61 | + 'description' => __('Review content.', 'woocommerce'), |
|
| 62 | 62 | ), |
| 63 | 63 | 'reviewer' => array( |
| 64 | 64 | 'required' => true, |
| 65 | 65 | 'type' => 'string', |
| 66 | - 'description' => __( 'Name of the reviewer.', 'woocommerce' ), |
|
| 66 | + 'description' => __('Name of the reviewer.', 'woocommerce'), |
|
| 67 | 67 | ), |
| 68 | 68 | 'reviewer_email' => array( |
| 69 | 69 | 'required' => true, |
| 70 | 70 | 'type' => 'string', |
| 71 | - 'description' => __( 'Email of the reviewer.', 'woocommerce' ), |
|
| 71 | + 'description' => __('Email of the reviewer.', 'woocommerce'), |
|
| 72 | 72 | ), |
| 73 | 73 | ) |
| 74 | 74 | ), |
| 75 | 75 | ), |
| 76 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 76 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 77 | 77 | ) |
| 78 | 78 | ); |
| 79 | 79 | |
@@ -81,37 +81,37 @@ discard block |
||
| 81 | 81 | $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
| 82 | 82 | 'args' => array( |
| 83 | 83 | 'id' => array( |
| 84 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 84 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 85 | 85 | 'type' => 'integer', |
| 86 | 86 | ), |
| 87 | 87 | ), |
| 88 | 88 | array( |
| 89 | 89 | 'methods' => WP_REST_Server::READABLE, |
| 90 | - 'callback' => array( $this, 'get_item' ), |
|
| 91 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 90 | + 'callback' => array($this, 'get_item'), |
|
| 91 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 92 | 92 | 'args' => array( |
| 93 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 93 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 94 | 94 | ), |
| 95 | 95 | ), |
| 96 | 96 | array( |
| 97 | 97 | 'methods' => WP_REST_Server::EDITABLE, |
| 98 | - 'callback' => array( $this, 'update_item' ), |
|
| 99 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
| 100 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
| 98 | + 'callback' => array($this, 'update_item'), |
|
| 99 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
| 100 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
| 101 | 101 | ), |
| 102 | 102 | array( |
| 103 | 103 | 'methods' => WP_REST_Server::DELETABLE, |
| 104 | - 'callback' => array( $this, 'delete_item' ), |
|
| 105 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
| 104 | + 'callback' => array($this, 'delete_item'), |
|
| 105 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
| 106 | 106 | 'args' => array( |
| 107 | 107 | 'force' => array( |
| 108 | 108 | 'default' => false, |
| 109 | 109 | 'type' => 'boolean', |
| 110 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
| 110 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
| 111 | 111 | ), |
| 112 | 112 | ), |
| 113 | 113 | ), |
| 114 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 114 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 115 | 115 | ) |
| 116 | 116 | ); |
| 117 | 117 | |
@@ -119,11 +119,11 @@ discard block |
||
| 119 | 119 | $this->namespace, '/' . $this->rest_base . '/batch', array( |
| 120 | 120 | array( |
| 121 | 121 | 'methods' => WP_REST_Server::EDITABLE, |
| 122 | - 'callback' => array( $this, 'batch_items' ), |
|
| 123 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
| 124 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
| 122 | + 'callback' => array($this, 'batch_items'), |
|
| 123 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
| 124 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
| 125 | 125 | ), |
| 126 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
| 126 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
| 127 | 127 | ) |
| 128 | 128 | ); |
| 129 | 129 | } |
@@ -134,9 +134,9 @@ discard block |
||
| 134 | 134 | * @param WP_REST_Request $request Full details about the request. |
| 135 | 135 | * @return WP_Error|boolean |
| 136 | 136 | */ |
| 137 | - public function get_items_permissions_check( $request ) { |
|
| 138 | - if ( ! wc_rest_check_product_reviews_permissions( 'read' ) ) { |
|
| 139 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 137 | + public function get_items_permissions_check($request) { |
|
| 138 | + if ( ! wc_rest_check_product_reviews_permissions('read')) { |
|
| 139 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | return true; |
@@ -148,12 +148,12 @@ discard block |
||
| 148 | 148 | * @param WP_REST_Request $request Full details about the request. |
| 149 | 149 | * @return WP_Error|boolean |
| 150 | 150 | */ |
| 151 | - public function get_item_permissions_check( $request ) { |
|
| 151 | + public function get_item_permissions_check($request) { |
|
| 152 | 152 | $id = (int) $request['id']; |
| 153 | - $review = get_comment( $id ); |
|
| 153 | + $review = get_comment($id); |
|
| 154 | 154 | |
| 155 | - if ( $review && ! wc_rest_check_product_reviews_permissions( 'read', $review->comment_ID ) ) { |
|
| 156 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 155 | + if ($review && ! wc_rest_check_product_reviews_permissions('read', $review->comment_ID)) { |
|
| 156 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | return true; |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | * @param WP_REST_Request $request Full details about the request. |
| 166 | 166 | * @return WP_Error|boolean |
| 167 | 167 | */ |
| 168 | - public function create_item_permissions_check( $request ) { |
|
| 169 | - if ( ! wc_rest_check_product_reviews_permissions( 'create' ) ) { |
|
| 170 | - return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 168 | + public function create_item_permissions_check($request) { |
|
| 169 | + if ( ! wc_rest_check_product_reviews_permissions('create')) { |
|
| 170 | + return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | return true; |
@@ -179,12 +179,12 @@ discard block |
||
| 179 | 179 | * @param WP_REST_Request $request Full details about the request. |
| 180 | 180 | * @return WP_Error|boolean |
| 181 | 181 | */ |
| 182 | - public function update_item_permissions_check( $request ) { |
|
| 182 | + public function update_item_permissions_check($request) { |
|
| 183 | 183 | $id = (int) $request['id']; |
| 184 | - $review = get_comment( $id ); |
|
| 184 | + $review = get_comment($id); |
|
| 185 | 185 | |
| 186 | - if ( $review && ! wc_rest_check_product_reviews_permissions( 'edit', $review->comment_ID ) ) { |
|
| 187 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 186 | + if ($review && ! wc_rest_check_product_reviews_permissions('edit', $review->comment_ID)) { |
|
| 187 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | return true; |
@@ -196,12 +196,12 @@ discard block |
||
| 196 | 196 | * @param WP_REST_Request $request Full details about the request. |
| 197 | 197 | * @return WP_Error|boolean |
| 198 | 198 | */ |
| 199 | - public function delete_item_permissions_check( $request ) { |
|
| 199 | + public function delete_item_permissions_check($request) { |
|
| 200 | 200 | $id = (int) $request['id']; |
| 201 | - $review = get_comment( $id ); |
|
| 201 | + $review = get_comment($id); |
|
| 202 | 202 | |
| 203 | - if ( $review && ! wc_rest_check_product_reviews_permissions( 'delete', $review->comment_ID ) ) { |
|
| 204 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 203 | + if ($review && ! wc_rest_check_product_reviews_permissions('delete', $review->comment_ID)) { |
|
| 204 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | return true; |
@@ -213,9 +213,9 @@ discard block |
||
| 213 | 213 | * @param WP_REST_Request $request Full details about the request. |
| 214 | 214 | * @return boolean|WP_Error |
| 215 | 215 | */ |
| 216 | - public function batch_items_permissions_check( $request ) { |
|
| 217 | - if ( ! wc_rest_check_product_reviews_permissions( 'create' ) ) { |
|
| 218 | - return new WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 216 | + public function batch_items_permissions_check($request) { |
|
| 217 | + if ( ! wc_rest_check_product_reviews_permissions('create')) { |
|
| 218 | + return new WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | return true; |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | * @param WP_REST_Request $request Full details about the request. |
| 228 | 228 | * @return array|WP_Error |
| 229 | 229 | */ |
| 230 | - public function get_items( $request ) { |
|
| 230 | + public function get_items($request) { |
|
| 231 | 231 | // Retrieve the list of registered collection query parameters. |
| 232 | 232 | $registered = $this->get_collection_params(); |
| 233 | 233 | |
@@ -257,24 +257,24 @@ discard block |
||
| 257 | 257 | * For each known parameter which is both registered and present in the request, |
| 258 | 258 | * set the parameter's value on the query $prepared_args. |
| 259 | 259 | */ |
| 260 | - foreach ( $parameter_mappings as $api_param => $wp_param ) { |
|
| 261 | - if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) { |
|
| 262 | - $prepared_args[ $wp_param ] = $request[ $api_param ]; |
|
| 260 | + foreach ($parameter_mappings as $api_param => $wp_param) { |
|
| 261 | + if (isset($registered[$api_param], $request[$api_param])) { |
|
| 262 | + $prepared_args[$wp_param] = $request[$api_param]; |
|
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | // Ensure certain parameter values default to empty strings. |
| 267 | - foreach ( array( 'author_email', 'search' ) as $param ) { |
|
| 268 | - if ( ! isset( $prepared_args[ $param ] ) ) { |
|
| 269 | - $prepared_args[ $param ] = ''; |
|
| 267 | + foreach (array('author_email', 'search') as $param) { |
|
| 268 | + if ( ! isset($prepared_args[$param])) { |
|
| 269 | + $prepared_args[$param] = ''; |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - if ( isset( $registered['orderby'] ) ) { |
|
| 274 | - $prepared_args['orderby'] = $this->normalize_query_param( $request['orderby'] ); |
|
| 273 | + if (isset($registered['orderby'])) { |
|
| 274 | + $prepared_args['orderby'] = $this->normalize_query_param($request['orderby']); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - if ( isset( $prepared_args['status'] ) ) { |
|
| 277 | + if (isset($prepared_args['status'])) { |
|
| 278 | 278 | $prepared_args['status'] = 'approved' === $prepared_args['status'] ? 'approve' : $prepared_args['status']; |
| 279 | 279 | } |
| 280 | 280 | |
@@ -282,17 +282,17 @@ discard block |
||
| 282 | 282 | $prepared_args['date_query'] = array(); |
| 283 | 283 | |
| 284 | 284 | // Set before into date query. Date query must be specified as an array of an array. |
| 285 | - if ( isset( $registered['before'], $request['before'] ) ) { |
|
| 285 | + if (isset($registered['before'], $request['before'])) { |
|
| 286 | 286 | $prepared_args['date_query'][0]['before'] = $request['before']; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | // Set after into date query. Date query must be specified as an array of an array. |
| 290 | - if ( isset( $registered['after'], $request['after'] ) ) { |
|
| 290 | + if (isset($registered['after'], $request['after'])) { |
|
| 291 | 291 | $prepared_args['date_query'][0]['after'] = $request['after']; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - if ( isset( $registered['page'] ) && empty( $request['offset'] ) ) { |
|
| 295 | - $prepared_args['offset'] = $prepared_args['number'] * ( absint( $request['page'] ) - 1 ); |
|
| 294 | + if (isset($registered['page']) && empty($request['offset'])) { |
|
| 295 | + $prepared_args['offset'] = $prepared_args['number'] * (absint($request['page']) - 1); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -303,61 +303,61 @@ discard block |
||
| 303 | 303 | * @param array $prepared_args Array of arguments for WP_Comment_Query. |
| 304 | 304 | * @param WP_REST_Request $request The current request. |
| 305 | 305 | */ |
| 306 | - $prepared_args = apply_filters( 'woocommerce_rest_product_review_query', $prepared_args, $request ); |
|
| 306 | + $prepared_args = apply_filters('woocommerce_rest_product_review_query', $prepared_args, $request); |
|
| 307 | 307 | |
| 308 | 308 | // Make sure that returns only reviews. |
| 309 | 309 | $prepared_args['type'] = 'review'; |
| 310 | 310 | |
| 311 | 311 | // Query reviews. |
| 312 | 312 | $query = new WP_Comment_Query(); |
| 313 | - $query_result = $query->query( $prepared_args ); |
|
| 313 | + $query_result = $query->query($prepared_args); |
|
| 314 | 314 | $reviews = array(); |
| 315 | 315 | |
| 316 | - foreach ( $query_result as $review ) { |
|
| 317 | - if ( ! wc_rest_check_product_reviews_permissions( 'read', $review->comment_ID ) ) { |
|
| 316 | + foreach ($query_result as $review) { |
|
| 317 | + if ( ! wc_rest_check_product_reviews_permissions('read', $review->comment_ID)) { |
|
| 318 | 318 | continue; |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - $data = $this->prepare_item_for_response( $review, $request ); |
|
| 322 | - $reviews[] = $this->prepare_response_for_collection( $data ); |
|
| 321 | + $data = $this->prepare_item_for_response($review, $request); |
|
| 322 | + $reviews[] = $this->prepare_response_for_collection($data); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | $total_reviews = (int) $query->found_comments; |
| 326 | 326 | $max_pages = (int) $query->max_num_pages; |
| 327 | 327 | |
| 328 | - if ( $total_reviews < 1 ) { |
|
| 328 | + if ($total_reviews < 1) { |
|
| 329 | 329 | // Out-of-bounds, run the query again without LIMIT for total count. |
| 330 | - unset( $prepared_args['number'], $prepared_args['offset'] ); |
|
| 330 | + unset($prepared_args['number'], $prepared_args['offset']); |
|
| 331 | 331 | |
| 332 | 332 | $query = new WP_Comment_Query(); |
| 333 | 333 | $prepared_args['count'] = true; |
| 334 | 334 | |
| 335 | - $total_reviews = $query->query( $prepared_args ); |
|
| 336 | - $max_pages = ceil( $total_reviews / $request['per_page'] ); |
|
| 335 | + $total_reviews = $query->query($prepared_args); |
|
| 336 | + $max_pages = ceil($total_reviews / $request['per_page']); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - $response = rest_ensure_response( $reviews ); |
|
| 340 | - $response->header( 'X-WP-Total', $total_reviews ); |
|
| 341 | - $response->header( 'X-WP-TotalPages', $max_pages ); |
|
| 339 | + $response = rest_ensure_response($reviews); |
|
| 340 | + $response->header('X-WP-Total', $total_reviews); |
|
| 341 | + $response->header('X-WP-TotalPages', $max_pages); |
|
| 342 | 342 | |
| 343 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 343 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base))); |
|
| 344 | 344 | |
| 345 | - if ( $request['page'] > 1 ) { |
|
| 345 | + if ($request['page'] > 1) { |
|
| 346 | 346 | $prev_page = $request['page'] - 1; |
| 347 | 347 | |
| 348 | - if ( $prev_page > $max_pages ) { |
|
| 348 | + if ($prev_page > $max_pages) { |
|
| 349 | 349 | $prev_page = $max_pages; |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 353 | - $response->link_header( 'prev', $prev_link ); |
|
| 352 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 353 | + $response->link_header('prev', $prev_link); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | - if ( $max_pages > $request['page'] ) { |
|
| 356 | + if ($max_pages > $request['page']) { |
|
| 357 | 357 | $next_page = $request['page'] + 1; |
| 358 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 358 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 359 | 359 | |
| 360 | - $response->link_header( 'next', $next_link ); |
|
| 360 | + $response->link_header('next', $next_link); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | return $response; |
@@ -369,19 +369,19 @@ discard block |
||
| 369 | 369 | * @param WP_REST_Request $request Full details about the request. |
| 370 | 370 | * @return WP_Error|WP_REST_Response |
| 371 | 371 | */ |
| 372 | - public function create_item( $request ) { |
|
| 373 | - if ( ! empty( $request['id'] ) ) { |
|
| 374 | - return new WP_Error( 'woocommerce_rest_review_exists', __( 'Cannot create existing product review.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 372 | + public function create_item($request) { |
|
| 373 | + if ( ! empty($request['id'])) { |
|
| 374 | + return new WP_Error('woocommerce_rest_review_exists', __('Cannot create existing product review.', 'woocommerce'), array('status' => 400)); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | $product_id = (int) $request['product_id']; |
| 378 | 378 | |
| 379 | - if ( 'product' !== get_post_type( $product_id ) ) { |
|
| 380 | - return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 379 | + if ('product' !== get_post_type($product_id)) { |
|
| 380 | + return new WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404)); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - $prepared_review = $this->prepare_item_for_database( $request ); |
|
| 384 | - if ( is_wp_error( $prepared_review ) ) { |
|
| 383 | + $prepared_review = $this->prepare_item_for_database($request); |
|
| 384 | + if (is_wp_error($prepared_review)) { |
|
| 385 | 385 | return $prepared_review; |
| 386 | 386 | } |
| 387 | 387 | |
@@ -390,49 +390,49 @@ discard block |
||
| 390 | 390 | /* |
| 391 | 391 | * Do not allow a comment to be created with missing or empty comment_content. See wp_handle_comment_submission(). |
| 392 | 392 | */ |
| 393 | - if ( empty( $prepared_review['comment_content'] ) ) { |
|
| 394 | - return new WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 393 | + if (empty($prepared_review['comment_content'])) { |
|
| 394 | + return new WP_Error('woocommerce_rest_review_content_invalid', __('Invalid review content.', 'woocommerce'), array('status' => 400)); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | // Setting remaining values before wp_insert_comment so we can use wp_allow_comment(). |
| 398 | - if ( ! isset( $prepared_review['comment_date_gmt'] ) ) { |
|
| 399 | - $prepared_review['comment_date_gmt'] = current_time( 'mysql', true ); |
|
| 398 | + if ( ! isset($prepared_review['comment_date_gmt'])) { |
|
| 399 | + $prepared_review['comment_date_gmt'] = current_time('mysql', true); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - if ( ! empty( $_SERVER['REMOTE_ADDR'] ) && rest_is_ip_address( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) { // WPCS: input var ok, sanitization ok. |
|
| 403 | - $prepared_review['comment_author_IP'] = wc_clean( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // WPCS: input var ok. |
|
| 402 | + if ( ! empty($_SERVER['REMOTE_ADDR']) && rest_is_ip_address(wp_unslash($_SERVER['REMOTE_ADDR']))) { // WPCS: input var ok, sanitization ok. |
|
| 403 | + $prepared_review['comment_author_IP'] = wc_clean(wp_unslash($_SERVER['REMOTE_ADDR'])); // WPCS: input var ok. |
|
| 404 | 404 | } else { |
| 405 | 405 | $prepared_review['comment_author_IP'] = '127.0.0.1'; |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | - if ( ! empty( $request['author_user_agent'] ) ) { |
|
| 408 | + if ( ! empty($request['author_user_agent'])) { |
|
| 409 | 409 | $prepared_review['comment_agent'] = $request['author_user_agent']; |
| 410 | - } elseif ( $request->get_header( 'user_agent' ) ) { |
|
| 411 | - $prepared_review['comment_agent'] = $request->get_header( 'user_agent' ); |
|
| 410 | + } elseif ($request->get_header('user_agent')) { |
|
| 411 | + $prepared_review['comment_agent'] = $request->get_header('user_agent'); |
|
| 412 | 412 | } else { |
| 413 | 413 | $prepared_review['comment_agent'] = ''; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_review ); |
|
| 417 | - if ( is_wp_error( $check_comment_lengths ) ) { |
|
| 418 | - $error_code = str_replace( array( 'comment_author', 'comment_content' ), array( 'reviewer', 'review_content' ), $check_comment_lengths->get_error_code() ); |
|
| 419 | - return new WP_Error( 'woocommerce_rest_' . $error_code, __( 'Product review field exceeds maximum length allowed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 416 | + $check_comment_lengths = wp_check_comment_data_max_lengths($prepared_review); |
|
| 417 | + if (is_wp_error($check_comment_lengths)) { |
|
| 418 | + $error_code = str_replace(array('comment_author', 'comment_content'), array('reviewer', 'review_content'), $check_comment_lengths->get_error_code()); |
|
| 419 | + return new WP_Error('woocommerce_rest_' . $error_code, __('Product review field exceeds maximum length allowed.', 'woocommerce'), array('status' => 400)); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | $prepared_review['comment_parent'] = 0; |
| 423 | 423 | $prepared_review['comment_author_url'] = ''; |
| 424 | - $prepared_review['comment_approved'] = wp_allow_comment( $prepared_review, true ); |
|
| 424 | + $prepared_review['comment_approved'] = wp_allow_comment($prepared_review, true); |
|
| 425 | 425 | |
| 426 | - if ( is_wp_error( $prepared_review['comment_approved'] ) ) { |
|
| 426 | + if (is_wp_error($prepared_review['comment_approved'])) { |
|
| 427 | 427 | $error_code = $prepared_review['comment_approved']->get_error_code(); |
| 428 | 428 | $error_message = $prepared_review['comment_approved']->get_error_message(); |
| 429 | 429 | |
| 430 | - if ( 'comment_duplicate' === $error_code ) { |
|
| 431 | - return new WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 409 ) ); |
|
| 430 | + if ('comment_duplicate' === $error_code) { |
|
| 431 | + return new WP_Error('woocommerce_rest_' . $error_code, $error_message, array('status' => 409)); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - if ( 'comment_flood' === $error_code ) { |
|
| 435 | - return new WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 400 ) ); |
|
| 434 | + if ('comment_flood' === $error_code) { |
|
| 435 | + return new WP_Error('woocommerce_rest_' . $error_code, $error_message, array('status' => 400)); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | return $prepared_review['comment_approved']; |
@@ -449,24 +449,24 @@ discard block |
||
| 449 | 449 | * @param array|WP_Error $prepared_review The prepared review data for wp_insert_comment(). |
| 450 | 450 | * @param WP_REST_Request $request Request used to insert the review. |
| 451 | 451 | */ |
| 452 | - $prepared_review = apply_filters( 'woocommerce_rest_pre_insert_product_review', $prepared_review, $request ); |
|
| 453 | - if ( is_wp_error( $prepared_review ) ) { |
|
| 452 | + $prepared_review = apply_filters('woocommerce_rest_pre_insert_product_review', $prepared_review, $request); |
|
| 453 | + if (is_wp_error($prepared_review)) { |
|
| 454 | 454 | return $prepared_review; |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - $review_id = wp_insert_comment( wp_filter_comment( wp_slash( (array) $prepared_review ) ) ); |
|
| 457 | + $review_id = wp_insert_comment(wp_filter_comment(wp_slash((array) $prepared_review))); |
|
| 458 | 458 | |
| 459 | - if ( ! $review_id ) { |
|
| 460 | - return new WP_Error( 'woocommerce_rest_review_failed_create', __( 'Creating product review failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 459 | + if ( ! $review_id) { |
|
| 460 | + return new WP_Error('woocommerce_rest_review_failed_create', __('Creating product review failed.', 'woocommerce'), array('status' => 500)); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - if ( isset( $request['status'] ) ) { |
|
| 464 | - $this->handle_status_param( $request['status'], $review_id ); |
|
| 463 | + if (isset($request['status'])) { |
|
| 464 | + $this->handle_status_param($request['status'], $review_id); |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | - update_comment_meta( $review_id, 'rating', ! empty( $request['rating'] ) ? $request['rating'] : '0' ); |
|
| 467 | + update_comment_meta($review_id, 'rating', ! empty($request['rating']) ? $request['rating'] : '0'); |
|
| 468 | 468 | |
| 469 | - $review = get_comment( $review_id ); |
|
| 469 | + $review = get_comment($review_id); |
|
| 470 | 470 | |
| 471 | 471 | /** |
| 472 | 472 | * Fires after a comment is created or updated via the REST API. |
@@ -475,21 +475,21 @@ discard block |
||
| 475 | 475 | * @param WP_REST_Request $request Request object. |
| 476 | 476 | * @param bool $creating True when creating a comment, false when updating. |
| 477 | 477 | */ |
| 478 | - do_action( 'woocommerce_rest_insert_product_review', $review, $request, true ); |
|
| 478 | + do_action('woocommerce_rest_insert_product_review', $review, $request, true); |
|
| 479 | 479 | |
| 480 | - $fields_update = $this->update_additional_fields_for_object( $review, $request ); |
|
| 481 | - if ( is_wp_error( $fields_update ) ) { |
|
| 480 | + $fields_update = $this->update_additional_fields_for_object($review, $request); |
|
| 481 | + if (is_wp_error($fields_update)) { |
|
| 482 | 482 | return $fields_update; |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | - $context = current_user_can( 'moderate_comments' ) ? 'edit' : 'view'; |
|
| 486 | - $request->set_param( 'context', $context ); |
|
| 485 | + $context = current_user_can('moderate_comments') ? 'edit' : 'view'; |
|
| 486 | + $request->set_param('context', $context); |
|
| 487 | 487 | |
| 488 | - $response = $this->prepare_item_for_response( $review, $request ); |
|
| 489 | - $response = rest_ensure_response( $response ); |
|
| 488 | + $response = $this->prepare_item_for_response($review, $request); |
|
| 489 | + $response = rest_ensure_response($response); |
|
| 490 | 490 | |
| 491 | - $response->set_status( 201 ); |
|
| 492 | - $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $review_id ) ) ); |
|
| 491 | + $response->set_status(201); |
|
| 492 | + $response->header('Location', rest_url(sprintf('%s/%s/%d', $this->namespace, $this->rest_base, $review_id))); |
|
| 493 | 493 | |
| 494 | 494 | return $response; |
| 495 | 495 | } |
@@ -500,14 +500,14 @@ discard block |
||
| 500 | 500 | * @param WP_REST_Request $request Full details about the request. |
| 501 | 501 | * @return WP_Error|WP_REST_Response |
| 502 | 502 | */ |
| 503 | - public function get_item( $request ) { |
|
| 504 | - $review = $this->get_review( $request['id'] ); |
|
| 505 | - if ( is_wp_error( $review ) ) { |
|
| 503 | + public function get_item($request) { |
|
| 504 | + $review = $this->get_review($request['id']); |
|
| 505 | + if (is_wp_error($review)) { |
|
| 506 | 506 | return $review; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - $data = $this->prepare_item_for_response( $review, $request ); |
|
| 510 | - $response = rest_ensure_response( $data ); |
|
| 509 | + $data = $this->prepare_item_for_response($review, $request); |
|
| 510 | + $response = rest_ensure_response($data); |
|
| 511 | 511 | |
| 512 | 512 | return $response; |
| 513 | 513 | } |
@@ -518,84 +518,84 @@ discard block |
||
| 518 | 518 | * @param WP_REST_Request $request Full details about the request. |
| 519 | 519 | * @return WP_Error|WP_REST_Response Response object on success, or error object on failure. |
| 520 | 520 | */ |
| 521 | - public function update_item( $request ) { |
|
| 522 | - $review = $this->get_review( $request['id'] ); |
|
| 523 | - if ( is_wp_error( $review ) ) { |
|
| 521 | + public function update_item($request) { |
|
| 522 | + $review = $this->get_review($request['id']); |
|
| 523 | + if (is_wp_error($review)) { |
|
| 524 | 524 | return $review; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | $id = (int) $review->comment_ID; |
| 528 | 528 | |
| 529 | - if ( isset( $request['type'] ) && 'review' !== get_comment_type( $id ) ) { |
|
| 530 | - return new WP_Error( 'woocommerce_rest_review_invalid_type', __( 'Sorry, you are not allowed to change the comment type.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 529 | + if (isset($request['type']) && 'review' !== get_comment_type($id)) { |
|
| 530 | + return new WP_Error('woocommerce_rest_review_invalid_type', __('Sorry, you are not allowed to change the comment type.', 'woocommerce'), array('status' => 404)); |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | - $prepared_args = $this->prepare_item_for_database( $request ); |
|
| 534 | - if ( is_wp_error( $prepared_args ) ) { |
|
| 533 | + $prepared_args = $this->prepare_item_for_database($request); |
|
| 534 | + if (is_wp_error($prepared_args)) { |
|
| 535 | 535 | return $prepared_args; |
| 536 | 536 | } |
| 537 | 537 | |
| 538 | - if ( ! empty( $prepared_args['comment_post_ID'] ) ) { |
|
| 539 | - if ( 'product' !== get_post_type( (int) $prepared_args['comment_post_ID'] ) ) { |
|
| 540 | - return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 538 | + if ( ! empty($prepared_args['comment_post_ID'])) { |
|
| 539 | + if ('product' !== get_post_type((int) $prepared_args['comment_post_ID'])) { |
|
| 540 | + return new WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404)); |
|
| 541 | 541 | } |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | - if ( empty( $prepared_args ) && isset( $request['status'] ) ) { |
|
| 544 | + if (empty($prepared_args) && isset($request['status'])) { |
|
| 545 | 545 | // Only the comment status is being changed. |
| 546 | - $change = $this->handle_status_param( $request['status'], $id ); |
|
| 546 | + $change = $this->handle_status_param($request['status'], $id); |
|
| 547 | 547 | |
| 548 | - if ( ! $change ) { |
|
| 549 | - return new WP_Error( 'woocommerce_rest_review_failed_edit', __( 'Updating review status failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 548 | + if ( ! $change) { |
|
| 549 | + return new WP_Error('woocommerce_rest_review_failed_edit', __('Updating review status failed.', 'woocommerce'), array('status' => 500)); |
|
| 550 | 550 | } |
| 551 | - } elseif ( ! empty( $prepared_args ) ) { |
|
| 552 | - if ( is_wp_error( $prepared_args ) ) { |
|
| 551 | + } elseif ( ! empty($prepared_args)) { |
|
| 552 | + if (is_wp_error($prepared_args)) { |
|
| 553 | 553 | return $prepared_args; |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | - if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { |
|
| 557 | - return new WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 556 | + if (isset($prepared_args['comment_content']) && empty($prepared_args['comment_content'])) { |
|
| 557 | + return new WP_Error('woocommerce_rest_review_content_invalid', __('Invalid review content.', 'woocommerce'), array('status' => 400)); |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | $prepared_args['comment_ID'] = $id; |
| 561 | 561 | |
| 562 | - $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args ); |
|
| 563 | - if ( is_wp_error( $check_comment_lengths ) ) { |
|
| 564 | - $error_code = str_replace( array( 'comment_author', 'comment_content' ), array( 'reviewer', 'review_content' ), $check_comment_lengths->get_error_code() ); |
|
| 565 | - return new WP_Error( 'woocommerce_rest_' . $error_code, __( 'Product review field exceeds maximum length allowed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 562 | + $check_comment_lengths = wp_check_comment_data_max_lengths($prepared_args); |
|
| 563 | + if (is_wp_error($check_comment_lengths)) { |
|
| 564 | + $error_code = str_replace(array('comment_author', 'comment_content'), array('reviewer', 'review_content'), $check_comment_lengths->get_error_code()); |
|
| 565 | + return new WP_Error('woocommerce_rest_' . $error_code, __('Product review field exceeds maximum length allowed.', 'woocommerce'), array('status' => 400)); |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | - $updated = wp_update_comment( wp_slash( (array) $prepared_args ) ); |
|
| 568 | + $updated = wp_update_comment(wp_slash((array) $prepared_args)); |
|
| 569 | 569 | |
| 570 | - if ( false === $updated ) { |
|
| 571 | - return new WP_Error( 'woocommerce_rest_comment_failed_edit', __( 'Updating review failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 570 | + if (false === $updated) { |
|
| 571 | + return new WP_Error('woocommerce_rest_comment_failed_edit', __('Updating review failed.', 'woocommerce'), array('status' => 500)); |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | - if ( isset( $request['status'] ) ) { |
|
| 575 | - $this->handle_status_param( $request['status'], $id ); |
|
| 574 | + if (isset($request['status'])) { |
|
| 575 | + $this->handle_status_param($request['status'], $id); |
|
| 576 | 576 | } |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | - if ( ! empty( $request['rating'] ) ) { |
|
| 580 | - update_comment_meta( $id, 'rating', $request['rating'] ); |
|
| 579 | + if ( ! empty($request['rating'])) { |
|
| 580 | + update_comment_meta($id, 'rating', $request['rating']); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | - $review = get_comment( $id ); |
|
| 583 | + $review = get_comment($id); |
|
| 584 | 584 | |
| 585 | 585 | /** This action is documented in includes/api/class-wc-rest-product-reviews-controller.php */ |
| 586 | - do_action( 'woocommerce_rest_insert_product_review', $review, $request, false ); |
|
| 586 | + do_action('woocommerce_rest_insert_product_review', $review, $request, false); |
|
| 587 | 587 | |
| 588 | - $fields_update = $this->update_additional_fields_for_object( $review, $request ); |
|
| 588 | + $fields_update = $this->update_additional_fields_for_object($review, $request); |
|
| 589 | 589 | |
| 590 | - if ( is_wp_error( $fields_update ) ) { |
|
| 590 | + if (is_wp_error($fields_update)) { |
|
| 591 | 591 | return $fields_update; |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | - $request->set_param( 'context', 'edit' ); |
|
| 594 | + $request->set_param('context', 'edit'); |
|
| 595 | 595 | |
| 596 | - $response = $this->prepare_item_for_response( $review, $request ); |
|
| 596 | + $response = $this->prepare_item_for_response($review, $request); |
|
| 597 | 597 | |
| 598 | - return rest_ensure_response( $response ); |
|
| 598 | + return rest_ensure_response($response); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | /** |
@@ -604,13 +604,13 @@ discard block |
||
| 604 | 604 | * @param WP_REST_Request $request Full details about the request. |
| 605 | 605 | * @return WP_Error|WP_REST_Response Response object on success, or error object on failure. |
| 606 | 606 | */ |
| 607 | - public function delete_item( $request ) { |
|
| 608 | - $review = $this->get_review( $request['id'] ); |
|
| 609 | - if ( is_wp_error( $review ) ) { |
|
| 607 | + public function delete_item($request) { |
|
| 608 | + $review = $this->get_review($request['id']); |
|
| 609 | + if (is_wp_error($review)) { |
|
| 610 | 610 | return $review; |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 613 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
| 614 | 614 | |
| 615 | 615 | /** |
| 616 | 616 | * Filters whether a review can be trashed. |
@@ -621,13 +621,13 @@ discard block |
||
| 621 | 621 | * @param bool $supports_trash Whether the post type support trashing. |
| 622 | 622 | * @param WP_Comment $review The review object being considered for trashing support. |
| 623 | 623 | */ |
| 624 | - $supports_trash = apply_filters( 'woocommerce_rest_product_review_trashable', ( EMPTY_TRASH_DAYS > 0 ), $review ); |
|
| 624 | + $supports_trash = apply_filters('woocommerce_rest_product_review_trashable', (EMPTY_TRASH_DAYS > 0), $review); |
|
| 625 | 625 | |
| 626 | - $request->set_param( 'context', 'edit' ); |
|
| 626 | + $request->set_param('context', 'edit'); |
|
| 627 | 627 | |
| 628 | - if ( $force ) { |
|
| 629 | - $previous = $this->prepare_item_for_response( $review, $request ); |
|
| 630 | - $result = wp_delete_comment( $review->comment_ID, true ); |
|
| 628 | + if ($force) { |
|
| 629 | + $previous = $this->prepare_item_for_response($review, $request); |
|
| 630 | + $result = wp_delete_comment($review->comment_ID, true); |
|
| 631 | 631 | $response = new WP_REST_Response(); |
| 632 | 632 | $response->set_data( |
| 633 | 633 | array( |
@@ -637,22 +637,22 @@ discard block |
||
| 637 | 637 | ); |
| 638 | 638 | } else { |
| 639 | 639 | // If this type doesn't support trashing, error out. |
| 640 | - if ( ! $supports_trash ) { |
|
| 640 | + if ( ! $supports_trash) { |
|
| 641 | 641 | /* translators: %s: force=true */ |
| 642 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( "The object does not support trashing. Set '%s' to delete.", 'woocommerce' ), 'force=true' ), array( 'status' => 501 ) ); |
|
| 642 | + return new WP_Error('woocommerce_rest_trash_not_supported', sprintf(__("The object does not support trashing. Set '%s' to delete.", 'woocommerce'), 'force=true'), array('status' => 501)); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | - if ( 'trash' === $review->comment_approved ) { |
|
| 646 | - return new WP_Error( 'woocommerce_rest_already_trashed', __( 'The object has already been trashed.', 'woocommerce' ), array( 'status' => 410 ) ); |
|
| 645 | + if ('trash' === $review->comment_approved) { |
|
| 646 | + return new WP_Error('woocommerce_rest_already_trashed', __('The object has already been trashed.', 'woocommerce'), array('status' => 410)); |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | - $result = wp_trash_comment( $review->comment_ID ); |
|
| 650 | - $review = get_comment( $review->comment_ID ); |
|
| 651 | - $response = $this->prepare_item_for_response( $review, $request ); |
|
| 649 | + $result = wp_trash_comment($review->comment_ID); |
|
| 650 | + $review = get_comment($review->comment_ID); |
|
| 651 | + $response = $this->prepare_item_for_response($review, $request); |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | - if ( ! $result ) { |
|
| 655 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'The object cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 654 | + if ( ! $result) { |
|
| 655 | + return new WP_Error('woocommerce_rest_cannot_delete', __('The object cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | /** |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | * @param WP_REST_Response $response The response returned from the API. |
| 663 | 663 | * @param WP_REST_Request $request The request sent to the API. |
| 664 | 664 | */ |
| 665 | - do_action( 'woocommerce_rest_delete_review', $review, $response, $request ); |
|
| 665 | + do_action('woocommerce_rest_delete_review', $review, $response, $request); |
|
| 666 | 666 | |
| 667 | 667 | return $response; |
| 668 | 668 | } |
@@ -674,52 +674,52 @@ discard block |
||
| 674 | 674 | * @param WP_REST_Request $request Request object. |
| 675 | 675 | * @return WP_REST_Response $response Response data. |
| 676 | 676 | */ |
| 677 | - public function prepare_item_for_response( $review, $request ) { |
|
| 678 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 679 | - $fields = $this->get_fields_for_response( $request ); |
|
| 677 | + public function prepare_item_for_response($review, $request) { |
|
| 678 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 679 | + $fields = $this->get_fields_for_response($request); |
|
| 680 | 680 | $data = array(); |
| 681 | 681 | |
| 682 | - if ( in_array( 'id', $fields, true ) ) { |
|
| 682 | + if (in_array('id', $fields, true)) { |
|
| 683 | 683 | $data['id'] = (int) $review->comment_ID; |
| 684 | 684 | } |
| 685 | - if ( in_array( 'date_created', $fields, true ) ) { |
|
| 686 | - $data['date_created'] = wc_rest_prepare_date_response( $review->comment_date ); |
|
| 685 | + if (in_array('date_created', $fields, true)) { |
|
| 686 | + $data['date_created'] = wc_rest_prepare_date_response($review->comment_date); |
|
| 687 | 687 | } |
| 688 | - if ( in_array( 'date_created_gmt', $fields, true ) ) { |
|
| 689 | - $data['date_created_gmt'] = wc_rest_prepare_date_response( $review->comment_date_gmt ); |
|
| 688 | + if (in_array('date_created_gmt', $fields, true)) { |
|
| 689 | + $data['date_created_gmt'] = wc_rest_prepare_date_response($review->comment_date_gmt); |
|
| 690 | 690 | } |
| 691 | - if ( in_array( 'product_id', $fields, true ) ) { |
|
| 691 | + if (in_array('product_id', $fields, true)) { |
|
| 692 | 692 | $data['product_id'] = (int) $review->comment_post_ID; |
| 693 | 693 | } |
| 694 | - if ( in_array( 'status', $fields, true ) ) { |
|
| 695 | - $data['status'] = $this->prepare_status_response( (string) $review->comment_approved ); |
|
| 694 | + if (in_array('status', $fields, true)) { |
|
| 695 | + $data['status'] = $this->prepare_status_response((string) $review->comment_approved); |
|
| 696 | 696 | } |
| 697 | - if ( in_array( 'reviewer', $fields, true ) ) { |
|
| 697 | + if (in_array('reviewer', $fields, true)) { |
|
| 698 | 698 | $data['reviewer'] = $review->comment_author; |
| 699 | 699 | } |
| 700 | - if ( in_array( 'reviewer_email', $fields, true ) ) { |
|
| 700 | + if (in_array('reviewer_email', $fields, true)) { |
|
| 701 | 701 | $data['reviewer_email'] = $review->comment_author_email; |
| 702 | 702 | } |
| 703 | - if ( in_array( 'review', $fields, true ) ) { |
|
| 704 | - $data['review'] = 'view' === $context ? wpautop( $review->comment_content ) : $review->comment_content; |
|
| 703 | + if (in_array('review', $fields, true)) { |
|
| 704 | + $data['review'] = 'view' === $context ? wpautop($review->comment_content) : $review->comment_content; |
|
| 705 | 705 | } |
| 706 | - if ( in_array( 'rating', $fields, true ) ) { |
|
| 707 | - $data['rating'] = (int) get_comment_meta( $review->comment_ID, 'rating', true ); |
|
| 706 | + if (in_array('rating', $fields, true)) { |
|
| 707 | + $data['rating'] = (int) get_comment_meta($review->comment_ID, 'rating', true); |
|
| 708 | 708 | } |
| 709 | - if ( in_array( 'verified', $fields, true ) ) { |
|
| 710 | - $data['verified'] = wc_review_is_from_verified_owner( $review->comment_ID ); |
|
| 709 | + if (in_array('verified', $fields, true)) { |
|
| 710 | + $data['verified'] = wc_review_is_from_verified_owner($review->comment_ID); |
|
| 711 | 711 | } |
| 712 | - if ( in_array( 'reviewer_avatar_urls', $fields, true ) ) { |
|
| 713 | - $data['reviewer_avatar_urls'] = rest_get_avatar_urls( $review->comment_author_email ); |
|
| 712 | + if (in_array('reviewer_avatar_urls', $fields, true)) { |
|
| 713 | + $data['reviewer_avatar_urls'] = rest_get_avatar_urls($review->comment_author_email); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 717 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 716 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 717 | + $data = $this->filter_response_by_context($data, $context); |
|
| 718 | 718 | |
| 719 | 719 | // Wrap the data in a response object. |
| 720 | - $response = rest_ensure_response( $data ); |
|
| 720 | + $response = rest_ensure_response($data); |
|
| 721 | 721 | |
| 722 | - $response->add_links( $this->prepare_links( $review ) ); |
|
| 722 | + $response->add_links($this->prepare_links($review)); |
|
| 723 | 723 | |
| 724 | 724 | /** |
| 725 | 725 | * Filter product reviews object returned from the REST API. |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * @param WP_Comment $review Product review object used to create response. |
| 729 | 729 | * @param WP_REST_Request $request Request object. |
| 730 | 730 | */ |
| 731 | - return apply_filters( 'woocommerce_rest_prepare_product_review', $response, $review, $request ); |
|
| 731 | + return apply_filters('woocommerce_rest_prepare_product_review', $response, $review, $request); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | /** |
@@ -737,38 +737,38 @@ discard block |
||
| 737 | 737 | * @param WP_REST_Request $request Request object. |
| 738 | 738 | * @return array|WP_Error $prepared_review |
| 739 | 739 | */ |
| 740 | - protected function prepare_item_for_database( $request ) { |
|
| 741 | - if ( isset( $request['id'] ) ) { |
|
| 740 | + protected function prepare_item_for_database($request) { |
|
| 741 | + if (isset($request['id'])) { |
|
| 742 | 742 | $prepared_review['comment_ID'] = (int) $request['id']; |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | - if ( isset( $request['review'] ) ) { |
|
| 745 | + if (isset($request['review'])) { |
|
| 746 | 746 | $prepared_review['comment_content'] = $request['review']; |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | - if ( isset( $request['product_id'] ) ) { |
|
| 749 | + if (isset($request['product_id'])) { |
|
| 750 | 750 | $prepared_review['comment_post_ID'] = (int) $request['product_id']; |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | - if ( isset( $request['reviewer'] ) ) { |
|
| 753 | + if (isset($request['reviewer'])) { |
|
| 754 | 754 | $prepared_review['comment_author'] = $request['reviewer']; |
| 755 | 755 | } |
| 756 | 756 | |
| 757 | - if ( isset( $request['reviewer_email'] ) ) { |
|
| 757 | + if (isset($request['reviewer_email'])) { |
|
| 758 | 758 | $prepared_review['comment_author_email'] = $request['reviewer_email']; |
| 759 | 759 | } |
| 760 | 760 | |
| 761 | - if ( ! empty( $request['date_created'] ) ) { |
|
| 762 | - $date_data = rest_get_date_with_gmt( $request['date_created'] ); |
|
| 761 | + if ( ! empty($request['date_created'])) { |
|
| 762 | + $date_data = rest_get_date_with_gmt($request['date_created']); |
|
| 763 | 763 | |
| 764 | - if ( ! empty( $date_data ) ) { |
|
| 765 | - list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data; |
|
| 764 | + if ( ! empty($date_data)) { |
|
| 765 | + list($prepared_review['comment_date'], $prepared_review['comment_date_gmt']) = $date_data; |
|
| 766 | 766 | } |
| 767 | - } elseif ( ! empty( $request['date_created_gmt'] ) ) { |
|
| 768 | - $date_data = rest_get_date_with_gmt( $request['date_created_gmt'], true ); |
|
| 767 | + } elseif ( ! empty($request['date_created_gmt'])) { |
|
| 768 | + $date_data = rest_get_date_with_gmt($request['date_created_gmt'], true); |
|
| 769 | 769 | |
| 770 | - if ( ! empty( $date_data ) ) { |
|
| 771 | - list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data; |
|
| 770 | + if ( ! empty($date_data)) { |
|
| 771 | + list($prepared_review['comment_date'], $prepared_review['comment_date_gmt']) = $date_data; |
|
| 772 | 772 | } |
| 773 | 773 | } |
| 774 | 774 | |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | * @param array $prepared_review The prepared review data for `wp_insert_comment`. |
| 782 | 782 | * @param WP_REST_Request $request The current request. |
| 783 | 783 | */ |
| 784 | - return apply_filters( 'woocommerce_rest_preprocess_product_review', $prepared_review, $request ); |
|
| 784 | + return apply_filters('woocommerce_rest_preprocess_product_review', $prepared_review, $request); |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | /** |
@@ -790,25 +790,25 @@ discard block |
||
| 790 | 790 | * @param WP_Comment $review Product review object. |
| 791 | 791 | * @return array Links for the given product review. |
| 792 | 792 | */ |
| 793 | - protected function prepare_links( $review ) { |
|
| 793 | + protected function prepare_links($review) { |
|
| 794 | 794 | $links = array( |
| 795 | 795 | 'self' => array( |
| 796 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $review->comment_ID ) ), |
|
| 796 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $review->comment_ID)), |
|
| 797 | 797 | ), |
| 798 | 798 | 'collection' => array( |
| 799 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
| 799 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
| 800 | 800 | ), |
| 801 | 801 | ); |
| 802 | 802 | |
| 803 | - if ( 0 !== (int) $review->comment_post_ID ) { |
|
| 803 | + if (0 !== (int) $review->comment_post_ID) { |
|
| 804 | 804 | $links['up'] = array( |
| 805 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $review->comment_post_ID ) ), |
|
| 805 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $review->comment_post_ID)), |
|
| 806 | 806 | ); |
| 807 | 807 | } |
| 808 | 808 | |
| 809 | - if ( 0 !== (int) $review->user_id ) { |
|
| 809 | + if (0 !== (int) $review->user_id) { |
|
| 810 | 810 | $links['reviewer'] = array( |
| 811 | - 'href' => rest_url( 'wp/v2/users/' . $review->user_id ), |
|
| 811 | + 'href' => rest_url('wp/v2/users/' . $review->user_id), |
|
| 812 | 812 | 'embeddable' => true, |
| 813 | 813 | ); |
| 814 | 814 | } |
@@ -828,91 +828,91 @@ discard block |
||
| 828 | 828 | 'type' => 'object', |
| 829 | 829 | 'properties' => array( |
| 830 | 830 | 'id' => array( |
| 831 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 831 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 832 | 832 | 'type' => 'integer', |
| 833 | - 'context' => array( 'view', 'edit' ), |
|
| 833 | + 'context' => array('view', 'edit'), |
|
| 834 | 834 | 'readonly' => true, |
| 835 | 835 | ), |
| 836 | 836 | 'date_created' => array( |
| 837 | - 'description' => __( "The date the review was created, in the site's timezone.", 'woocommerce' ), |
|
| 837 | + 'description' => __("The date the review was created, in the site's timezone.", 'woocommerce'), |
|
| 838 | 838 | 'type' => 'date-time', |
| 839 | - 'context' => array( 'view', 'edit' ), |
|
| 839 | + 'context' => array('view', 'edit'), |
|
| 840 | 840 | 'readonly' => true, |
| 841 | 841 | ), |
| 842 | 842 | 'date_created_gmt' => array( |
| 843 | - 'description' => __( 'The date the review was created, as GMT.', 'woocommerce' ), |
|
| 843 | + 'description' => __('The date the review was created, as GMT.', 'woocommerce'), |
|
| 844 | 844 | 'type' => 'date-time', |
| 845 | - 'context' => array( 'view', 'edit' ), |
|
| 845 | + 'context' => array('view', 'edit'), |
|
| 846 | 846 | 'readonly' => true, |
| 847 | 847 | ), |
| 848 | 848 | 'product_id' => array( |
| 849 | - 'description' => __( 'Unique identifier for the product that the review belongs to.', 'woocommerce' ), |
|
| 849 | + 'description' => __('Unique identifier for the product that the review belongs to.', 'woocommerce'), |
|
| 850 | 850 | 'type' => 'integer', |
| 851 | - 'context' => array( 'view', 'edit' ), |
|
| 851 | + 'context' => array('view', 'edit'), |
|
| 852 | 852 | ), |
| 853 | 853 | 'status' => array( |
| 854 | - 'description' => __( 'Status of the review.', 'woocommerce' ), |
|
| 854 | + 'description' => __('Status of the review.', 'woocommerce'), |
|
| 855 | 855 | 'type' => 'string', |
| 856 | 856 | 'default' => 'approved', |
| 857 | - 'enum' => array( 'approved', 'hold', 'spam', 'unspam', 'trash', 'untrash' ), |
|
| 858 | - 'context' => array( 'view', 'edit' ), |
|
| 857 | + 'enum' => array('approved', 'hold', 'spam', 'unspam', 'trash', 'untrash'), |
|
| 858 | + 'context' => array('view', 'edit'), |
|
| 859 | 859 | ), |
| 860 | 860 | 'reviewer' => array( |
| 861 | - 'description' => __( 'Reviewer name.', 'woocommerce' ), |
|
| 861 | + 'description' => __('Reviewer name.', 'woocommerce'), |
|
| 862 | 862 | 'type' => 'string', |
| 863 | - 'context' => array( 'view', 'edit' ), |
|
| 863 | + 'context' => array('view', 'edit'), |
|
| 864 | 864 | ), |
| 865 | 865 | 'reviewer_email' => array( |
| 866 | - 'description' => __( 'Reviewer email.', 'woocommerce' ), |
|
| 866 | + 'description' => __('Reviewer email.', 'woocommerce'), |
|
| 867 | 867 | 'type' => 'string', |
| 868 | 868 | 'format' => 'email', |
| 869 | - 'context' => array( 'view', 'edit' ), |
|
| 869 | + 'context' => array('view', 'edit'), |
|
| 870 | 870 | ), |
| 871 | 871 | 'review' => array( |
| 872 | - 'description' => __( 'The content of the review.', 'woocommerce' ), |
|
| 872 | + 'description' => __('The content of the review.', 'woocommerce'), |
|
| 873 | 873 | 'type' => 'string', |
| 874 | - 'context' => array( 'view', 'edit' ), |
|
| 874 | + 'context' => array('view', 'edit'), |
|
| 875 | 875 | 'arg_options' => array( |
| 876 | 876 | 'sanitize_callback' => 'wp_filter_post_kses', |
| 877 | 877 | ), |
| 878 | 878 | ), |
| 879 | 879 | 'rating' => array( |
| 880 | - 'description' => __( 'Review rating (0 to 5).', 'woocommerce' ), |
|
| 880 | + 'description' => __('Review rating (0 to 5).', 'woocommerce'), |
|
| 881 | 881 | 'type' => 'integer', |
| 882 | - 'context' => array( 'view', 'edit' ), |
|
| 882 | + 'context' => array('view', 'edit'), |
|
| 883 | 883 | ), |
| 884 | 884 | 'verified' => array( |
| 885 | - 'description' => __( 'Shows if the reviewer bought the product or not.', 'woocommerce' ), |
|
| 885 | + 'description' => __('Shows if the reviewer bought the product or not.', 'woocommerce'), |
|
| 886 | 886 | 'type' => 'boolean', |
| 887 | - 'context' => array( 'view', 'edit' ), |
|
| 887 | + 'context' => array('view', 'edit'), |
|
| 888 | 888 | 'readonly' => true, |
| 889 | 889 | ), |
| 890 | 890 | ), |
| 891 | 891 | ); |
| 892 | 892 | |
| 893 | - if ( get_option( 'show_avatars' ) ) { |
|
| 893 | + if (get_option('show_avatars')) { |
|
| 894 | 894 | $avatar_properties = array(); |
| 895 | 895 | $avatar_sizes = rest_get_avatar_sizes(); |
| 896 | 896 | |
| 897 | - foreach ( $avatar_sizes as $size ) { |
|
| 898 | - $avatar_properties[ $size ] = array( |
|
| 897 | + foreach ($avatar_sizes as $size) { |
|
| 898 | + $avatar_properties[$size] = array( |
|
| 899 | 899 | /* translators: %d: avatar image size in pixels */ |
| 900 | - 'description' => sprintf( __( 'Avatar URL with image size of %d pixels.', 'woocommerce' ), $size ), |
|
| 900 | + 'description' => sprintf(__('Avatar URL with image size of %d pixels.', 'woocommerce'), $size), |
|
| 901 | 901 | 'type' => 'string', |
| 902 | 902 | 'format' => 'uri', |
| 903 | - 'context' => array( 'embed', 'view', 'edit' ), |
|
| 903 | + 'context' => array('embed', 'view', 'edit'), |
|
| 904 | 904 | ); |
| 905 | 905 | } |
| 906 | 906 | $schema['properties']['reviewer_avatar_urls'] = array( |
| 907 | - 'description' => __( 'Avatar URLs for the object reviewer.', 'woocommerce' ), |
|
| 907 | + 'description' => __('Avatar URLs for the object reviewer.', 'woocommerce'), |
|
| 908 | 908 | 'type' => 'object', |
| 909 | - 'context' => array( 'view', 'edit' ), |
|
| 909 | + 'context' => array('view', 'edit'), |
|
| 910 | 910 | 'readonly' => true, |
| 911 | 911 | 'properties' => $avatar_properties, |
| 912 | 912 | ); |
| 913 | 913 | } |
| 914 | 914 | |
| 915 | - return $this->add_additional_fields_schema( $schema ); |
|
| 915 | + return $this->add_additional_fields_schema($schema); |
|
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | /** |
@@ -925,38 +925,38 @@ discard block |
||
| 925 | 925 | |
| 926 | 926 | $params['context']['default'] = 'view'; |
| 927 | 927 | |
| 928 | - $params['after'] = array( |
|
| 929 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 928 | + $params['after'] = array( |
|
| 929 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 930 | 930 | 'type' => 'string', |
| 931 | 931 | 'format' => 'date-time', |
| 932 | 932 | ); |
| 933 | - $params['before'] = array( |
|
| 934 | - 'description' => __( 'Limit response to reviews published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 933 | + $params['before'] = array( |
|
| 934 | + 'description' => __('Limit response to reviews published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 935 | 935 | 'type' => 'string', |
| 936 | 936 | 'format' => 'date-time', |
| 937 | 937 | ); |
| 938 | - $params['exclude'] = array( |
|
| 939 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
|
| 938 | + $params['exclude'] = array( |
|
| 939 | + 'description' => __('Ensure result set excludes specific IDs.', 'woocommerce'), |
|
| 940 | 940 | 'type' => 'array', |
| 941 | 941 | 'items' => array( |
| 942 | 942 | 'type' => 'integer', |
| 943 | 943 | ), |
| 944 | 944 | 'default' => array(), |
| 945 | 945 | ); |
| 946 | - $params['include'] = array( |
|
| 947 | - 'description' => __( 'Limit result set to specific IDs.', 'woocommerce' ), |
|
| 946 | + $params['include'] = array( |
|
| 947 | + 'description' => __('Limit result set to specific IDs.', 'woocommerce'), |
|
| 948 | 948 | 'type' => 'array', |
| 949 | 949 | 'items' => array( |
| 950 | 950 | 'type' => 'integer', |
| 951 | 951 | ), |
| 952 | 952 | 'default' => array(), |
| 953 | 953 | ); |
| 954 | - $params['offset'] = array( |
|
| 955 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
| 954 | + $params['offset'] = array( |
|
| 955 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
| 956 | 956 | 'type' => 'integer', |
| 957 | 957 | ); |
| 958 | - $params['order'] = array( |
|
| 959 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 958 | + $params['order'] = array( |
|
| 959 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 960 | 960 | 'type' => 'string', |
| 961 | 961 | 'default' => 'desc', |
| 962 | 962 | 'enum' => array( |
@@ -964,8 +964,8 @@ discard block |
||
| 964 | 964 | 'desc', |
| 965 | 965 | ), |
| 966 | 966 | ); |
| 967 | - $params['orderby'] = array( |
|
| 968 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 967 | + $params['orderby'] = array( |
|
| 968 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 969 | 969 | 'type' => 'string', |
| 970 | 970 | 'default' => 'date_gmt', |
| 971 | 971 | 'enum' => array( |
@@ -976,37 +976,37 @@ discard block |
||
| 976 | 976 | 'product', |
| 977 | 977 | ), |
| 978 | 978 | ); |
| 979 | - $params['reviewer'] = array( |
|
| 980 | - 'description' => __( 'Limit result set to reviews assigned to specific user IDs.', 'woocommerce' ), |
|
| 979 | + $params['reviewer'] = array( |
|
| 980 | + 'description' => __('Limit result set to reviews assigned to specific user IDs.', 'woocommerce'), |
|
| 981 | 981 | 'type' => 'array', |
| 982 | 982 | 'items' => array( |
| 983 | 983 | 'type' => 'integer', |
| 984 | 984 | ), |
| 985 | 985 | ); |
| 986 | 986 | $params['reviewer_exclude'] = array( |
| 987 | - 'description' => __( 'Ensure result set excludes reviews assigned to specific user IDs.', 'woocommerce' ), |
|
| 987 | + 'description' => __('Ensure result set excludes reviews assigned to specific user IDs.', 'woocommerce'), |
|
| 988 | 988 | 'type' => 'array', |
| 989 | 989 | 'items' => array( |
| 990 | 990 | 'type' => 'integer', |
| 991 | 991 | ), |
| 992 | 992 | ); |
| 993 | - $params['reviewer_email'] = array( |
|
| 993 | + $params['reviewer_email'] = array( |
|
| 994 | 994 | 'default' => null, |
| 995 | - 'description' => __( 'Limit result set to that from a specific author email.', 'woocommerce' ), |
|
| 995 | + 'description' => __('Limit result set to that from a specific author email.', 'woocommerce'), |
|
| 996 | 996 | 'format' => 'email', |
| 997 | 997 | 'type' => 'string', |
| 998 | 998 | ); |
| 999 | - $params['product'] = array( |
|
| 999 | + $params['product'] = array( |
|
| 1000 | 1000 | 'default' => array(), |
| 1001 | - 'description' => __( 'Limit result set to reviews assigned to specific product IDs.', 'woocommerce' ), |
|
| 1001 | + 'description' => __('Limit result set to reviews assigned to specific product IDs.', 'woocommerce'), |
|
| 1002 | 1002 | 'type' => 'array', |
| 1003 | 1003 | 'items' => array( |
| 1004 | 1004 | 'type' => 'integer', |
| 1005 | 1005 | ), |
| 1006 | 1006 | ); |
| 1007 | - $params['status'] = array( |
|
| 1007 | + $params['status'] = array( |
|
| 1008 | 1008 | 'default' => 'approved', |
| 1009 | - 'description' => __( 'Limit result set to reviews assigned a specific status.', 'woocommerce' ), |
|
| 1009 | + 'description' => __('Limit result set to reviews assigned a specific status.', 'woocommerce'), |
|
| 1010 | 1010 | 'sanitize_callback' => 'sanitize_key', |
| 1011 | 1011 | 'type' => 'string', |
| 1012 | 1012 | 'enum' => array( |
@@ -1028,7 +1028,7 @@ discard block |
||
| 1028 | 1028 | * @since 3.5.0 |
| 1029 | 1029 | * @param array $params JSON Schema-formatted collection parameters. |
| 1030 | 1030 | */ |
| 1031 | - return apply_filters( 'woocommerce_rest_product_review_collection_params', $params ); |
|
| 1031 | + return apply_filters('woocommerce_rest_product_review_collection_params', $params); |
|
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | /** |
@@ -1038,24 +1038,24 @@ discard block |
||
| 1038 | 1038 | * @param int $id Supplied ID. |
| 1039 | 1039 | * @return WP_Comment|WP_Error Comment object if ID is valid, WP_Error otherwise. |
| 1040 | 1040 | */ |
| 1041 | - protected function get_review( $id ) { |
|
| 1041 | + protected function get_review($id) { |
|
| 1042 | 1042 | $id = (int) $id; |
| 1043 | - $error = new WP_Error( 'woocommerce_rest_review_invalid_id', __( 'Invalid review ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 1043 | + $error = new WP_Error('woocommerce_rest_review_invalid_id', __('Invalid review ID.', 'woocommerce'), array('status' => 404)); |
|
| 1044 | 1044 | |
| 1045 | - if ( 0 >= $id ) { |
|
| 1045 | + if (0 >= $id) { |
|
| 1046 | 1046 | return $error; |
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | - $review = get_comment( $id ); |
|
| 1050 | - if ( empty( $review ) ) { |
|
| 1049 | + $review = get_comment($id); |
|
| 1050 | + if (empty($review)) { |
|
| 1051 | 1051 | return $error; |
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | - if ( ! empty( $review->comment_post_ID ) ) { |
|
| 1055 | - $post = get_post( (int) $review->comment_post_ID ); |
|
| 1054 | + if ( ! empty($review->comment_post_ID)) { |
|
| 1055 | + $post = get_post((int) $review->comment_post_ID); |
|
| 1056 | 1056 | |
| 1057 | - if ( 'product' !== get_post_type( (int) $review->comment_post_ID ) ) { |
|
| 1058 | - return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 1057 | + if ('product' !== get_post_type((int) $review->comment_post_ID)) { |
|
| 1058 | + return new WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404)); |
|
| 1059 | 1059 | } |
| 1060 | 1060 | } |
| 1061 | 1061 | |
@@ -1069,10 +1069,10 @@ discard block |
||
| 1069 | 1069 | * @param string $query_param Query parameter. |
| 1070 | 1070 | * @return string |
| 1071 | 1071 | */ |
| 1072 | - protected function normalize_query_param( $query_param ) { |
|
| 1072 | + protected function normalize_query_param($query_param) { |
|
| 1073 | 1073 | $prefix = 'comment_'; |
| 1074 | 1074 | |
| 1075 | - switch ( $query_param ) { |
|
| 1075 | + switch ($query_param) { |
|
| 1076 | 1076 | case 'id': |
| 1077 | 1077 | $normalized = $prefix . 'ID'; |
| 1078 | 1078 | break; |
@@ -1097,8 +1097,8 @@ discard block |
||
| 1097 | 1097 | * @param string|int $comment_approved comment status. |
| 1098 | 1098 | * @return string Comment status. |
| 1099 | 1099 | */ |
| 1100 | - protected function prepare_status_response( $comment_approved ) { |
|
| 1101 | - switch ( $comment_approved ) { |
|
| 1100 | + protected function prepare_status_response($comment_approved) { |
|
| 1101 | + switch ($comment_approved) { |
|
| 1102 | 1102 | case 'hold': |
| 1103 | 1103 | case '0': |
| 1104 | 1104 | $status = 'hold'; |
@@ -1125,34 +1125,34 @@ discard block |
||
| 1125 | 1125 | * @param int $id Review ID. |
| 1126 | 1126 | * @return bool Whether the status was changed. |
| 1127 | 1127 | */ |
| 1128 | - protected function handle_status_param( $new_status, $id ) { |
|
| 1129 | - $old_status = wp_get_comment_status( $id ); |
|
| 1128 | + protected function handle_status_param($new_status, $id) { |
|
| 1129 | + $old_status = wp_get_comment_status($id); |
|
| 1130 | 1130 | |
| 1131 | - if ( $new_status === $old_status ) { |
|
| 1131 | + if ($new_status === $old_status) { |
|
| 1132 | 1132 | return false; |
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | - switch ( $new_status ) { |
|
| 1135 | + switch ($new_status) { |
|
| 1136 | 1136 | case 'approved': |
| 1137 | 1137 | case 'approve': |
| 1138 | 1138 | case '1': |
| 1139 | - $changed = wp_set_comment_status( $id, 'approve' ); |
|
| 1139 | + $changed = wp_set_comment_status($id, 'approve'); |
|
| 1140 | 1140 | break; |
| 1141 | 1141 | case 'hold': |
| 1142 | 1142 | case '0': |
| 1143 | - $changed = wp_set_comment_status( $id, 'hold' ); |
|
| 1143 | + $changed = wp_set_comment_status($id, 'hold'); |
|
| 1144 | 1144 | break; |
| 1145 | 1145 | case 'spam': |
| 1146 | - $changed = wp_spam_comment( $id ); |
|
| 1146 | + $changed = wp_spam_comment($id); |
|
| 1147 | 1147 | break; |
| 1148 | 1148 | case 'unspam': |
| 1149 | - $changed = wp_unspam_comment( $id ); |
|
| 1149 | + $changed = wp_unspam_comment($id); |
|
| 1150 | 1150 | break; |
| 1151 | 1151 | case 'trash': |
| 1152 | - $changed = wp_trash_comment( $id ); |
|
| 1152 | + $changed = wp_trash_comment($id); |
|
| 1153 | 1153 | break; |
| 1154 | 1154 | case 'untrash': |
| 1155 | - $changed = wp_untrash_comment( $id ); |
|
| 1155 | + $changed = wp_untrash_comment($id); |
|
| 1156 | 1156 | break; |
| 1157 | 1157 | default: |
| 1158 | 1158 | $changed = false; |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @since 2.6.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * REST API Products controller class. |
@@ -31,39 +31,39 @@ discard block |
||
| 31 | 31 | * @param WC_Product|WC_Product_Variation $product Product instance. |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - protected function get_images( $product ) { |
|
| 34 | + protected function get_images($product) { |
|
| 35 | 35 | $images = array(); |
| 36 | 36 | $attachment_ids = array(); |
| 37 | 37 | |
| 38 | 38 | // Add featured image. |
| 39 | - if ( $product->get_image_id() ) { |
|
| 39 | + if ($product->get_image_id()) { |
|
| 40 | 40 | $attachment_ids[] = $product->get_image_id(); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // Add gallery images. |
| 44 | - $attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() ); |
|
| 44 | + $attachment_ids = array_merge($attachment_ids, $product->get_gallery_image_ids()); |
|
| 45 | 45 | |
| 46 | 46 | // Build image data. |
| 47 | - foreach ( $attachment_ids as $attachment_id ) { |
|
| 48 | - $attachment_post = get_post( $attachment_id ); |
|
| 49 | - if ( is_null( $attachment_post ) ) { |
|
| 47 | + foreach ($attachment_ids as $attachment_id) { |
|
| 48 | + $attachment_post = get_post($attachment_id); |
|
| 49 | + if (is_null($attachment_post)) { |
|
| 50 | 50 | continue; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - $attachment = wp_get_attachment_image_src( $attachment_id, 'full' ); |
|
| 54 | - if ( ! is_array( $attachment ) ) { |
|
| 53 | + $attachment = wp_get_attachment_image_src($attachment_id, 'full'); |
|
| 54 | + if ( ! is_array($attachment)) { |
|
| 55 | 55 | continue; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | $images[] = array( |
| 59 | 59 | 'id' => (int) $attachment_id, |
| 60 | - 'date_created' => wc_rest_prepare_date_response( $attachment_post->post_date, false ), |
|
| 61 | - 'date_created_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ), |
|
| 62 | - 'date_modified' => wc_rest_prepare_date_response( $attachment_post->post_modified, false ), |
|
| 63 | - 'date_modified_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_modified_gmt ) ), |
|
| 64 | - 'src' => current( $attachment ), |
|
| 65 | - 'name' => get_the_title( $attachment_id ), |
|
| 66 | - 'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ), |
|
| 60 | + 'date_created' => wc_rest_prepare_date_response($attachment_post->post_date, false), |
|
| 61 | + 'date_created_gmt' => wc_rest_prepare_date_response(strtotime($attachment_post->post_date_gmt)), |
|
| 62 | + 'date_modified' => wc_rest_prepare_date_response($attachment_post->post_modified, false), |
|
| 63 | + 'date_modified_gmt' => wc_rest_prepare_date_response(strtotime($attachment_post->post_modified_gmt)), |
|
| 64 | + 'src' => current($attachment), |
|
| 65 | + 'name' => get_the_title($attachment_id), |
|
| 66 | + 'alt' => get_post_meta($attachment_id, '_wp_attachment_image_alt', true), |
|
| 67 | 67 | ); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | * @param WP_REST_Request $request Request data. |
| 78 | 78 | * @return array |
| 79 | 79 | */ |
| 80 | - protected function prepare_objects_query( $request ) { |
|
| 81 | - $args = WC_REST_CRUD_Controller::prepare_objects_query( $request ); |
|
| 80 | + protected function prepare_objects_query($request) { |
|
| 81 | + $args = WC_REST_CRUD_Controller::prepare_objects_query($request); |
|
| 82 | 82 | |
| 83 | 83 | // Set post_status. |
| 84 | 84 | $args['post_status'] = $request['status']; |
@@ -95,18 +95,18 @@ discard block |
||
| 95 | 95 | ); |
| 96 | 96 | |
| 97 | 97 | // Set tax_query for each passed arg. |
| 98 | - foreach ( $taxonomies as $taxonomy => $key ) { |
|
| 99 | - if ( ! empty( $request[ $key ] ) ) { |
|
| 98 | + foreach ($taxonomies as $taxonomy => $key) { |
|
| 99 | + if ( ! empty($request[$key])) { |
|
| 100 | 100 | $tax_query[] = array( |
| 101 | 101 | 'taxonomy' => $taxonomy, |
| 102 | 102 | 'field' => 'term_id', |
| 103 | - 'terms' => $request[ $key ], |
|
| 103 | + 'terms' => $request[$key], |
|
| 104 | 104 | ); |
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | // Filter product type by slug. |
| 109 | - if ( ! empty( $request['type'] ) ) { |
|
| 109 | + if ( ! empty($request['type'])) { |
|
| 110 | 110 | $tax_query[] = array( |
| 111 | 111 | 'taxonomy' => 'product_type', |
| 112 | 112 | 'field' => 'slug', |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | // Filter by attribute and term. |
| 118 | - if ( ! empty( $request['attribute'] ) && ! empty( $request['attribute_term'] ) ) { |
|
| 119 | - if ( in_array( $request['attribute'], wc_get_attribute_taxonomy_names(), true ) ) { |
|
| 118 | + if ( ! empty($request['attribute']) && ! empty($request['attribute_term'])) { |
|
| 119 | + if (in_array($request['attribute'], wc_get_attribute_taxonomy_names(), true)) { |
|
| 120 | 120 | $tax_query[] = array( |
| 121 | 121 | 'taxonomy' => $request['attribute'], |
| 122 | 122 | 'field' => 'term_id', |
@@ -126,16 +126,16 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Build tax_query if taxonomies are set. |
| 129 | - if ( ! empty( $tax_query ) ) { |
|
| 130 | - if ( ! empty( $args['tax_query'] ) ) { |
|
| 131 | - $args['tax_query'] = array_merge( $tax_query, $args['tax_query'] ); // WPCS: slow query ok. |
|
| 129 | + if ( ! empty($tax_query)) { |
|
| 130 | + if ( ! empty($args['tax_query'])) { |
|
| 131 | + $args['tax_query'] = array_merge($tax_query, $args['tax_query']); // WPCS: slow query ok. |
|
| 132 | 132 | } else { |
| 133 | 133 | $args['tax_query'] = $tax_query; // WPCS: slow query ok. |
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // Filter featured. |
| 138 | - if ( is_bool( $request['featured'] ) ) { |
|
| 138 | + if (is_bool($request['featured'])) { |
|
| 139 | 139 | $args['tax_query'][] = array( |
| 140 | 140 | 'taxonomy' => 'product_visibility', |
| 141 | 141 | 'field' => 'name', |
@@ -145,10 +145,10 @@ discard block |
||
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // Filter by sku. |
| 148 | - if ( ! empty( $request['sku'] ) ) { |
|
| 149 | - $skus = explode( ',', $request['sku'] ); |
|
| 148 | + if ( ! empty($request['sku'])) { |
|
| 149 | + $skus = explode(',', $request['sku']); |
|
| 150 | 150 | // Include the current string as a SKU too. |
| 151 | - if ( 1 < count( $skus ) ) { |
|
| 151 | + if (1 < count($skus)) { |
|
| 152 | 152 | $skus[] = $request['sku']; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // Filter by tax class. |
| 165 | - if ( ! empty( $request['tax_class'] ) ) { |
|
| 165 | + if ( ! empty($request['tax_class'])) { |
|
| 166 | 166 | $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
| 167 | 167 | $args, array( |
| 168 | 168 | 'key' => '_tax_class', |
@@ -172,12 +172,12 @@ discard block |
||
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // Price filter. |
| 175 | - if ( ! empty( $request['min_price'] ) || ! empty( $request['max_price'] ) ) { |
|
| 176 | - $args['meta_query'] = $this->add_meta_query( $args, wc_get_min_max_price_meta_query( $request ) ); // WPCS: slow query ok. |
|
| 175 | + if ( ! empty($request['min_price']) || ! empty($request['max_price'])) { |
|
| 176 | + $args['meta_query'] = $this->add_meta_query($args, wc_get_min_max_price_meta_query($request)); // WPCS: slow query ok. |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | // Filter product by stock_status. |
| 180 | - if ( ! empty( $request['stock_status'] ) ) { |
|
| 180 | + if ( ! empty($request['stock_status'])) { |
|
| 181 | 181 | $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
| 182 | 182 | $args, array( |
| 183 | 183 | 'key' => '_stock_status', |
@@ -187,30 +187,30 @@ discard block |
||
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // Filter by on sale products. |
| 190 | - if ( is_bool( $request['on_sale'] ) ) { |
|
| 190 | + if (is_bool($request['on_sale'])) { |
|
| 191 | 191 | $on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in'; |
| 192 | 192 | $on_sale_ids = wc_get_product_ids_on_sale(); |
| 193 | 193 | |
| 194 | 194 | // Use 0 when there's no on sale products to avoid return all products. |
| 195 | - $on_sale_ids = empty( $on_sale_ids ) ? array( 0 ) : $on_sale_ids; |
|
| 195 | + $on_sale_ids = empty($on_sale_ids) ? array(0) : $on_sale_ids; |
|
| 196 | 196 | |
| 197 | - $args[ $on_sale_key ] += $on_sale_ids; |
|
| 197 | + $args[$on_sale_key] += $on_sale_ids; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Force the post_type argument, since it's not a user input variable. |
| 201 | - if ( ! empty( $request['sku'] ) ) { |
|
| 202 | - $args['post_type'] = array( 'product', 'product_variation' ); |
|
| 201 | + if ( ! empty($request['sku'])) { |
|
| 202 | + $args['post_type'] = array('product', 'product_variation'); |
|
| 203 | 203 | } else { |
| 204 | 204 | $args['post_type'] = $this->post_type; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - $orderby = $request->get_param( 'orderby' ); |
|
| 208 | - $order = $request->get_param( 'order' ); |
|
| 207 | + $orderby = $request->get_param('orderby'); |
|
| 208 | + $order = $request->get_param('order'); |
|
| 209 | 209 | |
| 210 | - $ordering_args = WC()->query->get_catalog_ordering_args( $orderby, $order ); |
|
| 210 | + $ordering_args = WC()->query->get_catalog_ordering_args($orderby, $order); |
|
| 211 | 211 | $args['orderby'] = $ordering_args['orderby']; |
| 212 | 212 | $args['order'] = $ordering_args['order']; |
| 213 | - if ( $ordering_args['meta_key'] ) { |
|
| 213 | + if ($ordering_args['meta_key']) { |
|
| 214 | 214 | $args['meta_key'] = $ordering_args['meta_key']; // WPCS: slow query ok. |
| 215 | 215 | } |
| 216 | 216 | |
@@ -225,49 +225,49 @@ discard block |
||
| 225 | 225 | * @param array $images Images data. |
| 226 | 226 | * @return WC_Product |
| 227 | 227 | */ |
| 228 | - protected function set_product_images( $product, $images ) { |
|
| 229 | - $images = is_array( $images ) ? array_filter( $images ) : array(); |
|
| 228 | + protected function set_product_images($product, $images) { |
|
| 229 | + $images = is_array($images) ? array_filter($images) : array(); |
|
| 230 | 230 | |
| 231 | - if ( ! empty( $images ) ) { |
|
| 231 | + if ( ! empty($images)) { |
|
| 232 | 232 | $gallery = array(); |
| 233 | 233 | |
| 234 | - foreach ( $images as $index => $image ) { |
|
| 235 | - $attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0; |
|
| 234 | + foreach ($images as $index => $image) { |
|
| 235 | + $attachment_id = isset($image['id']) ? absint($image['id']) : 0; |
|
| 236 | 236 | |
| 237 | - if ( 0 === $attachment_id && isset( $image['src'] ) ) { |
|
| 238 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) ); |
|
| 237 | + if (0 === $attachment_id && isset($image['src'])) { |
|
| 238 | + $upload = wc_rest_upload_image_from_url(esc_url_raw($image['src'])); |
|
| 239 | 239 | |
| 240 | - if ( is_wp_error( $upload ) ) { |
|
| 241 | - if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $product->get_id(), $images ) ) { |
|
| 242 | - throw new WC_REST_Exception( 'woocommerce_product_image_upload_error', $upload->get_error_message(), 400 ); |
|
| 240 | + if (is_wp_error($upload)) { |
|
| 241 | + if ( ! apply_filters('woocommerce_rest_suppress_image_upload_error', false, $upload, $product->get_id(), $images)) { |
|
| 242 | + throw new WC_REST_Exception('woocommerce_product_image_upload_error', $upload->get_error_message(), 400); |
|
| 243 | 243 | } else { |
| 244 | 244 | continue; |
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - $attachment_id = wc_rest_set_uploaded_image_as_attachment( $upload, $product->get_id() ); |
|
| 248 | + $attachment_id = wc_rest_set_uploaded_image_as_attachment($upload, $product->get_id()); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - if ( ! wp_attachment_is_image( $attachment_id ) ) { |
|
| 251 | + if ( ! wp_attachment_is_image($attachment_id)) { |
|
| 252 | 252 | /* translators: %s: image ID */ |
| 253 | - throw new WC_REST_Exception( 'woocommerce_product_invalid_image_id', sprintf( __( '#%s is an invalid image ID.', 'woocommerce' ), $attachment_id ), 400 ); |
|
| 253 | + throw new WC_REST_Exception('woocommerce_product_invalid_image_id', sprintf(__('#%s is an invalid image ID.', 'woocommerce'), $attachment_id), 400); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | $featured_image = $product->get_image_id(); |
| 257 | 257 | |
| 258 | - if ( 0 === $index ) { |
|
| 259 | - $product->set_image_id( $attachment_id ); |
|
| 258 | + if (0 === $index) { |
|
| 259 | + $product->set_image_id($attachment_id); |
|
| 260 | 260 | } else { |
| 261 | 261 | $gallery[] = $attachment_id; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // Set the image alt if present. |
| 265 | - if ( ! empty( $image['alt'] ) ) { |
|
| 266 | - update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) ); |
|
| 265 | + if ( ! empty($image['alt'])) { |
|
| 266 | + update_post_meta($attachment_id, '_wp_attachment_image_alt', wc_clean($image['alt'])); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // Set the image name if present. |
| 270 | - if ( ! empty( $image['name'] ) ) { |
|
| 270 | + if ( ! empty($image['name'])) { |
|
| 271 | 271 | wp_update_post( |
| 272 | 272 | array( |
| 273 | 273 | 'ID' => $attachment_id, |
@@ -277,10 +277,10 @@ discard block |
||
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - $product->set_gallery_image_ids( $gallery ); |
|
| 280 | + $product->set_gallery_image_ids($gallery); |
|
| 281 | 281 | } else { |
| 282 | - $product->set_image_id( '' ); |
|
| 283 | - $product->set_gallery_image_ids( array() ); |
|
| 282 | + $product->set_image_id(''); |
|
| 283 | + $product->set_gallery_image_ids(array()); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | return $product; |
@@ -293,381 +293,381 @@ discard block |
||
| 293 | 293 | * @param bool $creating If is creating a new object. |
| 294 | 294 | * @return WP_Error|WC_Data |
| 295 | 295 | */ |
| 296 | - protected function prepare_object_for_database( $request, $creating = false ) { |
|
| 297 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
| 296 | + protected function prepare_object_for_database($request, $creating = false) { |
|
| 297 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
| 298 | 298 | |
| 299 | 299 | // Type is the most important part here because we need to be using the correct class and methods. |
| 300 | - if ( isset( $request['type'] ) ) { |
|
| 301 | - $classname = WC_Product_Factory::get_classname_from_product_type( $request['type'] ); |
|
| 300 | + if (isset($request['type'])) { |
|
| 301 | + $classname = WC_Product_Factory::get_classname_from_product_type($request['type']); |
|
| 302 | 302 | |
| 303 | - if ( ! class_exists( $classname ) ) { |
|
| 303 | + if ( ! class_exists($classname)) { |
|
| 304 | 304 | $classname = 'WC_Product_Simple'; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - $product = new $classname( $id ); |
|
| 308 | - } elseif ( isset( $request['id'] ) ) { |
|
| 309 | - $product = wc_get_product( $id ); |
|
| 307 | + $product = new $classname($id); |
|
| 308 | + } elseif (isset($request['id'])) { |
|
| 309 | + $product = wc_get_product($id); |
|
| 310 | 310 | } else { |
| 311 | 311 | $product = new WC_Product_Simple(); |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - if ( 'variation' === $product->get_type() ) { |
|
| 314 | + if ('variation' === $product->get_type()) { |
|
| 315 | 315 | return new WP_Error( |
| 316 | - "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( |
|
| 316 | + "woocommerce_rest_invalid_{$this->post_type}_id", __('To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce'), array( |
|
| 317 | 317 | 'status' => 404, |
| 318 | 318 | ) |
| 319 | 319 | ); |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | // Post title. |
| 323 | - if ( isset( $request['name'] ) ) { |
|
| 324 | - $product->set_name( wp_filter_post_kses( $request['name'] ) ); |
|
| 323 | + if (isset($request['name'])) { |
|
| 324 | + $product->set_name(wp_filter_post_kses($request['name'])); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | // Post content. |
| 328 | - if ( isset( $request['description'] ) ) { |
|
| 329 | - $product->set_description( wp_filter_post_kses( $request['description'] ) ); |
|
| 328 | + if (isset($request['description'])) { |
|
| 329 | + $product->set_description(wp_filter_post_kses($request['description'])); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | // Post excerpt. |
| 333 | - if ( isset( $request['short_description'] ) ) { |
|
| 334 | - $product->set_short_description( wp_filter_post_kses( $request['short_description'] ) ); |
|
| 333 | + if (isset($request['short_description'])) { |
|
| 334 | + $product->set_short_description(wp_filter_post_kses($request['short_description'])); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | // Post status. |
| 338 | - if ( isset( $request['status'] ) ) { |
|
| 339 | - $product->set_status( get_post_status_object( $request['status'] ) ? $request['status'] : 'draft' ); |
|
| 338 | + if (isset($request['status'])) { |
|
| 339 | + $product->set_status(get_post_status_object($request['status']) ? $request['status'] : 'draft'); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | // Post slug. |
| 343 | - if ( isset( $request['slug'] ) ) { |
|
| 344 | - $product->set_slug( $request['slug'] ); |
|
| 343 | + if (isset($request['slug'])) { |
|
| 344 | + $product->set_slug($request['slug']); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | // Menu order. |
| 348 | - if ( isset( $request['menu_order'] ) ) { |
|
| 349 | - $product->set_menu_order( $request['menu_order'] ); |
|
| 348 | + if (isset($request['menu_order'])) { |
|
| 349 | + $product->set_menu_order($request['menu_order']); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | // Comment status. |
| 353 | - if ( isset( $request['reviews_allowed'] ) ) { |
|
| 354 | - $product->set_reviews_allowed( $request['reviews_allowed'] ); |
|
| 353 | + if (isset($request['reviews_allowed'])) { |
|
| 354 | + $product->set_reviews_allowed($request['reviews_allowed']); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | // Virtual. |
| 358 | - if ( isset( $request['virtual'] ) ) { |
|
| 359 | - $product->set_virtual( $request['virtual'] ); |
|
| 358 | + if (isset($request['virtual'])) { |
|
| 359 | + $product->set_virtual($request['virtual']); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | // Tax status. |
| 363 | - if ( isset( $request['tax_status'] ) ) { |
|
| 364 | - $product->set_tax_status( $request['tax_status'] ); |
|
| 363 | + if (isset($request['tax_status'])) { |
|
| 364 | + $product->set_tax_status($request['tax_status']); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | // Tax Class. |
| 368 | - if ( isset( $request['tax_class'] ) ) { |
|
| 369 | - $product->set_tax_class( $request['tax_class'] ); |
|
| 368 | + if (isset($request['tax_class'])) { |
|
| 369 | + $product->set_tax_class($request['tax_class']); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | // Catalog Visibility. |
| 373 | - if ( isset( $request['catalog_visibility'] ) ) { |
|
| 374 | - $product->set_catalog_visibility( $request['catalog_visibility'] ); |
|
| 373 | + if (isset($request['catalog_visibility'])) { |
|
| 374 | + $product->set_catalog_visibility($request['catalog_visibility']); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | // Purchase Note. |
| 378 | - if ( isset( $request['purchase_note'] ) ) { |
|
| 379 | - $product->set_purchase_note( wp_kses_post( wp_unslash( $request['purchase_note'] ) ) ); |
|
| 378 | + if (isset($request['purchase_note'])) { |
|
| 379 | + $product->set_purchase_note(wp_kses_post(wp_unslash($request['purchase_note']))); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | // Featured Product. |
| 383 | - if ( isset( $request['featured'] ) ) { |
|
| 384 | - $product->set_featured( $request['featured'] ); |
|
| 383 | + if (isset($request['featured'])) { |
|
| 384 | + $product->set_featured($request['featured']); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | // Shipping data. |
| 388 | - $product = $this->save_product_shipping_data( $product, $request ); |
|
| 388 | + $product = $this->save_product_shipping_data($product, $request); |
|
| 389 | 389 | |
| 390 | 390 | // SKU. |
| 391 | - if ( isset( $request['sku'] ) ) { |
|
| 392 | - $product->set_sku( wc_clean( $request['sku'] ) ); |
|
| 391 | + if (isset($request['sku'])) { |
|
| 392 | + $product->set_sku(wc_clean($request['sku'])); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | // Attributes. |
| 396 | - if ( isset( $request['attributes'] ) ) { |
|
| 396 | + if (isset($request['attributes'])) { |
|
| 397 | 397 | $attributes = array(); |
| 398 | 398 | |
| 399 | - foreach ( $request['attributes'] as $attribute ) { |
|
| 399 | + foreach ($request['attributes'] as $attribute) { |
|
| 400 | 400 | $attribute_id = 0; |
| 401 | 401 | $attribute_name = ''; |
| 402 | 402 | |
| 403 | 403 | // Check ID for global attributes or name for product attributes. |
| 404 | - if ( ! empty( $attribute['id'] ) ) { |
|
| 405 | - $attribute_id = absint( $attribute['id'] ); |
|
| 406 | - $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
|
| 407 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
| 408 | - $attribute_name = wc_clean( $attribute['name'] ); |
|
| 404 | + if ( ! empty($attribute['id'])) { |
|
| 405 | + $attribute_id = absint($attribute['id']); |
|
| 406 | + $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id); |
|
| 407 | + } elseif ( ! empty($attribute['name'])) { |
|
| 408 | + $attribute_name = wc_clean($attribute['name']); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - if ( ! $attribute_id && ! $attribute_name ) { |
|
| 411 | + if ( ! $attribute_id && ! $attribute_name) { |
|
| 412 | 412 | continue; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - if ( $attribute_id ) { |
|
| 415 | + if ($attribute_id) { |
|
| 416 | 416 | |
| 417 | - if ( isset( $attribute['options'] ) ) { |
|
| 417 | + if (isset($attribute['options'])) { |
|
| 418 | 418 | $options = $attribute['options']; |
| 419 | 419 | |
| 420 | - if ( ! is_array( $attribute['options'] ) ) { |
|
| 420 | + if ( ! is_array($attribute['options'])) { |
|
| 421 | 421 | // Text based attributes - Posted values are term names. |
| 422 | - $options = explode( WC_DELIMITER, $options ); |
|
| 422 | + $options = explode(WC_DELIMITER, $options); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | - $values = array_map( 'wc_sanitize_term_text_based', $options ); |
|
| 426 | - $values = array_filter( $values, 'strlen' ); |
|
| 425 | + $values = array_map('wc_sanitize_term_text_based', $options); |
|
| 426 | + $values = array_filter($values, 'strlen'); |
|
| 427 | 427 | } else { |
| 428 | 428 | $values = array(); |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | - if ( ! empty( $values ) ) { |
|
| 431 | + if ( ! empty($values)) { |
|
| 432 | 432 | // Add attribute to array, but don't set values. |
| 433 | 433 | $attribute_object = new WC_Product_Attribute(); |
| 434 | - $attribute_object->set_id( $attribute_id ); |
|
| 435 | - $attribute_object->set_name( $attribute_name ); |
|
| 436 | - $attribute_object->set_options( $values ); |
|
| 437 | - $attribute_object->set_position( isset( $attribute['position'] ) ? (string) absint( $attribute['position'] ) : '0' ); |
|
| 438 | - $attribute_object->set_visible( ( isset( $attribute['visible'] ) && $attribute['visible'] ) ? 1 : 0 ); |
|
| 439 | - $attribute_object->set_variation( ( isset( $attribute['variation'] ) && $attribute['variation'] ) ? 1 : 0 ); |
|
| 434 | + $attribute_object->set_id($attribute_id); |
|
| 435 | + $attribute_object->set_name($attribute_name); |
|
| 436 | + $attribute_object->set_options($values); |
|
| 437 | + $attribute_object->set_position(isset($attribute['position']) ? (string) absint($attribute['position']) : '0'); |
|
| 438 | + $attribute_object->set_visible((isset($attribute['visible']) && $attribute['visible']) ? 1 : 0); |
|
| 439 | + $attribute_object->set_variation((isset($attribute['variation']) && $attribute['variation']) ? 1 : 0); |
|
| 440 | 440 | $attributes[] = $attribute_object; |
| 441 | 441 | } |
| 442 | - } elseif ( isset( $attribute['options'] ) ) { |
|
| 442 | + } elseif (isset($attribute['options'])) { |
|
| 443 | 443 | // Custom attribute - Add attribute to array and set the values. |
| 444 | - if ( is_array( $attribute['options'] ) ) { |
|
| 444 | + if (is_array($attribute['options'])) { |
|
| 445 | 445 | $values = $attribute['options']; |
| 446 | 446 | } else { |
| 447 | - $values = explode( WC_DELIMITER, $attribute['options'] ); |
|
| 447 | + $values = explode(WC_DELIMITER, $attribute['options']); |
|
| 448 | 448 | } |
| 449 | 449 | $attribute_object = new WC_Product_Attribute(); |
| 450 | - $attribute_object->set_name( $attribute_name ); |
|
| 451 | - $attribute_object->set_options( $values ); |
|
| 452 | - $attribute_object->set_position( isset( $attribute['position'] ) ? (string) absint( $attribute['position'] ) : '0' ); |
|
| 453 | - $attribute_object->set_visible( ( isset( $attribute['visible'] ) && $attribute['visible'] ) ? 1 : 0 ); |
|
| 454 | - $attribute_object->set_variation( ( isset( $attribute['variation'] ) && $attribute['variation'] ) ? 1 : 0 ); |
|
| 450 | + $attribute_object->set_name($attribute_name); |
|
| 451 | + $attribute_object->set_options($values); |
|
| 452 | + $attribute_object->set_position(isset($attribute['position']) ? (string) absint($attribute['position']) : '0'); |
|
| 453 | + $attribute_object->set_visible((isset($attribute['visible']) && $attribute['visible']) ? 1 : 0); |
|
| 454 | + $attribute_object->set_variation((isset($attribute['variation']) && $attribute['variation']) ? 1 : 0); |
|
| 455 | 455 | $attributes[] = $attribute_object; |
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | - $product->set_attributes( $attributes ); |
|
| 458 | + $product->set_attributes($attributes); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | // Sales and prices. |
| 462 | - if ( in_array( $product->get_type(), array( 'variable', 'grouped' ), true ) ) { |
|
| 463 | - $product->set_regular_price( '' ); |
|
| 464 | - $product->set_sale_price( '' ); |
|
| 465 | - $product->set_date_on_sale_to( '' ); |
|
| 466 | - $product->set_date_on_sale_from( '' ); |
|
| 467 | - $product->set_price( '' ); |
|
| 462 | + if (in_array($product->get_type(), array('variable', 'grouped'), true)) { |
|
| 463 | + $product->set_regular_price(''); |
|
| 464 | + $product->set_sale_price(''); |
|
| 465 | + $product->set_date_on_sale_to(''); |
|
| 466 | + $product->set_date_on_sale_from(''); |
|
| 467 | + $product->set_price(''); |
|
| 468 | 468 | } else { |
| 469 | 469 | // Regular Price. |
| 470 | - if ( isset( $request['regular_price'] ) ) { |
|
| 471 | - $product->set_regular_price( $request['regular_price'] ); |
|
| 470 | + if (isset($request['regular_price'])) { |
|
| 471 | + $product->set_regular_price($request['regular_price']); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | // Sale Price. |
| 475 | - if ( isset( $request['sale_price'] ) ) { |
|
| 476 | - $product->set_sale_price( $request['sale_price'] ); |
|
| 475 | + if (isset($request['sale_price'])) { |
|
| 476 | + $product->set_sale_price($request['sale_price']); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | - if ( isset( $request['date_on_sale_from'] ) ) { |
|
| 480 | - $product->set_date_on_sale_from( $request['date_on_sale_from'] ); |
|
| 479 | + if (isset($request['date_on_sale_from'])) { |
|
| 480 | + $product->set_date_on_sale_from($request['date_on_sale_from']); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | - if ( isset( $request['date_on_sale_from_gmt'] ) ) { |
|
| 484 | - $product->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null ); |
|
| 483 | + if (isset($request['date_on_sale_from_gmt'])) { |
|
| 484 | + $product->set_date_on_sale_from($request['date_on_sale_from_gmt'] ? strtotime($request['date_on_sale_from_gmt']) : null); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | - if ( isset( $request['date_on_sale_to'] ) ) { |
|
| 488 | - $product->set_date_on_sale_to( $request['date_on_sale_to'] ); |
|
| 487 | + if (isset($request['date_on_sale_to'])) { |
|
| 488 | + $product->set_date_on_sale_to($request['date_on_sale_to']); |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | - if ( isset( $request['date_on_sale_to_gmt'] ) ) { |
|
| 492 | - $product->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null ); |
|
| 491 | + if (isset($request['date_on_sale_to_gmt'])) { |
|
| 492 | + $product->set_date_on_sale_to($request['date_on_sale_to_gmt'] ? strtotime($request['date_on_sale_to_gmt']) : null); |
|
| 493 | 493 | } |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | // Product parent ID. |
| 497 | - if ( isset( $request['parent_id'] ) ) { |
|
| 498 | - $product->set_parent_id( $request['parent_id'] ); |
|
| 497 | + if (isset($request['parent_id'])) { |
|
| 498 | + $product->set_parent_id($request['parent_id']); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | // Sold individually. |
| 502 | - if ( isset( $request['sold_individually'] ) ) { |
|
| 503 | - $product->set_sold_individually( $request['sold_individually'] ); |
|
| 502 | + if (isset($request['sold_individually'])) { |
|
| 503 | + $product->set_sold_individually($request['sold_individually']); |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | // Stock status; stock_status has priority over in_stock. |
| 507 | - if ( isset( $request['stock_status'] ) ) { |
|
| 507 | + if (isset($request['stock_status'])) { |
|
| 508 | 508 | $stock_status = $request['stock_status']; |
| 509 | 509 | } else { |
| 510 | 510 | $stock_status = $product->get_stock_status(); |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | // Stock data. |
| 514 | - if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) { |
|
| 514 | + if ('yes' === get_option('woocommerce_manage_stock')) { |
|
| 515 | 515 | // Manage stock. |
| 516 | - if ( isset( $request['manage_stock'] ) ) { |
|
| 517 | - $product->set_manage_stock( $request['manage_stock'] ); |
|
| 516 | + if (isset($request['manage_stock'])) { |
|
| 517 | + $product->set_manage_stock($request['manage_stock']); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | // Backorders. |
| 521 | - if ( isset( $request['backorders'] ) ) { |
|
| 522 | - $product->set_backorders( $request['backorders'] ); |
|
| 521 | + if (isset($request['backorders'])) { |
|
| 522 | + $product->set_backorders($request['backorders']); |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | - if ( $product->is_type( 'grouped' ) ) { |
|
| 526 | - $product->set_manage_stock( 'no' ); |
|
| 527 | - $product->set_backorders( 'no' ); |
|
| 528 | - $product->set_stock_quantity( '' ); |
|
| 529 | - $product->set_stock_status( $stock_status ); |
|
| 530 | - } elseif ( $product->is_type( 'external' ) ) { |
|
| 531 | - $product->set_manage_stock( 'no' ); |
|
| 532 | - $product->set_backorders( 'no' ); |
|
| 533 | - $product->set_stock_quantity( '' ); |
|
| 534 | - $product->set_stock_status( 'instock' ); |
|
| 535 | - } elseif ( $product->get_manage_stock() ) { |
|
| 525 | + if ($product->is_type('grouped')) { |
|
| 526 | + $product->set_manage_stock('no'); |
|
| 527 | + $product->set_backorders('no'); |
|
| 528 | + $product->set_stock_quantity(''); |
|
| 529 | + $product->set_stock_status($stock_status); |
|
| 530 | + } elseif ($product->is_type('external')) { |
|
| 531 | + $product->set_manage_stock('no'); |
|
| 532 | + $product->set_backorders('no'); |
|
| 533 | + $product->set_stock_quantity(''); |
|
| 534 | + $product->set_stock_status('instock'); |
|
| 535 | + } elseif ($product->get_manage_stock()) { |
|
| 536 | 536 | // Stock status is always determined by children so sync later. |
| 537 | - if ( ! $product->is_type( 'variable' ) ) { |
|
| 538 | - $product->set_stock_status( $stock_status ); |
|
| 537 | + if ( ! $product->is_type('variable')) { |
|
| 538 | + $product->set_stock_status($stock_status); |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | // Stock quantity. |
| 542 | - if ( isset( $request['stock_quantity'] ) ) { |
|
| 543 | - $product->set_stock_quantity( wc_stock_amount( $request['stock_quantity'] ) ); |
|
| 544 | - } elseif ( isset( $request['inventory_delta'] ) ) { |
|
| 545 | - $stock_quantity = wc_stock_amount( $product->get_stock_quantity() ); |
|
| 546 | - $stock_quantity += wc_stock_amount( $request['inventory_delta'] ); |
|
| 547 | - $product->set_stock_quantity( wc_stock_amount( $stock_quantity ) ); |
|
| 542 | + if (isset($request['stock_quantity'])) { |
|
| 543 | + $product->set_stock_quantity(wc_stock_amount($request['stock_quantity'])); |
|
| 544 | + } elseif (isset($request['inventory_delta'])) { |
|
| 545 | + $stock_quantity = wc_stock_amount($product->get_stock_quantity()); |
|
| 546 | + $stock_quantity += wc_stock_amount($request['inventory_delta']); |
|
| 547 | + $product->set_stock_quantity(wc_stock_amount($stock_quantity)); |
|
| 548 | 548 | } |
| 549 | 549 | } else { |
| 550 | 550 | // Don't manage stock. |
| 551 | - $product->set_manage_stock( 'no' ); |
|
| 552 | - $product->set_stock_quantity( '' ); |
|
| 553 | - $product->set_stock_status( $stock_status ); |
|
| 551 | + $product->set_manage_stock('no'); |
|
| 552 | + $product->set_stock_quantity(''); |
|
| 553 | + $product->set_stock_status($stock_status); |
|
| 554 | 554 | } |
| 555 | - } elseif ( ! $product->is_type( 'variable' ) ) { |
|
| 556 | - $product->set_stock_status( $stock_status ); |
|
| 555 | + } elseif ( ! $product->is_type('variable')) { |
|
| 556 | + $product->set_stock_status($stock_status); |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | // Upsells. |
| 560 | - if ( isset( $request['upsell_ids'] ) ) { |
|
| 560 | + if (isset($request['upsell_ids'])) { |
|
| 561 | 561 | $upsells = array(); |
| 562 | 562 | $ids = $request['upsell_ids']; |
| 563 | 563 | |
| 564 | - if ( ! empty( $ids ) ) { |
|
| 565 | - foreach ( $ids as $id ) { |
|
| 566 | - if ( $id && $id > 0 ) { |
|
| 564 | + if ( ! empty($ids)) { |
|
| 565 | + foreach ($ids as $id) { |
|
| 566 | + if ($id && $id > 0) { |
|
| 567 | 567 | $upsells[] = $id; |
| 568 | 568 | } |
| 569 | 569 | } |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | - $product->set_upsell_ids( $upsells ); |
|
| 572 | + $product->set_upsell_ids($upsells); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | // Cross sells. |
| 576 | - if ( isset( $request['cross_sell_ids'] ) ) { |
|
| 576 | + if (isset($request['cross_sell_ids'])) { |
|
| 577 | 577 | $crosssells = array(); |
| 578 | 578 | $ids = $request['cross_sell_ids']; |
| 579 | 579 | |
| 580 | - if ( ! empty( $ids ) ) { |
|
| 581 | - foreach ( $ids as $id ) { |
|
| 582 | - if ( $id && $id > 0 ) { |
|
| 580 | + if ( ! empty($ids)) { |
|
| 581 | + foreach ($ids as $id) { |
|
| 582 | + if ($id && $id > 0) { |
|
| 583 | 583 | $crosssells[] = $id; |
| 584 | 584 | } |
| 585 | 585 | } |
| 586 | 586 | } |
| 587 | 587 | |
| 588 | - $product->set_cross_sell_ids( $crosssells ); |
|
| 588 | + $product->set_cross_sell_ids($crosssells); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | // Product categories. |
| 592 | - if ( isset( $request['categories'] ) && is_array( $request['categories'] ) ) { |
|
| 593 | - $product = $this->save_taxonomy_terms( $product, $request['categories'] ); |
|
| 592 | + if (isset($request['categories']) && is_array($request['categories'])) { |
|
| 593 | + $product = $this->save_taxonomy_terms($product, $request['categories']); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | // Product tags. |
| 597 | - if ( isset( $request['tags'] ) && is_array( $request['tags'] ) ) { |
|
| 598 | - $product = $this->save_taxonomy_terms( $product, $request['tags'], 'tag' ); |
|
| 597 | + if (isset($request['tags']) && is_array($request['tags'])) { |
|
| 598 | + $product = $this->save_taxonomy_terms($product, $request['tags'], 'tag'); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | // Downloadable. |
| 602 | - if ( isset( $request['downloadable'] ) ) { |
|
| 603 | - $product->set_downloadable( $request['downloadable'] ); |
|
| 602 | + if (isset($request['downloadable'])) { |
|
| 603 | + $product->set_downloadable($request['downloadable']); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | // Downloadable options. |
| 607 | - if ( $product->get_downloadable() ) { |
|
| 607 | + if ($product->get_downloadable()) { |
|
| 608 | 608 | |
| 609 | 609 | // Downloadable files. |
| 610 | - if ( isset( $request['downloads'] ) && is_array( $request['downloads'] ) ) { |
|
| 611 | - $product = $this->save_downloadable_files( $product, $request['downloads'] ); |
|
| 610 | + if (isset($request['downloads']) && is_array($request['downloads'])) { |
|
| 611 | + $product = $this->save_downloadable_files($product, $request['downloads']); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | // Download limit. |
| 615 | - if ( isset( $request['download_limit'] ) ) { |
|
| 616 | - $product->set_download_limit( $request['download_limit'] ); |
|
| 615 | + if (isset($request['download_limit'])) { |
|
| 616 | + $product->set_download_limit($request['download_limit']); |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | // Download expiry. |
| 620 | - if ( isset( $request['download_expiry'] ) ) { |
|
| 621 | - $product->set_download_expiry( $request['download_expiry'] ); |
|
| 620 | + if (isset($request['download_expiry'])) { |
|
| 621 | + $product->set_download_expiry($request['download_expiry']); |
|
| 622 | 622 | } |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | // Product url and button text for external products. |
| 626 | - if ( $product->is_type( 'external' ) ) { |
|
| 627 | - if ( isset( $request['external_url'] ) ) { |
|
| 628 | - $product->set_product_url( $request['external_url'] ); |
|
| 626 | + if ($product->is_type('external')) { |
|
| 627 | + if (isset($request['external_url'])) { |
|
| 628 | + $product->set_product_url($request['external_url']); |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - if ( isset( $request['button_text'] ) ) { |
|
| 632 | - $product->set_button_text( $request['button_text'] ); |
|
| 631 | + if (isset($request['button_text'])) { |
|
| 632 | + $product->set_button_text($request['button_text']); |
|
| 633 | 633 | } |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | // Save default attributes for variable products. |
| 637 | - if ( $product->is_type( 'variable' ) ) { |
|
| 638 | - $product = $this->save_default_attributes( $product, $request ); |
|
| 637 | + if ($product->is_type('variable')) { |
|
| 638 | + $product = $this->save_default_attributes($product, $request); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | // Set children for a grouped product. |
| 642 | - if ( $product->is_type( 'grouped' ) && isset( $request['grouped_products'] ) ) { |
|
| 643 | - $product->set_children( $request['grouped_products'] ); |
|
| 642 | + if ($product->is_type('grouped') && isset($request['grouped_products'])) { |
|
| 643 | + $product->set_children($request['grouped_products']); |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | // Check for featured/gallery images, upload it and set it. |
| 647 | - if ( isset( $request['images'] ) ) { |
|
| 648 | - $product = $this->set_product_images( $product, $request['images'] ); |
|
| 647 | + if (isset($request['images'])) { |
|
| 648 | + $product = $this->set_product_images($product, $request['images']); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | // Allow set meta_data. |
| 652 | - if ( is_array( $request['meta_data'] ) ) { |
|
| 653 | - foreach ( $request['meta_data'] as $meta ) { |
|
| 654 | - $product->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
| 652 | + if (is_array($request['meta_data'])) { |
|
| 653 | + foreach ($request['meta_data'] as $meta) { |
|
| 654 | + $product->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
| 655 | 655 | } |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | - if ( ! empty( $request['date_created'] ) ) { |
|
| 659 | - $date = rest_parse_date( $request['date_created'] ); |
|
| 658 | + if ( ! empty($request['date_created'])) { |
|
| 659 | + $date = rest_parse_date($request['date_created']); |
|
| 660 | 660 | |
| 661 | - if ( $date ) { |
|
| 662 | - $product->set_date_created( $date ); |
|
| 661 | + if ($date) { |
|
| 662 | + $product->set_date_created($date); |
|
| 663 | 663 | } |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | - if ( ! empty( $request['date_created_gmt'] ) ) { |
|
| 667 | - $date = rest_parse_date( $request['date_created_gmt'], true ); |
|
| 666 | + if ( ! empty($request['date_created_gmt'])) { |
|
| 667 | + $date = rest_parse_date($request['date_created_gmt'], true); |
|
| 668 | 668 | |
| 669 | - if ( $date ) { |
|
| 670 | - $product->set_date_created( $date ); |
|
| 669 | + if ($date) { |
|
| 670 | + $product->set_date_created($date); |
|
| 671 | 671 | } |
| 672 | 672 | } |
| 673 | 673 | |
@@ -681,7 +681,7 @@ discard block |
||
| 681 | 681 | * @param WP_REST_Request $request Request object. |
| 682 | 682 | * @param bool $creating If is creating a new object. |
| 683 | 683 | */ |
| 684 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $product, $request, $creating ); |
|
| 684 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $product, $request, $creating); |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
@@ -690,613 +690,613 @@ discard block |
||
| 690 | 690 | * @return array |
| 691 | 691 | */ |
| 692 | 692 | public function get_item_schema() { |
| 693 | - $weight_unit = get_option( 'woocommerce_weight_unit' ); |
|
| 694 | - $dimension_unit = get_option( 'woocommerce_dimension_unit' ); |
|
| 693 | + $weight_unit = get_option('woocommerce_weight_unit'); |
|
| 694 | + $dimension_unit = get_option('woocommerce_dimension_unit'); |
|
| 695 | 695 | $schema = array( |
| 696 | 696 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 697 | 697 | 'title' => $this->post_type, |
| 698 | 698 | 'type' => 'object', |
| 699 | 699 | 'properties' => array( |
| 700 | 700 | 'id' => array( |
| 701 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 701 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 702 | 702 | 'type' => 'integer', |
| 703 | - 'context' => array( 'view', 'edit' ), |
|
| 703 | + 'context' => array('view', 'edit'), |
|
| 704 | 704 | 'readonly' => true, |
| 705 | 705 | ), |
| 706 | 706 | 'name' => array( |
| 707 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
| 707 | + 'description' => __('Product name.', 'woocommerce'), |
|
| 708 | 708 | 'type' => 'string', |
| 709 | - 'context' => array( 'view', 'edit' ), |
|
| 709 | + 'context' => array('view', 'edit'), |
|
| 710 | 710 | ), |
| 711 | 711 | 'slug' => array( |
| 712 | - 'description' => __( 'Product slug.', 'woocommerce' ), |
|
| 712 | + 'description' => __('Product slug.', 'woocommerce'), |
|
| 713 | 713 | 'type' => 'string', |
| 714 | - 'context' => array( 'view', 'edit' ), |
|
| 714 | + 'context' => array('view', 'edit'), |
|
| 715 | 715 | ), |
| 716 | 716 | 'permalink' => array( |
| 717 | - 'description' => __( 'Product URL.', 'woocommerce' ), |
|
| 717 | + 'description' => __('Product URL.', 'woocommerce'), |
|
| 718 | 718 | 'type' => 'string', |
| 719 | 719 | 'format' => 'uri', |
| 720 | - 'context' => array( 'view', 'edit' ), |
|
| 720 | + 'context' => array('view', 'edit'), |
|
| 721 | 721 | 'readonly' => true, |
| 722 | 722 | ), |
| 723 | 723 | 'date_created' => array( |
| 724 | - 'description' => __( "The date the product was created, in the site's timezone.", 'woocommerce' ), |
|
| 724 | + 'description' => __("The date the product was created, in the site's timezone.", 'woocommerce'), |
|
| 725 | 725 | 'type' => 'date-time', |
| 726 | - 'context' => array( 'view', 'edit' ), |
|
| 726 | + 'context' => array('view', 'edit'), |
|
| 727 | 727 | ), |
| 728 | 728 | 'date_created_gmt' => array( |
| 729 | - 'description' => __( 'The date the product was created, as GMT.', 'woocommerce' ), |
|
| 729 | + 'description' => __('The date the product was created, as GMT.', 'woocommerce'), |
|
| 730 | 730 | 'type' => 'date-time', |
| 731 | - 'context' => array( 'view', 'edit' ), |
|
| 731 | + 'context' => array('view', 'edit'), |
|
| 732 | 732 | ), |
| 733 | 733 | 'date_modified' => array( |
| 734 | - 'description' => __( "The date the product was last modified, in the site's timezone.", 'woocommerce' ), |
|
| 734 | + 'description' => __("The date the product was last modified, in the site's timezone.", 'woocommerce'), |
|
| 735 | 735 | 'type' => 'date-time', |
| 736 | - 'context' => array( 'view', 'edit' ), |
|
| 736 | + 'context' => array('view', 'edit'), |
|
| 737 | 737 | 'readonly' => true, |
| 738 | 738 | ), |
| 739 | 739 | 'date_modified_gmt' => array( |
| 740 | - 'description' => __( 'The date the product was last modified, as GMT.', 'woocommerce' ), |
|
| 740 | + 'description' => __('The date the product was last modified, as GMT.', 'woocommerce'), |
|
| 741 | 741 | 'type' => 'date-time', |
| 742 | - 'context' => array( 'view', 'edit' ), |
|
| 742 | + 'context' => array('view', 'edit'), |
|
| 743 | 743 | 'readonly' => true, |
| 744 | 744 | ), |
| 745 | 745 | 'type' => array( |
| 746 | - 'description' => __( 'Product type.', 'woocommerce' ), |
|
| 746 | + 'description' => __('Product type.', 'woocommerce'), |
|
| 747 | 747 | 'type' => 'string', |
| 748 | 748 | 'default' => 'simple', |
| 749 | - 'enum' => array_keys( wc_get_product_types() ), |
|
| 750 | - 'context' => array( 'view', 'edit' ), |
|
| 749 | + 'enum' => array_keys(wc_get_product_types()), |
|
| 750 | + 'context' => array('view', 'edit'), |
|
| 751 | 751 | ), |
| 752 | 752 | 'status' => array( |
| 753 | - 'description' => __( 'Product status (post status).', 'woocommerce' ), |
|
| 753 | + 'description' => __('Product status (post status).', 'woocommerce'), |
|
| 754 | 754 | 'type' => 'string', |
| 755 | 755 | 'default' => 'publish', |
| 756 | - 'enum' => array_merge( array_keys( get_post_statuses() ), array( 'future' ) ), |
|
| 757 | - 'context' => array( 'view', 'edit' ), |
|
| 756 | + 'enum' => array_merge(array_keys(get_post_statuses()), array('future')), |
|
| 757 | + 'context' => array('view', 'edit'), |
|
| 758 | 758 | ), |
| 759 | 759 | 'featured' => array( |
| 760 | - 'description' => __( 'Featured product.', 'woocommerce' ), |
|
| 760 | + 'description' => __('Featured product.', 'woocommerce'), |
|
| 761 | 761 | 'type' => 'boolean', |
| 762 | 762 | 'default' => false, |
| 763 | - 'context' => array( 'view', 'edit' ), |
|
| 763 | + 'context' => array('view', 'edit'), |
|
| 764 | 764 | ), |
| 765 | 765 | 'catalog_visibility' => array( |
| 766 | - 'description' => __( 'Catalog visibility.', 'woocommerce' ), |
|
| 766 | + 'description' => __('Catalog visibility.', 'woocommerce'), |
|
| 767 | 767 | 'type' => 'string', |
| 768 | 768 | 'default' => 'visible', |
| 769 | - 'enum' => array( 'visible', 'catalog', 'search', 'hidden' ), |
|
| 770 | - 'context' => array( 'view', 'edit' ), |
|
| 769 | + 'enum' => array('visible', 'catalog', 'search', 'hidden'), |
|
| 770 | + 'context' => array('view', 'edit'), |
|
| 771 | 771 | ), |
| 772 | 772 | 'description' => array( |
| 773 | - 'description' => __( 'Product description.', 'woocommerce' ), |
|
| 773 | + 'description' => __('Product description.', 'woocommerce'), |
|
| 774 | 774 | 'type' => 'string', |
| 775 | - 'context' => array( 'view', 'edit' ), |
|
| 775 | + 'context' => array('view', 'edit'), |
|
| 776 | 776 | ), |
| 777 | 777 | 'short_description' => array( |
| 778 | - 'description' => __( 'Product short description.', 'woocommerce' ), |
|
| 778 | + 'description' => __('Product short description.', 'woocommerce'), |
|
| 779 | 779 | 'type' => 'string', |
| 780 | - 'context' => array( 'view', 'edit' ), |
|
| 780 | + 'context' => array('view', 'edit'), |
|
| 781 | 781 | ), |
| 782 | 782 | 'sku' => array( |
| 783 | - 'description' => __( 'Unique identifier.', 'woocommerce' ), |
|
| 783 | + 'description' => __('Unique identifier.', 'woocommerce'), |
|
| 784 | 784 | 'type' => 'string', |
| 785 | - 'context' => array( 'view', 'edit' ), |
|
| 785 | + 'context' => array('view', 'edit'), |
|
| 786 | 786 | ), |
| 787 | 787 | 'price' => array( |
| 788 | - 'description' => __( 'Current product price.', 'woocommerce' ), |
|
| 788 | + 'description' => __('Current product price.', 'woocommerce'), |
|
| 789 | 789 | 'type' => 'string', |
| 790 | - 'context' => array( 'view', 'edit' ), |
|
| 790 | + 'context' => array('view', 'edit'), |
|
| 791 | 791 | 'readonly' => true, |
| 792 | 792 | ), |
| 793 | 793 | 'regular_price' => array( |
| 794 | - 'description' => __( 'Product regular price.', 'woocommerce' ), |
|
| 794 | + 'description' => __('Product regular price.', 'woocommerce'), |
|
| 795 | 795 | 'type' => 'string', |
| 796 | - 'context' => array( 'view', 'edit' ), |
|
| 796 | + 'context' => array('view', 'edit'), |
|
| 797 | 797 | ), |
| 798 | 798 | 'sale_price' => array( |
| 799 | - 'description' => __( 'Product sale price.', 'woocommerce' ), |
|
| 799 | + 'description' => __('Product sale price.', 'woocommerce'), |
|
| 800 | 800 | 'type' => 'string', |
| 801 | - 'context' => array( 'view', 'edit' ), |
|
| 801 | + 'context' => array('view', 'edit'), |
|
| 802 | 802 | ), |
| 803 | 803 | 'date_on_sale_from' => array( |
| 804 | - 'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ), |
|
| 804 | + 'description' => __("Start date of sale price, in the site's timezone.", 'woocommerce'), |
|
| 805 | 805 | 'type' => 'date-time', |
| 806 | - 'context' => array( 'view', 'edit' ), |
|
| 806 | + 'context' => array('view', 'edit'), |
|
| 807 | 807 | ), |
| 808 | 808 | 'date_on_sale_from_gmt' => array( |
| 809 | - 'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ), |
|
| 809 | + 'description' => __('Start date of sale price, as GMT.', 'woocommerce'), |
|
| 810 | 810 | 'type' => 'date-time', |
| 811 | - 'context' => array( 'view', 'edit' ), |
|
| 811 | + 'context' => array('view', 'edit'), |
|
| 812 | 812 | ), |
| 813 | 813 | 'date_on_sale_to' => array( |
| 814 | - 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
|
| 814 | + 'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'), |
|
| 815 | 815 | 'type' => 'date-time', |
| 816 | - 'context' => array( 'view', 'edit' ), |
|
| 816 | + 'context' => array('view', 'edit'), |
|
| 817 | 817 | ), |
| 818 | 818 | 'date_on_sale_to_gmt' => array( |
| 819 | - 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
|
| 819 | + 'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'), |
|
| 820 | 820 | 'type' => 'date-time', |
| 821 | - 'context' => array( 'view', 'edit' ), |
|
| 821 | + 'context' => array('view', 'edit'), |
|
| 822 | 822 | ), |
| 823 | 823 | 'price_html' => array( |
| 824 | - 'description' => __( 'Price formatted in HTML.', 'woocommerce' ), |
|
| 824 | + 'description' => __('Price formatted in HTML.', 'woocommerce'), |
|
| 825 | 825 | 'type' => 'string', |
| 826 | - 'context' => array( 'view', 'edit' ), |
|
| 826 | + 'context' => array('view', 'edit'), |
|
| 827 | 827 | 'readonly' => true, |
| 828 | 828 | ), |
| 829 | 829 | 'on_sale' => array( |
| 830 | - 'description' => __( 'Shows if the product is on sale.', 'woocommerce' ), |
|
| 830 | + 'description' => __('Shows if the product is on sale.', 'woocommerce'), |
|
| 831 | 831 | 'type' => 'boolean', |
| 832 | - 'context' => array( 'view', 'edit' ), |
|
| 832 | + 'context' => array('view', 'edit'), |
|
| 833 | 833 | 'readonly' => true, |
| 834 | 834 | ), |
| 835 | 835 | 'purchasable' => array( |
| 836 | - 'description' => __( 'Shows if the product can be bought.', 'woocommerce' ), |
|
| 836 | + 'description' => __('Shows if the product can be bought.', 'woocommerce'), |
|
| 837 | 837 | 'type' => 'boolean', |
| 838 | - 'context' => array( 'view', 'edit' ), |
|
| 838 | + 'context' => array('view', 'edit'), |
|
| 839 | 839 | 'readonly' => true, |
| 840 | 840 | ), |
| 841 | 841 | 'total_sales' => array( |
| 842 | - 'description' => __( 'Amount of sales.', 'woocommerce' ), |
|
| 842 | + 'description' => __('Amount of sales.', 'woocommerce'), |
|
| 843 | 843 | 'type' => 'integer', |
| 844 | - 'context' => array( 'view', 'edit' ), |
|
| 844 | + 'context' => array('view', 'edit'), |
|
| 845 | 845 | 'readonly' => true, |
| 846 | 846 | ), |
| 847 | 847 | 'virtual' => array( |
| 848 | - 'description' => __( 'If the product is virtual.', 'woocommerce' ), |
|
| 848 | + 'description' => __('If the product is virtual.', 'woocommerce'), |
|
| 849 | 849 | 'type' => 'boolean', |
| 850 | 850 | 'default' => false, |
| 851 | - 'context' => array( 'view', 'edit' ), |
|
| 851 | + 'context' => array('view', 'edit'), |
|
| 852 | 852 | ), |
| 853 | 853 | 'downloadable' => array( |
| 854 | - 'description' => __( 'If the product is downloadable.', 'woocommerce' ), |
|
| 854 | + 'description' => __('If the product is downloadable.', 'woocommerce'), |
|
| 855 | 855 | 'type' => 'boolean', |
| 856 | 856 | 'default' => false, |
| 857 | - 'context' => array( 'view', 'edit' ), |
|
| 857 | + 'context' => array('view', 'edit'), |
|
| 858 | 858 | ), |
| 859 | 859 | 'downloads' => array( |
| 860 | - 'description' => __( 'List of downloadable files.', 'woocommerce' ), |
|
| 860 | + 'description' => __('List of downloadable files.', 'woocommerce'), |
|
| 861 | 861 | 'type' => 'array', |
| 862 | - 'context' => array( 'view', 'edit' ), |
|
| 862 | + 'context' => array('view', 'edit'), |
|
| 863 | 863 | 'items' => array( |
| 864 | 864 | 'type' => 'object', |
| 865 | 865 | 'properties' => array( |
| 866 | 866 | 'id' => array( |
| 867 | - 'description' => __( 'File ID.', 'woocommerce' ), |
|
| 867 | + 'description' => __('File ID.', 'woocommerce'), |
|
| 868 | 868 | 'type' => 'string', |
| 869 | - 'context' => array( 'view', 'edit' ), |
|
| 869 | + 'context' => array('view', 'edit'), |
|
| 870 | 870 | ), |
| 871 | 871 | 'name' => array( |
| 872 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
| 872 | + 'description' => __('File name.', 'woocommerce'), |
|
| 873 | 873 | 'type' => 'string', |
| 874 | - 'context' => array( 'view', 'edit' ), |
|
| 874 | + 'context' => array('view', 'edit'), |
|
| 875 | 875 | ), |
| 876 | 876 | 'file' => array( |
| 877 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
| 877 | + 'description' => __('File URL.', 'woocommerce'), |
|
| 878 | 878 | 'type' => 'string', |
| 879 | - 'context' => array( 'view', 'edit' ), |
|
| 879 | + 'context' => array('view', 'edit'), |
|
| 880 | 880 | ), |
| 881 | 881 | ), |
| 882 | 882 | ), |
| 883 | 883 | ), |
| 884 | 884 | 'download_limit' => array( |
| 885 | - 'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ), |
|
| 885 | + 'description' => __('Number of times downloadable files can be downloaded after purchase.', 'woocommerce'), |
|
| 886 | 886 | 'type' => 'integer', |
| 887 | 887 | 'default' => -1, |
| 888 | - 'context' => array( 'view', 'edit' ), |
|
| 888 | + 'context' => array('view', 'edit'), |
|
| 889 | 889 | ), |
| 890 | 890 | 'download_expiry' => array( |
| 891 | - 'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ), |
|
| 891 | + 'description' => __('Number of days until access to downloadable files expires.', 'woocommerce'), |
|
| 892 | 892 | 'type' => 'integer', |
| 893 | 893 | 'default' => -1, |
| 894 | - 'context' => array( 'view', 'edit' ), |
|
| 894 | + 'context' => array('view', 'edit'), |
|
| 895 | 895 | ), |
| 896 | 896 | 'external_url' => array( |
| 897 | - 'description' => __( 'Product external URL. Only for external products.', 'woocommerce' ), |
|
| 897 | + 'description' => __('Product external URL. Only for external products.', 'woocommerce'), |
|
| 898 | 898 | 'type' => 'string', |
| 899 | 899 | 'format' => 'uri', |
| 900 | - 'context' => array( 'view', 'edit' ), |
|
| 900 | + 'context' => array('view', 'edit'), |
|
| 901 | 901 | ), |
| 902 | 902 | 'button_text' => array( |
| 903 | - 'description' => __( 'Product external button text. Only for external products.', 'woocommerce' ), |
|
| 903 | + 'description' => __('Product external button text. Only for external products.', 'woocommerce'), |
|
| 904 | 904 | 'type' => 'string', |
| 905 | - 'context' => array( 'view', 'edit' ), |
|
| 905 | + 'context' => array('view', 'edit'), |
|
| 906 | 906 | ), |
| 907 | 907 | 'tax_status' => array( |
| 908 | - 'description' => __( 'Tax status.', 'woocommerce' ), |
|
| 908 | + 'description' => __('Tax status.', 'woocommerce'), |
|
| 909 | 909 | 'type' => 'string', |
| 910 | 910 | 'default' => 'taxable', |
| 911 | - 'enum' => array( 'taxable', 'shipping', 'none' ), |
|
| 912 | - 'context' => array( 'view', 'edit' ), |
|
| 911 | + 'enum' => array('taxable', 'shipping', 'none'), |
|
| 912 | + 'context' => array('view', 'edit'), |
|
| 913 | 913 | ), |
| 914 | 914 | 'tax_class' => array( |
| 915 | - 'description' => __( 'Tax class.', 'woocommerce' ), |
|
| 915 | + 'description' => __('Tax class.', 'woocommerce'), |
|
| 916 | 916 | 'type' => 'string', |
| 917 | - 'context' => array( 'view', 'edit' ), |
|
| 917 | + 'context' => array('view', 'edit'), |
|
| 918 | 918 | ), |
| 919 | 919 | 'manage_stock' => array( |
| 920 | - 'description' => __( 'Stock management at product level.', 'woocommerce' ), |
|
| 920 | + 'description' => __('Stock management at product level.', 'woocommerce'), |
|
| 921 | 921 | 'type' => 'boolean', |
| 922 | 922 | 'default' => false, |
| 923 | - 'context' => array( 'view', 'edit' ), |
|
| 923 | + 'context' => array('view', 'edit'), |
|
| 924 | 924 | ), |
| 925 | 925 | 'stock_quantity' => array( |
| 926 | - 'description' => __( 'Stock quantity.', 'woocommerce' ), |
|
| 926 | + 'description' => __('Stock quantity.', 'woocommerce'), |
|
| 927 | 927 | 'type' => 'integer', |
| 928 | - 'context' => array( 'view', 'edit' ), |
|
| 928 | + 'context' => array('view', 'edit'), |
|
| 929 | 929 | ), |
| 930 | 930 | 'stock_status' => array( |
| 931 | - 'description' => __( 'Controls the stock status of the product.', 'woocommerce' ), |
|
| 931 | + 'description' => __('Controls the stock status of the product.', 'woocommerce'), |
|
| 932 | 932 | 'type' => 'string', |
| 933 | 933 | 'default' => 'instock', |
| 934 | - 'enum' => array_keys( wc_get_product_stock_status_options() ), |
|
| 935 | - 'context' => array( 'view', 'edit' ), |
|
| 934 | + 'enum' => array_keys(wc_get_product_stock_status_options()), |
|
| 935 | + 'context' => array('view', 'edit'), |
|
| 936 | 936 | ), |
| 937 | 937 | 'backorders' => array( |
| 938 | - 'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ), |
|
| 938 | + 'description' => __('If managing stock, this controls if backorders are allowed.', 'woocommerce'), |
|
| 939 | 939 | 'type' => 'string', |
| 940 | 940 | 'default' => 'no', |
| 941 | - 'enum' => array( 'no', 'notify', 'yes' ), |
|
| 942 | - 'context' => array( 'view', 'edit' ), |
|
| 941 | + 'enum' => array('no', 'notify', 'yes'), |
|
| 942 | + 'context' => array('view', 'edit'), |
|
| 943 | 943 | ), |
| 944 | 944 | 'backorders_allowed' => array( |
| 945 | - 'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ), |
|
| 945 | + 'description' => __('Shows if backorders are allowed.', 'woocommerce'), |
|
| 946 | 946 | 'type' => 'boolean', |
| 947 | - 'context' => array( 'view', 'edit' ), |
|
| 947 | + 'context' => array('view', 'edit'), |
|
| 948 | 948 | 'readonly' => true, |
| 949 | 949 | ), |
| 950 | 950 | 'backordered' => array( |
| 951 | - 'description' => __( 'Shows if the product is on backordered.', 'woocommerce' ), |
|
| 951 | + 'description' => __('Shows if the product is on backordered.', 'woocommerce'), |
|
| 952 | 952 | 'type' => 'boolean', |
| 953 | - 'context' => array( 'view', 'edit' ), |
|
| 953 | + 'context' => array('view', 'edit'), |
|
| 954 | 954 | 'readonly' => true, |
| 955 | 955 | ), |
| 956 | 956 | 'sold_individually' => array( |
| 957 | - 'description' => __( 'Allow one item to be bought in a single order.', 'woocommerce' ), |
|
| 957 | + 'description' => __('Allow one item to be bought in a single order.', 'woocommerce'), |
|
| 958 | 958 | 'type' => 'boolean', |
| 959 | 959 | 'default' => false, |
| 960 | - 'context' => array( 'view', 'edit' ), |
|
| 960 | + 'context' => array('view', 'edit'), |
|
| 961 | 961 | ), |
| 962 | 962 | 'weight' => array( |
| 963 | 963 | /* translators: %s: weight unit */ |
| 964 | - 'description' => sprintf( __( 'Product weight (%s).', 'woocommerce' ), $weight_unit ), |
|
| 964 | + 'description' => sprintf(__('Product weight (%s).', 'woocommerce'), $weight_unit), |
|
| 965 | 965 | 'type' => 'string', |
| 966 | - 'context' => array( 'view', 'edit' ), |
|
| 966 | + 'context' => array('view', 'edit'), |
|
| 967 | 967 | ), |
| 968 | 968 | 'dimensions' => array( |
| 969 | - 'description' => __( 'Product dimensions.', 'woocommerce' ), |
|
| 969 | + 'description' => __('Product dimensions.', 'woocommerce'), |
|
| 970 | 970 | 'type' => 'object', |
| 971 | - 'context' => array( 'view', 'edit' ), |
|
| 971 | + 'context' => array('view', 'edit'), |
|
| 972 | 972 | 'properties' => array( |
| 973 | 973 | 'length' => array( |
| 974 | 974 | /* translators: %s: dimension unit */ |
| 975 | - 'description' => sprintf( __( 'Product length (%s).', 'woocommerce' ), $dimension_unit ), |
|
| 975 | + 'description' => sprintf(__('Product length (%s).', 'woocommerce'), $dimension_unit), |
|
| 976 | 976 | 'type' => 'string', |
| 977 | - 'context' => array( 'view', 'edit' ), |
|
| 977 | + 'context' => array('view', 'edit'), |
|
| 978 | 978 | ), |
| 979 | 979 | 'width' => array( |
| 980 | 980 | /* translators: %s: dimension unit */ |
| 981 | - 'description' => sprintf( __( 'Product width (%s).', 'woocommerce' ), $dimension_unit ), |
|
| 981 | + 'description' => sprintf(__('Product width (%s).', 'woocommerce'), $dimension_unit), |
|
| 982 | 982 | 'type' => 'string', |
| 983 | - 'context' => array( 'view', 'edit' ), |
|
| 983 | + 'context' => array('view', 'edit'), |
|
| 984 | 984 | ), |
| 985 | 985 | 'height' => array( |
| 986 | 986 | /* translators: %s: dimension unit */ |
| 987 | - 'description' => sprintf( __( 'Product height (%s).', 'woocommerce' ), $dimension_unit ), |
|
| 987 | + 'description' => sprintf(__('Product height (%s).', 'woocommerce'), $dimension_unit), |
|
| 988 | 988 | 'type' => 'string', |
| 989 | - 'context' => array( 'view', 'edit' ), |
|
| 989 | + 'context' => array('view', 'edit'), |
|
| 990 | 990 | ), |
| 991 | 991 | ), |
| 992 | 992 | ), |
| 993 | 993 | 'shipping_required' => array( |
| 994 | - 'description' => __( 'Shows if the product need to be shipped.', 'woocommerce' ), |
|
| 994 | + 'description' => __('Shows if the product need to be shipped.', 'woocommerce'), |
|
| 995 | 995 | 'type' => 'boolean', |
| 996 | - 'context' => array( 'view', 'edit' ), |
|
| 996 | + 'context' => array('view', 'edit'), |
|
| 997 | 997 | 'readonly' => true, |
| 998 | 998 | ), |
| 999 | 999 | 'shipping_taxable' => array( |
| 1000 | - 'description' => __( 'Shows whether or not the product shipping is taxable.', 'woocommerce' ), |
|
| 1000 | + 'description' => __('Shows whether or not the product shipping is taxable.', 'woocommerce'), |
|
| 1001 | 1001 | 'type' => 'boolean', |
| 1002 | - 'context' => array( 'view', 'edit' ), |
|
| 1002 | + 'context' => array('view', 'edit'), |
|
| 1003 | 1003 | 'readonly' => true, |
| 1004 | 1004 | ), |
| 1005 | 1005 | 'shipping_class' => array( |
| 1006 | - 'description' => __( 'Shipping class slug.', 'woocommerce' ), |
|
| 1006 | + 'description' => __('Shipping class slug.', 'woocommerce'), |
|
| 1007 | 1007 | 'type' => 'string', |
| 1008 | - 'context' => array( 'view', 'edit' ), |
|
| 1008 | + 'context' => array('view', 'edit'), |
|
| 1009 | 1009 | ), |
| 1010 | 1010 | 'shipping_class_id' => array( |
| 1011 | - 'description' => __( 'Shipping class ID.', 'woocommerce' ), |
|
| 1011 | + 'description' => __('Shipping class ID.', 'woocommerce'), |
|
| 1012 | 1012 | 'type' => 'string', |
| 1013 | - 'context' => array( 'view', 'edit' ), |
|
| 1013 | + 'context' => array('view', 'edit'), |
|
| 1014 | 1014 | 'readonly' => true, |
| 1015 | 1015 | ), |
| 1016 | 1016 | 'reviews_allowed' => array( |
| 1017 | - 'description' => __( 'Allow reviews.', 'woocommerce' ), |
|
| 1017 | + 'description' => __('Allow reviews.', 'woocommerce'), |
|
| 1018 | 1018 | 'type' => 'boolean', |
| 1019 | 1019 | 'default' => true, |
| 1020 | - 'context' => array( 'view', 'edit' ), |
|
| 1020 | + 'context' => array('view', 'edit'), |
|
| 1021 | 1021 | ), |
| 1022 | 1022 | 'average_rating' => array( |
| 1023 | - 'description' => __( 'Reviews average rating.', 'woocommerce' ), |
|
| 1023 | + 'description' => __('Reviews average rating.', 'woocommerce'), |
|
| 1024 | 1024 | 'type' => 'string', |
| 1025 | - 'context' => array( 'view', 'edit' ), |
|
| 1025 | + 'context' => array('view', 'edit'), |
|
| 1026 | 1026 | 'readonly' => true, |
| 1027 | 1027 | ), |
| 1028 | 1028 | 'rating_count' => array( |
| 1029 | - 'description' => __( 'Amount of reviews that the product have.', 'woocommerce' ), |
|
| 1029 | + 'description' => __('Amount of reviews that the product have.', 'woocommerce'), |
|
| 1030 | 1030 | 'type' => 'integer', |
| 1031 | - 'context' => array( 'view', 'edit' ), |
|
| 1031 | + 'context' => array('view', 'edit'), |
|
| 1032 | 1032 | 'readonly' => true, |
| 1033 | 1033 | ), |
| 1034 | 1034 | 'related_ids' => array( |
| 1035 | - 'description' => __( 'List of related products IDs.', 'woocommerce' ), |
|
| 1035 | + 'description' => __('List of related products IDs.', 'woocommerce'), |
|
| 1036 | 1036 | 'type' => 'array', |
| 1037 | 1037 | 'items' => array( |
| 1038 | 1038 | 'type' => 'integer', |
| 1039 | 1039 | ), |
| 1040 | - 'context' => array( 'view', 'edit' ), |
|
| 1040 | + 'context' => array('view', 'edit'), |
|
| 1041 | 1041 | 'readonly' => true, |
| 1042 | 1042 | ), |
| 1043 | 1043 | 'upsell_ids' => array( |
| 1044 | - 'description' => __( 'List of up-sell products IDs.', 'woocommerce' ), |
|
| 1044 | + 'description' => __('List of up-sell products IDs.', 'woocommerce'), |
|
| 1045 | 1045 | 'type' => 'array', |
| 1046 | 1046 | 'items' => array( |
| 1047 | 1047 | 'type' => 'integer', |
| 1048 | 1048 | ), |
| 1049 | - 'context' => array( 'view', 'edit' ), |
|
| 1049 | + 'context' => array('view', 'edit'), |
|
| 1050 | 1050 | ), |
| 1051 | 1051 | 'cross_sell_ids' => array( |
| 1052 | - 'description' => __( 'List of cross-sell products IDs.', 'woocommerce' ), |
|
| 1052 | + 'description' => __('List of cross-sell products IDs.', 'woocommerce'), |
|
| 1053 | 1053 | 'type' => 'array', |
| 1054 | 1054 | 'items' => array( |
| 1055 | 1055 | 'type' => 'integer', |
| 1056 | 1056 | ), |
| 1057 | - 'context' => array( 'view', 'edit' ), |
|
| 1057 | + 'context' => array('view', 'edit'), |
|
| 1058 | 1058 | ), |
| 1059 | 1059 | 'parent_id' => array( |
| 1060 | - 'description' => __( 'Product parent ID.', 'woocommerce' ), |
|
| 1060 | + 'description' => __('Product parent ID.', 'woocommerce'), |
|
| 1061 | 1061 | 'type' => 'integer', |
| 1062 | - 'context' => array( 'view', 'edit' ), |
|
| 1062 | + 'context' => array('view', 'edit'), |
|
| 1063 | 1063 | ), |
| 1064 | 1064 | 'purchase_note' => array( |
| 1065 | - 'description' => __( 'Optional note to send the customer after purchase.', 'woocommerce' ), |
|
| 1065 | + 'description' => __('Optional note to send the customer after purchase.', 'woocommerce'), |
|
| 1066 | 1066 | 'type' => 'string', |
| 1067 | - 'context' => array( 'view', 'edit' ), |
|
| 1067 | + 'context' => array('view', 'edit'), |
|
| 1068 | 1068 | ), |
| 1069 | 1069 | 'categories' => array( |
| 1070 | - 'description' => __( 'List of categories.', 'woocommerce' ), |
|
| 1070 | + 'description' => __('List of categories.', 'woocommerce'), |
|
| 1071 | 1071 | 'type' => 'array', |
| 1072 | - 'context' => array( 'view', 'edit' ), |
|
| 1072 | + 'context' => array('view', 'edit'), |
|
| 1073 | 1073 | 'items' => array( |
| 1074 | 1074 | 'type' => 'object', |
| 1075 | 1075 | 'properties' => array( |
| 1076 | 1076 | 'id' => array( |
| 1077 | - 'description' => __( 'Category ID.', 'woocommerce' ), |
|
| 1077 | + 'description' => __('Category ID.', 'woocommerce'), |
|
| 1078 | 1078 | 'type' => 'integer', |
| 1079 | - 'context' => array( 'view', 'edit' ), |
|
| 1079 | + 'context' => array('view', 'edit'), |
|
| 1080 | 1080 | ), |
| 1081 | 1081 | 'name' => array( |
| 1082 | - 'description' => __( 'Category name.', 'woocommerce' ), |
|
| 1082 | + 'description' => __('Category name.', 'woocommerce'), |
|
| 1083 | 1083 | 'type' => 'string', |
| 1084 | - 'context' => array( 'view', 'edit' ), |
|
| 1084 | + 'context' => array('view', 'edit'), |
|
| 1085 | 1085 | 'readonly' => true, |
| 1086 | 1086 | ), |
| 1087 | 1087 | 'slug' => array( |
| 1088 | - 'description' => __( 'Category slug.', 'woocommerce' ), |
|
| 1088 | + 'description' => __('Category slug.', 'woocommerce'), |
|
| 1089 | 1089 | 'type' => 'string', |
| 1090 | - 'context' => array( 'view', 'edit' ), |
|
| 1090 | + 'context' => array('view', 'edit'), |
|
| 1091 | 1091 | 'readonly' => true, |
| 1092 | 1092 | ), |
| 1093 | 1093 | ), |
| 1094 | 1094 | ), |
| 1095 | 1095 | ), |
| 1096 | 1096 | 'tags' => array( |
| 1097 | - 'description' => __( 'List of tags.', 'woocommerce' ), |
|
| 1097 | + 'description' => __('List of tags.', 'woocommerce'), |
|
| 1098 | 1098 | 'type' => 'array', |
| 1099 | - 'context' => array( 'view', 'edit' ), |
|
| 1099 | + 'context' => array('view', 'edit'), |
|
| 1100 | 1100 | 'items' => array( |
| 1101 | 1101 | 'type' => 'object', |
| 1102 | 1102 | 'properties' => array( |
| 1103 | 1103 | 'id' => array( |
| 1104 | - 'description' => __( 'Tag ID.', 'woocommerce' ), |
|
| 1104 | + 'description' => __('Tag ID.', 'woocommerce'), |
|
| 1105 | 1105 | 'type' => 'integer', |
| 1106 | - 'context' => array( 'view', 'edit' ), |
|
| 1106 | + 'context' => array('view', 'edit'), |
|
| 1107 | 1107 | ), |
| 1108 | 1108 | 'name' => array( |
| 1109 | - 'description' => __( 'Tag name.', 'woocommerce' ), |
|
| 1109 | + 'description' => __('Tag name.', 'woocommerce'), |
|
| 1110 | 1110 | 'type' => 'string', |
| 1111 | - 'context' => array( 'view', 'edit' ), |
|
| 1111 | + 'context' => array('view', 'edit'), |
|
| 1112 | 1112 | 'readonly' => true, |
| 1113 | 1113 | ), |
| 1114 | 1114 | 'slug' => array( |
| 1115 | - 'description' => __( 'Tag slug.', 'woocommerce' ), |
|
| 1115 | + 'description' => __('Tag slug.', 'woocommerce'), |
|
| 1116 | 1116 | 'type' => 'string', |
| 1117 | - 'context' => array( 'view', 'edit' ), |
|
| 1117 | + 'context' => array('view', 'edit'), |
|
| 1118 | 1118 | 'readonly' => true, |
| 1119 | 1119 | ), |
| 1120 | 1120 | ), |
| 1121 | 1121 | ), |
| 1122 | 1122 | ), |
| 1123 | 1123 | 'images' => array( |
| 1124 | - 'description' => __( 'List of images.', 'woocommerce' ), |
|
| 1124 | + 'description' => __('List of images.', 'woocommerce'), |
|
| 1125 | 1125 | 'type' => 'object', |
| 1126 | - 'context' => array( 'view', 'edit' ), |
|
| 1126 | + 'context' => array('view', 'edit'), |
|
| 1127 | 1127 | 'items' => array( |
| 1128 | 1128 | 'type' => 'object', |
| 1129 | 1129 | 'properties' => array( |
| 1130 | 1130 | 'id' => array( |
| 1131 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
| 1131 | + 'description' => __('Image ID.', 'woocommerce'), |
|
| 1132 | 1132 | 'type' => 'integer', |
| 1133 | - 'context' => array( 'view', 'edit' ), |
|
| 1133 | + 'context' => array('view', 'edit'), |
|
| 1134 | 1134 | ), |
| 1135 | 1135 | 'date_created' => array( |
| 1136 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
| 1136 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
| 1137 | 1137 | 'type' => 'date-time', |
| 1138 | - 'context' => array( 'view', 'edit' ), |
|
| 1138 | + 'context' => array('view', 'edit'), |
|
| 1139 | 1139 | 'readonly' => true, |
| 1140 | 1140 | ), |
| 1141 | 1141 | 'date_created_gmt' => array( |
| 1142 | - 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), |
|
| 1142 | + 'description' => __('The date the image was created, as GMT.', 'woocommerce'), |
|
| 1143 | 1143 | 'type' => 'date-time', |
| 1144 | - 'context' => array( 'view', 'edit' ), |
|
| 1144 | + 'context' => array('view', 'edit'), |
|
| 1145 | 1145 | 'readonly' => true, |
| 1146 | 1146 | ), |
| 1147 | 1147 | 'date_modified' => array( |
| 1148 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
| 1148 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
| 1149 | 1149 | 'type' => 'date-time', |
| 1150 | - 'context' => array( 'view', 'edit' ), |
|
| 1150 | + 'context' => array('view', 'edit'), |
|
| 1151 | 1151 | 'readonly' => true, |
| 1152 | 1152 | ), |
| 1153 | 1153 | 'date_modified_gmt' => array( |
| 1154 | - 'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ), |
|
| 1154 | + 'description' => __('The date the image was last modified, as GMT.', 'woocommerce'), |
|
| 1155 | 1155 | 'type' => 'date-time', |
| 1156 | - 'context' => array( 'view', 'edit' ), |
|
| 1156 | + 'context' => array('view', 'edit'), |
|
| 1157 | 1157 | 'readonly' => true, |
| 1158 | 1158 | ), |
| 1159 | 1159 | 'src' => array( |
| 1160 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
| 1160 | + 'description' => __('Image URL.', 'woocommerce'), |
|
| 1161 | 1161 | 'type' => 'string', |
| 1162 | 1162 | 'format' => 'uri', |
| 1163 | - 'context' => array( 'view', 'edit' ), |
|
| 1163 | + 'context' => array('view', 'edit'), |
|
| 1164 | 1164 | ), |
| 1165 | 1165 | 'name' => array( |
| 1166 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
| 1166 | + 'description' => __('Image name.', 'woocommerce'), |
|
| 1167 | 1167 | 'type' => 'string', |
| 1168 | - 'context' => array( 'view', 'edit' ), |
|
| 1168 | + 'context' => array('view', 'edit'), |
|
| 1169 | 1169 | ), |
| 1170 | 1170 | 'alt' => array( |
| 1171 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
| 1171 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
| 1172 | 1172 | 'type' => 'string', |
| 1173 | - 'context' => array( 'view', 'edit' ), |
|
| 1173 | + 'context' => array('view', 'edit'), |
|
| 1174 | 1174 | ), |
| 1175 | 1175 | ), |
| 1176 | 1176 | ), |
| 1177 | 1177 | ), |
| 1178 | 1178 | 'attributes' => array( |
| 1179 | - 'description' => __( 'List of attributes.', 'woocommerce' ), |
|
| 1179 | + 'description' => __('List of attributes.', 'woocommerce'), |
|
| 1180 | 1180 | 'type' => 'array', |
| 1181 | - 'context' => array( 'view', 'edit' ), |
|
| 1181 | + 'context' => array('view', 'edit'), |
|
| 1182 | 1182 | 'items' => array( |
| 1183 | 1183 | 'type' => 'object', |
| 1184 | 1184 | 'properties' => array( |
| 1185 | 1185 | 'id' => array( |
| 1186 | - 'description' => __( 'Attribute ID.', 'woocommerce' ), |
|
| 1186 | + 'description' => __('Attribute ID.', 'woocommerce'), |
|
| 1187 | 1187 | 'type' => 'integer', |
| 1188 | - 'context' => array( 'view', 'edit' ), |
|
| 1188 | + 'context' => array('view', 'edit'), |
|
| 1189 | 1189 | ), |
| 1190 | 1190 | 'name' => array( |
| 1191 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
| 1191 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
| 1192 | 1192 | 'type' => 'string', |
| 1193 | - 'context' => array( 'view', 'edit' ), |
|
| 1193 | + 'context' => array('view', 'edit'), |
|
| 1194 | 1194 | ), |
| 1195 | 1195 | 'position' => array( |
| 1196 | - 'description' => __( 'Attribute position.', 'woocommerce' ), |
|
| 1196 | + 'description' => __('Attribute position.', 'woocommerce'), |
|
| 1197 | 1197 | 'type' => 'integer', |
| 1198 | - 'context' => array( 'view', 'edit' ), |
|
| 1198 | + 'context' => array('view', 'edit'), |
|
| 1199 | 1199 | ), |
| 1200 | 1200 | 'visible' => array( |
| 1201 | - 'description' => __( "Define if the attribute is visible on the \"Additional information\" tab in the product's page.", 'woocommerce' ), |
|
| 1201 | + 'description' => __("Define if the attribute is visible on the \"Additional information\" tab in the product's page.", 'woocommerce'), |
|
| 1202 | 1202 | 'type' => 'boolean', |
| 1203 | 1203 | 'default' => false, |
| 1204 | - 'context' => array( 'view', 'edit' ), |
|
| 1204 | + 'context' => array('view', 'edit'), |
|
| 1205 | 1205 | ), |
| 1206 | 1206 | 'variation' => array( |
| 1207 | - 'description' => __( 'Define if the attribute can be used as variation.', 'woocommerce' ), |
|
| 1207 | + 'description' => __('Define if the attribute can be used as variation.', 'woocommerce'), |
|
| 1208 | 1208 | 'type' => 'boolean', |
| 1209 | 1209 | 'default' => false, |
| 1210 | - 'context' => array( 'view', 'edit' ), |
|
| 1210 | + 'context' => array('view', 'edit'), |
|
| 1211 | 1211 | ), |
| 1212 | 1212 | 'options' => array( |
| 1213 | - 'description' => __( 'List of available term names of the attribute.', 'woocommerce' ), |
|
| 1213 | + 'description' => __('List of available term names of the attribute.', 'woocommerce'), |
|
| 1214 | 1214 | 'type' => 'array', |
| 1215 | 1215 | 'items' => array( |
| 1216 | 1216 | 'type' => 'string', |
| 1217 | 1217 | ), |
| 1218 | - 'context' => array( 'view', 'edit' ), |
|
| 1218 | + 'context' => array('view', 'edit'), |
|
| 1219 | 1219 | ), |
| 1220 | 1220 | ), |
| 1221 | 1221 | ), |
| 1222 | 1222 | ), |
| 1223 | 1223 | 'default_attributes' => array( |
| 1224 | - 'description' => __( 'Defaults variation attributes.', 'woocommerce' ), |
|
| 1224 | + 'description' => __('Defaults variation attributes.', 'woocommerce'), |
|
| 1225 | 1225 | 'type' => 'array', |
| 1226 | - 'context' => array( 'view', 'edit' ), |
|
| 1226 | + 'context' => array('view', 'edit'), |
|
| 1227 | 1227 | 'items' => array( |
| 1228 | 1228 | 'type' => 'object', |
| 1229 | 1229 | 'properties' => array( |
| 1230 | 1230 | 'id' => array( |
| 1231 | - 'description' => __( 'Attribute ID.', 'woocommerce' ), |
|
| 1231 | + 'description' => __('Attribute ID.', 'woocommerce'), |
|
| 1232 | 1232 | 'type' => 'integer', |
| 1233 | - 'context' => array( 'view', 'edit' ), |
|
| 1233 | + 'context' => array('view', 'edit'), |
|
| 1234 | 1234 | ), |
| 1235 | 1235 | 'name' => array( |
| 1236 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
| 1236 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
| 1237 | 1237 | 'type' => 'string', |
| 1238 | - 'context' => array( 'view', 'edit' ), |
|
| 1238 | + 'context' => array('view', 'edit'), |
|
| 1239 | 1239 | ), |
| 1240 | 1240 | 'option' => array( |
| 1241 | - 'description' => __( 'Selected attribute term name.', 'woocommerce' ), |
|
| 1241 | + 'description' => __('Selected attribute term name.', 'woocommerce'), |
|
| 1242 | 1242 | 'type' => 'string', |
| 1243 | - 'context' => array( 'view', 'edit' ), |
|
| 1243 | + 'context' => array('view', 'edit'), |
|
| 1244 | 1244 | ), |
| 1245 | 1245 | ), |
| 1246 | 1246 | ), |
| 1247 | 1247 | ), |
| 1248 | 1248 | 'variations' => array( |
| 1249 | - 'description' => __( 'List of variations IDs.', 'woocommerce' ), |
|
| 1249 | + 'description' => __('List of variations IDs.', 'woocommerce'), |
|
| 1250 | 1250 | 'type' => 'array', |
| 1251 | - 'context' => array( 'view', 'edit' ), |
|
| 1251 | + 'context' => array('view', 'edit'), |
|
| 1252 | 1252 | 'items' => array( |
| 1253 | 1253 | 'type' => 'integer', |
| 1254 | 1254 | ), |
| 1255 | 1255 | 'readonly' => true, |
| 1256 | 1256 | ), |
| 1257 | 1257 | 'grouped_products' => array( |
| 1258 | - 'description' => __( 'List of grouped products ID.', 'woocommerce' ), |
|
| 1258 | + 'description' => __('List of grouped products ID.', 'woocommerce'), |
|
| 1259 | 1259 | 'type' => 'array', |
| 1260 | 1260 | 'items' => array( |
| 1261 | 1261 | 'type' => 'integer', |
| 1262 | 1262 | ), |
| 1263 | - 'context' => array( 'view', 'edit' ), |
|
| 1263 | + 'context' => array('view', 'edit'), |
|
| 1264 | 1264 | 'readonly' => true, |
| 1265 | 1265 | ), |
| 1266 | 1266 | 'menu_order' => array( |
| 1267 | - 'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ), |
|
| 1267 | + 'description' => __('Menu order, used to custom sort products.', 'woocommerce'), |
|
| 1268 | 1268 | 'type' => 'integer', |
| 1269 | - 'context' => array( 'view', 'edit' ), |
|
| 1269 | + 'context' => array('view', 'edit'), |
|
| 1270 | 1270 | ), |
| 1271 | 1271 | 'meta_data' => array( |
| 1272 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
| 1272 | + 'description' => __('Meta data.', 'woocommerce'), |
|
| 1273 | 1273 | 'type' => 'array', |
| 1274 | - 'context' => array( 'view', 'edit' ), |
|
| 1274 | + 'context' => array('view', 'edit'), |
|
| 1275 | 1275 | 'items' => array( |
| 1276 | 1276 | 'type' => 'object', |
| 1277 | 1277 | 'properties' => array( |
| 1278 | 1278 | 'id' => array( |
| 1279 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
| 1279 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
| 1280 | 1280 | 'type' => 'integer', |
| 1281 | - 'context' => array( 'view', 'edit' ), |
|
| 1281 | + 'context' => array('view', 'edit'), |
|
| 1282 | 1282 | 'readonly' => true, |
| 1283 | 1283 | ), |
| 1284 | 1284 | 'key' => array( |
| 1285 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
| 1285 | + 'description' => __('Meta key.', 'woocommerce'), |
|
| 1286 | 1286 | 'type' => 'string', |
| 1287 | - 'context' => array( 'view', 'edit' ), |
|
| 1287 | + 'context' => array('view', 'edit'), |
|
| 1288 | 1288 | ), |
| 1289 | 1289 | 'value' => array( |
| 1290 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
| 1290 | + 'description' => __('Meta value.', 'woocommerce'), |
|
| 1291 | 1291 | 'type' => 'mixed', |
| 1292 | - 'context' => array( 'view', 'edit' ), |
|
| 1292 | + 'context' => array('view', 'edit'), |
|
| 1293 | 1293 | ), |
| 1294 | 1294 | ), |
| 1295 | 1295 | ), |
| 1296 | 1296 | ), |
| 1297 | 1297 | ), |
| 1298 | 1298 | ); |
| 1299 | - return $this->add_additional_fields_schema( $schema ); |
|
| 1299 | + return $this->add_additional_fields_schema($schema); |
|
| 1300 | 1300 | } |
| 1301 | 1301 | |
| 1302 | 1302 | /** |
@@ -1306,13 +1306,13 @@ discard block |
||
| 1306 | 1306 | */ |
| 1307 | 1307 | public function get_collection_params() { |
| 1308 | 1308 | $params = parent::get_collection_params(); |
| 1309 | - $params['orderby']['enum'] = array_merge( $params['orderby']['enum'], array( 'price', 'popularity', 'rating' ) ); |
|
| 1309 | + $params['orderby']['enum'] = array_merge($params['orderby']['enum'], array('price', 'popularity', 'rating')); |
|
| 1310 | 1310 | |
| 1311 | - unset( $params['in_stock'] ); |
|
| 1311 | + unset($params['in_stock']); |
|
| 1312 | 1312 | $params['stock_status'] = array( |
| 1313 | - 'description' => __( 'Limit result set to products with specified stock status.', 'woocommerce' ), |
|
| 1313 | + 'description' => __('Limit result set to products with specified stock status.', 'woocommerce'), |
|
| 1314 | 1314 | 'type' => 'string', |
| 1315 | - 'enum' => array_keys( wc_get_product_stock_status_options() ), |
|
| 1315 | + 'enum' => array_keys(wc_get_product_stock_status_options()), |
|
| 1316 | 1316 | 'sanitize_callback' => 'sanitize_text_field', |
| 1317 | 1317 | 'validate_callback' => 'rest_validate_request_arg', |
| 1318 | 1318 | ); |
@@ -1328,14 +1328,14 @@ discard block |
||
| 1328 | 1328 | * Options: 'view' and 'edit'. |
| 1329 | 1329 | * @return array |
| 1330 | 1330 | */ |
| 1331 | - protected function get_product_data( $product, $context = 'view' ) { |
|
| 1332 | - $data = parent::get_product_data( $product, $context ); |
|
| 1331 | + protected function get_product_data($product, $context = 'view') { |
|
| 1332 | + $data = parent::get_product_data($product, $context); |
|
| 1333 | 1333 | |
| 1334 | 1334 | // Replace in_stock with stock_status. |
| 1335 | - $pos = array_search( 'in_stock', array_keys( $data ), true ); |
|
| 1336 | - $array_section_1 = array_slice( $data, 0, $pos, true ); |
|
| 1337 | - $array_section_2 = array_slice( $data, $pos + 1, null, true ); |
|
| 1335 | + $pos = array_search('in_stock', array_keys($data), true); |
|
| 1336 | + $array_section_1 = array_slice($data, 0, $pos, true); |
|
| 1337 | + $array_section_2 = array_slice($data, $pos + 1, null, true); |
|
| 1338 | 1338 | |
| 1339 | - return $array_section_1 + array( 'stock_status' => $product->get_stock_status( $context ) ) + $array_section_2; |
|
| 1339 | + return $array_section_1 + array('stock_status' => $product->get_stock_status($context)) + $array_section_2; |
|
| 1340 | 1340 | } |
| 1341 | 1341 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @since 3.5.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * REST API Reports Orders Totals controller class. |
@@ -39,16 +39,16 @@ discard block |
||
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | 41 | protected function get_reports() { |
| 42 | - $totals = wp_count_posts( 'shop_order' ); |
|
| 42 | + $totals = wp_count_posts('shop_order'); |
|
| 43 | 43 | $data = array(); |
| 44 | 44 | |
| 45 | - foreach ( wc_get_order_statuses() as $slug => $name ) { |
|
| 46 | - if ( ! isset( $totals->$slug ) ) { |
|
| 45 | + foreach (wc_get_order_statuses() as $slug => $name) { |
|
| 46 | + if ( ! isset($totals->$slug)) { |
|
| 47 | 47 | continue; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | $data[] = array( |
| 51 | - 'slug' => str_replace( 'wc-', '', $slug ), |
|
| 51 | + 'slug' => str_replace('wc-', '', $slug), |
|
| 52 | 52 | 'name' => $name, |
| 53 | 53 | 'total' => (int) $totals->$slug, |
| 54 | 54 | ); |
@@ -64,19 +64,19 @@ discard block |
||
| 64 | 64 | * @param WP_REST_Request $request Request object. |
| 65 | 65 | * @return WP_REST_Response $response Response data. |
| 66 | 66 | */ |
| 67 | - public function prepare_item_for_response( $report, $request ) { |
|
| 67 | + public function prepare_item_for_response($report, $request) { |
|
| 68 | 68 | $data = array( |
| 69 | 69 | 'slug' => $report->slug, |
| 70 | 70 | 'name' => $report->name, |
| 71 | 71 | 'total' => $report->total, |
| 72 | 72 | ); |
| 73 | 73 | |
| 74 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 75 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 76 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 74 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 75 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 76 | + $data = $this->filter_response_by_context($data, $context); |
|
| 77 | 77 | |
| 78 | 78 | // Wrap the data in a response object. |
| 79 | - $response = rest_ensure_response( $data ); |
|
| 79 | + $response = rest_ensure_response($data); |
|
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * Filter a report returned from the API. |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param object $report The original report object. |
| 88 | 88 | * @param WP_REST_Request $request Request used to generate the response. |
| 89 | 89 | */ |
| 90 | - return apply_filters( 'woocommerce_rest_prepare_report_orders_count', $response, $report, $request ); |
|
| 90 | + return apply_filters('woocommerce_rest_prepare_report_orders_count', $response, $report, $request); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -102,26 +102,26 @@ discard block |
||
| 102 | 102 | 'type' => 'object', |
| 103 | 103 | 'properties' => array( |
| 104 | 104 | 'slug' => array( |
| 105 | - 'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ), |
|
| 105 | + 'description' => __('An alphanumeric identifier for the resource.', 'woocommerce'), |
|
| 106 | 106 | 'type' => 'string', |
| 107 | - 'context' => array( 'view' ), |
|
| 107 | + 'context' => array('view'), |
|
| 108 | 108 | 'readonly' => true, |
| 109 | 109 | ), |
| 110 | 110 | 'name' => array( |
| 111 | - 'description' => __( 'Order status name.', 'woocommerce' ), |
|
| 111 | + 'description' => __('Order status name.', 'woocommerce'), |
|
| 112 | 112 | 'type' => 'string', |
| 113 | - 'context' => array( 'view' ), |
|
| 113 | + 'context' => array('view'), |
|
| 114 | 114 | 'readonly' => true, |
| 115 | 115 | ), |
| 116 | 116 | 'total' => array( |
| 117 | - 'description' => __( 'Amount of orders.', 'woocommerce' ), |
|
| 117 | + 'description' => __('Amount of orders.', 'woocommerce'), |
|
| 118 | 118 | 'type' => 'string', |
| 119 | - 'context' => array( 'view' ), |
|
| 119 | + 'context' => array('view'), |
|
| 120 | 120 | 'readonly' => true, |
| 121 | 121 | ), |
| 122 | 122 | ), |
| 123 | 123 | ); |
| 124 | 124 | |
| 125 | - return $this->add_additional_fields_schema( $schema ); |
|
| 125 | + return $this->add_additional_fields_schema($schema); |
|
| 126 | 126 | } |
| 127 | 127 | } |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | * @since 2.6.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * REST API Report Top Sellers controller class. |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | * @since 2.6.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * REST API Tax Classes controller class. |