diff --git a/src/Controllers/Version2/class-wc-rest-coupons-v2-controller.php b/src/Controllers/Version2/class-wc-rest-coupons-v2-controller.php index 7dbcaa1..e8ab107 100644 --- a/src/Controllers/Version2/class-wc-rest-coupons-v2-controller.php +++ b/src/Controllers/Version2/class-wc-rest-coupons-v2-controller.php @@ -511,7 +511,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), diff --git a/src/Controllers/Version2/class-wc-rest-customers-v2-controller.php b/src/Controllers/Version2/class-wc-rest-customers-v2-controller.php index 29d4e07..22fb257 100644 --- a/src/Controllers/Version2/class-wc-rest-customers-v2-controller.php +++ b/src/Controllers/Version2/class-wc-rest-customers-v2-controller.php @@ -350,7 +350,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), diff --git a/src/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php b/src/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php index dff06e2..c0b30dc 100644 --- a/src/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php +++ b/src/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php @@ -410,7 +410,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), @@ -432,13 +432,13 @@ public function get_item_schema() { ), 'name' => array( 'description' => __( 'Product name.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'product_id' => array( 'description' => __( 'Product ID.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'integer', 'null' ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ), @@ -535,7 +535,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ), diff --git a/src/Controllers/Version2/class-wc-rest-orders-v2-controller.php b/src/Controllers/Version2/class-wc-rest-orders-v2-controller.php index a9422ae..2744e42 100644 --- a/src/Controllers/Version2/class-wc-rest-orders-v2-controller.php +++ b/src/Controllers/Version2/class-wc-rest-orders-v2-controller.php @@ -1170,7 +1170,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), @@ -1191,12 +1191,12 @@ public function get_item_schema() { ), 'name' => array( 'description' => __( 'Product name.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), 'product_id' => array( 'description' => __( 'Product ID.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'integer' ), 'context' => array( 'view', 'edit' ), ), 'variation_id' => array( @@ -1282,7 +1282,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), @@ -1373,7 +1373,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), @@ -1397,12 +1397,12 @@ public function get_item_schema() { ), 'method_title' => array( 'description' => __( 'Shipping method name.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), 'method_id' => array( 'description' => __( 'Shipping method ID.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), 'instance_id' => array( @@ -1464,7 +1464,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), @@ -1488,7 +1488,7 @@ public function get_item_schema() { ), 'name' => array( 'description' => __( 'Fee name.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), 'tax_class' => array( @@ -1562,7 +1562,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), @@ -1586,7 +1586,7 @@ public function get_item_schema() { ), 'code' => array( 'description' => __( 'Coupon code.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), 'discount' => array( @@ -1620,7 +1620,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), diff --git a/src/Controllers/Version2/class-wc-rest-product-variations-v2-controller.php b/src/Controllers/Version2/class-wc-rest-product-variations-v2-controller.php index 392098a..4941870 100644 --- a/src/Controllers/Version2/class-wc-rest-product-variations-v2-controller.php +++ b/src/Controllers/Version2/class-wc-rest-product-variations-v2-controller.php @@ -799,7 +799,7 @@ public function get_item_schema() { ), 'manage_stock' => array( 'description' => __( 'Stock management at variation level.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'boolean', 'null' ), 'default' => false, 'context' => array( 'view', 'edit' ), ), @@ -982,7 +982,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), diff --git a/src/Controllers/Version2/class-wc-rest-products-v2-controller.php b/src/Controllers/Version2/class-wc-rest-products-v2-controller.php index f38ecb7..8155463 100644 --- a/src/Controllers/Version2/class-wc-rest-products-v2-controller.php +++ b/src/Controllers/Version2/class-wc-rest-products-v2-controller.php @@ -2084,7 +2084,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), diff --git a/src/Controllers/Version2/class-wc-rest-setting-options-v2-controller.php b/src/Controllers/Version2/class-wc-rest-setting-options-v2-controller.php index 7c8a72a..e23aa3a 100644 --- a/src/Controllers/Version2/class-wc-rest-setting-options-v2-controller.php +++ b/src/Controllers/Version2/class-wc-rest-setting-options-v2-controller.php @@ -530,12 +530,18 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Setting value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'array', 'null' ), + 'items' => array( + 'type' => array( 'string', 'null' ), + ), 'context' => array( 'view', 'edit' ), ), 'default' => array( 'description' => __( 'Default value for the setting.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'array', 'null' ), + 'items' => array( + 'type' => array( 'string', 'null' ), + ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ), diff --git a/src/Controllers/Version3/class-wc-rest-controller.php b/src/Controllers/Version3/class-wc-rest-controller.php index 5ee0bc4..d851be5 100644 --- a/src/Controllers/Version3/class-wc-rest-controller.php +++ b/src/Controllers/Version3/class-wc-rest-controller.php @@ -77,6 +77,35 @@ protected function add_additional_fields_schema( $schema ) { return $schema; } + /** + * Compatibility functions for WP 5.5, since custom types are not supported anymore. + * See @link https://core.trac.wordpress.org/changeset/48306 + * + * @param string $method Optional. HTTP method of the request. + * + * @return array Endpoint arguments. + */ + public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) { + + $endpoint_args = parent::get_endpoint_args_for_item_schema( $method ); + + if ( false === strpos( WP_REST_Server::EDITABLE, $method ) ) { + return $endpoint_args; + } + + foreach ( $endpoint_args as $field_id => $params ) { + /** + * Custom types are not supported as of WP 5.5, this translates type => 'date-time' to type => 'string' with format date-time. + */ + if ( 'date-time' === $params['type'] ) { + $endpoint_args[ $field_id ]['type'] = 'string'; + $endpoint_args[ $field_id ]['format'] = 'date-time'; + } + } + + return $endpoint_args; + } + /** * Get normalized rest base. * diff --git a/src/Controllers/Version3/class-wc-rest-crud-controller.php b/src/Controllers/Version3/class-wc-rest-crud-controller.php index c12186e..7aaa3af 100644 --- a/src/Controllers/Version3/class-wc-rest-crud-controller.php +++ b/src/Controllers/Version3/class-wc-rest-crud-controller.php @@ -91,6 +91,8 @@ public function delete_item_permissions_check( $request ) { return true; } + + /** * Get object permalink. * diff --git a/src/Controllers/Version3/class-wc-rest-customers-controller.php b/src/Controllers/Version3/class-wc-rest-customers-controller.php index 65ce592..072fb08 100644 --- a/src/Controllers/Version3/class-wc-rest-customers-controller.php +++ b/src/Controllers/Version3/class-wc-rest-customers-controller.php @@ -293,7 +293,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), diff --git a/src/Controllers/Version3/class-wc-rest-product-variations-controller.php b/src/Controllers/Version3/class-wc-rest-product-variations-controller.php index 0477e81..6c71016 100644 --- a/src/Controllers/Version3/class-wc-rest-product-variations-controller.php +++ b/src/Controllers/Version3/class-wc-rest-product-variations-controller.php @@ -736,7 +736,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), diff --git a/src/Controllers/Version3/class-wc-rest-products-controller.php b/src/Controllers/Version3/class-wc-rest-products-controller.php index a6401bf..6f3d3a0 100644 --- a/src/Controllers/Version3/class-wc-rest-products-controller.php +++ b/src/Controllers/Version3/class-wc-rest-products-controller.php @@ -1288,7 +1288,7 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Meta value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), ), ), diff --git a/src/Controllers/Version3/class-wc-rest-setting-options-controller.php b/src/Controllers/Version3/class-wc-rest-setting-options-controller.php index b725569..59d3828 100644 --- a/src/Controllers/Version3/class-wc-rest-setting-options-controller.php +++ b/src/Controllers/Version3/class-wc-rest-setting-options-controller.php @@ -199,12 +199,18 @@ public function get_item_schema() { ), 'value' => array( 'description' => __( 'Setting value.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'array', 'null' ), + 'items' => array( + 'type' => array( 'string', 'null' ), + ), 'context' => array( 'view', 'edit' ), ), 'default' => array( 'description' => __( 'Default value for the setting.', 'woocommerce-rest-api' ), - 'type' => 'mixed', + 'type' => array( 'string', 'array', 'null' ), + 'items' => array( + 'type' => array( 'string', 'null' ), + ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ),