@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API reports controller class. |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | array( |
| 34 | 34 | array( |
| 35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
| 36 | - 'callback' => array( $this, 'get_items' ), |
|
| 37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 36 | + 'callback' => array($this, 'get_items'), |
|
| 37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 38 | 38 | 'args' => $this->get_collection_params(), |
| 39 | 39 | ), |
| 40 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 40 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 41 | 41 | ), |
| 42 | 42 | true |
| 43 | 43 | ); |
@@ -49,9 +49,9 @@ discard block |
||
| 49 | 49 | * @param \WP_REST_Request $request Full details about the request. |
| 50 | 50 | * @return \WP_Error|boolean |
| 51 | 51 | */ |
| 52 | - public function get_items_permissions_check( $request ) { |
|
| 53 | - if ( ! wc_rest_check_manager_permissions( 'reports', 'read' ) ) { |
|
| 54 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 52 | + public function get_items_permissions_check($request) { |
|
| 53 | + if ( ! wc_rest_check_manager_permissions('reports', 'read')) { |
|
| 54 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | return true; |
@@ -64,66 +64,66 @@ discard block |
||
| 64 | 64 | * @param \WP_REST_Request $request Request data. |
| 65 | 65 | * @return array|\WP_Error |
| 66 | 66 | */ |
| 67 | - public function get_items( $request ) { |
|
| 67 | + public function get_items($request) { |
|
| 68 | 68 | $data = []; |
| 69 | 69 | $reports = []; |
| 70 | - if ( class_exists( 'WC_Admin_Reports_Sync' ) ) { |
|
| 70 | + if (class_exists('WC_Admin_Reports_Sync')) { |
|
| 71 | 71 | $reports = array( |
| 72 | 72 | array( |
| 73 | 73 | 'slug' => 'performance-indicators', |
| 74 | - 'description' => __( 'Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce' ), |
|
| 74 | + 'description' => __('Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce'), |
|
| 75 | 75 | ), |
| 76 | 76 | array( |
| 77 | 77 | 'slug' => 'revenue/stats', |
| 78 | - 'description' => __( 'Stats about revenue.', 'woocommerce' ), |
|
| 78 | + 'description' => __('Stats about revenue.', 'woocommerce'), |
|
| 79 | 79 | ), |
| 80 | 80 | array( |
| 81 | 81 | 'slug' => 'orders/stats', |
| 82 | - 'description' => __( 'Stats about orders.', 'woocommerce' ), |
|
| 82 | + 'description' => __('Stats about orders.', 'woocommerce'), |
|
| 83 | 83 | ), |
| 84 | 84 | array( |
| 85 | 85 | 'slug' => 'products', |
| 86 | - 'description' => __( 'Products detailed reports.', 'woocommerce' ), |
|
| 86 | + 'description' => __('Products detailed reports.', 'woocommerce'), |
|
| 87 | 87 | ), |
| 88 | 88 | array( |
| 89 | 89 | 'slug' => 'products/stats', |
| 90 | - 'description' => __( 'Stats about products.', 'woocommerce' ), |
|
| 90 | + 'description' => __('Stats about products.', 'woocommerce'), |
|
| 91 | 91 | ), |
| 92 | 92 | array( |
| 93 | 93 | 'slug' => 'categories', |
| 94 | - 'description' => __( 'Product categories detailed reports.', 'woocommerce' ), |
|
| 94 | + 'description' => __('Product categories detailed reports.', 'woocommerce'), |
|
| 95 | 95 | ), |
| 96 | 96 | array( |
| 97 | 97 | 'slug' => 'categories/stats', |
| 98 | - 'description' => __( 'Stats about product categories.', 'woocommerce' ), |
|
| 98 | + 'description' => __('Stats about product categories.', 'woocommerce'), |
|
| 99 | 99 | ), |
| 100 | 100 | array( |
| 101 | 101 | 'slug' => 'coupons', |
| 102 | - 'description' => __( 'Coupons detailed reports.', 'woocommerce' ), |
|
| 102 | + 'description' => __('Coupons detailed reports.', 'woocommerce'), |
|
| 103 | 103 | ), |
| 104 | 104 | array( |
| 105 | 105 | 'slug' => 'coupons/stats', |
| 106 | - 'description' => __( 'Stats about coupons.', 'woocommerce' ), |
|
| 106 | + 'description' => __('Stats about coupons.', 'woocommerce'), |
|
| 107 | 107 | ), |
| 108 | 108 | array( |
| 109 | 109 | 'slug' => 'taxes', |
| 110 | - 'description' => __( 'Taxes detailed reports.', 'woocommerce' ), |
|
| 110 | + 'description' => __('Taxes detailed reports.', 'woocommerce'), |
|
| 111 | 111 | ), |
| 112 | 112 | array( |
| 113 | 113 | 'slug' => 'taxes/stats', |
| 114 | - 'description' => __( 'Stats about taxes.', 'woocommerce' ), |
|
| 114 | + 'description' => __('Stats about taxes.', 'woocommerce'), |
|
| 115 | 115 | ), |
| 116 | 116 | array( |
| 117 | 117 | 'slug' => 'downloads', |
| 118 | - 'description' => __( 'Product downloads detailed reports.', 'woocommerce' ), |
|
| 118 | + 'description' => __('Product downloads detailed reports.', 'woocommerce'), |
|
| 119 | 119 | ), |
| 120 | 120 | array( |
| 121 | 121 | 'slug' => 'downloads/stats', |
| 122 | - 'description' => __( 'Stats about product downloads.', 'woocommerce' ), |
|
| 122 | + 'description' => __('Stats about product downloads.', 'woocommerce'), |
|
| 123 | 123 | ), |
| 124 | 124 | array( |
| 125 | 125 | 'slug' => 'customers', |
| 126 | - 'description' => __( 'Customers detailed reports.', 'woocommerce' ), |
|
| 126 | + 'description' => __('Customers detailed reports.', 'woocommerce'), |
|
| 127 | 127 | ), |
| 128 | 128 | ); |
| 129 | 129 | } |
@@ -135,22 +135,22 @@ discard block |
||
| 135 | 135 | * |
| 136 | 136 | * @param array $endpoints The list of allowed reports.. |
| 137 | 137 | */ |
| 138 | - $reports = apply_filters( 'woocommerce_admin_reports', $reports ); |
|
| 138 | + $reports = apply_filters('woocommerce_admin_reports', $reports); |
|
| 139 | 139 | |
| 140 | - foreach ( $reports as $report ) { |
|
| 141 | - if ( empty( $report['slug'] ) ) { |
|
| 140 | + foreach ($reports as $report) { |
|
| 141 | + if (empty($report['slug'])) { |
|
| 142 | 142 | continue; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - if ( empty( $report['path'] ) ) { |
|
| 145 | + if (empty($report['path'])) { |
|
| 146 | 146 | $report['path'] = '/' . $this->namespace . '/reports/' . $report['slug']; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | // Allows a different admin page to be loaded here, |
| 150 | 150 | // or allows an empty url if no report exists for a set of performance indicators. |
| 151 | - if ( ! isset( $report['url'] ) ) { |
|
| 152 | - if ( '/stats' === substr( $report['slug'], -6 ) ) { |
|
| 153 | - $url_slug = substr( $report['slug'], 0, -6 ); |
|
| 151 | + if ( ! isset($report['url'])) { |
|
| 152 | + if ('/stats' === substr($report['slug'], -6)) { |
|
| 153 | + $url_slug = substr($report['slug'], 0, -6); |
|
| 154 | 154 | } else { |
| 155 | 155 | $url_slug = $report['slug']; |
| 156 | 156 | } |
@@ -158,11 +158,11 @@ discard block |
||
| 158 | 158 | $report['url'] = '/analytics/' . $url_slug; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - $item = $this->prepare_item_for_response( (object) $report, $request ); |
|
| 162 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 161 | + $item = $this->prepare_item_for_response((object) $report, $request); |
|
| 162 | + $data[] = $this->prepare_response_for_collection($item); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - return rest_ensure_response( $data ); |
|
| 165 | + return rest_ensure_response($data); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -172,14 +172,14 @@ discard block |
||
| 172 | 172 | * @param int $order_id Order ID. |
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | - public function get_order_number( $order_id ) { |
|
| 176 | - $order = wc_get_order( $order_id ); |
|
| 175 | + public function get_order_number($order_id) { |
|
| 176 | + $order = wc_get_order($order_id); |
|
| 177 | 177 | |
| 178 | - if ( 'shop_order_refund' === $order->get_type() ) { |
|
| 179 | - $order = wc_get_order( $order->get_parent_id() ); |
|
| 178 | + if ('shop_order_refund' === $order->get_type()) { |
|
| 179 | + $order = wc_get_order($order->get_parent_id()); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if ( ! has_filter( 'woocommerce_order_number' ) ) { |
|
| 182 | + if ( ! has_filter('woocommerce_order_number')) { |
|
| 183 | 183 | return $order->get_id(); |
| 184 | 184 | } |
| 185 | 185 | |
@@ -193,29 +193,29 @@ discard block |
||
| 193 | 193 | * @param \WP_REST_Request $request Request object. |
| 194 | 194 | * @return \WP_REST_Response |
| 195 | 195 | */ |
| 196 | - public function prepare_item_for_response( $report, $request ) { |
|
| 196 | + public function prepare_item_for_response($report, $request) { |
|
| 197 | 197 | $data = array( |
| 198 | 198 | 'slug' => $report->slug, |
| 199 | 199 | 'description' => $report->description, |
| 200 | 200 | 'path' => $report->path, |
| 201 | 201 | ); |
| 202 | 202 | |
| 203 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 204 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 205 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 203 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 204 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 205 | + $data = $this->filter_response_by_context($data, $context); |
|
| 206 | 206 | |
| 207 | 207 | // Wrap the data in a response object. |
| 208 | - $response = rest_ensure_response( $data ); |
|
| 208 | + $response = rest_ensure_response($data); |
|
| 209 | 209 | $response->add_links( |
| 210 | 210 | array( |
| 211 | 211 | 'self' => array( |
| 212 | - 'href' => rest_url( $report->path ), |
|
| 212 | + 'href' => rest_url($report->path), |
|
| 213 | 213 | ), |
| 214 | 214 | 'report' => array( |
| 215 | 215 | 'href' => $report->url, |
| 216 | 216 | ), |
| 217 | 217 | 'collection' => array( |
| 218 | - 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), |
|
| 218 | + 'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)), |
|
| 219 | 219 | ), |
| 220 | 220 | ) |
| 221 | 221 | ); |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | * @param object $report The original report object. |
| 230 | 230 | * @param \WP_REST_Request $request Request used to generate the response. |
| 231 | 231 | */ |
| 232 | - return apply_filters( 'woocommerce_rest_prepare_report', $response, $report, $request ); |
|
| 232 | + return apply_filters('woocommerce_rest_prepare_report', $response, $report, $request); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -244,27 +244,27 @@ discard block |
||
| 244 | 244 | 'type' => 'object', |
| 245 | 245 | 'properties' => array( |
| 246 | 246 | 'slug' => array( |
| 247 | - 'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ), |
|
| 247 | + 'description' => __('An alphanumeric identifier for the resource.', 'woocommerce'), |
|
| 248 | 248 | 'type' => 'string', |
| 249 | - 'context' => array( 'view' ), |
|
| 249 | + 'context' => array('view'), |
|
| 250 | 250 | 'readonly' => true, |
| 251 | 251 | ), |
| 252 | 252 | 'description' => array( |
| 253 | - 'description' => __( 'A human-readable description of the resource.', 'woocommerce' ), |
|
| 253 | + 'description' => __('A human-readable description of the resource.', 'woocommerce'), |
|
| 254 | 254 | 'type' => 'string', |
| 255 | - 'context' => array( 'view' ), |
|
| 255 | + 'context' => array('view'), |
|
| 256 | 256 | 'readonly' => true, |
| 257 | 257 | ), |
| 258 | 258 | 'path' => array( |
| 259 | - 'description' => __( 'API path.', 'woocommerce' ), |
|
| 259 | + 'description' => __('API path.', 'woocommerce'), |
|
| 260 | 260 | 'type' => 'string', |
| 261 | - 'context' => array( 'view' ), |
|
| 261 | + 'context' => array('view'), |
|
| 262 | 262 | 'readonly' => true, |
| 263 | 263 | ), |
| 264 | 264 | ), |
| 265 | 265 | ); |
| 266 | 266 | |
| 267 | - return $this->add_additional_fields_schema( $schema ); |
|
| 267 | + return $this->add_additional_fields_schema($schema); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | */ |
| 275 | 275 | public function get_collection_params() { |
| 276 | 276 | return array( |
| 277 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 277 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 278 | 278 | ); |
| 279 | 279 | } |
| 280 | 280 | |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | public function get_order_statuses() { |
| 287 | 287 | $order_statuses = array(); |
| 288 | 288 | |
| 289 | - foreach ( array_keys( wc_get_order_statuses() ) as $status ) { |
|
| 290 | - $order_statuses[] = str_replace( 'wc-', '', $status ); |
|
| 289 | + foreach (array_keys(wc_get_order_statuses()) as $status) { |
|
| 290 | + $order_statuses[] = str_replace('wc-', '', $status); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | return $order_statuses; |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | namespace WooCommerce\RestApi\Version4\Controllers; |
| 12 | 12 | |
| 13 | -defined( 'ABSPATH' ) || exit; |
|
| 13 | +defined('ABSPATH') || exit; |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * REST API Shipping Zones base class. |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * @param int $zone_id Shipping Zone ID. |
| 34 | 34 | * @return WC_Shipping_Zone|\WP_Error |
| 35 | 35 | */ |
| 36 | - protected function get_zone( $zone_id ) { |
|
| 37 | - $zone = \WC_Shipping_Zones::get_zone_by( 'zone_id', $zone_id ); |
|
| 36 | + protected function get_zone($zone_id) { |
|
| 37 | + $zone = \WC_Shipping_Zones::get_zone_by('zone_id', $zone_id); |
|
| 38 | 38 | |
| 39 | - if ( false === $zone ) { |
|
| 40 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 39 | + if (false === $zone) { |
|
| 40 | + return new \WP_Error('woocommerce_rest_shipping_zone_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | return $zone; |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | * @param \WP_REST_Request $request Full details about the request. |
| 50 | 50 | * @return \WP_Error|boolean |
| 51 | 51 | */ |
| 52 | - public function get_items_permissions_check( $request ) { |
|
| 53 | - if ( ! wc_shipping_enabled() ) { |
|
| 54 | - return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 52 | + public function get_items_permissions_check($request) { |
|
| 53 | + if ( ! wc_shipping_enabled()) { |
|
| 54 | + return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404)); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
| 58 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 57 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
| 58 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | return true; |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | * @param \WP_REST_Request $request Full details about the request. |
| 68 | 68 | * @return \WP_Error|boolean |
| 69 | 69 | */ |
| 70 | - public function create_item_permissions_check( $request ) { |
|
| 71 | - if ( ! wc_shipping_enabled() ) { |
|
| 72 | - return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 70 | + public function create_item_permissions_check($request) { |
|
| 71 | + if ( ! wc_shipping_enabled()) { |
|
| 72 | + return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404)); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
| 76 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 75 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
| 76 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | return true; |
@@ -85,13 +85,13 @@ discard block |
||
| 85 | 85 | * @param \WP_REST_Request $request Full details about the request. |
| 86 | 86 | * @return \WP_Error|boolean |
| 87 | 87 | */ |
| 88 | - public function update_items_permissions_check( $request ) { |
|
| 89 | - if ( ! wc_shipping_enabled() ) { |
|
| 90 | - return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 88 | + public function update_items_permissions_check($request) { |
|
| 89 | + if ( ! wc_shipping_enabled()) { |
|
| 90 | + return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404)); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
| 94 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 93 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
| 94 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | return true; |
@@ -103,13 +103,13 @@ discard block |
||
| 103 | 103 | * @param \WP_REST_Request $request Full details about the request. |
| 104 | 104 | * @return \WP_Error|boolean |
| 105 | 105 | */ |
| 106 | - public function delete_items_permissions_check( $request ) { |
|
| 107 | - if ( ! wc_shipping_enabled() ) { |
|
| 108 | - return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 106 | + public function delete_items_permissions_check($request) { |
|
| 107 | + if ( ! wc_shipping_enabled()) { |
|
| 108 | + return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404)); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) { |
|
| 112 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 111 | + if ( ! wc_rest_check_manager_permissions('settings', 'delete')) { |
|
| 112 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | return true; |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | namespace WooCommerce\RestApi\Version4\Controllers; |
| 17 | 17 | |
| 18 | -defined( 'ABSPATH' ) || exit; |
|
| 18 | +defined('ABSPATH') || exit; |
|
| 19 | 19 | |
| 20 | 20 | use \WP_REST_Controller; |
| 21 | 21 | |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @return array |
| 53 | 53 | */ |
| 54 | - protected function add_additional_fields_schema( $schema ) { |
|
| 55 | - if ( empty( $schema['title'] ) ) { |
|
| 54 | + protected function add_additional_fields_schema($schema) { |
|
| 55 | + if (empty($schema['title'])) { |
|
| 56 | 56 | return $schema; |
| 57 | 57 | } |
| 58 | 58 | |
@@ -61,17 +61,17 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | $object_type = $schema['title']; |
| 63 | 63 | |
| 64 | - $additional_fields = $this->get_additional_fields( $object_type ); |
|
| 64 | + $additional_fields = $this->get_additional_fields($object_type); |
|
| 65 | 65 | |
| 66 | - foreach ( $additional_fields as $field_name => $field_options ) { |
|
| 67 | - if ( ! $field_options['schema'] ) { |
|
| 66 | + foreach ($additional_fields as $field_name => $field_options) { |
|
| 67 | + if ( ! $field_options['schema']) { |
|
| 68 | 68 | continue; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - $schema['properties'][ $field_name ] = $field_options['schema']; |
|
| 71 | + $schema['properties'][$field_name] = $field_options['schema']; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $schema['properties'] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema['properties'] ); |
|
| 74 | + $schema['properties'] = apply_filters('woocommerce_rest_' . $object_type . '_schema', $schema['properties']); |
|
| 75 | 75 | |
| 76 | 76 | return $schema; |
| 77 | 77 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @return string |
| 83 | 83 | */ |
| 84 | 84 | protected function get_normalized_rest_base() { |
| 85 | - return preg_replace( '/\(.*\)\//i', '', $this->rest_base ); |
|
| 85 | + return preg_replace('/\(.*\)\//i', '', $this->rest_base); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -91,25 +91,25 @@ discard block |
||
| 91 | 91 | * @param array $items Request items. |
| 92 | 92 | * @return bool|\WP_Error |
| 93 | 93 | */ |
| 94 | - protected function check_batch_limit( $items ) { |
|
| 95 | - $limit = apply_filters( 'woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base() ); |
|
| 94 | + protected function check_batch_limit($items) { |
|
| 95 | + $limit = apply_filters('woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base()); |
|
| 96 | 96 | $total = 0; |
| 97 | 97 | |
| 98 | - if ( ! empty( $items['create'] ) ) { |
|
| 99 | - $total += count( $items['create'] ); |
|
| 98 | + if ( ! empty($items['create'])) { |
|
| 99 | + $total += count($items['create']); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if ( ! empty( $items['update'] ) ) { |
|
| 103 | - $total += count( $items['update'] ); |
|
| 102 | + if ( ! empty($items['update'])) { |
|
| 103 | + $total += count($items['update']); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if ( ! empty( $items['delete'] ) ) { |
|
| 107 | - $total += count( $items['delete'] ); |
|
| 106 | + if ( ! empty($items['delete'])) { |
|
| 107 | + $total += count($items['delete']); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if ( $total > $limit ) { |
|
| 110 | + if ($total > $limit) { |
|
| 111 | 111 | /* translators: %s: items limit */ |
| 112 | - return new \WP_Error( 'woocommerce_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'woocommerce' ), $limit ), array( 'status' => 413 ) ); |
|
| 112 | + return new \WP_Error('woocommerce_rest_request_entity_too_large', sprintf(__('Unable to accept more than %s items for this request.', 'woocommerce'), $limit), array('status' => 413)); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | return true; |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @param \WP_REST_Request $request Full details about the request. |
| 122 | 122 | * @return array Of \WP_Error or \WP_REST_Response. |
| 123 | 123 | */ |
| 124 | - public function batch_items( $request ) { |
|
| 124 | + public function batch_items($request) { |
|
| 125 | 125 | /** |
| 126 | 126 | * REST Server |
| 127 | 127 | * |
@@ -130,34 +130,34 @@ discard block |
||
| 130 | 130 | global $wp_rest_server; |
| 131 | 131 | |
| 132 | 132 | // Get the request params. |
| 133 | - $items = array_filter( $request->get_params() ); |
|
| 133 | + $items = array_filter($request->get_params()); |
|
| 134 | 134 | $response = array(); |
| 135 | 135 | |
| 136 | 136 | // Check batch limit. |
| 137 | - $limit = $this->check_batch_limit( $items ); |
|
| 138 | - if ( is_wp_error( $limit ) ) { |
|
| 137 | + $limit = $this->check_batch_limit($items); |
|
| 138 | + if (is_wp_error($limit)) { |
|
| 139 | 139 | return $limit; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - if ( ! empty( $items['create'] ) ) { |
|
| 143 | - foreach ( $items['create'] as $item ) { |
|
| 144 | - $_item = new \WP_REST_Request( 'POST' ); |
|
| 142 | + if ( ! empty($items['create'])) { |
|
| 143 | + foreach ($items['create'] as $item) { |
|
| 144 | + $_item = new \WP_REST_Request('POST'); |
|
| 145 | 145 | |
| 146 | 146 | // Default parameters. |
| 147 | 147 | $defaults = array(); |
| 148 | 148 | $schema = $this->get_public_item_schema(); |
| 149 | - foreach ( $schema['properties'] as $arg => $options ) { |
|
| 150 | - if ( isset( $options['default'] ) ) { |
|
| 151 | - $defaults[ $arg ] = $options['default']; |
|
| 149 | + foreach ($schema['properties'] as $arg => $options) { |
|
| 150 | + if (isset($options['default'])) { |
|
| 151 | + $defaults[$arg] = $options['default']; |
|
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | - $_item->set_default_params( $defaults ); |
|
| 154 | + $_item->set_default_params($defaults); |
|
| 155 | 155 | |
| 156 | 156 | // Set request parameters. |
| 157 | - $_item->set_body_params( $item ); |
|
| 158 | - $_response = $this->create_item( $_item ); |
|
| 157 | + $_item->set_body_params($item); |
|
| 158 | + $_response = $this->create_item($_item); |
|
| 159 | 159 | |
| 160 | - if ( is_wp_error( $_response ) ) { |
|
| 160 | + if (is_wp_error($_response)) { |
|
| 161 | 161 | $response['create'][] = array( |
| 162 | 162 | 'id' => 0, |
| 163 | 163 | 'error' => array( |
@@ -167,18 +167,18 @@ discard block |
||
| 167 | 167 | ), |
| 168 | 168 | ); |
| 169 | 169 | } else { |
| 170 | - $response['create'][] = $wp_rest_server->response_to_data( $_response, '' ); |
|
| 170 | + $response['create'][] = $wp_rest_server->response_to_data($_response, ''); |
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - if ( ! empty( $items['update'] ) ) { |
|
| 176 | - foreach ( $items['update'] as $item ) { |
|
| 177 | - $_item = new \WP_REST_Request( 'PUT' ); |
|
| 178 | - $_item->set_body_params( $item ); |
|
| 179 | - $_response = $this->update_item( $_item ); |
|
| 175 | + if ( ! empty($items['update'])) { |
|
| 176 | + foreach ($items['update'] as $item) { |
|
| 177 | + $_item = new \WP_REST_Request('PUT'); |
|
| 178 | + $_item->set_body_params($item); |
|
| 179 | + $_response = $this->update_item($_item); |
|
| 180 | 180 | |
| 181 | - if ( is_wp_error( $_response ) ) { |
|
| 181 | + if (is_wp_error($_response)) { |
|
| 182 | 182 | $response['update'][] = array( |
| 183 | 183 | 'id' => $item['id'], |
| 184 | 184 | 'error' => array( |
@@ -188,29 +188,29 @@ discard block |
||
| 188 | 188 | ), |
| 189 | 189 | ); |
| 190 | 190 | } else { |
| 191 | - $response['update'][] = $wp_rest_server->response_to_data( $_response, '' ); |
|
| 191 | + $response['update'][] = $wp_rest_server->response_to_data($_response, ''); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - if ( ! empty( $items['delete'] ) ) { |
|
| 197 | - foreach ( $items['delete'] as $id ) { |
|
| 196 | + if ( ! empty($items['delete'])) { |
|
| 197 | + foreach ($items['delete'] as $id) { |
|
| 198 | 198 | $id = (int) $id; |
| 199 | 199 | |
| 200 | - if ( 0 === $id ) { |
|
| 200 | + if (0 === $id) { |
|
| 201 | 201 | continue; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - $_item = new \WP_REST_Request( 'DELETE' ); |
|
| 204 | + $_item = new \WP_REST_Request('DELETE'); |
|
| 205 | 205 | $_item->set_query_params( |
| 206 | 206 | array( |
| 207 | 207 | 'id' => $id, |
| 208 | 208 | 'force' => true, |
| 209 | 209 | ) |
| 210 | 210 | ); |
| 211 | - $_response = $this->delete_item( $_item ); |
|
| 211 | + $_response = $this->delete_item($_item); |
|
| 212 | 212 | |
| 213 | - if ( is_wp_error( $_response ) ) { |
|
| 213 | + if (is_wp_error($_response)) { |
|
| 214 | 214 | $response['delete'][] = array( |
| 215 | 215 | 'id' => $id, |
| 216 | 216 | 'error' => array( |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | ), |
| 221 | 221 | ); |
| 222 | 222 | } else { |
| 223 | - $response['delete'][] = $wp_rest_server->response_to_data( $_response, '' ); |
|
| 223 | + $response['delete'][] = $wp_rest_server->response_to_data($_response, ''); |
|
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -236,9 +236,9 @@ discard block |
||
| 236 | 236 | * @param array $setting Setting. |
| 237 | 237 | * @return string |
| 238 | 238 | */ |
| 239 | - public function validate_setting_text_field( $value, $setting ) { |
|
| 240 | - $value = is_null( $value ) ? '' : $value; |
|
| 241 | - return wp_kses_post( trim( stripslashes( $value ) ) ); |
|
| 239 | + public function validate_setting_text_field($value, $setting) { |
|
| 240 | + $value = is_null($value) ? '' : $value; |
|
| 241 | + return wp_kses_post(trim(stripslashes($value))); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -249,11 +249,11 @@ discard block |
||
| 249 | 249 | * @param array $setting Setting. |
| 250 | 250 | * @return string|\WP_Error |
| 251 | 251 | */ |
| 252 | - public function validate_setting_select_field( $value, $setting ) { |
|
| 253 | - if ( array_key_exists( $value, $setting['options'] ) ) { |
|
| 252 | + public function validate_setting_select_field($value, $setting) { |
|
| 253 | + if (array_key_exists($value, $setting['options'])) { |
|
| 254 | 254 | return $value; |
| 255 | 255 | } else { |
| 256 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 256 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | |
@@ -265,18 +265,18 @@ discard block |
||
| 265 | 265 | * @param array $setting Setting. |
| 266 | 266 | * @return array|\WP_Error |
| 267 | 267 | */ |
| 268 | - public function validate_setting_multiselect_field( $values, $setting ) { |
|
| 269 | - if ( empty( $values ) ) { |
|
| 268 | + public function validate_setting_multiselect_field($values, $setting) { |
|
| 269 | + if (empty($values)) { |
|
| 270 | 270 | return array(); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - if ( ! is_array( $values ) ) { |
|
| 274 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 273 | + if ( ! is_array($values)) { |
|
| 274 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | $final_values = array(); |
| 278 | - foreach ( $values as $value ) { |
|
| 279 | - if ( array_key_exists( $value, $setting['options'] ) ) { |
|
| 278 | + foreach ($values as $value) { |
|
| 279 | + if (array_key_exists($value, $setting['options'])) { |
|
| 280 | 280 | $final_values[] = $value; |
| 281 | 281 | } |
| 282 | 282 | } |
@@ -292,19 +292,19 @@ discard block |
||
| 292 | 292 | * @param array $setting Setting. |
| 293 | 293 | * @return string|\WP_Error |
| 294 | 294 | */ |
| 295 | - public function validate_setting_image_width_field( $values, $setting ) { |
|
| 296 | - if ( ! is_array( $values ) ) { |
|
| 297 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 295 | + public function validate_setting_image_width_field($values, $setting) { |
|
| 296 | + if ( ! is_array($values)) { |
|
| 297 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | $current = $setting['value']; |
| 301 | - if ( isset( $values['width'] ) ) { |
|
| 302 | - $current['width'] = intval( $values['width'] ); |
|
| 301 | + if (isset($values['width'])) { |
|
| 302 | + $current['width'] = intval($values['width']); |
|
| 303 | 303 | } |
| 304 | - if ( isset( $values['height'] ) ) { |
|
| 305 | - $current['height'] = intval( $values['height'] ); |
|
| 304 | + if (isset($values['height'])) { |
|
| 305 | + $current['height'] = intval($values['height']); |
|
| 306 | 306 | } |
| 307 | - if ( isset( $values['crop'] ) ) { |
|
| 307 | + if (isset($values['crop'])) { |
|
| 308 | 308 | $current['crop'] = (bool) $values['crop']; |
| 309 | 309 | } |
| 310 | 310 | return $current; |
@@ -318,8 +318,8 @@ discard block |
||
| 318 | 318 | * @param array $setting Setting. |
| 319 | 319 | * @return string|\WP_Error |
| 320 | 320 | */ |
| 321 | - public function validate_setting_radio_field( $value, $setting ) { |
|
| 322 | - return $this->validate_setting_select_field( $value, $setting ); |
|
| 321 | + public function validate_setting_radio_field($value, $setting) { |
|
| 322 | + return $this->validate_setting_select_field($value, $setting); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
@@ -330,14 +330,14 @@ discard block |
||
| 330 | 330 | * @param array $setting Setting. |
| 331 | 331 | * @return string|\WP_Error |
| 332 | 332 | */ |
| 333 | - public function validate_setting_checkbox_field( $value, $setting ) { |
|
| 334 | - if ( in_array( $value, array( 'yes', 'no' ) ) ) { |
|
| 333 | + public function validate_setting_checkbox_field($value, $setting) { |
|
| 334 | + if (in_array($value, array('yes', 'no'))) { |
|
| 335 | 335 | return $value; |
| 336 | - } elseif ( empty( $value ) ) { |
|
| 337 | - $value = isset( $setting['default'] ) ? $setting['default'] : 'no'; |
|
| 336 | + } elseif (empty($value)) { |
|
| 337 | + $value = isset($setting['default']) ? $setting['default'] : 'no'; |
|
| 338 | 338 | return $value; |
| 339 | 339 | } else { |
| 340 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 340 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
| 341 | 341 | } |
| 342 | 342 | } |
| 343 | 343 | |
@@ -349,10 +349,10 @@ discard block |
||
| 349 | 349 | * @param array $setting Setting. |
| 350 | 350 | * @return string |
| 351 | 351 | */ |
| 352 | - public function validate_setting_textarea_field( $value, $setting ) { |
|
| 353 | - $value = is_null( $value ) ? '' : $value; |
|
| 352 | + public function validate_setting_textarea_field($value, $setting) { |
|
| 353 | + $value = is_null($value) ? '' : $value; |
|
| 354 | 354 | return wp_kses( |
| 355 | - trim( stripslashes( $value ) ), |
|
| 355 | + trim(stripslashes($value)), |
|
| 356 | 356 | array_merge( |
| 357 | 357 | array( |
| 358 | 358 | 'iframe' => array( |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | 'class' => true, |
| 363 | 363 | ), |
| 364 | 364 | ), |
| 365 | - wp_kses_allowed_html( 'post' ) |
|
| 365 | + wp_kses_allowed_html('post') |
|
| 366 | 366 | ) |
| 367 | 367 | ); |
| 368 | 368 | } |
@@ -375,8 +375,8 @@ discard block |
||
| 375 | 375 | * @param array $meta_query Meta query. |
| 376 | 376 | * @return array |
| 377 | 377 | */ |
| 378 | - protected function add_meta_query( $args, $meta_query ) { |
|
| 379 | - if ( empty( $args['meta_query'] ) ) { |
|
| 378 | + protected function add_meta_query($args, $meta_query) { |
|
| 379 | + if (empty($args['meta_query'])) { |
|
| 380 | 380 | $args['meta_query'] = array(); |
| 381 | 381 | } |
| 382 | 382 | |
@@ -397,25 +397,25 @@ discard block |
||
| 397 | 397 | 'type' => 'object', |
| 398 | 398 | 'properties' => array( |
| 399 | 399 | 'create' => array( |
| 400 | - 'description' => __( 'List of created resources.', 'woocommerce' ), |
|
| 400 | + 'description' => __('List of created resources.', 'woocommerce'), |
|
| 401 | 401 | 'type' => 'array', |
| 402 | - 'context' => array( 'view', 'edit' ), |
|
| 402 | + 'context' => array('view', 'edit'), |
|
| 403 | 403 | 'items' => array( |
| 404 | 404 | 'type' => 'object', |
| 405 | 405 | ), |
| 406 | 406 | ), |
| 407 | 407 | 'update' => array( |
| 408 | - 'description' => __( 'List of updated resources.', 'woocommerce' ), |
|
| 408 | + 'description' => __('List of updated resources.', 'woocommerce'), |
|
| 409 | 409 | 'type' => 'array', |
| 410 | - 'context' => array( 'view', 'edit' ), |
|
| 410 | + 'context' => array('view', 'edit'), |
|
| 411 | 411 | 'items' => array( |
| 412 | 412 | 'type' => 'object', |
| 413 | 413 | ), |
| 414 | 414 | ), |
| 415 | 415 | 'delete' => array( |
| 416 | - 'description' => __( 'List of delete resources.', 'woocommerce' ), |
|
| 416 | + 'description' => __('List of delete resources.', 'woocommerce'), |
|
| 417 | 417 | 'type' => 'array', |
| 418 | - 'context' => array( 'view', 'edit' ), |
|
| 418 | + 'context' => array('view', 'edit'), |
|
| 419 | 419 | 'items' => array( |
| 420 | 420 | 'type' => 'integer', |
| 421 | 421 | ), |
@@ -435,32 +435,32 @@ discard block |
||
| 435 | 435 | * @param \WP_REST_Request $request Full details about the request. |
| 436 | 436 | * @return array Fields to be included in the response. |
| 437 | 437 | */ |
| 438 | - public function get_fields_for_response( $request ) { |
|
| 438 | + public function get_fields_for_response($request) { |
|
| 439 | 439 | $schema = $this->get_item_schema(); |
| 440 | - $fields = isset( $schema['properties'] ) ? array_keys( $schema['properties'] ) : array(); |
|
| 440 | + $fields = isset($schema['properties']) ? array_keys($schema['properties']) : array(); |
|
| 441 | 441 | |
| 442 | 442 | $additional_fields = $this->get_additional_fields(); |
| 443 | - foreach ( $additional_fields as $field_name => $field_options ) { |
|
| 443 | + foreach ($additional_fields as $field_name => $field_options) { |
|
| 444 | 444 | // For back-compat, include any field with an empty schema |
| 445 | 445 | // because it won't be present in $this->get_item_schema(). |
| 446 | - if ( is_null( $field_options['schema'] ) ) { |
|
| 446 | + if (is_null($field_options['schema'])) { |
|
| 447 | 447 | $fields[] = $field_name; |
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - if ( ! isset( $request['_fields'] ) ) { |
|
| 451 | + if ( ! isset($request['_fields'])) { |
|
| 452 | 452 | return $fields; |
| 453 | 453 | } |
| 454 | - $requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] ); |
|
| 455 | - if ( 0 === count( $requested_fields ) ) { |
|
| 454 | + $requested_fields = is_array($request['_fields']) ? $request['_fields'] : preg_split('/[\s,]+/', $request['_fields']); |
|
| 455 | + if (0 === count($requested_fields)) { |
|
| 456 | 456 | return $fields; |
| 457 | 457 | } |
| 458 | 458 | // Trim off outside whitespace from the comma delimited list. |
| 459 | - $requested_fields = array_map( 'trim', $requested_fields ); |
|
| 459 | + $requested_fields = array_map('trim', $requested_fields); |
|
| 460 | 460 | // Always persist 'id', because it can be needed for add_additional_fields_to_object(). |
| 461 | - if ( in_array( 'id', $fields, true ) ) { |
|
| 461 | + if (in_array('id', $fields, true)) { |
|
| 462 | 462 | $requested_fields[] = 'id'; |
| 463 | 463 | } |
| 464 | - return array_intersect( $fields, $requested_fields ); |
|
| 464 | + return array_intersect($fields, $requested_fields); |
|
| 465 | 465 | } |
| 466 | 466 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API Settings controller class. |
@@ -35,10 +35,10 @@ discard block |
||
| 35 | 35 | array( |
| 36 | 36 | array( |
| 37 | 37 | 'methods' => \WP_REST_Server::READABLE, |
| 38 | - 'callback' => array( $this, 'get_items' ), |
|
| 39 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 38 | + 'callback' => array($this, 'get_items'), |
|
| 39 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 40 | 40 | ), |
| 41 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 41 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 42 | 42 | ), |
| 43 | 43 | true |
| 44 | 44 | ); |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | array( |
| 49 | 49 | array( |
| 50 | 50 | 'methods' => \WP_REST_Server::EDITABLE, |
| 51 | - 'callback' => array( $this, 'batch_items' ), |
|
| 52 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
| 51 | + 'callback' => array($this, 'batch_items'), |
|
| 52 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
| 53 | 53 | ), |
| 54 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
| 54 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
| 55 | 55 | ), |
| 56 | 56 | true |
| 57 | 57 | ); |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | * @param \WP_REST_Request $request Full data about the request. |
| 64 | 64 | * @return \WP_Error|bool |
| 65 | 65 | */ |
| 66 | - public function update_items_permissions_check( $request ) { |
|
| 67 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
| 68 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 66 | + public function update_items_permissions_check($request) { |
|
| 67 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
| 68 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | return true; |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * @param \WP_REST_Request $request Request data. |
| 78 | 78 | * @return \WP_Error\WP_REST_Response |
| 79 | 79 | */ |
| 80 | - public function update_item( $request ) { |
|
| 80 | + public function update_item($request) { |
|
| 81 | 81 | $options_controller = new \WC_REST_Setting_Options_Controller(); |
| 82 | - $response = $options_controller->update_item( $request ); |
|
| 82 | + $response = $options_controller->update_item($request); |
|
| 83 | 83 | |
| 84 | 84 | return $response; |
| 85 | 85 | } |
@@ -91,34 +91,34 @@ discard block |
||
| 91 | 91 | * @param \WP_REST_Request $request Request data. |
| 92 | 92 | * @return \WP_Error\WP_REST_Response |
| 93 | 93 | */ |
| 94 | - public function get_items( $request ) { |
|
| 95 | - $groups = apply_filters( 'woocommerce_settings_groups', array() ); |
|
| 96 | - if ( empty( $groups ) ) { |
|
| 97 | - return new \WP_Error( 'rest_setting_groups_empty', __( 'No setting groups have been registered.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 94 | + public function get_items($request) { |
|
| 95 | + $groups = apply_filters('woocommerce_settings_groups', array()); |
|
| 96 | + if (empty($groups)) { |
|
| 97 | + return new \WP_Error('rest_setting_groups_empty', __('No setting groups have been registered.', 'woocommerce'), array('status' => 500)); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $defaults = $this->group_defaults(); |
| 101 | 101 | $filtered_groups = array(); |
| 102 | - foreach ( $groups as $group ) { |
|
| 102 | + foreach ($groups as $group) { |
|
| 103 | 103 | $sub_groups = array(); |
| 104 | - foreach ( $groups as $_group ) { |
|
| 105 | - if ( ! empty( $_group['parent_id'] ) && $group['id'] === $_group['parent_id'] ) { |
|
| 104 | + foreach ($groups as $_group) { |
|
| 105 | + if ( ! empty($_group['parent_id']) && $group['id'] === $_group['parent_id']) { |
|
| 106 | 106 | $sub_groups[] = $_group['id']; |
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | $group['sub_groups'] = $sub_groups; |
| 110 | 110 | |
| 111 | - $group = wp_parse_args( $group, $defaults ); |
|
| 112 | - if ( ! is_null( $group['id'] ) && ! is_null( $group['label'] ) ) { |
|
| 113 | - $group_obj = $this->filter_group( $group ); |
|
| 114 | - $group_data = $this->prepare_item_for_response( $group_obj, $request ); |
|
| 115 | - $group_data = $this->prepare_response_for_collection( $group_data ); |
|
| 111 | + $group = wp_parse_args($group, $defaults); |
|
| 112 | + if ( ! is_null($group['id']) && ! is_null($group['label'])) { |
|
| 113 | + $group_obj = $this->filter_group($group); |
|
| 114 | + $group_data = $this->prepare_item_for_response($group_obj, $request); |
|
| 115 | + $group_data = $this->prepare_response_for_collection($group_data); |
|
| 116 | 116 | |
| 117 | 117 | $filtered_groups[] = $group_data; |
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - $response = rest_ensure_response( $filtered_groups ); |
|
| 121 | + $response = rest_ensure_response($filtered_groups); |
|
| 122 | 122 | return $response; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -128,11 +128,11 @@ discard block |
||
| 128 | 128 | * @param string $group_id Group ID. |
| 129 | 129 | * @return array Links for the given group. |
| 130 | 130 | */ |
| 131 | - protected function prepare_links( $group_id ) { |
|
| 131 | + protected function prepare_links($group_id) { |
|
| 132 | 132 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
| 133 | 133 | $links = array( |
| 134 | 134 | 'options' => array( |
| 135 | - 'href' => rest_url( trailingslashit( $base ) . $group_id ), |
|
| 135 | + 'href' => rest_url(trailingslashit($base) . $group_id), |
|
| 136 | 136 | ), |
| 137 | 137 | ); |
| 138 | 138 | |
@@ -147,14 +147,14 @@ discard block |
||
| 147 | 147 | * @param \WP_REST_Request $request Request object. |
| 148 | 148 | * @return \WP_REST_Response $response Response data. |
| 149 | 149 | */ |
| 150 | - public function prepare_item_for_response( $item, $request ) { |
|
| 151 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
| 152 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
| 153 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 150 | + public function prepare_item_for_response($item, $request) { |
|
| 151 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
| 152 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
| 153 | + $data = $this->filter_response_by_context($data, $context); |
|
| 154 | 154 | |
| 155 | - $response = rest_ensure_response( $data ); |
|
| 155 | + $response = rest_ensure_response($data); |
|
| 156 | 156 | |
| 157 | - $response->add_links( $this->prepare_links( $item['id'] ) ); |
|
| 157 | + $response->add_links($this->prepare_links($item['id'])); |
|
| 158 | 158 | |
| 159 | 159 | return $response; |
| 160 | 160 | } |
@@ -167,10 +167,10 @@ discard block |
||
| 167 | 167 | * @param array $group Group. |
| 168 | 168 | * @return array |
| 169 | 169 | */ |
| 170 | - public function filter_group( $group ) { |
|
| 170 | + public function filter_group($group) { |
|
| 171 | 171 | return array_intersect_key( |
| 172 | 172 | $group, |
| 173 | - array_flip( array_filter( array_keys( $group ), array( $this, 'allowed_group_keys' ) ) ) |
|
| 173 | + array_flip(array_filter(array_keys($group), array($this, 'allowed_group_keys'))) |
|
| 174 | 174 | ); |
| 175 | 175 | } |
| 176 | 176 | |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | * @param string $key Key to check. |
| 182 | 182 | * @return boolean |
| 183 | 183 | */ |
| 184 | - public function allowed_group_keys( $key ) { |
|
| 185 | - return in_array( $key, array( 'id', 'label', 'description', 'parent_id', 'sub_groups' ) ); |
|
| 184 | + public function allowed_group_keys($key) { |
|
| 185 | + return in_array($key, array('id', 'label', 'description', 'parent_id', 'sub_groups')); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -208,9 +208,9 @@ discard block |
||
| 208 | 208 | * @param \WP_REST_Request $request Full data about the request. |
| 209 | 209 | * @return \WP_Error|boolean |
| 210 | 210 | */ |
| 211 | - public function get_items_permissions_check( $request ) { |
|
| 212 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
| 213 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 211 | + public function get_items_permissions_check($request) { |
|
| 212 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
| 213 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | return true; |
@@ -229,33 +229,33 @@ discard block |
||
| 229 | 229 | 'type' => 'object', |
| 230 | 230 | 'properties' => array( |
| 231 | 231 | 'id' => array( |
| 232 | - 'description' => __( 'A unique identifier that can be used to link settings together.', 'woocommerce' ), |
|
| 232 | + 'description' => __('A unique identifier that can be used to link settings together.', 'woocommerce'), |
|
| 233 | 233 | 'type' => 'string', |
| 234 | - 'context' => array( 'view', 'edit' ), |
|
| 234 | + 'context' => array('view', 'edit'), |
|
| 235 | 235 | ), |
| 236 | 236 | 'label' => array( |
| 237 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
| 237 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
| 238 | 238 | 'type' => 'string', |
| 239 | - 'context' => array( 'view', 'edit' ), |
|
| 239 | + 'context' => array('view', 'edit'), |
|
| 240 | 240 | ), |
| 241 | 241 | 'description' => array( |
| 242 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
| 242 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
| 243 | 243 | 'type' => 'string', |
| 244 | - 'context' => array( 'view', 'edit' ), |
|
| 244 | + 'context' => array('view', 'edit'), |
|
| 245 | 245 | ), |
| 246 | 246 | 'parent_id' => array( |
| 247 | - 'description' => __( 'ID of parent grouping.', 'woocommerce' ), |
|
| 247 | + 'description' => __('ID of parent grouping.', 'woocommerce'), |
|
| 248 | 248 | 'type' => 'string', |
| 249 | - 'context' => array( 'view', 'edit' ), |
|
| 249 | + 'context' => array('view', 'edit'), |
|
| 250 | 250 | ), |
| 251 | 251 | 'sub_groups' => array( |
| 252 | - 'description' => __( 'IDs for settings sub groups.', 'woocommerce' ), |
|
| 252 | + 'description' => __('IDs for settings sub groups.', 'woocommerce'), |
|
| 253 | 253 | 'type' => 'string', |
| 254 | - 'context' => array( 'view', 'edit' ), |
|
| 254 | + 'context' => array('view', 'edit'), |
|
| 255 | 255 | ), |
| 256 | 256 | ), |
| 257 | 257 | ); |
| 258 | 258 | |
| 259 | - return $this->add_additional_fields_schema( $schema ); |
|
| 259 | + return $this->add_additional_fields_schema($schema); |
|
| 260 | 260 | } |
| 261 | 261 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | namespace WooCommerce\RestApi\Version4\Controllers; |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * POSTS Controller. |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * @param \WP_REST_Request $request Full details about the request. |
| 44 | 44 | * @return \WP_Error|boolean |
| 45 | 45 | */ |
| 46 | - public function get_items_permissions_check( $request ) { |
|
| 47 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'read' ) ) { |
|
| 48 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 46 | + public function get_items_permissions_check($request) { |
|
| 47 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'read')) { |
|
| 48 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | return true; |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | * @param \WP_REST_Request $request Full details about the request. |
| 58 | 58 | * @return \WP_Error|boolean |
| 59 | 59 | */ |
| 60 | - public function create_item_permissions_check( $request ) { |
|
| 61 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'create' ) ) { |
|
| 62 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 60 | + public function create_item_permissions_check($request) { |
|
| 61 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'create')) { |
|
| 62 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | return true; |
@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | * @param \WP_REST_Request $request Full details about the request. |
| 72 | 72 | * @return \WP_Error|boolean |
| 73 | 73 | */ |
| 74 | - public function get_item_permissions_check( $request ) { |
|
| 75 | - $post = get_post( (int) $request['id'] ); |
|
| 74 | + public function get_item_permissions_check($request) { |
|
| 75 | + $post = get_post((int) $request['id']); |
|
| 76 | 76 | |
| 77 | - if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) { |
|
| 78 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 77 | + if ($post && ! wc_rest_check_post_permissions($this->post_type, 'read', $post->ID)) { |
|
| 78 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | return true; |
@@ -87,11 +87,11 @@ discard block |
||
| 87 | 87 | * @param \WP_REST_Request $request Full details about the request. |
| 88 | 88 | * @return \WP_Error|boolean |
| 89 | 89 | */ |
| 90 | - public function update_item_permissions_check( $request ) { |
|
| 91 | - $post = get_post( (int) $request['id'] ); |
|
| 90 | + public function update_item_permissions_check($request) { |
|
| 91 | + $post = get_post((int) $request['id']); |
|
| 92 | 92 | |
| 93 | - if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $post->ID ) ) { |
|
| 94 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 93 | + if ($post && ! wc_rest_check_post_permissions($this->post_type, 'edit', $post->ID)) { |
|
| 94 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | return true; |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | * @param \WP_REST_Request $request Full details about the request. |
| 104 | 104 | * @return bool|\WP_Error |
| 105 | 105 | */ |
| 106 | - public function delete_item_permissions_check( $request ) { |
|
| 107 | - $post = get_post( (int) $request['id'] ); |
|
| 106 | + public function delete_item_permissions_check($request) { |
|
| 107 | + $post = get_post((int) $request['id']); |
|
| 108 | 108 | |
| 109 | - if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $post->ID ) ) { |
|
| 110 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 109 | + if ($post && ! wc_rest_check_post_permissions($this->post_type, 'delete', $post->ID)) { |
|
| 110 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | return true; |
@@ -120,9 +120,9 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @return boolean|\WP_Error |
| 122 | 122 | */ |
| 123 | - public function batch_items_permissions_check( $request ) { |
|
| 124 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'batch' ) ) { |
|
| 125 | - 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() ) ); |
|
| 123 | + public function batch_items_permissions_check($request) { |
|
| 124 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'batch')) { |
|
| 125 | + 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())); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | return true; |
@@ -134,21 +134,21 @@ discard block |
||
| 134 | 134 | * @param \WP_REST_Request $request Full details about the request. |
| 135 | 135 | * @return \WP_Error\WP_REST_Response |
| 136 | 136 | */ |
| 137 | - public function get_item( $request ) { |
|
| 137 | + public function get_item($request) { |
|
| 138 | 138 | $id = (int) $request['id']; |
| 139 | - $post = get_post( $id ); |
|
| 139 | + $post = get_post($id); |
|
| 140 | 140 | |
| 141 | - if ( ! empty( $post->post_type ) && 'product_variation' === $post->post_type && 'product' === $this->post_type ) { |
|
| 142 | - return new \WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 143 | - } elseif ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) { |
|
| 144 | - return new \WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 141 | + if ( ! empty($post->post_type) && 'product_variation' === $post->post_type && 'product' === $this->post_type) { |
|
| 142 | + return new \WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce'), array('status' => 404)); |
|
| 143 | + } elseif (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) { |
|
| 144 | + return new \WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('Invalid ID.', 'woocommerce'), array('status' => 404)); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - $data = $this->prepare_item_for_response( $post, $request ); |
|
| 148 | - $response = rest_ensure_response( $data ); |
|
| 147 | + $data = $this->prepare_item_for_response($post, $request); |
|
| 148 | + $response = rest_ensure_response($data); |
|
| 149 | 149 | |
| 150 | - if ( $this->public ) { |
|
| 151 | - $response->link_header( 'alternate', get_permalink( $id ), array( 'type' => 'text/html' ) ); |
|
| 150 | + if ($this->public) { |
|
| 151 | + $response->link_header('alternate', get_permalink($id), array('type' => 'text/html')); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | return $response; |
@@ -160,39 +160,39 @@ discard block |
||
| 160 | 160 | * @param \WP_REST_Request $request Full details about the request. |
| 161 | 161 | * @return \WP_Error\WP_REST_Response |
| 162 | 162 | */ |
| 163 | - public function create_item( $request ) { |
|
| 164 | - if ( ! empty( $request['id'] ) ) { |
|
| 163 | + public function create_item($request) { |
|
| 164 | + if ( ! empty($request['id'])) { |
|
| 165 | 165 | /* translators: %s: post type */ |
| 166 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
| 166 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $post = $this->prepare_item_for_database( $request ); |
|
| 170 | - if ( is_wp_error( $post ) ) { |
|
| 169 | + $post = $this->prepare_item_for_database($request); |
|
| 170 | + if (is_wp_error($post)) { |
|
| 171 | 171 | return $post; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | $post->post_type = $this->post_type; |
| 175 | - $post_id = wp_insert_post( $post, true ); |
|
| 175 | + $post_id = wp_insert_post($post, true); |
|
| 176 | 176 | |
| 177 | - if ( is_wp_error( $post_id ) ) { |
|
| 177 | + if (is_wp_error($post_id)) { |
|
| 178 | 178 | |
| 179 | - if ( in_array( $post_id->get_error_code(), array( 'db_insert_error' ) ) ) { |
|
| 180 | - $post_id->add_data( array( 'status' => 500 ) ); |
|
| 179 | + if (in_array($post_id->get_error_code(), array('db_insert_error'))) { |
|
| 180 | + $post_id->add_data(array('status' => 500)); |
|
| 181 | 181 | } else { |
| 182 | - $post_id->add_data( array( 'status' => 400 ) ); |
|
| 182 | + $post_id->add_data(array('status' => 400)); |
|
| 183 | 183 | } |
| 184 | 184 | return $post_id; |
| 185 | 185 | } |
| 186 | 186 | $post->ID = $post_id; |
| 187 | - $post = get_post( $post_id ); |
|
| 187 | + $post = get_post($post_id); |
|
| 188 | 188 | |
| 189 | - $this->update_additional_fields_for_object( $post, $request ); |
|
| 189 | + $this->update_additional_fields_for_object($post, $request); |
|
| 190 | 190 | |
| 191 | 191 | // Add meta fields. |
| 192 | - $meta_fields = $this->add_post_meta_fields( $post, $request ); |
|
| 193 | - if ( is_wp_error( $meta_fields ) ) { |
|
| 192 | + $meta_fields = $this->add_post_meta_fields($post, $request); |
|
| 193 | + if (is_wp_error($meta_fields)) { |
|
| 194 | 194 | // Remove post. |
| 195 | - $this->delete_post( $post ); |
|
| 195 | + $this->delete_post($post); |
|
| 196 | 196 | |
| 197 | 197 | return $meta_fields; |
| 198 | 198 | } |
@@ -204,13 +204,13 @@ discard block |
||
| 204 | 204 | * @param \WP_REST_Request $request Request object. |
| 205 | 205 | * @param boolean $creating True when creating item, false when updating. |
| 206 | 206 | */ |
| 207 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, true ); |
|
| 207 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, true); |
|
| 208 | 208 | |
| 209 | - $request->set_param( 'context', 'edit' ); |
|
| 210 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
| 211 | - $response = rest_ensure_response( $response ); |
|
| 212 | - $response->set_status( 201 ); |
|
| 213 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post_id ) ) ); |
|
| 209 | + $request->set_param('context', 'edit'); |
|
| 210 | + $response = $this->prepare_item_for_response($post, $request); |
|
| 211 | + $response = rest_ensure_response($response); |
|
| 212 | + $response->set_status(201); |
|
| 213 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post_id))); |
|
| 214 | 214 | |
| 215 | 215 | return $response; |
| 216 | 216 | } |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * @param \WP_REST_Request $request \WP_REST_Request Object. |
| 223 | 223 | * @return bool|\WP_Error |
| 224 | 224 | */ |
| 225 | - protected function add_post_meta_fields( $post, $request ) { |
|
| 225 | + protected function add_post_meta_fields($post, $request) { |
|
| 226 | 226 | return true; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | * @param WP_Post $post Post object. |
| 233 | 233 | */ |
| 234 | - protected function delete_post( $post ) { |
|
| 235 | - wp_delete_post( $post->ID, true ); |
|
| 234 | + protected function delete_post($post) { |
|
| 235 | + wp_delete_post($post->ID, true); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -241,37 +241,37 @@ discard block |
||
| 241 | 241 | * @param \WP_REST_Request $request Full details about the request. |
| 242 | 242 | * @return \WP_Error\WP_REST_Response |
| 243 | 243 | */ |
| 244 | - public function update_item( $request ) { |
|
| 244 | + public function update_item($request) { |
|
| 245 | 245 | $id = (int) $request['id']; |
| 246 | - $post = get_post( $id ); |
|
| 246 | + $post = get_post($id); |
|
| 247 | 247 | |
| 248 | - if ( ! empty( $post->post_type ) && 'product_variation' === $post->post_type && 'product' === $this->post_type ) { |
|
| 249 | - return new \WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 250 | - } elseif ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) { |
|
| 251 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 248 | + if ( ! empty($post->post_type) && 'product_variation' === $post->post_type && 'product' === $this->post_type) { |
|
| 249 | + return new \WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce'), array('status' => 404)); |
|
| 250 | + } elseif (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) { |
|
| 251 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400)); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - $post = $this->prepare_item_for_database( $request ); |
|
| 255 | - if ( is_wp_error( $post ) ) { |
|
| 254 | + $post = $this->prepare_item_for_database($request); |
|
| 255 | + if (is_wp_error($post)) { |
|
| 256 | 256 | return $post; |
| 257 | 257 | } |
| 258 | 258 | // Convert the post object to an array, otherwise wp_update_post will expect non-escaped input. |
| 259 | - $post_id = wp_update_post( (array) $post, true ); |
|
| 260 | - if ( is_wp_error( $post_id ) ) { |
|
| 261 | - if ( in_array( $post_id->get_error_code(), array( 'db_update_error' ) ) ) { |
|
| 262 | - $post_id->add_data( array( 'status' => 500 ) ); |
|
| 259 | + $post_id = wp_update_post((array) $post, true); |
|
| 260 | + if (is_wp_error($post_id)) { |
|
| 261 | + if (in_array($post_id->get_error_code(), array('db_update_error'))) { |
|
| 262 | + $post_id->add_data(array('status' => 500)); |
|
| 263 | 263 | } else { |
| 264 | - $post_id->add_data( array( 'status' => 400 ) ); |
|
| 264 | + $post_id->add_data(array('status' => 400)); |
|
| 265 | 265 | } |
| 266 | 266 | return $post_id; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - $post = get_post( $post_id ); |
|
| 270 | - $this->update_additional_fields_for_object( $post, $request ); |
|
| 269 | + $post = get_post($post_id); |
|
| 270 | + $this->update_additional_fields_for_object($post, $request); |
|
| 271 | 271 | |
| 272 | 272 | // Update meta fields. |
| 273 | - $meta_fields = $this->update_post_meta_fields( $post, $request ); |
|
| 274 | - if ( is_wp_error( $meta_fields ) ) { |
|
| 273 | + $meta_fields = $this->update_post_meta_fields($post, $request); |
|
| 274 | + if (is_wp_error($meta_fields)) { |
|
| 275 | 275 | return $meta_fields; |
| 276 | 276 | } |
| 277 | 277 | |
@@ -282,11 +282,11 @@ discard block |
||
| 282 | 282 | * @param \WP_REST_Request $request Request object. |
| 283 | 283 | * @param boolean $creating True when creating item, false when updating. |
| 284 | 284 | */ |
| 285 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, false ); |
|
| 285 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, false); |
|
| 286 | 286 | |
| 287 | - $request->set_param( 'context', 'edit' ); |
|
| 288 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
| 289 | - return rest_ensure_response( $response ); |
|
| 287 | + $request->set_param('context', 'edit'); |
|
| 288 | + $response = $this->prepare_item_for_response($post, $request); |
|
| 289 | + return rest_ensure_response($response); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @param \WP_REST_Request $request Full details about the request. |
| 296 | 296 | * @return \WP_Error\WP_REST_Response |
| 297 | 297 | */ |
| 298 | - public function get_items( $request ) { |
|
| 298 | + public function get_items($request) { |
|
| 299 | 299 | $args = array(); |
| 300 | 300 | $args['offset'] = $request['offset']; |
| 301 | 301 | $args['order'] = $request['order']; |
@@ -311,19 +311,19 @@ discard block |
||
| 311 | 311 | |
| 312 | 312 | $args['date_query'] = array(); |
| 313 | 313 | // Set before into date query. Date query must be specified as an array of an array. |
| 314 | - if ( isset( $request['before'] ) ) { |
|
| 314 | + if (isset($request['before'])) { |
|
| 315 | 315 | $args['date_query'][0]['before'] = $request['before']; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // Set after into date query. Date query must be specified as an array of an array. |
| 319 | - if ( isset( $request['after'] ) ) { |
|
| 319 | + if (isset($request['after'])) { |
|
| 320 | 320 | $args['date_query'][0]['after'] = $request['after']; |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - if ( 'wc/v1' === $this->namespace ) { |
|
| 324 | - if ( is_array( $request['filter'] ) ) { |
|
| 325 | - $args = array_merge( $args, $request['filter'] ); |
|
| 326 | - unset( $args['filter'] ); |
|
| 323 | + if ('wc/v1' === $this->namespace) { |
|
| 324 | + if (is_array($request['filter'])) { |
|
| 325 | + $args = array_merge($args, $request['filter']); |
|
| 326 | + unset($args['filter']); |
|
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | |
@@ -339,59 +339,59 @@ discard block |
||
| 339 | 339 | * @param array $args Key value array of query var to query value. |
| 340 | 340 | * @param \WP_REST_Request $request The request used. |
| 341 | 341 | */ |
| 342 | - $args = apply_filters( "woocommerce_rest_{$this->post_type}_query", $args, $request ); |
|
| 343 | - $query_args = $this->prepare_items_query( $args, $request ); |
|
| 342 | + $args = apply_filters("woocommerce_rest_{$this->post_type}_query", $args, $request); |
|
| 343 | + $query_args = $this->prepare_items_query($args, $request); |
|
| 344 | 344 | |
| 345 | 345 | $posts_query = new \WP_Query(); |
| 346 | - $query_result = $posts_query->query( $query_args ); |
|
| 346 | + $query_result = $posts_query->query($query_args); |
|
| 347 | 347 | |
| 348 | 348 | $posts = array(); |
| 349 | - foreach ( $query_result as $post ) { |
|
| 350 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) { |
|
| 349 | + foreach ($query_result as $post) { |
|
| 350 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'read', $post->ID)) { |
|
| 351 | 351 | continue; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - $data = $this->prepare_item_for_response( $post, $request ); |
|
| 355 | - $posts[] = $this->prepare_response_for_collection( $data ); |
|
| 354 | + $data = $this->prepare_item_for_response($post, $request); |
|
| 355 | + $posts[] = $this->prepare_response_for_collection($data); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | $page = (int) $query_args['paged']; |
| 359 | 359 | $total_posts = $posts_query->found_posts; |
| 360 | 360 | |
| 361 | - if ( $total_posts < 1 ) { |
|
| 361 | + if ($total_posts < 1) { |
|
| 362 | 362 | // Out-of-bounds, run the query again without LIMIT for total count. |
| 363 | - unset( $query_args['paged'] ); |
|
| 363 | + unset($query_args['paged']); |
|
| 364 | 364 | $count_query = new \WP_Query(); |
| 365 | - $count_query->query( $query_args ); |
|
| 365 | + $count_query->query($query_args); |
|
| 366 | 366 | $total_posts = $count_query->found_posts; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - $max_pages = ceil( $total_posts / (int) $query_args['posts_per_page'] ); |
|
| 369 | + $max_pages = ceil($total_posts / (int) $query_args['posts_per_page']); |
|
| 370 | 370 | |
| 371 | - $response = rest_ensure_response( $posts ); |
|
| 372 | - $response->header( 'X-WP-Total', (int) $total_posts ); |
|
| 373 | - $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
| 371 | + $response = rest_ensure_response($posts); |
|
| 372 | + $response->header('X-WP-Total', (int) $total_posts); |
|
| 373 | + $response->header('X-WP-TotalPages', (int) $max_pages); |
|
| 374 | 374 | |
| 375 | 375 | $request_params = $request->get_query_params(); |
| 376 | - if ( ! empty( $request_params['filter'] ) ) { |
|
| 376 | + if ( ! empty($request_params['filter'])) { |
|
| 377 | 377 | // Normalize the pagination params. |
| 378 | - unset( $request_params['filter']['posts_per_page'] ); |
|
| 379 | - unset( $request_params['filter']['paged'] ); |
|
| 378 | + unset($request_params['filter']['posts_per_page']); |
|
| 379 | + unset($request_params['filter']['paged']); |
|
| 380 | 380 | } |
| 381 | - $base = add_query_arg( $request_params, rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 381 | + $base = add_query_arg($request_params, rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 382 | 382 | |
| 383 | - if ( $page > 1 ) { |
|
| 383 | + if ($page > 1) { |
|
| 384 | 384 | $prev_page = $page - 1; |
| 385 | - if ( $prev_page > $max_pages ) { |
|
| 385 | + if ($prev_page > $max_pages) { |
|
| 386 | 386 | $prev_page = $max_pages; |
| 387 | 387 | } |
| 388 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 389 | - $response->link_header( 'prev', $prev_link ); |
|
| 388 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 389 | + $response->link_header('prev', $prev_link); |
|
| 390 | 390 | } |
| 391 | - if ( $max_pages > $page ) { |
|
| 391 | + if ($max_pages > $page) { |
|
| 392 | 392 | $next_page = $page + 1; |
| 393 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 394 | - $response->link_header( 'next', $next_link ); |
|
| 393 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 394 | + $response->link_header('next', $next_link); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | return $response; |
@@ -403,13 +403,13 @@ discard block |
||
| 403 | 403 | * @param \WP_REST_Request $request Full details about the request. |
| 404 | 404 | * @return \WP_REST_Response|\WP_Error |
| 405 | 405 | */ |
| 406 | - public function delete_item( $request ) { |
|
| 406 | + public function delete_item($request) { |
|
| 407 | 407 | $id = (int) $request['id']; |
| 408 | 408 | $force = (bool) $request['force']; |
| 409 | - $post = get_post( $id ); |
|
| 409 | + $post = get_post($id); |
|
| 410 | 410 | |
| 411 | - if ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) { |
|
| 412 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 411 | + if (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) { |
|
| 412 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 404)); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | $supports_trash = EMPTY_TRASH_DAYS > 0; |
@@ -422,40 +422,40 @@ discard block |
||
| 422 | 422 | * @param boolean $supports_trash Whether the item type support trashing. |
| 423 | 423 | * @param WP_Post $post The Post object being considered for trashing support. |
| 424 | 424 | */ |
| 425 | - $supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_trashable", $supports_trash, $post ); |
|
| 425 | + $supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_trashable", $supports_trash, $post); |
|
| 426 | 426 | |
| 427 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $post->ID ) ) { |
|
| 427 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $post->ID)) { |
|
| 428 | 428 | /* translators: %s: post type */ |
| 429 | - return new \WP_Error( "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 429 | + return new \WP_Error("woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), array('status' => rest_authorization_required_code())); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - $request->set_param( 'context', 'edit' ); |
|
| 433 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
| 432 | + $request->set_param('context', 'edit'); |
|
| 433 | + $response = $this->prepare_item_for_response($post, $request); |
|
| 434 | 434 | |
| 435 | 435 | // If we're forcing, then delete permanently. |
| 436 | - if ( $force ) { |
|
| 437 | - $result = wp_delete_post( $id, true ); |
|
| 436 | + if ($force) { |
|
| 437 | + $result = wp_delete_post($id, true); |
|
| 438 | 438 | } else { |
| 439 | 439 | // If we don't support trashing for this type, error out. |
| 440 | - if ( ! $supports_trash ) { |
|
| 440 | + if ( ! $supports_trash) { |
|
| 441 | 441 | /* translators: %s: post type */ |
| 442 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( 'status' => 501 ) ); |
|
| 442 | + return new \WP_Error('woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array('status' => 501)); |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | // Otherwise, only trash if we haven't already. |
| 446 | - if ( 'trash' === $post->post_status ) { |
|
| 446 | + if ('trash' === $post->post_status) { |
|
| 447 | 447 | /* translators: %s: post type */ |
| 448 | - return new \WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 410 ) ); |
|
| 448 | + return new \WP_Error('woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array('status' => 410)); |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | // (Note that internally this falls through to `wp_delete_post` if |
| 452 | 452 | // the trash is disabled.) |
| 453 | - $result = wp_trash_post( $id ); |
|
| 453 | + $result = wp_trash_post($id); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - if ( ! $result ) { |
|
| 456 | + if ( ! $result) { |
|
| 457 | 457 | /* translators: %s: post type */ |
| 458 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) ); |
|
| 458 | + return new \WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array('status' => 500)); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | * @param \WP_REST_Response $response The response data. |
| 466 | 466 | * @param \WP_REST_Request $request The request sent to the API. |
| 467 | 467 | */ |
| 468 | - do_action( "woocommerce_rest_delete_{$this->post_type}", $post, $response, $request ); |
|
| 468 | + do_action("woocommerce_rest_delete_{$this->post_type}", $post, $response, $request); |
|
| 469 | 469 | |
| 470 | 470 | return $response; |
| 471 | 471 | } |
@@ -477,13 +477,13 @@ discard block |
||
| 477 | 477 | * @param \WP_REST_Request $request Request object. |
| 478 | 478 | * @return array Links for the given post. |
| 479 | 479 | */ |
| 480 | - protected function prepare_links( $post, $request ) { |
|
| 480 | + protected function prepare_links($post, $request) { |
|
| 481 | 481 | $links = array( |
| 482 | 482 | 'self' => array( |
| 483 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ), |
|
| 483 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID)), |
|
| 484 | 484 | ), |
| 485 | 485 | 'collection' => array( |
| 486 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
| 486 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
| 487 | 487 | ), |
| 488 | 488 | ); |
| 489 | 489 | |
@@ -498,12 +498,12 @@ discard block |
||
| 498 | 498 | * @param \WP_REST_Request $request Request object. |
| 499 | 499 | * @return array $query_args |
| 500 | 500 | */ |
| 501 | - protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
| 501 | + protected function prepare_items_query($prepared_args = array(), $request = null) { |
|
| 502 | 502 | |
| 503 | - $valid_vars = array_flip( $this->get_allowed_query_vars() ); |
|
| 503 | + $valid_vars = array_flip($this->get_allowed_query_vars()); |
|
| 504 | 504 | $query_args = array(); |
| 505 | - foreach ( $valid_vars as $var => $index ) { |
|
| 506 | - if ( isset( $prepared_args[ $var ] ) ) { |
|
| 505 | + foreach ($valid_vars as $var => $index) { |
|
| 506 | + if (isset($prepared_args[$var])) { |
|
| 507 | 507 | /** |
| 508 | 508 | * Filter the query_vars used in `get_items` for the constructed query. |
| 509 | 509 | * |
@@ -511,17 +511,17 @@ discard block |
||
| 511 | 511 | * |
| 512 | 512 | * @param mixed $prepared_args[ $var ] The query_var value. |
| 513 | 513 | */ |
| 514 | - $query_args[ $var ] = apply_filters( "woocommerce_rest_query_var-{$var}", $prepared_args[ $var ] ); |
|
| 514 | + $query_args[$var] = apply_filters("woocommerce_rest_query_var-{$var}", $prepared_args[$var]); |
|
| 515 | 515 | } |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | $query_args['ignore_sticky_posts'] = true; |
| 519 | 519 | |
| 520 | - if ( 'include' === $query_args['orderby'] ) { |
|
| 520 | + if ('include' === $query_args['orderby']) { |
|
| 521 | 521 | $query_args['orderby'] = 'post__in'; |
| 522 | - } elseif ( 'id' === $query_args['orderby'] ) { |
|
| 522 | + } elseif ('id' === $query_args['orderby']) { |
|
| 523 | 523 | $query_args['orderby'] = 'ID'; // ID must be capitalized. |
| 524 | - } elseif ( 'slug' === $query_args['orderby'] ) { |
|
| 524 | + } elseif ('slug' === $query_args['orderby']) { |
|
| 525 | 525 | $query_args['orderby'] = 'name'; |
| 526 | 526 | } |
| 527 | 527 | |
@@ -543,10 +543,10 @@ discard block |
||
| 543 | 543 | * |
| 544 | 544 | * @param array Array of allowed \WP_Query query vars. |
| 545 | 545 | */ |
| 546 | - $valid_vars = apply_filters( 'query_vars', $wp->public_query_vars ); |
|
| 546 | + $valid_vars = apply_filters('query_vars', $wp->public_query_vars); |
|
| 547 | 547 | |
| 548 | - $post_type_obj = get_post_type_object( $this->post_type ); |
|
| 549 | - if ( current_user_can( $post_type_obj->cap->edit_posts ) ) { |
|
| 548 | + $post_type_obj = get_post_type_object($this->post_type); |
|
| 549 | + if (current_user_can($post_type_obj->cap->edit_posts)) { |
|
| 550 | 550 | /** |
| 551 | 551 | * Filter the allowed 'private' query vars for authorized users. |
| 552 | 552 | * |
@@ -560,8 +560,8 @@ discard block |
||
| 560 | 560 | * @param array $private_query_vars Array of allowed query vars for authorized users. |
| 561 | 561 | * } |
| 562 | 562 | */ |
| 563 | - $private = apply_filters( 'woocommerce_rest_private_query_vars', $wp->private_query_vars ); |
|
| 564 | - $valid_vars = array_merge( $valid_vars, $private ); |
|
| 563 | + $private = apply_filters('woocommerce_rest_private_query_vars', $wp->private_query_vars); |
|
| 564 | + $valid_vars = array_merge($valid_vars, $private); |
|
| 565 | 565 | } |
| 566 | 566 | // Define our own in addition to WP's normal vars. |
| 567 | 567 | $rest_valid = array( |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | 'meta_compare', |
| 582 | 582 | 'meta_value_num', |
| 583 | 583 | ); |
| 584 | - $valid_vars = array_merge( $valid_vars, $rest_valid ); |
|
| 584 | + $valid_vars = array_merge($valid_vars, $rest_valid); |
|
| 585 | 585 | |
| 586 | 586 | /** |
| 587 | 587 | * Filter allowed query vars for the REST API. |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | * @param string $allowed_query_var The query var to allow. |
| 597 | 597 | * } |
| 598 | 598 | */ |
| 599 | - $valid_vars = apply_filters( 'woocommerce_rest_query_vars', $valid_vars ); |
|
| 599 | + $valid_vars = apply_filters('woocommerce_rest_query_vars', $valid_vars); |
|
| 600 | 600 | |
| 601 | 601 | return $valid_vars; |
| 602 | 602 | } |
@@ -612,19 +612,19 @@ discard block |
||
| 612 | 612 | $params['context']['default'] = 'view'; |
| 613 | 613 | |
| 614 | 614 | $params['after'] = array( |
| 615 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 615 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 616 | 616 | 'type' => 'string', |
| 617 | 617 | 'format' => 'date-time', |
| 618 | 618 | 'validate_callback' => 'rest_validate_request_arg', |
| 619 | 619 | ); |
| 620 | 620 | $params['before'] = array( |
| 621 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 621 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 622 | 622 | 'type' => 'string', |
| 623 | 623 | 'format' => 'date-time', |
| 624 | 624 | 'validate_callback' => 'rest_validate_request_arg', |
| 625 | 625 | ); |
| 626 | 626 | $params['exclude'] = array( |
| 627 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
|
| 627 | + 'description' => __('Ensure result set excludes specific IDs.', 'woocommerce'), |
|
| 628 | 628 | 'type' => 'array', |
| 629 | 629 | 'items' => array( |
| 630 | 630 | 'type' => 'integer', |
@@ -633,7 +633,7 @@ discard block |
||
| 633 | 633 | 'sanitize_callback' => 'wp_parse_id_list', |
| 634 | 634 | ); |
| 635 | 635 | $params['include'] = array( |
| 636 | - 'description' => __( 'Limit result set to specific ids.', 'woocommerce' ), |
|
| 636 | + 'description' => __('Limit result set to specific ids.', 'woocommerce'), |
|
| 637 | 637 | 'type' => 'array', |
| 638 | 638 | 'items' => array( |
| 639 | 639 | 'type' => 'integer', |
@@ -642,20 +642,20 @@ discard block |
||
| 642 | 642 | 'sanitize_callback' => 'wp_parse_id_list', |
| 643 | 643 | ); |
| 644 | 644 | $params['offset'] = array( |
| 645 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
| 645 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
| 646 | 646 | 'type' => 'integer', |
| 647 | 647 | 'sanitize_callback' => 'absint', |
| 648 | 648 | 'validate_callback' => 'rest_validate_request_arg', |
| 649 | 649 | ); |
| 650 | 650 | $params['order'] = array( |
| 651 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 651 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 652 | 652 | 'type' => 'string', |
| 653 | 653 | 'default' => 'desc', |
| 654 | - 'enum' => array( 'asc', 'desc' ), |
|
| 654 | + 'enum' => array('asc', 'desc'), |
|
| 655 | 655 | 'validate_callback' => 'rest_validate_request_arg', |
| 656 | 656 | ); |
| 657 | 657 | $params['orderby'] = array( |
| 658 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 658 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 659 | 659 | 'type' => 'string', |
| 660 | 660 | 'default' => 'date', |
| 661 | 661 | 'enum' => array( |
@@ -668,11 +668,11 @@ discard block |
||
| 668 | 668 | 'validate_callback' => 'rest_validate_request_arg', |
| 669 | 669 | ); |
| 670 | 670 | |
| 671 | - $post_type_obj = get_post_type_object( $this->post_type ); |
|
| 671 | + $post_type_obj = get_post_type_object($this->post_type); |
|
| 672 | 672 | |
| 673 | - if ( isset( $post_type_obj->hierarchical ) && $post_type_obj->hierarchical ) { |
|
| 673 | + if (isset($post_type_obj->hierarchical) && $post_type_obj->hierarchical) { |
|
| 674 | 674 | $params['parent'] = array( |
| 675 | - 'description' => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ), |
|
| 675 | + 'description' => __('Limit result set to those of particular parent IDs.', 'woocommerce'), |
|
| 676 | 676 | 'type' => 'array', |
| 677 | 677 | 'items' => array( |
| 678 | 678 | 'type' => 'integer', |
@@ -681,7 +681,7 @@ discard block |
||
| 681 | 681 | 'default' => array(), |
| 682 | 682 | ); |
| 683 | 683 | $params['parent_exclude'] = array( |
| 684 | - 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ), |
|
| 684 | + 'description' => __('Limit result set to all items except those of a particular parent ID.', 'woocommerce'), |
|
| 685 | 685 | 'type' => 'array', |
| 686 | 686 | 'items' => array( |
| 687 | 687 | 'type' => 'integer', |
@@ -691,10 +691,10 @@ discard block |
||
| 691 | 691 | ); |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | - if ( 'wc/v1' === $this->namespace ) { |
|
| 694 | + if ('wc/v1' === $this->namespace) { |
|
| 695 | 695 | $params['filter'] = array( |
| 696 | 696 | 'type' => 'object', |
| 697 | - 'description' => __( 'Use WP Query arguments to modify the response; private query vars require appropriate authorization.', 'woocommerce' ), |
|
| 697 | + 'description' => __('Use WP Query arguments to modify the response; private query vars require appropriate authorization.', 'woocommerce'), |
|
| 698 | 698 | ); |
| 699 | 699 | } |
| 700 | 700 | |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | * @param \WP_REST_Request $request Request object. |
| 709 | 709 | * @return bool|\WP_Error |
| 710 | 710 | */ |
| 711 | - protected function update_post_meta_fields( $post, $request ) { |
|
| 711 | + protected function update_post_meta_fields($post, $request) { |
|
| 712 | 712 | return true; |
| 713 | 713 | } |
| 714 | 714 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API System Status Tools controller class. |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | array( |
| 34 | 34 | array( |
| 35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
| 36 | - 'callback' => array( $this, 'get_items' ), |
|
| 37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 36 | + 'callback' => array($this, 'get_items'), |
|
| 37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 38 | 38 | 'args' => $this->get_collection_params(), |
| 39 | 39 | ), |
| 40 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 40 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 41 | 41 | ), |
| 42 | 42 | true |
| 43 | 43 | ); |
@@ -48,22 +48,22 @@ discard block |
||
| 48 | 48 | array( |
| 49 | 49 | 'args' => array( |
| 50 | 50 | 'id' => array( |
| 51 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 51 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 52 | 52 | 'type' => 'string', |
| 53 | 53 | ), |
| 54 | 54 | ), |
| 55 | 55 | array( |
| 56 | 56 | 'methods' => \WP_REST_Server::READABLE, |
| 57 | - 'callback' => array( $this, 'get_item' ), |
|
| 58 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 57 | + 'callback' => array($this, 'get_item'), |
|
| 58 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 59 | 59 | ), |
| 60 | 60 | array( |
| 61 | 61 | 'methods' => \WP_REST_Server::EDITABLE, |
| 62 | - 'callback' => array( $this, 'update_item' ), |
|
| 63 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
| 64 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
| 62 | + 'callback' => array($this, 'update_item'), |
|
| 63 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
| 64 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
| 65 | 65 | ), |
| 66 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 66 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 67 | 67 | ), |
| 68 | 68 | true |
| 69 | 69 | ); |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | * @param \WP_REST_Request $request Full details about the request. |
| 76 | 76 | * @return \WP_Error|boolean |
| 77 | 77 | */ |
| 78 | - public function get_items_permissions_check( $request ) { |
|
| 79 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { |
|
| 80 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 78 | + public function get_items_permissions_check($request) { |
|
| 79 | + if ( ! wc_rest_check_manager_permissions('system_status', 'read')) { |
|
| 80 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 81 | 81 | } |
| 82 | 82 | return true; |
| 83 | 83 | } |
@@ -88,9 +88,9 @@ discard block |
||
| 88 | 88 | * @param \WP_REST_Request $request Full details about the request. |
| 89 | 89 | * @return \WP_Error|boolean |
| 90 | 90 | */ |
| 91 | - public function get_item_permissions_check( $request ) { |
|
| 92 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { |
|
| 93 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 91 | + public function get_item_permissions_check($request) { |
|
| 92 | + if ( ! wc_rest_check_manager_permissions('system_status', 'read')) { |
|
| 93 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 94 | 94 | } |
| 95 | 95 | return true; |
| 96 | 96 | } |
@@ -101,9 +101,9 @@ discard block |
||
| 101 | 101 | * @param \WP_REST_Request $request Full details about the request. |
| 102 | 102 | * @return \WP_Error|boolean |
| 103 | 103 | */ |
| 104 | - public function update_item_permissions_check( $request ) { |
|
| 105 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'edit' ) ) { |
|
| 106 | - return new \WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot update resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 104 | + public function update_item_permissions_check($request) { |
|
| 105 | + if ( ! wc_rest_check_manager_permissions('system_status', 'edit')) { |
|
| 106 | + return new \WP_Error('woocommerce_rest_cannot_update', __('Sorry, you cannot update resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 107 | 107 | } |
| 108 | 108 | return true; |
| 109 | 109 | } |
@@ -117,89 +117,89 @@ discard block |
||
| 117 | 117 | public function get_tools() { |
| 118 | 118 | $tools = array( |
| 119 | 119 | 'clear_transients' => array( |
| 120 | - 'name' => __( 'WooCommerce transients', 'woocommerce' ), |
|
| 121 | - 'button' => __( 'Clear transients', 'woocommerce' ), |
|
| 122 | - 'desc' => __( 'This tool will clear the product/shop transients cache.', 'woocommerce' ), |
|
| 120 | + 'name' => __('WooCommerce transients', 'woocommerce'), |
|
| 121 | + 'button' => __('Clear transients', 'woocommerce'), |
|
| 122 | + 'desc' => __('This tool will clear the product/shop transients cache.', 'woocommerce'), |
|
| 123 | 123 | ), |
| 124 | 124 | 'clear_expired_transients' => array( |
| 125 | - 'name' => __( 'Expired transients', 'woocommerce' ), |
|
| 126 | - 'button' => __( 'Clear transients', 'woocommerce' ), |
|
| 127 | - 'desc' => __( 'This tool will clear ALL expired transients from WordPress.', 'woocommerce' ), |
|
| 125 | + 'name' => __('Expired transients', 'woocommerce'), |
|
| 126 | + 'button' => __('Clear transients', 'woocommerce'), |
|
| 127 | + 'desc' => __('This tool will clear ALL expired transients from WordPress.', 'woocommerce'), |
|
| 128 | 128 | ), |
| 129 | 129 | 'delete_orphaned_variations' => array( |
| 130 | - 'name' => __( 'Orphaned variations', 'woocommerce' ), |
|
| 131 | - 'button' => __( 'Delete orphaned variations', 'woocommerce' ), |
|
| 132 | - 'desc' => __( 'This tool will delete all variations which have no parent.', 'woocommerce' ), |
|
| 130 | + 'name' => __('Orphaned variations', 'woocommerce'), |
|
| 131 | + 'button' => __('Delete orphaned variations', 'woocommerce'), |
|
| 132 | + 'desc' => __('This tool will delete all variations which have no parent.', 'woocommerce'), |
|
| 133 | 133 | ), |
| 134 | 134 | 'clear_expired_download_permissions' => array( |
| 135 | - 'name' => __( 'Used-up download permissions', 'woocommerce' ), |
|
| 136 | - 'button' => __( 'Clean up download permissions', 'woocommerce' ), |
|
| 137 | - 'desc' => __( 'This tool will delete expired download permissions and permissions with 0 remaining downloads.', 'woocommerce' ), |
|
| 135 | + 'name' => __('Used-up download permissions', 'woocommerce'), |
|
| 136 | + 'button' => __('Clean up download permissions', 'woocommerce'), |
|
| 137 | + 'desc' => __('This tool will delete expired download permissions and permissions with 0 remaining downloads.', 'woocommerce'), |
|
| 138 | 138 | ), |
| 139 | 139 | 'regenerate_product_lookup_tables' => array( |
| 140 | - 'name' => __( 'Product lookup tables', 'woocommerce' ), |
|
| 141 | - 'button' => __( 'Regenerate', 'woocommerce' ), |
|
| 142 | - 'desc' => __( 'This tool will regenerate product lookup table data. This process may take a while.', 'woocommerce' ), |
|
| 140 | + 'name' => __('Product lookup tables', 'woocommerce'), |
|
| 141 | + 'button' => __('Regenerate', 'woocommerce'), |
|
| 142 | + 'desc' => __('This tool will regenerate product lookup table data. This process may take a while.', 'woocommerce'), |
|
| 143 | 143 | ), |
| 144 | 144 | 'recount_terms' => array( |
| 145 | - 'name' => __( 'Term counts', 'woocommerce' ), |
|
| 146 | - 'button' => __( 'Recount terms', 'woocommerce' ), |
|
| 147 | - 'desc' => __( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', 'woocommerce' ), |
|
| 145 | + 'name' => __('Term counts', 'woocommerce'), |
|
| 146 | + 'button' => __('Recount terms', 'woocommerce'), |
|
| 147 | + 'desc' => __('This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', 'woocommerce'), |
|
| 148 | 148 | ), |
| 149 | 149 | 'reset_roles' => array( |
| 150 | - 'name' => __( 'Capabilities', 'woocommerce' ), |
|
| 151 | - 'button' => __( 'Reset capabilities', 'woocommerce' ), |
|
| 152 | - 'desc' => __( 'This tool will reset the admin, customer and shop_manager roles to default. Use this if your users cannot access all of the WooCommerce admin pages.', 'woocommerce' ), |
|
| 150 | + 'name' => __('Capabilities', 'woocommerce'), |
|
| 151 | + 'button' => __('Reset capabilities', 'woocommerce'), |
|
| 152 | + 'desc' => __('This tool will reset the admin, customer and shop_manager roles to default. Use this if your users cannot access all of the WooCommerce admin pages.', 'woocommerce'), |
|
| 153 | 153 | ), |
| 154 | 154 | 'clear_sessions' => array( |
| 155 | - 'name' => __( 'Clear customer sessions', 'woocommerce' ), |
|
| 156 | - 'button' => __( 'Clear', 'woocommerce' ), |
|
| 155 | + 'name' => __('Clear customer sessions', 'woocommerce'), |
|
| 156 | + 'button' => __('Clear', 'woocommerce'), |
|
| 157 | 157 | 'desc' => sprintf( |
| 158 | 158 | '<strong class="red">%1$s</strong> %2$s', |
| 159 | - __( 'Note:', 'woocommerce' ), |
|
| 160 | - __( 'This tool will delete all customer session data from the database, including current carts and saved carts in the database.', 'woocommerce' ) |
|
| 159 | + __('Note:', 'woocommerce'), |
|
| 160 | + __('This tool will delete all customer session data from the database, including current carts and saved carts in the database.', 'woocommerce') |
|
| 161 | 161 | ), |
| 162 | 162 | ), |
| 163 | 163 | 'install_pages' => array( |
| 164 | - 'name' => __( 'Create default WooCommerce pages', 'woocommerce' ), |
|
| 165 | - 'button' => __( 'Create pages', 'woocommerce' ), |
|
| 164 | + 'name' => __('Create default WooCommerce pages', 'woocommerce'), |
|
| 165 | + 'button' => __('Create pages', 'woocommerce'), |
|
| 166 | 166 | 'desc' => sprintf( |
| 167 | 167 | '<strong class="red">%1$s</strong> %2$s', |
| 168 | - __( 'Note:', 'woocommerce' ), |
|
| 169 | - __( 'This tool will install all the missing WooCommerce pages. Pages already defined and set up will not be replaced.', 'woocommerce' ) |
|
| 168 | + __('Note:', 'woocommerce'), |
|
| 169 | + __('This tool will install all the missing WooCommerce pages. Pages already defined and set up will not be replaced.', 'woocommerce') |
|
| 170 | 170 | ), |
| 171 | 171 | ), |
| 172 | 172 | 'delete_taxes' => array( |
| 173 | - 'name' => __( 'Delete WooCommerce tax rates', 'woocommerce' ), |
|
| 174 | - 'button' => __( 'Delete tax rates', 'woocommerce' ), |
|
| 173 | + 'name' => __('Delete WooCommerce tax rates', 'woocommerce'), |
|
| 174 | + 'button' => __('Delete tax rates', 'woocommerce'), |
|
| 175 | 175 | 'desc' => sprintf( |
| 176 | 176 | '<strong class="red">%1$s</strong> %2$s', |
| 177 | - __( 'Note:', 'woocommerce' ), |
|
| 178 | - __( 'This option will delete ALL of your tax rates, use with caution. This action cannot be reversed.', 'woocommerce' ) |
|
| 177 | + __('Note:', 'woocommerce'), |
|
| 178 | + __('This option will delete ALL of your tax rates, use with caution. This action cannot be reversed.', 'woocommerce') |
|
| 179 | 179 | ), |
| 180 | 180 | ), |
| 181 | 181 | 'regenerate_thumbnails' => array( |
| 182 | - 'name' => __( 'Regenerate shop thumbnails', 'woocommerce' ), |
|
| 183 | - 'button' => __( 'Regenerate', 'woocommerce' ), |
|
| 184 | - 'desc' => __( 'This will regenerate all shop thumbnails to match your theme and/or image settings.', 'woocommerce' ), |
|
| 182 | + 'name' => __('Regenerate shop thumbnails', 'woocommerce'), |
|
| 183 | + 'button' => __('Regenerate', 'woocommerce'), |
|
| 184 | + 'desc' => __('This will regenerate all shop thumbnails to match your theme and/or image settings.', 'woocommerce'), |
|
| 185 | 185 | ), |
| 186 | 186 | 'db_update_routine' => array( |
| 187 | - 'name' => __( 'Update database', 'woocommerce' ), |
|
| 188 | - 'button' => __( 'Update database', 'woocommerce' ), |
|
| 187 | + 'name' => __('Update database', 'woocommerce'), |
|
| 188 | + 'button' => __('Update database', 'woocommerce'), |
|
| 189 | 189 | 'desc' => sprintf( |
| 190 | 190 | '<strong class="red">%1$s</strong> %2$s', |
| 191 | - __( 'Note:', 'woocommerce' ), |
|
| 192 | - __( 'This tool will update your WooCommerce database to the latest version. Please ensure you make sufficient backups before proceeding.', 'woocommerce' ) |
|
| 191 | + __('Note:', 'woocommerce'), |
|
| 192 | + __('This tool will update your WooCommerce database to the latest version. Please ensure you make sufficient backups before proceeding.', 'woocommerce') |
|
| 193 | 193 | ), |
| 194 | 194 | ), |
| 195 | 195 | ); |
| 196 | 196 | |
| 197 | 197 | // Jetpack does the image resizing heavy lifting so you don't have to. |
| 198 | - if ( ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) || ! apply_filters( 'woocommerce_background_image_regeneration', true ) ) { |
|
| 199 | - unset( $tools['regenerate_thumbnails'] ); |
|
| 198 | + if ((class_exists('Jetpack') && Jetpack::is_module_active('photon')) || ! apply_filters('woocommerce_background_image_regeneration', true)) { |
|
| 199 | + unset($tools['regenerate_thumbnails']); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - return apply_filters( 'woocommerce_debug_tools', $tools ); |
|
| 202 | + return apply_filters('woocommerce_debug_tools', $tools); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -208,9 +208,9 @@ discard block |
||
| 208 | 208 | * @param \WP_REST_Request $request Full details about the request. |
| 209 | 209 | * @return \WP_Error\WP_REST_Response |
| 210 | 210 | */ |
| 211 | - public function get_items( $request ) { |
|
| 211 | + public function get_items($request) { |
|
| 212 | 212 | $tools = array(); |
| 213 | - foreach ( $this->get_tools() as $id => $tool ) { |
|
| 213 | + foreach ($this->get_tools() as $id => $tool) { |
|
| 214 | 214 | $tools[] = $this->prepare_response_for_collection( |
| 215 | 215 | $this->prepare_item_for_response( |
| 216 | 216 | array( |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | ); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $response = rest_ensure_response( $tools ); |
|
| 227 | + $response = rest_ensure_response($tools); |
|
| 228 | 228 | return $response; |
| 229 | 229 | } |
| 230 | 230 | |
@@ -234,12 +234,12 @@ discard block |
||
| 234 | 234 | * @param \WP_REST_Request $request Request data. |
| 235 | 235 | * @return \WP_Error\WP_REST_Response |
| 236 | 236 | */ |
| 237 | - public function get_item( $request ) { |
|
| 237 | + public function get_item($request) { |
|
| 238 | 238 | $tools = $this->get_tools(); |
| 239 | - if ( empty( $tools[ $request['id'] ] ) ) { |
|
| 240 | - return new \WP_Error( 'woocommerce_rest_system_status_tool_invalid_id', __( 'Invalid tool ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 239 | + if (empty($tools[$request['id']])) { |
|
| 240 | + return new \WP_Error('woocommerce_rest_system_status_tool_invalid_id', __('Invalid tool ID.', 'woocommerce'), array('status' => 404)); |
|
| 241 | 241 | } |
| 242 | - $tool = $tools[ $request['id'] ]; |
|
| 242 | + $tool = $tools[$request['id']]; |
|
| 243 | 243 | return rest_ensure_response( |
| 244 | 244 | $this->prepare_item_for_response( |
| 245 | 245 | array( |
@@ -259,13 +259,13 @@ discard block |
||
| 259 | 259 | * @param \WP_REST_Request $request Request data. |
| 260 | 260 | * @return \WP_Error\WP_REST_Response |
| 261 | 261 | */ |
| 262 | - public function update_item( $request ) { |
|
| 262 | + public function update_item($request) { |
|
| 263 | 263 | $tools = $this->get_tools(); |
| 264 | - if ( empty( $tools[ $request['id'] ] ) ) { |
|
| 265 | - return new \WP_Error( 'woocommerce_rest_system_status_tool_invalid_id', __( 'Invalid tool ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 264 | + if (empty($tools[$request['id']])) { |
|
| 265 | + return new \WP_Error('woocommerce_rest_system_status_tool_invalid_id', __('Invalid tool ID.', 'woocommerce'), array('status' => 404)); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - $tool = $tools[ $request['id'] ]; |
|
| 268 | + $tool = $tools[$request['id']]; |
|
| 269 | 269 | $tool = array( |
| 270 | 270 | 'id' => $request['id'], |
| 271 | 271 | 'name' => $tool['name'], |
@@ -273,8 +273,8 @@ discard block |
||
| 273 | 273 | 'description' => $tool['desc'], |
| 274 | 274 | ); |
| 275 | 275 | |
| 276 | - $execute_return = $this->execute_tool( $request['id'] ); |
|
| 277 | - $tool = array_merge( $tool, $execute_return ); |
|
| 276 | + $execute_return = $this->execute_tool($request['id']); |
|
| 277 | + $tool = array_merge($tool, $execute_return); |
|
| 278 | 278 | |
| 279 | 279 | /** |
| 280 | 280 | * Fires after a WooCommerce REST system status tool has been executed. |
@@ -282,11 +282,11 @@ discard block |
||
| 282 | 282 | * @param array $tool Details about the tool that has been executed. |
| 283 | 283 | * @param \WP_REST_Request $request The current \WP_REST_Request object. |
| 284 | 284 | */ |
| 285 | - do_action( 'woocommerce_rest_insert_system_status_tool', $tool, $request ); |
|
| 285 | + do_action('woocommerce_rest_insert_system_status_tool', $tool, $request); |
|
| 286 | 286 | |
| 287 | - $request->set_param( 'context', 'edit' ); |
|
| 288 | - $response = $this->prepare_item_for_response( $tool, $request ); |
|
| 289 | - return rest_ensure_response( $response ); |
|
| 287 | + $request->set_param('context', 'edit'); |
|
| 288 | + $response = $this->prepare_item_for_response($tool, $request); |
|
| 289 | + return rest_ensure_response($response); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -296,14 +296,14 @@ discard block |
||
| 296 | 296 | * @param \WP_REST_Request $request Request object. |
| 297 | 297 | * @return \WP_REST_Response $response Response data. |
| 298 | 298 | */ |
| 299 | - public function prepare_item_for_response( $item, $request ) { |
|
| 300 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
| 301 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
| 302 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 299 | + public function prepare_item_for_response($item, $request) { |
|
| 300 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
| 301 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
| 302 | + $data = $this->filter_response_by_context($data, $context); |
|
| 303 | 303 | |
| 304 | - $response = rest_ensure_response( $data ); |
|
| 304 | + $response = rest_ensure_response($data); |
|
| 305 | 305 | |
| 306 | - $response->add_links( $this->prepare_links( $item['id'] ) ); |
|
| 306 | + $response->add_links($this->prepare_links($item['id'])); |
|
| 307 | 307 | |
| 308 | 308 | return $response; |
| 309 | 309 | } |
@@ -320,46 +320,46 @@ discard block |
||
| 320 | 320 | 'type' => 'object', |
| 321 | 321 | 'properties' => array( |
| 322 | 322 | 'id' => array( |
| 323 | - 'description' => __( 'A unique identifier for the tool.', 'woocommerce' ), |
|
| 323 | + 'description' => __('A unique identifier for the tool.', 'woocommerce'), |
|
| 324 | 324 | 'type' => 'string', |
| 325 | - 'context' => array( 'view', 'edit' ), |
|
| 325 | + 'context' => array('view', 'edit'), |
|
| 326 | 326 | 'arg_options' => array( |
| 327 | 327 | 'sanitize_callback' => 'sanitize_title', |
| 328 | 328 | ), |
| 329 | 329 | ), |
| 330 | 330 | 'name' => array( |
| 331 | - 'description' => __( 'Tool name.', 'woocommerce' ), |
|
| 331 | + 'description' => __('Tool name.', 'woocommerce'), |
|
| 332 | 332 | 'type' => 'string', |
| 333 | - 'context' => array( 'view', 'edit' ), |
|
| 333 | + 'context' => array('view', 'edit'), |
|
| 334 | 334 | 'arg_options' => array( |
| 335 | 335 | 'sanitize_callback' => 'sanitize_text_field', |
| 336 | 336 | ), |
| 337 | 337 | ), |
| 338 | 338 | 'action' => array( |
| 339 | - 'description' => __( 'What running the tool will do.', 'woocommerce' ), |
|
| 339 | + 'description' => __('What running the tool will do.', 'woocommerce'), |
|
| 340 | 340 | 'type' => 'string', |
| 341 | - 'context' => array( 'view', 'edit' ), |
|
| 341 | + 'context' => array('view', 'edit'), |
|
| 342 | 342 | 'arg_options' => array( |
| 343 | 343 | 'sanitize_callback' => 'sanitize_text_field', |
| 344 | 344 | ), |
| 345 | 345 | ), |
| 346 | 346 | 'description' => array( |
| 347 | - 'description' => __( 'Tool description.', 'woocommerce' ), |
|
| 347 | + 'description' => __('Tool description.', 'woocommerce'), |
|
| 348 | 348 | 'type' => 'string', |
| 349 | - 'context' => array( 'view', 'edit' ), |
|
| 349 | + 'context' => array('view', 'edit'), |
|
| 350 | 350 | 'arg_options' => array( |
| 351 | 351 | 'sanitize_callback' => 'sanitize_text_field', |
| 352 | 352 | ), |
| 353 | 353 | ), |
| 354 | 354 | 'success' => array( |
| 355 | - 'description' => __( 'Did the tool run successfully?', 'woocommerce' ), |
|
| 355 | + 'description' => __('Did the tool run successfully?', 'woocommerce'), |
|
| 356 | 356 | 'type' => 'boolean', |
| 357 | - 'context' => array( 'edit' ), |
|
| 357 | + 'context' => array('edit'), |
|
| 358 | 358 | ), |
| 359 | 359 | 'message' => array( |
| 360 | - 'description' => __( 'Tool return message.', 'woocommerce' ), |
|
| 360 | + 'description' => __('Tool return message.', 'woocommerce'), |
|
| 361 | 361 | 'type' => 'string', |
| 362 | - 'context' => array( 'edit' ), |
|
| 362 | + 'context' => array('edit'), |
|
| 363 | 363 | 'arg_options' => array( |
| 364 | 364 | 'sanitize_callback' => 'sanitize_text_field', |
| 365 | 365 | ), |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | ), |
| 368 | 368 | ); |
| 369 | 369 | |
| 370 | - return $this->add_additional_fields_schema( $schema ); |
|
| 370 | + return $this->add_additional_fields_schema($schema); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
@@ -376,11 +376,11 @@ discard block |
||
| 376 | 376 | * @param string $id ID. |
| 377 | 377 | * @return array |
| 378 | 378 | */ |
| 379 | - protected function prepare_links( $id ) { |
|
| 379 | + protected function prepare_links($id) { |
|
| 380 | 380 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
| 381 | 381 | $links = array( |
| 382 | 382 | 'item' => array( |
| 383 | - 'href' => rest_url( trailingslashit( $base ) . $id ), |
|
| 383 | + 'href' => rest_url(trailingslashit($base) . $id), |
|
| 384 | 384 | 'embeddable' => true, |
| 385 | 385 | ), |
| 386 | 386 | ); |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | */ |
| 396 | 396 | public function get_collection_params() { |
| 397 | 397 | return array( |
| 398 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 398 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 399 | 399 | ); |
| 400 | 400 | } |
| 401 | 401 | |
@@ -405,30 +405,30 @@ discard block |
||
| 405 | 405 | * @param string $tool Tool. |
| 406 | 406 | * @return array |
| 407 | 407 | */ |
| 408 | - public function execute_tool( $tool ) { |
|
| 408 | + public function execute_tool($tool) { |
|
| 409 | 409 | global $wpdb; |
| 410 | 410 | $ran = true; |
| 411 | - switch ( $tool ) { |
|
| 411 | + switch ($tool) { |
|
| 412 | 412 | case 'clear_transients': |
| 413 | 413 | wc_delete_product_transients(); |
| 414 | 414 | wc_delete_shop_order_transients(); |
| 415 | - delete_transient( 'wc_count_comments' ); |
|
| 415 | + delete_transient('wc_count_comments'); |
|
| 416 | 416 | |
| 417 | 417 | $attribute_taxonomies = wc_get_attribute_taxonomies(); |
| 418 | 418 | |
| 419 | - if ( $attribute_taxonomies ) { |
|
| 420 | - foreach ( $attribute_taxonomies as $attribute ) { |
|
| 421 | - delete_transient( 'wc_layered_nav_counts_pa_' . $attribute->attribute_name ); |
|
| 419 | + if ($attribute_taxonomies) { |
|
| 420 | + foreach ($attribute_taxonomies as $attribute) { |
|
| 421 | + delete_transient('wc_layered_nav_counts_pa_' . $attribute->attribute_name); |
|
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | - \WC_Cache_Helper::get_transient_version( 'shipping', true ); |
|
| 426 | - $message = __( 'Product transients cleared', 'woocommerce' ); |
|
| 425 | + \WC_Cache_Helper::get_transient_version('shipping', true); |
|
| 426 | + $message = __('Product transients cleared', 'woocommerce'); |
|
| 427 | 427 | break; |
| 428 | 428 | |
| 429 | 429 | case 'clear_expired_transients': |
| 430 | 430 | /* translators: %d: amount of expired transients */ |
| 431 | - $message = sprintf( __( '%d transients rows cleared', 'woocommerce' ), wc_delete_expired_transients() ); |
|
| 431 | + $message = sprintf(__('%d transients rows cleared', 'woocommerce'), wc_delete_expired_transients()); |
|
| 432 | 432 | break; |
| 433 | 433 | |
| 434 | 434 | case 'delete_orphaned_variations': |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | ) |
| 443 | 443 | ); |
| 444 | 444 | /* translators: %d: amount of orphaned variations */ |
| 445 | - $message = sprintf( __( '%d orphaned variations deleted', 'woocommerce' ), $result ); |
|
| 445 | + $message = sprintf(__('%d orphaned variations deleted', 'woocommerce'), $result); |
|
| 446 | 446 | break; |
| 447 | 447 | |
| 448 | 448 | case 'clear_expired_download_permissions': |
@@ -452,25 +452,25 @@ discard block |
||
| 452 | 452 | $wpdb->prepare( |
| 453 | 453 | "DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions |
| 454 | 454 | WHERE ( downloads_remaining != '' AND downloads_remaining = 0 ) OR ( access_expires IS NOT NULL AND access_expires < %s )", |
| 455 | - date( 'Y-m-d', current_time( 'timestamp' ) ) |
|
| 455 | + date('Y-m-d', current_time('timestamp')) |
|
| 456 | 456 | ) |
| 457 | 457 | ) |
| 458 | 458 | ); |
| 459 | 459 | /* translators: %d: amount of permissions */ |
| 460 | - $message = sprintf( __( '%d permissions deleted', 'woocommerce' ), $result ); |
|
| 460 | + $message = sprintf(__('%d permissions deleted', 'woocommerce'), $result); |
|
| 461 | 461 | break; |
| 462 | 462 | |
| 463 | 463 | case 'regenerate_product_lookup_tables': |
| 464 | - if ( ! wc_update_product_lookup_tables_is_running() ) { |
|
| 464 | + if ( ! wc_update_product_lookup_tables_is_running()) { |
|
| 465 | 465 | wc_update_product_lookup_tables(); |
| 466 | 466 | } |
| 467 | - $message = __( 'Lookup tables are regenerating', 'woocommerce' ); |
|
| 467 | + $message = __('Lookup tables are regenerating', 'woocommerce'); |
|
| 468 | 468 | break; |
| 469 | 469 | case 'reset_roles': |
| 470 | 470 | // Remove then re-add caps and roles. |
| 471 | 471 | \WC_Install::remove_roles(); |
| 472 | 472 | \WC_Install::create_roles(); |
| 473 | - $message = __( 'Roles successfully reset', 'woocommerce' ); |
|
| 473 | + $message = __('Roles successfully reset', 'woocommerce'); |
|
| 474 | 474 | break; |
| 475 | 475 | |
| 476 | 476 | case 'recount_terms': |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | 'fields' => 'id=>parent', |
| 482 | 482 | ) |
| 483 | 483 | ); |
| 484 | - _wc_term_recount( $product_cats, get_taxonomy( 'product_cat' ), true, false ); |
|
| 484 | + _wc_term_recount($product_cats, get_taxonomy('product_cat'), true, false); |
|
| 485 | 485 | $product_tags = get_terms( |
| 486 | 486 | 'product_tag', |
| 487 | 487 | array( |
@@ -489,61 +489,61 @@ discard block |
||
| 489 | 489 | 'fields' => 'id=>parent', |
| 490 | 490 | ) |
| 491 | 491 | ); |
| 492 | - _wc_term_recount( $product_tags, get_taxonomy( 'product_tag' ), true, false ); |
|
| 493 | - $message = __( 'Terms successfully recounted', 'woocommerce' ); |
|
| 492 | + _wc_term_recount($product_tags, get_taxonomy('product_tag'), true, false); |
|
| 493 | + $message = __('Terms successfully recounted', 'woocommerce'); |
|
| 494 | 494 | break; |
| 495 | 495 | |
| 496 | 496 | case 'clear_sessions': |
| 497 | - $wpdb->query( "TRUNCATE {$wpdb->prefix}woocommerce_sessions" ); |
|
| 498 | - $result = absint( $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key='_woocommerce_persistent_cart_" . get_current_blog_id() . "';" ) ); // WPCS: unprepared SQL ok. |
|
| 497 | + $wpdb->query("TRUNCATE {$wpdb->prefix}woocommerce_sessions"); |
|
| 498 | + $result = absint($wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key='_woocommerce_persistent_cart_" . get_current_blog_id() . "';")); // WPCS: unprepared SQL ok. |
|
| 499 | 499 | wp_cache_flush(); |
| 500 | 500 | /* translators: %d: amount of sessions */ |
| 501 | - $message = sprintf( __( 'Deleted all active sessions, and %d saved carts.', 'woocommerce' ), absint( $result ) ); |
|
| 501 | + $message = sprintf(__('Deleted all active sessions, and %d saved carts.', 'woocommerce'), absint($result)); |
|
| 502 | 502 | break; |
| 503 | 503 | |
| 504 | 504 | case 'install_pages': |
| 505 | 505 | \WC_Install::create_pages(); |
| 506 | - $message = __( 'All missing WooCommerce pages successfully installed', 'woocommerce' ); |
|
| 506 | + $message = __('All missing WooCommerce pages successfully installed', 'woocommerce'); |
|
| 507 | 507 | break; |
| 508 | 508 | |
| 509 | 509 | case 'delete_taxes': |
| 510 | - $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rates;" ); |
|
| 511 | - $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations;" ); |
|
| 512 | - \WC_Cache_Helper::incr_cache_prefix( 'taxes' ); |
|
| 513 | - $message = __( 'Tax rates successfully deleted', 'woocommerce' ); |
|
| 510 | + $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rates;"); |
|
| 511 | + $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations;"); |
|
| 512 | + \WC_Cache_Helper::incr_cache_prefix('taxes'); |
|
| 513 | + $message = __('Tax rates successfully deleted', 'woocommerce'); |
|
| 514 | 514 | break; |
| 515 | 515 | |
| 516 | 516 | case 'regenerate_thumbnails': |
| 517 | 517 | \WC_Regenerate_Images::queue_image_regeneration(); |
| 518 | - $message = __( 'Thumbnail regeneration has been scheduled to run in the background.', 'woocommerce' ); |
|
| 518 | + $message = __('Thumbnail regeneration has been scheduled to run in the background.', 'woocommerce'); |
|
| 519 | 519 | break; |
| 520 | 520 | |
| 521 | 521 | case 'db_update_routine': |
| 522 | 522 | $blog_id = get_current_blog_id(); |
| 523 | 523 | // Used to fire an action added in WP_Background_Process::_construct() that calls WP_Background_Process::handle_cron_healthcheck(). |
| 524 | 524 | // This method will make sure the database updates are executed even if cron is disabled. Nothing will happen if the updates are already running. |
| 525 | - do_action( 'wp_' . $blog_id . '_wc_updater_cron' ); |
|
| 526 | - $message = __( 'Database upgrade routine has been scheduled to run in the background.', 'woocommerce' ); |
|
| 525 | + do_action('wp_' . $blog_id . '_wc_updater_cron'); |
|
| 526 | + $message = __('Database upgrade routine has been scheduled to run in the background.', 'woocommerce'); |
|
| 527 | 527 | break; |
| 528 | 528 | |
| 529 | 529 | default: |
| 530 | 530 | $tools = $this->get_tools(); |
| 531 | - if ( isset( $tools[ $tool ]['callback'] ) ) { |
|
| 532 | - $callback = $tools[ $tool ]['callback']; |
|
| 533 | - $return = call_user_func( $callback ); |
|
| 534 | - if ( is_string( $return ) ) { |
|
| 531 | + if (isset($tools[$tool]['callback'])) { |
|
| 532 | + $callback = $tools[$tool]['callback']; |
|
| 533 | + $return = call_user_func($callback); |
|
| 534 | + if (is_string($return)) { |
|
| 535 | 535 | $message = $return; |
| 536 | - } elseif ( false === $return ) { |
|
| 537 | - $callback_string = is_array( $callback ) ? get_class( $callback[0] ) . '::' . $callback[1] : $callback; |
|
| 536 | + } elseif (false === $return) { |
|
| 537 | + $callback_string = is_array($callback) ? get_class($callback[0]) . '::' . $callback[1] : $callback; |
|
| 538 | 538 | $ran = false; |
| 539 | 539 | /* translators: %s: callback string */ |
| 540 | - $message = sprintf( __( 'There was an error calling %s', 'woocommerce' ), $callback_string ); |
|
| 540 | + $message = sprintf(__('There was an error calling %s', 'woocommerce'), $callback_string); |
|
| 541 | 541 | } else { |
| 542 | - $message = __( 'Tool ran.', 'woocommerce' ); |
|
| 542 | + $message = __('Tool ran.', 'woocommerce'); |
|
| 543 | 543 | } |
| 544 | 544 | } else { |
| 545 | 545 | $ran = false; |
| 546 | - $message = __( 'There was an error calling this tool. There is no callback present.', 'woocommerce' ); |
|
| 546 | + $message = __('There was an error calling this tool. There is no callback present.', 'woocommerce'); |
|
| 547 | 547 | } |
| 548 | 548 | break; |
| 549 | 549 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * Shipping methods controller class. |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | array( |
| 34 | 34 | array( |
| 35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
| 36 | - 'callback' => array( $this, 'get_items' ), |
|
| 37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 36 | + 'callback' => array($this, 'get_items'), |
|
| 37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 38 | 38 | 'args' => $this->get_collection_params(), |
| 39 | 39 | ), |
| 40 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 40 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 41 | 41 | ), |
| 42 | 42 | true |
| 43 | 43 | ); |
@@ -47,19 +47,19 @@ discard block |
||
| 47 | 47 | array( |
| 48 | 48 | 'args' => array( |
| 49 | 49 | 'id' => array( |
| 50 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 50 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 51 | 51 | 'type' => 'string', |
| 52 | 52 | ), |
| 53 | 53 | ), |
| 54 | 54 | array( |
| 55 | 55 | 'methods' => \WP_REST_Server::READABLE, |
| 56 | - 'callback' => array( $this, 'get_item' ), |
|
| 57 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 56 | + 'callback' => array($this, 'get_item'), |
|
| 57 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 58 | 58 | 'args' => array( |
| 59 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 59 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 60 | 60 | ), |
| 61 | 61 | ), |
| 62 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 62 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 63 | 63 | ), |
| 64 | 64 | true |
| 65 | 65 | ); |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | * @param \WP_REST_Request $request Full details about the request. |
| 72 | 72 | * @return \WP_Error|boolean |
| 73 | 73 | */ |
| 74 | - public function get_items_permissions_check( $request ) { |
|
| 75 | - if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) { |
|
| 76 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 74 | + public function get_items_permissions_check($request) { |
|
| 75 | + if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) { |
|
| 76 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 77 | 77 | } |
| 78 | 78 | return true; |
| 79 | 79 | } |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | * @param \WP_REST_Request $request Full details about the request. |
| 85 | 85 | * @return \WP_Error|boolean |
| 86 | 86 | */ |
| 87 | - public function get_item_permissions_check( $request ) { |
|
| 88 | - if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) { |
|
| 89 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 87 | + public function get_item_permissions_check($request) { |
|
| 88 | + if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) { |
|
| 89 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 90 | 90 | } |
| 91 | 91 | return true; |
| 92 | 92 | } |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | * @param \WP_REST_Request $request Full details about the request. |
| 98 | 98 | * @return \WP_Error\WP_REST_Response |
| 99 | 99 | */ |
| 100 | - public function get_items( $request ) { |
|
| 100 | + public function get_items($request) { |
|
| 101 | 101 | $wc_shipping = \WC_Shipping::instance(); |
| 102 | 102 | $response = array(); |
| 103 | - foreach ( $wc_shipping->get_shipping_methods() as $id => $shipping_method ) { |
|
| 104 | - $method = $this->prepare_item_for_response( $shipping_method, $request ); |
|
| 105 | - $method = $this->prepare_response_for_collection( $method ); |
|
| 103 | + foreach ($wc_shipping->get_shipping_methods() as $id => $shipping_method) { |
|
| 104 | + $method = $this->prepare_item_for_response($shipping_method, $request); |
|
| 105 | + $method = $this->prepare_response_for_collection($method); |
|
| 106 | 106 | $response[] = $method; |
| 107 | 107 | } |
| 108 | - return rest_ensure_response( $response ); |
|
| 108 | + return rest_ensure_response($response); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -114,17 +114,17 @@ discard block |
||
| 114 | 114 | * @param \WP_REST_Request $request Request data. |
| 115 | 115 | * @return \WP_REST_Response|\WP_Error |
| 116 | 116 | */ |
| 117 | - public function get_item( $request ) { |
|
| 117 | + public function get_item($request) { |
|
| 118 | 118 | $wc_shipping = \WC_Shipping::instance(); |
| 119 | 119 | $methods = $wc_shipping->get_shipping_methods(); |
| 120 | - if ( empty( $methods[ $request['id'] ] ) ) { |
|
| 121 | - return new \WP_Error( 'woocommerce_rest_shipping_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 120 | + if (empty($methods[$request['id']])) { |
|
| 121 | + return new \WP_Error('woocommerce_rest_shipping_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - $method = $methods[ $request['id'] ]; |
|
| 125 | - $response = $this->prepare_item_for_response( $method, $request ); |
|
| 124 | + $method = $methods[$request['id']]; |
|
| 125 | + $response = $this->prepare_item_for_response($method, $request); |
|
| 126 | 126 | |
| 127 | - return rest_ensure_response( $response ); |
|
| 127 | + return rest_ensure_response($response); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -134,21 +134,21 @@ discard block |
||
| 134 | 134 | * @param \WP_REST_Request $request Request object. |
| 135 | 135 | * @return \WP_REST_Response $response Response data. |
| 136 | 136 | */ |
| 137 | - public function prepare_item_for_response( $method, $request ) { |
|
| 137 | + public function prepare_item_for_response($method, $request) { |
|
| 138 | 138 | $data = array( |
| 139 | 139 | 'id' => $method->id, |
| 140 | 140 | 'title' => $method->method_title, |
| 141 | 141 | 'description' => $method->method_description, |
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 145 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 146 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 144 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 145 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 146 | + $data = $this->filter_response_by_context($data, $context); |
|
| 147 | 147 | |
| 148 | 148 | // Wrap the data in a response object. |
| 149 | - $response = rest_ensure_response( $data ); |
|
| 149 | + $response = rest_ensure_response($data); |
|
| 150 | 150 | |
| 151 | - $response->add_links( $this->prepare_links( $method, $request ) ); |
|
| 151 | + $response->add_links($this->prepare_links($method, $request)); |
|
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | 154 | * Filter shipping methods object returned from the REST API. |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @param WC_Shipping_Method $method Shipping method object used to create response. |
| 158 | 158 | * @param \WP_REST_Request $request Request object. |
| 159 | 159 | */ |
| 160 | - return apply_filters( 'woocommerce_rest_prepare_shipping_method', $response, $method, $request ); |
|
| 160 | + return apply_filters('woocommerce_rest_prepare_shipping_method', $response, $method, $request); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -167,13 +167,13 @@ discard block |
||
| 167 | 167 | * @param \WP_REST_Request $request Request object. |
| 168 | 168 | * @return array |
| 169 | 169 | */ |
| 170 | - protected function prepare_links( $method, $request ) { |
|
| 170 | + protected function prepare_links($method, $request) { |
|
| 171 | 171 | $links = array( |
| 172 | 172 | 'self' => array( |
| 173 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $method->id ) ), |
|
| 173 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $method->id)), |
|
| 174 | 174 | ), |
| 175 | 175 | 'collection' => array( |
| 176 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
| 176 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
| 177 | 177 | ), |
| 178 | 178 | ); |
| 179 | 179 | |
@@ -192,27 +192,27 @@ discard block |
||
| 192 | 192 | 'type' => 'object', |
| 193 | 193 | 'properties' => array( |
| 194 | 194 | 'id' => array( |
| 195 | - 'description' => __( 'Method ID.', 'woocommerce' ), |
|
| 195 | + 'description' => __('Method ID.', 'woocommerce'), |
|
| 196 | 196 | 'type' => 'string', |
| 197 | - 'context' => array( 'view' ), |
|
| 197 | + 'context' => array('view'), |
|
| 198 | 198 | 'readonly' => true, |
| 199 | 199 | ), |
| 200 | 200 | 'title' => array( |
| 201 | - 'description' => __( 'Shipping method title.', 'woocommerce' ), |
|
| 201 | + 'description' => __('Shipping method title.', 'woocommerce'), |
|
| 202 | 202 | 'type' => 'string', |
| 203 | - 'context' => array( 'view' ), |
|
| 203 | + 'context' => array('view'), |
|
| 204 | 204 | 'readonly' => true, |
| 205 | 205 | ), |
| 206 | 206 | 'description' => array( |
| 207 | - 'description' => __( 'Shipping method description.', 'woocommerce' ), |
|
| 207 | + 'description' => __('Shipping method description.', 'woocommerce'), |
|
| 208 | 208 | 'type' => 'string', |
| 209 | - 'context' => array( 'view' ), |
|
| 209 | + 'context' => array('view'), |
|
| 210 | 210 | 'readonly' => true, |
| 211 | 211 | ), |
| 212 | 212 | ), |
| 213 | 213 | ); |
| 214 | 214 | |
| 215 | - return $this->add_additional_fields_schema( $schema ); |
|
| 215 | + return $this->add_additional_fields_schema($schema); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | public function get_collection_params() { |
| 224 | 224 | return array( |
| 225 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 225 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 226 | 226 | ); |
| 227 | 227 | } |
| 228 | 228 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API Order Notes controller class. |
@@ -40,29 +40,29 @@ discard block |
||
| 40 | 40 | array( |
| 41 | 41 | 'args' => array( |
| 42 | 42 | 'order_id' => array( |
| 43 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
| 43 | + 'description' => __('The order ID.', 'woocommerce'), |
|
| 44 | 44 | 'type' => 'integer', |
| 45 | 45 | ), |
| 46 | 46 | ), |
| 47 | 47 | array( |
| 48 | 48 | 'methods' => \WP_REST_Server::READABLE, |
| 49 | - 'callback' => array( $this, 'get_items' ), |
|
| 50 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 49 | + 'callback' => array($this, 'get_items'), |
|
| 50 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 51 | 51 | 'args' => $this->get_collection_params(), |
| 52 | 52 | ), |
| 53 | 53 | array( |
| 54 | 54 | 'methods' => \WP_REST_Server::CREATABLE, |
| 55 | - 'callback' => array( $this, 'create_item' ), |
|
| 56 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
| 57 | - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), array( |
|
| 55 | + 'callback' => array($this, 'create_item'), |
|
| 56 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
| 57 | + 'args' => array_merge($this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), array( |
|
| 58 | 58 | 'note' => array( |
| 59 | 59 | 'type' => 'string', |
| 60 | - 'description' => __( 'Order note content.', 'woocommerce' ), |
|
| 60 | + 'description' => __('Order note content.', 'woocommerce'), |
|
| 61 | 61 | 'required' => true, |
| 62 | 62 | ), |
| 63 | - ) ), |
|
| 63 | + )), |
|
| 64 | 64 | ), |
| 65 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 65 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 66 | 66 | ), |
| 67 | 67 | true |
| 68 | 68 | ); |
@@ -73,35 +73,35 @@ discard block |
||
| 73 | 73 | array( |
| 74 | 74 | 'args' => array( |
| 75 | 75 | 'id' => array( |
| 76 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 76 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 77 | 77 | 'type' => 'integer', |
| 78 | 78 | ), |
| 79 | 79 | 'order_id' => array( |
| 80 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
| 80 | + 'description' => __('The order ID.', 'woocommerce'), |
|
| 81 | 81 | 'type' => 'integer', |
| 82 | 82 | ), |
| 83 | 83 | ), |
| 84 | 84 | array( |
| 85 | 85 | 'methods' => \WP_REST_Server::READABLE, |
| 86 | - 'callback' => array( $this, 'get_item' ), |
|
| 87 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 86 | + 'callback' => array($this, 'get_item'), |
|
| 87 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 88 | 88 | 'args' => array( |
| 89 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 89 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 90 | 90 | ), |
| 91 | 91 | ), |
| 92 | 92 | array( |
| 93 | 93 | 'methods' => \WP_REST_Server::DELETABLE, |
| 94 | - 'callback' => array( $this, 'delete_item' ), |
|
| 95 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
| 94 | + 'callback' => array($this, 'delete_item'), |
|
| 95 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
| 96 | 96 | 'args' => array( |
| 97 | 97 | 'force' => array( |
| 98 | 98 | 'default' => false, |
| 99 | 99 | 'type' => 'boolean', |
| 100 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
| 100 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
| 101 | 101 | ), |
| 102 | 102 | ), |
| 103 | 103 | ), |
| 104 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 104 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 105 | 105 | ), |
| 106 | 106 | true |
| 107 | 107 | ); |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | * @param \WP_REST_Request $request Full details about the request. |
| 114 | 114 | * @return \WP_Error|boolean |
| 115 | 115 | */ |
| 116 | - public function get_items_permissions_check( $request ) { |
|
| 117 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'read' ) ) { |
|
| 118 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 116 | + public function get_items_permissions_check($request) { |
|
| 117 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'read')) { |
|
| 118 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | return true; |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | * |
| 129 | 129 | * @return bool|\WP_Error |
| 130 | 130 | */ |
| 131 | - public function create_item_permissions_check( $request ) { |
|
| 132 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'create' ) ) { |
|
| 133 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 131 | + public function create_item_permissions_check($request) { |
|
| 132 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'create')) { |
|
| 133 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | return true; |
@@ -142,11 +142,11 @@ 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 get_item_permissions_check( $request ) { |
|
| 146 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 145 | + public function get_item_permissions_check($request) { |
|
| 146 | + $order = wc_get_order((int) $request['order_id']); |
|
| 147 | 147 | |
| 148 | - if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'read', $order->get_id() ) ) { |
|
| 149 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 148 | + if ($order && ! wc_rest_check_post_permissions($this->post_type, 'read', $order->get_id())) { |
|
| 149 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | return true; |
@@ -159,11 +159,11 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @return bool|\WP_Error |
| 161 | 161 | */ |
| 162 | - public function delete_item_permissions_check( $request ) { |
|
| 163 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 162 | + public function delete_item_permissions_check($request) { |
|
| 163 | + $order = wc_get_order((int) $request['order_id']); |
|
| 164 | 164 | |
| 165 | - if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $order->get_id() ) ) { |
|
| 166 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 165 | + if ($order && ! wc_rest_check_post_permissions($this->post_type, 'delete', $order->get_id())) { |
|
| 166 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | return true; |
@@ -176,11 +176,11 @@ discard block |
||
| 176 | 176 | * |
| 177 | 177 | * @return array|\WP_Error |
| 178 | 178 | */ |
| 179 | - public function get_items( $request ) { |
|
| 180 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 179 | + public function get_items($request) { |
|
| 180 | + $order = wc_get_order((int) $request['order_id']); |
|
| 181 | 181 | |
| 182 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
| 183 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 182 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
| 183 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | $args = array( |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | ); |
| 191 | 191 | |
| 192 | 192 | // Allow filter by order note type. |
| 193 | - if ( 'customer' === $request['type'] ) { |
|
| 193 | + if ('customer' === $request['type']) { |
|
| 194 | 194 | $args['meta_query'] = array( // WPCS: slow query ok. |
| 195 | 195 | array( |
| 196 | 196 | 'key' => 'is_customer_note', |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | 'compare' => '=', |
| 199 | 199 | ), |
| 200 | 200 | ); |
| 201 | - } elseif ( 'internal' === $request['type'] ) { |
|
| 201 | + } elseif ('internal' === $request['type']) { |
|
| 202 | 202 | $args['meta_query'] = array( // WPCS: slow query ok. |
| 203 | 203 | array( |
| 204 | 204 | 'key' => 'is_customer_note', |
@@ -207,20 +207,20 @@ discard block |
||
| 207 | 207 | ); |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); |
|
| 210 | + remove_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1); |
|
| 211 | 211 | |
| 212 | - $notes = get_comments( $args ); |
|
| 212 | + $notes = get_comments($args); |
|
| 213 | 213 | |
| 214 | - add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); |
|
| 214 | + add_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1); |
|
| 215 | 215 | |
| 216 | 216 | $data = array(); |
| 217 | - foreach ( $notes as $note ) { |
|
| 218 | - $order_note = $this->prepare_item_for_response( $note, $request ); |
|
| 219 | - $order_note = $this->prepare_response_for_collection( $order_note ); |
|
| 217 | + foreach ($notes as $note) { |
|
| 218 | + $order_note = $this->prepare_item_for_response($note, $request); |
|
| 219 | + $order_note = $this->prepare_response_for_collection($order_note); |
|
| 220 | 220 | $data[] = $order_note; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - return rest_ensure_response( $data ); |
|
| 223 | + return rest_ensure_response($data); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -229,27 +229,27 @@ discard block |
||
| 229 | 229 | * @param \WP_REST_Request $request Full details about the request. |
| 230 | 230 | * @return \WP_Error\WP_REST_Response |
| 231 | 231 | */ |
| 232 | - public function create_item( $request ) { |
|
| 233 | - if ( ! empty( $request['id'] ) ) { |
|
| 232 | + public function create_item($request) { |
|
| 233 | + if ( ! empty($request['id'])) { |
|
| 234 | 234 | /* translators: %s: post type */ |
| 235 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
| 235 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 238 | + $order = wc_get_order((int) $request['order_id']); |
|
| 239 | 239 | |
| 240 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
| 241 | - return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 240 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
| 241 | + return new \WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | // Create the note. |
| 245 | - $note_id = $order->add_order_note( $request['note'], $request['customer_note'], $request['added_by_user'] ); |
|
| 245 | + $note_id = $order->add_order_note($request['note'], $request['customer_note'], $request['added_by_user']); |
|
| 246 | 246 | |
| 247 | - if ( ! $note_id ) { |
|
| 248 | - return new \WP_Error( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 247 | + if ( ! $note_id) { |
|
| 248 | + return new \WP_Error('woocommerce_api_cannot_create_order_note', __('Cannot create order note, please try again.', 'woocommerce'), array('status' => 500)); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - $note = get_comment( $note_id ); |
|
| 252 | - $this->update_additional_fields_for_object( $note, $request ); |
|
| 251 | + $note = get_comment($note_id); |
|
| 252 | + $this->update_additional_fields_for_object($note, $request); |
|
| 253 | 253 | |
| 254 | 254 | /** |
| 255 | 255 | * Fires after a order note is created or updated via the REST API. |
@@ -258,13 +258,13 @@ discard block |
||
| 258 | 258 | * @param \WP_REST_Request $request Request object. |
| 259 | 259 | * @param boolean $creating True when creating item, false when updating. |
| 260 | 260 | */ |
| 261 | - do_action( 'woocommerce_rest_insert_order_note', $note, $request, true ); |
|
| 261 | + do_action('woocommerce_rest_insert_order_note', $note, $request, true); |
|
| 262 | 262 | |
| 263 | - $request->set_param( 'context', 'edit' ); |
|
| 264 | - $response = $this->prepare_item_for_response( $note, $request ); |
|
| 265 | - $response = rest_ensure_response( $response ); |
|
| 266 | - $response->set_status( 201 ); |
|
| 267 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, str_replace( '(?P<order_id>[\d]+)', $order->get_id(), $this->rest_base ), $note_id ) ) ); |
|
| 263 | + $request->set_param('context', 'edit'); |
|
| 264 | + $response = $this->prepare_item_for_response($note, $request); |
|
| 265 | + $response = rest_ensure_response($response); |
|
| 266 | + $response->set_status(201); |
|
| 267 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, str_replace('(?P<order_id>[\d]+)', $order->get_id(), $this->rest_base), $note_id))); |
|
| 268 | 268 | |
| 269 | 269 | return $response; |
| 270 | 270 | } |
@@ -275,22 +275,22 @@ discard block |
||
| 275 | 275 | * @param \WP_REST_Request $request Full details about the request. |
| 276 | 276 | * @return \WP_Error\WP_REST_Response |
| 277 | 277 | */ |
| 278 | - public function get_item( $request ) { |
|
| 278 | + public function get_item($request) { |
|
| 279 | 279 | $id = (int) $request['id']; |
| 280 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 280 | + $order = wc_get_order((int) $request['order_id']); |
|
| 281 | 281 | |
| 282 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
| 283 | - return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 282 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
| 283 | + return new \WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - $note = get_comment( $id ); |
|
| 286 | + $note = get_comment($id); |
|
| 287 | 287 | |
| 288 | - if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) { |
|
| 289 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 288 | + if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) { |
|
| 289 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - $order_note = $this->prepare_item_for_response( $note, $request ); |
|
| 293 | - $response = rest_ensure_response( $order_note ); |
|
| 292 | + $order_note = $this->prepare_item_for_response($note, $request); |
|
| 293 | + $response = rest_ensure_response($order_note); |
|
| 294 | 294 | |
| 295 | 295 | return $response; |
| 296 | 296 | } |
@@ -301,33 +301,33 @@ discard block |
||
| 301 | 301 | * @param \WP_REST_Request $request Full details about the request. |
| 302 | 302 | * @return \WP_REST_Response|\WP_Error |
| 303 | 303 | */ |
| 304 | - public function delete_item( $request ) { |
|
| 304 | + public function delete_item($request) { |
|
| 305 | 305 | $id = (int) $request['id']; |
| 306 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 306 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
| 307 | 307 | |
| 308 | 308 | // We don't support trashing for this type, error out. |
| 309 | - if ( ! $force ) { |
|
| 310 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
| 309 | + if ( ! $force) { |
|
| 310 | + return new \WP_Error('woocommerce_rest_trash_not_supported', __('Webhooks do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 313 | + $order = wc_get_order((int) $request['order_id']); |
|
| 314 | 314 | |
| 315 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
| 316 | - return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 315 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
| 316 | + return new \WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - $note = get_comment( $id ); |
|
| 319 | + $note = get_comment($id); |
|
| 320 | 320 | |
| 321 | - if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) { |
|
| 322 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 321 | + if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) { |
|
| 322 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - $request->set_param( 'context', 'edit' ); |
|
| 326 | - $previous = $this->prepare_item_for_response( $note, $request ); |
|
| 327 | - $result = wc_delete_order_note( $note->comment_ID ); |
|
| 325 | + $request->set_param('context', 'edit'); |
|
| 326 | + $previous = $this->prepare_item_for_response($note, $request); |
|
| 327 | + $result = wc_delete_order_note($note->comment_ID); |
|
| 328 | 328 | |
| 329 | - if ( ! $result ) { |
|
| 330 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), 'order_note' ), array( 'status' => 500 ) ); |
|
| 329 | + if ( ! $result) { |
|
| 330 | + return new \WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), 'order_note'), array('status' => 500)); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | $response = new \WP_REST_Response(); |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | * @param \WP_REST_Response $response The response data. |
| 346 | 346 | * @param \WP_REST_Request $request The request sent to the API. |
| 347 | 347 | */ |
| 348 | - do_action( 'woocommerce_rest_delete_order_note', $note, $response, $request ); |
|
| 348 | + do_action('woocommerce_rest_delete_order_note', $note, $response, $request); |
|
| 349 | 349 | |
| 350 | 350 | return $response; |
| 351 | 351 | } |
@@ -357,24 +357,24 @@ discard block |
||
| 357 | 357 | * @param \WP_REST_Request $request Request object. |
| 358 | 358 | * @return \WP_REST_Response $response Response data. |
| 359 | 359 | */ |
| 360 | - public function prepare_item_for_response( $note, $request ) { |
|
| 360 | + public function prepare_item_for_response($note, $request) { |
|
| 361 | 361 | $data = array( |
| 362 | 362 | 'id' => (int) $note->comment_ID, |
| 363 | - 'author' => __( 'WooCommerce', 'woocommerce' ) === $note->comment_author ? 'system' : $note->comment_author, |
|
| 364 | - 'date_created' => wc_rest_prepare_date_response( $note->comment_date ), |
|
| 365 | - 'date_created_gmt' => wc_rest_prepare_date_response( $note->comment_date_gmt ), |
|
| 363 | + 'author' => __('WooCommerce', 'woocommerce') === $note->comment_author ? 'system' : $note->comment_author, |
|
| 364 | + 'date_created' => wc_rest_prepare_date_response($note->comment_date), |
|
| 365 | + 'date_created_gmt' => wc_rest_prepare_date_response($note->comment_date_gmt), |
|
| 366 | 366 | 'note' => $note->comment_content, |
| 367 | - 'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ), |
|
| 367 | + 'customer_note' => (bool) get_comment_meta($note->comment_ID, 'is_customer_note', true), |
|
| 368 | 368 | ); |
| 369 | 369 | |
| 370 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 371 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 372 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 370 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 371 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 372 | + $data = $this->filter_response_by_context($data, $context); |
|
| 373 | 373 | |
| 374 | 374 | // Wrap the data in a response object. |
| 375 | - $response = rest_ensure_response( $data ); |
|
| 375 | + $response = rest_ensure_response($data); |
|
| 376 | 376 | |
| 377 | - $response->add_links( $this->prepare_links( $note ) ); |
|
| 377 | + $response->add_links($this->prepare_links($note)); |
|
| 378 | 378 | |
| 379 | 379 | /** |
| 380 | 380 | * Filter order note object returned from the REST API. |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | * @param WP_Comment $note Order note object used to create response. |
| 384 | 384 | * @param \WP_REST_Request $request Request object. |
| 385 | 385 | */ |
| 386 | - return apply_filters( 'woocommerce_rest_prepare_order_note', $response, $note, $request ); |
|
| 386 | + return apply_filters('woocommerce_rest_prepare_order_note', $response, $note, $request); |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -392,18 +392,18 @@ discard block |
||
| 392 | 392 | * @param WP_Comment $note Delivery order_note object. |
| 393 | 393 | * @return array Links for the given order note. |
| 394 | 394 | */ |
| 395 | - protected function prepare_links( $note ) { |
|
| 395 | + protected function prepare_links($note) { |
|
| 396 | 396 | $order_id = (int) $note->comment_post_ID; |
| 397 | - $base = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base ); |
|
| 397 | + $base = str_replace('(?P<order_id>[\d]+)', $order_id, $this->rest_base); |
|
| 398 | 398 | $links = array( |
| 399 | 399 | 'self' => array( |
| 400 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $note->comment_ID ) ), |
|
| 400 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $note->comment_ID)), |
|
| 401 | 401 | ), |
| 402 | 402 | 'collection' => array( |
| 403 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
| 403 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
| 404 | 404 | ), |
| 405 | 405 | 'up' => array( |
| 406 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order_id ) ), |
|
| 406 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $order_id)), |
|
| 407 | 407 | ), |
| 408 | 408 | ); |
| 409 | 409 | |
@@ -422,50 +422,50 @@ discard block |
||
| 422 | 422 | 'type' => 'object', |
| 423 | 423 | 'properties' => array( |
| 424 | 424 | 'id' => array( |
| 425 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 425 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 426 | 426 | 'type' => 'integer', |
| 427 | - 'context' => array( 'view', 'edit' ), |
|
| 427 | + 'context' => array('view', 'edit'), |
|
| 428 | 428 | 'readonly' => true, |
| 429 | 429 | ), |
| 430 | 430 | 'author' => array( |
| 431 | - 'description' => __( 'Order note author.', 'woocommerce' ), |
|
| 431 | + 'description' => __('Order note author.', 'woocommerce'), |
|
| 432 | 432 | 'type' => 'string', |
| 433 | - 'context' => array( 'view', 'edit' ), |
|
| 433 | + 'context' => array('view', 'edit'), |
|
| 434 | 434 | 'readonly' => true, |
| 435 | 435 | ), |
| 436 | 436 | 'date_created' => array( |
| 437 | - 'description' => __( "The date the order note was created, in the site's timezone.", 'woocommerce' ), |
|
| 437 | + 'description' => __("The date the order note was created, in the site's timezone.", 'woocommerce'), |
|
| 438 | 438 | 'type' => 'date-time', |
| 439 | - 'context' => array( 'view', 'edit' ), |
|
| 439 | + 'context' => array('view', 'edit'), |
|
| 440 | 440 | 'readonly' => true, |
| 441 | 441 | ), |
| 442 | 442 | 'date_created_gmt' => array( |
| 443 | - 'description' => __( 'The date the order note was created, as GMT.', 'woocommerce' ), |
|
| 443 | + 'description' => __('The date the order note was created, as GMT.', 'woocommerce'), |
|
| 444 | 444 | 'type' => 'date-time', |
| 445 | - 'context' => array( 'view', 'edit' ), |
|
| 445 | + 'context' => array('view', 'edit'), |
|
| 446 | 446 | 'readonly' => true, |
| 447 | 447 | ), |
| 448 | 448 | 'note' => array( |
| 449 | - 'description' => __( 'Order note content.', 'woocommerce' ), |
|
| 449 | + 'description' => __('Order note content.', 'woocommerce'), |
|
| 450 | 450 | 'type' => 'string', |
| 451 | - 'context' => array( 'view', 'edit' ), |
|
| 451 | + 'context' => array('view', 'edit'), |
|
| 452 | 452 | ), |
| 453 | 453 | 'customer_note' => array( |
| 454 | - 'description' => __( 'If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.', 'woocommerce' ), |
|
| 454 | + 'description' => __('If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.', 'woocommerce'), |
|
| 455 | 455 | 'type' => 'boolean', |
| 456 | 456 | 'default' => false, |
| 457 | - 'context' => array( 'view', 'edit' ), |
|
| 457 | + 'context' => array('view', 'edit'), |
|
| 458 | 458 | ), |
| 459 | 459 | 'added_by_user' => array( |
| 460 | - 'description' => __( 'If true, this note will be attributed to the current user. If false, the note will be attributed to the system.', 'woocommerce' ), |
|
| 460 | + 'description' => __('If true, this note will be attributed to the current user. If false, the note will be attributed to the system.', 'woocommerce'), |
|
| 461 | 461 | 'type' => 'boolean', |
| 462 | 462 | 'default' => false, |
| 463 | - 'context' => array( 'edit' ), |
|
| 463 | + 'context' => array('edit'), |
|
| 464 | 464 | ), |
| 465 | 465 | ), |
| 466 | 466 | ); |
| 467 | 467 | |
| 468 | - return $this->add_additional_fields_schema( $schema ); |
|
| 468 | + return $this->add_additional_fields_schema($schema); |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | /** |
@@ -475,12 +475,12 @@ discard block |
||
| 475 | 475 | */ |
| 476 | 476 | public function get_collection_params() { |
| 477 | 477 | $params = array(); |
| 478 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
| 478 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
| 479 | 479 | $params['type'] = array( |
| 480 | 480 | 'default' => 'any', |
| 481 | - 'description' => __( 'Limit result to customers or internal notes.', 'woocommerce' ), |
|
| 481 | + 'description' => __('Limit result to customers or internal notes.', 'woocommerce'), |
|
| 482 | 482 | 'type' => 'string', |
| 483 | - 'enum' => array( 'any', 'customer', 'internal' ), |
|
| 483 | + 'enum' => array('any', 'customer', 'internal'), |
|
| 484 | 484 | 'sanitize_callback' => 'sanitize_key', |
| 485 | 485 | 'validate_callback' => 'rest_validate_request_arg', |
| 486 | 486 | ); |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API Product Reviews controller class. |
@@ -33,41 +33,41 @@ discard block |
||
| 33 | 33 | array( |
| 34 | 34 | array( |
| 35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
| 36 | - 'callback' => array( $this, 'get_items' ), |
|
| 37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 36 | + 'callback' => array($this, 'get_items'), |
|
| 37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 38 | 38 | 'args' => $this->get_collection_params(), |
| 39 | 39 | ), |
| 40 | 40 | array( |
| 41 | 41 | 'methods' => \WP_REST_Server::CREATABLE, |
| 42 | - 'callback' => array( $this, 'create_item' ), |
|
| 43 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
| 42 | + 'callback' => array($this, 'create_item'), |
|
| 43 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
| 44 | 44 | 'args' => array_merge( |
| 45 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
| 45 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
| 46 | 46 | array( |
| 47 | 47 | 'product_id' => array( |
| 48 | 48 | 'required' => true, |
| 49 | - 'description' => __( 'Unique identifier for the product.', 'woocommerce' ), |
|
| 49 | + 'description' => __('Unique identifier for the product.', 'woocommerce'), |
|
| 50 | 50 | 'type' => 'integer', |
| 51 | 51 | ), |
| 52 | 52 | 'review' => array( |
| 53 | 53 | 'required' => true, |
| 54 | 54 | 'type' => 'string', |
| 55 | - 'description' => __( 'Review content.', 'woocommerce' ), |
|
| 55 | + 'description' => __('Review content.', 'woocommerce'), |
|
| 56 | 56 | ), |
| 57 | 57 | 'reviewer' => array( |
| 58 | 58 | 'required' => true, |
| 59 | 59 | 'type' => 'string', |
| 60 | - 'description' => __( 'Name of the reviewer.', 'woocommerce' ), |
|
| 60 | + 'description' => __('Name of the reviewer.', 'woocommerce'), |
|
| 61 | 61 | ), |
| 62 | 62 | 'reviewer_email' => array( |
| 63 | 63 | 'required' => true, |
| 64 | 64 | 'type' => 'string', |
| 65 | - 'description' => __( 'Email of the reviewer.', 'woocommerce' ), |
|
| 65 | + 'description' => __('Email of the reviewer.', 'woocommerce'), |
|
| 66 | 66 | ), |
| 67 | 67 | ) |
| 68 | 68 | ), |
| 69 | 69 | ), |
| 70 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 70 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 71 | 71 | ), |
| 72 | 72 | true |
| 73 | 73 | ); |
@@ -78,37 +78,37 @@ discard block |
||
| 78 | 78 | array( |
| 79 | 79 | 'args' => array( |
| 80 | 80 | 'id' => array( |
| 81 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 81 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 82 | 82 | 'type' => 'integer', |
| 83 | 83 | ), |
| 84 | 84 | ), |
| 85 | 85 | array( |
| 86 | 86 | 'methods' => \WP_REST_Server::READABLE, |
| 87 | - 'callback' => array( $this, 'get_item' ), |
|
| 88 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 87 | + 'callback' => array($this, 'get_item'), |
|
| 88 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 89 | 89 | 'args' => array( |
| 90 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 90 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 91 | 91 | ), |
| 92 | 92 | ), |
| 93 | 93 | array( |
| 94 | 94 | 'methods' => \WP_REST_Server::EDITABLE, |
| 95 | - 'callback' => array( $this, 'update_item' ), |
|
| 96 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
| 97 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
| 95 | + 'callback' => array($this, 'update_item'), |
|
| 96 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
| 97 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
| 98 | 98 | ), |
| 99 | 99 | array( |
| 100 | 100 | 'methods' => \WP_REST_Server::DELETABLE, |
| 101 | - 'callback' => array( $this, 'delete_item' ), |
|
| 102 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
| 101 | + 'callback' => array($this, 'delete_item'), |
|
| 102 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
| 103 | 103 | 'args' => array( |
| 104 | 104 | 'force' => array( |
| 105 | 105 | 'default' => false, |
| 106 | 106 | 'type' => 'boolean', |
| 107 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
| 107 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
| 108 | 108 | ), |
| 109 | 109 | ), |
| 110 | 110 | ), |
| 111 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 111 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 112 | 112 | ), |
| 113 | 113 | true |
| 114 | 114 | ); |
@@ -119,11 +119,11 @@ discard block |
||
| 119 | 119 | 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 | true |
| 129 | 129 | ); |
@@ -135,9 +135,9 @@ discard block |
||
| 135 | 135 | * @param \WP_REST_Request $request Full details about the request. |
| 136 | 136 | * @return \WP_Error|boolean |
| 137 | 137 | */ |
| 138 | - public function get_items_permissions_check( $request ) { |
|
| 139 | - if ( ! wc_rest_check_product_reviews_permissions( 'read' ) ) { |
|
| 140 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 138 | + public function get_items_permissions_check($request) { |
|
| 139 | + if ( ! wc_rest_check_product_reviews_permissions('read')) { |
|
| 140 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | return true; |
@@ -149,12 +149,12 @@ discard block |
||
| 149 | 149 | * @param \WP_REST_Request $request Full details about the request. |
| 150 | 150 | * @return \WP_Error|boolean |
| 151 | 151 | */ |
| 152 | - public function get_item_permissions_check( $request ) { |
|
| 152 | + public function get_item_permissions_check($request) { |
|
| 153 | 153 | $id = (int) $request['id']; |
| 154 | - $review = get_comment( $id ); |
|
| 154 | + $review = get_comment($id); |
|
| 155 | 155 | |
| 156 | - if ( $review && ! wc_rest_check_product_reviews_permissions( 'read', $review->comment_ID ) ) { |
|
| 157 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 156 | + if ($review && ! wc_rest_check_product_reviews_permissions('read', $review->comment_ID)) { |
|
| 157 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | return true; |
@@ -166,9 +166,9 @@ discard block |
||
| 166 | 166 | * @param \WP_REST_Request $request Full details about the request. |
| 167 | 167 | * @return \WP_Error|boolean |
| 168 | 168 | */ |
| 169 | - public function create_item_permissions_check( $request ) { |
|
| 170 | - if ( ! wc_rest_check_product_reviews_permissions( 'create' ) ) { |
|
| 171 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 169 | + public function create_item_permissions_check($request) { |
|
| 170 | + if ( ! wc_rest_check_product_reviews_permissions('create')) { |
|
| 171 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | return true; |
@@ -180,12 +180,12 @@ 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 ) { |
|
| 183 | + public function update_item_permissions_check($request) { |
|
| 184 | 184 | $id = (int) $request['id']; |
| 185 | - $review = get_comment( $id ); |
|
| 185 | + $review = get_comment($id); |
|
| 186 | 186 | |
| 187 | - if ( $review && ! wc_rest_check_product_reviews_permissions( 'edit', $review->comment_ID ) ) { |
|
| 188 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 187 | + if ($review && ! wc_rest_check_product_reviews_permissions('edit', $review->comment_ID)) { |
|
| 188 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | return true; |
@@ -197,12 +197,12 @@ discard block |
||
| 197 | 197 | * @param \WP_REST_Request $request Full details about the request. |
| 198 | 198 | * @return \WP_Error|boolean |
| 199 | 199 | */ |
| 200 | - public function delete_item_permissions_check( $request ) { |
|
| 200 | + public function delete_item_permissions_check($request) { |
|
| 201 | 201 | $id = (int) $request['id']; |
| 202 | - $review = get_comment( $id ); |
|
| 202 | + $review = get_comment($id); |
|
| 203 | 203 | |
| 204 | - if ( $review && ! wc_rest_check_product_reviews_permissions( 'delete', $review->comment_ID ) ) { |
|
| 205 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 204 | + if ($review && ! wc_rest_check_product_reviews_permissions('delete', $review->comment_ID)) { |
|
| 205 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | return true; |
@@ -214,9 +214,9 @@ discard block |
||
| 214 | 214 | * @param \WP_REST_Request $request Full details about the request. |
| 215 | 215 | * @return boolean|\WP_Error |
| 216 | 216 | */ |
| 217 | - public function batch_items_permissions_check( $request ) { |
|
| 218 | - if ( ! wc_rest_check_product_reviews_permissions( 'create' ) ) { |
|
| 219 | - 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() ) ); |
|
| 217 | + public function batch_items_permissions_check($request) { |
|
| 218 | + if ( ! wc_rest_check_product_reviews_permissions('create')) { |
|
| 219 | + 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())); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | return true; |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | * @param \WP_REST_Request $request Full details about the request. |
| 229 | 229 | * @return array|\WP_Error |
| 230 | 230 | */ |
| 231 | - public function get_items( $request ) { |
|
| 231 | + public function get_items($request) { |
|
| 232 | 232 | // Retrieve the list of registered collection query parameters. |
| 233 | 233 | $registered = $this->get_collection_params(); |
| 234 | 234 | |
@@ -258,24 +258,24 @@ discard block |
||
| 258 | 258 | * For each known parameter which is both registered and present in the request, |
| 259 | 259 | * set the parameter's value on the query $prepared_args. |
| 260 | 260 | */ |
| 261 | - foreach ( $parameter_mappings as $api_param => $wp_param ) { |
|
| 262 | - if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) { |
|
| 263 | - $prepared_args[ $wp_param ] = $request[ $api_param ]; |
|
| 261 | + foreach ($parameter_mappings as $api_param => $wp_param) { |
|
| 262 | + if (isset($registered[$api_param], $request[$api_param])) { |
|
| 263 | + $prepared_args[$wp_param] = $request[$api_param]; |
|
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | // Ensure certain parameter values default to empty strings. |
| 268 | - foreach ( array( 'author_email', 'search' ) as $param ) { |
|
| 269 | - if ( ! isset( $prepared_args[ $param ] ) ) { |
|
| 270 | - $prepared_args[ $param ] = ''; |
|
| 268 | + foreach (array('author_email', 'search') as $param) { |
|
| 269 | + if ( ! isset($prepared_args[$param])) { |
|
| 270 | + $prepared_args[$param] = ''; |
|
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if ( isset( $registered['orderby'] ) ) { |
|
| 275 | - $prepared_args['orderby'] = $this->normalize_query_param( $request['orderby'] ); |
|
| 274 | + if (isset($registered['orderby'])) { |
|
| 275 | + $prepared_args['orderby'] = $this->normalize_query_param($request['orderby']); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if ( isset( $prepared_args['status'] ) ) { |
|
| 278 | + if (isset($prepared_args['status'])) { |
|
| 279 | 279 | $prepared_args['status'] = 'approved' === $prepared_args['status'] ? 'approve' : $prepared_args['status']; |
| 280 | 280 | } |
| 281 | 281 | |
@@ -283,17 +283,17 @@ discard block |
||
| 283 | 283 | $prepared_args['date_query'] = array(); |
| 284 | 284 | |
| 285 | 285 | // Set before into date query. Date query must be specified as an array of an array. |
| 286 | - if ( isset( $registered['before'], $request['before'] ) ) { |
|
| 286 | + if (isset($registered['before'], $request['before'])) { |
|
| 287 | 287 | $prepared_args['date_query'][0]['before'] = $request['before']; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | // Set after into date query. Date query must be specified as an array of an array. |
| 291 | - if ( isset( $registered['after'], $request['after'] ) ) { |
|
| 291 | + if (isset($registered['after'], $request['after'])) { |
|
| 292 | 292 | $prepared_args['date_query'][0]['after'] = $request['after']; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - if ( isset( $registered['page'] ) && empty( $request['offset'] ) ) { |
|
| 296 | - $prepared_args['offset'] = $prepared_args['number'] * ( absint( $request['page'] ) - 1 ); |
|
| 295 | + if (isset($registered['page']) && empty($request['offset'])) { |
|
| 296 | + $prepared_args['offset'] = $prepared_args['number'] * (absint($request['page']) - 1); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -304,61 +304,61 @@ discard block |
||
| 304 | 304 | * @param array $prepared_args Array of arguments for \WP_Comment_Query. |
| 305 | 305 | * @param \WP_REST_Request $request The current request. |
| 306 | 306 | */ |
| 307 | - $prepared_args = apply_filters( 'woocommerce_rest_product_review_query', $prepared_args, $request ); |
|
| 307 | + $prepared_args = apply_filters('woocommerce_rest_product_review_query', $prepared_args, $request); |
|
| 308 | 308 | |
| 309 | 309 | // Make sure that returns only reviews. |
| 310 | 310 | $prepared_args['type'] = 'review'; |
| 311 | 311 | |
| 312 | 312 | // Query reviews. |
| 313 | 313 | $query = new \WP_Comment_Query(); |
| 314 | - $query_result = $query->query( $prepared_args ); |
|
| 314 | + $query_result = $query->query($prepared_args); |
|
| 315 | 315 | $reviews = array(); |
| 316 | 316 | |
| 317 | - foreach ( $query_result as $review ) { |
|
| 318 | - if ( ! wc_rest_check_product_reviews_permissions( 'read', $review->comment_ID ) ) { |
|
| 317 | + foreach ($query_result as $review) { |
|
| 318 | + if ( ! wc_rest_check_product_reviews_permissions('read', $review->comment_ID)) { |
|
| 319 | 319 | continue; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - $data = $this->prepare_item_for_response( $review, $request ); |
|
| 323 | - $reviews[] = $this->prepare_response_for_collection( $data ); |
|
| 322 | + $data = $this->prepare_item_for_response($review, $request); |
|
| 323 | + $reviews[] = $this->prepare_response_for_collection($data); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | $total_reviews = (int) $query->found_comments; |
| 327 | 327 | $max_pages = (int) $query->max_num_pages; |
| 328 | 328 | |
| 329 | - if ( $total_reviews < 1 ) { |
|
| 329 | + if ($total_reviews < 1) { |
|
| 330 | 330 | // Out-of-bounds, run the query again without LIMIT for total count. |
| 331 | - unset( $prepared_args['number'], $prepared_args['offset'] ); |
|
| 331 | + unset($prepared_args['number'], $prepared_args['offset']); |
|
| 332 | 332 | |
| 333 | 333 | $query = new \WP_Comment_Query(); |
| 334 | 334 | $prepared_args['count'] = true; |
| 335 | 335 | |
| 336 | - $total_reviews = $query->query( $prepared_args ); |
|
| 337 | - $max_pages = ceil( $total_reviews / $request['per_page'] ); |
|
| 336 | + $total_reviews = $query->query($prepared_args); |
|
| 337 | + $max_pages = ceil($total_reviews / $request['per_page']); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - $response = rest_ensure_response( $reviews ); |
|
| 341 | - $response->header( 'X-WP-Total', $total_reviews ); |
|
| 342 | - $response->header( 'X-WP-TotalPages', $max_pages ); |
|
| 340 | + $response = rest_ensure_response($reviews); |
|
| 341 | + $response->header('X-WP-Total', $total_reviews); |
|
| 342 | + $response->header('X-WP-TotalPages', $max_pages); |
|
| 343 | 343 | |
| 344 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 344 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base))); |
|
| 345 | 345 | |
| 346 | - if ( $request['page'] > 1 ) { |
|
| 346 | + if ($request['page'] > 1) { |
|
| 347 | 347 | $prev_page = $request['page'] - 1; |
| 348 | 348 | |
| 349 | - if ( $prev_page > $max_pages ) { |
|
| 349 | + if ($prev_page > $max_pages) { |
|
| 350 | 350 | $prev_page = $max_pages; |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 354 | - $response->link_header( 'prev', $prev_link ); |
|
| 353 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 354 | + $response->link_header('prev', $prev_link); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - if ( $max_pages > $request['page'] ) { |
|
| 357 | + if ($max_pages > $request['page']) { |
|
| 358 | 358 | $next_page = $request['page'] + 1; |
| 359 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 359 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 360 | 360 | |
| 361 | - $response->link_header( 'next', $next_link ); |
|
| 361 | + $response->link_header('next', $next_link); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | return $response; |
@@ -370,19 +370,19 @@ discard block |
||
| 370 | 370 | * @param \WP_REST_Request $request Full details about the request. |
| 371 | 371 | * @return \WP_Error|\WP_REST_Response |
| 372 | 372 | */ |
| 373 | - public function create_item( $request ) { |
|
| 374 | - if ( ! empty( $request['id'] ) ) { |
|
| 375 | - return new \WP_Error( 'woocommerce_rest_review_exists', __( 'Cannot create existing product review.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 373 | + public function create_item($request) { |
|
| 374 | + if ( ! empty($request['id'])) { |
|
| 375 | + return new \WP_Error('woocommerce_rest_review_exists', __('Cannot create existing product review.', 'woocommerce'), array('status' => 400)); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | $product_id = (int) $request['product_id']; |
| 379 | 379 | |
| 380 | - if ( 'product' !== get_post_type( $product_id ) ) { |
|
| 381 | - return new \WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 380 | + if ('product' !== get_post_type($product_id)) { |
|
| 381 | + return new \WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404)); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - $prepared_review = $this->prepare_item_for_database( $request ); |
|
| 385 | - if ( is_wp_error( $prepared_review ) ) { |
|
| 384 | + $prepared_review = $this->prepare_item_for_database($request); |
|
| 385 | + if (is_wp_error($prepared_review)) { |
|
| 386 | 386 | return $prepared_review; |
| 387 | 387 | } |
| 388 | 388 | |
@@ -391,49 +391,49 @@ discard block |
||
| 391 | 391 | /* |
| 392 | 392 | * Do not allow a comment to be created with missing or empty comment_content. See wp_handle_comment_submission(). |
| 393 | 393 | */ |
| 394 | - if ( empty( $prepared_review['comment_content'] ) ) { |
|
| 395 | - return new \WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 394 | + if (empty($prepared_review['comment_content'])) { |
|
| 395 | + return new \WP_Error('woocommerce_rest_review_content_invalid', __('Invalid review content.', 'woocommerce'), array('status' => 400)); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | // Setting remaining values before wp_insert_comment so we can use wp_allow_comment(). |
| 399 | - if ( ! isset( $prepared_review['comment_date_gmt'] ) ) { |
|
| 400 | - $prepared_review['comment_date_gmt'] = current_time( 'mysql', true ); |
|
| 399 | + if ( ! isset($prepared_review['comment_date_gmt'])) { |
|
| 400 | + $prepared_review['comment_date_gmt'] = current_time('mysql', true); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - if ( ! empty( $_SERVER['REMOTE_ADDR'] ) && rest_is_ip_address( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) { // WPCS: input var ok, sanitization ok. |
|
| 404 | - $prepared_review['comment_author_IP'] = wc_clean( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // WPCS: input var ok. |
|
| 403 | + if ( ! empty($_SERVER['REMOTE_ADDR']) && rest_is_ip_address(wp_unslash($_SERVER['REMOTE_ADDR']))) { // WPCS: input var ok, sanitization ok. |
|
| 404 | + $prepared_review['comment_author_IP'] = wc_clean(wp_unslash($_SERVER['REMOTE_ADDR'])); // WPCS: input var ok. |
|
| 405 | 405 | } else { |
| 406 | 406 | $prepared_review['comment_author_IP'] = '127.0.0.1'; |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - if ( ! empty( $request['author_user_agent'] ) ) { |
|
| 409 | + if ( ! empty($request['author_user_agent'])) { |
|
| 410 | 410 | $prepared_review['comment_agent'] = $request['author_user_agent']; |
| 411 | - } elseif ( $request->get_header( 'user_agent' ) ) { |
|
| 412 | - $prepared_review['comment_agent'] = $request->get_header( 'user_agent' ); |
|
| 411 | + } elseif ($request->get_header('user_agent')) { |
|
| 412 | + $prepared_review['comment_agent'] = $request->get_header('user_agent'); |
|
| 413 | 413 | } else { |
| 414 | 414 | $prepared_review['comment_agent'] = ''; |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | - $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_review ); |
|
| 418 | - if ( is_wp_error( $check_comment_lengths ) ) { |
|
| 419 | - $error_code = str_replace( array( 'comment_author', 'comment_content' ), array( 'reviewer', 'review_content' ), $check_comment_lengths->get_error_code() ); |
|
| 420 | - return new \WP_Error( 'woocommerce_rest_' . $error_code, __( 'Product review field exceeds maximum length allowed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 417 | + $check_comment_lengths = wp_check_comment_data_max_lengths($prepared_review); |
|
| 418 | + if (is_wp_error($check_comment_lengths)) { |
|
| 419 | + $error_code = str_replace(array('comment_author', 'comment_content'), array('reviewer', 'review_content'), $check_comment_lengths->get_error_code()); |
|
| 420 | + return new \WP_Error('woocommerce_rest_' . $error_code, __('Product review field exceeds maximum length allowed.', 'woocommerce'), array('status' => 400)); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | $prepared_review['comment_parent'] = 0; |
| 424 | 424 | $prepared_review['comment_author_url'] = ''; |
| 425 | - $prepared_review['comment_approved'] = wp_allow_comment( $prepared_review, true ); |
|
| 425 | + $prepared_review['comment_approved'] = wp_allow_comment($prepared_review, true); |
|
| 426 | 426 | |
| 427 | - if ( is_wp_error( $prepared_review['comment_approved'] ) ) { |
|
| 427 | + if (is_wp_error($prepared_review['comment_approved'])) { |
|
| 428 | 428 | $error_code = $prepared_review['comment_approved']->get_error_code(); |
| 429 | 429 | $error_message = $prepared_review['comment_approved']->get_error_message(); |
| 430 | 430 | |
| 431 | - if ( 'comment_duplicate' === $error_code ) { |
|
| 432 | - return new \WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 409 ) ); |
|
| 431 | + if ('comment_duplicate' === $error_code) { |
|
| 432 | + return new \WP_Error('woocommerce_rest_' . $error_code, $error_message, array('status' => 409)); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - if ( 'comment_flood' === $error_code ) { |
|
| 436 | - return new \WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 400 ) ); |
|
| 435 | + if ('comment_flood' === $error_code) { |
|
| 436 | + return new \WP_Error('woocommerce_rest_' . $error_code, $error_message, array('status' => 400)); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | return $prepared_review['comment_approved']; |
@@ -450,24 +450,24 @@ discard block |
||
| 450 | 450 | * @param array|\WP_Error $prepared_review The prepared review data for wp_insert_comment(). |
| 451 | 451 | * @param \WP_REST_Request $request Request used to insert the review. |
| 452 | 452 | */ |
| 453 | - $prepared_review = apply_filters( 'woocommerce_rest_pre_insert_product_review', $prepared_review, $request ); |
|
| 454 | - if ( is_wp_error( $prepared_review ) ) { |
|
| 453 | + $prepared_review = apply_filters('woocommerce_rest_pre_insert_product_review', $prepared_review, $request); |
|
| 454 | + if (is_wp_error($prepared_review)) { |
|
| 455 | 455 | return $prepared_review; |
| 456 | 456 | } |
| 457 | 457 | |
| 458 | - $review_id = wp_insert_comment( wp_filter_comment( wp_slash( (array) $prepared_review ) ) ); |
|
| 458 | + $review_id = wp_insert_comment(wp_filter_comment(wp_slash((array) $prepared_review))); |
|
| 459 | 459 | |
| 460 | - if ( ! $review_id ) { |
|
| 461 | - return new \WP_Error( 'woocommerce_rest_review_failed_create', __( 'Creating product review failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 460 | + if ( ! $review_id) { |
|
| 461 | + return new \WP_Error('woocommerce_rest_review_failed_create', __('Creating product review failed.', 'woocommerce'), array('status' => 500)); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | - if ( isset( $request['status'] ) ) { |
|
| 465 | - $this->handle_status_param( $request['status'], $review_id ); |
|
| 464 | + if (isset($request['status'])) { |
|
| 465 | + $this->handle_status_param($request['status'], $review_id); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - update_comment_meta( $review_id, 'rating', ! empty( $request['rating'] ) ? $request['rating'] : '0' ); |
|
| 468 | + update_comment_meta($review_id, 'rating', ! empty($request['rating']) ? $request['rating'] : '0'); |
|
| 469 | 469 | |
| 470 | - $review = get_comment( $review_id ); |
|
| 470 | + $review = get_comment($review_id); |
|
| 471 | 471 | |
| 472 | 472 | /** |
| 473 | 473 | * Fires after a comment is created or updated via the REST API. |
@@ -476,21 +476,21 @@ discard block |
||
| 476 | 476 | * @param \WP_REST_Request $request Request object. |
| 477 | 477 | * @param bool $creating True when creating a comment, false when updating. |
| 478 | 478 | */ |
| 479 | - do_action( 'woocommerce_rest_insert_product_review', $review, $request, true ); |
|
| 479 | + do_action('woocommerce_rest_insert_product_review', $review, $request, true); |
|
| 480 | 480 | |
| 481 | - $fields_update = $this->update_additional_fields_for_object( $review, $request ); |
|
| 482 | - if ( is_wp_error( $fields_update ) ) { |
|
| 481 | + $fields_update = $this->update_additional_fields_for_object($review, $request); |
|
| 482 | + if (is_wp_error($fields_update)) { |
|
| 483 | 483 | return $fields_update; |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - $context = current_user_can( 'moderate_comments' ) ? 'edit' : 'view'; |
|
| 487 | - $request->set_param( 'context', $context ); |
|
| 486 | + $context = current_user_can('moderate_comments') ? 'edit' : 'view'; |
|
| 487 | + $request->set_param('context', $context); |
|
| 488 | 488 | |
| 489 | - $response = $this->prepare_item_for_response( $review, $request ); |
|
| 490 | - $response = rest_ensure_response( $response ); |
|
| 489 | + $response = $this->prepare_item_for_response($review, $request); |
|
| 490 | + $response = rest_ensure_response($response); |
|
| 491 | 491 | |
| 492 | - $response->set_status( 201 ); |
|
| 493 | - $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $review_id ) ) ); |
|
| 492 | + $response->set_status(201); |
|
| 493 | + $response->header('Location', rest_url(sprintf('%s/%s/%d', $this->namespace, $this->rest_base, $review_id))); |
|
| 494 | 494 | |
| 495 | 495 | return $response; |
| 496 | 496 | } |
@@ -501,14 +501,14 @@ discard block |
||
| 501 | 501 | * @param \WP_REST_Request $request Full details about the request. |
| 502 | 502 | * @return \WP_Error|\WP_REST_Response |
| 503 | 503 | */ |
| 504 | - public function get_item( $request ) { |
|
| 505 | - $review = $this->get_review( $request['id'] ); |
|
| 506 | - if ( is_wp_error( $review ) ) { |
|
| 504 | + public function get_item($request) { |
|
| 505 | + $review = $this->get_review($request['id']); |
|
| 506 | + if (is_wp_error($review)) { |
|
| 507 | 507 | return $review; |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | - $data = $this->prepare_item_for_response( $review, $request ); |
|
| 511 | - $response = rest_ensure_response( $data ); |
|
| 510 | + $data = $this->prepare_item_for_response($review, $request); |
|
| 511 | + $response = rest_ensure_response($data); |
|
| 512 | 512 | |
| 513 | 513 | return $response; |
| 514 | 514 | } |
@@ -519,84 +519,84 @@ discard block |
||
| 519 | 519 | * @param \WP_REST_Request $request Full details about the request. |
| 520 | 520 | * @return \WP_Error|\WP_REST_Response Response object on success, or error object on failure. |
| 521 | 521 | */ |
| 522 | - public function update_item( $request ) { |
|
| 523 | - $review = $this->get_review( $request['id'] ); |
|
| 524 | - if ( is_wp_error( $review ) ) { |
|
| 522 | + public function update_item($request) { |
|
| 523 | + $review = $this->get_review($request['id']); |
|
| 524 | + if (is_wp_error($review)) { |
|
| 525 | 525 | return $review; |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | $id = (int) $review->comment_ID; |
| 529 | 529 | |
| 530 | - if ( isset( $request['type'] ) && 'review' !== get_comment_type( $id ) ) { |
|
| 531 | - return new \WP_Error( 'woocommerce_rest_review_invalid_type', __( 'Sorry, you are not allowed to change the comment type.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 530 | + if (isset($request['type']) && 'review' !== get_comment_type($id)) { |
|
| 531 | + return new \WP_Error('woocommerce_rest_review_invalid_type', __('Sorry, you are not allowed to change the comment type.', 'woocommerce'), array('status' => 404)); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - $prepared_args = $this->prepare_item_for_database( $request ); |
|
| 535 | - if ( is_wp_error( $prepared_args ) ) { |
|
| 534 | + $prepared_args = $this->prepare_item_for_database($request); |
|
| 535 | + if (is_wp_error($prepared_args)) { |
|
| 536 | 536 | return $prepared_args; |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - if ( ! empty( $prepared_args['comment_post_ID'] ) ) { |
|
| 540 | - if ( 'product' !== get_post_type( (int) $prepared_args['comment_post_ID'] ) ) { |
|
| 541 | - return new \WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 539 | + if ( ! empty($prepared_args['comment_post_ID'])) { |
|
| 540 | + if ('product' !== get_post_type((int) $prepared_args['comment_post_ID'])) { |
|
| 541 | + return new \WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404)); |
|
| 542 | 542 | } |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - if ( empty( $prepared_args ) && isset( $request['status'] ) ) { |
|
| 545 | + if (empty($prepared_args) && isset($request['status'])) { |
|
| 546 | 546 | // Only the comment status is being changed. |
| 547 | - $change = $this->handle_status_param( $request['status'], $id ); |
|
| 547 | + $change = $this->handle_status_param($request['status'], $id); |
|
| 548 | 548 | |
| 549 | - if ( ! $change ) { |
|
| 550 | - return new \WP_Error( 'woocommerce_rest_review_failed_edit', __( 'Updating review status failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 549 | + if ( ! $change) { |
|
| 550 | + return new \WP_Error('woocommerce_rest_review_failed_edit', __('Updating review status failed.', 'woocommerce'), array('status' => 500)); |
|
| 551 | 551 | } |
| 552 | - } elseif ( ! empty( $prepared_args ) ) { |
|
| 553 | - if ( is_wp_error( $prepared_args ) ) { |
|
| 552 | + } elseif ( ! empty($prepared_args)) { |
|
| 553 | + if (is_wp_error($prepared_args)) { |
|
| 554 | 554 | return $prepared_args; |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | - if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { |
|
| 558 | - return new \WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 557 | + if (isset($prepared_args['comment_content']) && empty($prepared_args['comment_content'])) { |
|
| 558 | + return new \WP_Error('woocommerce_rest_review_content_invalid', __('Invalid review content.', 'woocommerce'), array('status' => 400)); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | $prepared_args['comment_ID'] = $id; |
| 562 | 562 | |
| 563 | - $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args ); |
|
| 564 | - if ( is_wp_error( $check_comment_lengths ) ) { |
|
| 565 | - $error_code = str_replace( array( 'comment_author', 'comment_content' ), array( 'reviewer', 'review_content' ), $check_comment_lengths->get_error_code() ); |
|
| 566 | - return new \WP_Error( 'woocommerce_rest_' . $error_code, __( 'Product review field exceeds maximum length allowed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 563 | + $check_comment_lengths = wp_check_comment_data_max_lengths($prepared_args); |
|
| 564 | + if (is_wp_error($check_comment_lengths)) { |
|
| 565 | + $error_code = str_replace(array('comment_author', 'comment_content'), array('reviewer', 'review_content'), $check_comment_lengths->get_error_code()); |
|
| 566 | + return new \WP_Error('woocommerce_rest_' . $error_code, __('Product review field exceeds maximum length allowed.', 'woocommerce'), array('status' => 400)); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | - $updated = wp_update_comment( wp_slash( (array) $prepared_args ) ); |
|
| 569 | + $updated = wp_update_comment(wp_slash((array) $prepared_args)); |
|
| 570 | 570 | |
| 571 | - if ( false === $updated ) { |
|
| 572 | - return new \WP_Error( 'woocommerce_rest_comment_failed_edit', __( 'Updating review failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 571 | + if (false === $updated) { |
|
| 572 | + return new \WP_Error('woocommerce_rest_comment_failed_edit', __('Updating review failed.', 'woocommerce'), array('status' => 500)); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | - if ( isset( $request['status'] ) ) { |
|
| 576 | - $this->handle_status_param( $request['status'], $id ); |
|
| 575 | + if (isset($request['status'])) { |
|
| 576 | + $this->handle_status_param($request['status'], $id); |
|
| 577 | 577 | } |
| 578 | 578 | } |
| 579 | 579 | |
| 580 | - if ( ! empty( $request['rating'] ) ) { |
|
| 581 | - update_comment_meta( $id, 'rating', $request['rating'] ); |
|
| 580 | + if ( ! empty($request['rating'])) { |
|
| 581 | + update_comment_meta($id, 'rating', $request['rating']); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | - $review = get_comment( $id ); |
|
| 584 | + $review = get_comment($id); |
|
| 585 | 585 | |
| 586 | 586 | /** This action is documented in includes/api/class-wc-rest-product-reviews-controller.php */ |
| 587 | - do_action( 'woocommerce_rest_insert_product_review', $review, $request, false ); |
|
| 587 | + do_action('woocommerce_rest_insert_product_review', $review, $request, false); |
|
| 588 | 588 | |
| 589 | - $fields_update = $this->update_additional_fields_for_object( $review, $request ); |
|
| 589 | + $fields_update = $this->update_additional_fields_for_object($review, $request); |
|
| 590 | 590 | |
| 591 | - if ( is_wp_error( $fields_update ) ) { |
|
| 591 | + if (is_wp_error($fields_update)) { |
|
| 592 | 592 | return $fields_update; |
| 593 | 593 | } |
| 594 | 594 | |
| 595 | - $request->set_param( 'context', 'edit' ); |
|
| 595 | + $request->set_param('context', 'edit'); |
|
| 596 | 596 | |
| 597 | - $response = $this->prepare_item_for_response( $review, $request ); |
|
| 597 | + $response = $this->prepare_item_for_response($review, $request); |
|
| 598 | 598 | |
| 599 | - return rest_ensure_response( $response ); |
|
| 599 | + return rest_ensure_response($response); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | /** |
@@ -605,13 +605,13 @@ discard block |
||
| 605 | 605 | * @param \WP_REST_Request $request Full details about the request. |
| 606 | 606 | * @return \WP_Error|\WP_REST_Response Response object on success, or error object on failure. |
| 607 | 607 | */ |
| 608 | - public function delete_item( $request ) { |
|
| 609 | - $review = $this->get_review( $request['id'] ); |
|
| 610 | - if ( is_wp_error( $review ) ) { |
|
| 608 | + public function delete_item($request) { |
|
| 609 | + $review = $this->get_review($request['id']); |
|
| 610 | + if (is_wp_error($review)) { |
|
| 611 | 611 | return $review; |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 614 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
| 615 | 615 | |
| 616 | 616 | /** |
| 617 | 617 | * Filters whether a review can be trashed. |
@@ -622,13 +622,13 @@ discard block |
||
| 622 | 622 | * @param bool $supports_trash Whether the post type support trashing. |
| 623 | 623 | * @param WP_Comment $review The review object being considered for trashing support. |
| 624 | 624 | */ |
| 625 | - $supports_trash = apply_filters( 'woocommerce_rest_product_review_trashable', ( EMPTY_TRASH_DAYS > 0 ), $review ); |
|
| 625 | + $supports_trash = apply_filters('woocommerce_rest_product_review_trashable', (EMPTY_TRASH_DAYS > 0), $review); |
|
| 626 | 626 | |
| 627 | - $request->set_param( 'context', 'edit' ); |
|
| 627 | + $request->set_param('context', 'edit'); |
|
| 628 | 628 | |
| 629 | - if ( $force ) { |
|
| 630 | - $previous = $this->prepare_item_for_response( $review, $request ); |
|
| 631 | - $result = wp_delete_comment( $review->comment_ID, true ); |
|
| 629 | + if ($force) { |
|
| 630 | + $previous = $this->prepare_item_for_response($review, $request); |
|
| 631 | + $result = wp_delete_comment($review->comment_ID, true); |
|
| 632 | 632 | $response = new \WP_REST_Response(); |
| 633 | 633 | $response->set_data( |
| 634 | 634 | array( |
@@ -638,22 +638,22 @@ discard block |
||
| 638 | 638 | ); |
| 639 | 639 | } else { |
| 640 | 640 | // If this type doesn't support trashing, error out. |
| 641 | - if ( ! $supports_trash ) { |
|
| 641 | + if ( ! $supports_trash) { |
|
| 642 | 642 | /* translators: %s: force=true */ |
| 643 | - 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 | + 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)); |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | - if ( 'trash' === $review->comment_approved ) { |
|
| 647 | - return new \WP_Error( 'woocommerce_rest_already_trashed', __( 'The object has already been trashed.', 'woocommerce' ), array( 'status' => 410 ) ); |
|
| 646 | + if ('trash' === $review->comment_approved) { |
|
| 647 | + return new \WP_Error('woocommerce_rest_already_trashed', __('The object has already been trashed.', 'woocommerce'), array('status' => 410)); |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - $result = wp_trash_comment( $review->comment_ID ); |
|
| 651 | - $review = get_comment( $review->comment_ID ); |
|
| 652 | - $response = $this->prepare_item_for_response( $review, $request ); |
|
| 650 | + $result = wp_trash_comment($review->comment_ID); |
|
| 651 | + $review = get_comment($review->comment_ID); |
|
| 652 | + $response = $this->prepare_item_for_response($review, $request); |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | - if ( ! $result ) { |
|
| 656 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The object cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 655 | + if ( ! $result) { |
|
| 656 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('The object cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | /** |
@@ -663,7 +663,7 @@ discard block |
||
| 663 | 663 | * @param \WP_REST_Response $response The response returned from the API. |
| 664 | 664 | * @param \WP_REST_Request $request The request sent to the API. |
| 665 | 665 | */ |
| 666 | - do_action( 'woocommerce_rest_delete_review', $review, $response, $request ); |
|
| 666 | + do_action('woocommerce_rest_delete_review', $review, $response, $request); |
|
| 667 | 667 | |
| 668 | 668 | return $response; |
| 669 | 669 | } |
@@ -675,52 +675,52 @@ discard block |
||
| 675 | 675 | * @param \WP_REST_Request $request Request object. |
| 676 | 676 | * @return \WP_REST_Response $response Response data. |
| 677 | 677 | */ |
| 678 | - public function prepare_item_for_response( $review, $request ) { |
|
| 679 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 680 | - $fields = $this->get_fields_for_response( $request ); |
|
| 678 | + public function prepare_item_for_response($review, $request) { |
|
| 679 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 680 | + $fields = $this->get_fields_for_response($request); |
|
| 681 | 681 | $data = array(); |
| 682 | 682 | |
| 683 | - if ( in_array( 'id', $fields, true ) ) { |
|
| 683 | + if (in_array('id', $fields, true)) { |
|
| 684 | 684 | $data['id'] = (int) $review->comment_ID; |
| 685 | 685 | } |
| 686 | - if ( in_array( 'date_created', $fields, true ) ) { |
|
| 687 | - $data['date_created'] = wc_rest_prepare_date_response( $review->comment_date ); |
|
| 686 | + if (in_array('date_created', $fields, true)) { |
|
| 687 | + $data['date_created'] = wc_rest_prepare_date_response($review->comment_date); |
|
| 688 | 688 | } |
| 689 | - if ( in_array( 'date_created_gmt', $fields, true ) ) { |
|
| 690 | - $data['date_created_gmt'] = wc_rest_prepare_date_response( $review->comment_date_gmt ); |
|
| 689 | + if (in_array('date_created_gmt', $fields, true)) { |
|
| 690 | + $data['date_created_gmt'] = wc_rest_prepare_date_response($review->comment_date_gmt); |
|
| 691 | 691 | } |
| 692 | - if ( in_array( 'product_id', $fields, true ) ) { |
|
| 692 | + if (in_array('product_id', $fields, true)) { |
|
| 693 | 693 | $data['product_id'] = (int) $review->comment_post_ID; |
| 694 | 694 | } |
| 695 | - if ( in_array( 'status', $fields, true ) ) { |
|
| 696 | - $data['status'] = $this->prepare_status_response( (string) $review->comment_approved ); |
|
| 695 | + if (in_array('status', $fields, true)) { |
|
| 696 | + $data['status'] = $this->prepare_status_response((string) $review->comment_approved); |
|
| 697 | 697 | } |
| 698 | - if ( in_array( 'reviewer', $fields, true ) ) { |
|
| 698 | + if (in_array('reviewer', $fields, true)) { |
|
| 699 | 699 | $data['reviewer'] = $review->comment_author; |
| 700 | 700 | } |
| 701 | - if ( in_array( 'reviewer_email', $fields, true ) ) { |
|
| 701 | + if (in_array('reviewer_email', $fields, true)) { |
|
| 702 | 702 | $data['reviewer_email'] = $review->comment_author_email; |
| 703 | 703 | } |
| 704 | - if ( in_array( 'review', $fields, true ) ) { |
|
| 705 | - $data['review'] = 'view' === $context ? wpautop( $review->comment_content ) : $review->comment_content; |
|
| 704 | + if (in_array('review', $fields, true)) { |
|
| 705 | + $data['review'] = 'view' === $context ? wpautop($review->comment_content) : $review->comment_content; |
|
| 706 | 706 | } |
| 707 | - if ( in_array( 'rating', $fields, true ) ) { |
|
| 708 | - $data['rating'] = (int) get_comment_meta( $review->comment_ID, 'rating', true ); |
|
| 707 | + if (in_array('rating', $fields, true)) { |
|
| 708 | + $data['rating'] = (int) get_comment_meta($review->comment_ID, 'rating', true); |
|
| 709 | 709 | } |
| 710 | - if ( in_array( 'verified', $fields, true ) ) { |
|
| 711 | - $data['verified'] = wc_review_is_from_verified_owner( $review->comment_ID ); |
|
| 710 | + if (in_array('verified', $fields, true)) { |
|
| 711 | + $data['verified'] = wc_review_is_from_verified_owner($review->comment_ID); |
|
| 712 | 712 | } |
| 713 | - if ( in_array( 'reviewer_avatar_urls', $fields, true ) ) { |
|
| 714 | - $data['reviewer_avatar_urls'] = rest_get_avatar_urls( $review->comment_author_email ); |
|
| 713 | + if (in_array('reviewer_avatar_urls', $fields, true)) { |
|
| 714 | + $data['reviewer_avatar_urls'] = rest_get_avatar_urls($review->comment_author_email); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 718 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 717 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 718 | + $data = $this->filter_response_by_context($data, $context); |
|
| 719 | 719 | |
| 720 | 720 | // Wrap the data in a response object. |
| 721 | - $response = rest_ensure_response( $data ); |
|
| 721 | + $response = rest_ensure_response($data); |
|
| 722 | 722 | |
| 723 | - $response->add_links( $this->prepare_links( $review ) ); |
|
| 723 | + $response->add_links($this->prepare_links($review)); |
|
| 724 | 724 | |
| 725 | 725 | /** |
| 726 | 726 | * Filter product reviews object returned from the REST API. |
@@ -729,7 +729,7 @@ discard block |
||
| 729 | 729 | * @param \WP_Comment $review Product review object used to create response. |
| 730 | 730 | * @param \WP_REST_Request $request Request object. |
| 731 | 731 | */ |
| 732 | - return apply_filters( 'woocommerce_rest_prepare_product_review', $response, $review, $request ); |
|
| 732 | + return apply_filters('woocommerce_rest_prepare_product_review', $response, $review, $request); |
|
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | /** |
@@ -738,38 +738,38 @@ discard block |
||
| 738 | 738 | * @param \WP_REST_Request $request Request object. |
| 739 | 739 | * @return array|\WP_Error $prepared_review |
| 740 | 740 | */ |
| 741 | - protected function prepare_item_for_database( $request ) { |
|
| 742 | - if ( isset( $request['id'] ) ) { |
|
| 741 | + protected function prepare_item_for_database($request) { |
|
| 742 | + if (isset($request['id'])) { |
|
| 743 | 743 | $prepared_review['comment_ID'] = (int) $request['id']; |
| 744 | 744 | } |
| 745 | 745 | |
| 746 | - if ( isset( $request['review'] ) ) { |
|
| 746 | + if (isset($request['review'])) { |
|
| 747 | 747 | $prepared_review['comment_content'] = $request['review']; |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | - if ( isset( $request['product_id'] ) ) { |
|
| 750 | + if (isset($request['product_id'])) { |
|
| 751 | 751 | $prepared_review['comment_post_ID'] = (int) $request['product_id']; |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | - if ( isset( $request['reviewer'] ) ) { |
|
| 754 | + if (isset($request['reviewer'])) { |
|
| 755 | 755 | $prepared_review['comment_author'] = $request['reviewer']; |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | - if ( isset( $request['reviewer_email'] ) ) { |
|
| 758 | + if (isset($request['reviewer_email'])) { |
|
| 759 | 759 | $prepared_review['comment_author_email'] = $request['reviewer_email']; |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - if ( ! empty( $request['date_created'] ) ) { |
|
| 763 | - $date_data = rest_get_date_with_gmt( $request['date_created'] ); |
|
| 762 | + if ( ! empty($request['date_created'])) { |
|
| 763 | + $date_data = rest_get_date_with_gmt($request['date_created']); |
|
| 764 | 764 | |
| 765 | - if ( ! empty( $date_data ) ) { |
|
| 766 | - list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data; |
|
| 765 | + if ( ! empty($date_data)) { |
|
| 766 | + list($prepared_review['comment_date'], $prepared_review['comment_date_gmt']) = $date_data; |
|
| 767 | 767 | } |
| 768 | - } elseif ( ! empty( $request['date_created_gmt'] ) ) { |
|
| 769 | - $date_data = rest_get_date_with_gmt( $request['date_created_gmt'], true ); |
|
| 768 | + } elseif ( ! empty($request['date_created_gmt'])) { |
|
| 769 | + $date_data = rest_get_date_with_gmt($request['date_created_gmt'], true); |
|
| 770 | 770 | |
| 771 | - if ( ! empty( $date_data ) ) { |
|
| 772 | - list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data; |
|
| 771 | + if ( ! empty($date_data)) { |
|
| 772 | + list($prepared_review['comment_date'], $prepared_review['comment_date_gmt']) = $date_data; |
|
| 773 | 773 | } |
| 774 | 774 | } |
| 775 | 775 | |
@@ -782,7 +782,7 @@ discard block |
||
| 782 | 782 | * @param array $prepared_review The prepared review data for `wp_insert_comment`. |
| 783 | 783 | * @param \WP_REST_Request $request The current request. |
| 784 | 784 | */ |
| 785 | - return apply_filters( 'woocommerce_rest_preprocess_product_review', $prepared_review, $request ); |
|
| 785 | + return apply_filters('woocommerce_rest_preprocess_product_review', $prepared_review, $request); |
|
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | /** |
@@ -791,24 +791,24 @@ discard block |
||
| 791 | 791 | * @param WP_Comment $review Product review object. |
| 792 | 792 | * @return array Links for the given product review. |
| 793 | 793 | */ |
| 794 | - protected function prepare_links( $review ) { |
|
| 794 | + protected function prepare_links($review) { |
|
| 795 | 795 | $links = array( |
| 796 | 796 | 'self' => array( |
| 797 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $review->comment_ID ) ), |
|
| 797 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $review->comment_ID)), |
|
| 798 | 798 | ), |
| 799 | 799 | 'collection' => array( |
| 800 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
| 800 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
| 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 | 'embeddable' => true, |
| 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 | } |
@@ -827,91 +827,91 @@ discard block |
||
| 827 | 827 | 'type' => 'object', |
| 828 | 828 | 'properties' => array( |
| 829 | 829 | 'id' => array( |
| 830 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 830 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 831 | 831 | 'type' => 'integer', |
| 832 | - 'context' => array( 'view', 'edit' ), |
|
| 832 | + 'context' => array('view', 'edit'), |
|
| 833 | 833 | 'readonly' => true, |
| 834 | 834 | ), |
| 835 | 835 | 'date_created' => array( |
| 836 | - 'description' => __( "The date the review was created, in the site's timezone.", 'woocommerce' ), |
|
| 836 | + 'description' => __("The date the review was created, in the site's timezone.", 'woocommerce'), |
|
| 837 | 837 | 'type' => 'date-time', |
| 838 | - 'context' => array( 'view', 'edit' ), |
|
| 838 | + 'context' => array('view', 'edit'), |
|
| 839 | 839 | 'readonly' => true, |
| 840 | 840 | ), |
| 841 | 841 | 'date_created_gmt' => array( |
| 842 | - 'description' => __( 'The date the review was created, as GMT.', 'woocommerce' ), |
|
| 842 | + 'description' => __('The date the review was created, as GMT.', 'woocommerce'), |
|
| 843 | 843 | 'type' => 'date-time', |
| 844 | - 'context' => array( 'view', 'edit' ), |
|
| 844 | + 'context' => array('view', 'edit'), |
|
| 845 | 845 | 'readonly' => true, |
| 846 | 846 | ), |
| 847 | 847 | 'product_id' => array( |
| 848 | - 'description' => __( 'Unique identifier for the product that the review belongs to.', 'woocommerce' ), |
|
| 848 | + 'description' => __('Unique identifier for the product that the review belongs to.', 'woocommerce'), |
|
| 849 | 849 | 'type' => 'integer', |
| 850 | - 'context' => array( 'view', 'edit' ), |
|
| 850 | + 'context' => array('view', 'edit'), |
|
| 851 | 851 | ), |
| 852 | 852 | 'status' => array( |
| 853 | - 'description' => __( 'Status of the review.', 'woocommerce' ), |
|
| 853 | + 'description' => __('Status of the review.', 'woocommerce'), |
|
| 854 | 854 | 'type' => 'string', |
| 855 | 855 | 'default' => 'approved', |
| 856 | - 'enum' => array( 'approved', 'hold', 'spam', 'unspam', 'trash', 'untrash' ), |
|
| 857 | - 'context' => array( 'view', 'edit' ), |
|
| 856 | + 'enum' => array('approved', 'hold', 'spam', 'unspam', 'trash', 'untrash'), |
|
| 857 | + 'context' => array('view', 'edit'), |
|
| 858 | 858 | ), |
| 859 | 859 | 'reviewer' => array( |
| 860 | - 'description' => __( 'Reviewer name.', 'woocommerce' ), |
|
| 860 | + 'description' => __('Reviewer name.', 'woocommerce'), |
|
| 861 | 861 | 'type' => 'string', |
| 862 | - 'context' => array( 'view', 'edit' ), |
|
| 862 | + 'context' => array('view', 'edit'), |
|
| 863 | 863 | ), |
| 864 | 864 | 'reviewer_email' => array( |
| 865 | - 'description' => __( 'Reviewer email.', 'woocommerce' ), |
|
| 865 | + 'description' => __('Reviewer email.', 'woocommerce'), |
|
| 866 | 866 | 'type' => 'string', |
| 867 | 867 | 'format' => 'email', |
| 868 | - 'context' => array( 'view', 'edit' ), |
|
| 868 | + 'context' => array('view', 'edit'), |
|
| 869 | 869 | ), |
| 870 | 870 | 'review' => array( |
| 871 | - 'description' => __( 'The content of the review.', 'woocommerce' ), |
|
| 871 | + 'description' => __('The content of the review.', 'woocommerce'), |
|
| 872 | 872 | 'type' => 'string', |
| 873 | - 'context' => array( 'view', 'edit' ), |
|
| 873 | + 'context' => array('view', 'edit'), |
|
| 874 | 874 | 'arg_options' => array( |
| 875 | 875 | 'sanitize_callback' => 'wp_filter_post_kses', |
| 876 | 876 | ), |
| 877 | 877 | ), |
| 878 | 878 | 'rating' => array( |
| 879 | - 'description' => __( 'Review rating (0 to 5).', 'woocommerce' ), |
|
| 879 | + 'description' => __('Review rating (0 to 5).', 'woocommerce'), |
|
| 880 | 880 | 'type' => 'integer', |
| 881 | - 'context' => array( 'view', 'edit' ), |
|
| 881 | + 'context' => array('view', 'edit'), |
|
| 882 | 882 | ), |
| 883 | 883 | 'verified' => array( |
| 884 | - 'description' => __( 'Shows if the reviewer bought the product or not.', 'woocommerce' ), |
|
| 884 | + 'description' => __('Shows if the reviewer bought the product or not.', 'woocommerce'), |
|
| 885 | 885 | 'type' => 'boolean', |
| 886 | - 'context' => array( 'view', 'edit' ), |
|
| 886 | + 'context' => array('view', 'edit'), |
|
| 887 | 887 | 'readonly' => true, |
| 888 | 888 | ), |
| 889 | 889 | ), |
| 890 | 890 | ); |
| 891 | 891 | |
| 892 | - if ( get_option( 'show_avatars' ) ) { |
|
| 892 | + if (get_option('show_avatars')) { |
|
| 893 | 893 | $avatar_properties = array(); |
| 894 | 894 | $avatar_sizes = rest_get_avatar_sizes(); |
| 895 | 895 | |
| 896 | - foreach ( $avatar_sizes as $size ) { |
|
| 897 | - $avatar_properties[ $size ] = array( |
|
| 896 | + foreach ($avatar_sizes as $size) { |
|
| 897 | + $avatar_properties[$size] = array( |
|
| 898 | 898 | /* translators: %d: avatar image size in pixels */ |
| 899 | - 'description' => sprintf( __( 'Avatar URL with image size of %d pixels.', 'woocommerce' ), $size ), |
|
| 899 | + 'description' => sprintf(__('Avatar URL with image size of %d pixels.', 'woocommerce'), $size), |
|
| 900 | 900 | 'type' => 'string', |
| 901 | 901 | 'format' => 'uri', |
| 902 | - 'context' => array( 'embed', 'view', 'edit' ), |
|
| 902 | + 'context' => array('embed', 'view', 'edit'), |
|
| 903 | 903 | ); |
| 904 | 904 | } |
| 905 | 905 | $schema['properties']['reviewer_avatar_urls'] = array( |
| 906 | - 'description' => __( 'Avatar URLs for the object reviewer.', 'woocommerce' ), |
|
| 906 | + 'description' => __('Avatar URLs for the object reviewer.', 'woocommerce'), |
|
| 907 | 907 | 'type' => 'object', |
| 908 | - 'context' => array( 'view', 'edit' ), |
|
| 908 | + 'context' => array('view', 'edit'), |
|
| 909 | 909 | 'readonly' => true, |
| 910 | 910 | 'properties' => $avatar_properties, |
| 911 | 911 | ); |
| 912 | 912 | } |
| 913 | 913 | |
| 914 | - return $this->add_additional_fields_schema( $schema ); |
|
| 914 | + return $this->add_additional_fields_schema($schema); |
|
| 915 | 915 | } |
| 916 | 916 | |
| 917 | 917 | /** |
@@ -924,38 +924,38 @@ discard block |
||
| 924 | 924 | |
| 925 | 925 | $params['context']['default'] = 'view'; |
| 926 | 926 | |
| 927 | - $params['after'] = array( |
|
| 928 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 927 | + $params['after'] = array( |
|
| 928 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 929 | 929 | 'type' => 'string', |
| 930 | 930 | 'format' => 'date-time', |
| 931 | 931 | ); |
| 932 | - $params['before'] = array( |
|
| 933 | - 'description' => __( 'Limit response to reviews published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 932 | + $params['before'] = array( |
|
| 933 | + 'description' => __('Limit response to reviews published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 934 | 934 | 'type' => 'string', |
| 935 | 935 | 'format' => 'date-time', |
| 936 | 936 | ); |
| 937 | - $params['exclude'] = array( |
|
| 938 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
|
| 937 | + $params['exclude'] = array( |
|
| 938 | + 'description' => __('Ensure result set excludes specific IDs.', 'woocommerce'), |
|
| 939 | 939 | 'type' => 'array', |
| 940 | 940 | 'items' => array( |
| 941 | 941 | 'type' => 'integer', |
| 942 | 942 | ), |
| 943 | 943 | 'default' => array(), |
| 944 | 944 | ); |
| 945 | - $params['include'] = array( |
|
| 946 | - 'description' => __( 'Limit result set to specific IDs.', 'woocommerce' ), |
|
| 945 | + $params['include'] = array( |
|
| 946 | + 'description' => __('Limit result set to specific IDs.', 'woocommerce'), |
|
| 947 | 947 | 'type' => 'array', |
| 948 | 948 | 'items' => array( |
| 949 | 949 | 'type' => 'integer', |
| 950 | 950 | ), |
| 951 | 951 | 'default' => array(), |
| 952 | 952 | ); |
| 953 | - $params['offset'] = array( |
|
| 954 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
| 953 | + $params['offset'] = array( |
|
| 954 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
| 955 | 955 | 'type' => 'integer', |
| 956 | 956 | ); |
| 957 | - $params['order'] = array( |
|
| 958 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 957 | + $params['order'] = array( |
|
| 958 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 959 | 959 | 'type' => 'string', |
| 960 | 960 | 'default' => 'desc', |
| 961 | 961 | 'enum' => array( |
@@ -963,8 +963,8 @@ discard block |
||
| 963 | 963 | 'desc', |
| 964 | 964 | ), |
| 965 | 965 | ); |
| 966 | - $params['orderby'] = array( |
|
| 967 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 966 | + $params['orderby'] = array( |
|
| 967 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 968 | 968 | 'type' => 'string', |
| 969 | 969 | 'default' => 'date_gmt', |
| 970 | 970 | 'enum' => array( |
@@ -975,37 +975,37 @@ discard block |
||
| 975 | 975 | 'product', |
| 976 | 976 | ), |
| 977 | 977 | ); |
| 978 | - $params['reviewer'] = array( |
|
| 979 | - 'description' => __( 'Limit result set to reviews assigned to specific user IDs.', 'woocommerce' ), |
|
| 978 | + $params['reviewer'] = array( |
|
| 979 | + 'description' => __('Limit result set to reviews assigned to specific user IDs.', 'woocommerce'), |
|
| 980 | 980 | 'type' => 'array', |
| 981 | 981 | 'items' => array( |
| 982 | 982 | 'type' => 'integer', |
| 983 | 983 | ), |
| 984 | 984 | ); |
| 985 | 985 | $params['reviewer_exclude'] = array( |
| 986 | - 'description' => __( 'Ensure result set excludes reviews assigned to specific user IDs.', 'woocommerce' ), |
|
| 986 | + 'description' => __('Ensure result set excludes reviews assigned to specific user IDs.', 'woocommerce'), |
|
| 987 | 987 | 'type' => 'array', |
| 988 | 988 | 'items' => array( |
| 989 | 989 | 'type' => 'integer', |
| 990 | 990 | ), |
| 991 | 991 | ); |
| 992 | - $params['reviewer_email'] = array( |
|
| 992 | + $params['reviewer_email'] = array( |
|
| 993 | 993 | 'default' => null, |
| 994 | - 'description' => __( 'Limit result set to that from a specific author email.', 'woocommerce' ), |
|
| 994 | + 'description' => __('Limit result set to that from a specific author email.', 'woocommerce'), |
|
| 995 | 995 | 'format' => 'email', |
| 996 | 996 | 'type' => 'string', |
| 997 | 997 | ); |
| 998 | - $params['product'] = array( |
|
| 998 | + $params['product'] = array( |
|
| 999 | 999 | 'default' => array(), |
| 1000 | - 'description' => __( 'Limit result set to reviews assigned to specific product IDs.', 'woocommerce' ), |
|
| 1000 | + 'description' => __('Limit result set to reviews assigned to specific product IDs.', 'woocommerce'), |
|
| 1001 | 1001 | 'type' => 'array', |
| 1002 | 1002 | 'items' => array( |
| 1003 | 1003 | 'type' => 'integer', |
| 1004 | 1004 | ), |
| 1005 | 1005 | ); |
| 1006 | - $params['status'] = array( |
|
| 1006 | + $params['status'] = array( |
|
| 1007 | 1007 | 'default' => 'approved', |
| 1008 | - 'description' => __( 'Limit result set to reviews assigned a specific status.', 'woocommerce' ), |
|
| 1008 | + 'description' => __('Limit result set to reviews assigned a specific status.', 'woocommerce'), |
|
| 1009 | 1009 | 'sanitize_callback' => 'sanitize_key', |
| 1010 | 1010 | 'type' => 'string', |
| 1011 | 1011 | 'enum' => array( |
@@ -1027,7 +1027,7 @@ discard block |
||
| 1027 | 1027 | * @since 3.5.0 |
| 1028 | 1028 | * @param array $params JSON Schema-formatted collection parameters. |
| 1029 | 1029 | */ |
| 1030 | - return apply_filters( 'woocommerce_rest_product_review_collection_params', $params ); |
|
| 1030 | + return apply_filters('woocommerce_rest_product_review_collection_params', $params); |
|
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | 1033 | /** |
@@ -1037,24 +1037,24 @@ discard block |
||
| 1037 | 1037 | * @param int $id Supplied ID. |
| 1038 | 1038 | * @return WP_Comment|\WP_Error Comment object if ID is valid, \WP_Error otherwise. |
| 1039 | 1039 | */ |
| 1040 | - protected function get_review( $id ) { |
|
| 1040 | + protected function get_review($id) { |
|
| 1041 | 1041 | $id = (int) $id; |
| 1042 | - $error = new \WP_Error( 'woocommerce_rest_review_invalid_id', __( 'Invalid review ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 1042 | + $error = new \WP_Error('woocommerce_rest_review_invalid_id', __('Invalid review ID.', 'woocommerce'), array('status' => 404)); |
|
| 1043 | 1043 | |
| 1044 | - if ( 0 >= $id ) { |
|
| 1044 | + if (0 >= $id) { |
|
| 1045 | 1045 | return $error; |
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | - $review = get_comment( $id ); |
|
| 1049 | - if ( empty( $review ) ) { |
|
| 1048 | + $review = get_comment($id); |
|
| 1049 | + if (empty($review)) { |
|
| 1050 | 1050 | return $error; |
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | - if ( ! empty( $review->comment_post_ID ) ) { |
|
| 1054 | - $post = get_post( (int) $review->comment_post_ID ); |
|
| 1053 | + if ( ! empty($review->comment_post_ID)) { |
|
| 1054 | + $post = get_post((int) $review->comment_post_ID); |
|
| 1055 | 1055 | |
| 1056 | - if ( 'product' !== get_post_type( (int) $review->comment_post_ID ) ) { |
|
| 1057 | - return new \WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 1056 | + if ('product' !== get_post_type((int) $review->comment_post_ID)) { |
|
| 1057 | + return new \WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404)); |
|
| 1058 | 1058 | } |
| 1059 | 1059 | } |
| 1060 | 1060 | |
@@ -1068,10 +1068,10 @@ discard block |
||
| 1068 | 1068 | * @param string $query_param Query parameter. |
| 1069 | 1069 | * @return string |
| 1070 | 1070 | */ |
| 1071 | - protected function normalize_query_param( $query_param ) { |
|
| 1071 | + protected function normalize_query_param($query_param) { |
|
| 1072 | 1072 | $prefix = 'comment_'; |
| 1073 | 1073 | |
| 1074 | - switch ( $query_param ) { |
|
| 1074 | + switch ($query_param) { |
|
| 1075 | 1075 | case 'id': |
| 1076 | 1076 | $normalized = $prefix . 'ID'; |
| 1077 | 1077 | break; |
@@ -1096,8 +1096,8 @@ discard block |
||
| 1096 | 1096 | * @param string|int $comment_approved comment status. |
| 1097 | 1097 | * @return string Comment status. |
| 1098 | 1098 | */ |
| 1099 | - protected function prepare_status_response( $comment_approved ) { |
|
| 1100 | - switch ( $comment_approved ) { |
|
| 1099 | + protected function prepare_status_response($comment_approved) { |
|
| 1100 | + switch ($comment_approved) { |
|
| 1101 | 1101 | case 'hold': |
| 1102 | 1102 | case '0': |
| 1103 | 1103 | $status = 'hold'; |
@@ -1124,34 +1124,34 @@ discard block |
||
| 1124 | 1124 | * @param int $id Review ID. |
| 1125 | 1125 | * @return bool Whether the status was changed. |
| 1126 | 1126 | */ |
| 1127 | - protected function handle_status_param( $new_status, $id ) { |
|
| 1128 | - $old_status = wp_get_comment_status( $id ); |
|
| 1127 | + protected function handle_status_param($new_status, $id) { |
|
| 1128 | + $old_status = wp_get_comment_status($id); |
|
| 1129 | 1129 | |
| 1130 | - if ( $new_status === $old_status ) { |
|
| 1130 | + if ($new_status === $old_status) { |
|
| 1131 | 1131 | return false; |
| 1132 | 1132 | } |
| 1133 | 1133 | |
| 1134 | - switch ( $new_status ) { |
|
| 1134 | + switch ($new_status) { |
|
| 1135 | 1135 | case 'approved': |
| 1136 | 1136 | case 'approve': |
| 1137 | 1137 | case '1': |
| 1138 | - $changed = wp_set_comment_status( $id, 'approve' ); |
|
| 1138 | + $changed = wp_set_comment_status($id, 'approve'); |
|
| 1139 | 1139 | break; |
| 1140 | 1140 | case 'hold': |
| 1141 | 1141 | case '0': |
| 1142 | - $changed = wp_set_comment_status( $id, 'hold' ); |
|
| 1142 | + $changed = wp_set_comment_status($id, 'hold'); |
|
| 1143 | 1143 | break; |
| 1144 | 1144 | case 'spam': |
| 1145 | - $changed = wp_spam_comment( $id ); |
|
| 1145 | + $changed = wp_spam_comment($id); |
|
| 1146 | 1146 | break; |
| 1147 | 1147 | case 'unspam': |
| 1148 | - $changed = wp_unspam_comment( $id ); |
|
| 1148 | + $changed = wp_unspam_comment($id); |
|
| 1149 | 1149 | break; |
| 1150 | 1150 | case 'trash': |
| 1151 | - $changed = wp_trash_comment( $id ); |
|
| 1151 | + $changed = wp_trash_comment($id); |
|
| 1152 | 1152 | break; |
| 1153 | 1153 | case 'untrash': |
| 1154 | - $changed = wp_untrash_comment( $id ); |
|
| 1154 | + $changed = wp_untrash_comment($id); |
|
| 1155 | 1155 | break; |
| 1156 | 1156 | default: |
| 1157 | 1157 | $changed = false; |