Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 7a46674

Browse files
authored
Merge pull request #239 from woocommerce/fix/4.3.2/27282
[WC 4.3] Port over fixes from Core for API BW
2 parents 3da3790 + 8c8b802 commit 7a46674

22 files changed

+249
-58
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "woocommerce-rest-api",
33
"title": "WooCommerce REST API",
4-
"version": "1.0.10",
4+
"version": "1.0.10-pl-2",
55
"homepage": "https://woocommerce.com/",
66
"repository": {
77
"type": "git",

src/Controllers/Version2/class-wc-rest-coupons-v2-controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ public function get_item_schema() {
511511
),
512512
'value' => array(
513513
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
514-
'type' => array( 'string', 'null' ),
514+
'type' => 'mixed',
515515
'context' => array( 'view', 'edit' ),
516516
),
517517
),

src/Controllers/Version2/class-wc-rest-customers-v2-controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public function get_item_schema() {
350350
),
351351
'value' => array(
352352
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
353-
'type' => array( 'string', 'null' ),
353+
'type' => 'mixed',
354354
'context' => array( 'view', 'edit' ),
355355
),
356356
),

src/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public function get_item_schema() {
410410
),
411411
'value' => array(
412412
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
413-
'type' => array( 'string', 'null' ),
413+
'type' => 'mixed',
414414
'context' => array( 'view', 'edit' ),
415415
),
416416
),
@@ -432,13 +432,13 @@ public function get_item_schema() {
432432
),
433433
'name' => array(
434434
'description' => __( 'Product name.', 'woocommerce-rest-api' ),
435-
'type' => array( 'string', 'null' ),
435+
'type' => 'mixed',
436436
'context' => array( 'view', 'edit' ),
437437
'readonly' => true,
438438
),
439439
'product_id' => array(
440440
'description' => __( 'Product ID.', 'woocommerce-rest-api' ),
441-
'type' => array( 'integer', 'null' ),
441+
'type' => 'mixed',
442442
'context' => array( 'view', 'edit' ),
443443
'readonly' => true,
444444
),
@@ -535,7 +535,7 @@ public function get_item_schema() {
535535
),
536536
'value' => array(
537537
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
538-
'type' => array( 'string', 'null' ),
538+
'type' => 'mixed',
539539
'context' => array( 'view', 'edit' ),
540540
'readonly' => true,
541541
),

src/Controllers/Version2/class-wc-rest-orders-v2-controller.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ public function get_item_schema() {
11701170
),
11711171
'value' => array(
11721172
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
1173-
'type' => array( 'string', 'null' ),
1173+
'type' => 'mixed',
11741174
'context' => array( 'view', 'edit' ),
11751175
),
11761176
),
@@ -1191,12 +1191,12 @@ public function get_item_schema() {
11911191
),
11921192
'name' => array(
11931193
'description' => __( 'Product name.', 'woocommerce-rest-api' ),
1194-
'type' => array( 'string', 'null' ),
1194+
'type' => 'mixed',
11951195
'context' => array( 'view', 'edit' ),
11961196
),
11971197
'product_id' => array(
11981198
'description' => __( 'Product ID.', 'woocommerce-rest-api' ),
1199-
'type' => array( 'integer' ),
1199+
'type' => 'mixed',
12001200
'context' => array( 'view', 'edit' ),
12011201
),
12021202
'variation_id' => array(
@@ -1282,7 +1282,7 @@ public function get_item_schema() {
12821282
),
12831283
'value' => array(
12841284
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
1285-
'type' => array( 'string', 'null' ),
1285+
'type' => 'mixed',
12861286
'context' => array( 'view', 'edit' ),
12871287
),
12881288
),
@@ -1373,7 +1373,7 @@ public function get_item_schema() {
13731373
),
13741374
'value' => array(
13751375
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
1376-
'type' => array( 'string', 'null' ),
1376+
'type' => 'mixed',
13771377
'context' => array( 'view', 'edit' ),
13781378
),
13791379
),
@@ -1397,12 +1397,12 @@ public function get_item_schema() {
13971397
),
13981398
'method_title' => array(
13991399
'description' => __( 'Shipping method name.', 'woocommerce-rest-api' ),
1400-
'type' => array( 'string', 'null' ),
1400+
'type' => 'mixed',
14011401
'context' => array( 'view', 'edit' ),
14021402
),
14031403
'method_id' => array(
14041404
'description' => __( 'Shipping method ID.', 'woocommerce-rest-api' ),
1405-
'type' => array( 'string', 'null' ),
1405+
'type' => 'mixed',
14061406
'context' => array( 'view', 'edit' ),
14071407
),
14081408
'instance_id' => array(
@@ -1464,7 +1464,7 @@ public function get_item_schema() {
14641464
),
14651465
'value' => array(
14661466
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
1467-
'type' => array( 'string', 'null' ),
1467+
'type' => 'mixed',
14681468
'context' => array( 'view', 'edit' ),
14691469
),
14701470
),
@@ -1488,7 +1488,7 @@ public function get_item_schema() {
14881488
),
14891489
'name' => array(
14901490
'description' => __( 'Fee name.', 'woocommerce-rest-api' ),
1491-
'type' => array( 'string', 'null' ),
1491+
'type' => 'mixed',
14921492
'context' => array( 'view', 'edit' ),
14931493
),
14941494
'tax_class' => array(
@@ -1562,7 +1562,7 @@ public function get_item_schema() {
15621562
),
15631563
'value' => array(
15641564
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
1565-
'type' => array( 'string', 'null' ),
1565+
'type' => 'mixed',
15661566
'context' => array( 'view', 'edit' ),
15671567
),
15681568
),
@@ -1586,7 +1586,7 @@ public function get_item_schema() {
15861586
),
15871587
'code' => array(
15881588
'description' => __( 'Coupon code.', 'woocommerce-rest-api' ),
1589-
'type' => array( 'string', 'null' ),
1589+
'type' => 'mixed',
15901590
'context' => array( 'view', 'edit' ),
15911591
),
15921592
'discount' => array(
@@ -1620,7 +1620,7 @@ public function get_item_schema() {
16201620
),
16211621
'value' => array(
16221622
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
1623-
'type' => array( 'string', 'null' ),
1623+
'type' => 'mixed',
16241624
'context' => array( 'view', 'edit' ),
16251625
),
16261626
),

