@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @since 3.0.0 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -47,74 +47,74 @@ discard block |
||
| 47 | 47 | * Initialize orders actions. |
| 48 | 48 | */ |
| 49 | 49 | public function __construct() { |
| 50 | - add_filter( "woocommerce_rest_{$this->post_type}_query", array( $this, 'query_args' ), 10, 2 ); |
|
| 50 | + add_filter("woocommerce_rest_{$this->post_type}_query", array($this, 'query_args'), 10, 2); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * Register the routes for orders. |
| 55 | 55 | */ |
| 56 | 56 | public function register_routes() { |
| 57 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
| 57 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
| 58 | 58 | array( |
| 59 | 59 | 'methods' => WP_REST_Server::READABLE, |
| 60 | - 'callback' => array( $this, 'get_items' ), |
|
| 61 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 60 | + 'callback' => array($this, 'get_items'), |
|
| 61 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 62 | 62 | 'args' => $this->get_collection_params(), |
| 63 | 63 | ), |
| 64 | 64 | array( |
| 65 | 65 | 'methods' => WP_REST_Server::CREATABLE, |
| 66 | - 'callback' => array( $this, 'create_item' ), |
|
| 67 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
| 68 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
|
| 66 | + 'callback' => array($this, 'create_item'), |
|
| 67 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
| 68 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), |
|
| 69 | 69 | ), |
| 70 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 71 | - ) ); |
|
| 70 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 71 | + )); |
|
| 72 | 72 | |
| 73 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
| 73 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
| 74 | 74 | 'args' => array( |
| 75 | 75 | 'id' => array( |
| 76 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 76 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 77 | 77 | 'type' => 'integer', |
| 78 | 78 | ), |
| 79 | 79 | ), |
| 80 | 80 | array( |
| 81 | 81 | 'methods' => WP_REST_Server::READABLE, |
| 82 | - 'callback' => array( $this, 'get_item' ), |
|
| 83 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 82 | + 'callback' => array($this, 'get_item'), |
|
| 83 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 84 | 84 | 'args' => array( |
| 85 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 85 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 86 | 86 | ), |
| 87 | 87 | ), |
| 88 | 88 | array( |
| 89 | 89 | 'methods' => WP_REST_Server::EDITABLE, |
| 90 | - 'callback' => array( $this, 'update_item' ), |
|
| 91 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
| 92 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
| 90 | + 'callback' => array($this, 'update_item'), |
|
| 91 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
| 92 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
| 93 | 93 | ), |
| 94 | 94 | array( |
| 95 | 95 | 'methods' => WP_REST_Server::DELETABLE, |
| 96 | - 'callback' => array( $this, 'delete_item' ), |
|
| 97 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
| 96 | + 'callback' => array($this, 'delete_item'), |
|
| 97 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
| 98 | 98 | 'args' => array( |
| 99 | 99 | 'force' => array( |
| 100 | 100 | 'default' => false, |
| 101 | 101 | 'type' => 'boolean', |
| 102 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
| 102 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
| 103 | 103 | ), |
| 104 | 104 | ), |
| 105 | 105 | ), |
| 106 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 107 | - ) ); |
|
| 106 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 107 | + )); |
|
| 108 | 108 | |
| 109 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( |
|
| 109 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array( |
|
| 110 | 110 | array( |
| 111 | 111 | 'methods' => WP_REST_Server::EDITABLE, |
| 112 | - 'callback' => array( $this, 'batch_items' ), |
|
| 113 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
| 114 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
| 112 | + 'callback' => array($this, 'batch_items'), |
|
| 113 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
| 114 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
| 115 | 115 | ), |
| 116 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
| 117 | - ) ); |
|
| 116 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
| 117 | + )); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | * @param WP_REST_Request $request Request object. |
| 125 | 125 | * @return WP_REST_Response $data |
| 126 | 126 | */ |
| 127 | - public function prepare_item_for_response( $post, $request ) { |
|
| 128 | - $order = wc_get_order( $post ); |
|
| 129 | - $dp = is_null( $request['dp'] ) ? wc_get_price_decimals() : absint( $request['dp'] ); |
|
| 127 | + public function prepare_item_for_response($post, $request) { |
|
| 128 | + $order = wc_get_order($post); |
|
| 129 | + $dp = is_null($request['dp']) ? wc_get_price_decimals() : absint($request['dp']); |
|
| 130 | 130 | |
| 131 | 131 | $data = array( |
| 132 | 132 | 'id' => $order->get_id(), |
@@ -137,16 +137,16 @@ discard block |
||
| 137 | 137 | 'currency' => $order->get_currency(), |
| 138 | 138 | 'version' => $order->get_version(), |
| 139 | 139 | 'prices_include_tax' => $order->get_prices_include_tax(), |
| 140 | - 'date_created' => wc_rest_prepare_date_response( $order->get_date_created() ), // v1 API used UTC. |
|
| 141 | - 'date_modified' => wc_rest_prepare_date_response( $order->get_date_modified() ), // v1 API used UTC. |
|
| 140 | + 'date_created' => wc_rest_prepare_date_response($order->get_date_created()), // v1 API used UTC. |
|
| 141 | + 'date_modified' => wc_rest_prepare_date_response($order->get_date_modified()), // v1 API used UTC. |
|
| 142 | 142 | 'customer_id' => $order->get_customer_id(), |
| 143 | - 'discount_total' => wc_format_decimal( $order->get_total_discount(), $dp ), |
|
| 144 | - 'discount_tax' => wc_format_decimal( $order->get_discount_tax(), $dp ), |
|
| 145 | - 'shipping_total' => wc_format_decimal( $order->get_shipping_total(), $dp ), |
|
| 146 | - 'shipping_tax' => wc_format_decimal( $order->get_shipping_tax(), $dp ), |
|
| 147 | - 'cart_tax' => wc_format_decimal( $order->get_cart_tax(), $dp ), |
|
| 148 | - 'total' => wc_format_decimal( $order->get_total(), $dp ), |
|
| 149 | - 'total_tax' => wc_format_decimal( $order->get_total_tax(), $dp ), |
|
| 143 | + 'discount_total' => wc_format_decimal($order->get_total_discount(), $dp), |
|
| 144 | + 'discount_tax' => wc_format_decimal($order->get_discount_tax(), $dp), |
|
| 145 | + 'shipping_total' => wc_format_decimal($order->get_shipping_total(), $dp), |
|
| 146 | + 'shipping_tax' => wc_format_decimal($order->get_shipping_tax(), $dp), |
|
| 147 | + 'cart_tax' => wc_format_decimal($order->get_cart_tax(), $dp), |
|
| 148 | + 'total' => wc_format_decimal($order->get_total(), $dp), |
|
| 149 | + 'total_tax' => wc_format_decimal($order->get_total_tax(), $dp), |
|
| 150 | 150 | 'billing' => array(), |
| 151 | 151 | 'shipping' => array(), |
| 152 | 152 | 'payment_method' => $order->get_payment_method(), |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | 'customer_user_agent' => $order->get_customer_user_agent(), |
| 157 | 157 | 'created_via' => $order->get_created_via(), |
| 158 | 158 | 'customer_note' => $order->get_customer_note(), |
| 159 | - 'date_completed' => wc_rest_prepare_date_response( $order->get_date_completed(), false ), // v1 API used local time. |
|
| 160 | - 'date_paid' => wc_rest_prepare_date_response( $order->get_date_paid(), false ), // v1 API used local time. |
|
| 159 | + 'date_completed' => wc_rest_prepare_date_response($order->get_date_completed(), false), // v1 API used local time. |
|
| 160 | + 'date_paid' => wc_rest_prepare_date_response($order->get_date_paid(), false), // v1 API used local time. |
|
| 161 | 161 | 'cart_hash' => $order->get_cart_hash(), |
| 162 | 162 | 'line_items' => array(), |
| 163 | 163 | 'tax_lines' => array(), |
@@ -168,18 +168,18 @@ discard block |
||
| 168 | 168 | ); |
| 169 | 169 | |
| 170 | 170 | // Add addresses. |
| 171 | - $data['billing'] = $order->get_address( 'billing' ); |
|
| 172 | - $data['shipping'] = $order->get_address( 'shipping' ); |
|
| 171 | + $data['billing'] = $order->get_address('billing'); |
|
| 172 | + $data['shipping'] = $order->get_address('shipping'); |
|
| 173 | 173 | |
| 174 | 174 | // Add line items. |
| 175 | - foreach ( $order->get_items() as $item_id => $item ) { |
|
| 176 | - $product = $order->get_product_from_item( $item ); |
|
| 175 | + foreach ($order->get_items() as $item_id => $item) { |
|
| 176 | + $product = $order->get_product_from_item($item); |
|
| 177 | 177 | $product_id = 0; |
| 178 | 178 | $variation_id = 0; |
| 179 | 179 | $product_sku = null; |
| 180 | 180 | |
| 181 | 181 | // Check if the product exists. |
| 182 | - if ( is_object( $product ) ) { |
|
| 182 | + if (is_object($product)) { |
|
| 183 | 183 | $product_id = $item->get_product_id(); |
| 184 | 184 | $variation_id = $item->get_variation_id(); |
| 185 | 185 | $product_sku = $product->get_sku(); |
@@ -189,11 +189,11 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | $hideprefix = 'true' === $request['all_item_meta'] ? null : '_'; |
| 191 | 191 | |
| 192 | - foreach ( $item->get_formatted_meta_data( $hideprefix, true ) as $meta_key => $formatted_meta ) { |
|
| 192 | + foreach ($item->get_formatted_meta_data($hideprefix, true) as $meta_key => $formatted_meta) { |
|
| 193 | 193 | $item_meta[] = array( |
| 194 | 194 | 'key' => $formatted_meta->key, |
| 195 | 195 | 'label' => $formatted_meta->display_key, |
| 196 | - 'value' => wc_clean( $formatted_meta->display_value ), |
|
| 196 | + 'value' => wc_clean($formatted_meta->display_value), |
|
| 197 | 197 | ); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -203,71 +203,71 @@ discard block |
||
| 203 | 203 | 'sku' => $product_sku, |
| 204 | 204 | 'product_id' => (int) $product_id, |
| 205 | 205 | 'variation_id' => (int) $variation_id, |
| 206 | - 'quantity' => wc_stock_amount( $item['qty'] ), |
|
| 207 | - 'tax_class' => ! empty( $item['tax_class'] ) ? $item['tax_class'] : '', |
|
| 208 | - 'price' => wc_format_decimal( $order->get_item_total( $item, false, false ), $dp ), |
|
| 209 | - 'subtotal' => wc_format_decimal( $order->get_line_subtotal( $item, false, false ), $dp ), |
|
| 210 | - 'subtotal_tax' => wc_format_decimal( $item['line_subtotal_tax'], $dp ), |
|
| 211 | - 'total' => wc_format_decimal( $order->get_line_total( $item, false, false ), $dp ), |
|
| 212 | - 'total_tax' => wc_format_decimal( $item['line_tax'], $dp ), |
|
| 206 | + 'quantity' => wc_stock_amount($item['qty']), |
|
| 207 | + 'tax_class' => ! empty($item['tax_class']) ? $item['tax_class'] : '', |
|
| 208 | + 'price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), |
|
| 209 | + 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $dp), |
|
| 210 | + 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), |
|
| 211 | + 'total' => wc_format_decimal($order->get_line_total($item, false, false), $dp), |
|
| 212 | + 'total_tax' => wc_format_decimal($item['line_tax'], $dp), |
|
| 213 | 213 | 'taxes' => array(), |
| 214 | 214 | 'meta' => $item_meta, |
| 215 | 215 | ); |
| 216 | 216 | |
| 217 | - $item_line_taxes = maybe_unserialize( $item['line_tax_data'] ); |
|
| 218 | - if ( isset( $item_line_taxes['total'] ) ) { |
|
| 217 | + $item_line_taxes = maybe_unserialize($item['line_tax_data']); |
|
| 218 | + if (isset($item_line_taxes['total'])) { |
|
| 219 | 219 | $line_tax = array(); |
| 220 | 220 | |
| 221 | - foreach ( $item_line_taxes['total'] as $tax_rate_id => $tax ) { |
|
| 222 | - $line_tax[ $tax_rate_id ] = array( |
|
| 221 | + foreach ($item_line_taxes['total'] as $tax_rate_id => $tax) { |
|
| 222 | + $line_tax[$tax_rate_id] = array( |
|
| 223 | 223 | 'id' => $tax_rate_id, |
| 224 | 224 | 'total' => $tax, |
| 225 | 225 | 'subtotal' => '', |
| 226 | 226 | ); |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - foreach ( $item_line_taxes['subtotal'] as $tax_rate_id => $tax ) { |
|
| 230 | - $line_tax[ $tax_rate_id ]['subtotal'] = $tax; |
|
| 229 | + foreach ($item_line_taxes['subtotal'] as $tax_rate_id => $tax) { |
|
| 230 | + $line_tax[$tax_rate_id]['subtotal'] = $tax; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - $line_item['taxes'] = array_values( $line_tax ); |
|
| 233 | + $line_item['taxes'] = array_values($line_tax); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | $data['line_items'][] = $line_item; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // Add taxes. |
| 240 | - foreach ( $order->get_items( 'tax' ) as $key => $tax ) { |
|
| 240 | + foreach ($order->get_items('tax') as $key => $tax) { |
|
| 241 | 241 | $tax_line = array( |
| 242 | 242 | 'id' => $key, |
| 243 | 243 | 'rate_code' => $tax['name'], |
| 244 | 244 | 'rate_id' => $tax['rate_id'], |
| 245 | - 'label' => isset( $tax['label'] ) ? $tax['label'] : $tax['name'], |
|
| 245 | + 'label' => isset($tax['label']) ? $tax['label'] : $tax['name'], |
|
| 246 | 246 | 'compound' => (bool) $tax['compound'], |
| 247 | - 'tax_total' => wc_format_decimal( $tax['tax_amount'], $dp ), |
|
| 248 | - 'shipping_tax_total' => wc_format_decimal( $tax['shipping_tax_amount'], $dp ), |
|
| 247 | + 'tax_total' => wc_format_decimal($tax['tax_amount'], $dp), |
|
| 248 | + 'shipping_tax_total' => wc_format_decimal($tax['shipping_tax_amount'], $dp), |
|
| 249 | 249 | ); |
| 250 | 250 | |
| 251 | 251 | $data['tax_lines'][] = $tax_line; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | // Add shipping. |
| 255 | - foreach ( $order->get_shipping_methods() as $shipping_item_id => $shipping_item ) { |
|
| 255 | + foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) { |
|
| 256 | 256 | $shipping_line = array( |
| 257 | 257 | 'id' => $shipping_item_id, |
| 258 | 258 | 'method_title' => $shipping_item['name'], |
| 259 | 259 | 'method_id' => $shipping_item['method_id'], |
| 260 | - 'total' => wc_format_decimal( $shipping_item['cost'], $dp ), |
|
| 261 | - 'total_tax' => wc_format_decimal( '', $dp ), |
|
| 260 | + 'total' => wc_format_decimal($shipping_item['cost'], $dp), |
|
| 261 | + 'total_tax' => wc_format_decimal('', $dp), |
|
| 262 | 262 | 'taxes' => array(), |
| 263 | 263 | ); |
| 264 | 264 | |
| 265 | 265 | $shipping_taxes = $shipping_item->get_taxes(); |
| 266 | 266 | |
| 267 | - if ( ! empty( $shipping_taxes['total'] ) ) { |
|
| 268 | - $shipping_line['total_tax'] = wc_format_decimal( array_sum( $shipping_taxes['total'] ), $dp ); |
|
| 267 | + if ( ! empty($shipping_taxes['total'])) { |
|
| 268 | + $shipping_line['total_tax'] = wc_format_decimal(array_sum($shipping_taxes['total']), $dp); |
|
| 269 | 269 | |
| 270 | - foreach ( $shipping_taxes['total'] as $tax_rate_id => $tax ) { |
|
| 270 | + foreach ($shipping_taxes['total'] as $tax_rate_id => $tax) { |
|
| 271 | 271 | $shipping_line['taxes'][] = array( |
| 272 | 272 | 'id' => $tax_rate_id, |
| 273 | 273 | 'total' => $tax, |
@@ -279,70 +279,70 @@ discard block |
||
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // Add fees. |
| 282 | - foreach ( $order->get_fees() as $fee_item_id => $fee_item ) { |
|
| 282 | + foreach ($order->get_fees() as $fee_item_id => $fee_item) { |
|
| 283 | 283 | $fee_line = array( |
| 284 | 284 | 'id' => $fee_item_id, |
| 285 | 285 | 'name' => $fee_item['name'], |
| 286 | - 'tax_class' => ! empty( $fee_item['tax_class'] ) ? $fee_item['tax_class'] : '', |
|
| 286 | + 'tax_class' => ! empty($fee_item['tax_class']) ? $fee_item['tax_class'] : '', |
|
| 287 | 287 | 'tax_status' => 'taxable', |
| 288 | - 'total' => wc_format_decimal( $order->get_line_total( $fee_item ), $dp ), |
|
| 289 | - 'total_tax' => wc_format_decimal( $order->get_line_tax( $fee_item ), $dp ), |
|
| 288 | + 'total' => wc_format_decimal($order->get_line_total($fee_item), $dp), |
|
| 289 | + 'total_tax' => wc_format_decimal($order->get_line_tax($fee_item), $dp), |
|
| 290 | 290 | 'taxes' => array(), |
| 291 | 291 | ); |
| 292 | 292 | |
| 293 | - $fee_line_taxes = maybe_unserialize( $fee_item['line_tax_data'] ); |
|
| 294 | - if ( isset( $fee_line_taxes['total'] ) ) { |
|
| 293 | + $fee_line_taxes = maybe_unserialize($fee_item['line_tax_data']); |
|
| 294 | + if (isset($fee_line_taxes['total'])) { |
|
| 295 | 295 | $fee_tax = array(); |
| 296 | 296 | |
| 297 | - foreach ( $fee_line_taxes['total'] as $tax_rate_id => $tax ) { |
|
| 298 | - $fee_tax[ $tax_rate_id ] = array( |
|
| 297 | + foreach ($fee_line_taxes['total'] as $tax_rate_id => $tax) { |
|
| 298 | + $fee_tax[$tax_rate_id] = array( |
|
| 299 | 299 | 'id' => $tax_rate_id, |
| 300 | 300 | 'total' => $tax, |
| 301 | 301 | 'subtotal' => '', |
| 302 | 302 | ); |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - if ( isset( $fee_line_taxes['subtotal'] ) ) { |
|
| 306 | - foreach ( $fee_line_taxes['subtotal'] as $tax_rate_id => $tax ) { |
|
| 307 | - $fee_tax[ $tax_rate_id ]['subtotal'] = $tax; |
|
| 305 | + if (isset($fee_line_taxes['subtotal'])) { |
|
| 306 | + foreach ($fee_line_taxes['subtotal'] as $tax_rate_id => $tax) { |
|
| 307 | + $fee_tax[$tax_rate_id]['subtotal'] = $tax; |
|
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - $fee_line['taxes'] = array_values( $fee_tax ); |
|
| 311 | + $fee_line['taxes'] = array_values($fee_tax); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | $data['fee_lines'][] = $fee_line; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | // Add coupons. |
| 318 | - foreach ( $order->get_items( 'coupon' ) as $coupon_item_id => $coupon_item ) { |
|
| 318 | + foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) { |
|
| 319 | 319 | $coupon_line = array( |
| 320 | 320 | 'id' => $coupon_item_id, |
| 321 | 321 | 'code' => $coupon_item['name'], |
| 322 | - 'discount' => wc_format_decimal( $coupon_item['discount_amount'], $dp ), |
|
| 323 | - 'discount_tax' => wc_format_decimal( $coupon_item['discount_amount_tax'], $dp ), |
|
| 322 | + 'discount' => wc_format_decimal($coupon_item['discount_amount'], $dp), |
|
| 323 | + 'discount_tax' => wc_format_decimal($coupon_item['discount_amount_tax'], $dp), |
|
| 324 | 324 | ); |
| 325 | 325 | |
| 326 | 326 | $data['coupon_lines'][] = $coupon_line; |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | // Add refunds. |
| 330 | - foreach ( $order->get_refunds() as $refund ) { |
|
| 330 | + foreach ($order->get_refunds() as $refund) { |
|
| 331 | 331 | $data['refunds'][] = array( |
| 332 | 332 | 'id' => $refund->get_id(), |
| 333 | 333 | 'refund' => $refund->get_reason() ? $refund->get_reason() : '', |
| 334 | - 'total' => '-' . wc_format_decimal( $refund->get_amount(), $dp ), |
|
| 334 | + 'total' => '-' . wc_format_decimal($refund->get_amount(), $dp), |
|
| 335 | 335 | ); |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 339 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 340 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 338 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 339 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 340 | + $data = $this->filter_response_by_context($data, $context); |
|
| 341 | 341 | |
| 342 | 342 | // Wrap the data in a response object. |
| 343 | - $response = rest_ensure_response( $data ); |
|
| 343 | + $response = rest_ensure_response($data); |
|
| 344 | 344 | |
| 345 | - $response->add_links( $this->prepare_links( $order, $request ) ); |
|
| 345 | + $response->add_links($this->prepare_links($order, $request)); |
|
| 346 | 346 | |
| 347 | 347 | /** |
| 348 | 348 | * Filter the data for a response. |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | * @param WP_Post $post Post object. |
| 355 | 355 | * @param WP_REST_Request $request Request object. |
| 356 | 356 | */ |
| 357 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request ); |
|
| 357 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -364,23 +364,23 @@ discard block |
||
| 364 | 364 | * @param WP_REST_Request $request Request object. |
| 365 | 365 | * @return array Links for the given order. |
| 366 | 366 | */ |
| 367 | - protected function prepare_links( $order, $request ) { |
|
| 367 | + protected function prepare_links($order, $request) { |
|
| 368 | 368 | $links = array( |
| 369 | 369 | 'self' => array( |
| 370 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $order->get_id() ) ), |
|
| 370 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $order->get_id())), |
|
| 371 | 371 | ), |
| 372 | 372 | 'collection' => array( |
| 373 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
| 373 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
| 374 | 374 | ), |
| 375 | 375 | ); |
| 376 | - if ( 0 !== (int) $order->get_user_id() ) { |
|
| 376 | + if (0 !== (int) $order->get_user_id()) { |
|
| 377 | 377 | $links['customer'] = array( |
| 378 | - 'href' => rest_url( sprintf( '/%s/customers/%d', $this->namespace, $order->get_user_id() ) ), |
|
| 378 | + 'href' => rest_url(sprintf('/%s/customers/%d', $this->namespace, $order->get_user_id())), |
|
| 379 | 379 | ); |
| 380 | 380 | } |
| 381 | - if ( 0 !== (int) $order->get_parent_id() ) { |
|
| 381 | + if (0 !== (int) $order->get_parent_id()) { |
|
| 382 | 382 | $links['up'] = array( |
| 383 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order->get_parent_id() ) ), |
|
| 383 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $order->get_parent_id())), |
|
| 384 | 384 | ); |
| 385 | 385 | } |
| 386 | 386 | return $links; |
@@ -393,18 +393,18 @@ discard block |
||
| 393 | 393 | * @param WP_REST_Request $request |
| 394 | 394 | * @return array |
| 395 | 395 | */ |
| 396 | - public function query_args( $args, $request ) { |
|
| 396 | + public function query_args($args, $request) { |
|
| 397 | 397 | global $wpdb; |
| 398 | 398 | |
| 399 | 399 | // Set post_status. |
| 400 | - if ( 'any' !== $request['status'] ) { |
|
| 400 | + if ('any' !== $request['status']) { |
|
| 401 | 401 | $args['post_status'] = 'wc-' . $request['status']; |
| 402 | 402 | } else { |
| 403 | 403 | $args['post_status'] = 'any'; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - if ( isset( $request['customer'] ) ) { |
|
| 407 | - if ( ! empty( $args['meta_query'] ) ) { |
|
| 406 | + if (isset($request['customer'])) { |
|
| 407 | + if ( ! empty($args['meta_query'])) { |
|
| 408 | 408 | $args['meta_query'] = array(); |
| 409 | 409 | } |
| 410 | 410 | |
@@ -416,27 +416,27 @@ discard block |
||
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | // Search by product. |
| 419 | - if ( ! empty( $request['product'] ) ) { |
|
| 420 | - $order_ids = $wpdb->get_col( $wpdb->prepare( " |
|
| 419 | + if ( ! empty($request['product'])) { |
|
| 420 | + $order_ids = $wpdb->get_col($wpdb->prepare(" |
|
| 421 | 421 | SELECT order_id |
| 422 | 422 | FROM {$wpdb->prefix}woocommerce_order_items |
| 423 | 423 | WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE meta_key = '_product_id' AND meta_value = %d ) |
| 424 | 424 | AND order_item_type = 'line_item' |
| 425 | - ", $request['product'] ) ); |
|
| 425 | + ", $request['product'])); |
|
| 426 | 426 | |
| 427 | 427 | // Force WP_Query return empty if don't found any order. |
| 428 | - $order_ids = ! empty( $order_ids ) ? $order_ids : array( 0 ); |
|
| 428 | + $order_ids = ! empty($order_ids) ? $order_ids : array(0); |
|
| 429 | 429 | |
| 430 | 430 | $args['post__in'] = $order_ids; |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | // Search. |
| 434 | - if ( ! empty( $args['s'] ) ) { |
|
| 435 | - $order_ids = wc_order_search( $args['s'] ); |
|
| 434 | + if ( ! empty($args['s'])) { |
|
| 435 | + $order_ids = wc_order_search($args['s']); |
|
| 436 | 436 | |
| 437 | - if ( ! empty( $order_ids ) ) { |
|
| 438 | - unset( $args['s'] ); |
|
| 439 | - $args['post__in'] = array_merge( $order_ids, array( 0 ) ); |
|
| 437 | + if ( ! empty($order_ids)) { |
|
| 438 | + unset($args['s']); |
|
| 439 | + $args['post__in'] = array_merge($order_ids, array(0)); |
|
| 440 | 440 | } |
| 441 | 441 | } |
| 442 | 442 | |
@@ -449,41 +449,41 @@ discard block |
||
| 449 | 449 | * @param WP_REST_Request $request Request object. |
| 450 | 450 | * @return WP_Error|WC_Order $data Object. |
| 451 | 451 | */ |
| 452 | - protected function prepare_item_for_database( $request ) { |
|
| 453 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
| 454 | - $order = new WC_Order( $id ); |
|
| 452 | + protected function prepare_item_for_database($request) { |
|
| 453 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
| 454 | + $order = new WC_Order($id); |
|
| 455 | 455 | $schema = $this->get_item_schema(); |
| 456 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
| 456 | + $data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props'))); |
|
| 457 | 457 | |
| 458 | 458 | // Handle all writable props |
| 459 | - foreach ( $data_keys as $key ) { |
|
| 460 | - $value = $request[ $key ]; |
|
| 459 | + foreach ($data_keys as $key) { |
|
| 460 | + $value = $request[$key]; |
|
| 461 | 461 | |
| 462 | - if ( ! is_null( $value ) ) { |
|
| 463 | - switch ( $key ) { |
|
| 462 | + if ( ! is_null($value)) { |
|
| 463 | + switch ($key) { |
|
| 464 | 464 | case 'billing' : |
| 465 | 465 | case 'shipping' : |
| 466 | - $this->update_address( $order, $value, $key ); |
|
| 466 | + $this->update_address($order, $value, $key); |
|
| 467 | 467 | break; |
| 468 | 468 | case 'line_items' : |
| 469 | 469 | case 'shipping_lines' : |
| 470 | 470 | case 'fee_lines' : |
| 471 | 471 | case 'coupon_lines' : |
| 472 | - if ( is_array( $value ) ) { |
|
| 473 | - foreach ( $value as $item ) { |
|
| 474 | - if ( is_array( $item ) ) { |
|
| 475 | - if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) { |
|
| 476 | - $order->remove_item( $item['id'] ); |
|
| 472 | + if (is_array($value)) { |
|
| 473 | + foreach ($value as $item) { |
|
| 474 | + if (is_array($item)) { |
|
| 475 | + if ($this->item_is_null($item) || (isset($item['quantity']) && 0 === $item['quantity'])) { |
|
| 476 | + $order->remove_item($item['id']); |
|
| 477 | 477 | } else { |
| 478 | - $this->set_item( $order, $key, $item ); |
|
| 478 | + $this->set_item($order, $key, $item); |
|
| 479 | 479 | } |
| 480 | 480 | } |
| 481 | 481 | } |
| 482 | 482 | } |
| 483 | 483 | break; |
| 484 | 484 | default : |
| 485 | - if ( is_callable( array( $order, "set_{$key}" ) ) ) { |
|
| 486 | - $order->{"set_{$key}"}( $value ); |
|
| 485 | + if (is_callable(array($order, "set_{$key}"))) { |
|
| 486 | + $order->{"set_{$key}"}($value); |
|
| 487 | 487 | } |
| 488 | 488 | break; |
| 489 | 489 | } |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | * @param WC_Order $order The order object. |
| 500 | 500 | * @param WP_REST_Request $request Request object. |
| 501 | 501 | */ |
| 502 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}", $order, $request ); |
|
| 502 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $order, $request); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /** |
@@ -508,8 +508,8 @@ discard block |
||
| 508 | 508 | * @param array $data |
| 509 | 509 | * @return WC_Order |
| 510 | 510 | */ |
| 511 | - protected function create_base_order( $data ) { |
|
| 512 | - return wc_create_order( $data ); |
|
| 511 | + protected function create_base_order($data) { |
|
| 512 | + return wc_create_order($data); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -517,8 +517,8 @@ discard block |
||
| 517 | 517 | * @param array $schema |
| 518 | 518 | * @return bool |
| 519 | 519 | */ |
| 520 | - protected function filter_writable_props( $schema ) { |
|
| 521 | - return empty( $schema['readonly'] ); |
|
| 520 | + protected function filter_writable_props($schema) { |
|
| 521 | + return empty($schema['readonly']); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | /** |
@@ -527,34 +527,34 @@ discard block |
||
| 527 | 527 | * @param WP_REST_Request $request Full details about the request. |
| 528 | 528 | * @return int|WP_Error |
| 529 | 529 | */ |
| 530 | - protected function create_order( $request ) { |
|
| 530 | + protected function create_order($request) { |
|
| 531 | 531 | try { |
| 532 | 532 | // Make sure customer exists. |
| 533 | - if ( ! is_null( $request['customer_id'] ) && 0 !== $request['customer_id'] && false === get_user_by( 'id', $request['customer_id'] ) ) { |
|
| 534 | - throw new WC_REST_Exception( 'woocommerce_rest_invalid_customer_id',__( 'Customer ID is invalid.', 'woocommerce' ), 400 ); |
|
| 533 | + if ( ! is_null($request['customer_id']) && 0 !== $request['customer_id'] && false === get_user_by('id', $request['customer_id'])) { |
|
| 534 | + throw new WC_REST_Exception('woocommerce_rest_invalid_customer_id', __('Customer ID is invalid.', 'woocommerce'), 400); |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | // Make sure customer is part of blog. |
| 538 | - if ( is_multisite() && ! is_user_member_of_blog( $request['customer_id'] ) ) { |
|
| 539 | - add_user_to_blog( get_current_blog_id(), $request['customer_id'], 'customer' ); |
|
| 538 | + if (is_multisite() && ! is_user_member_of_blog($request['customer_id'])) { |
|
| 539 | + add_user_to_blog(get_current_blog_id(), $request['customer_id'], 'customer'); |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | - $order = $this->prepare_item_for_database( $request ); |
|
| 543 | - $order->set_created_via( 'rest-api' ); |
|
| 544 | - $order->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) ); |
|
| 542 | + $order = $this->prepare_item_for_database($request); |
|
| 543 | + $order->set_created_via('rest-api'); |
|
| 544 | + $order->set_prices_include_tax('yes' === get_option('woocommerce_prices_include_tax')); |
|
| 545 | 545 | $order->calculate_totals(); |
| 546 | 546 | $order->save(); |
| 547 | 547 | |
| 548 | 548 | // Handle set paid. |
| 549 | - if ( true === $request['set_paid'] ) { |
|
| 550 | - $order->payment_complete( $request['transaction_id'] ); |
|
| 549 | + if (true === $request['set_paid']) { |
|
| 550 | + $order->payment_complete($request['transaction_id']); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | return $order->get_id(); |
| 554 | - } catch ( WC_Data_Exception $e ) { |
|
| 555 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
|
| 556 | - } catch ( WC_REST_Exception $e ) { |
|
| 557 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
| 554 | + } catch (WC_Data_Exception $e) { |
|
| 555 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData()); |
|
| 556 | + } catch (WC_REST_Exception $e) { |
|
| 557 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
| 558 | 558 | } |
| 559 | 559 | } |
| 560 | 560 | |
@@ -564,26 +564,26 @@ discard block |
||
| 564 | 564 | * @param WP_REST_Request $request Full details about the request. |
| 565 | 565 | * @return int|WP_Error |
| 566 | 566 | */ |
| 567 | - protected function update_order( $request ) { |
|
| 567 | + protected function update_order($request) { |
|
| 568 | 568 | try { |
| 569 | - $order = $this->prepare_item_for_database( $request ); |
|
| 569 | + $order = $this->prepare_item_for_database($request); |
|
| 570 | 570 | $order->save(); |
| 571 | 571 | |
| 572 | 572 | // Handle set paid. |
| 573 | - if ( $order->needs_payment() && true === $request['set_paid'] ) { |
|
| 574 | - $order->payment_complete( $request['transaction_id'] ); |
|
| 573 | + if ($order->needs_payment() && true === $request['set_paid']) { |
|
| 574 | + $order->payment_complete($request['transaction_id']); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | // If items have changed, recalculate order totals. |
| 578 | - if ( isset( $request['billing'] ) || isset( $request['shipping'] ) || isset( $request['line_items'] ) || isset( $request['shipping_lines'] ) || isset( $request['fee_lines'] ) || isset( $request['coupon_lines'] ) ) { |
|
| 579 | - $order->calculate_totals( true ); |
|
| 578 | + if (isset($request['billing']) || isset($request['shipping']) || isset($request['line_items']) || isset($request['shipping_lines']) || isset($request['fee_lines']) || isset($request['coupon_lines'])) { |
|
| 579 | + $order->calculate_totals(true); |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | return $order->get_id(); |
| 583 | - } catch ( WC_Data_Exception $e ) { |
|
| 584 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
|
| 585 | - } catch ( WC_REST_Exception $e ) { |
|
| 586 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
| 583 | + } catch (WC_Data_Exception $e) { |
|
| 584 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData()); |
|
| 585 | + } catch (WC_REST_Exception $e) { |
|
| 586 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
| 587 | 587 | } |
| 588 | 588 | } |
| 589 | 589 | |
@@ -594,10 +594,10 @@ discard block |
||
| 594 | 594 | * @param array $posted |
| 595 | 595 | * @param string $type |
| 596 | 596 | */ |
| 597 | - protected function update_address( $order, $posted, $type = 'billing' ) { |
|
| 598 | - foreach ( $posted as $key => $value ) { |
|
| 599 | - if ( is_callable( array( $order, "set_{$type}_{$key}" ) ) ) { |
|
| 600 | - $order->{"set_{$type}_{$key}"}( $value ); |
|
| 597 | + protected function update_address($order, $posted, $type = 'billing') { |
|
| 598 | + foreach ($posted as $key => $value) { |
|
| 599 | + if (is_callable(array($order, "set_{$type}_{$key}"))) { |
|
| 600 | + $order->{"set_{$type}_{$key}"}($value); |
|
| 601 | 601 | } |
| 602 | 602 | } |
| 603 | 603 | } |
@@ -610,15 +610,15 @@ discard block |
||
| 610 | 610 | * @return int |
| 611 | 611 | * @throws WC_REST_Exception |
| 612 | 612 | */ |
| 613 | - protected function get_product_id( $posted ) { |
|
| 614 | - if ( ! empty( $posted['sku'] ) ) { |
|
| 615 | - $product_id = (int) wc_get_product_id_by_sku( $posted['sku'] ); |
|
| 616 | - } elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) { |
|
| 613 | + protected function get_product_id($posted) { |
|
| 614 | + if ( ! empty($posted['sku'])) { |
|
| 615 | + $product_id = (int) wc_get_product_id_by_sku($posted['sku']); |
|
| 616 | + } elseif ( ! empty($posted['product_id']) && empty($posted['variation_id'])) { |
|
| 617 | 617 | $product_id = (int) $posted['product_id']; |
| 618 | - } elseif ( ! empty( $posted['variation_id'] ) ) { |
|
| 618 | + } elseif ( ! empty($posted['variation_id'])) { |
|
| 619 | 619 | $product_id = (int) $posted['variation_id']; |
| 620 | 620 | } else { |
| 621 | - throw new WC_REST_Exception( 'woocommerce_rest_required_product_reference', __( 'Product ID or SKU is required.', 'woocommerce' ), 400 ); |
|
| 621 | + throw new WC_REST_Exception('woocommerce_rest_required_product_reference', __('Product ID or SKU is required.', 'woocommerce'), 400); |
|
| 622 | 622 | } |
| 623 | 623 | return $product_id; |
| 624 | 624 | } |
@@ -629,9 +629,9 @@ discard block |
||
| 629 | 629 | * @param string $prop |
| 630 | 630 | * @param array $posted Request data. |
| 631 | 631 | */ |
| 632 | - protected function maybe_set_item_prop( $item, $prop, $posted ) { |
|
| 633 | - if ( isset( $posted[ $prop ] ) ) { |
|
| 634 | - $item->{"set_$prop"}( $posted[ $prop ] ); |
|
| 632 | + protected function maybe_set_item_prop($item, $prop, $posted) { |
|
| 633 | + if (isset($posted[$prop])) { |
|
| 634 | + $item->{"set_$prop"}($posted[$prop]); |
|
| 635 | 635 | } |
| 636 | 636 | } |
| 637 | 637 | |
@@ -641,9 +641,9 @@ discard block |
||
| 641 | 641 | * @param string[] $props |
| 642 | 642 | * @param array $posted Request data. |
| 643 | 643 | */ |
| 644 | - protected function maybe_set_item_props( $item, $props, $posted ) { |
|
| 645 | - foreach ( $props as $prop ) { |
|
| 646 | - $this->maybe_set_item_prop( $item, $prop, $posted ); |
|
| 644 | + protected function maybe_set_item_props($item, $props, $posted) { |
|
| 645 | + foreach ($props as $prop) { |
|
| 646 | + $this->maybe_set_item_prop($item, $prop, $posted); |
|
| 647 | 647 | } |
| 648 | 648 | } |
| 649 | 649 | |
@@ -656,22 +656,22 @@ discard block |
||
| 656 | 656 | * @return WC_Order_Item_Product |
| 657 | 657 | * @throws WC_REST_Exception Invalid data, server error. |
| 658 | 658 | */ |
| 659 | - protected function prepare_line_items( $posted, $action = 'create' ) { |
|
| 660 | - $item = new WC_Order_Item_Product( ! empty( $posted['id'] ) ? $posted['id'] : '' ); |
|
| 661 | - $product = wc_get_product( $this->get_product_id( $posted ) ); |
|
| 662 | - |
|
| 663 | - if ( $product !== $item->get_product() ) { |
|
| 664 | - $item->set_product( $product ); |
|
| 665 | - |
|
| 666 | - if ( 'create' === $action ) { |
|
| 667 | - $quantity = isset( $posted['quantity'] ) ? $posted['quantity'] : 1; |
|
| 668 | - $total = wc_get_price_excluding_tax( $product, array( 'qty' => $quantity ) ); |
|
| 669 | - $item->set_total( $total ); |
|
| 670 | - $item->set_subtotal( $total ); |
|
| 659 | + protected function prepare_line_items($posted, $action = 'create') { |
|
| 660 | + $item = new WC_Order_Item_Product( ! empty($posted['id']) ? $posted['id'] : ''); |
|
| 661 | + $product = wc_get_product($this->get_product_id($posted)); |
|
| 662 | + |
|
| 663 | + if ($product !== $item->get_product()) { |
|
| 664 | + $item->set_product($product); |
|
| 665 | + |
|
| 666 | + if ('create' === $action) { |
|
| 667 | + $quantity = isset($posted['quantity']) ? $posted['quantity'] : 1; |
|
| 668 | + $total = wc_get_price_excluding_tax($product, array('qty' => $quantity)); |
|
| 669 | + $item->set_total($total); |
|
| 670 | + $item->set_subtotal($total); |
|
| 671 | 671 | } |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | - $this->maybe_set_item_props( $item, array( 'name', 'quantity', 'total', 'subtotal', 'tax_class' ), $posted ); |
|
| 674 | + $this->maybe_set_item_props($item, array('name', 'quantity', 'total', 'subtotal', 'tax_class'), $posted); |
|
| 675 | 675 | |
| 676 | 676 | return $item; |
| 677 | 677 | } |
@@ -685,16 +685,16 @@ discard block |
||
| 685 | 685 | * @return WC_Order_Item_Shipping |
| 686 | 686 | * @throws WC_REST_Exception Invalid data, server error. |
| 687 | 687 | */ |
| 688 | - protected function prepare_shipping_lines( $posted, $action ) { |
|
| 689 | - $item = new WC_Order_Item_Shipping( ! empty( $posted['id'] ) ? $posted['id'] : '' ); |
|
| 688 | + protected function prepare_shipping_lines($posted, $action) { |
|
| 689 | + $item = new WC_Order_Item_Shipping( ! empty($posted['id']) ? $posted['id'] : ''); |
|
| 690 | 690 | |
| 691 | - if ( 'create' === $action ) { |
|
| 692 | - if ( empty( $posted['method_id'] ) ) { |
|
| 693 | - throw new WC_REST_Exception( 'woocommerce_rest_invalid_shipping_item', __( 'Shipping method ID is required.', 'woocommerce' ), 400 ); |
|
| 691 | + if ('create' === $action) { |
|
| 692 | + if (empty($posted['method_id'])) { |
|
| 693 | + throw new WC_REST_Exception('woocommerce_rest_invalid_shipping_item', __('Shipping method ID is required.', 'woocommerce'), 400); |
|
| 694 | 694 | } |
| 695 | 695 | } |
| 696 | 696 | |
| 697 | - $this->maybe_set_item_props( $item, array( 'method_id', 'method_title', 'total' ), $posted ); |
|
| 697 | + $this->maybe_set_item_props($item, array('method_id', 'method_title', 'total'), $posted); |
|
| 698 | 698 | |
| 699 | 699 | return $item; |
| 700 | 700 | } |
@@ -708,16 +708,16 @@ discard block |
||
| 708 | 708 | * @return WC_Order_Item_Fee |
| 709 | 709 | * @throws WC_REST_Exception Invalid data, server error. |
| 710 | 710 | */ |
| 711 | - protected function prepare_fee_lines( $posted, $action ) { |
|
| 712 | - $item = new WC_Order_Item_Fee( ! empty( $posted['id'] ) ? $posted['id'] : '' ); |
|
| 711 | + protected function prepare_fee_lines($posted, $action) { |
|
| 712 | + $item = new WC_Order_Item_Fee( ! empty($posted['id']) ? $posted['id'] : ''); |
|
| 713 | 713 | |
| 714 | - if ( 'create' === $action ) { |
|
| 715 | - if ( empty( $posted['name'] ) ) { |
|
| 716 | - throw new WC_REST_Exception( 'woocommerce_rest_invalid_fee_item', __( 'Fee name is required.', 'woocommerce' ), 400 ); |
|
| 714 | + if ('create' === $action) { |
|
| 715 | + if (empty($posted['name'])) { |
|
| 716 | + throw new WC_REST_Exception('woocommerce_rest_invalid_fee_item', __('Fee name is required.', 'woocommerce'), 400); |
|
| 717 | 717 | } |
| 718 | 718 | } |
| 719 | 719 | |
| 720 | - $this->maybe_set_item_props( $item, array( 'name', 'tax_class', 'tax_status', 'total' ), $posted ); |
|
| 720 | + $this->maybe_set_item_props($item, array('name', 'tax_class', 'tax_status', 'total'), $posted); |
|
| 721 | 721 | |
| 722 | 722 | return $item; |
| 723 | 723 | } |
@@ -731,16 +731,16 @@ discard block |
||
| 731 | 731 | * @return WC_Order_Item_Coupon |
| 732 | 732 | * @throws WC_REST_Exception Invalid data, server error. |
| 733 | 733 | */ |
| 734 | - protected function prepare_coupon_lines( $posted, $action ) { |
|
| 735 | - $item = new WC_Order_Item_Coupon( ! empty( $posted['id'] ) ? $posted['id'] : '' ); |
|
| 734 | + protected function prepare_coupon_lines($posted, $action) { |
|
| 735 | + $item = new WC_Order_Item_Coupon( ! empty($posted['id']) ? $posted['id'] : ''); |
|
| 736 | 736 | |
| 737 | - if ( 'create' === $action ) { |
|
| 738 | - if ( empty( $posted['code'] ) ) { |
|
| 739 | - throw new WC_REST_Exception( 'woocommerce_rest_invalid_coupon_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 ); |
|
| 737 | + if ('create' === $action) { |
|
| 738 | + if (empty($posted['code'])) { |
|
| 739 | + throw new WC_REST_Exception('woocommerce_rest_invalid_coupon_coupon', __('Coupon code is required.', 'woocommerce'), 400); |
|
| 740 | 740 | } |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | - $this->maybe_set_item_props( $item, array( 'code', 'discount' ), $posted ); |
|
| 743 | + $this->maybe_set_item_props($item, array('code', 'discount'), $posted); |
|
| 744 | 744 | |
| 745 | 745 | return $item; |
| 746 | 746 | } |
@@ -755,10 +755,10 @@ discard block |
||
| 755 | 755 | * @param array $posted item provided in the request body |
| 756 | 756 | * @throws WC_REST_Exception If item ID is not associated with order |
| 757 | 757 | */ |
| 758 | - protected function set_item( $order, $item_type, $posted ) { |
|
| 758 | + protected function set_item($order, $item_type, $posted) { |
|
| 759 | 759 | global $wpdb; |
| 760 | 760 | |
| 761 | - if ( ! empty( $posted['id'] ) ) { |
|
| 761 | + if ( ! empty($posted['id'])) { |
|
| 762 | 762 | $action = 'update'; |
| 763 | 763 | } else { |
| 764 | 764 | $action = 'create'; |
@@ -767,29 +767,29 @@ discard block |
||
| 767 | 767 | $method = 'prepare_' . $item_type; |
| 768 | 768 | |
| 769 | 769 | // Verify provided line item ID is associated with order. |
| 770 | - if ( 'update' === $action ) { |
|
| 770 | + if ('update' === $action) { |
|
| 771 | 771 | $result = $wpdb->get_row( |
| 772 | - $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d", |
|
| 773 | - absint( $posted['id'] ), |
|
| 774 | - absint( $order->get_id() ) |
|
| 772 | + $wpdb->prepare("SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d", |
|
| 773 | + absint($posted['id']), |
|
| 774 | + absint($order->get_id()) |
|
| 775 | 775 | ) ); |
| 776 | - if ( is_null( $result ) ) { |
|
| 777 | - throw new WC_REST_Exception( 'woocommerce_rest_invalid_item_id', __( 'Order item ID provided is not associated with order.', 'woocommerce' ), 400 ); |
|
| 776 | + if (is_null($result)) { |
|
| 777 | + throw new WC_REST_Exception('woocommerce_rest_invalid_item_id', __('Order item ID provided is not associated with order.', 'woocommerce'), 400); |
|
| 778 | 778 | } |
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | // Prepare item data |
| 782 | - $item = $this->$method( $posted, $action ); |
|
| 782 | + $item = $this->$method($posted, $action); |
|
| 783 | 783 | |
| 784 | 784 | /** |
| 785 | 785 | * Action hook to adjust item before save. |
| 786 | 786 | * @since 3.0.0 |
| 787 | 787 | */ |
| 788 | - do_action( 'woocommerce_rest_set_order_item', $item, $posted ); |
|
| 788 | + do_action('woocommerce_rest_set_order_item', $item, $posted); |
|
| 789 | 789 | |
| 790 | 790 | // Save or add to order |
| 791 | - if ( 'create' === $action ) { |
|
| 792 | - $order->add_item( $item ); |
|
| 791 | + if ('create' === $action) { |
|
| 792 | + $order->add_item($item); |
|
| 793 | 793 | } else { |
| 794 | 794 | $item->save(); |
| 795 | 795 | } |
@@ -802,11 +802,11 @@ discard block |
||
| 802 | 802 | * @param array $item Item provided in the request body. |
| 803 | 803 | * @return bool True if the item resource ID is null, false otherwise. |
| 804 | 804 | */ |
| 805 | - protected function item_is_null( $item ) { |
|
| 806 | - $keys = array( 'product_id', 'method_id', 'method_title', 'name', 'code' ); |
|
| 805 | + protected function item_is_null($item) { |
|
| 806 | + $keys = array('product_id', 'method_id', 'method_title', 'name', 'code'); |
|
| 807 | 807 | |
| 808 | - foreach ( $keys as $key ) { |
|
| 809 | - if ( array_key_exists( $key, $item ) && is_null( $item[ $key ] ) ) { |
|
| 808 | + foreach ($keys as $key) { |
|
| 809 | + if (array_key_exists($key, $item) && is_null($item[$key])) { |
|
| 810 | 810 | return true; |
| 811 | 811 | } |
| 812 | 812 | } |
@@ -820,19 +820,19 @@ discard block |
||
| 820 | 820 | * @param WP_REST_Request $request Full details about the request. |
| 821 | 821 | * @return WP_Error|WP_REST_Response |
| 822 | 822 | */ |
| 823 | - public function create_item( $request ) { |
|
| 824 | - if ( ! empty( $request['id'] ) ) { |
|
| 823 | + public function create_item($request) { |
|
| 824 | + if ( ! empty($request['id'])) { |
|
| 825 | 825 | /* translators: %s: post type */ |
| 826 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
| 826 | + return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
| 827 | 827 | } |
| 828 | 828 | |
| 829 | - $order_id = $this->create_order( $request ); |
|
| 830 | - if ( is_wp_error( $order_id ) ) { |
|
| 829 | + $order_id = $this->create_order($request); |
|
| 830 | + if (is_wp_error($order_id)) { |
|
| 831 | 831 | return $order_id; |
| 832 | 832 | } |
| 833 | 833 | |
| 834 | - $post = get_post( $order_id ); |
|
| 835 | - $this->update_additional_fields_for_object( $post, $request ); |
|
| 834 | + $post = get_post($order_id); |
|
| 835 | + $this->update_additional_fields_for_object($post, $request); |
|
| 836 | 836 | |
| 837 | 837 | /** |
| 838 | 838 | * Fires after a single item is created or updated via the REST API. |
@@ -841,12 +841,12 @@ discard block |
||
| 841 | 841 | * @param WP_REST_Request $request Request object. |
| 842 | 842 | * @param boolean $creating True when creating item, false when updating. |
| 843 | 843 | */ |
| 844 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, true ); |
|
| 845 | - $request->set_param( 'context', 'edit' ); |
|
| 846 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
| 847 | - $response = rest_ensure_response( $response ); |
|
| 848 | - $response->set_status( 201 ); |
|
| 849 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ) ); |
|
| 844 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, true); |
|
| 845 | + $request->set_param('context', 'edit'); |
|
| 846 | + $response = $this->prepare_item_for_response($post, $request); |
|
| 847 | + $response = rest_ensure_response($response); |
|
| 848 | + $response->set_status(201); |
|
| 849 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID))); |
|
| 850 | 850 | |
| 851 | 851 | return $response; |
| 852 | 852 | } |
@@ -857,21 +857,21 @@ discard block |
||
| 857 | 857 | * @param WP_REST_Request $request Full details about the request. |
| 858 | 858 | * @return WP_Error|WP_REST_Response |
| 859 | 859 | */ |
| 860 | - public function update_item( $request ) { |
|
| 860 | + public function update_item($request) { |
|
| 861 | 861 | try { |
| 862 | 862 | $post_id = (int) $request['id']; |
| 863 | 863 | |
| 864 | - if ( empty( $post_id ) || get_post_type( $post_id ) !== $this->post_type ) { |
|
| 865 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 864 | + if (empty($post_id) || get_post_type($post_id) !== $this->post_type) { |
|
| 865 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400)); |
|
| 866 | 866 | } |
| 867 | 867 | |
| 868 | - $order_id = $this->update_order( $request ); |
|
| 869 | - if ( is_wp_error( $order_id ) ) { |
|
| 868 | + $order_id = $this->update_order($request); |
|
| 869 | + if (is_wp_error($order_id)) { |
|
| 870 | 870 | return $order_id; |
| 871 | 871 | } |
| 872 | 872 | |
| 873 | - $post = get_post( $order_id ); |
|
| 874 | - $this->update_additional_fields_for_object( $post, $request ); |
|
| 873 | + $post = get_post($order_id); |
|
| 874 | + $this->update_additional_fields_for_object($post, $request); |
|
| 875 | 875 | |
| 876 | 876 | /** |
| 877 | 877 | * Fires after a single item is created or updated via the REST API. |
@@ -880,13 +880,13 @@ discard block |
||
| 880 | 880 | * @param WP_REST_Request $request Request object. |
| 881 | 881 | * @param boolean $creating True when creating item, false when updating. |
| 882 | 882 | */ |
| 883 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, false ); |
|
| 884 | - $request->set_param( 'context', 'edit' ); |
|
| 885 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
| 886 | - return rest_ensure_response( $response ); |
|
| 883 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, false); |
|
| 884 | + $request->set_param('context', 'edit'); |
|
| 885 | + $response = $this->prepare_item_for_response($post, $request); |
|
| 886 | + return rest_ensure_response($response); |
|
| 887 | 887 | |
| 888 | - } catch ( Exception $e ) { |
|
| 889 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
| 888 | + } catch (Exception $e) { |
|
| 889 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
| 890 | 890 | } |
| 891 | 891 | } |
| 892 | 892 | |
@@ -897,8 +897,8 @@ discard block |
||
| 897 | 897 | protected function get_order_statuses() { |
| 898 | 898 | $order_statuses = array(); |
| 899 | 899 | |
| 900 | - foreach ( array_keys( wc_get_order_statuses() ) as $status ) { |
|
| 901 | - $order_statuses[] = str_replace( 'wc-', '', $status ); |
|
| 900 | + foreach (array_keys(wc_get_order_statuses()) as $status) { |
|
| 901 | + $order_statuses[] = str_replace('wc-', '', $status); |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | return $order_statuses; |
@@ -916,419 +916,419 @@ discard block |
||
| 916 | 916 | 'type' => 'object', |
| 917 | 917 | 'properties' => array( |
| 918 | 918 | 'id' => array( |
| 919 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 919 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 920 | 920 | 'type' => 'integer', |
| 921 | - 'context' => array( 'view', 'edit' ), |
|
| 921 | + 'context' => array('view', 'edit'), |
|
| 922 | 922 | 'readonly' => true, |
| 923 | 923 | ), |
| 924 | 924 | 'parent_id' => array( |
| 925 | - 'description' => __( 'Parent order ID.', 'woocommerce' ), |
|
| 925 | + 'description' => __('Parent order ID.', 'woocommerce'), |
|
| 926 | 926 | 'type' => 'integer', |
| 927 | - 'context' => array( 'view', 'edit' ), |
|
| 927 | + 'context' => array('view', 'edit'), |
|
| 928 | 928 | ), |
| 929 | 929 | 'status' => array( |
| 930 | - 'description' => __( 'Order status.', 'woocommerce' ), |
|
| 930 | + 'description' => __('Order status.', 'woocommerce'), |
|
| 931 | 931 | 'type' => 'string', |
| 932 | 932 | 'default' => 'pending', |
| 933 | 933 | 'enum' => $this->get_order_statuses(), |
| 934 | - 'context' => array( 'view', 'edit' ), |
|
| 934 | + 'context' => array('view', 'edit'), |
|
| 935 | 935 | ), |
| 936 | 936 | 'order_key' => array( |
| 937 | - 'description' => __( 'Order key.', 'woocommerce' ), |
|
| 937 | + 'description' => __('Order key.', 'woocommerce'), |
|
| 938 | 938 | 'type' => 'string', |
| 939 | - 'context' => array( 'view', 'edit' ), |
|
| 939 | + 'context' => array('view', 'edit'), |
|
| 940 | 940 | 'readonly' => true, |
| 941 | 941 | ), |
| 942 | 942 | 'number' => array( |
| 943 | - 'description' => __( 'Order number.', 'woocommerce' ), |
|
| 943 | + 'description' => __('Order number.', 'woocommerce'), |
|
| 944 | 944 | 'type' => 'string', |
| 945 | - 'context' => array( 'view', 'edit' ), |
|
| 945 | + 'context' => array('view', 'edit'), |
|
| 946 | 946 | 'readonly' => true, |
| 947 | 947 | ), |
| 948 | 948 | 'currency' => array( |
| 949 | - 'description' => __( 'Currency the order was created with, in ISO format.', 'woocommerce' ), |
|
| 949 | + 'description' => __('Currency the order was created with, in ISO format.', 'woocommerce'), |
|
| 950 | 950 | 'type' => 'string', |
| 951 | 951 | 'default' => get_woocommerce_currency(), |
| 952 | - 'enum' => array_keys( get_woocommerce_currencies() ), |
|
| 953 | - 'context' => array( 'view', 'edit' ), |
|
| 952 | + 'enum' => array_keys(get_woocommerce_currencies()), |
|
| 953 | + 'context' => array('view', 'edit'), |
|
| 954 | 954 | ), |
| 955 | 955 | 'version' => array( |
| 956 | - 'description' => __( 'Version of WooCommerce which last updated the order.', 'woocommerce' ), |
|
| 956 | + 'description' => __('Version of WooCommerce which last updated the order.', 'woocommerce'), |
|
| 957 | 957 | 'type' => 'integer', |
| 958 | - 'context' => array( 'view', 'edit' ), |
|
| 958 | + 'context' => array('view', 'edit'), |
|
| 959 | 959 | 'readonly' => true, |
| 960 | 960 | ), |
| 961 | 961 | 'prices_include_tax' => array( |
| 962 | - 'description' => __( 'True the prices included tax during checkout.', 'woocommerce' ), |
|
| 962 | + 'description' => __('True the prices included tax during checkout.', 'woocommerce'), |
|
| 963 | 963 | 'type' => 'boolean', |
| 964 | - 'context' => array( 'view', 'edit' ), |
|
| 964 | + 'context' => array('view', 'edit'), |
|
| 965 | 965 | 'readonly' => true, |
| 966 | 966 | ), |
| 967 | 967 | 'date_created' => array( |
| 968 | - 'description' => __( "The date the order was created, as GMT.", 'woocommerce' ), |
|
| 968 | + 'description' => __("The date the order was created, as GMT.", 'woocommerce'), |
|
| 969 | 969 | 'type' => 'date-time', |
| 970 | - 'context' => array( 'view', 'edit' ), |
|
| 970 | + 'context' => array('view', 'edit'), |
|
| 971 | 971 | 'readonly' => true, |
| 972 | 972 | ), |
| 973 | 973 | 'date_modified' => array( |
| 974 | - 'description' => __( "The date the order was last modified, as GMT.", 'woocommerce' ), |
|
| 974 | + 'description' => __("The date the order was last modified, as GMT.", 'woocommerce'), |
|
| 975 | 975 | 'type' => 'date-time', |
| 976 | - 'context' => array( 'view', 'edit' ), |
|
| 976 | + 'context' => array('view', 'edit'), |
|
| 977 | 977 | 'readonly' => true, |
| 978 | 978 | ), |
| 979 | 979 | 'customer_id' => array( |
| 980 | - 'description' => __( 'User ID who owns the order. 0 for guests.', 'woocommerce' ), |
|
| 980 | + 'description' => __('User ID who owns the order. 0 for guests.', 'woocommerce'), |
|
| 981 | 981 | 'type' => 'integer', |
| 982 | 982 | 'default' => 0, |
| 983 | - 'context' => array( 'view', 'edit' ), |
|
| 983 | + 'context' => array('view', 'edit'), |
|
| 984 | 984 | ), |
| 985 | 985 | 'discount_total' => array( |
| 986 | - 'description' => __( 'Total discount amount for the order.', 'woocommerce' ), |
|
| 986 | + 'description' => __('Total discount amount for the order.', 'woocommerce'), |
|
| 987 | 987 | 'type' => 'string', |
| 988 | - 'context' => array( 'view', 'edit' ), |
|
| 988 | + 'context' => array('view', 'edit'), |
|
| 989 | 989 | 'readonly' => true, |
| 990 | 990 | ), |
| 991 | 991 | 'discount_tax' => array( |
| 992 | - 'description' => __( 'Total discount tax amount for the order.', 'woocommerce' ), |
|
| 992 | + 'description' => __('Total discount tax amount for the order.', 'woocommerce'), |
|
| 993 | 993 | 'type' => 'string', |
| 994 | - 'context' => array( 'view', 'edit' ), |
|
| 994 | + 'context' => array('view', 'edit'), |
|
| 995 | 995 | 'readonly' => true, |
| 996 | 996 | ), |
| 997 | 997 | 'shipping_total' => array( |
| 998 | - 'description' => __( 'Total shipping amount for the order.', 'woocommerce' ), |
|
| 998 | + 'description' => __('Total shipping amount for the order.', 'woocommerce'), |
|
| 999 | 999 | 'type' => 'string', |
| 1000 | - 'context' => array( 'view', 'edit' ), |
|
| 1000 | + 'context' => array('view', 'edit'), |
|
| 1001 | 1001 | 'readonly' => true, |
| 1002 | 1002 | ), |
| 1003 | 1003 | 'shipping_tax' => array( |
| 1004 | - 'description' => __( 'Total shipping tax amount for the order.', 'woocommerce' ), |
|
| 1004 | + 'description' => __('Total shipping tax amount for the order.', 'woocommerce'), |
|
| 1005 | 1005 | 'type' => 'string', |
| 1006 | - 'context' => array( 'view', 'edit' ), |
|
| 1006 | + 'context' => array('view', 'edit'), |
|
| 1007 | 1007 | 'readonly' => true, |
| 1008 | 1008 | ), |
| 1009 | 1009 | 'cart_tax' => array( |
| 1010 | - 'description' => __( 'Sum of line item taxes only.', 'woocommerce' ), |
|
| 1010 | + 'description' => __('Sum of line item taxes only.', 'woocommerce'), |
|
| 1011 | 1011 | 'type' => 'string', |
| 1012 | - 'context' => array( 'view', 'edit' ), |
|
| 1012 | + 'context' => array('view', 'edit'), |
|
| 1013 | 1013 | 'readonly' => true, |
| 1014 | 1014 | ), |
| 1015 | 1015 | 'total' => array( |
| 1016 | - 'description' => __( 'Grand total.', 'woocommerce' ), |
|
| 1016 | + 'description' => __('Grand total.', 'woocommerce'), |
|
| 1017 | 1017 | 'type' => 'string', |
| 1018 | - 'context' => array( 'view', 'edit' ), |
|
| 1018 | + 'context' => array('view', 'edit'), |
|
| 1019 | 1019 | 'readonly' => true, |
| 1020 | 1020 | ), |
| 1021 | 1021 | 'total_tax' => array( |
| 1022 | - 'description' => __( 'Sum of all taxes.', 'woocommerce' ), |
|
| 1022 | + 'description' => __('Sum of all taxes.', 'woocommerce'), |
|
| 1023 | 1023 | 'type' => 'string', |
| 1024 | - 'context' => array( 'view', 'edit' ), |
|
| 1024 | + 'context' => array('view', 'edit'), |
|
| 1025 | 1025 | 'readonly' => true, |
| 1026 | 1026 | ), |
| 1027 | 1027 | 'billing' => array( |
| 1028 | - 'description' => __( 'Billing address.', 'woocommerce' ), |
|
| 1028 | + 'description' => __('Billing address.', 'woocommerce'), |
|
| 1029 | 1029 | 'type' => 'object', |
| 1030 | - 'context' => array( 'view', 'edit' ), |
|
| 1030 | + 'context' => array('view', 'edit'), |
|
| 1031 | 1031 | 'properties' => array( |
| 1032 | 1032 | 'first_name' => array( |
| 1033 | - 'description' => __( 'First name.', 'woocommerce' ), |
|
| 1033 | + 'description' => __('First name.', 'woocommerce'), |
|
| 1034 | 1034 | 'type' => 'string', |
| 1035 | - 'context' => array( 'view', 'edit' ), |
|
| 1035 | + 'context' => array('view', 'edit'), |
|
| 1036 | 1036 | ), |
| 1037 | 1037 | 'last_name' => array( |
| 1038 | - 'description' => __( 'Last name.', 'woocommerce' ), |
|
| 1038 | + 'description' => __('Last name.', 'woocommerce'), |
|
| 1039 | 1039 | 'type' => 'string', |
| 1040 | - 'context' => array( 'view', 'edit' ), |
|
| 1040 | + 'context' => array('view', 'edit'), |
|
| 1041 | 1041 | ), |
| 1042 | 1042 | 'company' => array( |
| 1043 | - 'description' => __( 'Company name.', 'woocommerce' ), |
|
| 1043 | + 'description' => __('Company name.', 'woocommerce'), |
|
| 1044 | 1044 | 'type' => 'string', |
| 1045 | - 'context' => array( 'view', 'edit' ), |
|
| 1045 | + 'context' => array('view', 'edit'), |
|
| 1046 | 1046 | ), |
| 1047 | 1047 | 'address_1' => array( |
| 1048 | - 'description' => __( 'Address line 1.', 'woocommerce' ), |
|
| 1048 | + 'description' => __('Address line 1.', 'woocommerce'), |
|
| 1049 | 1049 | 'type' => 'string', |
| 1050 | - 'context' => array( 'view', 'edit' ), |
|
| 1050 | + 'context' => array('view', 'edit'), |
|
| 1051 | 1051 | ), |
| 1052 | 1052 | 'address_2' => array( |
| 1053 | - 'description' => __( 'Address line 2.', 'woocommerce' ), |
|
| 1053 | + 'description' => __('Address line 2.', 'woocommerce'), |
|
| 1054 | 1054 | 'type' => 'string', |
| 1055 | - 'context' => array( 'view', 'edit' ), |
|
| 1055 | + 'context' => array('view', 'edit'), |
|
| 1056 | 1056 | ), |
| 1057 | 1057 | 'city' => array( |
| 1058 | - 'description' => __( 'City name.', 'woocommerce' ), |
|
| 1058 | + 'description' => __('City name.', 'woocommerce'), |
|
| 1059 | 1059 | 'type' => 'string', |
| 1060 | - 'context' => array( 'view', 'edit' ), |
|
| 1060 | + 'context' => array('view', 'edit'), |
|
| 1061 | 1061 | ), |
| 1062 | 1062 | 'state' => array( |
| 1063 | - 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ), |
|
| 1063 | + 'description' => __('ISO code or name of the state, province or district.', 'woocommerce'), |
|
| 1064 | 1064 | 'type' => 'string', |
| 1065 | - 'context' => array( 'view', 'edit' ), |
|
| 1065 | + 'context' => array('view', 'edit'), |
|
| 1066 | 1066 | ), |
| 1067 | 1067 | 'postcode' => array( |
| 1068 | - 'description' => __( 'Postal code.', 'woocommerce' ), |
|
| 1068 | + 'description' => __('Postal code.', 'woocommerce'), |
|
| 1069 | 1069 | 'type' => 'string', |
| 1070 | - 'context' => array( 'view', 'edit' ), |
|
| 1070 | + 'context' => array('view', 'edit'), |
|
| 1071 | 1071 | ), |
| 1072 | 1072 | 'country' => array( |
| 1073 | - 'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce' ), |
|
| 1073 | + 'description' => __('Country code in ISO 3166-1 alpha-2 format.', 'woocommerce'), |
|
| 1074 | 1074 | 'type' => 'string', |
| 1075 | - 'context' => array( 'view', 'edit' ), |
|
| 1075 | + 'context' => array('view', 'edit'), |
|
| 1076 | 1076 | ), |
| 1077 | 1077 | 'email' => array( |
| 1078 | - 'description' => __( 'Email address.', 'woocommerce' ), |
|
| 1078 | + 'description' => __('Email address.', 'woocommerce'), |
|
| 1079 | 1079 | 'type' => 'string', |
| 1080 | 1080 | 'format' => 'email', |
| 1081 | - 'context' => array( 'view', 'edit' ), |
|
| 1081 | + 'context' => array('view', 'edit'), |
|
| 1082 | 1082 | ), |
| 1083 | 1083 | 'phone' => array( |
| 1084 | - 'description' => __( 'Phone number.', 'woocommerce' ), |
|
| 1084 | + 'description' => __('Phone number.', 'woocommerce'), |
|
| 1085 | 1085 | 'type' => 'string', |
| 1086 | - 'context' => array( 'view', 'edit' ), |
|
| 1086 | + 'context' => array('view', 'edit'), |
|
| 1087 | 1087 | ), |
| 1088 | 1088 | ), |
| 1089 | 1089 | ), |
| 1090 | 1090 | 'shipping' => array( |
| 1091 | - 'description' => __( 'Shipping address.', 'woocommerce' ), |
|
| 1091 | + 'description' => __('Shipping address.', 'woocommerce'), |
|
| 1092 | 1092 | 'type' => 'object', |
| 1093 | - 'context' => array( 'view', 'edit' ), |
|
| 1093 | + 'context' => array('view', 'edit'), |
|
| 1094 | 1094 | 'properties' => array( |
| 1095 | 1095 | 'first_name' => array( |
| 1096 | - 'description' => __( 'First name.', 'woocommerce' ), |
|
| 1096 | + 'description' => __('First name.', 'woocommerce'), |
|
| 1097 | 1097 | 'type' => 'string', |
| 1098 | - 'context' => array( 'view', 'edit' ), |
|
| 1098 | + 'context' => array('view', 'edit'), |
|
| 1099 | 1099 | ), |
| 1100 | 1100 | 'last_name' => array( |
| 1101 | - 'description' => __( 'Last name.', 'woocommerce' ), |
|
| 1101 | + 'description' => __('Last name.', 'woocommerce'), |
|
| 1102 | 1102 | 'type' => 'string', |
| 1103 | - 'context' => array( 'view', 'edit' ), |
|
| 1103 | + 'context' => array('view', 'edit'), |
|
| 1104 | 1104 | ), |
| 1105 | 1105 | 'company' => array( |
| 1106 | - 'description' => __( 'Company name.', 'woocommerce' ), |
|
| 1106 | + 'description' => __('Company name.', 'woocommerce'), |
|
| 1107 | 1107 | 'type' => 'string', |
| 1108 | - 'context' => array( 'view', 'edit' ), |
|
| 1108 | + 'context' => array('view', 'edit'), |
|
| 1109 | 1109 | ), |
| 1110 | 1110 | 'address_1' => array( |
| 1111 | - 'description' => __( 'Address line 1.', 'woocommerce' ), |
|
| 1111 | + 'description' => __('Address line 1.', 'woocommerce'), |
|
| 1112 | 1112 | 'type' => 'string', |
| 1113 | - 'context' => array( 'view', 'edit' ), |
|
| 1113 | + 'context' => array('view', 'edit'), |
|
| 1114 | 1114 | ), |
| 1115 | 1115 | 'address_2' => array( |
| 1116 | - 'description' => __( 'Address line 2.', 'woocommerce' ), |
|
| 1116 | + 'description' => __('Address line 2.', 'woocommerce'), |
|
| 1117 | 1117 | 'type' => 'string', |
| 1118 | - 'context' => array( 'view', 'edit' ), |
|
| 1118 | + 'context' => array('view', 'edit'), |
|
| 1119 | 1119 | ), |
| 1120 | 1120 | 'city' => array( |
| 1121 | - 'description' => __( 'City name.', 'woocommerce' ), |
|
| 1121 | + 'description' => __('City name.', 'woocommerce'), |
|
| 1122 | 1122 | 'type' => 'string', |
| 1123 | - 'context' => array( 'view', 'edit' ), |
|
| 1123 | + 'context' => array('view', 'edit'), |
|
| 1124 | 1124 | ), |
| 1125 | 1125 | 'state' => array( |
| 1126 | - 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ), |
|
| 1126 | + 'description' => __('ISO code or name of the state, province or district.', 'woocommerce'), |
|
| 1127 | 1127 | 'type' => 'string', |
| 1128 | - 'context' => array( 'view', 'edit' ), |
|
| 1128 | + 'context' => array('view', 'edit'), |
|
| 1129 | 1129 | ), |
| 1130 | 1130 | 'postcode' => array( |
| 1131 | - 'description' => __( 'Postal code.', 'woocommerce' ), |
|
| 1131 | + 'description' => __('Postal code.', 'woocommerce'), |
|
| 1132 | 1132 | 'type' => 'string', |
| 1133 | - 'context' => array( 'view', 'edit' ), |
|
| 1133 | + 'context' => array('view', 'edit'), |
|
| 1134 | 1134 | ), |
| 1135 | 1135 | 'country' => array( |
| 1136 | - 'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce' ), |
|
| 1136 | + 'description' => __('Country code in ISO 3166-1 alpha-2 format.', 'woocommerce'), |
|
| 1137 | 1137 | 'type' => 'string', |
| 1138 | - 'context' => array( 'view', 'edit' ), |
|
| 1138 | + 'context' => array('view', 'edit'), |
|
| 1139 | 1139 | ), |
| 1140 | 1140 | ), |
| 1141 | 1141 | ), |
| 1142 | 1142 | 'payment_method' => array( |
| 1143 | - 'description' => __( 'Payment method ID.', 'woocommerce' ), |
|
| 1143 | + 'description' => __('Payment method ID.', 'woocommerce'), |
|
| 1144 | 1144 | 'type' => 'string', |
| 1145 | - 'context' => array( 'view', 'edit' ), |
|
| 1145 | + 'context' => array('view', 'edit'), |
|
| 1146 | 1146 | ), |
| 1147 | 1147 | 'payment_method_title' => array( |
| 1148 | - 'description' => __( 'Payment method title.', 'woocommerce' ), |
|
| 1148 | + 'description' => __('Payment method title.', 'woocommerce'), |
|
| 1149 | 1149 | 'type' => 'string', |
| 1150 | - 'context' => array( 'view', 'edit' ), |
|
| 1150 | + 'context' => array('view', 'edit'), |
|
| 1151 | 1151 | 'arg_options' => array( |
| 1152 | 1152 | 'sanitize_callback' => 'sanitize_text_field', |
| 1153 | 1153 | ), |
| 1154 | 1154 | ), |
| 1155 | 1155 | 'set_paid' => array( |
| 1156 | - 'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce' ), |
|
| 1156 | + 'description' => __('Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce'), |
|
| 1157 | 1157 | 'type' => 'boolean', |
| 1158 | 1158 | 'default' => false, |
| 1159 | - 'context' => array( 'edit' ), |
|
| 1159 | + 'context' => array('edit'), |
|
| 1160 | 1160 | ), |
| 1161 | 1161 | 'transaction_id' => array( |
| 1162 | - 'description' => __( 'Unique transaction ID.', 'woocommerce' ), |
|
| 1162 | + 'description' => __('Unique transaction ID.', 'woocommerce'), |
|
| 1163 | 1163 | 'type' => 'string', |
| 1164 | - 'context' => array( 'view', 'edit' ), |
|
| 1164 | + 'context' => array('view', 'edit'), |
|
| 1165 | 1165 | ), |
| 1166 | 1166 | 'customer_ip_address' => array( |
| 1167 | - 'description' => __( "Customer's IP address.", 'woocommerce' ), |
|
| 1167 | + 'description' => __("Customer's IP address.", 'woocommerce'), |
|
| 1168 | 1168 | 'type' => 'string', |
| 1169 | - 'context' => array( 'view', 'edit' ), |
|
| 1169 | + 'context' => array('view', 'edit'), |
|
| 1170 | 1170 | 'readonly' => true, |
| 1171 | 1171 | ), |
| 1172 | 1172 | 'customer_user_agent' => array( |
| 1173 | - 'description' => __( 'User agent of the customer.', 'woocommerce' ), |
|
| 1173 | + 'description' => __('User agent of the customer.', 'woocommerce'), |
|
| 1174 | 1174 | 'type' => 'string', |
| 1175 | - 'context' => array( 'view', 'edit' ), |
|
| 1175 | + 'context' => array('view', 'edit'), |
|
| 1176 | 1176 | 'readonly' => true, |
| 1177 | 1177 | ), |
| 1178 | 1178 | 'created_via' => array( |
| 1179 | - 'description' => __( 'Shows where the order was created.', 'woocommerce' ), |
|
| 1179 | + 'description' => __('Shows where the order was created.', 'woocommerce'), |
|
| 1180 | 1180 | 'type' => 'string', |
| 1181 | - 'context' => array( 'view', 'edit' ), |
|
| 1181 | + 'context' => array('view', 'edit'), |
|
| 1182 | 1182 | 'readonly' => true, |
| 1183 | 1183 | ), |
| 1184 | 1184 | 'customer_note' => array( |
| 1185 | - 'description' => __( 'Note left by customer during checkout.', 'woocommerce' ), |
|
| 1185 | + 'description' => __('Note left by customer during checkout.', 'woocommerce'), |
|
| 1186 | 1186 | 'type' => 'string', |
| 1187 | - 'context' => array( 'view', 'edit' ), |
|
| 1187 | + 'context' => array('view', 'edit'), |
|
| 1188 | 1188 | ), |
| 1189 | 1189 | 'date_completed' => array( |
| 1190 | - 'description' => __( "The date the order was completed, in the site's timezone.", 'woocommerce' ), |
|
| 1190 | + 'description' => __("The date the order was completed, in the site's timezone.", 'woocommerce'), |
|
| 1191 | 1191 | 'type' => 'date-time', |
| 1192 | - 'context' => array( 'view', 'edit' ), |
|
| 1192 | + 'context' => array('view', 'edit'), |
|
| 1193 | 1193 | 'readonly' => true, |
| 1194 | 1194 | ), |
| 1195 | 1195 | 'date_paid' => array( |
| 1196 | - 'description' => __( "The date the order was paid, in the site's timezone.", 'woocommerce' ), |
|
| 1196 | + 'description' => __("The date the order was paid, in the site's timezone.", 'woocommerce'), |
|
| 1197 | 1197 | 'type' => 'date-time', |
| 1198 | - 'context' => array( 'view', 'edit' ), |
|
| 1198 | + 'context' => array('view', 'edit'), |
|
| 1199 | 1199 | 'readonly' => true, |
| 1200 | 1200 | ), |
| 1201 | 1201 | 'cart_hash' => array( |
| 1202 | - 'description' => __( 'MD5 hash of cart items to ensure orders are not modified.', 'woocommerce' ), |
|
| 1202 | + 'description' => __('MD5 hash of cart items to ensure orders are not modified.', 'woocommerce'), |
|
| 1203 | 1203 | 'type' => 'string', |
| 1204 | - 'context' => array( 'view', 'edit' ), |
|
| 1204 | + 'context' => array('view', 'edit'), |
|
| 1205 | 1205 | 'readonly' => true, |
| 1206 | 1206 | ), |
| 1207 | 1207 | 'line_items' => array( |
| 1208 | - 'description' => __( 'Line items data.', 'woocommerce' ), |
|
| 1208 | + 'description' => __('Line items data.', 'woocommerce'), |
|
| 1209 | 1209 | 'type' => 'array', |
| 1210 | - 'context' => array( 'view', 'edit' ), |
|
| 1210 | + 'context' => array('view', 'edit'), |
|
| 1211 | 1211 | 'items' => array( |
| 1212 | 1212 | 'type' => 'object', |
| 1213 | 1213 | 'properties' => array( |
| 1214 | 1214 | 'id' => array( |
| 1215 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
| 1215 | + 'description' => __('Item ID.', 'woocommerce'), |
|
| 1216 | 1216 | 'type' => 'integer', |
| 1217 | - 'context' => array( 'view', 'edit' ), |
|
| 1217 | + 'context' => array('view', 'edit'), |
|
| 1218 | 1218 | 'readonly' => true, |
| 1219 | 1219 | ), |
| 1220 | 1220 | 'name' => array( |
| 1221 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
| 1221 | + 'description' => __('Product name.', 'woocommerce'), |
|
| 1222 | 1222 | 'type' => 'mixed', |
| 1223 | - 'context' => array( 'view', 'edit' ), |
|
| 1223 | + 'context' => array('view', 'edit'), |
|
| 1224 | 1224 | 'readonly' => true, |
| 1225 | 1225 | ), |
| 1226 | 1226 | 'sku' => array( |
| 1227 | - 'description' => __( 'Product SKU.', 'woocommerce' ), |
|
| 1227 | + 'description' => __('Product SKU.', 'woocommerce'), |
|
| 1228 | 1228 | 'type' => 'string', |
| 1229 | - 'context' => array( 'view', 'edit' ), |
|
| 1229 | + 'context' => array('view', 'edit'), |
|
| 1230 | 1230 | 'readonly' => true, |
| 1231 | 1231 | ), |
| 1232 | 1232 | 'product_id' => array( |
| 1233 | - 'description' => __( 'Product ID.', 'woocommerce' ), |
|
| 1233 | + 'description' => __('Product ID.', 'woocommerce'), |
|
| 1234 | 1234 | 'type' => 'mixed', |
| 1235 | - 'context' => array( 'view', 'edit' ), |
|
| 1235 | + 'context' => array('view', 'edit'), |
|
| 1236 | 1236 | ), |
| 1237 | 1237 | 'variation_id' => array( |
| 1238 | - 'description' => __( 'Variation ID, if applicable.', 'woocommerce' ), |
|
| 1238 | + 'description' => __('Variation ID, if applicable.', 'woocommerce'), |
|
| 1239 | 1239 | 'type' => 'integer', |
| 1240 | - 'context' => array( 'view', 'edit' ), |
|
| 1240 | + 'context' => array('view', 'edit'), |
|
| 1241 | 1241 | ), |
| 1242 | 1242 | 'quantity' => array( |
| 1243 | - 'description' => __( 'Quantity ordered.', 'woocommerce' ), |
|
| 1243 | + 'description' => __('Quantity ordered.', 'woocommerce'), |
|
| 1244 | 1244 | 'type' => 'integer', |
| 1245 | - 'context' => array( 'view', 'edit' ), |
|
| 1245 | + 'context' => array('view', 'edit'), |
|
| 1246 | 1246 | ), |
| 1247 | 1247 | 'tax_class' => array( |
| 1248 | - 'description' => __( 'Tax class of product.', 'woocommerce' ), |
|
| 1248 | + 'description' => __('Tax class of product.', 'woocommerce'), |
|
| 1249 | 1249 | 'type' => 'string', |
| 1250 | - 'context' => array( 'view', 'edit' ), |
|
| 1250 | + 'context' => array('view', 'edit'), |
|
| 1251 | 1251 | 'readonly' => true, |
| 1252 | 1252 | ), |
| 1253 | 1253 | 'price' => array( |
| 1254 | - 'description' => __( 'Product price.', 'woocommerce' ), |
|
| 1254 | + 'description' => __('Product price.', 'woocommerce'), |
|
| 1255 | 1255 | 'type' => 'string', |
| 1256 | - 'context' => array( 'view', 'edit' ), |
|
| 1256 | + 'context' => array('view', 'edit'), |
|
| 1257 | 1257 | 'readonly' => true, |
| 1258 | 1258 | ), |
| 1259 | 1259 | 'subtotal' => array( |
| 1260 | - 'description' => __( 'Line subtotal (before discounts).', 'woocommerce' ), |
|
| 1260 | + 'description' => __('Line subtotal (before discounts).', 'woocommerce'), |
|
| 1261 | 1261 | 'type' => 'string', |
| 1262 | - 'context' => array( 'view', 'edit' ), |
|
| 1262 | + 'context' => array('view', 'edit'), |
|
| 1263 | 1263 | ), |
| 1264 | 1264 | 'subtotal_tax' => array( |
| 1265 | - 'description' => __( 'Line subtotal tax (before discounts).', 'woocommerce' ), |
|
| 1265 | + 'description' => __('Line subtotal tax (before discounts).', 'woocommerce'), |
|
| 1266 | 1266 | 'type' => 'string', |
| 1267 | - 'context' => array( 'view', 'edit' ), |
|
| 1267 | + 'context' => array('view', 'edit'), |
|
| 1268 | 1268 | ), |
| 1269 | 1269 | 'total' => array( |
| 1270 | - 'description' => __( 'Line total (after discounts).', 'woocommerce' ), |
|
| 1270 | + 'description' => __('Line total (after discounts).', 'woocommerce'), |
|
| 1271 | 1271 | 'type' => 'string', |
| 1272 | - 'context' => array( 'view', 'edit' ), |
|
| 1272 | + 'context' => array('view', 'edit'), |
|
| 1273 | 1273 | ), |
| 1274 | 1274 | 'total_tax' => array( |
| 1275 | - 'description' => __( 'Line total tax (after discounts).', 'woocommerce' ), |
|
| 1275 | + 'description' => __('Line total tax (after discounts).', 'woocommerce'), |
|
| 1276 | 1276 | 'type' => 'string', |
| 1277 | - 'context' => array( 'view', 'edit' ), |
|
| 1277 | + 'context' => array('view', 'edit'), |
|
| 1278 | 1278 | ), |
| 1279 | 1279 | 'taxes' => array( |
| 1280 | - 'description' => __( 'Line taxes.', 'woocommerce' ), |
|
| 1280 | + 'description' => __('Line taxes.', 'woocommerce'), |
|
| 1281 | 1281 | 'type' => 'array', |
| 1282 | - 'context' => array( 'view', 'edit' ), |
|
| 1282 | + 'context' => array('view', 'edit'), |
|
| 1283 | 1283 | 'readonly' => true, |
| 1284 | 1284 | 'items' => array( |
| 1285 | 1285 | 'type' => 'object', |
| 1286 | 1286 | 'properties' => array( |
| 1287 | 1287 | 'id' => array( |
| 1288 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
| 1288 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
| 1289 | 1289 | 'type' => 'integer', |
| 1290 | - 'context' => array( 'view', 'edit' ), |
|
| 1290 | + 'context' => array('view', 'edit'), |
|
| 1291 | 1291 | 'readonly' => true, |
| 1292 | 1292 | ), |
| 1293 | 1293 | 'total' => array( |
| 1294 | - 'description' => __( 'Tax total.', 'woocommerce' ), |
|
| 1294 | + 'description' => __('Tax total.', 'woocommerce'), |
|
| 1295 | 1295 | 'type' => 'string', |
| 1296 | - 'context' => array( 'view', 'edit' ), |
|
| 1296 | + 'context' => array('view', 'edit'), |
|
| 1297 | 1297 | 'readonly' => true, |
| 1298 | 1298 | ), |
| 1299 | 1299 | 'subtotal' => array( |
| 1300 | - 'description' => __( 'Tax subtotal.', 'woocommerce' ), |
|
| 1300 | + 'description' => __('Tax subtotal.', 'woocommerce'), |
|
| 1301 | 1301 | 'type' => 'string', |
| 1302 | - 'context' => array( 'view', 'edit' ), |
|
| 1302 | + 'context' => array('view', 'edit'), |
|
| 1303 | 1303 | 'readonly' => true, |
| 1304 | 1304 | ), |
| 1305 | 1305 | ), |
| 1306 | 1306 | ), |
| 1307 | 1307 | ), |
| 1308 | 1308 | 'meta' => array( |
| 1309 | - 'description' => __( 'Line item meta data.', 'woocommerce' ), |
|
| 1309 | + 'description' => __('Line item meta data.', 'woocommerce'), |
|
| 1310 | 1310 | 'type' => 'array', |
| 1311 | - 'context' => array( 'view', 'edit' ), |
|
| 1311 | + 'context' => array('view', 'edit'), |
|
| 1312 | 1312 | 'readonly' => true, |
| 1313 | 1313 | 'items' => array( |
| 1314 | 1314 | 'type' => 'object', |
| 1315 | 1315 | 'properties' => array( |
| 1316 | 1316 | 'key' => array( |
| 1317 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
| 1317 | + 'description' => __('Meta key.', 'woocommerce'), |
|
| 1318 | 1318 | 'type' => 'string', |
| 1319 | - 'context' => array( 'view', 'edit' ), |
|
| 1319 | + 'context' => array('view', 'edit'), |
|
| 1320 | 1320 | 'readonly' => true, |
| 1321 | 1321 | ), |
| 1322 | 1322 | 'label' => array( |
| 1323 | - 'description' => __( 'Meta label.', 'woocommerce' ), |
|
| 1323 | + 'description' => __('Meta label.', 'woocommerce'), |
|
| 1324 | 1324 | 'type' => 'string', |
| 1325 | - 'context' => array( 'view', 'edit' ), |
|
| 1325 | + 'context' => array('view', 'edit'), |
|
| 1326 | 1326 | 'readonly' => true, |
| 1327 | 1327 | ), |
| 1328 | 1328 | 'value' => array( |
| 1329 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
| 1329 | + 'description' => __('Meta value.', 'woocommerce'), |
|
| 1330 | 1330 | 'type' => 'mixed', |
| 1331 | - 'context' => array( 'view', 'edit' ), |
|
| 1331 | + 'context' => array('view', 'edit'), |
|
| 1332 | 1332 | 'readonly' => true, |
| 1333 | 1333 | ), |
| 1334 | 1334 | ), |
@@ -1338,110 +1338,110 @@ discard block |
||
| 1338 | 1338 | ), |
| 1339 | 1339 | ), |
| 1340 | 1340 | 'tax_lines' => array( |
| 1341 | - 'description' => __( 'Tax lines data.', 'woocommerce' ), |
|
| 1341 | + 'description' => __('Tax lines data.', 'woocommerce'), |
|
| 1342 | 1342 | 'type' => 'array', |
| 1343 | - 'context' => array( 'view', 'edit' ), |
|
| 1343 | + 'context' => array('view', 'edit'), |
|
| 1344 | 1344 | 'readonly' => true, |
| 1345 | 1345 | 'items' => array( |
| 1346 | 1346 | 'type' => 'object', |
| 1347 | 1347 | 'properties' => array( |
| 1348 | 1348 | 'id' => array( |
| 1349 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
| 1349 | + 'description' => __('Item ID.', 'woocommerce'), |
|
| 1350 | 1350 | 'type' => 'integer', |
| 1351 | - 'context' => array( 'view', 'edit' ), |
|
| 1351 | + 'context' => array('view', 'edit'), |
|
| 1352 | 1352 | 'readonly' => true, |
| 1353 | 1353 | ), |
| 1354 | 1354 | 'rate_code' => array( |
| 1355 | - 'description' => __( 'Tax rate code.', 'woocommerce' ), |
|
| 1355 | + 'description' => __('Tax rate code.', 'woocommerce'), |
|
| 1356 | 1356 | 'type' => 'string', |
| 1357 | - 'context' => array( 'view', 'edit' ), |
|
| 1357 | + 'context' => array('view', 'edit'), |
|
| 1358 | 1358 | 'readonly' => true, |
| 1359 | 1359 | ), |
| 1360 | 1360 | 'rate_id' => array( |
| 1361 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
| 1361 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
| 1362 | 1362 | 'type' => 'string', |
| 1363 | - 'context' => array( 'view', 'edit' ), |
|
| 1363 | + 'context' => array('view', 'edit'), |
|
| 1364 | 1364 | 'readonly' => true, |
| 1365 | 1365 | ), |
| 1366 | 1366 | 'label' => array( |
| 1367 | - 'description' => __( 'Tax rate label.', 'woocommerce' ), |
|
| 1367 | + 'description' => __('Tax rate label.', 'woocommerce'), |
|
| 1368 | 1368 | 'type' => 'string', |
| 1369 | - 'context' => array( 'view', 'edit' ), |
|
| 1369 | + 'context' => array('view', 'edit'), |
|
| 1370 | 1370 | 'readonly' => true, |
| 1371 | 1371 | ), |
| 1372 | 1372 | 'compound' => array( |
| 1373 | - 'description' => __( 'Show if is a compound tax rate.', 'woocommerce' ), |
|
| 1373 | + 'description' => __('Show if is a compound tax rate.', 'woocommerce'), |
|
| 1374 | 1374 | 'type' => 'boolean', |
| 1375 | - 'context' => array( 'view', 'edit' ), |
|
| 1375 | + 'context' => array('view', 'edit'), |
|
| 1376 | 1376 | 'readonly' => true, |
| 1377 | 1377 | ), |
| 1378 | 1378 | 'tax_total' => array( |
| 1379 | - 'description' => __( 'Tax total (not including shipping taxes).', 'woocommerce' ), |
|
| 1379 | + 'description' => __('Tax total (not including shipping taxes).', 'woocommerce'), |
|
| 1380 | 1380 | 'type' => 'string', |
| 1381 | - 'context' => array( 'view', 'edit' ), |
|
| 1381 | + 'context' => array('view', 'edit'), |
|
| 1382 | 1382 | 'readonly' => true, |
| 1383 | 1383 | ), |
| 1384 | 1384 | 'shipping_tax_total' => array( |
| 1385 | - 'description' => __( 'Shipping tax total.', 'woocommerce' ), |
|
| 1385 | + 'description' => __('Shipping tax total.', 'woocommerce'), |
|
| 1386 | 1386 | 'type' => 'string', |
| 1387 | - 'context' => array( 'view', 'edit' ), |
|
| 1387 | + 'context' => array('view', 'edit'), |
|
| 1388 | 1388 | 'readonly' => true, |
| 1389 | 1389 | ), |
| 1390 | 1390 | ), |
| 1391 | 1391 | ), |
| 1392 | 1392 | ), |
| 1393 | 1393 | 'shipping_lines' => array( |
| 1394 | - 'description' => __( 'Shipping lines data.', 'woocommerce' ), |
|
| 1394 | + 'description' => __('Shipping lines data.', 'woocommerce'), |
|
| 1395 | 1395 | 'type' => 'array', |
| 1396 | - 'context' => array( 'view', 'edit' ), |
|
| 1396 | + 'context' => array('view', 'edit'), |
|
| 1397 | 1397 | 'items' => array( |
| 1398 | 1398 | 'type' => 'object', |
| 1399 | 1399 | 'properties' => array( |
| 1400 | 1400 | 'id' => array( |
| 1401 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
| 1401 | + 'description' => __('Item ID.', 'woocommerce'), |
|
| 1402 | 1402 | 'type' => 'integer', |
| 1403 | - 'context' => array( 'view', 'edit' ), |
|
| 1403 | + 'context' => array('view', 'edit'), |
|
| 1404 | 1404 | 'readonly' => true, |
| 1405 | 1405 | ), |
| 1406 | 1406 | 'method_title' => array( |
| 1407 | - 'description' => __( 'Shipping method name.', 'woocommerce' ), |
|
| 1407 | + 'description' => __('Shipping method name.', 'woocommerce'), |
|
| 1408 | 1408 | 'type' => 'mixed', |
| 1409 | - 'context' => array( 'view', 'edit' ), |
|
| 1409 | + 'context' => array('view', 'edit'), |
|
| 1410 | 1410 | ), |
| 1411 | 1411 | 'method_id' => array( |
| 1412 | - 'description' => __( 'Shipping method ID.', 'woocommerce' ), |
|
| 1412 | + 'description' => __('Shipping method ID.', 'woocommerce'), |
|
| 1413 | 1413 | 'type' => 'mixed', |
| 1414 | - 'context' => array( 'view', 'edit' ), |
|
| 1414 | + 'context' => array('view', 'edit'), |
|
| 1415 | 1415 | ), |
| 1416 | 1416 | 'total' => array( |
| 1417 | - 'description' => __( 'Line total (after discounts).', 'woocommerce' ), |
|
| 1417 | + 'description' => __('Line total (after discounts).', 'woocommerce'), |
|
| 1418 | 1418 | 'type' => 'string', |
| 1419 | - 'context' => array( 'view', 'edit' ), |
|
| 1419 | + 'context' => array('view', 'edit'), |
|
| 1420 | 1420 | ), |
| 1421 | 1421 | 'total_tax' => array( |
| 1422 | - 'description' => __( 'Line total tax (after discounts).', 'woocommerce' ), |
|
| 1422 | + 'description' => __('Line total tax (after discounts).', 'woocommerce'), |
|
| 1423 | 1423 | 'type' => 'string', |
| 1424 | - 'context' => array( 'view', 'edit' ), |
|
| 1424 | + 'context' => array('view', 'edit'), |
|
| 1425 | 1425 | 'readonly' => true, |
| 1426 | 1426 | ), |
| 1427 | 1427 | 'taxes' => array( |
| 1428 | - 'description' => __( 'Line taxes.', 'woocommerce' ), |
|
| 1428 | + 'description' => __('Line taxes.', 'woocommerce'), |
|
| 1429 | 1429 | 'type' => 'array', |
| 1430 | - 'context' => array( 'view', 'edit' ), |
|
| 1430 | + 'context' => array('view', 'edit'), |
|
| 1431 | 1431 | 'readonly' => true, |
| 1432 | 1432 | 'items' => array( |
| 1433 | 1433 | 'type' => 'object', |
| 1434 | 1434 | 'properties' => array( |
| 1435 | 1435 | 'id' => array( |
| 1436 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
| 1436 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
| 1437 | 1437 | 'type' => 'integer', |
| 1438 | - 'context' => array( 'view', 'edit' ), |
|
| 1438 | + 'context' => array('view', 'edit'), |
|
| 1439 | 1439 | 'readonly' => true, |
| 1440 | 1440 | ), |
| 1441 | 1441 | 'total' => array( |
| 1442 | - 'description' => __( 'Tax total.', 'woocommerce' ), |
|
| 1442 | + 'description' => __('Tax total.', 'woocommerce'), |
|
| 1443 | 1443 | 'type' => 'string', |
| 1444 | - 'context' => array( 'view', 'edit' ), |
|
| 1444 | + 'context' => array('view', 'edit'), |
|
| 1445 | 1445 | 'readonly' => true, |
| 1446 | 1446 | ), |
| 1447 | 1447 | ), |
@@ -1451,68 +1451,68 @@ discard block |
||
| 1451 | 1451 | ), |
| 1452 | 1452 | ), |
| 1453 | 1453 | 'fee_lines' => array( |
| 1454 | - 'description' => __( 'Fee lines data.', 'woocommerce' ), |
|
| 1454 | + 'description' => __('Fee lines data.', 'woocommerce'), |
|
| 1455 | 1455 | 'type' => 'array', |
| 1456 | - 'context' => array( 'view', 'edit' ), |
|
| 1456 | + 'context' => array('view', 'edit'), |
|
| 1457 | 1457 | 'items' => array( |
| 1458 | 1458 | 'type' => 'object', |
| 1459 | 1459 | 'properties' => array( |
| 1460 | 1460 | 'id' => array( |
| 1461 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
| 1461 | + 'description' => __('Item ID.', 'woocommerce'), |
|
| 1462 | 1462 | 'type' => 'integer', |
| 1463 | - 'context' => array( 'view', 'edit' ), |
|
| 1463 | + 'context' => array('view', 'edit'), |
|
| 1464 | 1464 | 'readonly' => true, |
| 1465 | 1465 | ), |
| 1466 | 1466 | 'name' => array( |
| 1467 | - 'description' => __( 'Fee name.', 'woocommerce' ), |
|
| 1467 | + 'description' => __('Fee name.', 'woocommerce'), |
|
| 1468 | 1468 | 'type' => 'mixed', |
| 1469 | - 'context' => array( 'view', 'edit' ), |
|
| 1469 | + 'context' => array('view', 'edit'), |
|
| 1470 | 1470 | ), |
| 1471 | 1471 | 'tax_class' => array( |
| 1472 | - 'description' => __( 'Tax class of fee.', 'woocommerce' ), |
|
| 1472 | + 'description' => __('Tax class of fee.', 'woocommerce'), |
|
| 1473 | 1473 | 'type' => 'string', |
| 1474 | - 'context' => array( 'view', 'edit' ), |
|
| 1474 | + 'context' => array('view', 'edit'), |
|
| 1475 | 1475 | ), |
| 1476 | 1476 | 'tax_status' => array( |
| 1477 | - 'description' => __( 'Tax status of fee.', 'woocommerce' ), |
|
| 1477 | + 'description' => __('Tax status of fee.', 'woocommerce'), |
|
| 1478 | 1478 | 'type' => 'string', |
| 1479 | - 'context' => array( 'view', 'edit' ), |
|
| 1480 | - 'enum' => array( 'taxable', 'none' ), |
|
| 1479 | + 'context' => array('view', 'edit'), |
|
| 1480 | + 'enum' => array('taxable', 'none'), |
|
| 1481 | 1481 | ), |
| 1482 | 1482 | 'total' => array( |
| 1483 | - 'description' => __( 'Line total (after discounts).', 'woocommerce' ), |
|
| 1483 | + 'description' => __('Line total (after discounts).', 'woocommerce'), |
|
| 1484 | 1484 | 'type' => 'string', |
| 1485 | - 'context' => array( 'view', 'edit' ), |
|
| 1485 | + 'context' => array('view', 'edit'), |
|
| 1486 | 1486 | ), |
| 1487 | 1487 | 'total_tax' => array( |
| 1488 | - 'description' => __( 'Line total tax (after discounts).', 'woocommerce' ), |
|
| 1488 | + 'description' => __('Line total tax (after discounts).', 'woocommerce'), |
|
| 1489 | 1489 | 'type' => 'string', |
| 1490 | - 'context' => array( 'view', 'edit' ), |
|
| 1490 | + 'context' => array('view', 'edit'), |
|
| 1491 | 1491 | ), |
| 1492 | 1492 | 'taxes' => array( |
| 1493 | - 'description' => __( 'Line taxes.', 'woocommerce' ), |
|
| 1493 | + 'description' => __('Line taxes.', 'woocommerce'), |
|
| 1494 | 1494 | 'type' => 'array', |
| 1495 | - 'context' => array( 'view', 'edit' ), |
|
| 1495 | + 'context' => array('view', 'edit'), |
|
| 1496 | 1496 | 'readonly' => true, |
| 1497 | 1497 | 'items' => array( |
| 1498 | 1498 | 'type' => 'object', |
| 1499 | 1499 | 'properties' => array( |
| 1500 | 1500 | 'id' => array( |
| 1501 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
| 1501 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
| 1502 | 1502 | 'type' => 'integer', |
| 1503 | - 'context' => array( 'view', 'edit' ), |
|
| 1503 | + 'context' => array('view', 'edit'), |
|
| 1504 | 1504 | 'readonly' => true, |
| 1505 | 1505 | ), |
| 1506 | 1506 | 'total' => array( |
| 1507 | - 'description' => __( 'Tax total.', 'woocommerce' ), |
|
| 1507 | + 'description' => __('Tax total.', 'woocommerce'), |
|
| 1508 | 1508 | 'type' => 'string', |
| 1509 | - 'context' => array( 'view', 'edit' ), |
|
| 1509 | + 'context' => array('view', 'edit'), |
|
| 1510 | 1510 | 'readonly' => true, |
| 1511 | 1511 | ), |
| 1512 | 1512 | 'subtotal' => array( |
| 1513 | - 'description' => __( 'Tax subtotal.', 'woocommerce' ), |
|
| 1513 | + 'description' => __('Tax subtotal.', 'woocommerce'), |
|
| 1514 | 1514 | 'type' => 'string', |
| 1515 | - 'context' => array( 'view', 'edit' ), |
|
| 1515 | + 'context' => array('view', 'edit'), |
|
| 1516 | 1516 | 'readonly' => true, |
| 1517 | 1517 | ), |
| 1518 | 1518 | ), |
@@ -1522,61 +1522,61 @@ discard block |
||
| 1522 | 1522 | ), |
| 1523 | 1523 | ), |
| 1524 | 1524 | 'coupon_lines' => array( |
| 1525 | - 'description' => __( 'Coupons line data.', 'woocommerce' ), |
|
| 1525 | + 'description' => __('Coupons line data.', 'woocommerce'), |
|
| 1526 | 1526 | 'type' => 'array', |
| 1527 | - 'context' => array( 'view', 'edit' ), |
|
| 1527 | + 'context' => array('view', 'edit'), |
|
| 1528 | 1528 | 'items' => array( |
| 1529 | 1529 | 'type' => 'object', |
| 1530 | 1530 | 'properties' => array( |
| 1531 | 1531 | 'id' => array( |
| 1532 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
| 1532 | + 'description' => __('Item ID.', 'woocommerce'), |
|
| 1533 | 1533 | 'type' => 'integer', |
| 1534 | - 'context' => array( 'view', 'edit' ), |
|
| 1534 | + 'context' => array('view', 'edit'), |
|
| 1535 | 1535 | 'readonly' => true, |
| 1536 | 1536 | ), |
| 1537 | 1537 | 'code' => array( |
| 1538 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
| 1538 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
| 1539 | 1539 | 'type' => 'mixed', |
| 1540 | - 'context' => array( 'view', 'edit' ), |
|
| 1540 | + 'context' => array('view', 'edit'), |
|
| 1541 | 1541 | ), |
| 1542 | 1542 | 'discount' => array( |
| 1543 | - 'description' => __( 'Discount total.', 'woocommerce' ), |
|
| 1543 | + 'description' => __('Discount total.', 'woocommerce'), |
|
| 1544 | 1544 | 'type' => 'string', |
| 1545 | - 'context' => array( 'view', 'edit' ), |
|
| 1545 | + 'context' => array('view', 'edit'), |
|
| 1546 | 1546 | ), |
| 1547 | 1547 | 'discount_tax' => array( |
| 1548 | - 'description' => __( 'Discount total tax.', 'woocommerce' ), |
|
| 1548 | + 'description' => __('Discount total tax.', 'woocommerce'), |
|
| 1549 | 1549 | 'type' => 'string', |
| 1550 | - 'context' => array( 'view', 'edit' ), |
|
| 1550 | + 'context' => array('view', 'edit'), |
|
| 1551 | 1551 | 'readonly' => true, |
| 1552 | 1552 | ), |
| 1553 | 1553 | ), |
| 1554 | 1554 | ), |
| 1555 | 1555 | ), |
| 1556 | 1556 | 'refunds' => array( |
| 1557 | - 'description' => __( 'List of refunds.', 'woocommerce' ), |
|
| 1557 | + 'description' => __('List of refunds.', 'woocommerce'), |
|
| 1558 | 1558 | 'type' => 'array', |
| 1559 | - 'context' => array( 'view', 'edit' ), |
|
| 1559 | + 'context' => array('view', 'edit'), |
|
| 1560 | 1560 | 'readonly' => true, |
| 1561 | 1561 | 'items' => array( |
| 1562 | 1562 | 'type' => 'object', |
| 1563 | 1563 | 'properties' => array( |
| 1564 | 1564 | 'id' => array( |
| 1565 | - 'description' => __( 'Refund ID.', 'woocommerce' ), |
|
| 1565 | + 'description' => __('Refund ID.', 'woocommerce'), |
|
| 1566 | 1566 | 'type' => 'integer', |
| 1567 | - 'context' => array( 'view', 'edit' ), |
|
| 1567 | + 'context' => array('view', 'edit'), |
|
| 1568 | 1568 | 'readonly' => true, |
| 1569 | 1569 | ), |
| 1570 | 1570 | 'reason' => array( |
| 1571 | - 'description' => __( 'Refund reason.', 'woocommerce' ), |
|
| 1571 | + 'description' => __('Refund reason.', 'woocommerce'), |
|
| 1572 | 1572 | 'type' => 'string', |
| 1573 | - 'context' => array( 'view', 'edit' ), |
|
| 1573 | + 'context' => array('view', 'edit'), |
|
| 1574 | 1574 | 'readonly' => true, |
| 1575 | 1575 | ), |
| 1576 | 1576 | 'total' => array( |
| 1577 | - 'description' => __( 'Refund total.', 'woocommerce' ), |
|
| 1577 | + 'description' => __('Refund total.', 'woocommerce'), |
|
| 1578 | 1578 | 'type' => 'string', |
| 1579 | - 'context' => array( 'view', 'edit' ), |
|
| 1579 | + 'context' => array('view', 'edit'), |
|
| 1580 | 1580 | 'readonly' => true, |
| 1581 | 1581 | ), |
| 1582 | 1582 | ), |
@@ -1585,7 +1585,7 @@ discard block |
||
| 1585 | 1585 | ), |
| 1586 | 1586 | ); |
| 1587 | 1587 | |
| 1588 | - return $this->add_additional_fields_schema( $schema ); |
|
| 1588 | + return $this->add_additional_fields_schema($schema); |
|
| 1589 | 1589 | } |
| 1590 | 1590 | |
| 1591 | 1591 | /** |
@@ -1598,27 +1598,27 @@ discard block |
||
| 1598 | 1598 | |
| 1599 | 1599 | $params['status'] = array( |
| 1600 | 1600 | 'default' => 'any', |
| 1601 | - 'description' => __( 'Limit result set to orders assigned a specific status.', 'woocommerce' ), |
|
| 1601 | + 'description' => __('Limit result set to orders assigned a specific status.', 'woocommerce'), |
|
| 1602 | 1602 | 'type' => 'string', |
| 1603 | - 'enum' => array_merge( array( 'any' ), $this->get_order_statuses() ), |
|
| 1603 | + 'enum' => array_merge(array('any'), $this->get_order_statuses()), |
|
| 1604 | 1604 | 'sanitize_callback' => 'sanitize_key', |
| 1605 | 1605 | 'validate_callback' => 'rest_validate_request_arg', |
| 1606 | 1606 | ); |
| 1607 | 1607 | $params['customer'] = array( |
| 1608 | - 'description' => __( 'Limit result set to orders assigned a specific customer.', 'woocommerce' ), |
|
| 1608 | + 'description' => __('Limit result set to orders assigned a specific customer.', 'woocommerce'), |
|
| 1609 | 1609 | 'type' => 'integer', |
| 1610 | 1610 | 'sanitize_callback' => 'absint', |
| 1611 | 1611 | 'validate_callback' => 'rest_validate_request_arg', |
| 1612 | 1612 | ); |
| 1613 | 1613 | $params['product'] = array( |
| 1614 | - 'description' => __( 'Limit result set to orders assigned a specific product.', 'woocommerce' ), |
|
| 1614 | + 'description' => __('Limit result set to orders assigned a specific product.', 'woocommerce'), |
|
| 1615 | 1615 | 'type' => 'integer', |
| 1616 | 1616 | 'sanitize_callback' => 'absint', |
| 1617 | 1617 | 'validate_callback' => 'rest_validate_request_arg', |
| 1618 | 1618 | ); |
| 1619 | 1619 | $params['dp'] = array( |
| 1620 | 1620 | 'default' => wc_get_price_decimals(), |
| 1621 | - 'description' => __( 'Number of decimal points to use in each resource.', 'woocommerce' ), |
|
| 1621 | + 'description' => __('Number of decimal points to use in each resource.', 'woocommerce'), |
|
| 1622 | 1622 | 'type' => 'integer', |
| 1623 | 1623 | 'sanitize_callback' => 'absint', |
| 1624 | 1624 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @since 3.0.0 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -47,67 +47,67 @@ discard block |
||
| 47 | 47 | * Register the routes for order notes. |
| 48 | 48 | */ |
| 49 | 49 | public function register_routes() { |
| 50 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
| 50 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
| 51 | 51 | 'args' => array( |
| 52 | 52 | 'order_id' => array( |
| 53 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
| 53 | + 'description' => __('The order ID.', 'woocommerce'), |
|
| 54 | 54 | 'type' => 'integer', |
| 55 | 55 | ), |
| 56 | 56 | ), |
| 57 | 57 | array( |
| 58 | 58 | 'methods' => WP_REST_Server::READABLE, |
| 59 | - 'callback' => array( $this, 'get_items' ), |
|
| 60 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 59 | + 'callback' => array($this, 'get_items'), |
|
| 60 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 61 | 61 | 'args' => $this->get_collection_params(), |
| 62 | 62 | ), |
| 63 | 63 | array( |
| 64 | 64 | 'methods' => WP_REST_Server::CREATABLE, |
| 65 | - 'callback' => array( $this, 'create_item' ), |
|
| 66 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
| 67 | - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
| 65 | + 'callback' => array($this, 'create_item'), |
|
| 66 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
| 67 | + 'args' => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
| 68 | 68 | 'note' => array( |
| 69 | 69 | 'type' => 'string', |
| 70 | - 'description' => __( 'Order note content.', 'woocommerce' ), |
|
| 70 | + 'description' => __('Order note content.', 'woocommerce'), |
|
| 71 | 71 | 'required' => true, |
| 72 | 72 | ), |
| 73 | - ) ), |
|
| 73 | + )), |
|
| 74 | 74 | ), |
| 75 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 76 | - ) ); |
|
| 75 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 76 | + )); |
|
| 77 | 77 | |
| 78 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
| 78 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', 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 | 'order_id' => array( |
| 85 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
| 85 | + 'description' => __('The order ID.', 'woocommerce'), |
|
| 86 | 86 | 'type' => 'integer', |
| 87 | 87 | ), |
| 88 | 88 | ), |
| 89 | 89 | array( |
| 90 | 90 | 'methods' => WP_REST_Server::READABLE, |
| 91 | - 'callback' => array( $this, 'get_item' ), |
|
| 92 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 91 | + 'callback' => array($this, 'get_item'), |
|
| 92 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 93 | 93 | 'args' => array( |
| 94 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 94 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 95 | 95 | ), |
| 96 | 96 | ), |
| 97 | 97 | array( |
| 98 | 98 | 'methods' => WP_REST_Server::DELETABLE, |
| 99 | - 'callback' => array( $this, 'delete_item' ), |
|
| 100 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
| 99 | + 'callback' => array($this, 'delete_item'), |
|
| 100 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
| 101 | 101 | 'args' => array( |
| 102 | 102 | 'force' => array( |
| 103 | 103 | 'default' => false, |
| 104 | 104 | 'type' => 'boolean', |
| 105 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
| 105 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
| 106 | 106 | ), |
| 107 | 107 | ), |
| 108 | 108 | ), |
| 109 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 110 | - ) ); |
|
| 109 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 110 | + )); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | * @param WP_REST_Request $request Full details about the request. |
| 117 | 117 | * @return WP_Error|boolean |
| 118 | 118 | */ |
| 119 | - public function get_items_permissions_check( $request ) { |
|
| 120 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'read' ) ) { |
|
| 121 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 119 | + public function get_items_permissions_check($request) { |
|
| 120 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'read')) { |
|
| 121 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | return true; |
@@ -131,9 +131,9 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @return bool|WP_Error |
| 133 | 133 | */ |
| 134 | - public function create_item_permissions_check( $request ) { |
|
| 135 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'create' ) ) { |
|
| 136 | - return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 134 | + public function create_item_permissions_check($request) { |
|
| 135 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'create')) { |
|
| 136 | + return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | return true; |
@@ -145,11 +145,11 @@ discard block |
||
| 145 | 145 | * @param WP_REST_Request $request Full details about the request. |
| 146 | 146 | * @return WP_Error|boolean |
| 147 | 147 | */ |
| 148 | - public function get_item_permissions_check( $request ) { |
|
| 149 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 148 | + public function get_item_permissions_check($request) { |
|
| 149 | + $order = wc_get_order((int) $request['order_id']); |
|
| 150 | 150 | |
| 151 | - if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'read', $order->get_id() ) ) { |
|
| 152 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 151 | + if ($order && ! wc_rest_check_post_permissions($this->post_type, 'read', $order->get_id())) { |
|
| 152 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | return true; |
@@ -162,11 +162,11 @@ discard block |
||
| 162 | 162 | * |
| 163 | 163 | * @return bool|WP_Error |
| 164 | 164 | */ |
| 165 | - public function delete_item_permissions_check( $request ) { |
|
| 166 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 165 | + public function delete_item_permissions_check($request) { |
|
| 166 | + $order = wc_get_order((int) $request['order_id']); |
|
| 167 | 167 | |
| 168 | - if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $order->get_id() ) ) { |
|
| 169 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 168 | + if ($order && ! wc_rest_check_post_permissions($this->post_type, 'delete', $order->get_id())) { |
|
| 169 | + return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | return true; |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @return array|WP_Error |
| 181 | 181 | */ |
| 182 | - public function get_items( $request ) { |
|
| 183 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 182 | + public function get_items($request) { |
|
| 183 | + $order = wc_get_order((int) $request['order_id']); |
|
| 184 | 184 | |
| 185 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
| 186 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 185 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
| 186 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | $args = array( |
@@ -192,20 +192,20 @@ discard block |
||
| 192 | 192 | 'type' => 'order_note', |
| 193 | 193 | ); |
| 194 | 194 | |
| 195 | - remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); |
|
| 195 | + remove_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1); |
|
| 196 | 196 | |
| 197 | - $notes = get_comments( $args ); |
|
| 197 | + $notes = get_comments($args); |
|
| 198 | 198 | |
| 199 | - add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); |
|
| 199 | + add_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1); |
|
| 200 | 200 | |
| 201 | 201 | $data = array(); |
| 202 | - foreach ( $notes as $note ) { |
|
| 203 | - $order_note = $this->prepare_item_for_response( $note, $request ); |
|
| 204 | - $order_note = $this->prepare_response_for_collection( $order_note ); |
|
| 202 | + foreach ($notes as $note) { |
|
| 203 | + $order_note = $this->prepare_item_for_response($note, $request); |
|
| 204 | + $order_note = $this->prepare_response_for_collection($order_note); |
|
| 205 | 205 | $data[] = $order_note; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - return rest_ensure_response( $data ); |
|
| 208 | + return rest_ensure_response($data); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -214,27 +214,27 @@ discard block |
||
| 214 | 214 | * @param WP_REST_Request $request Full details about the request. |
| 215 | 215 | * @return WP_Error|WP_REST_Response |
| 216 | 216 | */ |
| 217 | - public function create_item( $request ) { |
|
| 218 | - if ( ! empty( $request['id'] ) ) { |
|
| 217 | + public function create_item($request) { |
|
| 218 | + if ( ! empty($request['id'])) { |
|
| 219 | 219 | /* translators: %s: post type */ |
| 220 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
| 220 | + return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 223 | + $order = wc_get_order((int) $request['order_id']); |
|
| 224 | 224 | |
| 225 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
| 226 | - return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 225 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
| 226 | + return new WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | // Create the note. |
| 230 | - $note_id = $order->add_order_note( $request['note'], $request['customer_note'] ); |
|
| 230 | + $note_id = $order->add_order_note($request['note'], $request['customer_note']); |
|
| 231 | 231 | |
| 232 | - if ( ! $note_id ) { |
|
| 233 | - return new WP_Error( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 232 | + if ( ! $note_id) { |
|
| 233 | + return new WP_Error('woocommerce_api_cannot_create_order_note', __('Cannot create order note, please try again.', 'woocommerce'), array('status' => 500)); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - $note = get_comment( $note_id ); |
|
| 237 | - $this->update_additional_fields_for_object( $note, $request ); |
|
| 236 | + $note = get_comment($note_id); |
|
| 237 | + $this->update_additional_fields_for_object($note, $request); |
|
| 238 | 238 | |
| 239 | 239 | /** |
| 240 | 240 | * Fires after a order note is created or updated via the REST API. |
@@ -243,13 +243,13 @@ discard block |
||
| 243 | 243 | * @param WP_REST_Request $request Request object. |
| 244 | 244 | * @param boolean $creating True when creating item, false when updating. |
| 245 | 245 | */ |
| 246 | - do_action( 'woocommerce_rest_insert_order_note', $note, $request, true ); |
|
| 246 | + do_action('woocommerce_rest_insert_order_note', $note, $request, true); |
|
| 247 | 247 | |
| 248 | - $request->set_param( 'context', 'edit' ); |
|
| 249 | - $response = $this->prepare_item_for_response( $note, $request ); |
|
| 250 | - $response = rest_ensure_response( $response ); |
|
| 251 | - $response->set_status( 201 ); |
|
| 252 | - $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 ) ) ); |
|
| 248 | + $request->set_param('context', 'edit'); |
|
| 249 | + $response = $this->prepare_item_for_response($note, $request); |
|
| 250 | + $response = rest_ensure_response($response); |
|
| 251 | + $response->set_status(201); |
|
| 252 | + $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))); |
|
| 253 | 253 | |
| 254 | 254 | return $response; |
| 255 | 255 | } |
@@ -260,22 +260,22 @@ discard block |
||
| 260 | 260 | * @param WP_REST_Request $request Full details about the request. |
| 261 | 261 | * @return WP_Error|WP_REST_Response |
| 262 | 262 | */ |
| 263 | - public function get_item( $request ) { |
|
| 263 | + public function get_item($request) { |
|
| 264 | 264 | $id = (int) $request['id']; |
| 265 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 265 | + $order = wc_get_order((int) $request['order_id']); |
|
| 266 | 266 | |
| 267 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
| 268 | - return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 267 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
| 268 | + return new WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - $note = get_comment( $id ); |
|
| 271 | + $note = get_comment($id); |
|
| 272 | 272 | |
| 273 | - if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) { |
|
| 274 | - return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 273 | + if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) { |
|
| 274 | + return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - $order_note = $this->prepare_item_for_response( $note, $request ); |
|
| 278 | - $response = rest_ensure_response( $order_note ); |
|
| 277 | + $order_note = $this->prepare_item_for_response($note, $request); |
|
| 278 | + $response = rest_ensure_response($order_note); |
|
| 279 | 279 | |
| 280 | 280 | return $response; |
| 281 | 281 | } |
@@ -286,34 +286,34 @@ discard block |
||
| 286 | 286 | * @param WP_REST_Request $request Full details about the request. |
| 287 | 287 | * @return WP_REST_Response|WP_Error |
| 288 | 288 | */ |
| 289 | - public function delete_item( $request ) { |
|
| 289 | + public function delete_item($request) { |
|
| 290 | 290 | $id = (int) $request['id']; |
| 291 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 291 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
| 292 | 292 | |
| 293 | 293 | // We don't support trashing for this type, error out. |
| 294 | - if ( ! $force ) { |
|
| 295 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
| 294 | + if ( ! $force) { |
|
| 295 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Webhooks do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
| 298 | + $order = wc_get_order((int) $request['order_id']); |
|
| 299 | 299 | |
| 300 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
| 301 | - return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 300 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
| 301 | + return new WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - $note = get_comment( $id ); |
|
| 304 | + $note = get_comment($id); |
|
| 305 | 305 | |
| 306 | - if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) { |
|
| 307 | - return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 306 | + if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) { |
|
| 307 | + return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - $request->set_param( 'context', 'edit' ); |
|
| 311 | - $response = $this->prepare_item_for_response( $note, $request ); |
|
| 310 | + $request->set_param('context', 'edit'); |
|
| 311 | + $response = $this->prepare_item_for_response($note, $request); |
|
| 312 | 312 | |
| 313 | - $result = wc_delete_order_note( $note->comment_ID ); |
|
| 313 | + $result = wc_delete_order_note($note->comment_ID); |
|
| 314 | 314 | |
| 315 | - if ( ! $result ) { |
|
| 316 | - return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), 'order_note' ), array( 'status' => 500 ) ); |
|
| 315 | + if ( ! $result) { |
|
| 316 | + return new WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), 'order_note'), array('status' => 500)); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | * @param WP_REST_Response $response The response data. |
| 324 | 324 | * @param WP_REST_Request $request The request sent to the API. |
| 325 | 325 | */ |
| 326 | - do_action( 'woocommerce_rest_delete_order_note', $note, $response, $request ); |
|
| 326 | + do_action('woocommerce_rest_delete_order_note', $note, $response, $request); |
|
| 327 | 327 | |
| 328 | 328 | return $response; |
| 329 | 329 | } |
@@ -335,22 +335,22 @@ discard block |
||
| 335 | 335 | * @param WP_REST_Request $request Request object. |
| 336 | 336 | * @return WP_REST_Response $response Response data. |
| 337 | 337 | */ |
| 338 | - public function prepare_item_for_response( $note, $request ) { |
|
| 338 | + public function prepare_item_for_response($note, $request) { |
|
| 339 | 339 | $data = array( |
| 340 | 340 | 'id' => (int) $note->comment_ID, |
| 341 | - 'date_created' => wc_rest_prepare_date_response( $note->comment_date_gmt ), |
|
| 341 | + 'date_created' => wc_rest_prepare_date_response($note->comment_date_gmt), |
|
| 342 | 342 | 'note' => $note->comment_content, |
| 343 | - 'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ), |
|
| 343 | + 'customer_note' => (bool) get_comment_meta($note->comment_ID, 'is_customer_note', true), |
|
| 344 | 344 | ); |
| 345 | 345 | |
| 346 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 347 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 348 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 346 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 347 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 348 | + $data = $this->filter_response_by_context($data, $context); |
|
| 349 | 349 | |
| 350 | 350 | // Wrap the data in a response object. |
| 351 | - $response = rest_ensure_response( $data ); |
|
| 351 | + $response = rest_ensure_response($data); |
|
| 352 | 352 | |
| 353 | - $response->add_links( $this->prepare_links( $note ) ); |
|
| 353 | + $response->add_links($this->prepare_links($note)); |
|
| 354 | 354 | |
| 355 | 355 | /** |
| 356 | 356 | * Filter order note object returned from the REST API. |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * @param WP_Comment $note Order note object used to create response. |
| 360 | 360 | * @param WP_REST_Request $request Request object. |
| 361 | 361 | */ |
| 362 | - return apply_filters( 'woocommerce_rest_prepare_order_note', $response, $note, $request ); |
|
| 362 | + return apply_filters('woocommerce_rest_prepare_order_note', $response, $note, $request); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -368,18 +368,18 @@ discard block |
||
| 368 | 368 | * @param WP_Comment $note Delivery order_note object. |
| 369 | 369 | * @return array Links for the given order note. |
| 370 | 370 | */ |
| 371 | - protected function prepare_links( $note ) { |
|
| 371 | + protected function prepare_links($note) { |
|
| 372 | 372 | $order_id = (int) $note->comment_post_ID; |
| 373 | - $base = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base ); |
|
| 373 | + $base = str_replace('(?P<order_id>[\d]+)', $order_id, $this->rest_base); |
|
| 374 | 374 | $links = array( |
| 375 | 375 | 'self' => array( |
| 376 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $note->comment_ID ) ), |
|
| 376 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $note->comment_ID)), |
|
| 377 | 377 | ), |
| 378 | 378 | 'collection' => array( |
| 379 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
| 379 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
| 380 | 380 | ), |
| 381 | 381 | 'up' => array( |
| 382 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order_id ) ), |
|
| 382 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $order_id)), |
|
| 383 | 383 | ), |
| 384 | 384 | ); |
| 385 | 385 | |
@@ -398,32 +398,32 @@ discard block |
||
| 398 | 398 | 'type' => 'object', |
| 399 | 399 | 'properties' => array( |
| 400 | 400 | 'id' => array( |
| 401 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 401 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 402 | 402 | 'type' => 'integer', |
| 403 | - 'context' => array( 'view', 'edit' ), |
|
| 403 | + 'context' => array('view', 'edit'), |
|
| 404 | 404 | 'readonly' => true, |
| 405 | 405 | ), |
| 406 | 406 | 'date_created' => array( |
| 407 | - 'description' => __( "The date the order note was created, in the site's timezone.", 'woocommerce' ), |
|
| 407 | + 'description' => __("The date the order note was created, in the site's timezone.", 'woocommerce'), |
|
| 408 | 408 | 'type' => 'date-time', |
| 409 | - 'context' => array( 'view', 'edit' ), |
|
| 409 | + 'context' => array('view', 'edit'), |
|
| 410 | 410 | 'readonly' => true, |
| 411 | 411 | ), |
| 412 | 412 | 'note' => array( |
| 413 | - 'description' => __( 'Order note.', 'woocommerce' ), |
|
| 413 | + 'description' => __('Order note.', 'woocommerce'), |
|
| 414 | 414 | 'type' => 'string', |
| 415 | - 'context' => array( 'view', 'edit' ), |
|
| 415 | + 'context' => array('view', 'edit'), |
|
| 416 | 416 | ), |
| 417 | 417 | 'customer_note' => array( |
| 418 | - 'description' => __( 'Shows/define if the note is only for reference or for the customer (the user will be notified).', 'woocommerce' ), |
|
| 418 | + 'description' => __('Shows/define if the note is only for reference or for the customer (the user will be notified).', 'woocommerce'), |
|
| 419 | 419 | 'type' => 'boolean', |
| 420 | 420 | 'default' => false, |
| 421 | - 'context' => array( 'view', 'edit' ), |
|
| 421 | + 'context' => array('view', 'edit'), |
|
| 422 | 422 | ), |
| 423 | 423 | ), |
| 424 | 424 | ); |
| 425 | 425 | |
| 426 | - return $this->add_additional_fields_schema( $schema ); |
|
| 426 | + return $this->add_additional_fields_schema($schema); |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | /** |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | */ |
| 434 | 434 | public function get_collection_params() { |
| 435 | 435 | return array( |
| 436 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 436 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 437 | 437 | ); |
| 438 | 438 | } |
| 439 | 439 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @package WooCommerce/RestApi |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if ( ! defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | array( |
| 37 | 37 | array( |
| 38 | 38 | 'methods' => WP_REST_Server::READABLE, |
| 39 | - 'callback' => array( $this, 'get_items' ), |
|
| 40 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 39 | + 'callback' => array($this, 'get_items'), |
|
| 40 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 41 | 41 | 'args' => $this->get_collection_params(), |
| 42 | 42 | ), |
| 43 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 43 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 44 | 44 | ) |
| 45 | 45 | ); |
| 46 | 46 | |
@@ -50,14 +50,14 @@ discard block |
||
| 50 | 50 | array( |
| 51 | 51 | 'args' => array( |
| 52 | 52 | 'id' => array( |
| 53 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 53 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 54 | 54 | 'type' => 'integer', |
| 55 | 55 | ), |
| 56 | 56 | ), |
| 57 | 57 | array( |
| 58 | 58 | 'methods' => WP_REST_Server::READABLE, |
| 59 | - 'callback' => array( $this, 'get_item' ), |
|
| 60 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 59 | + 'callback' => array($this, 'get_item'), |
|
| 60 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 61 | 61 | 'args' => array( |
| 62 | 62 | 'context' => $this->get_context_param( |
| 63 | 63 | array( |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | ), |
| 67 | 67 | ), |
| 68 | 68 | ), |
| 69 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 69 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 70 | 70 | ) |
| 71 | 71 | ); |
| 72 | 72 | } |
@@ -78,24 +78,24 @@ discard block |
||
| 78 | 78 | * @param string $context Request context. |
| 79 | 79 | * @return bool|WP_Error |
| 80 | 80 | */ |
| 81 | - protected function check_permissions( $request, $context = 'read' ) { |
|
| 81 | + protected function check_permissions($request, $context = 'read') { |
|
| 82 | 82 | // Get taxonomy. |
| 83 | - $taxonomy = $this->get_taxonomy( $request ); |
|
| 84 | - if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) { |
|
| 85 | - return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Taxonomy does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 83 | + $taxonomy = $this->get_taxonomy($request); |
|
| 84 | + if ( ! $taxonomy || ! taxonomy_exists($taxonomy)) { |
|
| 85 | + return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Taxonomy does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // Check permissions for a single term. |
| 89 | - $id = intval( $request['id'] ); |
|
| 90 | - if ( $id ) { |
|
| 91 | - $term = get_term( $id, $taxonomy ); |
|
| 89 | + $id = intval($request['id']); |
|
| 90 | + if ($id) { |
|
| 91 | + $term = get_term($id, $taxonomy); |
|
| 92 | 92 | |
| 93 | - if ( is_wp_error( $term ) || ! $term || $term->taxonomy !== $taxonomy ) { |
|
| 94 | - return new WP_Error( 'woocommerce_rest_term_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 93 | + if (is_wp_error($term) || ! $term || $term->taxonomy !== $taxonomy) { |
|
| 94 | + return new WP_Error('woocommerce_rest_term_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - return current_user_can( 'edit_posts' ); |
|
| 98 | + return current_user_can('edit_posts'); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param WP_REST_Request $request Request instance. |
| 106 | 106 | * @return WP_REST_Response |
| 107 | 107 | */ |
| 108 | - public function prepare_item_for_response( $item, $request ) { |
|
| 108 | + public function prepare_item_for_response($item, $request) { |
|
| 109 | 109 | $data = array( |
| 110 | 110 | 'id' => (int) $item->term_id, |
| 111 | 111 | 'name' => $item->name, |
@@ -114,14 +114,14 @@ discard block |
||
| 114 | 114 | 'count' => (int) $item->count, |
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 118 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 119 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 117 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 118 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 119 | + $data = $this->filter_response_by_context($data, $context); |
|
| 120 | 120 | |
| 121 | - $response = rest_ensure_response( $data ); |
|
| 121 | + $response = rest_ensure_response($data); |
|
| 122 | 122 | |
| 123 | - $response->header( 'X-Woo-Notice', __( 'Private REST API for use by block editor only.', 'woocommerce' ) ); |
|
| 124 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
| 123 | + $response->header('X-Woo-Notice', __('Private REST API for use by block editor only.', 'woocommerce')); |
|
| 124 | + $response->add_links($this->prepare_links($item, $request)); |
|
| 125 | 125 | |
| 126 | 126 | return $response; |
| 127 | 127 | } |
@@ -146,6 +146,6 @@ discard block |
||
| 146 | 146 | $schema['properties']['parent'] = $raw_schema['properties']['parent']; |
| 147 | 147 | $schema['properties']['count'] = $raw_schema['properties']['count']; |
| 148 | 148 | |
| 149 | - return $this->add_additional_fields_schema( $schema ); |
|
| 149 | + return $this->add_additional_fields_schema($schema); |
|
| 150 | 150 | } |
| 151 | 151 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @package WooCommerce/RestApi |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if ( ! defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | array( |
| 37 | 37 | array( |
| 38 | 38 | 'methods' => WP_REST_Server::READABLE, |
| 39 | - 'callback' => array( $this, 'get_items' ), |
|
| 40 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 39 | + 'callback' => array($this, 'get_items'), |
|
| 40 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 41 | 41 | 'args' => $this->get_collection_params(), |
| 42 | 42 | ), |
| 43 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 43 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 44 | 44 | ) |
| 45 | 45 | ); |
| 46 | 46 | |
@@ -50,14 +50,14 @@ discard block |
||
| 50 | 50 | array( |
| 51 | 51 | 'args' => array( |
| 52 | 52 | 'id' => array( |
| 53 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 53 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 54 | 54 | 'type' => 'integer', |
| 55 | 55 | ), |
| 56 | 56 | ), |
| 57 | 57 | array( |
| 58 | 58 | 'methods' => WP_REST_Server::READABLE, |
| 59 | - 'callback' => array( $this, 'get_item' ), |
|
| 60 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 59 | + 'callback' => array($this, 'get_item'), |
|
| 60 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 61 | 61 | 'args' => array( |
| 62 | 62 | 'context' => $this->get_context_param( |
| 63 | 63 | array( |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | ), |
| 67 | 67 | ), |
| 68 | 68 | ), |
| 69 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 69 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 70 | 70 | ) |
| 71 | 71 | ); |
| 72 | 72 | } |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * @param WP_REST_Request $request Full details about the request. |
| 78 | 78 | * @return WP_Error|boolean |
| 79 | 79 | */ |
| 80 | - public function get_items_permissions_check( $request ) { |
|
| 81 | - if ( ! current_user_can( 'edit_posts' ) ) { |
|
| 82 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 80 | + public function get_items_permissions_check($request) { |
|
| 81 | + if ( ! current_user_can('edit_posts')) { |
|
| 82 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | return true; |
@@ -90,15 +90,15 @@ discard block |
||
| 90 | 90 | * @param WP_REST_Request $request Full details about the request. |
| 91 | 91 | * @return WP_Error|boolean |
| 92 | 92 | */ |
| 93 | - public function get_item_permissions_check( $request ) { |
|
| 94 | - $taxonomy = $this->get_taxonomy( $request ); |
|
| 93 | + public function get_item_permissions_check($request) { |
|
| 94 | + $taxonomy = $this->get_taxonomy($request); |
|
| 95 | 95 | |
| 96 | - if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) { |
|
| 97 | - return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 96 | + if ( ! $taxonomy || ! taxonomy_exists($taxonomy)) { |
|
| 97 | + return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if ( ! current_user_can( 'edit_posts' ) ) { |
|
| 101 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 100 | + if ( ! current_user_can('edit_posts')) { |
|
| 101 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | return true; |
@@ -111,24 +111,24 @@ discard block |
||
| 111 | 111 | * @param string $context Request context. |
| 112 | 112 | * @return bool|WP_Error |
| 113 | 113 | */ |
| 114 | - protected function check_permissions( $request, $context = 'read' ) { |
|
| 114 | + protected function check_permissions($request, $context = 'read') { |
|
| 115 | 115 | // Get taxonomy. |
| 116 | - $taxonomy = $this->get_taxonomy( $request ); |
|
| 117 | - if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) { |
|
| 118 | - return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Taxonomy does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 116 | + $taxonomy = $this->get_taxonomy($request); |
|
| 117 | + if ( ! $taxonomy || ! taxonomy_exists($taxonomy)) { |
|
| 118 | + return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Taxonomy does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // Check permissions for a single term. |
| 122 | - $id = intval( $request['id'] ); |
|
| 123 | - if ( $id ) { |
|
| 124 | - $term = get_term( $id, $taxonomy ); |
|
| 122 | + $id = intval($request['id']); |
|
| 123 | + if ($id) { |
|
| 124 | + $term = get_term($id, $taxonomy); |
|
| 125 | 125 | |
| 126 | - if ( is_wp_error( $term ) || ! $term || $term->taxonomy !== $taxonomy ) { |
|
| 127 | - return new WP_Error( 'woocommerce_rest_term_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 126 | + if (is_wp_error($term) || ! $term || $term->taxonomy !== $taxonomy) { |
|
| 127 | + return new WP_Error('woocommerce_rest_term_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - return current_user_can( 'edit_posts' ); |
|
| 131 | + return current_user_can('edit_posts'); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -138,23 +138,23 @@ discard block |
||
| 138 | 138 | * @param WP_REST_Request $request Request instance. |
| 139 | 139 | * @return WP_REST_Response |
| 140 | 140 | */ |
| 141 | - public function prepare_item_for_response( $item, $request ) { |
|
| 142 | - $taxonomy = wc_attribute_taxonomy_name( $item->attribute_name ); |
|
| 141 | + public function prepare_item_for_response($item, $request) { |
|
| 142 | + $taxonomy = wc_attribute_taxonomy_name($item->attribute_name); |
|
| 143 | 143 | $data = array( |
| 144 | 144 | 'id' => (int) $item->attribute_id, |
| 145 | 145 | 'name' => $item->attribute_label, |
| 146 | 146 | 'slug' => $taxonomy, |
| 147 | - 'count' => wp_count_terms( $taxonomy ), |
|
| 147 | + 'count' => wp_count_terms($taxonomy), |
|
| 148 | 148 | ); |
| 149 | 149 | |
| 150 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 151 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 152 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 150 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 151 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 152 | + $data = $this->filter_response_by_context($data, $context); |
|
| 153 | 153 | |
| 154 | - $response = rest_ensure_response( $data ); |
|
| 154 | + $response = rest_ensure_response($data); |
|
| 155 | 155 | |
| 156 | - $response->header( 'X-Woo-Notice', __( 'Private REST API for use by block editor only.', 'woocommerce' ) ); |
|
| 157 | - $response->add_links( $this->prepare_links( $item ) ); |
|
| 156 | + $response->header('X-Woo-Notice', __('Private REST API for use by block editor only.', 'woocommerce')); |
|
| 157 | + $response->add_links($this->prepare_links($item)); |
|
| 158 | 158 | |
| 159 | 159 | return $response; |
| 160 | 160 | } |
@@ -177,12 +177,12 @@ discard block |
||
| 177 | 177 | $schema['properties']['name'] = $raw_schema['properties']['name']; |
| 178 | 178 | $schema['properties']['slug'] = $raw_schema['properties']['slug']; |
| 179 | 179 | $schema['properties']['count'] = array( |
| 180 | - 'description' => __( 'Number of terms in the attribute taxonomy.', 'woocommerce' ), |
|
| 180 | + 'description' => __('Number of terms in the attribute taxonomy.', 'woocommerce'), |
|
| 181 | 181 | 'type' => 'integer', |
| 182 | - 'context' => array( 'view', 'edit' ), |
|
| 182 | + 'context' => array('view', 'edit'), |
|
| 183 | 183 | 'readonly' => true, |
| 184 | 184 | ); |
| 185 | 185 | |
| 186 | - return $this->add_additional_fields_schema( $schema ); |
|
| 186 | + return $this->add_additional_fields_schema($schema); |
|
| 187 | 187 | } |
| 188 | 188 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @package WooCommerce/RestApi |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if ( ! defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | array( |
| 37 | 37 | array( |
| 38 | 38 | 'methods' => WP_REST_Server::READABLE, |
| 39 | - 'callback' => array( $this, 'get_items' ), |
|
| 40 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 39 | + 'callback' => array($this, 'get_items'), |
|
| 40 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 41 | 41 | 'args' => $this->get_collection_params(), |
| 42 | 42 | ), |
| 43 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 43 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 44 | 44 | ) |
| 45 | 45 | ); |
| 46 | 46 | |
@@ -50,14 +50,14 @@ discard block |
||
| 50 | 50 | array( |
| 51 | 51 | 'args' => array( |
| 52 | 52 | 'id' => array( |
| 53 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 53 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 54 | 54 | 'type' => 'integer', |
| 55 | 55 | ), |
| 56 | 56 | ), |
| 57 | 57 | array( |
| 58 | 58 | 'methods' => WP_REST_Server::READABLE, |
| 59 | - 'callback' => array( $this, 'get_item' ), |
|
| 60 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 59 | + 'callback' => array($this, 'get_item'), |
|
| 60 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 61 | 61 | 'args' => array( |
| 62 | 62 | 'context' => $this->get_context_param( |
| 63 | 63 | array( |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | ), |
| 67 | 67 | ), |
| 68 | 68 | ), |
| 69 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 69 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 70 | 70 | ) |
| 71 | 71 | ); |
| 72 | 72 | } |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * @param WP_REST_Request $request Full details about the request. |
| 78 | 78 | * @return WP_Error|boolean |
| 79 | 79 | */ |
| 80 | - public function get_items_permissions_check( $request ) { |
|
| 81 | - if ( ! current_user_can( 'edit_posts' ) ) { |
|
| 82 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 80 | + public function get_items_permissions_check($request) { |
|
| 81 | + if ( ! current_user_can('edit_posts')) { |
|
| 82 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | return true; |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | * @param WP_REST_Request $request Full details about the request. |
| 92 | 92 | * @return WP_Error|boolean |
| 93 | 93 | */ |
| 94 | - public function get_item_permissions_check( $request ) { |
|
| 95 | - if ( ! current_user_can( 'edit_posts' ) ) { |
|
| 96 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 94 | + public function get_item_permissions_check($request) { |
|
| 95 | + if ( ! current_user_can('edit_posts')) { |
|
| 96 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | return true; |
@@ -105,52 +105,52 @@ discard block |
||
| 105 | 105 | * @param WP_REST_Request $request Full details about the request. |
| 106 | 106 | * @return WP_Error|WP_REST_Response |
| 107 | 107 | */ |
| 108 | - public function get_items( $request ) { |
|
| 109 | - $query_args = $this->prepare_objects_query( $request ); |
|
| 110 | - $query_results = $this->get_objects( $query_args ); |
|
| 108 | + public function get_items($request) { |
|
| 109 | + $query_args = $this->prepare_objects_query($request); |
|
| 110 | + $query_results = $this->get_objects($query_args); |
|
| 111 | 111 | |
| 112 | 112 | $objects = array(); |
| 113 | - foreach ( $query_results['objects'] as $object ) { |
|
| 114 | - $data = $this->prepare_object_for_response( $object, $request ); |
|
| 115 | - $objects[] = $this->prepare_response_for_collection( $data ); |
|
| 113 | + foreach ($query_results['objects'] as $object) { |
|
| 114 | + $data = $this->prepare_object_for_response($object, $request); |
|
| 115 | + $objects[] = $this->prepare_response_for_collection($data); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | $page = (int) $query_args['paged']; |
| 119 | 119 | $max_pages = $query_results['pages']; |
| 120 | 120 | |
| 121 | - $response = rest_ensure_response( $objects ); |
|
| 122 | - $response->header( 'X-WP-Total', $query_results['total'] ); |
|
| 123 | - $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
| 124 | - $response->header( 'X-Woo-Notice', __( 'Private REST API for use by block editor only.', 'woocommerce' ) ); |
|
| 121 | + $response = rest_ensure_response($objects); |
|
| 122 | + $response->header('X-WP-Total', $query_results['total']); |
|
| 123 | + $response->header('X-WP-TotalPages', (int) $max_pages); |
|
| 124 | + $response->header('X-Woo-Notice', __('Private REST API for use by block editor only.', 'woocommerce')); |
|
| 125 | 125 | |
| 126 | 126 | $base = $this->rest_base; |
| 127 | 127 | $attrib_prefix = '(?P<'; |
| 128 | - if ( strpos( $base, $attrib_prefix ) !== false ) { |
|
| 128 | + if (strpos($base, $attrib_prefix) !== false) { |
|
| 129 | 129 | $attrib_names = array(); |
| 130 | - preg_match( '/\(\?P<[^>]+>.*\)/', $base, $attrib_names, PREG_OFFSET_CAPTURE ); |
|
| 131 | - foreach ( $attrib_names as $attrib_name_match ) { |
|
| 132 | - $beginning_offset = strlen( $attrib_prefix ); |
|
| 133 | - $attrib_name_end = strpos( $attrib_name_match[0], '>', $attrib_name_match[1] ); |
|
| 134 | - $attrib_name = substr( $attrib_name_match[0], $beginning_offset, $attrib_name_end - $beginning_offset ); |
|
| 135 | - if ( isset( $request[ $attrib_name ] ) ) { |
|
| 136 | - $base = str_replace( "(?P<$attrib_name>[\d]+)", $request[ $attrib_name ], $base ); |
|
| 130 | + preg_match('/\(\?P<[^>]+>.*\)/', $base, $attrib_names, PREG_OFFSET_CAPTURE); |
|
| 131 | + foreach ($attrib_names as $attrib_name_match) { |
|
| 132 | + $beginning_offset = strlen($attrib_prefix); |
|
| 133 | + $attrib_name_end = strpos($attrib_name_match[0], '>', $attrib_name_match[1]); |
|
| 134 | + $attrib_name = substr($attrib_name_match[0], $beginning_offset, $attrib_name_end - $beginning_offset); |
|
| 135 | + if (isset($request[$attrib_name])) { |
|
| 136 | + $base = str_replace("(?P<$attrib_name>[\d]+)", $request[$attrib_name], $base); |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ) ); |
|
| 140 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $base))); |
|
| 141 | 141 | |
| 142 | - if ( $page > 1 ) { |
|
| 142 | + if ($page > 1) { |
|
| 143 | 143 | $prev_page = $page - 1; |
| 144 | - if ( $prev_page > $max_pages ) { |
|
| 144 | + if ($prev_page > $max_pages) { |
|
| 145 | 145 | $prev_page = $max_pages; |
| 146 | 146 | } |
| 147 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 148 | - $response->link_header( 'prev', $prev_link ); |
|
| 147 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 148 | + $response->link_header('prev', $prev_link); |
|
| 149 | 149 | } |
| 150 | - if ( $max_pages > $page ) { |
|
| 150 | + if ($max_pages > $page) { |
|
| 151 | 151 | $next_page = $page + 1; |
| 152 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 153 | - $response->link_header( 'next', $next_link ); |
|
| 152 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 153 | + $response->link_header('next', $next_link); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | return $response; |
@@ -162,35 +162,35 @@ discard block |
||
| 162 | 162 | * @param WC_Product|WC_Product_Variation $product Product instance. |
| 163 | 163 | * @return array |
| 164 | 164 | */ |
| 165 | - protected function get_images( $product ) { |
|
| 165 | + protected function get_images($product) { |
|
| 166 | 166 | $images = array(); |
| 167 | 167 | $attachment_ids = array(); |
| 168 | 168 | |
| 169 | 169 | // Add featured image. |
| 170 | - if ( has_post_thumbnail( $product->get_id() ) ) { |
|
| 170 | + if (has_post_thumbnail($product->get_id())) { |
|
| 171 | 171 | $attachment_ids[] = $product->get_image_id(); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // Add gallery images. |
| 175 | - $attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() ); |
|
| 175 | + $attachment_ids = array_merge($attachment_ids, $product->get_gallery_image_ids()); |
|
| 176 | 176 | |
| 177 | 177 | // Build image data. |
| 178 | - foreach ( $attachment_ids as $attachment_id ) { |
|
| 179 | - $attachment_post = get_post( $attachment_id ); |
|
| 180 | - if ( is_null( $attachment_post ) ) { |
|
| 178 | + foreach ($attachment_ids as $attachment_id) { |
|
| 179 | + $attachment_post = get_post($attachment_id); |
|
| 180 | + if (is_null($attachment_post)) { |
|
| 181 | 181 | continue; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - $attachment = wp_get_attachment_image_src( $attachment_id, 'full' ); |
|
| 185 | - if ( ! is_array( $attachment ) ) { |
|
| 184 | + $attachment = wp_get_attachment_image_src($attachment_id, 'full'); |
|
| 185 | + if ( ! is_array($attachment)) { |
|
| 186 | 186 | continue; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | $images[] = array( |
| 190 | 190 | 'id' => (int) $attachment_id, |
| 191 | - 'src' => current( $attachment ), |
|
| 192 | - 'name' => get_the_title( $attachment_id ), |
|
| 193 | - 'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ), |
|
| 191 | + 'src' => current($attachment), |
|
| 192 | + 'name' => get_the_title($attachment_id), |
|
| 193 | + 'alt' => get_post_meta($attachment_id, '_wp_attachment_image_alt', true), |
|
| 194 | 194 | ); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -206,18 +206,18 @@ discard block |
||
| 206 | 206 | * @param WP_REST_Request $request Request object. |
| 207 | 207 | * @return WP_REST_Response |
| 208 | 208 | */ |
| 209 | - public function prepare_item_for_response( $post, $request ) { |
|
| 210 | - $product = wc_get_product( $post ); |
|
| 211 | - $data = $this->get_product_data( $product ); |
|
| 209 | + public function prepare_item_for_response($post, $request) { |
|
| 210 | + $product = wc_get_product($post); |
|
| 211 | + $data = $this->get_product_data($product); |
|
| 212 | 212 | |
| 213 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 214 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 215 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 213 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 214 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 215 | + $data = $this->filter_response_by_context($data, $context); |
|
| 216 | 216 | |
| 217 | 217 | // Wrap the data in a response object. |
| 218 | - $response = rest_ensure_response( $data ); |
|
| 219 | - $response->header( 'X-Woo-Notice', __( 'Private REST API for use by block editor only.', 'woocommerce' ) ); |
|
| 220 | - $response->add_links( $this->prepare_links( $product, $request ) ); |
|
| 218 | + $response = rest_ensure_response($data); |
|
| 219 | + $response->header('X-Woo-Notice', __('Private REST API for use by block editor only.', 'woocommerce')); |
|
| 220 | + $response->add_links($this->prepare_links($product, $request)); |
|
| 221 | 221 | |
| 222 | 222 | return $response; |
| 223 | 223 | } |
@@ -229,52 +229,52 @@ discard block |
||
| 229 | 229 | * @param WP_REST_Request $request Request data. |
| 230 | 230 | * @return array |
| 231 | 231 | */ |
| 232 | - protected function prepare_objects_query( $request ) { |
|
| 233 | - $args = parent::prepare_objects_query( $request ); |
|
| 232 | + protected function prepare_objects_query($request) { |
|
| 233 | + $args = parent::prepare_objects_query($request); |
|
| 234 | 234 | $operator_mapping = array( |
| 235 | 235 | 'in' => 'IN', |
| 236 | 236 | 'not_in' => 'NOT IN', |
| 237 | 237 | 'and' => 'AND', |
| 238 | 238 | ); |
| 239 | 239 | |
| 240 | - $orderby = $request->get_param( 'orderby' ); |
|
| 241 | - $order = $request->get_param( 'order' ); |
|
| 242 | - $category_operator = $operator_mapping[ $request->get_param( 'category_operator' ) ]; |
|
| 243 | - $attribute_operator = $operator_mapping[ $request->get_param( 'attribute_operator' ) ]; |
|
| 244 | - $catalog_visibility = $request->get_param( 'catalog_visibility' ); |
|
| 240 | + $orderby = $request->get_param('orderby'); |
|
| 241 | + $order = $request->get_param('order'); |
|
| 242 | + $category_operator = $operator_mapping[$request->get_param('category_operator')]; |
|
| 243 | + $attribute_operator = $operator_mapping[$request->get_param('attribute_operator')]; |
|
| 244 | + $catalog_visibility = $request->get_param('catalog_visibility'); |
|
| 245 | 245 | |
| 246 | - $ordering_args = WC()->query->get_catalog_ordering_args( $orderby, $order ); |
|
| 246 | + $ordering_args = WC()->query->get_catalog_ordering_args($orderby, $order); |
|
| 247 | 247 | $args['orderby'] = $ordering_args['orderby']; |
| 248 | 248 | $args['order'] = $ordering_args['order']; |
| 249 | - if ( $ordering_args['meta_key'] ) { |
|
| 249 | + if ($ordering_args['meta_key']) { |
|
| 250 | 250 | $args['meta_key'] = $ordering_args['meta_key']; // WPCS: slow query ok. |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if ( $category_operator && isset( $args['tax_query'] ) ) { |
|
| 254 | - foreach ( $args['tax_query'] as $i => $tax_query ) { |
|
| 255 | - if ( 'product_cat' === $tax_query['taxonomy'] ) { |
|
| 256 | - $args['tax_query'][ $i ]['operator'] = $category_operator; |
|
| 257 | - $args['tax_query'][ $i ]['include_children'] = 'AND' === $category_operator ? false : true; |
|
| 253 | + if ($category_operator && isset($args['tax_query'])) { |
|
| 254 | + foreach ($args['tax_query'] as $i => $tax_query) { |
|
| 255 | + if ('product_cat' === $tax_query['taxonomy']) { |
|
| 256 | + $args['tax_query'][$i]['operator'] = $category_operator; |
|
| 257 | + $args['tax_query'][$i]['include_children'] = 'AND' === $category_operator ? false : true; |
|
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if ( $attribute_operator && isset( $args['tax_query'] ) ) { |
|
| 263 | - foreach ( $args['tax_query'] as $i => $tax_query ) { |
|
| 264 | - if ( in_array( $tax_query['taxonomy'], wc_get_attribute_taxonomy_names(), true ) ) { |
|
| 265 | - $args['tax_query'][ $i ]['operator'] = $attribute_operator; |
|
| 262 | + if ($attribute_operator && isset($args['tax_query'])) { |
|
| 263 | + foreach ($args['tax_query'] as $i => $tax_query) { |
|
| 264 | + if (in_array($tax_query['taxonomy'], wc_get_attribute_taxonomy_names(), true)) { |
|
| 265 | + $args['tax_query'][$i]['operator'] = $attribute_operator; |
|
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - if ( in_array( $catalog_visibility, array_keys( wc_get_product_visibility_options() ), true ) ) { |
|
| 270 | + if (in_array($catalog_visibility, array_keys(wc_get_product_visibility_options()), true)) { |
|
| 271 | 271 | $exclude_from_catalog = 'search' === $catalog_visibility ? '' : 'exclude-from-catalog'; |
| 272 | 272 | $exclude_from_search = 'catalog' === $catalog_visibility ? '' : 'exclude-from-search'; |
| 273 | 273 | |
| 274 | 274 | $args['tax_query'][] = array( |
| 275 | 275 | 'taxonomy' => 'product_visibility', |
| 276 | 276 | 'field' => 'name', |
| 277 | - 'terms' => array( $exclude_from_catalog, $exclude_from_search ), |
|
| 277 | + 'terms' => array($exclude_from_catalog, $exclude_from_search), |
|
| 278 | 278 | 'operator' => 'hidden' === $catalog_visibility ? 'AND' : 'NOT IN', |
| 279 | 279 | ); |
| 280 | 280 | } |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | * Options: 'view' and 'edit'. |
| 291 | 291 | * @return array |
| 292 | 292 | */ |
| 293 | - protected function get_product_data( $product, $context = 'view' ) { |
|
| 294 | - $raw_data = parent::get_product_data( $product, $context ); |
|
| 293 | + protected function get_product_data($product, $context = 'view') { |
|
| 294 | + $raw_data = parent::get_product_data($product, $context); |
|
| 295 | 295 | $data = array(); |
| 296 | 296 | |
| 297 | 297 | $data['id'] = $raw_data['id']; |
@@ -317,27 +317,27 @@ discard block |
||
| 317 | 317 | */ |
| 318 | 318 | public function get_collection_params() { |
| 319 | 319 | $params = parent::get_collection_params(); |
| 320 | - $params['orderby']['enum'] = array_merge( $params['orderby']['enum'], array( 'price', 'popularity', 'rating', 'menu_order' ) ); |
|
| 320 | + $params['orderby']['enum'] = array_merge($params['orderby']['enum'], array('price', 'popularity', 'rating', 'menu_order')); |
|
| 321 | 321 | $params['category_operator'] = array( |
| 322 | - 'description' => __( 'Operator to compare product category terms.', 'woocommerce' ), |
|
| 322 | + 'description' => __('Operator to compare product category terms.', 'woocommerce'), |
|
| 323 | 323 | 'type' => 'string', |
| 324 | - 'enum' => array( 'in', 'not_in', 'and' ), |
|
| 324 | + 'enum' => array('in', 'not_in', 'and'), |
|
| 325 | 325 | 'default' => 'in', |
| 326 | 326 | 'sanitize_callback' => 'sanitize_key', |
| 327 | 327 | 'validate_callback' => 'rest_validate_request_arg', |
| 328 | 328 | ); |
| 329 | 329 | $params['attribute_operator'] = array( |
| 330 | - 'description' => __( 'Operator to compare product attribute terms.', 'woocommerce' ), |
|
| 330 | + 'description' => __('Operator to compare product attribute terms.', 'woocommerce'), |
|
| 331 | 331 | 'type' => 'string', |
| 332 | - 'enum' => array( 'in', 'not_in', 'and' ), |
|
| 332 | + 'enum' => array('in', 'not_in', 'and'), |
|
| 333 | 333 | 'default' => 'in', |
| 334 | 334 | 'sanitize_callback' => 'sanitize_key', |
| 335 | 335 | 'validate_callback' => 'rest_validate_request_arg', |
| 336 | 336 | ); |
| 337 | 337 | $params['catalog_visibility'] = array( |
| 338 | - 'description' => __( 'Determines if hidden or visible catalog products are shown.', 'woocommerce' ), |
|
| 338 | + 'description' => __('Determines if hidden or visible catalog products are shown.', 'woocommerce'), |
|
| 339 | 339 | 'type' => 'string', |
| 340 | - 'enum' => array( 'visible', 'catalog', 'search', 'hidden' ), |
|
| 340 | + 'enum' => array('visible', 'catalog', 'search', 'hidden'), |
|
| 341 | 341 | 'sanitize_callback' => 'sanitize_key', |
| 342 | 342 | 'validate_callback' => 'rest_validate_request_arg', |
| 343 | 343 | ); |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | $schema['properties']['images'] = array( |
| 372 | 372 | 'description' => $raw_schema['properties']['images']['description'], |
| 373 | 373 | 'type' => 'object', |
| 374 | - 'context' => array( 'view', 'edit' ), |
|
| 374 | + 'context' => array('view', 'edit'), |
|
| 375 | 375 | 'items' => array( |
| 376 | 376 | 'type' => 'object', |
| 377 | 377 | 'properties' => array(), |
@@ -385,6 +385,6 @@ discard block |
||
| 385 | 385 | $schema['properties']['images']['items']['properties']['name'] = $images_schema['name']; |
| 386 | 386 | $schema['properties']['images']['items']['properties']['alt'] = $images_schema['alt']; |
| 387 | 387 | |
| 388 | - return $this->add_additional_fields_schema( $schema ); |
|
| 388 | + return $this->add_additional_fields_schema($schema); |
|
| 389 | 389 | } |
| 390 | 390 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @package WooCommerce/RestApi |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if ( ! defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | array( |
| 37 | 37 | array( |
| 38 | 38 | 'methods' => WP_REST_Server::READABLE, |
| 39 | - 'callback' => array( $this, 'get_items' ), |
|
| 40 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 39 | + 'callback' => array($this, 'get_items'), |
|
| 40 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 41 | 41 | 'args' => $this->get_collection_params(), |
| 42 | 42 | ), |
| 43 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 43 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 44 | 44 | ) |
| 45 | 45 | ); |
| 46 | 46 | |
@@ -50,14 +50,14 @@ discard block |
||
| 50 | 50 | array( |
| 51 | 51 | 'args' => array( |
| 52 | 52 | 'id' => array( |
| 53 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 53 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 54 | 54 | 'type' => 'integer', |
| 55 | 55 | ), |
| 56 | 56 | ), |
| 57 | 57 | array( |
| 58 | 58 | 'methods' => WP_REST_Server::READABLE, |
| 59 | - 'callback' => array( $this, 'get_item' ), |
|
| 60 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 59 | + 'callback' => array($this, 'get_item'), |
|
| 60 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 61 | 61 | 'args' => array( |
| 62 | 62 | 'context' => $this->get_context_param( |
| 63 | 63 | array( |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | ), |
| 67 | 67 | ), |
| 68 | 68 | ), |
| 69 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 69 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 70 | 70 | ) |
| 71 | 71 | ); |
| 72 | 72 | } |
@@ -78,24 +78,24 @@ discard block |
||
| 78 | 78 | * @param string $context Request context. |
| 79 | 79 | * @return bool|WP_Error |
| 80 | 80 | */ |
| 81 | - protected function check_permissions( $request, $context = 'read' ) { |
|
| 81 | + protected function check_permissions($request, $context = 'read') { |
|
| 82 | 82 | // Get taxonomy. |
| 83 | - $taxonomy = $this->get_taxonomy( $request ); |
|
| 84 | - if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) { |
|
| 85 | - return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Taxonomy does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 83 | + $taxonomy = $this->get_taxonomy($request); |
|
| 84 | + if ( ! $taxonomy || ! taxonomy_exists($taxonomy)) { |
|
| 85 | + return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Taxonomy does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // Check permissions for a single term. |
| 89 | - $id = intval( $request['id'] ); |
|
| 90 | - if ( $id ) { |
|
| 91 | - $term = get_term( $id, $taxonomy ); |
|
| 89 | + $id = intval($request['id']); |
|
| 90 | + if ($id) { |
|
| 91 | + $term = get_term($id, $taxonomy); |
|
| 92 | 92 | |
| 93 | - if ( is_wp_error( $term ) || ! $term || $term->taxonomy !== $taxonomy ) { |
|
| 94 | - return new WP_Error( 'woocommerce_rest_term_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 93 | + if (is_wp_error($term) || ! $term || $term->taxonomy !== $taxonomy) { |
|
| 94 | + return new WP_Error('woocommerce_rest_term_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - return current_user_can( 'edit_posts' ); |
|
| 98 | + return current_user_can('edit_posts'); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -105,10 +105,10 @@ discard block |
||
| 105 | 105 | * @param WP_REST_Request $request Request instance. |
| 106 | 106 | * @return WP_REST_Response |
| 107 | 107 | */ |
| 108 | - public function prepare_item_for_response( $item, $request ) { |
|
| 108 | + public function prepare_item_for_response($item, $request) { |
|
| 109 | 109 | // Get the attribute slug. |
| 110 | - $attribute_id = absint( $request->get_param( 'attribute_id' ) ); |
|
| 111 | - $attribute = wc_get_attribute( $attribute_id ); |
|
| 110 | + $attribute_id = absint($request->get_param('attribute_id')); |
|
| 111 | + $attribute = wc_get_attribute($attribute_id); |
|
| 112 | 112 | |
| 113 | 113 | $data = array( |
| 114 | 114 | 'id' => (int) $item->term_id, |
@@ -122,15 +122,15 @@ discard block |
||
| 122 | 122 | ), |
| 123 | 123 | ); |
| 124 | 124 | |
| 125 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 126 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 127 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 125 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 126 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 127 | + $data = $this->filter_response_by_context($data, $context); |
|
| 128 | 128 | |
| 129 | - $response = rest_ensure_response( $data ); |
|
| 129 | + $response = rest_ensure_response($data); |
|
| 130 | 130 | |
| 131 | - $response->header( 'X-Woo-Notice', __( 'Private REST API for use by block editor only.', 'woocommerce' ) ); |
|
| 131 | + $response->header('X-Woo-Notice', __('Private REST API for use by block editor only.', 'woocommerce')); |
|
| 132 | 132 | |
| 133 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
| 133 | + $response->add_links($this->prepare_links($item, $request)); |
|
| 134 | 134 | |
| 135 | 135 | return $response; |
| 136 | 136 | } |
@@ -154,32 +154,32 @@ discard block |
||
| 154 | 154 | $schema['properties']['slug'] = $raw_schema['properties']['slug']; |
| 155 | 155 | $schema['properties']['count'] = $raw_schema['properties']['count']; |
| 156 | 156 | $schema['properties']['attribute'] = array( |
| 157 | - 'description' => __( 'Attribute.', 'woocommerce' ), |
|
| 157 | + 'description' => __('Attribute.', 'woocommerce'), |
|
| 158 | 158 | 'type' => 'object', |
| 159 | - 'context' => array( 'view', 'edit' ), |
|
| 159 | + 'context' => array('view', 'edit'), |
|
| 160 | 160 | 'readonly' => true, |
| 161 | 161 | 'properties' => array( |
| 162 | 162 | 'id' => array( |
| 163 | - 'description' => __( 'Attribute ID.', 'woocommerce' ), |
|
| 163 | + 'description' => __('Attribute ID.', 'woocommerce'), |
|
| 164 | 164 | 'type' => 'integer', |
| 165 | - 'context' => array( 'view', 'edit' ), |
|
| 165 | + 'context' => array('view', 'edit'), |
|
| 166 | 166 | 'readonly' => true, |
| 167 | 167 | ), |
| 168 | 168 | 'name' => array( |
| 169 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
| 169 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
| 170 | 170 | 'type' => 'string', |
| 171 | - 'context' => array( 'view', 'edit' ), |
|
| 171 | + 'context' => array('view', 'edit'), |
|
| 172 | 172 | 'readonly' => true, |
| 173 | 173 | ), |
| 174 | 174 | 'slug' => array( |
| 175 | - 'description' => __( 'Attribute slug.', 'woocommerce' ), |
|
| 175 | + 'description' => __('Attribute slug.', 'woocommerce'), |
|
| 176 | 176 | 'type' => 'string', |
| 177 | - 'context' => array( 'view', 'edit' ), |
|
| 177 | + 'context' => array('view', 'edit'), |
|
| 178 | 178 | 'readonly' => true, |
| 179 | 179 | ), |
| 180 | 180 | ), |
| 181 | 181 | ); |
| 182 | 182 | |
| 183 | - return $this->add_additional_fields_schema( $schema ); |
|
| 183 | + return $this->add_additional_fields_schema($schema); |
|
| 184 | 184 | } |
| 185 | 185 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @since 3.0.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Shipping methods controller class. |
@@ -40,30 +40,30 @@ discard block |
||
| 40 | 40 | $this->namespace, '/' . $this->rest_base, array( |
| 41 | 41 | array( |
| 42 | 42 | 'methods' => WP_REST_Server::READABLE, |
| 43 | - 'callback' => array( $this, 'get_items' ), |
|
| 44 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 43 | + 'callback' => array($this, 'get_items'), |
|
| 44 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 45 | 45 | 'args' => $this->get_collection_params(), |
| 46 | 46 | ), |
| 47 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 47 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 48 | 48 | ) |
| 49 | 49 | ); |
| 50 | 50 | register_rest_route( |
| 51 | 51 | $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array( |
| 52 | 52 | 'args' => array( |
| 53 | 53 | 'id' => array( |
| 54 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 54 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 55 | 55 | 'type' => 'string', |
| 56 | 56 | ), |
| 57 | 57 | ), |
| 58 | 58 | array( |
| 59 | 59 | 'methods' => WP_REST_Server::READABLE, |
| 60 | - 'callback' => array( $this, 'get_item' ), |
|
| 61 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 60 | + 'callback' => array($this, 'get_item'), |
|
| 61 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 62 | 62 | 'args' => array( |
| 63 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 63 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 64 | 64 | ), |
| 65 | 65 | ), |
| 66 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 66 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 67 | 67 | ) |
| 68 | 68 | ); |
| 69 | 69 | } |
@@ -74,9 +74,9 @@ discard block |
||
| 74 | 74 | * @param WP_REST_Request $request Full details about the request. |
| 75 | 75 | * @return WP_Error|boolean |
| 76 | 76 | */ |
| 77 | - public function get_items_permissions_check( $request ) { |
|
| 78 | - if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) { |
|
| 79 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 77 | + public function get_items_permissions_check($request) { |
|
| 78 | + if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) { |
|
| 79 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 80 | 80 | } |
| 81 | 81 | return true; |
| 82 | 82 | } |
@@ -87,9 +87,9 @@ 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 get_item_permissions_check( $request ) { |
|
| 91 | - if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) { |
|
| 92 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 90 | + public function get_item_permissions_check($request) { |
|
| 91 | + if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) { |
|
| 92 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 93 | 93 | } |
| 94 | 94 | return true; |
| 95 | 95 | } |
@@ -100,15 +100,15 @@ discard block |
||
| 100 | 100 | * @param WP_REST_Request $request Full details about the request. |
| 101 | 101 | * @return WP_Error|WP_REST_Response |
| 102 | 102 | */ |
| 103 | - public function get_items( $request ) { |
|
| 103 | + public function get_items($request) { |
|
| 104 | 104 | $wc_shipping = WC_Shipping::instance(); |
| 105 | 105 | $response = array(); |
| 106 | - foreach ( $wc_shipping->get_shipping_methods() as $id => $shipping_method ) { |
|
| 107 | - $method = $this->prepare_item_for_response( $shipping_method, $request ); |
|
| 108 | - $method = $this->prepare_response_for_collection( $method ); |
|
| 106 | + foreach ($wc_shipping->get_shipping_methods() as $id => $shipping_method) { |
|
| 107 | + $method = $this->prepare_item_for_response($shipping_method, $request); |
|
| 108 | + $method = $this->prepare_response_for_collection($method); |
|
| 109 | 109 | $response[] = $method; |
| 110 | 110 | } |
| 111 | - return rest_ensure_response( $response ); |
|
| 111 | + return rest_ensure_response($response); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -117,17 +117,17 @@ discard block |
||
| 117 | 117 | * @param WP_REST_Request $request Request data. |
| 118 | 118 | * @return WP_REST_Response|WP_Error |
| 119 | 119 | */ |
| 120 | - public function get_item( $request ) { |
|
| 120 | + public function get_item($request) { |
|
| 121 | 121 | $wc_shipping = WC_Shipping::instance(); |
| 122 | 122 | $methods = $wc_shipping->get_shipping_methods(); |
| 123 | - if ( empty( $methods[ $request['id'] ] ) ) { |
|
| 124 | - return new WP_Error( 'woocommerce_rest_shipping_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 123 | + if (empty($methods[$request['id']])) { |
|
| 124 | + return new WP_Error('woocommerce_rest_shipping_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - $method = $methods[ $request['id'] ]; |
|
| 128 | - $response = $this->prepare_item_for_response( $method, $request ); |
|
| 127 | + $method = $methods[$request['id']]; |
|
| 128 | + $response = $this->prepare_item_for_response($method, $request); |
|
| 129 | 129 | |
| 130 | - return rest_ensure_response( $response ); |
|
| 130 | + return rest_ensure_response($response); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -137,21 +137,21 @@ discard block |
||
| 137 | 137 | * @param WP_REST_Request $request Request object. |
| 138 | 138 | * @return WP_REST_Response $response Response data. |
| 139 | 139 | */ |
| 140 | - public function prepare_item_for_response( $method, $request ) { |
|
| 140 | + public function prepare_item_for_response($method, $request) { |
|
| 141 | 141 | $data = array( |
| 142 | 142 | 'id' => $method->id, |
| 143 | 143 | 'title' => $method->method_title, |
| 144 | 144 | 'description' => $method->method_description, |
| 145 | 145 | ); |
| 146 | 146 | |
| 147 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 148 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 149 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 147 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 148 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 149 | + $data = $this->filter_response_by_context($data, $context); |
|
| 150 | 150 | |
| 151 | 151 | // Wrap the data in a response object. |
| 152 | - $response = rest_ensure_response( $data ); |
|
| 152 | + $response = rest_ensure_response($data); |
|
| 153 | 153 | |
| 154 | - $response->add_links( $this->prepare_links( $method, $request ) ); |
|
| 154 | + $response->add_links($this->prepare_links($method, $request)); |
|
| 155 | 155 | |
| 156 | 156 | /** |
| 157 | 157 | * Filter shipping methods object returned from the REST API. |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * @param WC_Shipping_Method $method Shipping method object used to create response. |
| 161 | 161 | * @param WP_REST_Request $request Request object. |
| 162 | 162 | */ |
| 163 | - return apply_filters( 'woocommerce_rest_prepare_shipping_method', $response, $method, $request ); |
|
| 163 | + return apply_filters('woocommerce_rest_prepare_shipping_method', $response, $method, $request); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -170,13 +170,13 @@ discard block |
||
| 170 | 170 | * @param WP_REST_Request $request Request object. |
| 171 | 171 | * @return array |
| 172 | 172 | */ |
| 173 | - protected function prepare_links( $method, $request ) { |
|
| 173 | + protected function prepare_links($method, $request) { |
|
| 174 | 174 | $links = array( |
| 175 | 175 | 'self' => array( |
| 176 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $method->id ) ), |
|
| 176 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $method->id)), |
|
| 177 | 177 | ), |
| 178 | 178 | 'collection' => array( |
| 179 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
| 179 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
| 180 | 180 | ), |
| 181 | 181 | ); |
| 182 | 182 | |
@@ -195,27 +195,27 @@ discard block |
||
| 195 | 195 | 'type' => 'object', |
| 196 | 196 | 'properties' => array( |
| 197 | 197 | 'id' => array( |
| 198 | - 'description' => __( 'Method ID.', 'woocommerce' ), |
|
| 198 | + 'description' => __('Method ID.', 'woocommerce'), |
|
| 199 | 199 | 'type' => 'string', |
| 200 | - 'context' => array( 'view' ), |
|
| 200 | + 'context' => array('view'), |
|
| 201 | 201 | 'readonly' => true, |
| 202 | 202 | ), |
| 203 | 203 | 'title' => array( |
| 204 | - 'description' => __( 'Shipping method title.', 'woocommerce' ), |
|
| 204 | + 'description' => __('Shipping method title.', 'woocommerce'), |
|
| 205 | 205 | 'type' => 'string', |
| 206 | - 'context' => array( 'view' ), |
|
| 206 | + 'context' => array('view'), |
|
| 207 | 207 | 'readonly' => true, |
| 208 | 208 | ), |
| 209 | 209 | 'description' => array( |
| 210 | - 'description' => __( 'Shipping method description.', 'woocommerce' ), |
|
| 210 | + 'description' => __('Shipping method description.', 'woocommerce'), |
|
| 211 | 211 | 'type' => 'string', |
| 212 | - 'context' => array( 'view' ), |
|
| 212 | + 'context' => array('view'), |
|
| 213 | 213 | 'readonly' => true, |
| 214 | 214 | ), |
| 215 | 215 | ), |
| 216 | 216 | ); |
| 217 | 217 | |
| 218 | - return $this->add_additional_fields_schema( $schema ); |
|
| 218 | + return $this->add_additional_fields_schema($schema); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | public function get_collection_params() { |
| 227 | 227 | return array( |
| 228 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 228 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 229 | 229 | ); |
| 230 | 230 | } |
| 231 | 231 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @since 3.0.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * REST API Shipping Zones class. |
@@ -26,24 +26,24 @@ discard block |
||
| 26 | 26 | $this->namespace, '/' . $this->rest_base, array( |
| 27 | 27 | array( |
| 28 | 28 | 'methods' => WP_REST_Server::READABLE, |
| 29 | - 'callback' => array( $this, 'get_items' ), |
|
| 30 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 29 | + 'callback' => array($this, 'get_items'), |
|
| 30 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 31 | 31 | ), |
| 32 | 32 | array( |
| 33 | 33 | 'methods' => WP_REST_Server::CREATABLE, |
| 34 | - 'callback' => array( $this, 'create_item' ), |
|
| 35 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
| 34 | + 'callback' => array($this, 'create_item'), |
|
| 35 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
| 36 | 36 | 'args' => array_merge( |
| 37 | - $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
| 37 | + $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
| 38 | 38 | 'name' => array( |
| 39 | 39 | 'required' => true, |
| 40 | 40 | 'type' => 'string', |
| 41 | - 'description' => __( 'Shipping zone name.', 'woocommerce' ), |
|
| 41 | + 'description' => __('Shipping zone name.', 'woocommerce'), |
|
| 42 | 42 | ), |
| 43 | 43 | ) |
| 44 | 44 | ), |
| 45 | 45 | ), |
| 46 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 46 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 47 | 47 | ) |
| 48 | 48 | ); |
| 49 | 49 | |
@@ -51,34 +51,34 @@ discard block |
||
| 51 | 51 | $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d-]+)', array( |
| 52 | 52 | 'args' => array( |
| 53 | 53 | 'id' => array( |
| 54 | - 'description' => __( 'Unique ID for the resource.', 'woocommerce' ), |
|
| 54 | + 'description' => __('Unique ID for the resource.', 'woocommerce'), |
|
| 55 | 55 | 'type' => 'integer', |
| 56 | 56 | ), |
| 57 | 57 | ), |
| 58 | 58 | array( |
| 59 | 59 | 'methods' => WP_REST_Server::READABLE, |
| 60 | - 'callback' => array( $this, 'get_item' ), |
|
| 61 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 60 | + 'callback' => array($this, 'get_item'), |
|
| 61 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 62 | 62 | ), |
| 63 | 63 | array( |
| 64 | 64 | 'methods' => WP_REST_Server::EDITABLE, |
| 65 | - 'callback' => array( $this, 'update_item' ), |
|
| 66 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
| 67 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
| 65 | + 'callback' => array($this, 'update_item'), |
|
| 66 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
| 67 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
| 68 | 68 | ), |
| 69 | 69 | array( |
| 70 | 70 | 'methods' => WP_REST_Server::DELETABLE, |
| 71 | - 'callback' => array( $this, 'delete_item' ), |
|
| 72 | - 'permission_callback' => array( $this, 'delete_items_permissions_check' ), |
|
| 71 | + 'callback' => array($this, 'delete_item'), |
|
| 72 | + 'permission_callback' => array($this, 'delete_items_permissions_check'), |
|
| 73 | 73 | 'args' => array( |
| 74 | 74 | 'force' => array( |
| 75 | 75 | 'default' => false, |
| 76 | 76 | 'type' => 'boolean', |
| 77 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
| 77 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
| 78 | 78 | ), |
| 79 | 79 | ), |
| 80 | 80 | ), |
| 81 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 81 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 82 | 82 | ) |
| 83 | 83 | ); |
| 84 | 84 | } |
@@ -89,18 +89,18 @@ discard block |
||
| 89 | 89 | * @param WP_REST_Request $request Request data. |
| 90 | 90 | * @return WP_REST_Response|WP_Error |
| 91 | 91 | */ |
| 92 | - public function get_item( $request ) { |
|
| 93 | - $zone = $this->get_zone( $request->get_param( 'id' ) ); |
|
| 92 | + public function get_item($request) { |
|
| 93 | + $zone = $this->get_zone($request->get_param('id')); |
|
| 94 | 94 | |
| 95 | - if ( is_wp_error( $zone ) ) { |
|
| 95 | + if (is_wp_error($zone)) { |
|
| 96 | 96 | return $zone; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | $data = $zone->get_data(); |
| 100 | - $data = $this->prepare_item_for_response( $data, $request ); |
|
| 101 | - $data = $this->prepare_response_for_collection( $data ); |
|
| 100 | + $data = $this->prepare_item_for_response($data, $request); |
|
| 101 | + $data = $this->prepare_response_for_collection($data); |
|
| 102 | 102 | |
| 103 | - return rest_ensure_response( $data ); |
|
| 103 | + return rest_ensure_response($data); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -109,20 +109,20 @@ discard block |
||
| 109 | 109 | * @param WP_REST_Request $request Request data. |
| 110 | 110 | * @return WP_REST_Response |
| 111 | 111 | */ |
| 112 | - public function get_items( $request ) { |
|
| 113 | - $rest_of_the_world = WC_Shipping_Zones::get_zone_by( 'zone_id', 0 ); |
|
| 112 | + public function get_items($request) { |
|
| 113 | + $rest_of_the_world = WC_Shipping_Zones::get_zone_by('zone_id', 0); |
|
| 114 | 114 | |
| 115 | 115 | $zones = WC_Shipping_Zones::get_zones(); |
| 116 | - array_unshift( $zones, $rest_of_the_world->get_data() ); |
|
| 116 | + array_unshift($zones, $rest_of_the_world->get_data()); |
|
| 117 | 117 | $data = array(); |
| 118 | 118 | |
| 119 | - foreach ( $zones as $zone_obj ) { |
|
| 120 | - $zone = $this->prepare_item_for_response( $zone_obj, $request ); |
|
| 121 | - $zone = $this->prepare_response_for_collection( $zone ); |
|
| 119 | + foreach ($zones as $zone_obj) { |
|
| 120 | + $zone = $this->prepare_item_for_response($zone_obj, $request); |
|
| 121 | + $zone = $this->prepare_response_for_collection($zone); |
|
| 122 | 122 | $data[] = $zone; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - return rest_ensure_response( $data ); |
|
| 125 | + return rest_ensure_response($data); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -131,27 +131,27 @@ discard block |
||
| 131 | 131 | * @param WP_REST_Request $request Full details about the request. |
| 132 | 132 | * @return WP_REST_Request|WP_Error |
| 133 | 133 | */ |
| 134 | - public function create_item( $request ) { |
|
| 135 | - $zone = new WC_Shipping_Zone( null ); |
|
| 134 | + public function create_item($request) { |
|
| 135 | + $zone = new WC_Shipping_Zone(null); |
|
| 136 | 136 | |
| 137 | - if ( ! is_null( $request->get_param( 'name' ) ) ) { |
|
| 138 | - $zone->set_zone_name( $request->get_param( 'name' ) ); |
|
| 137 | + if ( ! is_null($request->get_param('name'))) { |
|
| 138 | + $zone->set_zone_name($request->get_param('name')); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if ( ! is_null( $request->get_param( 'order' ) ) ) { |
|
| 142 | - $zone->set_zone_order( $request->get_param( 'order' ) ); |
|
| 141 | + if ( ! is_null($request->get_param('order'))) { |
|
| 142 | + $zone->set_zone_order($request->get_param('order')); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | $zone->save(); |
| 146 | 146 | |
| 147 | - if ( $zone->get_id() !== 0 ) { |
|
| 148 | - $request->set_param( 'id', $zone->get_id() ); |
|
| 149 | - $response = $this->get_item( $request ); |
|
| 150 | - $response->set_status( 201 ); |
|
| 151 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $zone->get_id() ) ) ); |
|
| 147 | + if ($zone->get_id() !== 0) { |
|
| 148 | + $request->set_param('id', $zone->get_id()); |
|
| 149 | + $response = $this->get_item($request); |
|
| 150 | + $response->set_status(201); |
|
| 151 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $zone->get_id()))); |
|
| 152 | 152 | return $response; |
| 153 | 153 | } else { |
| 154 | - return new WP_Error( 'woocommerce_rest_shipping_zone_not_created', __( "Resource cannot be created. Check to make sure 'order' and 'name' are present.", 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 154 | + return new WP_Error('woocommerce_rest_shipping_zone_not_created', __("Resource cannot be created. Check to make sure 'order' and 'name' are present.", 'woocommerce'), array('status' => 500)); |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |
@@ -161,34 +161,34 @@ discard block |
||
| 161 | 161 | * @param WP_REST_Request $request Full details about the request. |
| 162 | 162 | * @return WP_REST_Request|WP_Error |
| 163 | 163 | */ |
| 164 | - public function update_item( $request ) { |
|
| 165 | - $zone = $this->get_zone( $request->get_param( 'id' ) ); |
|
| 164 | + public function update_item($request) { |
|
| 165 | + $zone = $this->get_zone($request->get_param('id')); |
|
| 166 | 166 | |
| 167 | - if ( is_wp_error( $zone ) ) { |
|
| 167 | + if (is_wp_error($zone)) { |
|
| 168 | 168 | return $zone; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - if ( 0 === $zone->get_id() ) { |
|
| 172 | - return new WP_Error( 'woocommerce_rest_shipping_zone_invalid_zone', __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) ); |
|
| 171 | + if (0 === $zone->get_id()) { |
|
| 172 | + return new WP_Error('woocommerce_rest_shipping_zone_invalid_zone', __('The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce'), array('status' => 403)); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | $zone_changed = false; |
| 176 | 176 | |
| 177 | - if ( ! is_null( $request->get_param( 'name' ) ) ) { |
|
| 178 | - $zone->set_zone_name( $request->get_param( 'name' ) ); |
|
| 177 | + if ( ! is_null($request->get_param('name'))) { |
|
| 178 | + $zone->set_zone_name($request->get_param('name')); |
|
| 179 | 179 | $zone_changed = true; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if ( ! is_null( $request->get_param( 'order' ) ) ) { |
|
| 183 | - $zone->set_zone_order( $request->get_param( 'order' ) ); |
|
| 182 | + if ( ! is_null($request->get_param('order'))) { |
|
| 183 | + $zone->set_zone_order($request->get_param('order')); |
|
| 184 | 184 | $zone_changed = true; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if ( $zone_changed ) { |
|
| 187 | + if ($zone_changed) { |
|
| 188 | 188 | $zone->save(); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - return $this->get_item( $request ); |
|
| 191 | + return $this->get_item($request); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -197,21 +197,21 @@ discard block |
||
| 197 | 197 | * @param WP_REST_Request $request Full details about the request. |
| 198 | 198 | * @return WP_REST_Request|WP_Error |
| 199 | 199 | */ |
| 200 | - public function delete_item( $request ) { |
|
| 201 | - $zone = $this->get_zone( $request->get_param( 'id' ) ); |
|
| 200 | + public function delete_item($request) { |
|
| 201 | + $zone = $this->get_zone($request->get_param('id')); |
|
| 202 | 202 | |
| 203 | - if ( is_wp_error( $zone ) ) { |
|
| 203 | + if (is_wp_error($zone)) { |
|
| 204 | 204 | return $zone; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | $force = $request['force']; |
| 208 | 208 | |
| 209 | - $response = $this->get_item( $request ); |
|
| 209 | + $response = $this->get_item($request); |
|
| 210 | 210 | |
| 211 | - if ( $force ) { |
|
| 211 | + if ($force) { |
|
| 212 | 212 | $zone->delete(); |
| 213 | 213 | } else { |
| 214 | - return new WP_Error( 'rest_trash_not_supported', __( 'Shipping zones do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
| 214 | + return new WP_Error('rest_trash_not_supported', __('Shipping zones do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | return $response; |
@@ -224,21 +224,21 @@ discard block |
||
| 224 | 224 | * @param WP_REST_Request $request Request object. |
| 225 | 225 | * @return WP_REST_Response $response |
| 226 | 226 | */ |
| 227 | - public function prepare_item_for_response( $item, $request ) { |
|
| 227 | + public function prepare_item_for_response($item, $request) { |
|
| 228 | 228 | $data = array( |
| 229 | 229 | 'id' => (int) $item['id'], |
| 230 | 230 | 'name' => $item['zone_name'], |
| 231 | 231 | 'order' => (int) $item['zone_order'], |
| 232 | 232 | ); |
| 233 | 233 | |
| 234 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
| 235 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 236 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 234 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
| 235 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 236 | + $data = $this->filter_response_by_context($data, $context); |
|
| 237 | 237 | |
| 238 | 238 | // Wrap the data in a response object. |
| 239 | - $response = rest_ensure_response( $data ); |
|
| 239 | + $response = rest_ensure_response($data); |
|
| 240 | 240 | |
| 241 | - $response->add_links( $this->prepare_links( $data['id'] ) ); |
|
| 241 | + $response->add_links($this->prepare_links($data['id'])); |
|
| 242 | 242 | |
| 243 | 243 | return $response; |
| 244 | 244 | } |
@@ -249,17 +249,17 @@ discard block |
||
| 249 | 249 | * @param int $zone_id Given Shipping Zone ID. |
| 250 | 250 | * @return array Links for the given Shipping Zone. |
| 251 | 251 | */ |
| 252 | - protected function prepare_links( $zone_id ) { |
|
| 252 | + protected function prepare_links($zone_id) { |
|
| 253 | 253 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
| 254 | 254 | $links = array( |
| 255 | 255 | 'self' => array( |
| 256 | - 'href' => rest_url( trailingslashit( $base ) . $zone_id ), |
|
| 256 | + 'href' => rest_url(trailingslashit($base) . $zone_id), |
|
| 257 | 257 | ), |
| 258 | 258 | 'collection' => array( |
| 259 | - 'href' => rest_url( $base ), |
|
| 259 | + 'href' => rest_url($base), |
|
| 260 | 260 | ), |
| 261 | 261 | 'describedby' => array( |
| 262 | - 'href' => rest_url( trailingslashit( $base ) . $zone_id . '/locations' ), |
|
| 262 | + 'href' => rest_url(trailingslashit($base) . $zone_id . '/locations'), |
|
| 263 | 263 | ), |
| 264 | 264 | ); |
| 265 | 265 | |
@@ -278,27 +278,27 @@ discard block |
||
| 278 | 278 | 'type' => 'object', |
| 279 | 279 | 'properties' => array( |
| 280 | 280 | 'id' => array( |
| 281 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 281 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 282 | 282 | 'type' => 'integer', |
| 283 | - 'context' => array( 'view', 'edit' ), |
|
| 283 | + 'context' => array('view', 'edit'), |
|
| 284 | 284 | 'readonly' => true, |
| 285 | 285 | ), |
| 286 | 286 | 'name' => array( |
| 287 | - 'description' => __( 'Shipping zone name.', 'woocommerce' ), |
|
| 287 | + 'description' => __('Shipping zone name.', 'woocommerce'), |
|
| 288 | 288 | 'type' => 'string', |
| 289 | - 'context' => array( 'view', 'edit' ), |
|
| 289 | + 'context' => array('view', 'edit'), |
|
| 290 | 290 | 'arg_options' => array( |
| 291 | 291 | 'sanitize_callback' => 'sanitize_text_field', |
| 292 | 292 | ), |
| 293 | 293 | ), |
| 294 | 294 | 'order' => array( |
| 295 | - 'description' => __( 'Shipping zone order.', 'woocommerce' ), |
|
| 295 | + 'description' => __('Shipping zone order.', 'woocommerce'), |
|
| 296 | 296 | 'type' => 'integer', |
| 297 | - 'context' => array( 'view', 'edit' ), |
|
| 297 | + 'context' => array('view', 'edit'), |
|
| 298 | 298 | ), |
| 299 | 299 | ), |
| 300 | 300 | ); |
| 301 | 301 | |
| 302 | - return $this->add_additional_fields_schema( $schema ); |
|
| 302 | + return $this->add_additional_fields_schema($schema); |
|
| 303 | 303 | } |
| 304 | 304 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @since 3.0.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * REST API Setting Options controller class. |
@@ -42,16 +42,16 @@ discard block |
||
| 42 | 42 | $this->namespace, '/' . $this->rest_base, array( |
| 43 | 43 | 'args' => array( |
| 44 | 44 | 'group' => array( |
| 45 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
| 45 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
| 46 | 46 | 'type' => 'string', |
| 47 | 47 | ), |
| 48 | 48 | ), |
| 49 | 49 | array( |
| 50 | 50 | 'methods' => WP_REST_Server::READABLE, |
| 51 | - 'callback' => array( $this, 'get_items' ), |
|
| 52 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 51 | + 'callback' => array($this, 'get_items'), |
|
| 52 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 53 | 53 | ), |
| 54 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 54 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 55 | 55 | ) |
| 56 | 56 | ); |
| 57 | 57 | |
@@ -59,17 +59,17 @@ discard block |
||
| 59 | 59 | $this->namespace, '/' . $this->rest_base . '/batch', array( |
| 60 | 60 | 'args' => array( |
| 61 | 61 | 'group' => array( |
| 62 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
| 62 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
| 63 | 63 | 'type' => 'string', |
| 64 | 64 | ), |
| 65 | 65 | ), |
| 66 | 66 | array( |
| 67 | 67 | 'methods' => WP_REST_Server::EDITABLE, |
| 68 | - 'callback' => array( $this, 'batch_items' ), |
|
| 69 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
| 70 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
| 68 | + 'callback' => array($this, 'batch_items'), |
|
| 69 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
| 70 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
| 71 | 71 | ), |
| 72 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
| 72 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
| 73 | 73 | ) |
| 74 | 74 | ); |
| 75 | 75 | |
@@ -77,26 +77,26 @@ discard block |
||
| 77 | 77 | $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array( |
| 78 | 78 | 'args' => array( |
| 79 | 79 | 'group' => array( |
| 80 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
| 80 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
| 81 | 81 | 'type' => 'string', |
| 82 | 82 | ), |
| 83 | 83 | 'id' => array( |
| 84 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 84 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 85 | 85 | 'type' => 'string', |
| 86 | 86 | ), |
| 87 | 87 | ), |
| 88 | 88 | array( |
| 89 | 89 | 'methods' => WP_REST_Server::READABLE, |
| 90 | - 'callback' => array( $this, 'get_item' ), |
|
| 91 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 90 | + 'callback' => array($this, 'get_item'), |
|
| 91 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 92 | 92 | ), |
| 93 | 93 | array( |
| 94 | 94 | 'methods' => WP_REST_Server::EDITABLE, |
| 95 | - 'callback' => array( $this, 'update_item' ), |
|
| 96 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
| 97 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
| 95 | + 'callback' => array($this, 'update_item'), |
|
| 96 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
| 97 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
| 98 | 98 | ), |
| 99 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 99 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 100 | 100 | ) |
| 101 | 101 | ); |
| 102 | 102 | } |
@@ -108,16 +108,16 @@ discard block |
||
| 108 | 108 | * @param WP_REST_Request $request Request data. |
| 109 | 109 | * @return WP_Error|WP_REST_Response |
| 110 | 110 | */ |
| 111 | - public function get_item( $request ) { |
|
| 112 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
| 111 | + public function get_item($request) { |
|
| 112 | + $setting = $this->get_setting($request['group_id'], $request['id']); |
|
| 113 | 113 | |
| 114 | - if ( is_wp_error( $setting ) ) { |
|
| 114 | + if (is_wp_error($setting)) { |
|
| 115 | 115 | return $setting; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - $response = $this->prepare_item_for_response( $setting, $request ); |
|
| 118 | + $response = $this->prepare_item_for_response($setting, $request); |
|
| 119 | 119 | |
| 120 | - return rest_ensure_response( $response ); |
|
| 120 | + return rest_ensure_response($response); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -127,24 +127,24 @@ discard block |
||
| 127 | 127 | * @param WP_REST_Request $request Request data. |
| 128 | 128 | * @return WP_Error|WP_REST_Response |
| 129 | 129 | */ |
| 130 | - public function get_items( $request ) { |
|
| 131 | - $settings = $this->get_group_settings( $request['group_id'] ); |
|
| 130 | + public function get_items($request) { |
|
| 131 | + $settings = $this->get_group_settings($request['group_id']); |
|
| 132 | 132 | |
| 133 | - if ( is_wp_error( $settings ) ) { |
|
| 133 | + if (is_wp_error($settings)) { |
|
| 134 | 134 | return $settings; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | $data = array(); |
| 138 | 138 | |
| 139 | - foreach ( $settings as $setting_obj ) { |
|
| 140 | - $setting = $this->prepare_item_for_response( $setting_obj, $request ); |
|
| 141 | - $setting = $this->prepare_response_for_collection( $setting ); |
|
| 142 | - if ( $this->is_setting_type_valid( $setting['type'] ) ) { |
|
| 139 | + foreach ($settings as $setting_obj) { |
|
| 140 | + $setting = $this->prepare_item_for_response($setting_obj, $request); |
|
| 141 | + $setting = $this->prepare_response_for_collection($setting); |
|
| 142 | + if ($this->is_setting_type_valid($setting['type'])) { |
|
| 143 | 143 | $data[] = $setting; |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - return rest_ensure_response( $data ); |
|
| 147 | + return rest_ensure_response($data); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -154,35 +154,35 @@ discard block |
||
| 154 | 154 | * @param string $group_id Group ID. |
| 155 | 155 | * @return array|WP_Error |
| 156 | 156 | */ |
| 157 | - public function get_group_settings( $group_id ) { |
|
| 158 | - if ( empty( $group_id ) ) { |
|
| 159 | - return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 157 | + public function get_group_settings($group_id) { |
|
| 158 | + if (empty($group_id)) { |
|
| 159 | + return new WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404)); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - $settings = apply_filters( 'woocommerce_settings-' . $group_id, array() ); |
|
| 162 | + $settings = apply_filters('woocommerce_settings-' . $group_id, array()); |
|
| 163 | 163 | |
| 164 | - if ( empty( $settings ) ) { |
|
| 165 | - return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 164 | + if (empty($settings)) { |
|
| 165 | + return new WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404)); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | $filtered_settings = array(); |
| 169 | - foreach ( $settings as $setting ) { |
|
| 169 | + foreach ($settings as $setting) { |
|
| 170 | 170 | $option_key = $setting['option_key']; |
| 171 | - $setting = $this->filter_setting( $setting ); |
|
| 172 | - $default = isset( $setting['default'] ) ? $setting['default'] : ''; |
|
| 171 | + $setting = $this->filter_setting($setting); |
|
| 172 | + $default = isset($setting['default']) ? $setting['default'] : ''; |
|
| 173 | 173 | // Get the option value. |
| 174 | - if ( is_array( $option_key ) ) { |
|
| 175 | - $option = get_option( $option_key[0] ); |
|
| 176 | - $setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default; |
|
| 174 | + if (is_array($option_key)) { |
|
| 175 | + $option = get_option($option_key[0]); |
|
| 176 | + $setting['value'] = isset($option[$option_key[1]]) ? $option[$option_key[1]] : $default; |
|
| 177 | 177 | } else { |
| 178 | - $admin_setting_value = WC_Admin_Settings::get_option( $option_key, $default ); |
|
| 178 | + $admin_setting_value = WC_Admin_Settings::get_option($option_key, $default); |
|
| 179 | 179 | $setting['value'] = $admin_setting_value; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if ( 'multi_select_countries' === $setting['type'] ) { |
|
| 182 | + if ('multi_select_countries' === $setting['type']) { |
|
| 183 | 183 | $setting['options'] = WC()->countries->get_countries(); |
| 184 | 184 | $setting['type'] = 'multiselect'; |
| 185 | - } elseif ( 'single_select_country' === $setting['type'] ) { |
|
| 185 | + } elseif ('single_select_country' === $setting['type']) { |
|
| 186 | 186 | $setting['type'] = 'select'; |
| 187 | 187 | $setting['options'] = $this->get_countries_and_states(); |
| 188 | 188 | } |
@@ -201,20 +201,20 @@ discard block |
||
| 201 | 201 | */ |
| 202 | 202 | private function get_countries_and_states() { |
| 203 | 203 | $countries = WC()->countries->get_countries(); |
| 204 | - if ( ! $countries ) { |
|
| 204 | + if ( ! $countries) { |
|
| 205 | 205 | return array(); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | $output = array(); |
| 209 | 209 | |
| 210 | - foreach ( $countries as $key => $value ) { |
|
| 211 | - $states = WC()->countries->get_states( $key ); |
|
| 212 | - if ( $states ) { |
|
| 213 | - foreach ( $states as $state_key => $state_value ) { |
|
| 214 | - $output[ $key . ':' . $state_key ] = $value . ' - ' . $state_value; |
|
| 210 | + foreach ($countries as $key => $value) { |
|
| 211 | + $states = WC()->countries->get_states($key); |
|
| 212 | + if ($states) { |
|
| 213 | + foreach ($states as $state_key => $state_value) { |
|
| 214 | + $output[$key . ':' . $state_key] = $value . ' - ' . $state_value; |
|
| 215 | 215 | } |
| 216 | 216 | } else { |
| 217 | - $output[ $key ] = $value; |
|
| 217 | + $output[$key] = $value; |
|
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | |
@@ -229,27 +229,27 @@ discard block |
||
| 229 | 229 | * @param string $setting_id Setting ID. |
| 230 | 230 | * @return stdClass|WP_Error |
| 231 | 231 | */ |
| 232 | - public function get_setting( $group_id, $setting_id ) { |
|
| 233 | - if ( empty( $setting_id ) ) { |
|
| 234 | - return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 232 | + public function get_setting($group_id, $setting_id) { |
|
| 233 | + if (empty($setting_id)) { |
|
| 234 | + return new WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - $settings = $this->get_group_settings( $group_id ); |
|
| 237 | + $settings = $this->get_group_settings($group_id); |
|
| 238 | 238 | |
| 239 | - if ( is_wp_error( $settings ) ) { |
|
| 239 | + if (is_wp_error($settings)) { |
|
| 240 | 240 | return $settings; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - $array_key = array_keys( wp_list_pluck( $settings, 'id' ), $setting_id ); |
|
| 243 | + $array_key = array_keys(wp_list_pluck($settings, 'id'), $setting_id); |
|
| 244 | 244 | |
| 245 | - if ( empty( $array_key ) ) { |
|
| 246 | - return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 245 | + if (empty($array_key)) { |
|
| 246 | + return new WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - $setting = $settings[ $array_key[0] ]; |
|
| 249 | + $setting = $settings[$array_key[0]]; |
|
| 250 | 250 | |
| 251 | - if ( ! $this->is_setting_type_valid( $setting['type'] ) ) { |
|
| 252 | - return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 251 | + if ( ! $this->is_setting_type_valid($setting['type'])) { |
|
| 252 | + return new WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | return $setting; |
@@ -262,24 +262,24 @@ discard block |
||
| 262 | 262 | * @param WP_REST_Request $request Full details about the request. |
| 263 | 263 | * @return array Of WP_Error or WP_REST_Response. |
| 264 | 264 | */ |
| 265 | - public function batch_items( $request ) { |
|
| 265 | + public function batch_items($request) { |
|
| 266 | 266 | // Get the request params. |
| 267 | - $items = array_filter( $request->get_params() ); |
|
| 267 | + $items = array_filter($request->get_params()); |
|
| 268 | 268 | |
| 269 | 269 | /* |
| 270 | 270 | * Since our batch settings update is group-specific and matches based on the route, |
| 271 | 271 | * we inject the URL parameters (containing group) into the batch items |
| 272 | 272 | */ |
| 273 | - if ( ! empty( $items['update'] ) ) { |
|
| 273 | + if ( ! empty($items['update'])) { |
|
| 274 | 274 | $to_update = array(); |
| 275 | - foreach ( $items['update'] as $item ) { |
|
| 276 | - $to_update[] = array_merge( $request->get_url_params(), $item ); |
|
| 275 | + foreach ($items['update'] as $item) { |
|
| 276 | + $to_update[] = array_merge($request->get_url_params(), $item); |
|
| 277 | 277 | } |
| 278 | - $request = new WP_REST_Request( $request->get_method() ); |
|
| 279 | - $request->set_body_params( array( 'update' => $to_update ) ); |
|
| 278 | + $request = new WP_REST_Request($request->get_method()); |
|
| 279 | + $request->set_body_params(array('update' => $to_update)); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - return parent::batch_items( $request ); |
|
| 282 | + return parent::batch_items($request); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -289,39 +289,39 @@ discard block |
||
| 289 | 289 | * @param WP_REST_Request $request Request data. |
| 290 | 290 | * @return WP_Error|WP_REST_Response |
| 291 | 291 | */ |
| 292 | - public function update_item( $request ) { |
|
| 293 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
| 292 | + public function update_item($request) { |
|
| 293 | + $setting = $this->get_setting($request['group_id'], $request['id']); |
|
| 294 | 294 | |
| 295 | - if ( is_wp_error( $setting ) ) { |
|
| 295 | + if (is_wp_error($setting)) { |
|
| 296 | 296 | return $setting; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( is_callable( array( $this, 'validate_setting_' . $setting['type'] . '_field' ) ) ) { |
|
| 300 | - $value = $this->{'validate_setting_' . $setting['type'] . '_field'}( $request['value'], $setting ); |
|
| 299 | + if (is_callable(array($this, 'validate_setting_' . $setting['type'] . '_field'))) { |
|
| 300 | + $value = $this->{'validate_setting_' . $setting['type'] . '_field'}($request['value'], $setting); |
|
| 301 | 301 | } else { |
| 302 | - $value = $this->validate_setting_text_field( $request['value'], $setting ); |
|
| 302 | + $value = $this->validate_setting_text_field($request['value'], $setting); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - if ( is_wp_error( $value ) ) { |
|
| 305 | + if (is_wp_error($value)) { |
|
| 306 | 306 | return $value; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if ( is_array( $setting['option_key'] ) ) { |
|
| 309 | + if (is_array($setting['option_key'])) { |
|
| 310 | 310 | $setting['value'] = $value; |
| 311 | 311 | $option_key = $setting['option_key']; |
| 312 | - $prev = get_option( $option_key[0] ); |
|
| 313 | - $prev[ $option_key[1] ] = $request['value']; |
|
| 314 | - update_option( $option_key[0], $prev ); |
|
| 312 | + $prev = get_option($option_key[0]); |
|
| 313 | + $prev[$option_key[1]] = $request['value']; |
|
| 314 | + update_option($option_key[0], $prev); |
|
| 315 | 315 | } else { |
| 316 | 316 | $update_data = array(); |
| 317 | - $update_data[ $setting['option_key'] ] = $value; |
|
| 317 | + $update_data[$setting['option_key']] = $value; |
|
| 318 | 318 | $setting['value'] = $value; |
| 319 | - WC_Admin_Settings::save_fields( array( $setting ), $update_data ); |
|
| 319 | + WC_Admin_Settings::save_fields(array($setting), $update_data); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - $response = $this->prepare_item_for_response( $setting, $request ); |
|
| 322 | + $response = $this->prepare_item_for_response($setting, $request); |
|
| 323 | 323 | |
| 324 | - return rest_ensure_response( $response ); |
|
| 324 | + return rest_ensure_response($response); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -332,13 +332,13 @@ discard block |
||
| 332 | 332 | * @param WP_REST_Request $request Request object. |
| 333 | 333 | * @return WP_REST_Response $response Response data. |
| 334 | 334 | */ |
| 335 | - public function prepare_item_for_response( $item, $request ) { |
|
| 336 | - unset( $item['option_key'] ); |
|
| 337 | - $data = $this->filter_setting( $item ); |
|
| 338 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 339 | - $data = $this->filter_response_by_context( $data, empty( $request['context'] ) ? 'view' : $request['context'] ); |
|
| 340 | - $response = rest_ensure_response( $data ); |
|
| 341 | - $response->add_links( $this->prepare_links( $data['id'], $request['group_id'] ) ); |
|
| 335 | + public function prepare_item_for_response($item, $request) { |
|
| 336 | + unset($item['option_key']); |
|
| 337 | + $data = $this->filter_setting($item); |
|
| 338 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 339 | + $data = $this->filter_response_by_context($data, empty($request['context']) ? 'view' : $request['context']); |
|
| 340 | + $response = rest_ensure_response($data); |
|
| 341 | + $response->add_links($this->prepare_links($data['id'], $request['group_id'])); |
|
| 342 | 342 | return $response; |
| 343 | 343 | } |
| 344 | 344 | |
@@ -350,14 +350,14 @@ discard block |
||
| 350 | 350 | * @param string $group_id Group ID. |
| 351 | 351 | * @return array Links for the given setting. |
| 352 | 352 | */ |
| 353 | - protected function prepare_links( $setting_id, $group_id ) { |
|
| 354 | - $base = str_replace( '(?P<group_id>[\w-]+)', $group_id, $this->rest_base ); |
|
| 353 | + protected function prepare_links($setting_id, $group_id) { |
|
| 354 | + $base = str_replace('(?P<group_id>[\w-]+)', $group_id, $this->rest_base); |
|
| 355 | 355 | $links = array( |
| 356 | 356 | 'self' => array( |
| 357 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $base, $setting_id ) ), |
|
| 357 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $base, $setting_id)), |
|
| 358 | 358 | ), |
| 359 | 359 | 'collection' => array( |
| 360 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
| 360 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
| 361 | 361 | ), |
| 362 | 362 | ); |
| 363 | 363 | |
@@ -371,9 +371,9 @@ discard block |
||
| 371 | 371 | * @param WP_REST_Request $request Full data about the request. |
| 372 | 372 | * @return WP_Error|boolean |
| 373 | 373 | */ |
| 374 | - public function get_items_permissions_check( $request ) { |
|
| 375 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
| 376 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 374 | + public function get_items_permissions_check($request) { |
|
| 375 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
| 376 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | return true; |
@@ -386,9 +386,9 @@ discard block |
||
| 386 | 386 | * @param WP_REST_Request $request Full data about the request. |
| 387 | 387 | * @return WP_Error|boolean |
| 388 | 388 | */ |
| 389 | - public function update_items_permissions_check( $request ) { |
|
| 390 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
| 391 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 389 | + public function update_items_permissions_check($request) { |
|
| 390 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
| 391 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | return true; |
@@ -402,18 +402,18 @@ discard block |
||
| 402 | 402 | * @param array $setting Settings. |
| 403 | 403 | * @return array |
| 404 | 404 | */ |
| 405 | - public function filter_setting( $setting ) { |
|
| 405 | + public function filter_setting($setting) { |
|
| 406 | 406 | $setting = array_intersect_key( |
| 407 | 407 | $setting, |
| 408 | - array_flip( array_filter( array_keys( $setting ), array( $this, 'allowed_setting_keys' ) ) ) |
|
| 408 | + array_flip(array_filter(array_keys($setting), array($this, 'allowed_setting_keys'))) |
|
| 409 | 409 | ); |
| 410 | 410 | |
| 411 | - if ( empty( $setting['options'] ) ) { |
|
| 412 | - unset( $setting['options'] ); |
|
| 411 | + if (empty($setting['options'])) { |
|
| 412 | + unset($setting['options']); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - if ( 'image_width' === $setting['type'] ) { |
|
| 416 | - $setting = $this->cast_image_width( $setting ); |
|
| 415 | + if ('image_width' === $setting['type']) { |
|
| 416 | + $setting = $this->cast_image_width($setting); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | return $setting; |
@@ -428,12 +428,12 @@ discard block |
||
| 428 | 428 | * @param array $setting Settings. |
| 429 | 429 | * @return array |
| 430 | 430 | */ |
| 431 | - public function cast_image_width( $setting ) { |
|
| 432 | - foreach ( array( 'default', 'value' ) as $key ) { |
|
| 433 | - if ( isset( $setting[ $key ] ) ) { |
|
| 434 | - $setting[ $key ]['width'] = intval( $setting[ $key ]['width'] ); |
|
| 435 | - $setting[ $key ]['height'] = intval( $setting[ $key ]['height'] ); |
|
| 436 | - $setting[ $key ]['crop'] = (bool) $setting[ $key ]['crop']; |
|
| 431 | + public function cast_image_width($setting) { |
|
| 432 | + foreach (array('default', 'value') as $key) { |
|
| 433 | + if (isset($setting[$key])) { |
|
| 434 | + $setting[$key]['width'] = intval($setting[$key]['width']); |
|
| 435 | + $setting[$key]['height'] = intval($setting[$key]['height']); |
|
| 436 | + $setting[$key]['crop'] = (bool) $setting[$key]['crop']; |
|
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | return $setting; |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | * @param string $key Key to check. |
| 447 | 447 | * @return boolean |
| 448 | 448 | */ |
| 449 | - public function allowed_setting_keys( $key ) { |
|
| 449 | + public function allowed_setting_keys($key) { |
|
| 450 | 450 | return in_array( |
| 451 | 451 | $key, array( |
| 452 | 452 | 'id', |
@@ -470,20 +470,20 @@ discard block |
||
| 470 | 470 | * @param string $type Type. |
| 471 | 471 | * @return bool |
| 472 | 472 | */ |
| 473 | - public function is_setting_type_valid( $type ) { |
|
| 473 | + public function is_setting_type_valid($type) { |
|
| 474 | 474 | return in_array( |
| 475 | 475 | $type, array( |
| 476 | - 'text', // Validates with validate_setting_text_field. |
|
| 477 | - 'email', // Validates with validate_setting_text_field. |
|
| 478 | - 'number', // Validates with validate_setting_text_field. |
|
| 479 | - 'color', // Validates with validate_setting_text_field. |
|
| 480 | - 'password', // Validates with validate_setting_text_field. |
|
| 481 | - 'textarea', // Validates with validate_setting_textarea_field. |
|
| 482 | - 'select', // Validates with validate_setting_select_field. |
|
| 483 | - 'multiselect', // Validates with validate_setting_multiselect_field. |
|
| 484 | - 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
| 485 | - 'checkbox', // Validates with validate_setting_checkbox_field. |
|
| 486 | - 'image_width', // Validates with validate_setting_image_width_field. |
|
| 476 | + 'text', // Validates with validate_setting_text_field. |
|
| 477 | + 'email', // Validates with validate_setting_text_field. |
|
| 478 | + 'number', // Validates with validate_setting_text_field. |
|
| 479 | + 'color', // Validates with validate_setting_text_field. |
|
| 480 | + 'password', // Validates with validate_setting_text_field. |
|
| 481 | + 'textarea', // Validates with validate_setting_textarea_field. |
|
| 482 | + 'select', // Validates with validate_setting_select_field. |
|
| 483 | + 'multiselect', // Validates with validate_setting_multiselect_field. |
|
| 484 | + 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
| 485 | + 'checkbox', // Validates with validate_setting_checkbox_field. |
|
| 486 | + 'image_width', // Validates with validate_setting_image_width_field. |
|
| 487 | 487 | 'thumbnail_cropping', // Validates with validate_setting_text_field. |
| 488 | 488 | ) |
| 489 | 489 | ); |
@@ -502,80 +502,80 @@ discard block |
||
| 502 | 502 | 'type' => 'object', |
| 503 | 503 | 'properties' => array( |
| 504 | 504 | 'id' => array( |
| 505 | - 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ), |
|
| 505 | + 'description' => __('A unique identifier for the setting.', 'woocommerce'), |
|
| 506 | 506 | 'type' => 'string', |
| 507 | 507 | 'arg_options' => array( |
| 508 | 508 | 'sanitize_callback' => 'sanitize_title', |
| 509 | 509 | ), |
| 510 | - 'context' => array( 'view', 'edit' ), |
|
| 510 | + 'context' => array('view', 'edit'), |
|
| 511 | 511 | 'readonly' => true, |
| 512 | 512 | ), |
| 513 | 513 | 'label' => array( |
| 514 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
| 514 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
| 515 | 515 | 'type' => 'string', |
| 516 | 516 | 'arg_options' => array( |
| 517 | 517 | 'sanitize_callback' => 'sanitize_text_field', |
| 518 | 518 | ), |
| 519 | - 'context' => array( 'view', 'edit' ), |
|
| 519 | + 'context' => array('view', 'edit'), |
|
| 520 | 520 | 'readonly' => true, |
| 521 | 521 | ), |
| 522 | 522 | 'description' => array( |
| 523 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
| 523 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
| 524 | 524 | 'type' => 'string', |
| 525 | 525 | 'arg_options' => array( |
| 526 | 526 | 'sanitize_callback' => 'sanitize_text_field', |
| 527 | 527 | ), |
| 528 | - 'context' => array( 'view', 'edit' ), |
|
| 528 | + 'context' => array('view', 'edit'), |
|
| 529 | 529 | 'readonly' => true, |
| 530 | 530 | ), |
| 531 | 531 | 'value' => array( |
| 532 | - 'description' => __( 'Setting value.', 'woocommerce' ), |
|
| 532 | + 'description' => __('Setting value.', 'woocommerce'), |
|
| 533 | 533 | 'type' => 'mixed', |
| 534 | - 'context' => array( 'view', 'edit' ), |
|
| 534 | + 'context' => array('view', 'edit'), |
|
| 535 | 535 | ), |
| 536 | 536 | 'default' => array( |
| 537 | - 'description' => __( 'Default value for the setting.', 'woocommerce' ), |
|
| 537 | + 'description' => __('Default value for the setting.', 'woocommerce'), |
|
| 538 | 538 | 'type' => 'mixed', |
| 539 | - 'context' => array( 'view', 'edit' ), |
|
| 539 | + 'context' => array('view', 'edit'), |
|
| 540 | 540 | 'readonly' => true, |
| 541 | 541 | ), |
| 542 | 542 | 'tip' => array( |
| 543 | - 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ), |
|
| 543 | + 'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'), |
|
| 544 | 544 | 'type' => 'string', |
| 545 | 545 | 'arg_options' => array( |
| 546 | 546 | 'sanitize_callback' => 'sanitize_text_field', |
| 547 | 547 | ), |
| 548 | - 'context' => array( 'view', 'edit' ), |
|
| 548 | + 'context' => array('view', 'edit'), |
|
| 549 | 549 | 'readonly' => true, |
| 550 | 550 | ), |
| 551 | 551 | 'placeholder' => array( |
| 552 | - 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ), |
|
| 552 | + 'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'), |
|
| 553 | 553 | 'type' => 'string', |
| 554 | 554 | 'arg_options' => array( |
| 555 | 555 | 'sanitize_callback' => 'sanitize_text_field', |
| 556 | 556 | ), |
| 557 | - 'context' => array( 'view', 'edit' ), |
|
| 557 | + 'context' => array('view', 'edit'), |
|
| 558 | 558 | 'readonly' => true, |
| 559 | 559 | ), |
| 560 | 560 | 'type' => array( |
| 561 | - 'description' => __( 'Type of setting.', 'woocommerce' ), |
|
| 561 | + 'description' => __('Type of setting.', 'woocommerce'), |
|
| 562 | 562 | 'type' => 'string', |
| 563 | 563 | 'arg_options' => array( |
| 564 | 564 | 'sanitize_callback' => 'sanitize_text_field', |
| 565 | 565 | ), |
| 566 | - 'context' => array( 'view', 'edit' ), |
|
| 567 | - 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox', 'thumbnail_cropping' ), |
|
| 566 | + 'context' => array('view', 'edit'), |
|
| 567 | + 'enum' => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox', 'thumbnail_cropping'), |
|
| 568 | 568 | 'readonly' => true, |
| 569 | 569 | ), |
| 570 | 570 | 'options' => array( |
| 571 | - 'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ), |
|
| 571 | + 'description' => __('Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce'), |
|
| 572 | 572 | 'type' => 'object', |
| 573 | - 'context' => array( 'view', 'edit' ), |
|
| 573 | + 'context' => array('view', 'edit'), |
|
| 574 | 574 | 'readonly' => true, |
| 575 | 575 | ), |
| 576 | 576 | ), |
| 577 | 577 | ); |
| 578 | 578 | |
| 579 | - return $this->add_additional_fields_schema( $schema ); |
|
| 579 | + return $this->add_additional_fields_schema($schema); |
|
| 580 | 580 | } |
| 581 | 581 | } |