@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API Settings controller class. |
@@ -35,10 +35,10 @@ discard block |
||
| 35 | 35 | array( |
| 36 | 36 | array( |
| 37 | 37 | 'methods' => \WP_REST_Server::READABLE, |
| 38 | - 'callback' => array( $this, 'get_items' ), |
|
| 39 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 38 | + 'callback' => array($this, 'get_items'), |
|
| 39 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 40 | 40 | ), |
| 41 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 41 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 42 | 42 | ), |
| 43 | 43 | true |
| 44 | 44 | ); |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | array( |
| 49 | 49 | array( |
| 50 | 50 | 'methods' => \WP_REST_Server::EDITABLE, |
| 51 | - 'callback' => array( $this, 'batch_items' ), |
|
| 52 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
| 51 | + 'callback' => array($this, 'batch_items'), |
|
| 52 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
| 53 | 53 | ), |
| 54 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
| 54 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
| 55 | 55 | ), |
| 56 | 56 | true |
| 57 | 57 | ); |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | * @param \WP_REST_Request $request Full data about the request. |
| 64 | 64 | * @return \WP_Error|bool |
| 65 | 65 | */ |
| 66 | - public function update_items_permissions_check( $request ) { |
|
| 67 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
| 68 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 66 | + public function update_items_permissions_check($request) { |
|
| 67 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
| 68 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | return true; |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * @param \WP_REST_Request $request Request data. |
| 78 | 78 | * @return \WP_Error\WP_REST_Response |
| 79 | 79 | */ |
| 80 | - public function update_item( $request ) { |
|
| 80 | + public function update_item($request) { |
|
| 81 | 81 | $options_controller = new \WC_REST_Setting_Options_Controller(); |
| 82 | - $response = $options_controller->update_item( $request ); |
|
| 82 | + $response = $options_controller->update_item($request); |
|
| 83 | 83 | |
| 84 | 84 | return $response; |
| 85 | 85 | } |
@@ -91,34 +91,34 @@ discard block |
||
| 91 | 91 | * @param \WP_REST_Request $request Request data. |
| 92 | 92 | * @return \WP_Error\WP_REST_Response |
| 93 | 93 | */ |
| 94 | - public function get_items( $request ) { |
|
| 95 | - $groups = apply_filters( 'woocommerce_settings_groups', array() ); |
|
| 96 | - if ( empty( $groups ) ) { |
|
| 97 | - return new \WP_Error( 'rest_setting_groups_empty', __( 'No setting groups have been registered.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 94 | + public function get_items($request) { |
|
| 95 | + $groups = apply_filters('woocommerce_settings_groups', array()); |
|
| 96 | + if (empty($groups)) { |
|
| 97 | + return new \WP_Error('rest_setting_groups_empty', __('No setting groups have been registered.', 'woocommerce'), array('status' => 500)); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $defaults = $this->group_defaults(); |
| 101 | 101 | $filtered_groups = array(); |
| 102 | - foreach ( $groups as $group ) { |
|
| 102 | + foreach ($groups as $group) { |
|
| 103 | 103 | $sub_groups = array(); |
| 104 | - foreach ( $groups as $_group ) { |
|
| 105 | - if ( ! empty( $_group['parent_id'] ) && $group['id'] === $_group['parent_id'] ) { |
|
| 104 | + foreach ($groups as $_group) { |
|
| 105 | + if ( ! empty($_group['parent_id']) && $group['id'] === $_group['parent_id']) { |
|
| 106 | 106 | $sub_groups[] = $_group['id']; |
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | $group['sub_groups'] = $sub_groups; |
| 110 | 110 | |
| 111 | - $group = wp_parse_args( $group, $defaults ); |
|
| 112 | - if ( ! is_null( $group['id'] ) && ! is_null( $group['label'] ) ) { |
|
| 113 | - $group_obj = $this->filter_group( $group ); |
|
| 114 | - $group_data = $this->prepare_item_for_response( $group_obj, $request ); |
|
| 115 | - $group_data = $this->prepare_response_for_collection( $group_data ); |
|
| 111 | + $group = wp_parse_args($group, $defaults); |
|
| 112 | + if ( ! is_null($group['id']) && ! is_null($group['label'])) { |
|
| 113 | + $group_obj = $this->filter_group($group); |
|
| 114 | + $group_data = $this->prepare_item_for_response($group_obj, $request); |
|
| 115 | + $group_data = $this->prepare_response_for_collection($group_data); |
|
| 116 | 116 | |
| 117 | 117 | $filtered_groups[] = $group_data; |
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - $response = rest_ensure_response( $filtered_groups ); |
|
| 121 | + $response = rest_ensure_response($filtered_groups); |
|
| 122 | 122 | return $response; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -128,11 +128,11 @@ discard block |
||
| 128 | 128 | * @param string $group_id Group ID. |
| 129 | 129 | * @return array Links for the given group. |
| 130 | 130 | */ |
| 131 | - protected function prepare_links( $group_id ) { |
|
| 131 | + protected function prepare_links($group_id) { |
|
| 132 | 132 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
| 133 | 133 | $links = array( |
| 134 | 134 | 'options' => array( |
| 135 | - 'href' => rest_url( trailingslashit( $base ) . $group_id ), |
|
| 135 | + 'href' => rest_url(trailingslashit($base) . $group_id), |
|
| 136 | 136 | ), |
| 137 | 137 | ); |
| 138 | 138 | |
@@ -147,14 +147,14 @@ discard block |
||
| 147 | 147 | * @param \WP_REST_Request $request Request object. |
| 148 | 148 | * @return \WP_REST_Response $response Response data. |
| 149 | 149 | */ |
| 150 | - public function prepare_item_for_response( $item, $request ) { |
|
| 151 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
| 152 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
| 153 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 150 | + public function prepare_item_for_response($item, $request) { |
|
| 151 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
| 152 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
| 153 | + $data = $this->filter_response_by_context($data, $context); |
|
| 154 | 154 | |
| 155 | - $response = rest_ensure_response( $data ); |
|
| 155 | + $response = rest_ensure_response($data); |
|
| 156 | 156 | |
| 157 | - $response->add_links( $this->prepare_links( $item['id'] ) ); |
|
| 157 | + $response->add_links($this->prepare_links($item['id'])); |
|
| 158 | 158 | |
| 159 | 159 | return $response; |
| 160 | 160 | } |
@@ -167,10 +167,10 @@ discard block |
||
| 167 | 167 | * @param array $group Group. |
| 168 | 168 | * @return array |
| 169 | 169 | */ |
| 170 | - public function filter_group( $group ) { |
|
| 170 | + public function filter_group($group) { |
|
| 171 | 171 | return array_intersect_key( |
| 172 | 172 | $group, |
| 173 | - array_flip( array_filter( array_keys( $group ), array( $this, 'allowed_group_keys' ) ) ) |
|
| 173 | + array_flip(array_filter(array_keys($group), array($this, 'allowed_group_keys'))) |
|
| 174 | 174 | ); |
| 175 | 175 | } |
| 176 | 176 | |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | * @param string $key Key to check. |
| 182 | 182 | * @return boolean |
| 183 | 183 | */ |
| 184 | - public function allowed_group_keys( $key ) { |
|
| 185 | - return in_array( $key, array( 'id', 'label', 'description', 'parent_id', 'sub_groups' ) ); |
|
| 184 | + public function allowed_group_keys($key) { |
|
| 185 | + return in_array($key, array('id', 'label', 'description', 'parent_id', 'sub_groups')); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -208,9 +208,9 @@ discard block |
||
| 208 | 208 | * @param \WP_REST_Request $request Full data about the request. |
| 209 | 209 | * @return \WP_Error|boolean |
| 210 | 210 | */ |
| 211 | - public function get_items_permissions_check( $request ) { |
|
| 212 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
| 213 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 211 | + public function get_items_permissions_check($request) { |
|
| 212 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
| 213 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | return true; |
@@ -229,33 +229,33 @@ discard block |
||
| 229 | 229 | 'type' => 'object', |
| 230 | 230 | 'properties' => array( |
| 231 | 231 | 'id' => array( |
| 232 | - 'description' => __( 'A unique identifier that can be used to link settings together.', 'woocommerce' ), |
|
| 232 | + 'description' => __('A unique identifier that can be used to link settings together.', 'woocommerce'), |
|
| 233 | 233 | 'type' => 'string', |
| 234 | - 'context' => array( 'view', 'edit' ), |
|
| 234 | + 'context' => array('view', 'edit'), |
|
| 235 | 235 | ), |
| 236 | 236 | 'label' => array( |
| 237 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
| 237 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
| 238 | 238 | 'type' => 'string', |
| 239 | - 'context' => array( 'view', 'edit' ), |
|
| 239 | + 'context' => array('view', 'edit'), |
|
| 240 | 240 | ), |
| 241 | 241 | 'description' => array( |
| 242 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
| 242 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
| 243 | 243 | 'type' => 'string', |
| 244 | - 'context' => array( 'view', 'edit' ), |
|
| 244 | + 'context' => array('view', 'edit'), |
|
| 245 | 245 | ), |
| 246 | 246 | 'parent_id' => array( |
| 247 | - 'description' => __( 'ID of parent grouping.', 'woocommerce' ), |
|
| 247 | + 'description' => __('ID of parent grouping.', 'woocommerce'), |
|
| 248 | 248 | 'type' => 'string', |
| 249 | - 'context' => array( 'view', 'edit' ), |
|
| 249 | + 'context' => array('view', 'edit'), |
|
| 250 | 250 | ), |
| 251 | 251 | 'sub_groups' => array( |
| 252 | - 'description' => __( 'IDs for settings sub groups.', 'woocommerce' ), |
|
| 252 | + 'description' => __('IDs for settings sub groups.', 'woocommerce'), |
|
| 253 | 253 | 'type' => 'string', |
| 254 | - 'context' => array( 'view', 'edit' ), |
|
| 254 | + 'context' => array('view', 'edit'), |
|
| 255 | 255 | ), |
| 256 | 256 | ), |
| 257 | 257 | ); |
| 258 | 258 | |
| 259 | - return $this->add_additional_fields_schema( $schema ); |
|
| 259 | + return $this->add_additional_fields_schema($schema); |
|
| 260 | 260 | } |
| 261 | 261 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API Shipping Zone Locations class. |
@@ -26,22 +26,22 @@ discard block |
||
| 26 | 26 | array( |
| 27 | 27 | 'args' => array( |
| 28 | 28 | 'id' => array( |
| 29 | - 'description' => __( 'Unique ID for the resource.', 'woocommerce' ), |
|
| 29 | + 'description' => __('Unique ID for the resource.', 'woocommerce'), |
|
| 30 | 30 | 'type' => 'integer', |
| 31 | 31 | ), |
| 32 | 32 | ), |
| 33 | 33 | array( |
| 34 | 34 | 'methods' => \WP_REST_Server::READABLE, |
| 35 | - 'callback' => array( $this, 'get_items' ), |
|
| 36 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 35 | + 'callback' => array($this, 'get_items'), |
|
| 36 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 37 | 37 | ), |
| 38 | 38 | array( |
| 39 | 39 | 'methods' => \WP_REST_Server::EDITABLE, |
| 40 | - 'callback' => array( $this, 'update_items' ), |
|
| 41 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
| 42 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
| 40 | + 'callback' => array($this, 'update_items'), |
|
| 41 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
| 42 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
| 43 | 43 | ), |
| 44 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 44 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 45 | 45 | ), |
| 46 | 46 | true |
| 47 | 47 | ); |
@@ -53,23 +53,23 @@ discard block |
||
| 53 | 53 | * @param \WP_REST_Request $request Request data. |
| 54 | 54 | * @return \WP_REST_Response|\WP_Error |
| 55 | 55 | */ |
| 56 | - public function get_items( $request ) { |
|
| 57 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
| 56 | + public function get_items($request) { |
|
| 57 | + $zone = $this->get_zone((int) $request['id']); |
|
| 58 | 58 | |
| 59 | - if ( is_wp_error( $zone ) ) { |
|
| 59 | + if (is_wp_error($zone)) { |
|
| 60 | 60 | return $zone; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | $locations = $zone->get_zone_locations(); |
| 64 | 64 | $data = array(); |
| 65 | 65 | |
| 66 | - foreach ( $locations as $location_obj ) { |
|
| 67 | - $location = $this->prepare_item_for_response( $location_obj, $request ); |
|
| 68 | - $location = $this->prepare_response_for_collection( $location ); |
|
| 66 | + foreach ($locations as $location_obj) { |
|
| 67 | + $location = $this->prepare_item_for_response($location_obj, $request); |
|
| 68 | + $location = $this->prepare_response_for_collection($location); |
|
| 69 | 69 | $data[] = $location; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - return rest_ensure_response( $data ); |
|
| 72 | + return rest_ensure_response($data); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -78,41 +78,41 @@ discard block |
||
| 78 | 78 | * @param \WP_REST_Request $request Request data. |
| 79 | 79 | * @return \WP_REST_Response|\WP_Error |
| 80 | 80 | */ |
| 81 | - public function update_items( $request ) { |
|
| 82 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
| 81 | + public function update_items($request) { |
|
| 82 | + $zone = $this->get_zone((int) $request['id']); |
|
| 83 | 83 | |
| 84 | - if ( is_wp_error( $zone ) ) { |
|
| 84 | + if (is_wp_error($zone)) { |
|
| 85 | 85 | return $zone; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if ( 0 === $zone->get_id() ) { |
|
| 89 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_locations_invalid_zone', __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) ); |
|
| 88 | + if (0 === $zone->get_id()) { |
|
| 89 | + return new \WP_Error('woocommerce_rest_shipping_zone_locations_invalid_zone', __('The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce'), array('status' => 403)); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | $raw_locations = $request->get_json_params(); |
| 93 | 93 | $locations = array(); |
| 94 | 94 | |
| 95 | - foreach ( (array) $raw_locations as $raw_location ) { |
|
| 96 | - if ( empty( $raw_location['code'] ) ) { |
|
| 95 | + foreach ((array) $raw_locations as $raw_location) { |
|
| 96 | + if (empty($raw_location['code'])) { |
|
| 97 | 97 | continue; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - $type = ! empty( $raw_location['type'] ) ? sanitize_text_field( $raw_location['type'] ) : 'country'; |
|
| 100 | + $type = ! empty($raw_location['type']) ? sanitize_text_field($raw_location['type']) : 'country'; |
|
| 101 | 101 | |
| 102 | - if ( ! in_array( $type, array( 'postcode', 'state', 'country', 'continent' ), true ) ) { |
|
| 102 | + if ( ! in_array($type, array('postcode', 'state', 'country', 'continent'), true)) { |
|
| 103 | 103 | continue; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $locations[] = array( |
| 107 | - 'code' => sanitize_text_field( $raw_location['code'] ), |
|
| 108 | - 'type' => sanitize_text_field( $type ), |
|
| 107 | + 'code' => sanitize_text_field($raw_location['code']), |
|
| 108 | + 'type' => sanitize_text_field($type), |
|
| 109 | 109 | ); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - $zone->set_locations( $locations ); |
|
| 112 | + $zone->set_locations($locations); |
|
| 113 | 113 | $zone->save(); |
| 114 | 114 | |
| 115 | - return $this->get_items( $request ); |
|
| 115 | + return $this->get_items($request); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -122,15 +122,15 @@ discard block |
||
| 122 | 122 | * @param \WP_REST_Request $request Request object. |
| 123 | 123 | * @return \WP_REST_Response $response |
| 124 | 124 | */ |
| 125 | - public function prepare_item_for_response( $item, $request ) { |
|
| 126 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
| 127 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
| 128 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 125 | + public function prepare_item_for_response($item, $request) { |
|
| 126 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
| 127 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
| 128 | + $data = $this->filter_response_by_context($data, $context); |
|
| 129 | 129 | |
| 130 | 130 | // Wrap the data in a response object. |
| 131 | - $response = rest_ensure_response( $data ); |
|
| 131 | + $response = rest_ensure_response($data); |
|
| 132 | 132 | |
| 133 | - $response->add_links( $this->prepare_links( (int) $request['id'] ) ); |
|
| 133 | + $response->add_links($this->prepare_links((int) $request['id'])); |
|
| 134 | 134 | |
| 135 | 135 | return $response; |
| 136 | 136 | } |
@@ -141,14 +141,14 @@ discard block |
||
| 141 | 141 | * @param int $zone_id Given Shipping Zone ID. |
| 142 | 142 | * @return array Links for the given Shipping Zone Location. |
| 143 | 143 | */ |
| 144 | - protected function prepare_links( $zone_id ) { |
|
| 144 | + protected function prepare_links($zone_id) { |
|
| 145 | 145 | $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id; |
| 146 | 146 | $links = array( |
| 147 | 147 | 'collection' => array( |
| 148 | - 'href' => rest_url( $base . '/locations' ), |
|
| 148 | + 'href' => rest_url($base . '/locations'), |
|
| 149 | 149 | ), |
| 150 | 150 | 'describes' => array( |
| 151 | - 'href' => rest_url( $base ), |
|
| 151 | + 'href' => rest_url($base), |
|
| 152 | 152 | ), |
| 153 | 153 | ); |
| 154 | 154 | |
@@ -167,12 +167,12 @@ discard block |
||
| 167 | 167 | 'type' => 'object', |
| 168 | 168 | 'properties' => array( |
| 169 | 169 | 'code' => array( |
| 170 | - 'description' => __( 'Shipping zone location code.', 'woocommerce' ), |
|
| 170 | + 'description' => __('Shipping zone location code.', 'woocommerce'), |
|
| 171 | 171 | 'type' => 'string', |
| 172 | - 'context' => array( 'view', 'edit' ), |
|
| 172 | + 'context' => array('view', 'edit'), |
|
| 173 | 173 | ), |
| 174 | 174 | 'type' => array( |
| 175 | - 'description' => __( 'Shipping zone location type.', 'woocommerce' ), |
|
| 175 | + 'description' => __('Shipping zone location type.', 'woocommerce'), |
|
| 176 | 176 | 'type' => 'string', |
| 177 | 177 | 'default' => 'country', |
| 178 | 178 | 'enum' => array( |
@@ -181,11 +181,11 @@ discard block |
||
| 181 | 181 | 'country', |
| 182 | 182 | 'continent', |
| 183 | 183 | ), |
| 184 | - 'context' => array( 'view', 'edit' ), |
|
| 184 | + 'context' => array('view', 'edit'), |
|
| 185 | 185 | ), |
| 186 | 186 | ), |
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | - return $this->add_additional_fields_schema( $schema ); |
|
| 189 | + return $this->add_additional_fields_schema($schema); |
|
| 190 | 190 | } |
| 191 | 191 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API Shipping Zones class. |
@@ -26,25 +26,25 @@ discard block |
||
| 26 | 26 | 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 ), |
|
| 37 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
| 38 | 38 | array( |
| 39 | 39 | 'name' => array( |
| 40 | 40 | 'required' => true, |
| 41 | 41 | 'type' => 'string', |
| 42 | - 'description' => __( 'Shipping zone name.', 'woocommerce' ), |
|
| 42 | + 'description' => __('Shipping zone name.', 'woocommerce'), |
|
| 43 | 43 | ), |
| 44 | 44 | ) |
| 45 | 45 | ), |
| 46 | 46 | ), |
| 47 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 47 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 48 | 48 | ), |
| 49 | 49 | true |
| 50 | 50 | ); |
@@ -55,34 +55,34 @@ discard block |
||
| 55 | 55 | array( |
| 56 | 56 | 'args' => array( |
| 57 | 57 | 'id' => array( |
| 58 | - 'description' => __( 'Unique ID for the resource.', 'woocommerce' ), |
|
| 58 | + 'description' => __('Unique ID for the resource.', 'woocommerce'), |
|
| 59 | 59 | 'type' => 'integer', |
| 60 | 60 | ), |
| 61 | 61 | ), |
| 62 | 62 | array( |
| 63 | 63 | 'methods' => \WP_REST_Server::READABLE, |
| 64 | - 'callback' => array( $this, 'get_item' ), |
|
| 65 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 64 | + 'callback' => array($this, 'get_item'), |
|
| 65 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 66 | 66 | ), |
| 67 | 67 | array( |
| 68 | 68 | 'methods' => \WP_REST_Server::EDITABLE, |
| 69 | - 'callback' => array( $this, 'update_item' ), |
|
| 70 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
| 71 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
| 69 | + 'callback' => array($this, 'update_item'), |
|
| 70 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
| 71 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
| 72 | 72 | ), |
| 73 | 73 | array( |
| 74 | 74 | 'methods' => \WP_REST_Server::DELETABLE, |
| 75 | - 'callback' => array( $this, 'delete_item' ), |
|
| 76 | - 'permission_callback' => array( $this, 'delete_items_permissions_check' ), |
|
| 75 | + 'callback' => array($this, 'delete_item'), |
|
| 76 | + 'permission_callback' => array($this, 'delete_items_permissions_check'), |
|
| 77 | 77 | 'args' => array( |
| 78 | 78 | 'force' => array( |
| 79 | 79 | 'default' => false, |
| 80 | 80 | 'type' => 'boolean', |
| 81 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
| 81 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
| 82 | 82 | ), |
| 83 | 83 | ), |
| 84 | 84 | ), |
| 85 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 85 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 86 | 86 | ), |
| 87 | 87 | true |
| 88 | 88 | ); |
@@ -94,18 +94,18 @@ discard block |
||
| 94 | 94 | * @param \WP_REST_Request $request Request data. |
| 95 | 95 | * @return \WP_REST_Response|\WP_Error |
| 96 | 96 | */ |
| 97 | - public function get_item( $request ) { |
|
| 98 | - $zone = $this->get_zone( $request->get_param( 'id' ) ); |
|
| 97 | + public function get_item($request) { |
|
| 98 | + $zone = $this->get_zone($request->get_param('id')); |
|
| 99 | 99 | |
| 100 | - if ( is_wp_error( $zone ) ) { |
|
| 100 | + if (is_wp_error($zone)) { |
|
| 101 | 101 | return $zone; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $data = $zone->get_data(); |
| 105 | - $data = $this->prepare_item_for_response( $data, $request ); |
|
| 106 | - $data = $this->prepare_response_for_collection( $data ); |
|
| 105 | + $data = $this->prepare_item_for_response($data, $request); |
|
| 106 | + $data = $this->prepare_response_for_collection($data); |
|
| 107 | 107 | |
| 108 | - return rest_ensure_response( $data ); |
|
| 108 | + return rest_ensure_response($data); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -114,20 +114,20 @@ discard block |
||
| 114 | 114 | * @param \WP_REST_Request $request Request data. |
| 115 | 115 | * @return \WP_REST_Response |
| 116 | 116 | */ |
| 117 | - public function get_items( $request ) { |
|
| 118 | - $rest_of_the_world = \WC_Shipping_Zones::get_zone_by( 'zone_id', 0 ); |
|
| 117 | + public function get_items($request) { |
|
| 118 | + $rest_of_the_world = \WC_Shipping_Zones::get_zone_by('zone_id', 0); |
|
| 119 | 119 | |
| 120 | 120 | $zones = \WC_Shipping_Zones::get_zones(); |
| 121 | - array_unshift( $zones, $rest_of_the_world->get_data() ); |
|
| 121 | + array_unshift($zones, $rest_of_the_world->get_data()); |
|
| 122 | 122 | $data = array(); |
| 123 | 123 | |
| 124 | - foreach ( $zones as $zone_obj ) { |
|
| 125 | - $zone = $this->prepare_item_for_response( $zone_obj, $request ); |
|
| 126 | - $zone = $this->prepare_response_for_collection( $zone ); |
|
| 124 | + foreach ($zones as $zone_obj) { |
|
| 125 | + $zone = $this->prepare_item_for_response($zone_obj, $request); |
|
| 126 | + $zone = $this->prepare_response_for_collection($zone); |
|
| 127 | 127 | $data[] = $zone; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - return rest_ensure_response( $data ); |
|
| 130 | + return rest_ensure_response($data); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -136,27 +136,27 @@ discard block |
||
| 136 | 136 | * @param \WP_REST_Request $request Full details about the request. |
| 137 | 137 | * @return \WP_REST_Request|\WP_Error |
| 138 | 138 | */ |
| 139 | - public function create_item( $request ) { |
|
| 140 | - $zone = new \WC_Shipping_Zone( null ); |
|
| 139 | + public function create_item($request) { |
|
| 140 | + $zone = new \WC_Shipping_Zone(null); |
|
| 141 | 141 | |
| 142 | - if ( ! is_null( $request->get_param( 'name' ) ) ) { |
|
| 143 | - $zone->set_zone_name( $request->get_param( 'name' ) ); |
|
| 142 | + if ( ! is_null($request->get_param('name'))) { |
|
| 143 | + $zone->set_zone_name($request->get_param('name')); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if ( ! is_null( $request->get_param( 'order' ) ) ) { |
|
| 147 | - $zone->set_zone_order( $request->get_param( 'order' ) ); |
|
| 146 | + if ( ! is_null($request->get_param('order'))) { |
|
| 147 | + $zone->set_zone_order($request->get_param('order')); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | $zone->save(); |
| 151 | 151 | |
| 152 | - if ( $zone->get_id() !== 0 ) { |
|
| 153 | - $request->set_param( 'id', $zone->get_id() ); |
|
| 154 | - $response = $this->get_item( $request ); |
|
| 155 | - $response->set_status( 201 ); |
|
| 156 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $zone->get_id() ) ) ); |
|
| 152 | + if ($zone->get_id() !== 0) { |
|
| 153 | + $request->set_param('id', $zone->get_id()); |
|
| 154 | + $response = $this->get_item($request); |
|
| 155 | + $response->set_status(201); |
|
| 156 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $zone->get_id()))); |
|
| 157 | 157 | return $response; |
| 158 | 158 | } else { |
| 159 | - 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 ) ); |
|
| 159 | + 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)); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
@@ -166,34 +166,34 @@ discard block |
||
| 166 | 166 | * @param \WP_REST_Request $request Full details about the request. |
| 167 | 167 | * @return \WP_REST_Request|\WP_Error |
| 168 | 168 | */ |
| 169 | - public function update_item( $request ) { |
|
| 170 | - $zone = $this->get_zone( $request->get_param( 'id' ) ); |
|
| 169 | + public function update_item($request) { |
|
| 170 | + $zone = $this->get_zone($request->get_param('id')); |
|
| 171 | 171 | |
| 172 | - if ( is_wp_error( $zone ) ) { |
|
| 172 | + if (is_wp_error($zone)) { |
|
| 173 | 173 | return $zone; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if ( 0 === $zone->get_id() ) { |
|
| 177 | - 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 ) ); |
|
| 176 | + if (0 === $zone->get_id()) { |
|
| 177 | + 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)); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | $zone_changed = false; |
| 181 | 181 | |
| 182 | - if ( ! is_null( $request->get_param( 'name' ) ) ) { |
|
| 183 | - $zone->set_zone_name( $request->get_param( 'name' ) ); |
|
| 182 | + if ( ! is_null($request->get_param('name'))) { |
|
| 183 | + $zone->set_zone_name($request->get_param('name')); |
|
| 184 | 184 | $zone_changed = true; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if ( ! is_null( $request->get_param( 'order' ) ) ) { |
|
| 188 | - $zone->set_zone_order( $request->get_param( 'order' ) ); |
|
| 187 | + if ( ! is_null($request->get_param('order'))) { |
|
| 188 | + $zone->set_zone_order($request->get_param('order')); |
|
| 189 | 189 | $zone_changed = true; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - if ( $zone_changed ) { |
|
| 192 | + if ($zone_changed) { |
|
| 193 | 193 | $zone->save(); |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - return $this->get_item( $request ); |
|
| 196 | + return $this->get_item($request); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -202,21 +202,21 @@ discard block |
||
| 202 | 202 | * @param \WP_REST_Request $request Full details about the request. |
| 203 | 203 | * @return \WP_REST_Request|\WP_Error |
| 204 | 204 | */ |
| 205 | - public function delete_item( $request ) { |
|
| 206 | - $zone = $this->get_zone( $request->get_param( 'id' ) ); |
|
| 205 | + public function delete_item($request) { |
|
| 206 | + $zone = $this->get_zone($request->get_param('id')); |
|
| 207 | 207 | |
| 208 | - if ( is_wp_error( $zone ) ) { |
|
| 208 | + if (is_wp_error($zone)) { |
|
| 209 | 209 | return $zone; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | $force = $request['force']; |
| 213 | 213 | |
| 214 | 214 | // We don't support trashing for this type, error out. |
| 215 | - if ( ! $force ) { |
|
| 216 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Shipping zones do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
| 215 | + if ( ! $force) { |
|
| 216 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Shipping zones do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - $previous = $this->get_item( $request ); |
|
| 219 | + $previous = $this->get_item($request); |
|
| 220 | 220 | $zone->delete(); |
| 221 | 221 | $response = new \WP_REST_Response(); |
| 222 | 222 | $response->set_data( |
@@ -236,21 +236,21 @@ discard block |
||
| 236 | 236 | * @param \WP_REST_Request $request Request object. |
| 237 | 237 | * @return \WP_REST_Response $response |
| 238 | 238 | */ |
| 239 | - public function prepare_item_for_response( $item, $request ) { |
|
| 239 | + public function prepare_item_for_response($item, $request) { |
|
| 240 | 240 | $data = array( |
| 241 | 241 | 'id' => (int) $item['id'], |
| 242 | 242 | 'name' => $item['zone_name'], |
| 243 | 243 | 'order' => (int) $item['zone_order'], |
| 244 | 244 | ); |
| 245 | 245 | |
| 246 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
| 247 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 248 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 246 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
| 247 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 248 | + $data = $this->filter_response_by_context($data, $context); |
|
| 249 | 249 | |
| 250 | 250 | // Wrap the data in a response object. |
| 251 | - $response = rest_ensure_response( $data ); |
|
| 251 | + $response = rest_ensure_response($data); |
|
| 252 | 252 | |
| 253 | - $response->add_links( $this->prepare_links( $data['id'] ) ); |
|
| 253 | + $response->add_links($this->prepare_links($data['id'])); |
|
| 254 | 254 | |
| 255 | 255 | return $response; |
| 256 | 256 | } |
@@ -261,17 +261,17 @@ discard block |
||
| 261 | 261 | * @param int $zone_id Given Shipping Zone ID. |
| 262 | 262 | * @return array Links for the given Shipping Zone. |
| 263 | 263 | */ |
| 264 | - protected function prepare_links( $zone_id ) { |
|
| 264 | + protected function prepare_links($zone_id) { |
|
| 265 | 265 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
| 266 | 266 | $links = array( |
| 267 | 267 | 'self' => array( |
| 268 | - 'href' => rest_url( trailingslashit( $base ) . $zone_id ), |
|
| 268 | + 'href' => rest_url(trailingslashit($base) . $zone_id), |
|
| 269 | 269 | ), |
| 270 | 270 | 'collection' => array( |
| 271 | - 'href' => rest_url( $base ), |
|
| 271 | + 'href' => rest_url($base), |
|
| 272 | 272 | ), |
| 273 | 273 | 'describedby' => array( |
| 274 | - 'href' => rest_url( trailingslashit( $base ) . $zone_id . '/locations' ), |
|
| 274 | + 'href' => rest_url(trailingslashit($base) . $zone_id . '/locations'), |
|
| 275 | 275 | ), |
| 276 | 276 | ); |
| 277 | 277 | |
@@ -290,27 +290,27 @@ discard block |
||
| 290 | 290 | 'type' => 'object', |
| 291 | 291 | 'properties' => array( |
| 292 | 292 | 'id' => array( |
| 293 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 293 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 294 | 294 | 'type' => 'integer', |
| 295 | - 'context' => array( 'view', 'edit' ), |
|
| 295 | + 'context' => array('view', 'edit'), |
|
| 296 | 296 | 'readonly' => true, |
| 297 | 297 | ), |
| 298 | 298 | 'name' => array( |
| 299 | - 'description' => __( 'Shipping zone name.', 'woocommerce' ), |
|
| 299 | + 'description' => __('Shipping zone name.', 'woocommerce'), |
|
| 300 | 300 | 'type' => 'string', |
| 301 | - 'context' => array( 'view', 'edit' ), |
|
| 301 | + 'context' => array('view', 'edit'), |
|
| 302 | 302 | 'arg_options' => array( |
| 303 | 303 | 'sanitize_callback' => 'sanitize_text_field', |
| 304 | 304 | ), |
| 305 | 305 | ), |
| 306 | 306 | 'order' => array( |
| 307 | - 'description' => __( 'Shipping zone order.', 'woocommerce' ), |
|
| 307 | + 'description' => __('Shipping zone order.', 'woocommerce'), |
|
| 308 | 308 | 'type' => 'integer', |
| 309 | - 'context' => array( 'view', 'edit' ), |
|
| 309 | + 'context' => array('view', 'edit'), |
|
| 310 | 310 | ), |
| 311 | 311 | ), |
| 312 | 312 | ); |
| 313 | 313 | |
| 314 | - return $this->add_additional_fields_schema( $schema ); |
|
| 314 | + return $this->add_additional_fields_schema($schema); |
|
| 315 | 315 | } |
| 316 | 316 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API Tax Class controller class. |
@@ -33,17 +33,17 @@ discard block |
||
| 33 | 33 | array( |
| 34 | 34 | array( |
| 35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
| 36 | - 'callback' => array( $this, 'get_items' ), |
|
| 37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 36 | + 'callback' => array($this, 'get_items'), |
|
| 37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 38 | 38 | 'args' => $this->get_collection_params(), |
| 39 | 39 | ), |
| 40 | 40 | array( |
| 41 | 41 | 'methods' => \WP_REST_Server::CREATABLE, |
| 42 | - 'callback' => array( $this, 'create_item' ), |
|
| 43 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
| 44 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
| 42 | + 'callback' => array($this, 'create_item'), |
|
| 43 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
| 44 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
| 45 | 45 | ), |
| 46 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 46 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 47 | 47 | ), |
| 48 | 48 | true |
| 49 | 49 | ); |
@@ -54,23 +54,23 @@ discard block |
||
| 54 | 54 | array( |
| 55 | 55 | 'args' => array( |
| 56 | 56 | 'slug' => array( |
| 57 | - 'description' => __( 'Unique slug for the resource.', 'woocommerce' ), |
|
| 57 | + 'description' => __('Unique slug for the resource.', 'woocommerce'), |
|
| 58 | 58 | 'type' => 'string', |
| 59 | 59 | ), |
| 60 | 60 | ), |
| 61 | 61 | array( |
| 62 | 62 | 'methods' => \WP_REST_Server::DELETABLE, |
| 63 | - 'callback' => array( $this, 'delete_item' ), |
|
| 64 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
| 63 | + 'callback' => array($this, 'delete_item'), |
|
| 64 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
| 65 | 65 | 'args' => array( |
| 66 | 66 | 'force' => array( |
| 67 | 67 | 'default' => false, |
| 68 | 68 | 'type' => 'boolean', |
| 69 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
| 69 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
| 70 | 70 | ), |
| 71 | 71 | ), |
| 72 | 72 | ), |
| 73 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 73 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 74 | 74 | ), |
| 75 | 75 | true |
| 76 | 76 | ); |
@@ -82,9 +82,9 @@ discard block |
||
| 82 | 82 | * @param \WP_REST_Request $request Full details about the request. |
| 83 | 83 | * @return \WP_Error|boolean |
| 84 | 84 | */ |
| 85 | - public function get_items_permissions_check( $request ) { |
|
| 86 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
| 87 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 85 | + public function get_items_permissions_check($request) { |
|
| 86 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
| 87 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | return true; |
@@ -97,9 +97,9 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @return bool|\WP_Error |
| 99 | 99 | */ |
| 100 | - public function create_item_permissions_check( $request ) { |
|
| 101 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'create' ) ) { |
|
| 102 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 100 | + public function create_item_permissions_check($request) { |
|
| 101 | + if ( ! wc_rest_check_manager_permissions('settings', 'create')) { |
|
| 102 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | return true; |
@@ -112,9 +112,9 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | * @return bool|\WP_Error |
| 114 | 114 | */ |
| 115 | - public function delete_item_permissions_check( $request ) { |
|
| 116 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) { |
|
| 117 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 115 | + public function delete_item_permissions_check($request) { |
|
| 116 | + if ( ! wc_rest_check_manager_permissions('settings', 'delete')) { |
|
| 117 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | return true; |
@@ -126,32 +126,32 @@ discard block |
||
| 126 | 126 | * @param \WP_REST_Request $request Request params. |
| 127 | 127 | * @return array |
| 128 | 128 | */ |
| 129 | - public function get_items( $request ) { |
|
| 129 | + public function get_items($request) { |
|
| 130 | 130 | $tax_classes = array(); |
| 131 | 131 | |
| 132 | 132 | // Add standard class. |
| 133 | 133 | $tax_classes[] = array( |
| 134 | 134 | 'slug' => 'standard', |
| 135 | - 'name' => __( 'Standard rate', 'woocommerce' ), |
|
| 135 | + 'name' => __('Standard rate', 'woocommerce'), |
|
| 136 | 136 | ); |
| 137 | 137 | |
| 138 | 138 | $classes = \WC_Tax::get_tax_classes(); |
| 139 | 139 | |
| 140 | - foreach ( $classes as $class ) { |
|
| 140 | + foreach ($classes as $class) { |
|
| 141 | 141 | $tax_classes[] = array( |
| 142 | - 'slug' => sanitize_title( $class ), |
|
| 142 | + 'slug' => sanitize_title($class), |
|
| 143 | 143 | 'name' => $class, |
| 144 | 144 | ); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | $data = array(); |
| 148 | - foreach ( $tax_classes as $tax_class ) { |
|
| 149 | - $class = $this->prepare_item_for_response( $tax_class, $request ); |
|
| 150 | - $class = $this->prepare_response_for_collection( $class ); |
|
| 148 | + foreach ($tax_classes as $tax_class) { |
|
| 149 | + $class = $this->prepare_item_for_response($tax_class, $request); |
|
| 150 | + $class = $this->prepare_response_for_collection($class); |
|
| 151 | 151 | $data[] = $class; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - return rest_ensure_response( $data ); |
|
| 154 | + return rest_ensure_response($data); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -160,33 +160,33 @@ discard block |
||
| 160 | 160 | * @param \WP_REST_Request $request Full details about the request. |
| 161 | 161 | * @return \WP_Error\WP_REST_Response |
| 162 | 162 | */ |
| 163 | - public function create_item( $request ) { |
|
| 163 | + public function create_item($request) { |
|
| 164 | 164 | $exists = false; |
| 165 | 165 | $classes = \WC_Tax::get_tax_classes(); |
| 166 | 166 | $tax_class = array( |
| 167 | - 'slug' => sanitize_title( $request['name'] ), |
|
| 167 | + 'slug' => sanitize_title($request['name']), |
|
| 168 | 168 | 'name' => $request['name'], |
| 169 | 169 | ); |
| 170 | 170 | |
| 171 | 171 | // Check if class exists. |
| 172 | - foreach ( $classes as $key => $class ) { |
|
| 173 | - if ( sanitize_title( $class ) === $tax_class['slug'] ) { |
|
| 172 | + foreach ($classes as $key => $class) { |
|
| 173 | + if (sanitize_title($class) === $tax_class['slug']) { |
|
| 174 | 174 | $exists = true; |
| 175 | 175 | break; |
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | // Return error if tax class already exists. |
| 180 | - if ( $exists ) { |
|
| 181 | - return new \WP_Error( 'woocommerce_rest_tax_class_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 180 | + if ($exists) { |
|
| 181 | + return new \WP_Error('woocommerce_rest_tax_class_exists', __('Cannot create existing resource.', 'woocommerce'), array('status' => 400)); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | // Add the new class. |
| 185 | 185 | $classes[] = $tax_class['name']; |
| 186 | 186 | |
| 187 | - update_option( 'woocommerce_tax_classes', implode( "\n", $classes ) ); |
|
| 187 | + update_option('woocommerce_tax_classes', implode("\n", $classes)); |
|
| 188 | 188 | |
| 189 | - $this->update_additional_fields_for_object( $tax_class, $request ); |
|
| 189 | + $this->update_additional_fields_for_object($tax_class, $request); |
|
| 190 | 190 | |
| 191 | 191 | /** |
| 192 | 192 | * Fires after a tax class is created or updated via the REST API. |
@@ -195,13 +195,13 @@ discard block |
||
| 195 | 195 | * @param \WP_REST_Request $request Request object. |
| 196 | 196 | * @param boolean $creating True when creating tax class, false when updating tax class. |
| 197 | 197 | */ |
| 198 | - do_action( 'woocommerce_rest_insert_tax_class', (object) $tax_class, $request, true ); |
|
| 198 | + do_action('woocommerce_rest_insert_tax_class', (object) $tax_class, $request, true); |
|
| 199 | 199 | |
| 200 | - $request->set_param( 'context', 'edit' ); |
|
| 201 | - $response = $this->prepare_item_for_response( $tax_class, $request ); |
|
| 202 | - $response = rest_ensure_response( $response ); |
|
| 203 | - $response->set_status( 201 ); |
|
| 204 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug'] ) ) ); |
|
| 200 | + $request->set_param('context', 'edit'); |
|
| 201 | + $response = $this->prepare_item_for_response($tax_class, $request); |
|
| 202 | + $response = rest_ensure_response($response); |
|
| 203 | + $response->set_status(201); |
|
| 204 | + $response->header('Location', rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug']))); |
|
| 205 | 205 | |
| 206 | 206 | return $response; |
| 207 | 207 | } |
@@ -212,40 +212,40 @@ discard block |
||
| 212 | 212 | * @param \WP_REST_Request $request Full details about the request. |
| 213 | 213 | * @return \WP_Error\WP_REST_Response |
| 214 | 214 | */ |
| 215 | - public function delete_item( $request ) { |
|
| 215 | + public function delete_item($request) { |
|
| 216 | 216 | global $wpdb; |
| 217 | 217 | |
| 218 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 218 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
| 219 | 219 | |
| 220 | 220 | // We don't support trashing for this type, error out. |
| 221 | - if ( ! $force ) { |
|
| 222 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Taxes do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
| 221 | + if ( ! $force) { |
|
| 222 | + return new \WP_Error('woocommerce_rest_trash_not_supported', __('Taxes do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | $tax_class = array( |
| 226 | - 'slug' => sanitize_title( $request['slug'] ), |
|
| 226 | + 'slug' => sanitize_title($request['slug']), |
|
| 227 | 227 | 'name' => '', |
| 228 | 228 | ); |
| 229 | 229 | $classes = \WC_Tax::get_tax_classes(); |
| 230 | 230 | $deleted = false; |
| 231 | 231 | |
| 232 | - foreach ( $classes as $key => $class ) { |
|
| 233 | - if ( sanitize_title( $class ) === $tax_class['slug'] ) { |
|
| 232 | + foreach ($classes as $key => $class) { |
|
| 233 | + if (sanitize_title($class) === $tax_class['slug']) { |
|
| 234 | 234 | $tax_class['name'] = $class; |
| 235 | - unset( $classes[ $key ] ); |
|
| 235 | + unset($classes[$key]); |
|
| 236 | 236 | $deleted = true; |
| 237 | 237 | break; |
| 238 | 238 | } |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if ( ! $deleted ) { |
|
| 242 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 241 | + if ( ! $deleted) { |
|
| 242 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource id.', 'woocommerce'), array('status' => 400)); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - $request->set_param( 'context', 'edit' ); |
|
| 246 | - $previous = $this->prepare_item_for_response( $tax_class, $request ); |
|
| 245 | + $request->set_param('context', 'edit'); |
|
| 246 | + $previous = $this->prepare_item_for_response($tax_class, $request); |
|
| 247 | 247 | |
| 248 | - update_option( 'woocommerce_tax_classes', implode( "\n", $classes ) ); |
|
| 248 | + update_option('woocommerce_tax_classes', implode("\n", $classes)); |
|
| 249 | 249 | |
| 250 | 250 | // Delete tax rate locations locations from the selected class. |
| 251 | 251 | $wpdb->query( |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | ); |
| 264 | 264 | |
| 265 | 265 | // Delete tax rates in the selected class. |
| 266 | - $wpdb->delete( $wpdb->prefix . 'woocommerce_tax_rates', array( 'tax_rate_class' => $tax_class['slug'] ), array( '%s' ) ); |
|
| 266 | + $wpdb->delete($wpdb->prefix . 'woocommerce_tax_rates', array('tax_rate_class' => $tax_class['slug']), array('%s')); |
|
| 267 | 267 | |
| 268 | 268 | $response = new \WP_REST_Response(); |
| 269 | 269 | $response->set_data( |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * @param \WP_REST_Response $response The response returned from the API. |
| 281 | 281 | * @param \WP_REST_Request $request The request sent to the API. |
| 282 | 282 | */ |
| 283 | - do_action( 'woocommerce_rest_delete_tax', (object) $tax_class, $response, $request ); |
|
| 283 | + do_action('woocommerce_rest_delete_tax', (object) $tax_class, $response, $request); |
|
| 284 | 284 | |
| 285 | 285 | return $response; |
| 286 | 286 | } |
@@ -292,17 +292,17 @@ discard block |
||
| 292 | 292 | * @param \WP_REST_Request $request Request object. |
| 293 | 293 | * @return \WP_REST_Response $response Response data. |
| 294 | 294 | */ |
| 295 | - public function prepare_item_for_response( $tax_class, $request ) { |
|
| 295 | + public function prepare_item_for_response($tax_class, $request) { |
|
| 296 | 296 | $data = $tax_class; |
| 297 | 297 | |
| 298 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 299 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 300 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 298 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 299 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 300 | + $data = $this->filter_response_by_context($data, $context); |
|
| 301 | 301 | |
| 302 | 302 | // Wrap the data in a response object. |
| 303 | - $response = rest_ensure_response( $data ); |
|
| 303 | + $response = rest_ensure_response($data); |
|
| 304 | 304 | |
| 305 | - $response->add_links( $this->prepare_links() ); |
|
| 305 | + $response->add_links($this->prepare_links()); |
|
| 306 | 306 | |
| 307 | 307 | /** |
| 308 | 308 | * Filter tax object returned from the REST API. |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * @param stdClass $tax_class Tax object used to create response. |
| 312 | 312 | * @param \WP_REST_Request $request Request object. |
| 313 | 313 | */ |
| 314 | - return apply_filters( 'woocommerce_rest_prepare_tax', $response, (object) $tax_class, $request ); |
|
| 314 | + return apply_filters('woocommerce_rest_prepare_tax', $response, (object) $tax_class, $request); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | protected function prepare_links() { |
| 323 | 323 | $links = array( |
| 324 | 324 | 'collection' => array( |
| 325 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
| 325 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
| 326 | 326 | ), |
| 327 | 327 | ); |
| 328 | 328 | |
@@ -341,15 +341,15 @@ discard block |
||
| 341 | 341 | 'type' => 'object', |
| 342 | 342 | 'properties' => array( |
| 343 | 343 | 'slug' => array( |
| 344 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 344 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 345 | 345 | 'type' => 'string', |
| 346 | - 'context' => array( 'view', 'edit' ), |
|
| 346 | + 'context' => array('view', 'edit'), |
|
| 347 | 347 | 'readonly' => true, |
| 348 | 348 | ), |
| 349 | 349 | 'name' => array( |
| 350 | - 'description' => __( 'Tax class name.', 'woocommerce' ), |
|
| 350 | + 'description' => __('Tax class name.', 'woocommerce'), |
|
| 351 | 351 | 'type' => 'string', |
| 352 | - 'context' => array( 'view', 'edit' ), |
|
| 352 | + 'context' => array('view', 'edit'), |
|
| 353 | 353 | 'required' => true, |
| 354 | 354 | 'arg_options' => array( |
| 355 | 355 | 'sanitize_callback' => 'sanitize_text_field', |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | ), |
| 359 | 359 | ); |
| 360 | 360 | |
| 361 | - return $this->add_additional_fields_schema( $schema ); |
|
| 361 | + return $this->add_additional_fields_schema($schema); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | /** |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | */ |
| 369 | 369 | public function get_collection_params() { |
| 370 | 370 | return array( |
| 371 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 371 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 372 | 372 | ); |
| 373 | 373 | } |
| 374 | 374 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API System Status controller class. |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | array( |
| 34 | 34 | array( |
| 35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
| 36 | - 'callback' => array( $this, 'get_items' ), |
|
| 37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 36 | + 'callback' => array($this, 'get_items'), |
|
| 37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 38 | 38 | 'args' => $this->get_collection_params(), |
| 39 | 39 | ), |
| 40 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 40 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 41 | 41 | ), |
| 42 | 42 | true |
| 43 | 43 | ); |
@@ -49,9 +49,9 @@ discard block |
||
| 49 | 49 | * @param \WP_REST_Request $request Full details about the request. |
| 50 | 50 | * @return \WP_Error|boolean |
| 51 | 51 | */ |
| 52 | - public function get_items_permissions_check( $request ) { |
|
| 53 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { |
|
| 54 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 52 | + public function get_items_permissions_check($request) { |
|
| 53 | + if ( ! wc_rest_check_manager_permissions('system_status', 'read')) { |
|
| 54 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 55 | 55 | } |
| 56 | 56 | return true; |
| 57 | 57 | } |
@@ -62,24 +62,24 @@ discard block |
||
| 62 | 62 | * @param \WP_REST_Request $request Full details about the request. |
| 63 | 63 | * @return \WP_Error\WP_REST_Response |
| 64 | 64 | */ |
| 65 | - public function get_items( $request ) { |
|
| 65 | + public function get_items($request) { |
|
| 66 | 66 | $schema = $this->get_item_schema(); |
| 67 | 67 | $mappings = $this->get_item_mappings(); |
| 68 | 68 | $response = array(); |
| 69 | 69 | |
| 70 | - foreach ( $mappings as $section => $values ) { |
|
| 71 | - foreach ( $values as $key => $value ) { |
|
| 72 | - if ( isset( $schema['properties'][ $section ]['properties'][ $key ]['type'] ) ) { |
|
| 73 | - settype( $values[ $key ], $schema['properties'][ $section ]['properties'][ $key ]['type'] ); |
|
| 70 | + foreach ($mappings as $section => $values) { |
|
| 71 | + foreach ($values as $key => $value) { |
|
| 72 | + if (isset($schema['properties'][$section]['properties'][$key]['type'])) { |
|
| 73 | + settype($values[$key], $schema['properties'][$section]['properties'][$key]['type']); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | - settype( $values, $schema['properties'][ $section ]['type'] ); |
|
| 77 | - $response[ $section ] = $values; |
|
| 76 | + settype($values, $schema['properties'][$section]['type']); |
|
| 77 | + $response[$section] = $values; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - $response = $this->prepare_item_for_response( $response, $request ); |
|
| 80 | + $response = $this->prepare_item_for_response($response, $request); |
|
| 81 | 81 | |
| 82 | - return rest_ensure_response( $response ); |
|
| 82 | + return rest_ensure_response($response); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -94,229 +94,229 @@ discard block |
||
| 94 | 94 | 'type' => 'object', |
| 95 | 95 | 'properties' => array( |
| 96 | 96 | 'environment' => array( |
| 97 | - 'description' => __( 'Environment.', 'woocommerce' ), |
|
| 97 | + 'description' => __('Environment.', 'woocommerce'), |
|
| 98 | 98 | 'type' => 'object', |
| 99 | - 'context' => array( 'view' ), |
|
| 99 | + 'context' => array('view'), |
|
| 100 | 100 | 'readonly' => true, |
| 101 | 101 | 'properties' => array( |
| 102 | 102 | 'home_url' => array( |
| 103 | - 'description' => __( 'Home URL.', 'woocommerce' ), |
|
| 103 | + 'description' => __('Home URL.', 'woocommerce'), |
|
| 104 | 104 | 'type' => 'string', |
| 105 | 105 | 'format' => 'uri', |
| 106 | - 'context' => array( 'view' ), |
|
| 106 | + 'context' => array('view'), |
|
| 107 | 107 | 'readonly' => true, |
| 108 | 108 | ), |
| 109 | 109 | 'site_url' => array( |
| 110 | - 'description' => __( 'Site URL.', 'woocommerce' ), |
|
| 110 | + 'description' => __('Site URL.', 'woocommerce'), |
|
| 111 | 111 | 'type' => 'string', |
| 112 | 112 | 'format' => 'uri', |
| 113 | - 'context' => array( 'view' ), |
|
| 113 | + 'context' => array('view'), |
|
| 114 | 114 | 'readonly' => true, |
| 115 | 115 | ), |
| 116 | 116 | 'wc_version' => array( |
| 117 | - 'description' => __( 'WooCommerce version.', 'woocommerce' ), |
|
| 117 | + 'description' => __('WooCommerce version.', 'woocommerce'), |
|
| 118 | 118 | 'type' => 'string', |
| 119 | - 'context' => array( 'view' ), |
|
| 119 | + 'context' => array('view'), |
|
| 120 | 120 | 'readonly' => true, |
| 121 | 121 | ), |
| 122 | 122 | 'log_directory' => array( |
| 123 | - 'description' => __( 'Log directory.', 'woocommerce' ), |
|
| 123 | + 'description' => __('Log directory.', 'woocommerce'), |
|
| 124 | 124 | 'type' => 'string', |
| 125 | - 'context' => array( 'view' ), |
|
| 125 | + 'context' => array('view'), |
|
| 126 | 126 | 'readonly' => true, |
| 127 | 127 | ), |
| 128 | 128 | 'log_directory_writable' => array( |
| 129 | - 'description' => __( 'Is log directory writable?', 'woocommerce' ), |
|
| 129 | + 'description' => __('Is log directory writable?', 'woocommerce'), |
|
| 130 | 130 | 'type' => 'boolean', |
| 131 | - 'context' => array( 'view' ), |
|
| 131 | + 'context' => array('view'), |
|
| 132 | 132 | 'readonly' => true, |
| 133 | 133 | ), |
| 134 | 134 | 'wp_version' => array( |
| 135 | - 'description' => __( 'WordPress version.', 'woocommerce' ), |
|
| 135 | + 'description' => __('WordPress version.', 'woocommerce'), |
|
| 136 | 136 | 'type' => 'string', |
| 137 | - 'context' => array( 'view' ), |
|
| 137 | + 'context' => array('view'), |
|
| 138 | 138 | 'readonly' => true, |
| 139 | 139 | ), |
| 140 | 140 | 'wp_multisite' => array( |
| 141 | - 'description' => __( 'Is WordPress multisite?', 'woocommerce' ), |
|
| 141 | + 'description' => __('Is WordPress multisite?', 'woocommerce'), |
|
| 142 | 142 | 'type' => 'boolean', |
| 143 | - 'context' => array( 'view' ), |
|
| 143 | + 'context' => array('view'), |
|
| 144 | 144 | 'readonly' => true, |
| 145 | 145 | ), |
| 146 | 146 | 'wp_memory_limit' => array( |
| 147 | - 'description' => __( 'WordPress memory limit.', 'woocommerce' ), |
|
| 147 | + 'description' => __('WordPress memory limit.', 'woocommerce'), |
|
| 148 | 148 | 'type' => 'integer', |
| 149 | - 'context' => array( 'view' ), |
|
| 149 | + 'context' => array('view'), |
|
| 150 | 150 | 'readonly' => true, |
| 151 | 151 | ), |
| 152 | 152 | 'wp_debug_mode' => array( |
| 153 | - 'description' => __( 'Is WordPress debug mode active?', 'woocommerce' ), |
|
| 153 | + 'description' => __('Is WordPress debug mode active?', 'woocommerce'), |
|
| 154 | 154 | 'type' => 'boolean', |
| 155 | - 'context' => array( 'view' ), |
|
| 155 | + 'context' => array('view'), |
|
| 156 | 156 | 'readonly' => true, |
| 157 | 157 | ), |
| 158 | 158 | 'wp_cron' => array( |
| 159 | - 'description' => __( 'Are WordPress cron jobs enabled?', 'woocommerce' ), |
|
| 159 | + 'description' => __('Are WordPress cron jobs enabled?', 'woocommerce'), |
|
| 160 | 160 | 'type' => 'boolean', |
| 161 | - 'context' => array( 'view' ), |
|
| 161 | + 'context' => array('view'), |
|
| 162 | 162 | 'readonly' => true, |
| 163 | 163 | ), |
| 164 | 164 | 'language' => array( |
| 165 | - 'description' => __( 'WordPress language.', 'woocommerce' ), |
|
| 165 | + 'description' => __('WordPress language.', 'woocommerce'), |
|
| 166 | 166 | 'type' => 'string', |
| 167 | - 'context' => array( 'view' ), |
|
| 167 | + 'context' => array('view'), |
|
| 168 | 168 | 'readonly' => true, |
| 169 | 169 | ), |
| 170 | 170 | 'server_info' => array( |
| 171 | - 'description' => __( 'Server info.', 'woocommerce' ), |
|
| 171 | + 'description' => __('Server info.', 'woocommerce'), |
|
| 172 | 172 | 'type' => 'string', |
| 173 | - 'context' => array( 'view' ), |
|
| 173 | + 'context' => array('view'), |
|
| 174 | 174 | 'readonly' => true, |
| 175 | 175 | ), |
| 176 | 176 | 'php_version' => array( |
| 177 | - 'description' => __( 'PHP version.', 'woocommerce' ), |
|
| 177 | + 'description' => __('PHP version.', 'woocommerce'), |
|
| 178 | 178 | 'type' => 'string', |
| 179 | - 'context' => array( 'view' ), |
|
| 179 | + 'context' => array('view'), |
|
| 180 | 180 | 'readonly' => true, |
| 181 | 181 | ), |
| 182 | 182 | 'php_post_max_size' => array( |
| 183 | - 'description' => __( 'PHP post max size.', 'woocommerce' ), |
|
| 183 | + 'description' => __('PHP post max size.', 'woocommerce'), |
|
| 184 | 184 | 'type' => 'integer', |
| 185 | - 'context' => array( 'view' ), |
|
| 185 | + 'context' => array('view'), |
|
| 186 | 186 | 'readonly' => true, |
| 187 | 187 | ), |
| 188 | 188 | 'php_max_execution_time' => array( |
| 189 | - 'description' => __( 'PHP max execution time.', 'woocommerce' ), |
|
| 189 | + 'description' => __('PHP max execution time.', 'woocommerce'), |
|
| 190 | 190 | 'type' => 'integer', |
| 191 | - 'context' => array( 'view' ), |
|
| 191 | + 'context' => array('view'), |
|
| 192 | 192 | 'readonly' => true, |
| 193 | 193 | ), |
| 194 | 194 | 'php_max_input_vars' => array( |
| 195 | - 'description' => __( 'PHP max input vars.', 'woocommerce' ), |
|
| 195 | + 'description' => __('PHP max input vars.', 'woocommerce'), |
|
| 196 | 196 | 'type' => 'integer', |
| 197 | - 'context' => array( 'view' ), |
|
| 197 | + 'context' => array('view'), |
|
| 198 | 198 | 'readonly' => true, |
| 199 | 199 | ), |
| 200 | 200 | 'curl_version' => array( |
| 201 | - 'description' => __( 'cURL version.', 'woocommerce' ), |
|
| 201 | + 'description' => __('cURL version.', 'woocommerce'), |
|
| 202 | 202 | 'type' => 'string', |
| 203 | - 'context' => array( 'view' ), |
|
| 203 | + 'context' => array('view'), |
|
| 204 | 204 | 'readonly' => true, |
| 205 | 205 | ), |
| 206 | 206 | 'suhosin_installed' => array( |
| 207 | - 'description' => __( 'Is SUHOSIN installed?', 'woocommerce' ), |
|
| 207 | + 'description' => __('Is SUHOSIN installed?', 'woocommerce'), |
|
| 208 | 208 | 'type' => 'boolean', |
| 209 | - 'context' => array( 'view' ), |
|
| 209 | + 'context' => array('view'), |
|
| 210 | 210 | 'readonly' => true, |
| 211 | 211 | ), |
| 212 | 212 | 'max_upload_size' => array( |
| 213 | - 'description' => __( 'Max upload size.', 'woocommerce' ), |
|
| 213 | + 'description' => __('Max upload size.', 'woocommerce'), |
|
| 214 | 214 | 'type' => 'integer', |
| 215 | - 'context' => array( 'view' ), |
|
| 215 | + 'context' => array('view'), |
|
| 216 | 216 | 'readonly' => true, |
| 217 | 217 | ), |
| 218 | 218 | 'mysql_version' => array( |
| 219 | - 'description' => __( 'MySQL version.', 'woocommerce' ), |
|
| 219 | + 'description' => __('MySQL version.', 'woocommerce'), |
|
| 220 | 220 | 'type' => 'string', |
| 221 | - 'context' => array( 'view' ), |
|
| 221 | + 'context' => array('view'), |
|
| 222 | 222 | 'readonly' => true, |
| 223 | 223 | ), |
| 224 | 224 | 'mysql_version_string' => array( |
| 225 | - 'description' => __( 'MySQL version string.', 'woocommerce' ), |
|
| 225 | + 'description' => __('MySQL version string.', 'woocommerce'), |
|
| 226 | 226 | 'type' => 'string', |
| 227 | - 'context' => array( 'view' ), |
|
| 227 | + 'context' => array('view'), |
|
| 228 | 228 | 'readonly' => true, |
| 229 | 229 | ), |
| 230 | 230 | 'default_timezone' => array( |
| 231 | - 'description' => __( 'Default timezone.', 'woocommerce' ), |
|
| 231 | + 'description' => __('Default timezone.', 'woocommerce'), |
|
| 232 | 232 | 'type' => 'string', |
| 233 | - 'context' => array( 'view' ), |
|
| 233 | + 'context' => array('view'), |
|
| 234 | 234 | 'readonly' => true, |
| 235 | 235 | ), |
| 236 | 236 | 'fsockopen_or_curl_enabled' => array( |
| 237 | - 'description' => __( 'Is fsockopen/cURL enabled?', 'woocommerce' ), |
|
| 237 | + 'description' => __('Is fsockopen/cURL enabled?', 'woocommerce'), |
|
| 238 | 238 | 'type' => 'boolean', |
| 239 | - 'context' => array( 'view' ), |
|
| 239 | + 'context' => array('view'), |
|
| 240 | 240 | 'readonly' => true, |
| 241 | 241 | ), |
| 242 | 242 | 'soapclient_enabled' => array( |
| 243 | - 'description' => __( 'Is SoapClient class enabled?', 'woocommerce' ), |
|
| 243 | + 'description' => __('Is SoapClient class enabled?', 'woocommerce'), |
|
| 244 | 244 | 'type' => 'boolean', |
| 245 | - 'context' => array( 'view' ), |
|
| 245 | + 'context' => array('view'), |
|
| 246 | 246 | 'readonly' => true, |
| 247 | 247 | ), |
| 248 | 248 | 'domdocument_enabled' => array( |
| 249 | - 'description' => __( 'Is DomDocument class enabled?', 'woocommerce' ), |
|
| 249 | + 'description' => __('Is DomDocument class enabled?', 'woocommerce'), |
|
| 250 | 250 | 'type' => 'boolean', |
| 251 | - 'context' => array( 'view' ), |
|
| 251 | + 'context' => array('view'), |
|
| 252 | 252 | 'readonly' => true, |
| 253 | 253 | ), |
| 254 | 254 | 'gzip_enabled' => array( |
| 255 | - 'description' => __( 'Is GZip enabled?', 'woocommerce' ), |
|
| 255 | + 'description' => __('Is GZip enabled?', 'woocommerce'), |
|
| 256 | 256 | 'type' => 'boolean', |
| 257 | - 'context' => array( 'view' ), |
|
| 257 | + 'context' => array('view'), |
|
| 258 | 258 | 'readonly' => true, |
| 259 | 259 | ), |
| 260 | 260 | 'mbstring_enabled' => array( |
| 261 | - 'description' => __( 'Is mbstring enabled?', 'woocommerce' ), |
|
| 261 | + 'description' => __('Is mbstring enabled?', 'woocommerce'), |
|
| 262 | 262 | 'type' => 'boolean', |
| 263 | - 'context' => array( 'view' ), |
|
| 263 | + 'context' => array('view'), |
|
| 264 | 264 | 'readonly' => true, |
| 265 | 265 | ), |
| 266 | 266 | 'remote_post_successful' => array( |
| 267 | - 'description' => __( 'Remote POST successful?', 'woocommerce' ), |
|
| 267 | + 'description' => __('Remote POST successful?', 'woocommerce'), |
|
| 268 | 268 | 'type' => 'boolean', |
| 269 | - 'context' => array( 'view' ), |
|
| 269 | + 'context' => array('view'), |
|
| 270 | 270 | 'readonly' => true, |
| 271 | 271 | ), |
| 272 | 272 | 'remote_post_response' => array( |
| 273 | - 'description' => __( 'Remote POST response.', 'woocommerce' ), |
|
| 273 | + 'description' => __('Remote POST response.', 'woocommerce'), |
|
| 274 | 274 | 'type' => 'string', |
| 275 | - 'context' => array( 'view' ), |
|
| 275 | + 'context' => array('view'), |
|
| 276 | 276 | 'readonly' => true, |
| 277 | 277 | ), |
| 278 | 278 | 'remote_get_successful' => array( |
| 279 | - 'description' => __( 'Remote GET successful?', 'woocommerce' ), |
|
| 279 | + 'description' => __('Remote GET successful?', 'woocommerce'), |
|
| 280 | 280 | 'type' => 'boolean', |
| 281 | - 'context' => array( 'view' ), |
|
| 281 | + 'context' => array('view'), |
|
| 282 | 282 | 'readonly' => true, |
| 283 | 283 | ), |
| 284 | 284 | 'remote_get_response' => array( |
| 285 | - 'description' => __( 'Remote GET response.', 'woocommerce' ), |
|
| 285 | + 'description' => __('Remote GET response.', 'woocommerce'), |
|
| 286 | 286 | 'type' => 'string', |
| 287 | - 'context' => array( 'view' ), |
|
| 287 | + 'context' => array('view'), |
|
| 288 | 288 | 'readonly' => true, |
| 289 | 289 | ), |
| 290 | 290 | ), |
| 291 | 291 | ), |
| 292 | 292 | 'database' => array( |
| 293 | - 'description' => __( 'Database.', 'woocommerce' ), |
|
| 293 | + 'description' => __('Database.', 'woocommerce'), |
|
| 294 | 294 | 'type' => 'object', |
| 295 | - 'context' => array( 'view' ), |
|
| 295 | + 'context' => array('view'), |
|
| 296 | 296 | 'readonly' => true, |
| 297 | 297 | 'properties' => array( |
| 298 | 298 | 'wc_database_version' => array( |
| 299 | - 'description' => __( 'WC database version.', 'woocommerce' ), |
|
| 299 | + 'description' => __('WC database version.', 'woocommerce'), |
|
| 300 | 300 | 'type' => 'string', |
| 301 | - 'context' => array( 'view' ), |
|
| 301 | + 'context' => array('view'), |
|
| 302 | 302 | 'readonly' => true, |
| 303 | 303 | ), |
| 304 | 304 | 'database_prefix' => array( |
| 305 | - 'description' => __( 'Database prefix.', 'woocommerce' ), |
|
| 305 | + 'description' => __('Database prefix.', 'woocommerce'), |
|
| 306 | 306 | 'type' => 'string', |
| 307 | - 'context' => array( 'view' ), |
|
| 307 | + 'context' => array('view'), |
|
| 308 | 308 | 'readonly' => true, |
| 309 | 309 | ), |
| 310 | 310 | 'maxmind_geoip_database' => array( |
| 311 | - 'description' => __( 'MaxMind GeoIP database.', 'woocommerce' ), |
|
| 311 | + 'description' => __('MaxMind GeoIP database.', 'woocommerce'), |
|
| 312 | 312 | 'type' => 'string', |
| 313 | - 'context' => array( 'view' ), |
|
| 313 | + 'context' => array('view'), |
|
| 314 | 314 | 'readonly' => true, |
| 315 | 315 | ), |
| 316 | 316 | 'database_tables' => array( |
| 317 | - 'description' => __( 'Database tables.', 'woocommerce' ), |
|
| 317 | + 'description' => __('Database tables.', 'woocommerce'), |
|
| 318 | 318 | 'type' => 'array', |
| 319 | - 'context' => array( 'view' ), |
|
| 319 | + 'context' => array('view'), |
|
| 320 | 320 | 'readonly' => true, |
| 321 | 321 | 'items' => array( |
| 322 | 322 | 'type' => 'string', |
@@ -325,190 +325,190 @@ discard block |
||
| 325 | 325 | ), |
| 326 | 326 | ), |
| 327 | 327 | 'active_plugins' => array( |
| 328 | - 'description' => __( 'Active plugins.', 'woocommerce' ), |
|
| 328 | + 'description' => __('Active plugins.', 'woocommerce'), |
|
| 329 | 329 | 'type' => 'array', |
| 330 | - 'context' => array( 'view' ), |
|
| 330 | + 'context' => array('view'), |
|
| 331 | 331 | 'readonly' => true, |
| 332 | 332 | 'items' => array( |
| 333 | 333 | 'type' => 'string', |
| 334 | 334 | ), |
| 335 | 335 | ), |
| 336 | 336 | 'inactive_plugins' => array( |
| 337 | - 'description' => __( 'Inactive plugins.', 'woocommerce' ), |
|
| 337 | + 'description' => __('Inactive plugins.', 'woocommerce'), |
|
| 338 | 338 | 'type' => 'array', |
| 339 | - 'context' => array( 'view' ), |
|
| 339 | + 'context' => array('view'), |
|
| 340 | 340 | 'readonly' => true, |
| 341 | 341 | 'items' => array( |
| 342 | 342 | 'type' => 'string', |
| 343 | 343 | ), |
| 344 | 344 | ), |
| 345 | 345 | 'dropins_mu_plugins' => array( |
| 346 | - 'description' => __( 'Dropins & MU plugins.', 'woocommerce' ), |
|
| 346 | + 'description' => __('Dropins & MU plugins.', 'woocommerce'), |
|
| 347 | 347 | 'type' => 'array', |
| 348 | - 'context' => array( 'view' ), |
|
| 348 | + 'context' => array('view'), |
|
| 349 | 349 | 'readonly' => true, |
| 350 | 350 | 'items' => array( |
| 351 | 351 | 'type' => 'string', |
| 352 | 352 | ), |
| 353 | 353 | ), |
| 354 | 354 | 'theme' => array( |
| 355 | - 'description' => __( 'Theme.', 'woocommerce' ), |
|
| 355 | + 'description' => __('Theme.', 'woocommerce'), |
|
| 356 | 356 | 'type' => 'object', |
| 357 | - 'context' => array( 'view' ), |
|
| 357 | + 'context' => array('view'), |
|
| 358 | 358 | 'readonly' => true, |
| 359 | 359 | 'properties' => array( |
| 360 | 360 | 'name' => array( |
| 361 | - 'description' => __( 'Theme name.', 'woocommerce' ), |
|
| 361 | + 'description' => __('Theme name.', 'woocommerce'), |
|
| 362 | 362 | 'type' => 'string', |
| 363 | - 'context' => array( 'view' ), |
|
| 363 | + 'context' => array('view'), |
|
| 364 | 364 | 'readonly' => true, |
| 365 | 365 | ), |
| 366 | 366 | 'version' => array( |
| 367 | - 'description' => __( 'Theme version.', 'woocommerce' ), |
|
| 367 | + 'description' => __('Theme version.', 'woocommerce'), |
|
| 368 | 368 | 'type' => 'string', |
| 369 | - 'context' => array( 'view' ), |
|
| 369 | + 'context' => array('view'), |
|
| 370 | 370 | 'readonly' => true, |
| 371 | 371 | ), |
| 372 | 372 | 'version_latest' => array( |
| 373 | - 'description' => __( 'Latest version of theme.', 'woocommerce' ), |
|
| 373 | + 'description' => __('Latest version of theme.', 'woocommerce'), |
|
| 374 | 374 | 'type' => 'string', |
| 375 | - 'context' => array( 'view' ), |
|
| 375 | + 'context' => array('view'), |
|
| 376 | 376 | 'readonly' => true, |
| 377 | 377 | ), |
| 378 | 378 | 'author_url' => array( |
| 379 | - 'description' => __( 'Theme author URL.', 'woocommerce' ), |
|
| 379 | + 'description' => __('Theme author URL.', 'woocommerce'), |
|
| 380 | 380 | 'type' => 'string', |
| 381 | 381 | 'format' => 'uri', |
| 382 | - 'context' => array( 'view' ), |
|
| 382 | + 'context' => array('view'), |
|
| 383 | 383 | 'readonly' => true, |
| 384 | 384 | ), |
| 385 | 385 | 'is_child_theme' => array( |
| 386 | - 'description' => __( 'Is this theme a child theme?', 'woocommerce' ), |
|
| 386 | + 'description' => __('Is this theme a child theme?', 'woocommerce'), |
|
| 387 | 387 | 'type' => 'boolean', |
| 388 | - 'context' => array( 'view' ), |
|
| 388 | + 'context' => array('view'), |
|
| 389 | 389 | 'readonly' => true, |
| 390 | 390 | ), |
| 391 | 391 | 'has_woocommerce_support' => array( |
| 392 | - 'description' => __( 'Does the theme declare WooCommerce support?', 'woocommerce' ), |
|
| 392 | + 'description' => __('Does the theme declare WooCommerce support?', 'woocommerce'), |
|
| 393 | 393 | 'type' => 'boolean', |
| 394 | - 'context' => array( 'view' ), |
|
| 394 | + 'context' => array('view'), |
|
| 395 | 395 | 'readonly' => true, |
| 396 | 396 | ), |
| 397 | 397 | 'has_woocommerce_file' => array( |
| 398 | - 'description' => __( 'Does the theme have a woocommerce.php file?', 'woocommerce' ), |
|
| 398 | + 'description' => __('Does the theme have a woocommerce.php file?', 'woocommerce'), |
|
| 399 | 399 | 'type' => 'boolean', |
| 400 | - 'context' => array( 'view' ), |
|
| 400 | + 'context' => array('view'), |
|
| 401 | 401 | 'readonly' => true, |
| 402 | 402 | ), |
| 403 | 403 | 'has_outdated_templates' => array( |
| 404 | - 'description' => __( 'Does this theme have outdated templates?', 'woocommerce' ), |
|
| 404 | + 'description' => __('Does this theme have outdated templates?', 'woocommerce'), |
|
| 405 | 405 | 'type' => 'boolean', |
| 406 | - 'context' => array( 'view' ), |
|
| 406 | + 'context' => array('view'), |
|
| 407 | 407 | 'readonly' => true, |
| 408 | 408 | ), |
| 409 | 409 | 'overrides' => array( |
| 410 | - 'description' => __( 'Template overrides.', 'woocommerce' ), |
|
| 410 | + 'description' => __('Template overrides.', 'woocommerce'), |
|
| 411 | 411 | 'type' => 'array', |
| 412 | - 'context' => array( 'view' ), |
|
| 412 | + 'context' => array('view'), |
|
| 413 | 413 | 'readonly' => true, |
| 414 | 414 | 'items' => array( |
| 415 | 415 | 'type' => 'string', |
| 416 | 416 | ), |
| 417 | 417 | ), |
| 418 | 418 | 'parent_name' => array( |
| 419 | - 'description' => __( 'Parent theme name.', 'woocommerce' ), |
|
| 419 | + 'description' => __('Parent theme name.', 'woocommerce'), |
|
| 420 | 420 | 'type' => 'string', |
| 421 | - 'context' => array( 'view' ), |
|
| 421 | + 'context' => array('view'), |
|
| 422 | 422 | 'readonly' => true, |
| 423 | 423 | ), |
| 424 | 424 | 'parent_version' => array( |
| 425 | - 'description' => __( 'Parent theme version.', 'woocommerce' ), |
|
| 425 | + 'description' => __('Parent theme version.', 'woocommerce'), |
|
| 426 | 426 | 'type' => 'string', |
| 427 | - 'context' => array( 'view' ), |
|
| 427 | + 'context' => array('view'), |
|
| 428 | 428 | 'readonly' => true, |
| 429 | 429 | ), |
| 430 | 430 | 'parent_author_url' => array( |
| 431 | - 'description' => __( 'Parent theme author URL.', 'woocommerce' ), |
|
| 431 | + 'description' => __('Parent theme author URL.', 'woocommerce'), |
|
| 432 | 432 | 'type' => 'string', |
| 433 | 433 | 'format' => 'uri', |
| 434 | - 'context' => array( 'view' ), |
|
| 434 | + 'context' => array('view'), |
|
| 435 | 435 | 'readonly' => true, |
| 436 | 436 | ), |
| 437 | 437 | ), |
| 438 | 438 | ), |
| 439 | 439 | 'settings' => array( |
| 440 | - 'description' => __( 'Settings.', 'woocommerce' ), |
|
| 440 | + 'description' => __('Settings.', 'woocommerce'), |
|
| 441 | 441 | 'type' => 'object', |
| 442 | - 'context' => array( 'view' ), |
|
| 442 | + 'context' => array('view'), |
|
| 443 | 443 | 'readonly' => true, |
| 444 | 444 | 'properties' => array( |
| 445 | 445 | 'api_enabled' => array( |
| 446 | - 'description' => __( 'REST API enabled?', 'woocommerce' ), |
|
| 446 | + 'description' => __('REST API enabled?', 'woocommerce'), |
|
| 447 | 447 | 'type' => 'boolean', |
| 448 | - 'context' => array( 'view' ), |
|
| 448 | + 'context' => array('view'), |
|
| 449 | 449 | 'readonly' => true, |
| 450 | 450 | ), |
| 451 | 451 | 'force_ssl' => array( |
| 452 | - 'description' => __( 'SSL forced?', 'woocommerce' ), |
|
| 452 | + 'description' => __('SSL forced?', 'woocommerce'), |
|
| 453 | 453 | 'type' => 'boolean', |
| 454 | - 'context' => array( 'view' ), |
|
| 454 | + 'context' => array('view'), |
|
| 455 | 455 | 'readonly' => true, |
| 456 | 456 | ), |
| 457 | 457 | 'currency' => array( |
| 458 | - 'description' => __( 'Currency.', 'woocommerce' ), |
|
| 458 | + 'description' => __('Currency.', 'woocommerce'), |
|
| 459 | 459 | 'type' => 'string', |
| 460 | - 'context' => array( 'view' ), |
|
| 460 | + 'context' => array('view'), |
|
| 461 | 461 | 'readonly' => true, |
| 462 | 462 | ), |
| 463 | 463 | 'currency_symbol' => array( |
| 464 | - 'description' => __( 'Currency symbol.', 'woocommerce' ), |
|
| 464 | + 'description' => __('Currency symbol.', 'woocommerce'), |
|
| 465 | 465 | 'type' => 'string', |
| 466 | - 'context' => array( 'view' ), |
|
| 466 | + 'context' => array('view'), |
|
| 467 | 467 | 'readonly' => true, |
| 468 | 468 | ), |
| 469 | 469 | 'currency_position' => array( |
| 470 | - 'description' => __( 'Currency position.', 'woocommerce' ), |
|
| 470 | + 'description' => __('Currency position.', 'woocommerce'), |
|
| 471 | 471 | 'type' => 'string', |
| 472 | - 'context' => array( 'view' ), |
|
| 472 | + 'context' => array('view'), |
|
| 473 | 473 | 'readonly' => true, |
| 474 | 474 | ), |
| 475 | 475 | 'thousand_separator' => array( |
| 476 | - 'description' => __( 'Thousand separator.', 'woocommerce' ), |
|
| 476 | + 'description' => __('Thousand separator.', 'woocommerce'), |
|
| 477 | 477 | 'type' => 'string', |
| 478 | - 'context' => array( 'view' ), |
|
| 478 | + 'context' => array('view'), |
|
| 479 | 479 | 'readonly' => true, |
| 480 | 480 | ), |
| 481 | 481 | 'decimal_separator' => array( |
| 482 | - 'description' => __( 'Decimal separator.', 'woocommerce' ), |
|
| 482 | + 'description' => __('Decimal separator.', 'woocommerce'), |
|
| 483 | 483 | 'type' => 'string', |
| 484 | - 'context' => array( 'view' ), |
|
| 484 | + 'context' => array('view'), |
|
| 485 | 485 | 'readonly' => true, |
| 486 | 486 | ), |
| 487 | 487 | 'number_of_decimals' => array( |
| 488 | - 'description' => __( 'Number of decimals.', 'woocommerce' ), |
|
| 488 | + 'description' => __('Number of decimals.', 'woocommerce'), |
|
| 489 | 489 | 'type' => 'integer', |
| 490 | - 'context' => array( 'view' ), |
|
| 490 | + 'context' => array('view'), |
|
| 491 | 491 | 'readonly' => true, |
| 492 | 492 | ), |
| 493 | 493 | 'geolocation_enabled' => array( |
| 494 | - 'description' => __( 'Geolocation enabled?', 'woocommerce' ), |
|
| 494 | + 'description' => __('Geolocation enabled?', 'woocommerce'), |
|
| 495 | 495 | 'type' => 'boolean', |
| 496 | - 'context' => array( 'view' ), |
|
| 496 | + 'context' => array('view'), |
|
| 497 | 497 | 'readonly' => true, |
| 498 | 498 | ), |
| 499 | 499 | 'taxonomies' => array( |
| 500 | - 'description' => __( 'Taxonomy terms for product/order statuses.', 'woocommerce' ), |
|
| 500 | + 'description' => __('Taxonomy terms for product/order statuses.', 'woocommerce'), |
|
| 501 | 501 | 'type' => 'array', |
| 502 | - 'context' => array( 'view' ), |
|
| 502 | + 'context' => array('view'), |
|
| 503 | 503 | 'readonly' => true, |
| 504 | 504 | 'items' => array( |
| 505 | 505 | 'type' => 'string', |
| 506 | 506 | ), |
| 507 | 507 | ), |
| 508 | 508 | 'product_visibility_terms' => array( |
| 509 | - 'description' => __( 'Terms in the product visibility taxonomy.', 'woocommerce' ), |
|
| 509 | + 'description' => __('Terms in the product visibility taxonomy.', 'woocommerce'), |
|
| 510 | 510 | 'type' => 'array', |
| 511 | - 'context' => array( 'view' ), |
|
| 511 | + 'context' => array('view'), |
|
| 512 | 512 | 'readonly' => true, |
| 513 | 513 | 'items' => array( |
| 514 | 514 | 'type' => 'string', |
@@ -517,38 +517,38 @@ discard block |
||
| 517 | 517 | ), |
| 518 | 518 | ), |
| 519 | 519 | 'security' => array( |
| 520 | - 'description' => __( 'Security.', 'woocommerce' ), |
|
| 520 | + 'description' => __('Security.', 'woocommerce'), |
|
| 521 | 521 | 'type' => 'object', |
| 522 | - 'context' => array( 'view' ), |
|
| 522 | + 'context' => array('view'), |
|
| 523 | 523 | 'readonly' => true, |
| 524 | 524 | 'properties' => array( |
| 525 | 525 | 'secure_connection' => array( |
| 526 | - 'description' => __( 'Is the connection to your store secure?', 'woocommerce' ), |
|
| 526 | + 'description' => __('Is the connection to your store secure?', 'woocommerce'), |
|
| 527 | 527 | 'type' => 'boolean', |
| 528 | - 'context' => array( 'view' ), |
|
| 528 | + 'context' => array('view'), |
|
| 529 | 529 | 'readonly' => true, |
| 530 | 530 | ), |
| 531 | 531 | 'hide_errors' => array( |
| 532 | - 'description' => __( 'Hide errors from visitors?', 'woocommerce' ), |
|
| 532 | + 'description' => __('Hide errors from visitors?', 'woocommerce'), |
|
| 533 | 533 | 'type' => 'boolean', |
| 534 | - 'context' => array( 'view' ), |
|
| 534 | + 'context' => array('view'), |
|
| 535 | 535 | 'readonly' => true, |
| 536 | 536 | ), |
| 537 | 537 | ), |
| 538 | 538 | ), |
| 539 | 539 | 'pages' => array( |
| 540 | - 'description' => __( 'WooCommerce pages.', 'woocommerce' ), |
|
| 540 | + 'description' => __('WooCommerce pages.', 'woocommerce'), |
|
| 541 | 541 | 'type' => 'array', |
| 542 | - 'context' => array( 'view' ), |
|
| 542 | + 'context' => array('view'), |
|
| 543 | 543 | 'readonly' => true, |
| 544 | 544 | 'items' => array( |
| 545 | 545 | 'type' => 'string', |
| 546 | 546 | ), |
| 547 | 547 | ), |
| 548 | 548 | 'post_type_counts' => array( |
| 549 | - 'description' => __( 'Post type counts.', 'woocommerce' ), |
|
| 549 | + 'description' => __('Post type counts.', 'woocommerce'), |
|
| 550 | 550 | 'type' => 'array', |
| 551 | - 'context' => array( 'view' ), |
|
| 551 | + 'context' => array('view'), |
|
| 552 | 552 | 'readonly' => true, |
| 553 | 553 | 'items' => array( |
| 554 | 554 | 'type' => 'string', |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | ), |
| 558 | 558 | ); |
| 559 | 559 | |
| 560 | - return $this->add_additional_fields_schema( $schema ); |
|
| 560 | + return $this->add_additional_fields_schema($schema); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | /** |
@@ -591,23 +591,23 @@ discard block |
||
| 591 | 591 | |
| 592 | 592 | // Figure out cURL version, if installed. |
| 593 | 593 | $curl_version = ''; |
| 594 | - if ( function_exists( 'curl_version' ) ) { |
|
| 594 | + if (function_exists('curl_version')) { |
|
| 595 | 595 | $curl_version = curl_version(); |
| 596 | 596 | $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version']; |
| 597 | - } elseif ( extension_loaded( 'curl' ) ) { |
|
| 598 | - $curl_version = __( 'cURL installed but unable to retrieve version.', 'woocommerce' ); |
|
| 597 | + } elseif (extension_loaded('curl')) { |
|
| 598 | + $curl_version = __('cURL installed but unable to retrieve version.', 'woocommerce'); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | // WP memory limit. |
| 602 | - $wp_memory_limit = wc_let_to_num( WP_MEMORY_LIMIT ); |
|
| 603 | - if ( function_exists( 'memory_get_usage' ) ) { |
|
| 604 | - $wp_memory_limit = max( $wp_memory_limit, wc_let_to_num( @ini_get( 'memory_limit' ) ) ); |
|
| 602 | + $wp_memory_limit = wc_let_to_num(WP_MEMORY_LIMIT); |
|
| 603 | + if (function_exists('memory_get_usage')) { |
|
| 604 | + $wp_memory_limit = max($wp_memory_limit, wc_let_to_num(@ini_get('memory_limit'))); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | // Test POST requests. |
| 608 | - $post_response_code = get_transient( 'woocommerce_test_remote_post' ); |
|
| 608 | + $post_response_code = get_transient('woocommerce_test_remote_post'); |
|
| 609 | 609 | |
| 610 | - if ( false === $post_response_code || is_wp_error( $post_response_code ) ) { |
|
| 610 | + if (false === $post_response_code || is_wp_error($post_response_code)) { |
|
| 611 | 611 | $response = wp_safe_remote_post( |
| 612 | 612 | 'https://www.paypal.com/cgi-bin/webscr', |
| 613 | 613 | array( |
@@ -619,63 +619,63 @@ discard block |
||
| 619 | 619 | ), |
| 620 | 620 | ) |
| 621 | 621 | ); |
| 622 | - if ( ! is_wp_error( $response ) ) { |
|
| 622 | + if ( ! is_wp_error($response)) { |
|
| 623 | 623 | $post_response_code = $response['response']['code']; |
| 624 | 624 | } |
| 625 | - set_transient( 'woocommerce_test_remote_post', $post_response_code, HOUR_IN_SECONDS ); |
|
| 625 | + set_transient('woocommerce_test_remote_post', $post_response_code, HOUR_IN_SECONDS); |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | - $post_response_successful = ! is_wp_error( $post_response_code ) && $post_response_code >= 200 && $post_response_code < 300; |
|
| 628 | + $post_response_successful = ! is_wp_error($post_response_code) && $post_response_code >= 200 && $post_response_code < 300; |
|
| 629 | 629 | |
| 630 | 630 | // Test GET requests. |
| 631 | - $get_response_code = get_transient( 'woocommerce_test_remote_get' ); |
|
| 631 | + $get_response_code = get_transient('woocommerce_test_remote_get'); |
|
| 632 | 632 | |
| 633 | - if ( false === $get_response_code || is_wp_error( $get_response_code ) ) { |
|
| 634 | - $response = wp_safe_remote_get( 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . ( is_multisite() ? '1' : '0' ) ); |
|
| 635 | - if ( ! is_wp_error( $response ) ) { |
|
| 633 | + if (false === $get_response_code || is_wp_error($get_response_code)) { |
|
| 634 | + $response = wp_safe_remote_get('https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . (is_multisite() ? '1' : '0')); |
|
| 635 | + if ( ! is_wp_error($response)) { |
|
| 636 | 636 | $get_response_code = $response['response']['code']; |
| 637 | 637 | } |
| 638 | - set_transient( 'woocommerce_test_remote_get', $get_response_code, HOUR_IN_SECONDS ); |
|
| 638 | + set_transient('woocommerce_test_remote_get', $get_response_code, HOUR_IN_SECONDS); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | - $get_response_successful = ! is_wp_error( $get_response_code ) && $get_response_code >= 200 && $get_response_code < 300; |
|
| 641 | + $get_response_successful = ! is_wp_error($get_response_code) && $get_response_code >= 200 && $get_response_code < 300; |
|
| 642 | 642 | |
| 643 | 643 | $database_version = wc_get_server_database_version(); |
| 644 | 644 | |
| 645 | 645 | // Return all environment info. Described by JSON Schema. |
| 646 | 646 | return array( |
| 647 | - 'home_url' => get_option( 'home' ), |
|
| 648 | - 'site_url' => get_option( 'siteurl' ), |
|
| 647 | + 'home_url' => get_option('home'), |
|
| 648 | + 'site_url' => get_option('siteurl'), |
|
| 649 | 649 | 'version' => WC()->version, |
| 650 | 650 | 'log_directory' => WC_LOG_DIR, |
| 651 | - 'log_directory_writable' => (bool) @fopen( WC_LOG_DIR . 'test-log.log', 'a' ), |
|
| 652 | - 'wp_version' => get_bloginfo( 'version' ), |
|
| 651 | + 'log_directory_writable' => (bool) @fopen(WC_LOG_DIR . 'test-log.log', 'a'), |
|
| 652 | + 'wp_version' => get_bloginfo('version'), |
|
| 653 | 653 | 'wp_multisite' => is_multisite(), |
| 654 | 654 | 'wp_memory_limit' => $wp_memory_limit, |
| 655 | - 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ), |
|
| 656 | - 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ), |
|
| 655 | + 'wp_debug_mode' => (defined('WP_DEBUG') && WP_DEBUG), |
|
| 656 | + 'wp_cron' => ! (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON), |
|
| 657 | 657 | 'language' => get_locale(), |
| 658 | 658 | 'external_object_cache' => wp_using_ext_object_cache(), |
| 659 | - 'server_info' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? wc_clean( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '', |
|
| 659 | + 'server_info' => isset($_SERVER['SERVER_SOFTWARE']) ? wc_clean(wp_unslash($_SERVER['SERVER_SOFTWARE'])) : '', |
|
| 660 | 660 | 'php_version' => phpversion(), |
| 661 | - 'php_post_max_size' => wc_let_to_num( ini_get( 'post_max_size' ) ), |
|
| 662 | - 'php_max_execution_time' => ini_get( 'max_execution_time' ), |
|
| 663 | - 'php_max_input_vars' => ini_get( 'max_input_vars' ), |
|
| 661 | + 'php_post_max_size' => wc_let_to_num(ini_get('post_max_size')), |
|
| 662 | + 'php_max_execution_time' => ini_get('max_execution_time'), |
|
| 663 | + 'php_max_input_vars' => ini_get('max_input_vars'), |
|
| 664 | 664 | 'curl_version' => $curl_version, |
| 665 | - 'suhosin_installed' => extension_loaded( 'suhosin' ), |
|
| 665 | + 'suhosin_installed' => extension_loaded('suhosin'), |
|
| 666 | 666 | 'max_upload_size' => wp_max_upload_size(), |
| 667 | 667 | 'mysql_version' => $database_version['number'], |
| 668 | 668 | 'mysql_version_string' => $database_version['string'], |
| 669 | 669 | 'default_timezone' => date_default_timezone_get(), |
| 670 | - 'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ), |
|
| 671 | - 'soapclient_enabled' => class_exists( 'SoapClient' ), |
|
| 672 | - 'domdocument_enabled' => class_exists( 'DOMDocument' ), |
|
| 673 | - 'gzip_enabled' => is_callable( 'gzopen' ), |
|
| 674 | - 'mbstring_enabled' => extension_loaded( 'mbstring' ), |
|
| 670 | + 'fsockopen_or_curl_enabled' => (function_exists('fsockopen') || function_exists('curl_init')), |
|
| 671 | + 'soapclient_enabled' => class_exists('SoapClient'), |
|
| 672 | + 'domdocument_enabled' => class_exists('DOMDocument'), |
|
| 673 | + 'gzip_enabled' => is_callable('gzopen'), |
|
| 674 | + 'mbstring_enabled' => extension_loaded('mbstring'), |
|
| 675 | 675 | 'remote_post_successful' => $post_response_successful, |
| 676 | - 'remote_post_response' => is_wp_error( $post_response_code ) ? $post_response_code->get_error_message() : $post_response_code, |
|
| 676 | + 'remote_post_response' => is_wp_error($post_response_code) ? $post_response_code->get_error_message() : $post_response_code, |
|
| 677 | 677 | 'remote_get_successful' => $get_response_successful, |
| 678 | - 'remote_get_response' => is_wp_error( $get_response_code ) ? $get_response_code->get_error_message() : $get_response_code, |
|
| 678 | + 'remote_get_response' => is_wp_error($get_response_code) ? $get_response_code->get_error_message() : $get_response_code, |
|
| 679 | 679 | ); |
| 680 | 680 | } |
| 681 | 681 | |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | * @param string $table Table name. |
| 686 | 686 | * @return stromg |
| 687 | 687 | */ |
| 688 | - protected function add_db_table_prefix( $table ) { |
|
| 688 | + protected function add_db_table_prefix($table) { |
|
| 689 | 689 | global $wpdb; |
| 690 | 690 | return $wpdb->prefix . $table; |
| 691 | 691 | } |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | * |
| 739 | 739 | * If we changed the tables above to include the prefix, then any filters against that table could break. |
| 740 | 740 | */ |
| 741 | - $core_tables = array_map( array( $this, 'add_db_table_prefix' ), $core_tables ); |
|
| 741 | + $core_tables = array_map(array($this, 'add_db_table_prefix'), $core_tables); |
|
| 742 | 742 | |
| 743 | 743 | /** |
| 744 | 744 | * Organize WooCommerce and non-WooCommerce tables separately for display purposes later. |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | * To ensure we include all WC tables, even if they do not exist, pre-populate the WC array with all the tables. |
| 747 | 747 | */ |
| 748 | 748 | $tables = array( |
| 749 | - 'woocommerce' => array_fill_keys( $core_tables, false ), |
|
| 749 | + 'woocommerce' => array_fill_keys($core_tables, false), |
|
| 750 | 750 | 'other' => array(), |
| 751 | 751 | ); |
| 752 | 752 | |
@@ -755,16 +755,16 @@ discard block |
||
| 755 | 755 | 'index' => 0, |
| 756 | 756 | ); |
| 757 | 757 | |
| 758 | - $site_tables_prefix = $wpdb->get_blog_prefix( get_current_blog_id() ); |
|
| 759 | - $global_tables = $wpdb->tables( 'global', true ); |
|
| 760 | - foreach ( $database_table_information as $table ) { |
|
| 758 | + $site_tables_prefix = $wpdb->get_blog_prefix(get_current_blog_id()); |
|
| 759 | + $global_tables = $wpdb->tables('global', true); |
|
| 760 | + foreach ($database_table_information as $table) { |
|
| 761 | 761 | // Only include tables matching the prefix of the current site, this is to prevent displaying all tables on a MS install not relating to the current. |
| 762 | - if ( is_multisite() && 0 !== strpos( $table->name, $site_tables_prefix ) && ! in_array( $table->name, $global_tables, true ) ) { |
|
| 762 | + if (is_multisite() && 0 !== strpos($table->name, $site_tables_prefix) && ! in_array($table->name, $global_tables, true)) { |
|
| 763 | 763 | continue; |
| 764 | 764 | } |
| 765 | - $table_type = in_array( $table->name, $core_tables, true ) ? 'woocommerce' : 'other'; |
|
| 765 | + $table_type = in_array($table->name, $core_tables, true) ? 'woocommerce' : 'other'; |
|
| 766 | 766 | |
| 767 | - $tables[ $table_type ][ $table->name ] = array( |
|
| 767 | + $tables[$table_type][$table->name] = array( |
|
| 768 | 768 | 'data' => $table->data, |
| 769 | 769 | 'index' => $table->index, |
| 770 | 770 | 'engine' => $table->engine, |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | |
| 777 | 777 | // Return all database info. Described by JSON Schema. |
| 778 | 778 | return array( |
| 779 | - 'wc_database_version' => get_option( 'woocommerce_db_version' ), |
|
| 779 | + 'wc_database_version' => get_option('woocommerce_db_version'), |
|
| 780 | 780 | 'database_prefix' => $wpdb->prefix, |
| 781 | 781 | 'maxmind_geoip_database' => \WC_Geolocation::get_local_database_path(), |
| 782 | 782 | 'database_tables' => $tables, |
@@ -792,9 +792,9 @@ discard block |
||
| 792 | 792 | public function get_post_type_counts() { |
| 793 | 793 | global $wpdb; |
| 794 | 794 | |
| 795 | - $post_type_counts = $wpdb->get_results( "SELECT post_type AS 'type', count(1) AS 'count' FROM {$wpdb->posts} GROUP BY post_type;" ); |
|
| 795 | + $post_type_counts = $wpdb->get_results("SELECT post_type AS 'type', count(1) AS 'count' FROM {$wpdb->posts} GROUP BY post_type;"); |
|
| 796 | 796 | |
| 797 | - return is_array( $post_type_counts ) ? $post_type_counts : array(); |
|
| 797 | + return is_array($post_type_counts) ? $post_type_counts : array(); |
|
| 798 | 798 | } |
| 799 | 799 | |
| 800 | 800 | /** |
@@ -805,21 +805,21 @@ discard block |
||
| 805 | 805 | public function get_active_plugins() { |
| 806 | 806 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 807 | 807 | |
| 808 | - if ( ! function_exists( 'get_plugin_data' ) ) { |
|
| 808 | + if ( ! function_exists('get_plugin_data')) { |
|
| 809 | 809 | return array(); |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 813 | - if ( is_multisite() ) { |
|
| 814 | - $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 815 | - $active_plugins = array_merge( $active_plugins, $network_activated_plugins ); |
|
| 812 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
| 813 | + if (is_multisite()) { |
|
| 814 | + $network_activated_plugins = array_keys(get_site_option('active_sitewide_plugins', array())); |
|
| 815 | + $active_plugins = array_merge($active_plugins, $network_activated_plugins); |
|
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | $active_plugins_data = array(); |
| 819 | 819 | |
| 820 | - foreach ( $active_plugins as $plugin ) { |
|
| 821 | - $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
|
| 822 | - $active_plugins_data[] = $this->format_plugin_data( $plugin, $data ); |
|
| 820 | + foreach ($active_plugins as $plugin) { |
|
| 821 | + $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
| 822 | + $active_plugins_data[] = $this->format_plugin_data($plugin, $data); |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | return $active_plugins_data; |
@@ -833,25 +833,25 @@ discard block |
||
| 833 | 833 | public function get_inactive_plugins() { |
| 834 | 834 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 835 | 835 | |
| 836 | - if ( ! function_exists( 'get_plugins' ) ) { |
|
| 836 | + if ( ! function_exists('get_plugins')) { |
|
| 837 | 837 | return array(); |
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | $plugins = get_plugins(); |
| 841 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 841 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
| 842 | 842 | |
| 843 | - if ( is_multisite() ) { |
|
| 844 | - $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 845 | - $active_plugins = array_merge( $active_plugins, $network_activated_plugins ); |
|
| 843 | + if (is_multisite()) { |
|
| 844 | + $network_activated_plugins = array_keys(get_site_option('active_sitewide_plugins', array())); |
|
| 845 | + $active_plugins = array_merge($active_plugins, $network_activated_plugins); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | $plugins_data = array(); |
| 849 | 849 | |
| 850 | - foreach ( $plugins as $plugin => $data ) { |
|
| 851 | - if ( in_array( $plugin, $active_plugins, true ) ) { |
|
| 850 | + foreach ($plugins as $plugin => $data) { |
|
| 851 | + if (in_array($plugin, $active_plugins, true)) { |
|
| 852 | 852 | continue; |
| 853 | 853 | } |
| 854 | - $plugins_data[] = $this->format_plugin_data( $plugin, $data ); |
|
| 854 | + $plugins_data[] = $this->format_plugin_data($plugin, $data); |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | return $plugins_data; |
@@ -865,23 +865,23 @@ discard block |
||
| 865 | 865 | * @param array $data Plugin data from WP. |
| 866 | 866 | * @return array Formatted data. |
| 867 | 867 | */ |
| 868 | - protected function format_plugin_data( $plugin, $data ) { |
|
| 868 | + protected function format_plugin_data($plugin, $data) { |
|
| 869 | 869 | require_once ABSPATH . 'wp-admin/includes/update.php'; |
| 870 | 870 | |
| 871 | - if ( ! function_exists( 'get_plugin_updates' ) ) { |
|
| 871 | + if ( ! function_exists('get_plugin_updates')) { |
|
| 872 | 872 | return array(); |
| 873 | 873 | } |
| 874 | 874 | |
| 875 | 875 | // Use WP API to lookup latest updates for plugins. WC_Helper injects updates for premium plugins. |
| 876 | - if ( empty( $this->available_updates ) ) { |
|
| 876 | + if (empty($this->available_updates)) { |
|
| 877 | 877 | $this->available_updates = get_plugin_updates(); |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | $version_latest = $data['Version']; |
| 881 | 881 | |
| 882 | 882 | // Find latest version. |
| 883 | - if ( isset( $this->available_updates[ $plugin ]->update->new_version ) ) { |
|
| 884 | - $version_latest = $this->available_updates[ $plugin ]->update->new_version; |
|
| 883 | + if (isset($this->available_updates[$plugin]->update->new_version)) { |
|
| 884 | + $version_latest = $this->available_updates[$plugin]->update->new_version; |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | return array( |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | 'version_latest' => $version_latest, |
| 892 | 892 | 'url' => $data['PluginURI'], |
| 893 | 893 | 'author_name' => $data['AuthorName'], |
| 894 | - 'author_url' => esc_url_raw( $data['AuthorURI'] ), |
|
| 894 | + 'author_url' => esc_url_raw($data['AuthorURI']), |
|
| 895 | 895 | 'network_activated' => $data['Network'], |
| 896 | 896 | ); |
| 897 | 897 | } |
@@ -908,7 +908,7 @@ discard block |
||
| 908 | 908 | 'dropins' => array(), |
| 909 | 909 | 'mu_plugins' => array(), |
| 910 | 910 | ); |
| 911 | - foreach ( $dropins as $key => $dropin ) { |
|
| 911 | + foreach ($dropins as $key => $dropin) { |
|
| 912 | 912 | $plugins['dropins'][] = array( |
| 913 | 913 | 'plugin' => $key, |
| 914 | 914 | 'name' => $dropin['Name'], |
@@ -916,14 +916,14 @@ discard block |
||
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | $mu_plugins = get_mu_plugins(); |
| 919 | - foreach ( $mu_plugins as $plugin => $mu_plugin ) { |
|
| 919 | + foreach ($mu_plugins as $plugin => $mu_plugin) { |
|
| 920 | 920 | $plugins['mu_plugins'][] = array( |
| 921 | 921 | 'plugin' => $plugin, |
| 922 | 922 | 'name' => $mu_plugin['Name'], |
| 923 | 923 | 'version' => $mu_plugin['Version'], |
| 924 | 924 | 'url' => $mu_plugin['PluginURI'], |
| 925 | 925 | 'author_name' => $mu_plugin['AuthorName'], |
| 926 | - 'author_url' => esc_url_raw( $mu_plugin['AuthorURI'] ), |
|
| 926 | + 'author_url' => esc_url_raw($mu_plugin['AuthorURI']), |
|
| 927 | 927 | ); |
| 928 | 928 | } |
| 929 | 929 | return $plugins; |
@@ -940,12 +940,12 @@ discard block |
||
| 940 | 940 | |
| 941 | 941 | // Get parent theme info if this theme is a child theme, otherwise |
| 942 | 942 | // pass empty info in the response. |
| 943 | - if ( is_child_theme() ) { |
|
| 944 | - $parent_theme = wp_get_theme( $active_theme->template ); |
|
| 943 | + if (is_child_theme()) { |
|
| 944 | + $parent_theme = wp_get_theme($active_theme->template); |
|
| 945 | 945 | $parent_theme_info = array( |
| 946 | 946 | 'parent_name' => $parent_theme->name, |
| 947 | 947 | 'parent_version' => $parent_theme->version, |
| 948 | - 'parent_version_latest' => \WC_Admin_Status::get_latest_theme_version( $parent_theme ), |
|
| 948 | + 'parent_version_latest' => \WC_Admin_Status::get_latest_theme_version($parent_theme), |
|
| 949 | 949 | 'parent_author_url' => $parent_theme->{'Author URI'}, |
| 950 | 950 | ); |
| 951 | 951 | } else { |
@@ -963,34 +963,34 @@ discard block |
||
| 963 | 963 | */ |
| 964 | 964 | $override_files = array(); |
| 965 | 965 | $outdated_templates = false; |
| 966 | - $scan_files = \WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates/' ); |
|
| 967 | - foreach ( $scan_files as $file ) { |
|
| 968 | - $located = apply_filters( 'wc_get_template', $file, $file, array(), WC()->template_path(), WC()->plugin_path() . '/templates/' ); |
|
| 966 | + $scan_files = \WC_Admin_Status::scan_template_files(WC()->plugin_path() . '/templates/'); |
|
| 967 | + foreach ($scan_files as $file) { |
|
| 968 | + $located = apply_filters('wc_get_template', $file, $file, array(), WC()->template_path(), WC()->plugin_path() . '/templates/'); |
|
| 969 | 969 | |
| 970 | - if ( file_exists( $located ) ) { |
|
| 970 | + if (file_exists($located)) { |
|
| 971 | 971 | $theme_file = $located; |
| 972 | - } elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { |
|
| 972 | + } elseif (file_exists(get_stylesheet_directory() . '/' . $file)) { |
|
| 973 | 973 | $theme_file = get_stylesheet_directory() . '/' . $file; |
| 974 | - } elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) { |
|
| 974 | + } elseif (file_exists(get_stylesheet_directory() . '/' . WC()->template_path() . $file)) { |
|
| 975 | 975 | $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file; |
| 976 | - } elseif ( file_exists( get_template_directory() . '/' . $file ) ) { |
|
| 976 | + } elseif (file_exists(get_template_directory() . '/' . $file)) { |
|
| 977 | 977 | $theme_file = get_template_directory() . '/' . $file; |
| 978 | - } elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) { |
|
| 978 | + } elseif (file_exists(get_template_directory() . '/' . WC()->template_path() . $file)) { |
|
| 979 | 979 | $theme_file = get_template_directory() . '/' . WC()->template_path() . $file; |
| 980 | 980 | } else { |
| 981 | 981 | $theme_file = false; |
| 982 | 982 | } |
| 983 | 983 | |
| 984 | - if ( ! empty( $theme_file ) ) { |
|
| 985 | - $core_version = \WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file ); |
|
| 986 | - $theme_version = \WC_Admin_Status::get_file_version( $theme_file ); |
|
| 987 | - if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) { |
|
| 988 | - if ( ! $outdated_templates ) { |
|
| 984 | + if ( ! empty($theme_file)) { |
|
| 985 | + $core_version = \WC_Admin_Status::get_file_version(WC()->plugin_path() . '/templates/' . $file); |
|
| 986 | + $theme_version = \WC_Admin_Status::get_file_version($theme_file); |
|
| 987 | + if ($core_version && (empty($theme_version) || version_compare($theme_version, $core_version, '<'))) { |
|
| 988 | + if ( ! $outdated_templates) { |
|
| 989 | 989 | $outdated_templates = true; |
| 990 | 990 | } |
| 991 | 991 | } |
| 992 | 992 | $override_files[] = array( |
| 993 | - 'file' => str_replace( WP_CONTENT_DIR . '/themes/', '', $theme_file ), |
|
| 993 | + 'file' => str_replace(WP_CONTENT_DIR . '/themes/', '', $theme_file), |
|
| 994 | 994 | 'version' => $theme_version, |
| 995 | 995 | 'core_version' => $core_version, |
| 996 | 996 | ); |
@@ -1000,16 +1000,16 @@ discard block |
||
| 1000 | 1000 | $active_theme_info = array( |
| 1001 | 1001 | 'name' => $active_theme->name, |
| 1002 | 1002 | 'version' => $active_theme->version, |
| 1003 | - 'version_latest' => \WC_Admin_Status::get_latest_theme_version( $active_theme ), |
|
| 1004 | - 'author_url' => esc_url_raw( $active_theme->{'Author URI'} ), |
|
| 1003 | + 'version_latest' => \WC_Admin_Status::get_latest_theme_version($active_theme), |
|
| 1004 | + 'author_url' => esc_url_raw($active_theme->{'Author URI'} ), |
|
| 1005 | 1005 | 'is_child_theme' => is_child_theme(), |
| 1006 | - 'has_woocommerce_support' => current_theme_supports( 'woocommerce' ), |
|
| 1007 | - 'has_woocommerce_file' => ( file_exists( get_stylesheet_directory() . '/woocommerce.php' ) || file_exists( get_template_directory() . '/woocommerce.php' ) ), |
|
| 1006 | + 'has_woocommerce_support' => current_theme_supports('woocommerce'), |
|
| 1007 | + 'has_woocommerce_file' => (file_exists(get_stylesheet_directory() . '/woocommerce.php') || file_exists(get_template_directory() . '/woocommerce.php')), |
|
| 1008 | 1008 | 'has_outdated_templates' => $outdated_templates, |
| 1009 | 1009 | 'overrides' => $override_files, |
| 1010 | 1010 | ); |
| 1011 | 1011 | |
| 1012 | - return array_merge( $active_theme_info, $parent_theme_info ); |
|
| 1012 | + return array_merge($active_theme_info, $parent_theme_info); |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | /** |
@@ -1021,36 +1021,36 @@ discard block |
||
| 1021 | 1021 | public function get_settings() { |
| 1022 | 1022 | // Get a list of terms used for product/order taxonomies. |
| 1023 | 1023 | $term_response = array(); |
| 1024 | - $terms = get_terms( 'product_type', array( 'hide_empty' => 0 ) ); |
|
| 1025 | - foreach ( $terms as $term ) { |
|
| 1026 | - $term_response[ $term->slug ] = strtolower( $term->name ); |
|
| 1024 | + $terms = get_terms('product_type', array('hide_empty' => 0)); |
|
| 1025 | + foreach ($terms as $term) { |
|
| 1026 | + $term_response[$term->slug] = strtolower($term->name); |
|
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | 1029 | // Get a list of terms used for product visibility. |
| 1030 | 1030 | $product_visibility_terms = array(); |
| 1031 | - $terms = get_terms( 'product_visibility', array( 'hide_empty' => 0 ) ); |
|
| 1032 | - foreach ( $terms as $term ) { |
|
| 1033 | - $product_visibility_terms[ $term->slug ] = strtolower( $term->name ); |
|
| 1031 | + $terms = get_terms('product_visibility', array('hide_empty' => 0)); |
|
| 1032 | + foreach ($terms as $term) { |
|
| 1033 | + $product_visibility_terms[$term->slug] = strtolower($term->name); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | // Check if WooCommerce.com account is connected. |
| 1037 | 1037 | $woo_com_connected = 'no'; |
| 1038 | - $helper_options = get_option( 'woocommerce_helper_data', array() ); |
|
| 1039 | - if ( array_key_exists( 'auth', $helper_options ) && ! empty( $helper_options['auth'] ) ) { |
|
| 1038 | + $helper_options = get_option('woocommerce_helper_data', array()); |
|
| 1039 | + if (array_key_exists('auth', $helper_options) && ! empty($helper_options['auth'])) { |
|
| 1040 | 1040 | $woo_com_connected = 'yes'; |
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | 1043 | // Return array of useful settings for debugging. |
| 1044 | 1044 | return array( |
| 1045 | - 'api_enabled' => 'yes' === get_option( 'woocommerce_api_enabled' ), |
|
| 1046 | - 'force_ssl' => 'yes' === get_option( 'woocommerce_force_ssl_checkout' ), |
|
| 1045 | + 'api_enabled' => 'yes' === get_option('woocommerce_api_enabled'), |
|
| 1046 | + 'force_ssl' => 'yes' === get_option('woocommerce_force_ssl_checkout'), |
|
| 1047 | 1047 | 'currency' => get_woocommerce_currency(), |
| 1048 | 1048 | 'currency_symbol' => get_woocommerce_currency_symbol(), |
| 1049 | - 'currency_position' => get_option( 'woocommerce_currency_pos' ), |
|
| 1049 | + 'currency_position' => get_option('woocommerce_currency_pos'), |
|
| 1050 | 1050 | 'thousand_separator' => wc_get_price_thousand_separator(), |
| 1051 | 1051 | 'decimal_separator' => wc_get_price_decimal_separator(), |
| 1052 | 1052 | 'number_of_decimals' => wc_get_price_decimals(), |
| 1053 | - 'geolocation_enabled' => in_array( get_option( 'woocommerce_default_customer_address' ), array( 'geolocation_ajax', 'geolocation' ) ), |
|
| 1053 | + 'geolocation_enabled' => in_array(get_option('woocommerce_default_customer_address'), array('geolocation_ajax', 'geolocation')), |
|
| 1054 | 1054 | 'taxonomies' => $term_response, |
| 1055 | 1055 | 'product_visibility_terms' => $product_visibility_terms, |
| 1056 | 1056 | 'woocommerce_com_connected' => $woo_com_connected, |
@@ -1063,10 +1063,10 @@ discard block |
||
| 1063 | 1063 | * @return array |
| 1064 | 1064 | */ |
| 1065 | 1065 | public function get_security_info() { |
| 1066 | - $check_page = wc_get_page_permalink( 'shop' ); |
|
| 1066 | + $check_page = wc_get_page_permalink('shop'); |
|
| 1067 | 1067 | return array( |
| 1068 | - 'secure_connection' => 'https' === substr( $check_page, 0, 5 ), |
|
| 1069 | - 'hide_errors' => ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ), |
|
| 1068 | + 'secure_connection' => 'https' === substr($check_page, 0, 5), |
|
| 1069 | + 'hide_errors' => ! (defined('WP_DEBUG') && defined('WP_DEBUG_DISPLAY') && WP_DEBUG && WP_DEBUG_DISPLAY) || 0 === intval(ini_get('display_errors')), |
|
| 1070 | 1070 | ); |
| 1071 | 1071 | } |
| 1072 | 1072 | |
@@ -1079,31 +1079,31 @@ discard block |
||
| 1079 | 1079 | public function get_pages() { |
| 1080 | 1080 | // WC pages to check against. |
| 1081 | 1081 | $check_pages = array( |
| 1082 | - _x( 'Shop base', 'Page setting', 'woocommerce' ) => array( |
|
| 1082 | + _x('Shop base', 'Page setting', 'woocommerce') => array( |
|
| 1083 | 1083 | 'option' => 'woocommerce_shop_page_id', |
| 1084 | 1084 | 'shortcode' => '', |
| 1085 | 1085 | ), |
| 1086 | - _x( 'Cart', 'Page setting', 'woocommerce' ) => array( |
|
| 1086 | + _x('Cart', 'Page setting', 'woocommerce') => array( |
|
| 1087 | 1087 | 'option' => 'woocommerce_cart_page_id', |
| 1088 | - 'shortcode' => '[' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']', |
|
| 1088 | + 'shortcode' => '[' . apply_filters('woocommerce_cart_shortcode_tag', 'woocommerce_cart') . ']', |
|
| 1089 | 1089 | ), |
| 1090 | - _x( 'Checkout', 'Page setting', 'woocommerce' ) => array( |
|
| 1090 | + _x('Checkout', 'Page setting', 'woocommerce') => array( |
|
| 1091 | 1091 | 'option' => 'woocommerce_checkout_page_id', |
| 1092 | - 'shortcode' => '[' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']', |
|
| 1092 | + 'shortcode' => '[' . apply_filters('woocommerce_checkout_shortcode_tag', 'woocommerce_checkout') . ']', |
|
| 1093 | 1093 | ), |
| 1094 | - _x( 'My account', 'Page setting', 'woocommerce' ) => array( |
|
| 1094 | + _x('My account', 'Page setting', 'woocommerce') => array( |
|
| 1095 | 1095 | 'option' => 'woocommerce_myaccount_page_id', |
| 1096 | - 'shortcode' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']', |
|
| 1096 | + 'shortcode' => '[' . apply_filters('woocommerce_my_account_shortcode_tag', 'woocommerce_my_account') . ']', |
|
| 1097 | 1097 | ), |
| 1098 | - _x( 'Terms and conditions', 'Page setting', 'woocommerce' ) => array( |
|
| 1098 | + _x('Terms and conditions', 'Page setting', 'woocommerce') => array( |
|
| 1099 | 1099 | 'option' => 'woocommerce_terms_page_id', |
| 1100 | 1100 | 'shortcode' => '', |
| 1101 | 1101 | ), |
| 1102 | 1102 | ); |
| 1103 | 1103 | |
| 1104 | 1104 | $pages_output = array(); |
| 1105 | - foreach ( $check_pages as $page_name => $values ) { |
|
| 1106 | - $page_id = get_option( $values['option'] ); |
|
| 1105 | + foreach ($check_pages as $page_name => $values) { |
|
| 1106 | + $page_id = get_option($values['option']); |
|
| 1107 | 1107 | $page_set = false; |
| 1108 | 1108 | $page_exists = false; |
| 1109 | 1109 | $page_visible = false; |
@@ -1111,21 +1111,21 @@ discard block |
||
| 1111 | 1111 | $shortcode_required = false; |
| 1112 | 1112 | |
| 1113 | 1113 | // Page checks. |
| 1114 | - if ( $page_id ) { |
|
| 1114 | + if ($page_id) { |
|
| 1115 | 1115 | $page_set = true; |
| 1116 | 1116 | } |
| 1117 | - if ( get_post( $page_id ) ) { |
|
| 1117 | + if (get_post($page_id)) { |
|
| 1118 | 1118 | $page_exists = true; |
| 1119 | 1119 | } |
| 1120 | - if ( 'publish' === get_post_status( $page_id ) ) { |
|
| 1120 | + if ('publish' === get_post_status($page_id)) { |
|
| 1121 | 1121 | $page_visible = true; |
| 1122 | 1122 | } |
| 1123 | 1123 | |
| 1124 | 1124 | // Shortcode checks. |
| 1125 | - if ( $values['shortcode'] && get_post( $page_id ) ) { |
|
| 1125 | + if ($values['shortcode'] && get_post($page_id)) { |
|
| 1126 | 1126 | $shortcode_required = true; |
| 1127 | - $page = get_post( $page_id ); |
|
| 1128 | - if ( strstr( $page->post_content, $values['shortcode'] ) ) { |
|
| 1127 | + $page = get_post($page_id); |
|
| 1128 | + if (strstr($page->post_content, $values['shortcode'])) { |
|
| 1129 | 1129 | $shortcode_present = true; |
| 1130 | 1130 | } |
| 1131 | 1131 | } |
@@ -1153,7 +1153,7 @@ discard block |
||
| 1153 | 1153 | */ |
| 1154 | 1154 | public function get_collection_params() { |
| 1155 | 1155 | return array( |
| 1156 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 1156 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 1157 | 1157 | ); |
| 1158 | 1158 | } |
| 1159 | 1159 | |
@@ -1164,11 +1164,11 @@ discard block |
||
| 1164 | 1164 | * @param \WP_REST_Request $request Request object. |
| 1165 | 1165 | * @return \WP_REST_Response |
| 1166 | 1166 | */ |
| 1167 | - public function prepare_item_for_response( $system_status, $request ) { |
|
| 1168 | - $data = $this->add_additional_fields_to_object( $system_status, $request ); |
|
| 1169 | - $data = $this->filter_response_by_context( $data, 'view' ); |
|
| 1167 | + public function prepare_item_for_response($system_status, $request) { |
|
| 1168 | + $data = $this->add_additional_fields_to_object($system_status, $request); |
|
| 1169 | + $data = $this->filter_response_by_context($data, 'view'); |
|
| 1170 | 1170 | |
| 1171 | - $response = rest_ensure_response( $data ); |
|
| 1171 | + $response = rest_ensure_response($data); |
|
| 1172 | 1172 | |
| 1173 | 1173 | /** |
| 1174 | 1174 | * Filter the system status returned from the REST API. |
@@ -1177,6 +1177,6 @@ discard block |
||
| 1177 | 1177 | * @param mixed $system_status System status |
| 1178 | 1178 | * @param \WP_REST_Request $request Request object. |
| 1179 | 1179 | */ |
| 1180 | - return apply_filters( 'woocommerce_rest_prepare_system_status', $response, $system_status, $request ); |
|
| 1180 | + return apply_filters('woocommerce_rest_prepare_system_status', $response, $system_status, $request); |
|
| 1181 | 1181 | } |
| 1182 | 1182 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | namespace WooCommerce\RestApi\Controllers\Version4; |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * POSTS Controller. |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * @param \WP_REST_Request $request Full details about the request. |
| 44 | 44 | * @return \WP_Error|boolean |
| 45 | 45 | */ |
| 46 | - public function get_items_permissions_check( $request ) { |
|
| 47 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'read' ) ) { |
|
| 48 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 46 | + public function get_items_permissions_check($request) { |
|
| 47 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'read')) { |
|
| 48 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | return true; |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | * @param \WP_REST_Request $request Full details about the request. |
| 58 | 58 | * @return \WP_Error|boolean |
| 59 | 59 | */ |
| 60 | - public function create_item_permissions_check( $request ) { |
|
| 61 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'create' ) ) { |
|
| 62 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 60 | + public function create_item_permissions_check($request) { |
|
| 61 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'create')) { |
|
| 62 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | return true; |
@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | * @param \WP_REST_Request $request Full details about the request. |
| 72 | 72 | * @return \WP_Error|boolean |
| 73 | 73 | */ |
| 74 | - public function get_item_permissions_check( $request ) { |
|
| 75 | - $post = get_post( (int) $request['id'] ); |
|
| 74 | + public function get_item_permissions_check($request) { |
|
| 75 | + $post = get_post((int) $request['id']); |
|
| 76 | 76 | |
| 77 | - if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) { |
|
| 78 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 77 | + if ($post && ! wc_rest_check_post_permissions($this->post_type, 'read', $post->ID)) { |
|
| 78 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | return true; |
@@ -87,11 +87,11 @@ discard block |
||
| 87 | 87 | * @param \WP_REST_Request $request Full details about the request. |
| 88 | 88 | * @return \WP_Error|boolean |
| 89 | 89 | */ |
| 90 | - public function update_item_permissions_check( $request ) { |
|
| 91 | - $post = get_post( (int) $request['id'] ); |
|
| 90 | + public function update_item_permissions_check($request) { |
|
| 91 | + $post = get_post((int) $request['id']); |
|
| 92 | 92 | |
| 93 | - if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $post->ID ) ) { |
|
| 94 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 93 | + if ($post && ! wc_rest_check_post_permissions($this->post_type, 'edit', $post->ID)) { |
|
| 94 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | return true; |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | * @param \WP_REST_Request $request Full details about the request. |
| 104 | 104 | * @return bool|\WP_Error |
| 105 | 105 | */ |
| 106 | - public function delete_item_permissions_check( $request ) { |
|
| 107 | - $post = get_post( (int) $request['id'] ); |
|
| 106 | + public function delete_item_permissions_check($request) { |
|
| 107 | + $post = get_post((int) $request['id']); |
|
| 108 | 108 | |
| 109 | - if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $post->ID ) ) { |
|
| 110 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 109 | + if ($post && ! wc_rest_check_post_permissions($this->post_type, 'delete', $post->ID)) { |
|
| 110 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | return true; |
@@ -120,9 +120,9 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @return boolean|\WP_Error |
| 122 | 122 | */ |
| 123 | - public function batch_items_permissions_check( $request ) { |
|
| 124 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'batch' ) ) { |
|
| 125 | - return new \WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 123 | + public function batch_items_permissions_check($request) { |
|
| 124 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'batch')) { |
|
| 125 | + return new \WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | return true; |
@@ -134,21 +134,21 @@ discard block |
||
| 134 | 134 | * @param \WP_REST_Request $request Full details about the request. |
| 135 | 135 | * @return \WP_Error\WP_REST_Response |
| 136 | 136 | */ |
| 137 | - public function get_item( $request ) { |
|
| 137 | + public function get_item($request) { |
|
| 138 | 138 | $id = (int) $request['id']; |
| 139 | - $post = get_post( $id ); |
|
| 139 | + $post = get_post($id); |
|
| 140 | 140 | |
| 141 | - if ( ! empty( $post->post_type ) && 'product_variation' === $post->post_type && 'product' === $this->post_type ) { |
|
| 142 | - return new \WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 143 | - } elseif ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) { |
|
| 144 | - return new \WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 141 | + if ( ! empty($post->post_type) && 'product_variation' === $post->post_type && 'product' === $this->post_type) { |
|
| 142 | + return new \WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce'), array('status' => 404)); |
|
| 143 | + } elseif (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) { |
|
| 144 | + return new \WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('Invalid ID.', 'woocommerce'), array('status' => 404)); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - $data = $this->prepare_item_for_response( $post, $request ); |
|
| 148 | - $response = rest_ensure_response( $data ); |
|
| 147 | + $data = $this->prepare_item_for_response($post, $request); |
|
| 148 | + $response = rest_ensure_response($data); |
|
| 149 | 149 | |
| 150 | - if ( $this->public ) { |
|
| 151 | - $response->link_header( 'alternate', get_permalink( $id ), array( 'type' => 'text/html' ) ); |
|
| 150 | + if ($this->public) { |
|
| 151 | + $response->link_header('alternate', get_permalink($id), array('type' => 'text/html')); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | return $response; |
@@ -160,39 +160,39 @@ discard block |
||
| 160 | 160 | * @param \WP_REST_Request $request Full details about the request. |
| 161 | 161 | * @return \WP_Error\WP_REST_Response |
| 162 | 162 | */ |
| 163 | - public function create_item( $request ) { |
|
| 164 | - if ( ! empty( $request['id'] ) ) { |
|
| 163 | + public function create_item($request) { |
|
| 164 | + if ( ! empty($request['id'])) { |
|
| 165 | 165 | /* translators: %s: post type */ |
| 166 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
| 166 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $post = $this->prepare_item_for_database( $request ); |
|
| 170 | - if ( is_wp_error( $post ) ) { |
|
| 169 | + $post = $this->prepare_item_for_database($request); |
|
| 170 | + if (is_wp_error($post)) { |
|
| 171 | 171 | return $post; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | $post->post_type = $this->post_type; |
| 175 | - $post_id = wp_insert_post( $post, true ); |
|
| 175 | + $post_id = wp_insert_post($post, true); |
|
| 176 | 176 | |
| 177 | - if ( is_wp_error( $post_id ) ) { |
|
| 177 | + if (is_wp_error($post_id)) { |
|
| 178 | 178 | |
| 179 | - if ( in_array( $post_id->get_error_code(), array( 'db_insert_error' ) ) ) { |
|
| 180 | - $post_id->add_data( array( 'status' => 500 ) ); |
|
| 179 | + if (in_array($post_id->get_error_code(), array('db_insert_error'))) { |
|
| 180 | + $post_id->add_data(array('status' => 500)); |
|
| 181 | 181 | } else { |
| 182 | - $post_id->add_data( array( 'status' => 400 ) ); |
|
| 182 | + $post_id->add_data(array('status' => 400)); |
|
| 183 | 183 | } |
| 184 | 184 | return $post_id; |
| 185 | 185 | } |
| 186 | 186 | $post->ID = $post_id; |
| 187 | - $post = get_post( $post_id ); |
|
| 187 | + $post = get_post($post_id); |
|
| 188 | 188 | |
| 189 | - $this->update_additional_fields_for_object( $post, $request ); |
|
| 189 | + $this->update_additional_fields_for_object($post, $request); |
|
| 190 | 190 | |
| 191 | 191 | // Add meta fields. |
| 192 | - $meta_fields = $this->add_post_meta_fields( $post, $request ); |
|
| 193 | - if ( is_wp_error( $meta_fields ) ) { |
|
| 192 | + $meta_fields = $this->add_post_meta_fields($post, $request); |
|
| 193 | + if (is_wp_error($meta_fields)) { |
|
| 194 | 194 | // Remove post. |
| 195 | - $this->delete_post( $post ); |
|
| 195 | + $this->delete_post($post); |
|
| 196 | 196 | |
| 197 | 197 | return $meta_fields; |
| 198 | 198 | } |
@@ -204,13 +204,13 @@ discard block |
||
| 204 | 204 | * @param \WP_REST_Request $request Request object. |
| 205 | 205 | * @param boolean $creating True when creating item, false when updating. |
| 206 | 206 | */ |
| 207 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, true ); |
|
| 207 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, true); |
|
| 208 | 208 | |
| 209 | - $request->set_param( 'context', 'edit' ); |
|
| 210 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
| 211 | - $response = rest_ensure_response( $response ); |
|
| 212 | - $response->set_status( 201 ); |
|
| 213 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post_id ) ) ); |
|
| 209 | + $request->set_param('context', 'edit'); |
|
| 210 | + $response = $this->prepare_item_for_response($post, $request); |
|
| 211 | + $response = rest_ensure_response($response); |
|
| 212 | + $response->set_status(201); |
|
| 213 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post_id))); |
|
| 214 | 214 | |
| 215 | 215 | return $response; |
| 216 | 216 | } |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * @param \WP_REST_Request $request \WP_REST_Request Object. |
| 223 | 223 | * @return bool|\WP_Error |
| 224 | 224 | */ |
| 225 | - protected function add_post_meta_fields( $post, $request ) { |
|
| 225 | + protected function add_post_meta_fields($post, $request) { |
|
| 226 | 226 | return true; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | * @param WP_Post $post Post object. |
| 233 | 233 | */ |
| 234 | - protected function delete_post( $post ) { |
|
| 235 | - wp_delete_post( $post->ID, true ); |
|
| 234 | + protected function delete_post($post) { |
|
| 235 | + wp_delete_post($post->ID, true); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -241,37 +241,37 @@ discard block |
||
| 241 | 241 | * @param \WP_REST_Request $request Full details about the request. |
| 242 | 242 | * @return \WP_Error\WP_REST_Response |
| 243 | 243 | */ |
| 244 | - public function update_item( $request ) { |
|
| 244 | + public function update_item($request) { |
|
| 245 | 245 | $id = (int) $request['id']; |
| 246 | - $post = get_post( $id ); |
|
| 246 | + $post = get_post($id); |
|
| 247 | 247 | |
| 248 | - if ( ! empty( $post->post_type ) && 'product_variation' === $post->post_type && 'product' === $this->post_type ) { |
|
| 249 | - return new \WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 250 | - } elseif ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) { |
|
| 251 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 248 | + if ( ! empty($post->post_type) && 'product_variation' === $post->post_type && 'product' === $this->post_type) { |
|
| 249 | + return new \WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce'), array('status' => 404)); |
|
| 250 | + } elseif (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) { |
|
| 251 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400)); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - $post = $this->prepare_item_for_database( $request ); |
|
| 255 | - if ( is_wp_error( $post ) ) { |
|
| 254 | + $post = $this->prepare_item_for_database($request); |
|
| 255 | + if (is_wp_error($post)) { |
|
| 256 | 256 | return $post; |
| 257 | 257 | } |
| 258 | 258 | // Convert the post object to an array, otherwise wp_update_post will expect non-escaped input. |
| 259 | - $post_id = wp_update_post( (array) $post, true ); |
|
| 260 | - if ( is_wp_error( $post_id ) ) { |
|
| 261 | - if ( in_array( $post_id->get_error_code(), array( 'db_update_error' ) ) ) { |
|
| 262 | - $post_id->add_data( array( 'status' => 500 ) ); |
|
| 259 | + $post_id = wp_update_post((array) $post, true); |
|
| 260 | + if (is_wp_error($post_id)) { |
|
| 261 | + if (in_array($post_id->get_error_code(), array('db_update_error'))) { |
|
| 262 | + $post_id->add_data(array('status' => 500)); |
|
| 263 | 263 | } else { |
| 264 | - $post_id->add_data( array( 'status' => 400 ) ); |
|
| 264 | + $post_id->add_data(array('status' => 400)); |
|
| 265 | 265 | } |
| 266 | 266 | return $post_id; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - $post = get_post( $post_id ); |
|
| 270 | - $this->update_additional_fields_for_object( $post, $request ); |
|
| 269 | + $post = get_post($post_id); |
|
| 270 | + $this->update_additional_fields_for_object($post, $request); |
|
| 271 | 271 | |
| 272 | 272 | // Update meta fields. |
| 273 | - $meta_fields = $this->update_post_meta_fields( $post, $request ); |
|
| 274 | - if ( is_wp_error( $meta_fields ) ) { |
|
| 273 | + $meta_fields = $this->update_post_meta_fields($post, $request); |
|
| 274 | + if (is_wp_error($meta_fields)) { |
|
| 275 | 275 | return $meta_fields; |
| 276 | 276 | } |
| 277 | 277 | |
@@ -282,11 +282,11 @@ discard block |
||
| 282 | 282 | * @param \WP_REST_Request $request Request object. |
| 283 | 283 | * @param boolean $creating True when creating item, false when updating. |
| 284 | 284 | */ |
| 285 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, false ); |
|
| 285 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, false); |
|
| 286 | 286 | |
| 287 | - $request->set_param( 'context', 'edit' ); |
|
| 288 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
| 289 | - return rest_ensure_response( $response ); |
|
| 287 | + $request->set_param('context', 'edit'); |
|
| 288 | + $response = $this->prepare_item_for_response($post, $request); |
|
| 289 | + return rest_ensure_response($response); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @param \WP_REST_Request $request Full details about the request. |
| 296 | 296 | * @return \WP_Error\WP_REST_Response |
| 297 | 297 | */ |
| 298 | - public function get_items( $request ) { |
|
| 298 | + public function get_items($request) { |
|
| 299 | 299 | $args = array(); |
| 300 | 300 | $args['offset'] = $request['offset']; |
| 301 | 301 | $args['order'] = $request['order']; |
@@ -311,19 +311,19 @@ discard block |
||
| 311 | 311 | |
| 312 | 312 | $args['date_query'] = array(); |
| 313 | 313 | // Set before into date query. Date query must be specified as an array of an array. |
| 314 | - if ( isset( $request['before'] ) ) { |
|
| 314 | + if (isset($request['before'])) { |
|
| 315 | 315 | $args['date_query'][0]['before'] = $request['before']; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // Set after into date query. Date query must be specified as an array of an array. |
| 319 | - if ( isset( $request['after'] ) ) { |
|
| 319 | + if (isset($request['after'])) { |
|
| 320 | 320 | $args['date_query'][0]['after'] = $request['after']; |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - if ( 'wc/v1' === $this->namespace ) { |
|
| 324 | - if ( is_array( $request['filter'] ) ) { |
|
| 325 | - $args = array_merge( $args, $request['filter'] ); |
|
| 326 | - unset( $args['filter'] ); |
|
| 323 | + if ('wc/v1' === $this->namespace) { |
|
| 324 | + if (is_array($request['filter'])) { |
|
| 325 | + $args = array_merge($args, $request['filter']); |
|
| 326 | + unset($args['filter']); |
|
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | |
@@ -339,59 +339,59 @@ discard block |
||
| 339 | 339 | * @param array $args Key value array of query var to query value. |
| 340 | 340 | * @param \WP_REST_Request $request The request used. |
| 341 | 341 | */ |
| 342 | - $args = apply_filters( "woocommerce_rest_{$this->post_type}_query", $args, $request ); |
|
| 343 | - $query_args = $this->prepare_items_query( $args, $request ); |
|
| 342 | + $args = apply_filters("woocommerce_rest_{$this->post_type}_query", $args, $request); |
|
| 343 | + $query_args = $this->prepare_items_query($args, $request); |
|
| 344 | 344 | |
| 345 | 345 | $posts_query = new \WP_Query(); |
| 346 | - $query_result = $posts_query->query( $query_args ); |
|
| 346 | + $query_result = $posts_query->query($query_args); |
|
| 347 | 347 | |
| 348 | 348 | $posts = array(); |
| 349 | - foreach ( $query_result as $post ) { |
|
| 350 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) { |
|
| 349 | + foreach ($query_result as $post) { |
|
| 350 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'read', $post->ID)) { |
|
| 351 | 351 | continue; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - $data = $this->prepare_item_for_response( $post, $request ); |
|
| 355 | - $posts[] = $this->prepare_response_for_collection( $data ); |
|
| 354 | + $data = $this->prepare_item_for_response($post, $request); |
|
| 355 | + $posts[] = $this->prepare_response_for_collection($data); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | $page = (int) $query_args['paged']; |
| 359 | 359 | $total_posts = $posts_query->found_posts; |
| 360 | 360 | |
| 361 | - if ( $total_posts < 1 ) { |
|
| 361 | + if ($total_posts < 1) { |
|
| 362 | 362 | // Out-of-bounds, run the query again without LIMIT for total count. |
| 363 | - unset( $query_args['paged'] ); |
|
| 363 | + unset($query_args['paged']); |
|
| 364 | 364 | $count_query = new \WP_Query(); |
| 365 | - $count_query->query( $query_args ); |
|
| 365 | + $count_query->query($query_args); |
|
| 366 | 366 | $total_posts = $count_query->found_posts; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - $max_pages = ceil( $total_posts / (int) $query_args['posts_per_page'] ); |
|
| 369 | + $max_pages = ceil($total_posts / (int) $query_args['posts_per_page']); |
|
| 370 | 370 | |
| 371 | - $response = rest_ensure_response( $posts ); |
|
| 372 | - $response->header( 'X-WP-Total', (int) $total_posts ); |
|
| 373 | - $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
| 371 | + $response = rest_ensure_response($posts); |
|
| 372 | + $response->header('X-WP-Total', (int) $total_posts); |
|
| 373 | + $response->header('X-WP-TotalPages', (int) $max_pages); |
|
| 374 | 374 | |
| 375 | 375 | $request_params = $request->get_query_params(); |
| 376 | - if ( ! empty( $request_params['filter'] ) ) { |
|
| 376 | + if ( ! empty($request_params['filter'])) { |
|
| 377 | 377 | // Normalize the pagination params. |
| 378 | - unset( $request_params['filter']['posts_per_page'] ); |
|
| 379 | - unset( $request_params['filter']['paged'] ); |
|
| 378 | + unset($request_params['filter']['posts_per_page']); |
|
| 379 | + unset($request_params['filter']['paged']); |
|
| 380 | 380 | } |
| 381 | - $base = add_query_arg( $request_params, rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 381 | + $base = add_query_arg($request_params, rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 382 | 382 | |
| 383 | - if ( $page > 1 ) { |
|
| 383 | + if ($page > 1) { |
|
| 384 | 384 | $prev_page = $page - 1; |
| 385 | - if ( $prev_page > $max_pages ) { |
|
| 385 | + if ($prev_page > $max_pages) { |
|
| 386 | 386 | $prev_page = $max_pages; |
| 387 | 387 | } |
| 388 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 389 | - $response->link_header( 'prev', $prev_link ); |
|
| 388 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 389 | + $response->link_header('prev', $prev_link); |
|
| 390 | 390 | } |
| 391 | - if ( $max_pages > $page ) { |
|
| 391 | + if ($max_pages > $page) { |
|
| 392 | 392 | $next_page = $page + 1; |
| 393 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 394 | - $response->link_header( 'next', $next_link ); |
|
| 393 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 394 | + $response->link_header('next', $next_link); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | return $response; |
@@ -403,13 +403,13 @@ discard block |
||
| 403 | 403 | * @param \WP_REST_Request $request Full details about the request. |
| 404 | 404 | * @return \WP_REST_Response|\WP_Error |
| 405 | 405 | */ |
| 406 | - public function delete_item( $request ) { |
|
| 406 | + public function delete_item($request) { |
|
| 407 | 407 | $id = (int) $request['id']; |
| 408 | 408 | $force = (bool) $request['force']; |
| 409 | - $post = get_post( $id ); |
|
| 409 | + $post = get_post($id); |
|
| 410 | 410 | |
| 411 | - if ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) { |
|
| 412 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 411 | + if (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) { |
|
| 412 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 404)); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | $supports_trash = EMPTY_TRASH_DAYS > 0; |
@@ -422,40 +422,40 @@ discard block |
||
| 422 | 422 | * @param boolean $supports_trash Whether the item type support trashing. |
| 423 | 423 | * @param WP_Post $post The Post object being considered for trashing support. |
| 424 | 424 | */ |
| 425 | - $supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_trashable", $supports_trash, $post ); |
|
| 425 | + $supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_trashable", $supports_trash, $post); |
|
| 426 | 426 | |
| 427 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $post->ID ) ) { |
|
| 427 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $post->ID)) { |
|
| 428 | 428 | /* translators: %s: post type */ |
| 429 | - return new \WP_Error( "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 429 | + return new \WP_Error("woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), array('status' => rest_authorization_required_code())); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - $request->set_param( 'context', 'edit' ); |
|
| 433 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
| 432 | + $request->set_param('context', 'edit'); |
|
| 433 | + $response = $this->prepare_item_for_response($post, $request); |
|
| 434 | 434 | |
| 435 | 435 | // If we're forcing, then delete permanently. |
| 436 | - if ( $force ) { |
|
| 437 | - $result = wp_delete_post( $id, true ); |
|
| 436 | + if ($force) { |
|
| 437 | + $result = wp_delete_post($id, true); |
|
| 438 | 438 | } else { |
| 439 | 439 | // If we don't support trashing for this type, error out. |
| 440 | - if ( ! $supports_trash ) { |
|
| 440 | + if ( ! $supports_trash) { |
|
| 441 | 441 | /* translators: %s: post type */ |
| 442 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( 'status' => 501 ) ); |
|
| 442 | + return new \WP_Error('woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array('status' => 501)); |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | // Otherwise, only trash if we haven't already. |
| 446 | - if ( 'trash' === $post->post_status ) { |
|
| 446 | + if ('trash' === $post->post_status) { |
|
| 447 | 447 | /* translators: %s: post type */ |
| 448 | - return new \WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 410 ) ); |
|
| 448 | + return new \WP_Error('woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array('status' => 410)); |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | // (Note that internally this falls through to `wp_delete_post` if |
| 452 | 452 | // the trash is disabled.) |
| 453 | - $result = wp_trash_post( $id ); |
|
| 453 | + $result = wp_trash_post($id); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - if ( ! $result ) { |
|
| 456 | + if ( ! $result) { |
|
| 457 | 457 | /* translators: %s: post type */ |
| 458 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) ); |
|
| 458 | + return new \WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array('status' => 500)); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | * @param \WP_REST_Response $response The response data. |
| 466 | 466 | * @param \WP_REST_Request $request The request sent to the API. |
| 467 | 467 | */ |
| 468 | - do_action( "woocommerce_rest_delete_{$this->post_type}", $post, $response, $request ); |
|
| 468 | + do_action("woocommerce_rest_delete_{$this->post_type}", $post, $response, $request); |
|
| 469 | 469 | |
| 470 | 470 | return $response; |
| 471 | 471 | } |
@@ -477,13 +477,13 @@ discard block |
||
| 477 | 477 | * @param \WP_REST_Request $request Request object. |
| 478 | 478 | * @return array Links for the given post. |
| 479 | 479 | */ |
| 480 | - protected function prepare_links( $post, $request ) { |
|
| 480 | + protected function prepare_links($post, $request) { |
|
| 481 | 481 | $links = array( |
| 482 | 482 | 'self' => array( |
| 483 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ), |
|
| 483 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID)), |
|
| 484 | 484 | ), |
| 485 | 485 | 'collection' => array( |
| 486 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
| 486 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
| 487 | 487 | ), |
| 488 | 488 | ); |
| 489 | 489 | |
@@ -498,12 +498,12 @@ discard block |
||
| 498 | 498 | * @param \WP_REST_Request $request Request object. |
| 499 | 499 | * @return array $query_args |
| 500 | 500 | */ |
| 501 | - protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
| 501 | + protected function prepare_items_query($prepared_args = array(), $request = null) { |
|
| 502 | 502 | |
| 503 | - $valid_vars = array_flip( $this->get_allowed_query_vars() ); |
|
| 503 | + $valid_vars = array_flip($this->get_allowed_query_vars()); |
|
| 504 | 504 | $query_args = array(); |
| 505 | - foreach ( $valid_vars as $var => $index ) { |
|
| 506 | - if ( isset( $prepared_args[ $var ] ) ) { |
|
| 505 | + foreach ($valid_vars as $var => $index) { |
|
| 506 | + if (isset($prepared_args[$var])) { |
|
| 507 | 507 | /** |
| 508 | 508 | * Filter the query_vars used in `get_items` for the constructed query. |
| 509 | 509 | * |
@@ -511,17 +511,17 @@ discard block |
||
| 511 | 511 | * |
| 512 | 512 | * @param mixed $prepared_args[ $var ] The query_var value. |
| 513 | 513 | */ |
| 514 | - $query_args[ $var ] = apply_filters( "woocommerce_rest_query_var-{$var}", $prepared_args[ $var ] ); |
|
| 514 | + $query_args[$var] = apply_filters("woocommerce_rest_query_var-{$var}", $prepared_args[$var]); |
|
| 515 | 515 | } |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | $query_args['ignore_sticky_posts'] = true; |
| 519 | 519 | |
| 520 | - if ( 'include' === $query_args['orderby'] ) { |
|
| 520 | + if ('include' === $query_args['orderby']) { |
|
| 521 | 521 | $query_args['orderby'] = 'post__in'; |
| 522 | - } elseif ( 'id' === $query_args['orderby'] ) { |
|
| 522 | + } elseif ('id' === $query_args['orderby']) { |
|
| 523 | 523 | $query_args['orderby'] = 'ID'; // ID must be capitalized. |
| 524 | - } elseif ( 'slug' === $query_args['orderby'] ) { |
|
| 524 | + } elseif ('slug' === $query_args['orderby']) { |
|
| 525 | 525 | $query_args['orderby'] = 'name'; |
| 526 | 526 | } |
| 527 | 527 | |
@@ -543,10 +543,10 @@ discard block |
||
| 543 | 543 | * |
| 544 | 544 | * @param array Array of allowed \WP_Query query vars. |
| 545 | 545 | */ |
| 546 | - $valid_vars = apply_filters( 'query_vars', $wp->public_query_vars ); |
|
| 546 | + $valid_vars = apply_filters('query_vars', $wp->public_query_vars); |
|
| 547 | 547 | |
| 548 | - $post_type_obj = get_post_type_object( $this->post_type ); |
|
| 549 | - if ( current_user_can( $post_type_obj->cap->edit_posts ) ) { |
|
| 548 | + $post_type_obj = get_post_type_object($this->post_type); |
|
| 549 | + if (current_user_can($post_type_obj->cap->edit_posts)) { |
|
| 550 | 550 | /** |
| 551 | 551 | * Filter the allowed 'private' query vars for authorized users. |
| 552 | 552 | * |
@@ -560,8 +560,8 @@ discard block |
||
| 560 | 560 | * @param array $private_query_vars Array of allowed query vars for authorized users. |
| 561 | 561 | * } |
| 562 | 562 | */ |
| 563 | - $private = apply_filters( 'woocommerce_rest_private_query_vars', $wp->private_query_vars ); |
|
| 564 | - $valid_vars = array_merge( $valid_vars, $private ); |
|
| 563 | + $private = apply_filters('woocommerce_rest_private_query_vars', $wp->private_query_vars); |
|
| 564 | + $valid_vars = array_merge($valid_vars, $private); |
|
| 565 | 565 | } |
| 566 | 566 | // Define our own in addition to WP's normal vars. |
| 567 | 567 | $rest_valid = array( |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | 'meta_compare', |
| 582 | 582 | 'meta_value_num', |
| 583 | 583 | ); |
| 584 | - $valid_vars = array_merge( $valid_vars, $rest_valid ); |
|
| 584 | + $valid_vars = array_merge($valid_vars, $rest_valid); |
|
| 585 | 585 | |
| 586 | 586 | /** |
| 587 | 587 | * Filter allowed query vars for the REST API. |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | * @param string $allowed_query_var The query var to allow. |
| 597 | 597 | * } |
| 598 | 598 | */ |
| 599 | - $valid_vars = apply_filters( 'woocommerce_rest_query_vars', $valid_vars ); |
|
| 599 | + $valid_vars = apply_filters('woocommerce_rest_query_vars', $valid_vars); |
|
| 600 | 600 | |
| 601 | 601 | return $valid_vars; |
| 602 | 602 | } |
@@ -612,19 +612,19 @@ discard block |
||
| 612 | 612 | $params['context']['default'] = 'view'; |
| 613 | 613 | |
| 614 | 614 | $params['after'] = array( |
| 615 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 615 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
| 616 | 616 | 'type' => 'string', |
| 617 | 617 | 'format' => 'date-time', |
| 618 | 618 | 'validate_callback' => 'rest_validate_request_arg', |
| 619 | 619 | ); |
| 620 | 620 | $params['before'] = array( |
| 621 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
| 621 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
| 622 | 622 | 'type' => 'string', |
| 623 | 623 | 'format' => 'date-time', |
| 624 | 624 | 'validate_callback' => 'rest_validate_request_arg', |
| 625 | 625 | ); |
| 626 | 626 | $params['exclude'] = array( |
| 627 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
|
| 627 | + 'description' => __('Ensure result set excludes specific IDs.', 'woocommerce'), |
|
| 628 | 628 | 'type' => 'array', |
| 629 | 629 | 'items' => array( |
| 630 | 630 | 'type' => 'integer', |
@@ -633,7 +633,7 @@ discard block |
||
| 633 | 633 | 'sanitize_callback' => 'wp_parse_id_list', |
| 634 | 634 | ); |
| 635 | 635 | $params['include'] = array( |
| 636 | - 'description' => __( 'Limit result set to specific ids.', 'woocommerce' ), |
|
| 636 | + 'description' => __('Limit result set to specific ids.', 'woocommerce'), |
|
| 637 | 637 | 'type' => 'array', |
| 638 | 638 | 'items' => array( |
| 639 | 639 | 'type' => 'integer', |
@@ -642,20 +642,20 @@ discard block |
||
| 642 | 642 | 'sanitize_callback' => 'wp_parse_id_list', |
| 643 | 643 | ); |
| 644 | 644 | $params['offset'] = array( |
| 645 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
| 645 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
| 646 | 646 | 'type' => 'integer', |
| 647 | 647 | 'sanitize_callback' => 'absint', |
| 648 | 648 | 'validate_callback' => 'rest_validate_request_arg', |
| 649 | 649 | ); |
| 650 | 650 | $params['order'] = array( |
| 651 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 651 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 652 | 652 | 'type' => 'string', |
| 653 | 653 | 'default' => 'desc', |
| 654 | - 'enum' => array( 'asc', 'desc' ), |
|
| 654 | + 'enum' => array('asc', 'desc'), |
|
| 655 | 655 | 'validate_callback' => 'rest_validate_request_arg', |
| 656 | 656 | ); |
| 657 | 657 | $params['orderby'] = array( |
| 658 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 658 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 659 | 659 | 'type' => 'string', |
| 660 | 660 | 'default' => 'date', |
| 661 | 661 | 'enum' => array( |
@@ -668,11 +668,11 @@ discard block |
||
| 668 | 668 | 'validate_callback' => 'rest_validate_request_arg', |
| 669 | 669 | ); |
| 670 | 670 | |
| 671 | - $post_type_obj = get_post_type_object( $this->post_type ); |
|
| 671 | + $post_type_obj = get_post_type_object($this->post_type); |
|
| 672 | 672 | |
| 673 | - if ( isset( $post_type_obj->hierarchical ) && $post_type_obj->hierarchical ) { |
|
| 673 | + if (isset($post_type_obj->hierarchical) && $post_type_obj->hierarchical) { |
|
| 674 | 674 | $params['parent'] = array( |
| 675 | - 'description' => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ), |
|
| 675 | + 'description' => __('Limit result set to those of particular parent IDs.', 'woocommerce'), |
|
| 676 | 676 | 'type' => 'array', |
| 677 | 677 | 'items' => array( |
| 678 | 678 | 'type' => 'integer', |
@@ -681,7 +681,7 @@ discard block |
||
| 681 | 681 | 'default' => array(), |
| 682 | 682 | ); |
| 683 | 683 | $params['parent_exclude'] = array( |
| 684 | - 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ), |
|
| 684 | + 'description' => __('Limit result set to all items except those of a particular parent ID.', 'woocommerce'), |
|
| 685 | 685 | 'type' => 'array', |
| 686 | 686 | 'items' => array( |
| 687 | 687 | 'type' => 'integer', |
@@ -691,10 +691,10 @@ discard block |
||
| 691 | 691 | ); |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | - if ( 'wc/v1' === $this->namespace ) { |
|
| 694 | + if ('wc/v1' === $this->namespace) { |
|
| 695 | 695 | $params['filter'] = array( |
| 696 | 696 | 'type' => 'object', |
| 697 | - 'description' => __( 'Use WP Query arguments to modify the response; private query vars require appropriate authorization.', 'woocommerce' ), |
|
| 697 | + 'description' => __('Use WP Query arguments to modify the response; private query vars require appropriate authorization.', 'woocommerce'), |
|
| 698 | 698 | ); |
| 699 | 699 | } |
| 700 | 700 | |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | * @param \WP_REST_Request $request Request object. |
| 709 | 709 | * @return bool|\WP_Error |
| 710 | 710 | */ |
| 711 | - protected function update_post_meta_fields( $post, $request ) { |
|
| 711 | + protected function update_post_meta_fields($post, $request) { |
|
| 712 | 712 | return true; |
| 713 | 713 | } |
| 714 | 714 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API Shipping Zone Methods class. |
@@ -26,31 +26,31 @@ discard block |
||
| 26 | 26 | array( |
| 27 | 27 | 'args' => array( |
| 28 | 28 | 'zone_id' => array( |
| 29 | - 'description' => __( 'Unique ID for the zone.', 'woocommerce' ), |
|
| 29 | + 'description' => __('Unique ID for the zone.', 'woocommerce'), |
|
| 30 | 30 | 'type' => 'integer', |
| 31 | 31 | ), |
| 32 | 32 | ), |
| 33 | 33 | array( |
| 34 | 34 | 'methods' => \WP_REST_Server::READABLE, |
| 35 | - 'callback' => array( $this, 'get_items' ), |
|
| 36 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 35 | + 'callback' => array($this, 'get_items'), |
|
| 36 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 37 | 37 | ), |
| 38 | 38 | array( |
| 39 | 39 | 'methods' => \WP_REST_Server::CREATABLE, |
| 40 | - 'callback' => array( $this, 'create_item' ), |
|
| 41 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
| 40 | + 'callback' => array($this, 'create_item'), |
|
| 41 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
| 42 | 42 | 'args' => array_merge( |
| 43 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
| 43 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
| 44 | 44 | array( |
| 45 | 45 | 'method_id' => array( |
| 46 | 46 | 'required' => true, |
| 47 | 47 | 'readonly' => false, |
| 48 | - 'description' => __( 'Shipping method ID.', 'woocommerce' ), |
|
| 48 | + 'description' => __('Shipping method ID.', 'woocommerce'), |
|
| 49 | 49 | ), |
| 50 | 50 | ) |
| 51 | 51 | ), |
| 52 | 52 | ), |
| 53 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 53 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 54 | 54 | ), |
| 55 | 55 | true |
| 56 | 56 | ); |
@@ -61,38 +61,38 @@ discard block |
||
| 61 | 61 | array( |
| 62 | 62 | 'args' => array( |
| 63 | 63 | 'zone_id' => array( |
| 64 | - 'description' => __( 'Unique ID for the zone.', 'woocommerce' ), |
|
| 64 | + 'description' => __('Unique ID for the zone.', 'woocommerce'), |
|
| 65 | 65 | 'type' => 'integer', |
| 66 | 66 | ), |
| 67 | 67 | 'instance_id' => array( |
| 68 | - 'description' => __( 'Unique ID for the instance.', 'woocommerce' ), |
|
| 68 | + 'description' => __('Unique ID for the instance.', 'woocommerce'), |
|
| 69 | 69 | 'type' => 'integer', |
| 70 | 70 | ), |
| 71 | 71 | ), |
| 72 | 72 | array( |
| 73 | 73 | 'methods' => \WP_REST_Server::READABLE, |
| 74 | - 'callback' => array( $this, 'get_item' ), |
|
| 75 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 74 | + 'callback' => array($this, 'get_item'), |
|
| 75 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 76 | 76 | ), |
| 77 | 77 | array( |
| 78 | 78 | 'methods' => \WP_REST_Server::EDITABLE, |
| 79 | - 'callback' => array( $this, 'update_item' ), |
|
| 80 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
| 81 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
| 79 | + 'callback' => array($this, 'update_item'), |
|
| 80 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
| 81 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
| 82 | 82 | ), |
| 83 | 83 | array( |
| 84 | 84 | 'methods' => \WP_REST_Server::DELETABLE, |
| 85 | - 'callback' => array( $this, 'delete_item' ), |
|
| 86 | - 'permission_callback' => array( $this, 'delete_items_permissions_check' ), |
|
| 85 | + 'callback' => array($this, 'delete_item'), |
|
| 86 | + 'permission_callback' => array($this, 'delete_items_permissions_check'), |
|
| 87 | 87 | 'args' => array( |
| 88 | 88 | 'force' => array( |
| 89 | 89 | 'default' => false, |
| 90 | 90 | 'type' => 'boolean', |
| 91 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
| 91 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
| 92 | 92 | ), |
| 93 | 93 | ), |
| 94 | 94 | ), |
| 95 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 95 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 96 | 96 | ), |
| 97 | 97 | true |
| 98 | 98 | ); |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | * @param \WP_REST_Request $request Request data. |
| 105 | 105 | * @return \WP_REST_Response|\WP_Error |
| 106 | 106 | */ |
| 107 | - public function get_item( $request ) { |
|
| 108 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
| 107 | + public function get_item($request) { |
|
| 108 | + $zone = $this->get_zone($request['zone_id']); |
|
| 109 | 109 | |
| 110 | - if ( is_wp_error( $zone ) ) { |
|
| 110 | + if (is_wp_error($zone)) { |
|
| 111 | 111 | return $zone; |
| 112 | 112 | } |
| 113 | 113 | |
@@ -115,20 +115,20 @@ discard block |
||
| 115 | 115 | $methods = $zone->get_shipping_methods(); |
| 116 | 116 | $method = false; |
| 117 | 117 | |
| 118 | - foreach ( $methods as $method_obj ) { |
|
| 119 | - if ( $instance_id === $method_obj->instance_id ) { |
|
| 118 | + foreach ($methods as $method_obj) { |
|
| 119 | + if ($instance_id === $method_obj->instance_id) { |
|
| 120 | 120 | $method = $method_obj; |
| 121 | 121 | break; |
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - if ( false === $method ) { |
|
| 126 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 125 | + if (false === $method) { |
|
| 126 | + return new \WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
| 129 | + $data = $this->prepare_item_for_response($method, $request); |
|
| 130 | 130 | |
| 131 | - return rest_ensure_response( $data ); |
|
| 131 | + return rest_ensure_response($data); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -137,22 +137,22 @@ discard block |
||
| 137 | 137 | * @param \WP_REST_Request $request Request data. |
| 138 | 138 | * @return \WP_REST_Response|\WP_Error |
| 139 | 139 | */ |
| 140 | - public function get_items( $request ) { |
|
| 141 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
| 140 | + public function get_items($request) { |
|
| 141 | + $zone = $this->get_zone($request['zone_id']); |
|
| 142 | 142 | |
| 143 | - if ( is_wp_error( $zone ) ) { |
|
| 143 | + if (is_wp_error($zone)) { |
|
| 144 | 144 | return $zone; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | $methods = $zone->get_shipping_methods(); |
| 148 | 148 | $data = array(); |
| 149 | 149 | |
| 150 | - foreach ( $methods as $method_obj ) { |
|
| 151 | - $method = $this->prepare_item_for_response( $method_obj, $request ); |
|
| 150 | + foreach ($methods as $method_obj) { |
|
| 151 | + $method = $this->prepare_item_for_response($method_obj, $request); |
|
| 152 | 152 | $data[] = $method; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - return rest_ensure_response( $data ); |
|
| 155 | + return rest_ensure_response($data); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -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 create_item( $request ) { |
|
| 164 | + public function create_item($request) { |
|
| 165 | 165 | $method_id = $request['method_id']; |
| 166 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
| 167 | - if ( is_wp_error( $zone ) ) { |
|
| 166 | + $zone = $this->get_zone($request['zone_id']); |
|
| 167 | + if (is_wp_error($zone)) { |
|
| 168 | 168 | return $zone; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - $instance_id = $zone->add_shipping_method( $method_id ); |
|
| 171 | + $instance_id = $zone->add_shipping_method($method_id); |
|
| 172 | 172 | $methods = $zone->get_shipping_methods(); |
| 173 | 173 | $method = false; |
| 174 | - foreach ( $methods as $method_obj ) { |
|
| 175 | - if ( $instance_id === $method_obj->instance_id ) { |
|
| 174 | + foreach ($methods as $method_obj) { |
|
| 175 | + if ($instance_id === $method_obj->instance_id) { |
|
| 176 | 176 | $method = $method_obj; |
| 177 | 177 | break; |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - if ( false === $method ) { |
|
| 182 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_not_created', __( 'Resource cannot be created.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 181 | + if (false === $method) { |
|
| 182 | + return new \WP_Error('woocommerce_rest_shipping_zone_not_created', __('Resource cannot be created.', 'woocommerce'), array('status' => 500)); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
| 186 | - if ( is_wp_error( $method ) ) { |
|
| 185 | + $method = $this->update_fields($instance_id, $method, $request); |
|
| 186 | + if (is_wp_error($method)) { |
|
| 187 | 187 | return $method; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
| 191 | - return rest_ensure_response( $data ); |
|
| 190 | + $data = $this->prepare_item_for_response($method, $request); |
|
| 191 | + return rest_ensure_response($data); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -197,9 +197,9 @@ discard block |
||
| 197 | 197 | * @param \WP_REST_Request $request Full details about the request. |
| 198 | 198 | * @return \WP_Error|boolean |
| 199 | 199 | */ |
| 200 | - public function delete_item( $request ) { |
|
| 201 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
| 202 | - if ( is_wp_error( $zone ) ) { |
|
| 200 | + public function delete_item($request) { |
|
| 201 | + $zone = $this->get_zone($request['zone_id']); |
|
| 202 | + if (is_wp_error($zone)) { |
|
| 203 | 203 | return $zone; |
| 204 | 204 | } |
| 205 | 205 | |
@@ -207,34 +207,34 @@ discard block |
||
| 207 | 207 | $force = $request['force']; |
| 208 | 208 | |
| 209 | 209 | // We don't support trashing for this type, error out. |
| 210 | - if ( ! $force ) { |
|
| 211 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Shipping methods do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
| 210 | + if ( ! $force) { |
|
| 211 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Shipping methods do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | $methods = $zone->get_shipping_methods(); |
| 215 | 215 | $method = false; |
| 216 | 216 | |
| 217 | - foreach ( $methods as $method_obj ) { |
|
| 218 | - if ( $instance_id === $method_obj->instance_id ) { |
|
| 217 | + foreach ($methods as $method_obj) { |
|
| 218 | + if ($instance_id === $method_obj->instance_id) { |
|
| 219 | 219 | $method = $method_obj; |
| 220 | 220 | break; |
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - if ( false === $method ) { |
|
| 225 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 224 | + if (false === $method) { |
|
| 225 | + return new \WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
| 229 | - if ( is_wp_error( $method ) ) { |
|
| 228 | + $method = $this->update_fields($instance_id, $method, $request); |
|
| 229 | + if (is_wp_error($method)) { |
|
| 230 | 230 | return $method; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - $request->set_param( 'context', 'view' ); |
|
| 234 | - $previous = $this->prepare_item_for_response( $method, $request ); |
|
| 233 | + $request->set_param('context', 'view'); |
|
| 234 | + $previous = $this->prepare_item_for_response($method, $request); |
|
| 235 | 235 | |
| 236 | 236 | // Actually delete. |
| 237 | - $zone->delete_shipping_method( $instance_id ); |
|
| 237 | + $zone->delete_shipping_method($instance_id); |
|
| 238 | 238 | $response = new \WP_REST_Response(); |
| 239 | 239 | $response->set_data( |
| 240 | 240 | array( |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * @param \WP_REST_Response $response The response data. |
| 251 | 251 | * @param \WP_REST_Request $request The request sent to the API. |
| 252 | 252 | */ |
| 253 | - do_action( 'woocommerce_rest_delete_shipping_zone_method', $method, $response, $request ); |
|
| 253 | + do_action('woocommerce_rest_delete_shipping_zone_method', $method, $response, $request); |
|
| 254 | 254 | |
| 255 | 255 | return $response; |
| 256 | 256 | } |
@@ -261,9 +261,9 @@ discard block |
||
| 261 | 261 | * @param \WP_REST_Request $request Request data. |
| 262 | 262 | * @return \WP_REST_Response|\WP_Error |
| 263 | 263 | */ |
| 264 | - public function update_item( $request ) { |
|
| 265 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
| 266 | - if ( is_wp_error( $zone ) ) { |
|
| 264 | + public function update_item($request) { |
|
| 265 | + $zone = $this->get_zone($request['zone_id']); |
|
| 266 | + if (is_wp_error($zone)) { |
|
| 267 | 267 | return $zone; |
| 268 | 268 | } |
| 269 | 269 | |
@@ -271,24 +271,24 @@ discard block |
||
| 271 | 271 | $methods = $zone->get_shipping_methods(); |
| 272 | 272 | $method = false; |
| 273 | 273 | |
| 274 | - foreach ( $methods as $method_obj ) { |
|
| 275 | - if ( $instance_id === $method_obj->instance_id ) { |
|
| 274 | + foreach ($methods as $method_obj) { |
|
| 275 | + if ($instance_id === $method_obj->instance_id) { |
|
| 276 | 276 | $method = $method_obj; |
| 277 | 277 | break; |
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - if ( false === $method ) { |
|
| 282 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 281 | + if (false === $method) { |
|
| 282 | + return new \WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
| 286 | - if ( is_wp_error( $method ) ) { |
|
| 285 | + $method = $this->update_fields($instance_id, $method, $request); |
|
| 286 | + if (is_wp_error($method)) { |
|
| 287 | 287 | return $method; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
| 291 | - return rest_ensure_response( $data ); |
|
| 290 | + $data = $this->prepare_item_for_response($method, $request); |
|
| 291 | + return rest_ensure_response($data); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -300,47 +300,47 @@ discard block |
||
| 300 | 300 | * |
| 301 | 301 | * @return WC_Shipping_Method |
| 302 | 302 | */ |
| 303 | - public function update_fields( $instance_id, $method, $request ) { |
|
| 303 | + public function update_fields($instance_id, $method, $request) { |
|
| 304 | 304 | global $wpdb; |
| 305 | 305 | |
| 306 | 306 | // Update settings if present. |
| 307 | - if ( isset( $request['settings'] ) ) { |
|
| 307 | + if (isset($request['settings'])) { |
|
| 308 | 308 | $method->init_instance_settings(); |
| 309 | 309 | $instance_settings = $method->instance_settings; |
| 310 | 310 | $errors_found = false; |
| 311 | - foreach ( $method->get_instance_form_fields() as $key => $field ) { |
|
| 312 | - if ( isset( $request['settings'][ $key ] ) ) { |
|
| 313 | - if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) { |
|
| 314 | - $value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field ); |
|
| 311 | + foreach ($method->get_instance_form_fields() as $key => $field) { |
|
| 312 | + if (isset($request['settings'][$key])) { |
|
| 313 | + if (is_callable(array($this, 'validate_setting_' . $field['type'] . '_field'))) { |
|
| 314 | + $value = $this->{'validate_setting_' . $field['type'] . '_field'}($request['settings'][$key], $field); |
|
| 315 | 315 | } else { |
| 316 | - $value = $this->validate_setting_text_field( $request['settings'][ $key ], $field ); |
|
| 316 | + $value = $this->validate_setting_text_field($request['settings'][$key], $field); |
|
| 317 | 317 | } |
| 318 | - if ( is_wp_error( $value ) ) { |
|
| 318 | + if (is_wp_error($value)) { |
|
| 319 | 319 | $errors_found = true; |
| 320 | 320 | break; |
| 321 | 321 | } |
| 322 | - $instance_settings[ $key ] = $value; |
|
| 322 | + $instance_settings[$key] = $value; |
|
| 323 | 323 | } |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - if ( $errors_found ) { |
|
| 327 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 326 | + if ($errors_found) { |
|
| 327 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - update_option( $method->get_instance_option_key(), apply_filters( 'woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method ) ); |
|
| 330 | + update_option($method->get_instance_option_key(), apply_filters('woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method)); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | // Update order. |
| 334 | - if ( isset( $request['order'] ) ) { |
|
| 335 | - $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'method_order' => absint( $request['order'] ) ), array( 'instance_id' => absint( $instance_id ) ) ); |
|
| 336 | - $method->method_order = absint( $request['order'] ); |
|
| 334 | + if (isset($request['order'])) { |
|
| 335 | + $wpdb->update("{$wpdb->prefix}woocommerce_shipping_zone_methods", array('method_order' => absint($request['order'])), array('instance_id' => absint($instance_id))); |
|
| 336 | + $method->method_order = absint($request['order']); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | // Update if this method is enabled or not. |
| 340 | - if ( isset( $request['enabled'] ) ) { |
|
| 341 | - if ( $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'is_enabled' => $request['enabled'] ), array( 'instance_id' => absint( $instance_id ) ) ) ) { |
|
| 342 | - do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled'] ); |
|
| 343 | - $method->enabled = ( true === $request['enabled'] ? 'yes' : 'no' ); |
|
| 340 | + if (isset($request['enabled'])) { |
|
| 341 | + if ($wpdb->update("{$wpdb->prefix}woocommerce_shipping_zone_methods", array('is_enabled' => $request['enabled']), array('instance_id' => absint($instance_id)))) { |
|
| 342 | + do_action('woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled']); |
|
| 343 | + $method->enabled = (true === $request['enabled'] ? 'yes' : 'no'); |
|
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | |
@@ -354,29 +354,29 @@ discard block |
||
| 354 | 354 | * @param \WP_REST_Request $request Request object. |
| 355 | 355 | * @return \WP_REST_Response $response |
| 356 | 356 | */ |
| 357 | - public function prepare_item_for_response( $item, $request ) { |
|
| 357 | + public function prepare_item_for_response($item, $request) { |
|
| 358 | 358 | $method = array( |
| 359 | 359 | 'id' => $item->instance_id, |
| 360 | 360 | 'instance_id' => $item->instance_id, |
| 361 | 361 | 'title' => $item->instance_settings['title'], |
| 362 | 362 | 'order' => $item->method_order, |
| 363 | - 'enabled' => ( 'yes' === $item->enabled ), |
|
| 363 | + 'enabled' => ('yes' === $item->enabled), |
|
| 364 | 364 | 'method_id' => $item->id, |
| 365 | 365 | 'method_title' => $item->method_title, |
| 366 | 366 | 'method_description' => $item->method_description, |
| 367 | - 'settings' => $this->get_settings( $item ), |
|
| 367 | + 'settings' => $this->get_settings($item), |
|
| 368 | 368 | ); |
| 369 | 369 | |
| 370 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
| 371 | - $data = $this->add_additional_fields_to_object( $method, $request ); |
|
| 372 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 370 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
| 371 | + $data = $this->add_additional_fields_to_object($method, $request); |
|
| 372 | + $data = $this->filter_response_by_context($data, $context); |
|
| 373 | 373 | |
| 374 | 374 | // Wrap the data in a response object. |
| 375 | - $response = rest_ensure_response( $data ); |
|
| 375 | + $response = rest_ensure_response($data); |
|
| 376 | 376 | |
| 377 | - $response->add_links( $this->prepare_links( $request['zone_id'], $item->instance_id ) ); |
|
| 377 | + $response->add_links($this->prepare_links($request['zone_id'], $item->instance_id)); |
|
| 378 | 378 | |
| 379 | - $response = $this->prepare_response_for_collection( $response ); |
|
| 379 | + $response = $this->prepare_response_for_collection($response); |
|
| 380 | 380 | |
| 381 | 381 | return $response; |
| 382 | 382 | } |
@@ -388,24 +388,24 @@ discard block |
||
| 388 | 388 | * |
| 389 | 389 | * @return array |
| 390 | 390 | */ |
| 391 | - public function get_settings( $item ) { |
|
| 391 | + public function get_settings($item) { |
|
| 392 | 392 | $item->init_instance_settings(); |
| 393 | 393 | $settings = array(); |
| 394 | - foreach ( $item->get_instance_form_fields() as $id => $field ) { |
|
| 394 | + foreach ($item->get_instance_form_fields() as $id => $field) { |
|
| 395 | 395 | $data = array( |
| 396 | 396 | 'id' => $id, |
| 397 | 397 | 'label' => $field['title'], |
| 398 | - 'description' => empty( $field['description'] ) ? '' : $field['description'], |
|
| 398 | + 'description' => empty($field['description']) ? '' : $field['description'], |
|
| 399 | 399 | 'type' => $field['type'], |
| 400 | - 'value' => $item->instance_settings[ $id ], |
|
| 401 | - 'default' => empty( $field['default'] ) ? '' : $field['default'], |
|
| 402 | - 'tip' => empty( $field['description'] ) ? '' : $field['description'], |
|
| 403 | - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], |
|
| 400 | + 'value' => $item->instance_settings[$id], |
|
| 401 | + 'default' => empty($field['default']) ? '' : $field['default'], |
|
| 402 | + 'tip' => empty($field['description']) ? '' : $field['description'], |
|
| 403 | + 'placeholder' => empty($field['placeholder']) ? '' : $field['placeholder'], |
|
| 404 | 404 | ); |
| 405 | - if ( ! empty( $field['options'] ) ) { |
|
| 405 | + if ( ! empty($field['options'])) { |
|
| 406 | 406 | $data['options'] = $field['options']; |
| 407 | 407 | } |
| 408 | - $settings[ $id ] = $data; |
|
| 408 | + $settings[$id] = $data; |
|
| 409 | 409 | } |
| 410 | 410 | return $settings; |
| 411 | 411 | } |
@@ -417,17 +417,17 @@ discard block |
||
| 417 | 417 | * @param int $instance_id Given Shipping Zone Method Instance ID. |
| 418 | 418 | * @return array Links for the given Shipping Zone Method. |
| 419 | 419 | */ |
| 420 | - protected function prepare_links( $zone_id, $instance_id ) { |
|
| 420 | + protected function prepare_links($zone_id, $instance_id) { |
|
| 421 | 421 | $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id; |
| 422 | 422 | $links = array( |
| 423 | 423 | 'self' => array( |
| 424 | - 'href' => rest_url( $base . '/methods/' . $instance_id ), |
|
| 424 | + 'href' => rest_url($base . '/methods/' . $instance_id), |
|
| 425 | 425 | ), |
| 426 | 426 | 'collection' => array( |
| 427 | - 'href' => rest_url( $base . '/methods' ), |
|
| 427 | + 'href' => rest_url($base . '/methods'), |
|
| 428 | 428 | ), |
| 429 | 429 | 'describes' => array( |
| 430 | - 'href' => rest_url( $base ), |
|
| 430 | + 'href' => rest_url($base), |
|
| 431 | 431 | ), |
| 432 | 432 | ); |
| 433 | 433 | |
@@ -446,102 +446,102 @@ discard block |
||
| 446 | 446 | 'type' => 'object', |
| 447 | 447 | 'properties' => array( |
| 448 | 448 | 'id' => array( |
| 449 | - 'description' => __( 'Shipping method instance ID.', 'woocommerce' ), |
|
| 449 | + 'description' => __('Shipping method instance ID.', 'woocommerce'), |
|
| 450 | 450 | 'type' => 'integer', |
| 451 | - 'context' => array( 'view', 'edit' ), |
|
| 451 | + 'context' => array('view', 'edit'), |
|
| 452 | 452 | 'readonly' => true, |
| 453 | 453 | ), |
| 454 | 454 | 'instance_id' => array( |
| 455 | - 'description' => __( 'Shipping method instance ID.', 'woocommerce' ), |
|
| 455 | + 'description' => __('Shipping method instance ID.', 'woocommerce'), |
|
| 456 | 456 | 'type' => 'integer', |
| 457 | - 'context' => array( 'view', 'edit' ), |
|
| 457 | + 'context' => array('view', 'edit'), |
|
| 458 | 458 | 'readonly' => true, |
| 459 | 459 | ), |
| 460 | 460 | 'title' => array( |
| 461 | - 'description' => __( 'Shipping method customer facing title.', 'woocommerce' ), |
|
| 461 | + 'description' => __('Shipping method customer facing title.', 'woocommerce'), |
|
| 462 | 462 | 'type' => 'string', |
| 463 | - 'context' => array( 'view', 'edit' ), |
|
| 463 | + 'context' => array('view', 'edit'), |
|
| 464 | 464 | 'readonly' => true, |
| 465 | 465 | ), |
| 466 | 466 | 'order' => array( |
| 467 | - 'description' => __( 'Shipping method sort order.', 'woocommerce' ), |
|
| 467 | + 'description' => __('Shipping method sort order.', 'woocommerce'), |
|
| 468 | 468 | 'type' => 'integer', |
| 469 | - 'context' => array( 'view', 'edit' ), |
|
| 469 | + 'context' => array('view', 'edit'), |
|
| 470 | 470 | ), |
| 471 | 471 | 'enabled' => array( |
| 472 | - 'description' => __( 'Shipping method enabled status.', 'woocommerce' ), |
|
| 472 | + 'description' => __('Shipping method enabled status.', 'woocommerce'), |
|
| 473 | 473 | 'type' => 'boolean', |
| 474 | - 'context' => array( 'view', 'edit' ), |
|
| 474 | + 'context' => array('view', 'edit'), |
|
| 475 | 475 | ), |
| 476 | 476 | 'method_id' => array( |
| 477 | - 'description' => __( 'Shipping method ID.', 'woocommerce' ), |
|
| 477 | + 'description' => __('Shipping method ID.', 'woocommerce'), |
|
| 478 | 478 | 'type' => 'string', |
| 479 | - 'context' => array( 'view', 'edit' ), |
|
| 479 | + 'context' => array('view', 'edit'), |
|
| 480 | 480 | 'readonly' => true, |
| 481 | 481 | ), |
| 482 | 482 | 'method_title' => array( |
| 483 | - 'description' => __( 'Shipping method title.', 'woocommerce' ), |
|
| 483 | + 'description' => __('Shipping method title.', 'woocommerce'), |
|
| 484 | 484 | 'type' => 'string', |
| 485 | - 'context' => array( 'view', 'edit' ), |
|
| 485 | + 'context' => array('view', 'edit'), |
|
| 486 | 486 | 'readonly' => true, |
| 487 | 487 | ), |
| 488 | 488 | 'method_description' => array( |
| 489 | - 'description' => __( 'Shipping method description.', 'woocommerce' ), |
|
| 489 | + 'description' => __('Shipping method description.', 'woocommerce'), |
|
| 490 | 490 | 'type' => 'string', |
| 491 | - 'context' => array( 'view', 'edit' ), |
|
| 491 | + 'context' => array('view', 'edit'), |
|
| 492 | 492 | 'readonly' => true, |
| 493 | 493 | ), |
| 494 | 494 | 'settings' => array( |
| 495 | - 'description' => __( 'Shipping method settings.', 'woocommerce' ), |
|
| 495 | + 'description' => __('Shipping method settings.', 'woocommerce'), |
|
| 496 | 496 | 'type' => 'object', |
| 497 | - 'context' => array( 'view', 'edit' ), |
|
| 497 | + 'context' => array('view', 'edit'), |
|
| 498 | 498 | 'properties' => array( |
| 499 | 499 | 'id' => array( |
| 500 | - 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ), |
|
| 500 | + 'description' => __('A unique identifier for the setting.', 'woocommerce'), |
|
| 501 | 501 | 'type' => 'string', |
| 502 | - 'context' => array( 'view', 'edit' ), |
|
| 502 | + 'context' => array('view', 'edit'), |
|
| 503 | 503 | 'readonly' => true, |
| 504 | 504 | ), |
| 505 | 505 | 'label' => array( |
| 506 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
| 506 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
| 507 | 507 | 'type' => 'string', |
| 508 | - 'context' => array( 'view', 'edit' ), |
|
| 508 | + 'context' => array('view', 'edit'), |
|
| 509 | 509 | 'readonly' => true, |
| 510 | 510 | ), |
| 511 | 511 | 'description' => array( |
| 512 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
| 512 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
| 513 | 513 | 'type' => 'string', |
| 514 | - 'context' => array( 'view', 'edit' ), |
|
| 514 | + 'context' => array('view', 'edit'), |
|
| 515 | 515 | 'readonly' => true, |
| 516 | 516 | ), |
| 517 | 517 | 'type' => array( |
| 518 | - 'description' => __( 'Type of setting.', 'woocommerce' ), |
|
| 518 | + 'description' => __('Type of setting.', 'woocommerce'), |
|
| 519 | 519 | 'type' => 'string', |
| 520 | - 'context' => array( 'view', 'edit' ), |
|
| 521 | - 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ), |
|
| 520 | + 'context' => array('view', 'edit'), |
|
| 521 | + 'enum' => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'), |
|
| 522 | 522 | 'readonly' => true, |
| 523 | 523 | ), |
| 524 | 524 | 'value' => array( |
| 525 | - 'description' => __( 'Setting value.', 'woocommerce' ), |
|
| 525 | + 'description' => __('Setting value.', 'woocommerce'), |
|
| 526 | 526 | 'type' => 'string', |
| 527 | - 'context' => array( 'view', 'edit' ), |
|
| 527 | + 'context' => array('view', 'edit'), |
|
| 528 | 528 | ), |
| 529 | 529 | 'default' => array( |
| 530 | - 'description' => __( 'Default value for the setting.', 'woocommerce' ), |
|
| 530 | + 'description' => __('Default value for the setting.', 'woocommerce'), |
|
| 531 | 531 | 'type' => 'string', |
| 532 | - 'context' => array( 'view', 'edit' ), |
|
| 532 | + 'context' => array('view', 'edit'), |
|
| 533 | 533 | 'readonly' => true, |
| 534 | 534 | ), |
| 535 | 535 | 'tip' => array( |
| 536 | - 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ), |
|
| 536 | + 'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'), |
|
| 537 | 537 | 'type' => 'string', |
| 538 | - 'context' => array( 'view', 'edit' ), |
|
| 538 | + 'context' => array('view', 'edit'), |
|
| 539 | 539 | 'readonly' => true, |
| 540 | 540 | ), |
| 541 | 541 | 'placeholder' => array( |
| 542 | - 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ), |
|
| 542 | + 'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'), |
|
| 543 | 543 | 'type' => 'string', |
| 544 | - 'context' => array( 'view', 'edit' ), |
|
| 544 | + 'context' => array('view', 'edit'), |
|
| 545 | 545 | 'readonly' => true, |
| 546 | 546 | ), |
| 547 | 547 | ), |
@@ -549,6 +549,6 @@ discard block |
||
| 549 | 549 | ), |
| 550 | 550 | ); |
| 551 | 551 | |
| 552 | - return $this->add_additional_fields_schema( $schema ); |
|
| 552 | + return $this->add_additional_fields_schema($schema); |
|
| 553 | 553 | } |
| 554 | 554 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | namespace WooCommerce\RestApi\Controllers\Version4; |
| 12 | 12 | |
| 13 | -defined( 'ABSPATH' ) || exit; |
|
| 13 | +defined('ABSPATH') || exit; |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * REST API Shipping Zones base class. |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * @param int $zone_id Shipping Zone ID. |
| 34 | 34 | * @return WC_Shipping_Zone|\WP_Error |
| 35 | 35 | */ |
| 36 | - protected function get_zone( $zone_id ) { |
|
| 37 | - $zone = \WC_Shipping_Zones::get_zone_by( 'zone_id', $zone_id ); |
|
| 36 | + protected function get_zone($zone_id) { |
|
| 37 | + $zone = \WC_Shipping_Zones::get_zone_by('zone_id', $zone_id); |
|
| 38 | 38 | |
| 39 | - if ( false === $zone ) { |
|
| 40 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 39 | + if (false === $zone) { |
|
| 40 | + return new \WP_Error('woocommerce_rest_shipping_zone_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | return $zone; |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | * @param \WP_REST_Request $request Full details about the request. |
| 50 | 50 | * @return \WP_Error|boolean |
| 51 | 51 | */ |
| 52 | - public function get_items_permissions_check( $request ) { |
|
| 53 | - if ( ! wc_shipping_enabled() ) { |
|
| 54 | - return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 52 | + public function get_items_permissions_check($request) { |
|
| 53 | + if ( ! wc_shipping_enabled()) { |
|
| 54 | + return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404)); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
| 58 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 57 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
| 58 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | return true; |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | * @param \WP_REST_Request $request Full details about the request. |
| 68 | 68 | * @return \WP_Error|boolean |
| 69 | 69 | */ |
| 70 | - public function create_item_permissions_check( $request ) { |
|
| 71 | - if ( ! wc_shipping_enabled() ) { |
|
| 72 | - return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 70 | + public function create_item_permissions_check($request) { |
|
| 71 | + if ( ! wc_shipping_enabled()) { |
|
| 72 | + return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404)); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
| 76 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 75 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
| 76 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | return true; |
@@ -85,13 +85,13 @@ discard block |
||
| 85 | 85 | * @param \WP_REST_Request $request Full details about the request. |
| 86 | 86 | * @return \WP_Error|boolean |
| 87 | 87 | */ |
| 88 | - public function update_items_permissions_check( $request ) { |
|
| 89 | - if ( ! wc_shipping_enabled() ) { |
|
| 90 | - return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 88 | + public function update_items_permissions_check($request) { |
|
| 89 | + if ( ! wc_shipping_enabled()) { |
|
| 90 | + return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404)); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
| 94 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 93 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
| 94 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | return true; |
@@ -103,13 +103,13 @@ discard block |
||
| 103 | 103 | * @param \WP_REST_Request $request Full details about the request. |
| 104 | 104 | * @return \WP_Error|boolean |
| 105 | 105 | */ |
| 106 | - public function delete_items_permissions_check( $request ) { |
|
| 107 | - if ( ! wc_shipping_enabled() ) { |
|
| 108 | - return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 106 | + public function delete_items_permissions_check($request) { |
|
| 107 | + if ( ! wc_shipping_enabled()) { |
|
| 108 | + return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404)); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) { |
|
| 112 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 111 | + if ( ! wc_rest_check_manager_permissions('settings', 'delete')) { |
|
| 112 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | return true; |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * REST API Taxes controller class. |
@@ -33,17 +33,17 @@ discard block |
||
| 33 | 33 | array( |
| 34 | 34 | array( |
| 35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
| 36 | - 'callback' => array( $this, 'get_items' ), |
|
| 37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 36 | + 'callback' => array($this, 'get_items'), |
|
| 37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
| 38 | 38 | 'args' => $this->get_collection_params(), |
| 39 | 39 | ), |
| 40 | 40 | array( |
| 41 | 41 | 'methods' => \WP_REST_Server::CREATABLE, |
| 42 | - 'callback' => array( $this, 'create_item' ), |
|
| 43 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
| 44 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
| 42 | + 'callback' => array($this, 'create_item'), |
|
| 43 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
| 44 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
| 45 | 45 | ), |
| 46 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 46 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 47 | 47 | ), |
| 48 | 48 | true |
| 49 | 49 | ); |
@@ -54,37 +54,37 @@ discard block |
||
| 54 | 54 | array( |
| 55 | 55 | 'args' => array( |
| 56 | 56 | 'id' => array( |
| 57 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 57 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 58 | 58 | 'type' => 'integer', |
| 59 | 59 | ), |
| 60 | 60 | ), |
| 61 | 61 | array( |
| 62 | 62 | 'methods' => \WP_REST_Server::READABLE, |
| 63 | - 'callback' => array( $this, 'get_item' ), |
|
| 64 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
| 63 | + 'callback' => array($this, 'get_item'), |
|
| 64 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
| 65 | 65 | 'args' => array( |
| 66 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
| 66 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
| 67 | 67 | ), |
| 68 | 68 | ), |
| 69 | 69 | array( |
| 70 | 70 | 'methods' => \WP_REST_Server::EDITABLE, |
| 71 | - 'callback' => array( $this, 'update_item' ), |
|
| 72 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
| 73 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
| 71 | + 'callback' => array($this, 'update_item'), |
|
| 72 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
| 73 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
| 74 | 74 | ), |
| 75 | 75 | array( |
| 76 | 76 | 'methods' => \WP_REST_Server::DELETABLE, |
| 77 | - 'callback' => array( $this, 'delete_item' ), |
|
| 78 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
| 77 | + 'callback' => array($this, 'delete_item'), |
|
| 78 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
| 79 | 79 | 'args' => array( |
| 80 | 80 | 'force' => array( |
| 81 | 81 | 'default' => false, |
| 82 | 82 | 'type' => 'boolean', |
| 83 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
| 83 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
| 84 | 84 | ), |
| 85 | 85 | ), |
| 86 | 86 | ), |
| 87 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 87 | + 'schema' => array($this, 'get_public_item_schema'), |
|
| 88 | 88 | ), |
| 89 | 89 | true |
| 90 | 90 | ); |
@@ -95,11 +95,11 @@ discard block |
||
| 95 | 95 | array( |
| 96 | 96 | array( |
| 97 | 97 | 'methods' => \WP_REST_Server::EDITABLE, |
| 98 | - 'callback' => array( $this, 'batch_items' ), |
|
| 99 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
| 100 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
| 98 | + 'callback' => array($this, 'batch_items'), |
|
| 99 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
| 100 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
| 101 | 101 | ), |
| 102 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
| 102 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
| 103 | 103 | ), |
| 104 | 104 | true |
| 105 | 105 | ); |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | * @param \WP_REST_Request $request Full details about the request. |
| 112 | 112 | * @return \WP_Error|boolean |
| 113 | 113 | */ |
| 114 | - public function get_items_permissions_check( $request ) { |
|
| 115 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
| 116 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 114 | + public function get_items_permissions_check($request) { |
|
| 115 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
| 116 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | return true; |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @return bool|\WP_Error |
| 128 | 128 | */ |
| 129 | - public function create_item_permissions_check( $request ) { |
|
| 130 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'create' ) ) { |
|
| 131 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 129 | + public function create_item_permissions_check($request) { |
|
| 130 | + if ( ! wc_rest_check_manager_permissions('settings', 'create')) { |
|
| 131 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | return true; |
@@ -140,9 +140,9 @@ discard block |
||
| 140 | 140 | * @param \WP_REST_Request $request Full details about the request. |
| 141 | 141 | * @return \WP_Error|boolean |
| 142 | 142 | */ |
| 143 | - public function get_item_permissions_check( $request ) { |
|
| 144 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
| 145 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 143 | + public function get_item_permissions_check($request) { |
|
| 144 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
| 145 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | return true; |
@@ -155,9 +155,9 @@ discard block |
||
| 155 | 155 | * |
| 156 | 156 | * @return bool|\WP_Error |
| 157 | 157 | */ |
| 158 | - public function update_item_permissions_check( $request ) { |
|
| 159 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
| 160 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 158 | + public function update_item_permissions_check($request) { |
|
| 159 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
| 160 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | return true; |
@@ -170,9 +170,9 @@ discard block |
||
| 170 | 170 | * |
| 171 | 171 | * @return bool|\WP_Error |
| 172 | 172 | */ |
| 173 | - public function delete_item_permissions_check( $request ) { |
|
| 174 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) { |
|
| 175 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 173 | + public function delete_item_permissions_check($request) { |
|
| 174 | + if ( ! wc_rest_check_manager_permissions('settings', 'delete')) { |
|
| 175 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | return true; |
@@ -185,9 +185,9 @@ discard block |
||
| 185 | 185 | * |
| 186 | 186 | * @return bool|\WP_Error |
| 187 | 187 | */ |
| 188 | - public function batch_items_permissions_check( $request ) { |
|
| 189 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'batch' ) ) { |
|
| 190 | - return new \WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 188 | + public function batch_items_permissions_check($request) { |
|
| 189 | + if ( ! wc_rest_check_manager_permissions('settings', 'batch')) { |
|
| 190 | + return new \WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | return true; |
@@ -199,22 +199,22 @@ discard block |
||
| 199 | 199 | * @param \WP_REST_Request $request Full details about the request. |
| 200 | 200 | * @return \WP_Error\WP_REST_Response |
| 201 | 201 | */ |
| 202 | - public function get_items( $request ) { |
|
| 202 | + public function get_items($request) { |
|
| 203 | 203 | global $wpdb; |
| 204 | 204 | |
| 205 | 205 | $prepared_args = array(); |
| 206 | 206 | $prepared_args['order'] = $request['order']; |
| 207 | 207 | $prepared_args['number'] = $request['per_page']; |
| 208 | - if ( ! empty( $request['offset'] ) ) { |
|
| 208 | + if ( ! empty($request['offset'])) { |
|
| 209 | 209 | $prepared_args['offset'] = $request['offset']; |
| 210 | 210 | } else { |
| 211 | - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; |
|
| 211 | + $prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number']; |
|
| 212 | 212 | } |
| 213 | 213 | $orderby_possibles = array( |
| 214 | 214 | 'id' => 'tax_rate_id', |
| 215 | 215 | 'order' => 'tax_rate_order', |
| 216 | 216 | ); |
| 217 | - $prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ]; |
|
| 217 | + $prepared_args['orderby'] = $orderby_possibles[$request['orderby']]; |
|
| 218 | 218 | $prepared_args['class'] = $request['class']; |
| 219 | 219 | $prepared_args['code'] = $request['code']; |
| 220 | 220 | $prepared_args['include'] = $request['include']; |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @param array $prepared_args Array of arguments for $wpdb->get_results(). |
| 226 | 226 | * @param \WP_REST_Request $request The current request. |
| 227 | 227 | */ |
| 228 | - $prepared_args = apply_filters( 'woocommerce_rest_tax_query', $prepared_args, $request ); |
|
| 228 | + $prepared_args = apply_filters('woocommerce_rest_tax_query', $prepared_args, $request); |
|
| 229 | 229 | |
| 230 | 230 | $query = " |
| 231 | 231 | SELECT * |
@@ -234,69 +234,69 @@ discard block |
||
| 234 | 234 | "; |
| 235 | 235 | |
| 236 | 236 | // Filter by tax class. |
| 237 | - if ( ! empty( $prepared_args['class'] ) ) { |
|
| 238 | - $class = 'standard' !== $prepared_args['class'] ? sanitize_title( $prepared_args['class'] ) : ''; |
|
| 237 | + if ( ! empty($prepared_args['class'])) { |
|
| 238 | + $class = 'standard' !== $prepared_args['class'] ? sanitize_title($prepared_args['class']) : ''; |
|
| 239 | 239 | $query .= " AND tax_rate_class = '$class'"; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // Filter by tax code. |
| 243 | 243 | $tax_code_search = $prepared_args['code']; |
| 244 | - if ( $tax_code_search ) { |
|
| 245 | - $tax_code_search = $wpdb->esc_like( $tax_code_search ); |
|
| 244 | + if ($tax_code_search) { |
|
| 245 | + $tax_code_search = $wpdb->esc_like($tax_code_search); |
|
| 246 | 246 | $tax_code_search = ' \'%' . $tax_code_search . '%\''; |
| 247 | 247 | $query .= ' AND CONCAT_WS( "-", NULLIF(tax_rate_country, ""), NULLIF(tax_rate_state, ""), NULLIF(tax_rate_name, ""), NULLIF(tax_rate_priority, "") ) LIKE ' . $tax_code_search; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | // Filter by included tax rate IDs. |
| 251 | 251 | $included_taxes = $prepared_args['include']; |
| 252 | - if ( ! empty( $included_taxes ) ) { |
|
| 253 | - $included_taxes = implode( ',', $prepared_args['include'] ); |
|
| 252 | + if ( ! empty($included_taxes)) { |
|
| 253 | + $included_taxes = implode(',', $prepared_args['include']); |
|
| 254 | 254 | $query .= " AND tax_rate_id IN ({$included_taxes})"; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | // Order tax rates. |
| 258 | - $order_by = sprintf( ' ORDER BY %s', sanitize_key( $prepared_args['orderby'] ) ); |
|
| 258 | + $order_by = sprintf(' ORDER BY %s', sanitize_key($prepared_args['orderby'])); |
|
| 259 | 259 | |
| 260 | 260 | // Pagination. |
| 261 | - $pagination = sprintf( ' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number'] ); |
|
| 261 | + $pagination = sprintf(' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number']); |
|
| 262 | 262 | |
| 263 | 263 | // Query taxes. |
| 264 | - $results = $wpdb->get_results( $query . $order_by . $pagination ); // @codingStandardsIgnoreLine. |
|
| 264 | + $results = $wpdb->get_results($query . $order_by . $pagination); // @codingStandardsIgnoreLine. |
|
| 265 | 265 | |
| 266 | 266 | $taxes = array(); |
| 267 | - foreach ( $results as $tax ) { |
|
| 268 | - $data = $this->prepare_item_for_response( $tax, $request ); |
|
| 269 | - $taxes[] = $this->prepare_response_for_collection( $data ); |
|
| 267 | + foreach ($results as $tax) { |
|
| 268 | + $data = $this->prepare_item_for_response($tax, $request); |
|
| 269 | + $taxes[] = $this->prepare_response_for_collection($data); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - $response = rest_ensure_response( $taxes ); |
|
| 272 | + $response = rest_ensure_response($taxes); |
|
| 273 | 273 | |
| 274 | 274 | // Store pagination values for headers then unset for count query. |
| 275 | 275 | $per_page = (int) $prepared_args['number']; |
| 276 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
| 276 | + $page = ceil((((int) $prepared_args['offset']) / $per_page) + 1); |
|
| 277 | 277 | |
| 278 | 278 | // Query only for ids. |
| 279 | - $wpdb->get_results( str_replace( 'SELECT *', 'SELECT tax_rate_id', $query ) ); // @codingStandardsIgnoreLine. |
|
| 279 | + $wpdb->get_results(str_replace('SELECT *', 'SELECT tax_rate_id', $query)); // @codingStandardsIgnoreLine. |
|
| 280 | 280 | |
| 281 | 281 | // Calculate totals. |
| 282 | 282 | $total_taxes = (int) $wpdb->num_rows; |
| 283 | - $response->header( 'X-WP-Total', (int) $total_taxes ); |
|
| 284 | - $max_pages = ceil( $total_taxes / $per_page ); |
|
| 285 | - $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
| 283 | + $response->header('X-WP-Total', (int) $total_taxes); |
|
| 284 | + $max_pages = ceil($total_taxes / $per_page); |
|
| 285 | + $response->header('X-WP-TotalPages', (int) $max_pages); |
|
| 286 | 286 | |
| 287 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
| 288 | - if ( $page > 1 ) { |
|
| 287 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
| 288 | + if ($page > 1) { |
|
| 289 | 289 | $prev_page = $page - 1; |
| 290 | - if ( $prev_page > $max_pages ) { |
|
| 290 | + if ($prev_page > $max_pages) { |
|
| 291 | 291 | $prev_page = $max_pages; |
| 292 | 292 | } |
| 293 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
| 294 | - $response->link_header( 'prev', $prev_link ); |
|
| 293 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
| 294 | + $response->link_header('prev', $prev_link); |
|
| 295 | 295 | } |
| 296 | - if ( $max_pages > $page ) { |
|
| 296 | + if ($max_pages > $page) { |
|
| 297 | 297 | $next_page = $page + 1; |
| 298 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
| 299 | - $response->link_header( 'next', $next_link ); |
|
| 298 | + $next_link = add_query_arg('page', $next_page, $base); |
|
| 299 | + $response->link_header('next', $next_link); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | return $response; |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | * @param stdClass|null $current Existing tax object. |
| 310 | 310 | * @return object |
| 311 | 311 | */ |
| 312 | - protected function create_or_update_tax( $request, $current = null ) { |
|
| 313 | - $id = absint( isset( $request['id'] ) ? $request['id'] : 0 ); |
|
| 312 | + protected function create_or_update_tax($request, $current = null) { |
|
| 313 | + $id = absint(isset($request['id']) ? $request['id'] : 0); |
|
| 314 | 314 | $data = array(); |
| 315 | 315 | $fields = array( |
| 316 | 316 | 'tax_rate_country', |
@@ -324,52 +324,52 @@ discard block |
||
| 324 | 324 | 'tax_rate_class', |
| 325 | 325 | ); |
| 326 | 326 | |
| 327 | - foreach ( $fields as $field ) { |
|
| 327 | + foreach ($fields as $field) { |
|
| 328 | 328 | // Keys via API differ from the stored names returned by _get_tax_rate. |
| 329 | - $key = 'tax_rate' === $field ? 'rate' : str_replace( 'tax_rate_', '', $field ); |
|
| 329 | + $key = 'tax_rate' === $field ? 'rate' : str_replace('tax_rate_', '', $field); |
|
| 330 | 330 | |
| 331 | 331 | // Remove data that was not posted. |
| 332 | - if ( ! isset( $request[ $key ] ) ) { |
|
| 332 | + if ( ! isset($request[$key])) { |
|
| 333 | 333 | continue; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | // Test new data against current data. |
| 337 | - if ( $current && $current->$field === $request[ $key ] ) { |
|
| 337 | + if ($current && $current->$field === $request[$key]) { |
|
| 338 | 338 | continue; |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | // Add to data array. |
| 342 | - switch ( $key ) { |
|
| 342 | + switch ($key) { |
|
| 343 | 343 | case 'tax_rate_priority': |
| 344 | 344 | case 'tax_rate_compound': |
| 345 | 345 | case 'tax_rate_shipping': |
| 346 | 346 | case 'tax_rate_order': |
| 347 | - $data[ $field ] = absint( $request[ $key ] ); |
|
| 347 | + $data[$field] = absint($request[$key]); |
|
| 348 | 348 | break; |
| 349 | 349 | case 'tax_rate_class': |
| 350 | - $data[ $field ] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : ''; |
|
| 350 | + $data[$field] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : ''; |
|
| 351 | 351 | break; |
| 352 | 352 | default: |
| 353 | - $data[ $field ] = wc_clean( $request[ $key ] ); |
|
| 353 | + $data[$field] = wc_clean($request[$key]); |
|
| 354 | 354 | break; |
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - if ( $id ) { |
|
| 359 | - \WC_Tax::_update_tax_rate( $id, $data ); |
|
| 358 | + if ($id) { |
|
| 359 | + \WC_Tax::_update_tax_rate($id, $data); |
|
| 360 | 360 | } else { |
| 361 | - $id = \WC_Tax::_insert_tax_rate( $data ); |
|
| 361 | + $id = \WC_Tax::_insert_tax_rate($data); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | // Add locales. |
| 365 | - if ( ! empty( $request['postcode'] ) ) { |
|
| 366 | - \WC_Tax::_update_tax_rate_postcodes( $id, wc_clean( $request['postcode'] ) ); |
|
| 365 | + if ( ! empty($request['postcode'])) { |
|
| 366 | + \WC_Tax::_update_tax_rate_postcodes($id, wc_clean($request['postcode'])); |
|
| 367 | 367 | } |
| 368 | - if ( ! empty( $request['city'] ) ) { |
|
| 369 | - \WC_Tax::_update_tax_rate_cities( $id, wc_clean( $request['city'] ) ); |
|
| 368 | + if ( ! empty($request['city'])) { |
|
| 369 | + \WC_Tax::_update_tax_rate_cities($id, wc_clean($request['city'])); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - return \WC_Tax::_get_tax_rate( $id, OBJECT ); |
|
| 372 | + return \WC_Tax::_get_tax_rate($id, OBJECT); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -378,14 +378,14 @@ discard block |
||
| 378 | 378 | * @param \WP_REST_Request $request Full details about the request. |
| 379 | 379 | * @return \WP_Error\WP_REST_Response |
| 380 | 380 | */ |
| 381 | - public function create_item( $request ) { |
|
| 382 | - if ( ! empty( $request['id'] ) ) { |
|
| 383 | - return new \WP_Error( 'woocommerce_rest_tax_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 381 | + public function create_item($request) { |
|
| 382 | + if ( ! empty($request['id'])) { |
|
| 383 | + return new \WP_Error('woocommerce_rest_tax_exists', __('Cannot create existing resource.', 'woocommerce'), array('status' => 400)); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - $tax = $this->create_or_update_tax( $request ); |
|
| 386 | + $tax = $this->create_or_update_tax($request); |
|
| 387 | 387 | |
| 388 | - $this->update_additional_fields_for_object( $tax, $request ); |
|
| 388 | + $this->update_additional_fields_for_object($tax, $request); |
|
| 389 | 389 | |
| 390 | 390 | /** |
| 391 | 391 | * Fires after a tax is created or updated via the REST API. |
@@ -394,13 +394,13 @@ discard block |
||
| 394 | 394 | * @param \WP_REST_Request $request Request object. |
| 395 | 395 | * @param boolean $creating True when creating tax, false when updating tax. |
| 396 | 396 | */ |
| 397 | - do_action( 'woocommerce_rest_insert_tax', $tax, $request, true ); |
|
| 397 | + do_action('woocommerce_rest_insert_tax', $tax, $request, true); |
|
| 398 | 398 | |
| 399 | - $request->set_param( 'context', 'edit' ); |
|
| 400 | - $response = $this->prepare_item_for_response( $tax, $request ); |
|
| 401 | - $response = rest_ensure_response( $response ); |
|
| 402 | - $response->set_status( 201 ); |
|
| 403 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id ) ) ); |
|
| 399 | + $request->set_param('context', 'edit'); |
|
| 400 | + $response = $this->prepare_item_for_response($tax, $request); |
|
| 401 | + $response = rest_ensure_response($response); |
|
| 402 | + $response->set_status(201); |
|
| 403 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id))); |
|
| 404 | 404 | |
| 405 | 405 | return $response; |
| 406 | 406 | } |
@@ -411,16 +411,16 @@ discard block |
||
| 411 | 411 | * @param \WP_REST_Request $request Full details about the request. |
| 412 | 412 | * @return \WP_Error\WP_REST_Response |
| 413 | 413 | */ |
| 414 | - public function get_item( $request ) { |
|
| 414 | + public function get_item($request) { |
|
| 415 | 415 | $id = (int) $request['id']; |
| 416 | - $tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT ); |
|
| 416 | + $tax_obj = \WC_Tax::_get_tax_rate($id, OBJECT); |
|
| 417 | 417 | |
| 418 | - if ( empty( $id ) || empty( $tax_obj ) ) { |
|
| 419 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 418 | + if (empty($id) || empty($tax_obj)) { |
|
| 419 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - $tax = $this->prepare_item_for_response( $tax_obj, $request ); |
|
| 423 | - $response = rest_ensure_response( $tax ); |
|
| 422 | + $tax = $this->prepare_item_for_response($tax_obj, $request); |
|
| 423 | + $response = rest_ensure_response($tax); |
|
| 424 | 424 | |
| 425 | 425 | return $response; |
| 426 | 426 | } |
@@ -431,17 +431,17 @@ discard block |
||
| 431 | 431 | * @param \WP_REST_Request $request Full details about the request. |
| 432 | 432 | * @return \WP_Error\WP_REST_Response |
| 433 | 433 | */ |
| 434 | - public function update_item( $request ) { |
|
| 434 | + public function update_item($request) { |
|
| 435 | 435 | $id = (int) $request['id']; |
| 436 | - $tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT ); |
|
| 436 | + $tax_obj = \WC_Tax::_get_tax_rate($id, OBJECT); |
|
| 437 | 437 | |
| 438 | - if ( empty( $id ) || empty( $tax_obj ) ) { |
|
| 439 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 438 | + if (empty($id) || empty($tax_obj)) { |
|
| 439 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | - $tax = $this->create_or_update_tax( $request, $tax_obj ); |
|
| 442 | + $tax = $this->create_or_update_tax($request, $tax_obj); |
|
| 443 | 443 | |
| 444 | - $this->update_additional_fields_for_object( $tax, $request ); |
|
| 444 | + $this->update_additional_fields_for_object($tax, $request); |
|
| 445 | 445 | |
| 446 | 446 | /** |
| 447 | 447 | * Fires after a tax is created or updated via the REST API. |
@@ -450,11 +450,11 @@ discard block |
||
| 450 | 450 | * @param \WP_REST_Request $request Request object. |
| 451 | 451 | * @param boolean $creating True when creating tax, false when updating tax. |
| 452 | 452 | */ |
| 453 | - do_action( 'woocommerce_rest_insert_tax', $tax, $request, false ); |
|
| 453 | + do_action('woocommerce_rest_insert_tax', $tax, $request, false); |
|
| 454 | 454 | |
| 455 | - $request->set_param( 'context', 'edit' ); |
|
| 456 | - $response = $this->prepare_item_for_response( $tax, $request ); |
|
| 457 | - $response = rest_ensure_response( $response ); |
|
| 455 | + $request->set_param('context', 'edit'); |
|
| 456 | + $response = $this->prepare_item_for_response($tax, $request); |
|
| 457 | + $response = rest_ensure_response($response); |
|
| 458 | 458 | |
| 459 | 459 | return $response; |
| 460 | 460 | } |
@@ -465,30 +465,30 @@ discard block |
||
| 465 | 465 | * @param \WP_REST_Request $request Full details about the request. |
| 466 | 466 | * @return \WP_Error\WP_REST_Response |
| 467 | 467 | */ |
| 468 | - public function delete_item( $request ) { |
|
| 468 | + public function delete_item($request) { |
|
| 469 | 469 | global $wpdb; |
| 470 | 470 | |
| 471 | 471 | $id = (int) $request['id']; |
| 472 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
| 472 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
| 473 | 473 | |
| 474 | 474 | // We don't support trashing for this type, error out. |
| 475 | - if ( ! $force ) { |
|
| 476 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Taxes do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
| 475 | + if ( ! $force) { |
|
| 476 | + return new \WP_Error('woocommerce_rest_trash_not_supported', __('Taxes do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | - $tax = \WC_Tax::_get_tax_rate( $id, OBJECT ); |
|
| 479 | + $tax = \WC_Tax::_get_tax_rate($id, OBJECT); |
|
| 480 | 480 | |
| 481 | - if ( empty( $id ) || empty( $tax ) ) { |
|
| 482 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
| 481 | + if (empty($id) || empty($tax)) { |
|
| 482 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 400)); |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | - $request->set_param( 'context', 'edit' ); |
|
| 486 | - $response = $this->prepare_item_for_response( $tax, $request ); |
|
| 485 | + $request->set_param('context', 'edit'); |
|
| 486 | + $response = $this->prepare_item_for_response($tax, $request); |
|
| 487 | 487 | |
| 488 | - \WC_Tax::_delete_tax_rate( $id ); |
|
| 488 | + \WC_Tax::_delete_tax_rate($id); |
|
| 489 | 489 | |
| 490 | - if ( 0 === $wpdb->rows_affected ) { |
|
| 491 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 490 | + if (0 === $wpdb->rows_affected) { |
|
| 491 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | /** |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | * @param \WP_REST_Response $response The response returned from the API. |
| 499 | 499 | * @param \WP_REST_Request $request The request sent to the API. |
| 500 | 500 | */ |
| 501 | - do_action( 'woocommerce_rest_delete_tax', $tax, $response, $request ); |
|
| 501 | + do_action('woocommerce_rest_delete_tax', $tax, $response, $request); |
|
| 502 | 502 | |
| 503 | 503 | return $response; |
| 504 | 504 | } |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | * @param \WP_REST_Request $request Request object. |
| 511 | 511 | * @return \WP_REST_Response $response Response data. |
| 512 | 512 | */ |
| 513 | - public function prepare_item_for_response( $tax, $request ) { |
|
| 513 | + public function prepare_item_for_response($tax, $request) { |
|
| 514 | 514 | global $wpdb; |
| 515 | 515 | |
| 516 | 516 | $id = (int) $tax->tax_rate_id; |
@@ -541,20 +541,20 @@ discard block |
||
| 541 | 541 | ) |
| 542 | 542 | ); |
| 543 | 543 | |
| 544 | - if ( ! is_wp_error( $tax ) && ! is_null( $tax ) ) { |
|
| 545 | - foreach ( $locales as $locale ) { |
|
| 546 | - $data[ $locale->location_type ] = $locale->location_code; |
|
| 544 | + if ( ! is_wp_error($tax) && ! is_null($tax)) { |
|
| 545 | + foreach ($locales as $locale) { |
|
| 546 | + $data[$locale->location_type] = $locale->location_code; |
|
| 547 | 547 | } |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 551 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 552 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 550 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
| 551 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 552 | + $data = $this->filter_response_by_context($data, $context); |
|
| 553 | 553 | |
| 554 | 554 | // Wrap the data in a response object. |
| 555 | - $response = rest_ensure_response( $data ); |
|
| 555 | + $response = rest_ensure_response($data); |
|
| 556 | 556 | |
| 557 | - $response->add_links( $this->prepare_links( $tax ) ); |
|
| 557 | + $response->add_links($this->prepare_links($tax)); |
|
| 558 | 558 | |
| 559 | 559 | /** |
| 560 | 560 | * Filter tax object returned from the REST API. |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | * @param stdClass $tax Tax object used to create response. |
| 564 | 564 | * @param \WP_REST_Request $request Request object. |
| 565 | 565 | */ |
| 566 | - return apply_filters( 'woocommerce_rest_prepare_tax', $response, $tax, $request ); |
|
| 566 | + return apply_filters('woocommerce_rest_prepare_tax', $response, $tax, $request); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | /** |
@@ -572,13 +572,13 @@ discard block |
||
| 572 | 572 | * @param stdClass $tax Tax object. |
| 573 | 573 | * @return array Links for the given tax. |
| 574 | 574 | */ |
| 575 | - protected function prepare_links( $tax ) { |
|
| 575 | + protected function prepare_links($tax) { |
|
| 576 | 576 | $links = array( |
| 577 | 577 | 'self' => array( |
| 578 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id ) ), |
|
| 578 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id)), |
|
| 579 | 579 | ), |
| 580 | 580 | 'collection' => array( |
| 581 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
| 581 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
| 582 | 582 | ), |
| 583 | 583 | ); |
| 584 | 584 | |
@@ -597,75 +597,75 @@ discard block |
||
| 597 | 597 | 'type' => 'object', |
| 598 | 598 | 'properties' => array( |
| 599 | 599 | 'id' => array( |
| 600 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
| 600 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
| 601 | 601 | 'type' => 'integer', |
| 602 | - 'context' => array( 'view', 'edit' ), |
|
| 602 | + 'context' => array('view', 'edit'), |
|
| 603 | 603 | 'readonly' => true, |
| 604 | 604 | ), |
| 605 | 605 | 'country' => array( |
| 606 | - 'description' => __( 'Country ISO 3166 code.', 'woocommerce' ), |
|
| 606 | + 'description' => __('Country ISO 3166 code.', 'woocommerce'), |
|
| 607 | 607 | 'type' => 'string', |
| 608 | - 'context' => array( 'view', 'edit' ), |
|
| 608 | + 'context' => array('view', 'edit'), |
|
| 609 | 609 | ), |
| 610 | 610 | 'state' => array( |
| 611 | - 'description' => __( 'State code.', 'woocommerce' ), |
|
| 611 | + 'description' => __('State code.', 'woocommerce'), |
|
| 612 | 612 | 'type' => 'string', |
| 613 | - 'context' => array( 'view', 'edit' ), |
|
| 613 | + 'context' => array('view', 'edit'), |
|
| 614 | 614 | ), |
| 615 | 615 | 'postcode' => array( |
| 616 | - 'description' => __( 'Postcode / ZIP.', 'woocommerce' ), |
|
| 616 | + 'description' => __('Postcode / ZIP.', 'woocommerce'), |
|
| 617 | 617 | 'type' => 'string', |
| 618 | - 'context' => array( 'view', 'edit' ), |
|
| 618 | + 'context' => array('view', 'edit'), |
|
| 619 | 619 | ), |
| 620 | 620 | 'city' => array( |
| 621 | - 'description' => __( 'City name.', 'woocommerce' ), |
|
| 621 | + 'description' => __('City name.', 'woocommerce'), |
|
| 622 | 622 | 'type' => 'string', |
| 623 | - 'context' => array( 'view', 'edit' ), |
|
| 623 | + 'context' => array('view', 'edit'), |
|
| 624 | 624 | ), |
| 625 | 625 | 'rate' => array( |
| 626 | - 'description' => __( 'Tax rate.', 'woocommerce' ), |
|
| 626 | + 'description' => __('Tax rate.', 'woocommerce'), |
|
| 627 | 627 | 'type' => 'string', |
| 628 | - 'context' => array( 'view', 'edit' ), |
|
| 628 | + 'context' => array('view', 'edit'), |
|
| 629 | 629 | ), |
| 630 | 630 | 'name' => array( |
| 631 | - 'description' => __( 'Tax rate name.', 'woocommerce' ), |
|
| 631 | + 'description' => __('Tax rate name.', 'woocommerce'), |
|
| 632 | 632 | 'type' => 'string', |
| 633 | - 'context' => array( 'view', 'edit' ), |
|
| 633 | + 'context' => array('view', 'edit'), |
|
| 634 | 634 | ), |
| 635 | 635 | 'priority' => array( |
| 636 | - 'description' => __( 'Tax priority.', 'woocommerce' ), |
|
| 636 | + 'description' => __('Tax priority.', 'woocommerce'), |
|
| 637 | 637 | 'type' => 'integer', |
| 638 | 638 | 'default' => 1, |
| 639 | - 'context' => array( 'view', 'edit' ), |
|
| 639 | + 'context' => array('view', 'edit'), |
|
| 640 | 640 | ), |
| 641 | 641 | 'compound' => array( |
| 642 | - 'description' => __( 'Whether or not this is a compound rate.', 'woocommerce' ), |
|
| 642 | + 'description' => __('Whether or not this is a compound rate.', 'woocommerce'), |
|
| 643 | 643 | 'type' => 'boolean', |
| 644 | 644 | 'default' => false, |
| 645 | - 'context' => array( 'view', 'edit' ), |
|
| 645 | + 'context' => array('view', 'edit'), |
|
| 646 | 646 | ), |
| 647 | 647 | 'shipping' => array( |
| 648 | - 'description' => __( 'Whether or not this tax rate also gets applied to shipping.', 'woocommerce' ), |
|
| 648 | + 'description' => __('Whether or not this tax rate also gets applied to shipping.', 'woocommerce'), |
|
| 649 | 649 | 'type' => 'boolean', |
| 650 | 650 | 'default' => true, |
| 651 | - 'context' => array( 'view', 'edit' ), |
|
| 651 | + 'context' => array('view', 'edit'), |
|
| 652 | 652 | ), |
| 653 | 653 | 'order' => array( |
| 654 | - 'description' => __( 'Indicates the order that will appear in queries.', 'woocommerce' ), |
|
| 654 | + 'description' => __('Indicates the order that will appear in queries.', 'woocommerce'), |
|
| 655 | 655 | 'type' => 'integer', |
| 656 | - 'context' => array( 'view', 'edit' ), |
|
| 656 | + 'context' => array('view', 'edit'), |
|
| 657 | 657 | ), |
| 658 | 658 | 'class' => array( |
| 659 | - 'description' => __( 'Tax class.', 'woocommerce' ), |
|
| 659 | + 'description' => __('Tax class.', 'woocommerce'), |
|
| 660 | 660 | 'type' => 'string', |
| 661 | 661 | 'default' => 'standard', |
| 662 | - 'enum' => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ), |
|
| 663 | - 'context' => array( 'view', 'edit' ), |
|
| 662 | + 'enum' => array_merge(array('standard'), \WC_Tax::get_tax_class_slugs()), |
|
| 663 | + 'context' => array('view', 'edit'), |
|
| 664 | 664 | ), |
| 665 | 665 | ), |
| 666 | 666 | ); |
| 667 | 667 | |
| 668 | - return $this->add_additional_fields_schema( $schema ); |
|
| 668 | + return $this->add_additional_fields_schema($schema); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | $params['context']['default'] = 'view'; |
| 680 | 680 | |
| 681 | 681 | $params['page'] = array( |
| 682 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
| 682 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
| 683 | 683 | 'type' => 'integer', |
| 684 | 684 | 'default' => 1, |
| 685 | 685 | 'sanitize_callback' => 'absint', |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | 'minimum' => 1, |
| 688 | 688 | ); |
| 689 | 689 | $params['per_page'] = array( |
| 690 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
| 690 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
| 691 | 691 | 'type' => 'integer', |
| 692 | 692 | 'default' => 10, |
| 693 | 693 | 'minimum' => 1, |
@@ -696,22 +696,22 @@ discard block |
||
| 696 | 696 | 'validate_callback' => 'rest_validate_request_arg', |
| 697 | 697 | ); |
| 698 | 698 | $params['offset'] = array( |
| 699 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
| 699 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
| 700 | 700 | 'type' => 'integer', |
| 701 | 701 | 'sanitize_callback' => 'absint', |
| 702 | 702 | 'validate_callback' => 'rest_validate_request_arg', |
| 703 | 703 | ); |
| 704 | 704 | $params['order'] = array( |
| 705 | 705 | 'default' => 'asc', |
| 706 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
| 707 | - 'enum' => array( 'asc', 'desc' ), |
|
| 706 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
| 707 | + 'enum' => array('asc', 'desc'), |
|
| 708 | 708 | 'sanitize_callback' => 'sanitize_key', |
| 709 | 709 | 'type' => 'string', |
| 710 | 710 | 'validate_callback' => 'rest_validate_request_arg', |
| 711 | 711 | ); |
| 712 | 712 | $params['orderby'] = array( |
| 713 | 713 | 'default' => 'order', |
| 714 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
| 714 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
| 715 | 715 | 'enum' => array( |
| 716 | 716 | 'id', |
| 717 | 717 | 'order', |
@@ -721,19 +721,19 @@ discard block |
||
| 721 | 721 | 'validate_callback' => 'rest_validate_request_arg', |
| 722 | 722 | ); |
| 723 | 723 | $params['class'] = array( |
| 724 | - 'description' => __( 'Sort by tax class.', 'woocommerce' ), |
|
| 725 | - 'enum' => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ), |
|
| 724 | + 'description' => __('Sort by tax class.', 'woocommerce'), |
|
| 725 | + 'enum' => array_merge(array('standard'), \WC_Tax::get_tax_class_slugs()), |
|
| 726 | 726 | 'sanitize_callback' => 'sanitize_title', |
| 727 | 727 | 'type' => 'string', |
| 728 | 728 | 'validate_callback' => 'rest_validate_request_arg', |
| 729 | 729 | ); |
| 730 | - $params['code'] = array( |
|
| 731 | - 'description' => __( 'Search by similar tax code.', 'woocommerce' ), |
|
| 730 | + $params['code'] = array( |
|
| 731 | + 'description' => __('Search by similar tax code.', 'woocommerce'), |
|
| 732 | 732 | 'type' => 'string', |
| 733 | 733 | 'validate_callback' => 'rest_validate_request_arg', |
| 734 | 734 | ); |
| 735 | 735 | $params['include'] = array( |
| 736 | - 'description' => __( 'Limit result set to items that have the specified rate ID(s) assigned.', 'woocommerce' ), |
|
| 736 | + 'description' => __('Limit result set to items that have the specified rate ID(s) assigned.', 'woocommerce'), |
|
| 737 | 737 | 'type' => 'array', |
| 738 | 738 | 'items' => array( |
| 739 | 739 | 'type' => 'integer', |