Cherry pick 52361 into release/9.4 (#52740)

* Add a `is_string` check to the params iterator (#52361)

This works fine:

```
curl -u bor0:asdf -X OPTIONS "localhost:8080/wp-json/wc/store/v1/products?_unstable_tax_asdf_operator=1" | jq
```

However, this causes a fatal error `PHP Fatal error:  Uncaught TypeError: str_starts_with(): Argument #1 ($haystack) must be of type string, int given`:

```
curl -u bor0:asdf -X OPTIONS "localhost:8080/wp-json/wc/store/v1/products?1=2" | jq
```

* Prep for cherry pick 52361

---------

Co-authored-by: Boro Sitnikovski <buritomath@gmail.com>
Co-authored-by: WooCommerce Bot <no-reply@woocommerce.com>
This commit is contained in:
github-actions[bot] 2024-11-12 22:20:12 +07:00 committed by GitHub
parent 9495d7ce98
commit 0bd6a01605
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 0 deletions

View File

@ -173,6 +173,7 @@ WooCommerce comes with some sample data you can use to see how products look; im
**WooCommerce**
* Fix - Fix StoreAPI erroring when a param is an integer [#52361](https://github.com/woocommerce/woocommerce/pull/52361)
* Fix - Product grid blocks: fix Image aspect ratio with WordPress 6.7 [#52431](https://github.com/woocommerce/woocommerce/pull/52431)
* Fix - Product Image Gallery: Render placeholder in Editor in WordPress 6.7 [#52432](https://github.com/woocommerce/woocommerce/pull/52432)
* Fix - Support situations in which (WooCommerce) translations are inadvertently loaded too early. [#52199](https://github.com/woocommerce/woocommerce/pull/52199)

View File

@ -301,6 +301,10 @@ class Products extends AbstractRoute {
// If the $_REQUEST contains a taxonomy query, add it to the params and sanitize it.
foreach ( $_REQUEST as $param => $value ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! is_string( $param ) ) {
continue;
}
if ( str_starts_with( $param, '_unstable_tax_' ) && ! str_ends_with( $param, '_operator' ) ) {
$params[ $param ] = array(
'description' => __( 'Limit result set to products assigned a specific category ID.', 'woocommerce' ),