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

Commit 3a90c6d

Browse files
authored
Merge pull request #232 from woocommerce/compatibility/5.5
Fix compatibility for WP 5.5
2 parents 304bb95 + efd2e62 commit 3a90c6d

13 files changed

+71
-28
lines changed

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' => 'mixed',
514+
'type' => array( 'string', 'null' ),
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' => 'mixed',
353+
'type' => array( 'string', 'null' ),
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' => 'mixed',
413+
'type' => array( 'string', 'null' ),
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' => 'mixed',
435+
'type' => array( 'string', 'null' ),
436436
'context' => array( 'view', 'edit' ),
437437
'readonly' => true,
438438
),
439439
'product_id' => array(
440440
'description' => __( 'Product ID.', 'woocommerce-rest-api' ),
441-
'type' => 'mixed',
441+
'type' => array( 'integer', 'null' ),
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' => 'mixed',
538+
'type' => array( 'string', 'null' ),
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' => 'mixed',
1173+
'type' => array( 'string', 'null' ),
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' => 'mixed',
1194+
'type' => array( 'string', 'null' ),
11951195
'context' => array( 'view', 'edit' ),
11961196
),
11971197
'product_id' => array(
11981198
'description' => __( 'Product ID.', 'woocommerce-rest-api' ),
1199-
'type' => 'mixed',
1199+
'type' => array( 'integer' ),
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' => 'mixed',
1285+
'type' => array( 'string', 'null' ),
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' => 'mixed',
1376+
'type' => array( 'string', 'null' ),
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' => 'mixed',
1400+
'type' => array( 'string', 'null' ),
14011401
'context' => array( 'view', 'edit' ),
14021402
),
14031403
'method_id' => array(
14041404
'description' => __( 'Shipping method ID.', 'woocommerce-rest-api' ),
1405-
'type' => 'mixed',
1405+
'type' => array( 'string', 'null' ),
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' => 'mixed',
1467+
'type' => array( 'string', 'null' ),
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' => 'mixed',
1491+
'type' => array( 'string', 'null' ),
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' => 'mixed',
1565+
'type' => array( 'string', 'null' ),
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' => 'mixed',
1589+
'type' => array( 'string', 'null' ),
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' => 'mixed',
1623+
'type' => array( 'string', 'null' ),
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
@@ -799,7 +799,7 @@ public function get_item_schema() {
799799
),
800800
'manage_stock' => array(
801801
'description' => __( 'Stock management at variation level.', 'woocommerce-rest-api' ),
802-
'type' => 'mixed',
802+
'type' => array( 'boolean', 'null' ),
803803
'default' => false,
804804
'context' => array( 'view', 'edit' ),
805805
),
@@ -982,7 +982,7 @@ public function get_item_schema() {
982982
),
983983
'value' => array(
984984
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
985-
'type' => 'mixed',
985+
'type' => array( 'string', 'null' ),
986986
'context' => array( 'view', 'edit' ),
987987
),
988988
),

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' => 'mixed',
2087+
'type' => array( 'string', 'null' ),
20882088
'context' => array( 'view', 'edit' ),
20892089
),
20902090
),

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

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

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,35 @@ protected function add_additional_fields_schema( $schema ) {
7777
return $schema;
7878
}
7979

80+
/**
81+
* Compatibility functions for WP 5.5, since custom types are not supported anymore.
82+
* See @link https://core.trac.wordpress.org/changeset/48306
83+
*
84+
* @param string $method Optional. HTTP method of the request.
85+
*
86+
* @return array Endpoint arguments.
87+
*/
88+
public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) {
89+
90+
$endpoint_args = parent::get_endpoint_args_for_item_schema( $method );
91+
92+
if ( false === strpos( WP_REST_Server::EDITABLE, $method ) ) {
93+
return $endpoint_args;
94+
}
95+
96+
foreach ( $endpoint_args as $field_id => $params ) {
97+
/**
98+
* Custom types are not supported as of WP 5.5, this translates type => 'date-time' to type => 'string' with format date-time.
99+
*/
100+
if ( 'date-time' === $params['type'] ) {
101+
$endpoint_args[ $field_id ]['type'] = 'string';
102+
$endpoint_args[ $field_id ]['format'] = 'date-time';
103+
}
104+
}
105+
106+
return $endpoint_args;
107+
}
108+
80109
/**
81110
* Get normalized rest base.
82111
*

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

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

94+
95+
9496
/**
9597
* Get object permalink.
9698
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public function get_item_schema() {
293293
),
294294
'value' => array(
295295
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
296-
'type' => 'mixed',
296+
'type' => array( 'string', 'null' ),
297297
'context' => array( 'view', 'edit' ),
298298
),
299299
),

0 commit comments

Comments
 (0)