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