mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
🐛 Fix the condition to inject the settings JS
Switched to using an existing DI service to determine if the current page requires the “gateway-settings” asset files.
This commit is contained in:
parent
c23129cb91
commit
238adedcad
4 changed files with 30 additions and 41 deletions
|
@ -214,6 +214,7 @@ return array(
|
|||
array(
|
||||
PayPalGateway::ID,
|
||||
CreditCardGateway::ID,
|
||||
CardButtonGateway::ID,
|
||||
),
|
||||
true
|
||||
);
|
||||
|
|
|
@ -112,6 +112,13 @@ class SettingsPageAssets {
|
|||
*/
|
||||
private $billing_agreements_endpoint;
|
||||
|
||||
/**
|
||||
* Whether we're on a settings page for our plugin's payment methods.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $is_paypal_payment_method_page;
|
||||
|
||||
/**
|
||||
* Assets constructor.
|
||||
*
|
||||
|
@ -128,6 +135,7 @@ class SettingsPageAssets {
|
|||
* @param bool $is_settings_page Whether it's a settings page of this plugin.
|
||||
* @param bool $is_acdc_enabled Whether the ACDC gateway is enabled.
|
||||
* @param BillingAgreementsEndpoint $billing_agreements_endpoint Billing Agreements endpoint.
|
||||
* @param bool $is_paypal_payment_method_page Whether we're on a settings page for our plugin's payment methods.
|
||||
*/
|
||||
public function __construct(
|
||||
string $module_url,
|
||||
|
@ -142,7 +150,8 @@ class SettingsPageAssets {
|
|||
array $all_funding_sources,
|
||||
bool $is_settings_page,
|
||||
bool $is_acdc_enabled,
|
||||
BillingAgreementsEndpoint $billing_agreements_endpoint
|
||||
BillingAgreementsEndpoint $billing_agreements_endpoint,
|
||||
bool $is_paypal_payment_method_page
|
||||
) {
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
|
@ -157,6 +166,7 @@ class SettingsPageAssets {
|
|||
$this->is_settings_page = $is_settings_page;
|
||||
$this->is_acdc_enabled = $is_acdc_enabled;
|
||||
$this->billing_agreements_endpoint = $billing_agreements_endpoint;
|
||||
$this->is_paypal_payment_method_page = $is_paypal_payment_method_page;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,7 +186,7 @@ class SettingsPageAssets {
|
|||
$this->register_admin_assets();
|
||||
}
|
||||
|
||||
if ( $this->is_paypal_payment_method_page() ) {
|
||||
if ( $this->is_paypal_payment_method_page ) {
|
||||
$this->register_paypal_admin_assets();
|
||||
}
|
||||
}
|
||||
|
@ -184,30 +194,6 @@ class SettingsPageAssets {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the current page is PayPal payment method settings.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_paypal_payment_method_page(): bool {
|
||||
|
||||
if ( ! function_exists( 'get_current_screen' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$screen = get_current_screen();
|
||||
if ( ! $screen || $screen->id !== 'woocommerce_page_wc-settings' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
$tab = wc_clean( wp_unslash( $_GET['tab'] ?? '' ) );
|
||||
$section = wc_clean( wp_unslash( $_GET['section'] ?? '' ) );
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
return 'checkout' === $tab && in_array( $section, array( PayPalGateway::ID, CardButtonGateway::ID ), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register assets for PayPal admin pages.
|
||||
*/
|
||||
|
|
|
@ -183,7 +183,8 @@ class WCGatewayModule implements ModuleInterface {
|
|||
$c->get( 'wcgateway.settings.funding-sources' ),
|
||||
$c->get( 'wcgateway.is-ppcp-settings-page' ),
|
||||
$settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ),
|
||||
$c->get( 'api.endpoint.billing-agreements' )
|
||||
$c->get( 'api.endpoint.billing-agreements' ),
|
||||
$c->get( 'wcgateway.is-ppcp-settings-payment-methods-page' )
|
||||
);
|
||||
$assets->register_assets();
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ class SettingsPagesAssetsTest extends TestCase
|
|||
array(),
|
||||
true,
|
||||
false,
|
||||
$billingAgreementEndpoint
|
||||
$billingAgreementEndpoint,
|
||||
true
|
||||
);
|
||||
|
||||
when('is_admin')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue