Skip to content

Commit

Permalink
Bug Fix: Cannot use object of type Closure as array
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed May 24, 2023
1 parent 664ca7b commit 9620731
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
16 changes: 15 additions & 1 deletion includes/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,22 @@ public function rest_pre_dispatch( $result, $server, $request ) {
* @param WP_REST_Request $request Request used to generate the response.
*/
public function rest_request_before_callbacks( $response, $handler, $request ) {
$controller = get_class( $handler['callback'][0] );
/**
* Here we attempt to determine the controller class from the handler.
*
* Note: the handler can be a closure, in which case we can't determine the controller.
*/
if ( isset( $handler['callback'] ) && is_array( $handler['callback'] ) && is_object( $handler['callback'][0] ) ) {
$controller = get_class( $handler['callback'][0] );
} else if ( is_object( $handler['callback'] ) ) {
$controller = get_class( $handler['callback'] );
} else {
return $response;
}

/**
* If the controller is one of the WooCommerce REST API controllers, we can hijack the request
*/
switch ( $controller ) {
case 'WC_REST_Orders_Controller':
$this->wc_rest_api_handler = new API\Orders( $request );
Expand Down
2 changes: 1 addition & 1 deletion includes/Gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function payment_gateways( array $gateways ) {
* - Order and set default order
* - Also going to remove icons from the gateways
*
* - BUG: a user with WooCommerce Blocks is getting null for $gateways?
* - NOTE: lots of plugins/themes call this filter and I can't guarantee that $gateways is an array
*
* @param array | null $gateways
*
Expand Down
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ There is more information on our website at [https://wcpos.com](https://wcpos.co
== Changelog ==

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

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

0 comments on commit 9620731

Please sign in to comment.