Skip to content

Commit 9620731

Browse files
committed
Bug Fix: Cannot use object of type Closure as array
1 parent 664ca7b commit 9620731

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

includes/API.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,22 @@ public function rest_pre_dispatch( $result, $server, $request ) {
195195
* @param WP_REST_Request $request Request used to generate the response.
196196
*/
197197
public function rest_request_before_callbacks( $response, $handler, $request ) {
198-
$controller = get_class( $handler['callback'][0] );
198+
/**
199+
* Here we attempt to determine the controller class from the handler.
200+
*
201+
* Note: the handler can be a closure, in which case we can't determine the controller.
202+
*/
203+
if ( isset( $handler['callback'] ) && is_array( $handler['callback'] ) && is_object( $handler['callback'][0] ) ) {
204+
$controller = get_class( $handler['callback'][0] );
205+
} else if ( is_object( $handler['callback'] ) ) {
206+
$controller = get_class( $handler['callback'] );
207+
} else {
208+
return $response;
209+
}
199210

211+
/**
212+
* If the controller is one of the WooCommerce REST API controllers, we can hijack the request
213+
*/
200214
switch ( $controller ) {
201215
case 'WC_REST_Orders_Controller':
202216
$this->wc_rest_api_handler = new API\Orders( $request );

includes/Gateways.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function payment_gateways( array $gateways ) {
4949
* - Order and set default order
5050
* - Also going to remove icons from the gateways
5151
*
52-
* - BUG: a user with WooCommerce Blocks is getting null for $gateways?
52+
* - NOTE: lots of plugins/themes call this filter and I can't guarantee that $gateways is an array
5353
*
5454
* @param array | null $gateways
5555
*

readme.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ There is more information on our website at [https://wcpos.com](https://wcpos.co
6464
== Changelog ==
6565

6666
= 1.1.1 - 2023/05/xx =
67-
* Fix: remove private meta data from Order Preview modal
67+
* Improvement: remove private meta data from Order Preview modal
68+
* Bug Fix: 'Cannot use object of type Closure as array' in the API.php file
6869

6970
= 1.1.0 - 2023/05/19 =
7071
* Fix: disable Lite Speed Cache for POS page

0 commit comments

Comments
 (0)