src/Controllers/Version2/class-wc-rest-product-variations-v2-controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ public function get_item_schema() {
797797
),
798798
'manage_stock' => array(
799799
'description' => __( 'Stock management at variation level.', 'woocommerce-rest-api' ),
800-
'type' => array( 'boolean', 'null' ),
800+
'type' => 'mixed',
801801
'default' => false,
802802
'context' => array( 'view', 'edit' ),
803803
),
@@ -980,7 +980,7 @@ public function get_item_schema() {
980980
),
981981
'value' => array(
982982
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
983-
'type' => array( 'string', 'null' ),
983+
'type' => 'mixed',
984984
'context' => array( 'view', 'edit' ),
985985
),
986986
),

src/Controllers/Version2/class-wc-rest-products-v2-controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2084,7 +2084,7 @@ public function get_item_schema() {
20842084
),
20852085
'value' => array(
20862086
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
2087-
'type' => array( 'string', 'null' ),
2087+
'type' => 'mixed',
20882088
'context' => array( 'view', 'edit' ),
20892089
),
20902090
),

src/Controllers/Version2/class-wc-rest-setting-options-v2-controller.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -530,18 +530,12 @@ public function get_item_schema() {
530530
),
531531
'value' => array(
532532
'description' => __( 'Setting value.', 'woocommerce-rest-api' ),
533-
'type' => array( 'string', 'array', 'null' ),
534-
'items' => array(
535-
'type' => array( 'string', 'null' ),
536-
),
533+
'type' => 'mixed',
537534
'context' => array( 'view', 'edit' ),
538535
),
539536
'default' => array(
540537
'description' => __( 'Default value for the setting.', 'woocommerce-rest-api' ),
541-
'type' => array( 'string', 'array', 'null' ),
542-
'items' => array(
543-
'type' => array( 'string', 'null' ),
544-
),
538+
'type' => 'mixed',
545539
'context' => array( 'view', 'edit' ),
546540
'readonly' => true,
547541
),

src/Controllers/Version3/class-wc-rest-controller.php

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,57 @@ public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CRE
9393
return $endpoint_args;
9494
}
9595

96+
$endpoint_args = $this->adjust_wp_5_5_datatype_compatibility( $endpoint_args );
97+
98+
return $endpoint_args;
99+
}
100+
101+
/**
102+
* Change datatypes `date-time` to string, and `mixed` to composite of all built in types. This is required for maintaining forward compatibility with WP 5.5 since custom post types are not supported anymore.
103+
*
104+
* See @link https://core.trac.wordpress.org/changeset/48306
105+
*
106+
* We still use the 'mixed' type, since if we convert to composite type everywhere, it won't work in 5.4 anymore because they require to define the full schema.
107+
*
108+
* @param array $endpoint_args Schema with datatypes to convert.
109+
110+
* @return mixed Schema with converted datatype.
111+
*/
112+
protected function adjust_wp_5_5_datatype_compatibility( $endpoint_args ) {
113+
if ( version_compare( get_bloginfo( 'version' ), '5.5', '<' ) ) {
114+
return $endpoint_args;
115+
}
116+
96117
foreach ( $endpoint_args as $field_id => $params ) {
118+
119+
if ( ! isset( $params['type'] ) ) {
120+
continue;
121+
}
122+
97123
/**
98-
* Custom types are not supported as of WP 5.5, this translates type => 'date-time' to type => 'string' with format date-time.
124+
* Custom types are not supported as of WP 5.5, this translates type => 'date-time' to type => 'string'.
99125
*/
100126
if ( 'date-time' === $params['type'] ) {
101-
$endpoint_args[ $field_id ]['type'] = 'string';
102-
$endpoint_args[ $field_id ]['format'] = 'date-time';
127+
$params['type'] = array( 'null', 'string' );
128+
}
129+
130+
/**
131+
* WARNING: Order of fields here is important, types of fields are ordered from most specific to least specific as perceived by core's built-in type validation methods.
132+
*/
133+
if ( 'mixed' === $params['type'] ) {
134+
$params['type'] = array( 'null', 'object', 'string', 'number', 'boolean', 'integer', 'array' );
135+
}
136+
137+
if ( isset( $params['properties'] ) ) {
138+
$params['properties'] = $this->adjust_wp_5_5_datatype_compatibility( $params['properties'] );
103139
}
104-
}
105140

141+
if ( isset( $params['items'] ) && isset( $params['items']['properties'] ) ) {
142+
$params['items']['properties'] = $this->adjust_wp_5_5_datatype_compatibility( $params['items']['properties'] );
143+
}
144+
145+
$endpoint_args[ $field_id ] = $params;
146+
}
106147
return $endpoint_args;
107148
}
108149

src/Controllers/Version3/class-wc-rest-crud-controller.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ public function delete_item_permissions_check( $request ) {
9191
return true;
9292
}
9393

94-
95-
9694
/**
9795
* Get object permalink.
9896
*

0 commit comments

Comments
 (0)