Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WooPayments REST: conditional initialization. #8805

Merged
merged 6 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/add-8797-conditional-rest-apis-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Guarantee REST intialization on REST request context (avoiding rest_preload_api_request context).
7 changes: 7 additions & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,13 @@ private static function get_wc_payments_http() {
* Initialize the REST API controllers.
*/
public static function init_rest_api() {
// Ensures we are not initializing our REST during `rest_preload_api_request`.
// When constructors signature changes, in manual update scenarios we were run into fatals.
// Those fatals are not critical, but it causes hickups in release process as catches unnecessary attention.
if ( function_exists( 'get_current_screen' ) && get_current_screen() ) {
return;
}

include_once WCPAY_ABSPATH . 'includes/exceptions/class-rest-request-exception.php';
include_once WCPAY_ABSPATH . 'includes/admin/class-wc-payments-rest-controller.php';

Expand Down
7 changes: 7 additions & 0 deletions includes/multi-currency/MultiCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ public function init() {
* @return void
*/
public function init_rest_api() {
// Ensures we are not initializing our REST during `rest_preload_api_request`.
// When constructors signature changes, in manual update scenarios we were run into fatals.
// Those fatals are not critical, but it causes hickups in release process as catches unnecessary attention.
if ( function_exists( 'get_current_screen' ) && get_current_screen() ) {
return;
}

$api_controller = new RestController( \WC_Payments::create_api_client() );
$api_controller->register_routes();
}
Expand Down