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(
|
array(
|
||||||
PayPalGateway::ID,
|
PayPalGateway::ID,
|
||||||
CreditCardGateway::ID,
|
CreditCardGateway::ID,
|
||||||
|
CardButtonGateway::ID,
|
||||||
),
|
),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
|
@ -112,6 +112,13 @@ class SettingsPageAssets {
|
||||||
*/
|
*/
|
||||||
private $billing_agreements_endpoint;
|
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.
|
* 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_settings_page Whether it's a settings page of this plugin.
|
||||||
* @param bool $is_acdc_enabled Whether the ACDC gateway is enabled.
|
* @param bool $is_acdc_enabled Whether the ACDC gateway is enabled.
|
||||||
* @param BillingAgreementsEndpoint $billing_agreements_endpoint Billing Agreements endpoint.
|
* @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(
|
public function __construct(
|
||||||
string $module_url,
|
string $module_url,
|
||||||
|
@ -142,21 +150,23 @@ class SettingsPageAssets {
|
||||||
array $all_funding_sources,
|
array $all_funding_sources,
|
||||||
bool $is_settings_page,
|
bool $is_settings_page,
|
||||||
bool $is_acdc_enabled,
|
bool $is_acdc_enabled,
|
||||||
BillingAgreementsEndpoint $billing_agreements_endpoint
|
BillingAgreementsEndpoint $billing_agreements_endpoint,
|
||||||
|
bool $is_paypal_payment_method_page
|
||||||
) {
|
) {
|
||||||
$this->module_url = $module_url;
|
$this->module_url = $module_url;
|
||||||
$this->version = $version;
|
$this->version = $version;
|
||||||
$this->subscription_helper = $subscription_helper;
|
$this->subscription_helper = $subscription_helper;
|
||||||
$this->client_id = $client_id;
|
$this->client_id = $client_id;
|
||||||
$this->currency = $currency;
|
$this->currency = $currency;
|
||||||
$this->country = $country;
|
$this->country = $country;
|
||||||
$this->environment = $environment;
|
$this->environment = $environment;
|
||||||
$this->is_pay_later_button_enabled = $is_pay_later_button_enabled;
|
$this->is_pay_later_button_enabled = $is_pay_later_button_enabled;
|
||||||
$this->disabled_sources = $disabled_sources;
|
$this->disabled_sources = $disabled_sources;
|
||||||
$this->all_funding_sources = $all_funding_sources;
|
$this->all_funding_sources = $all_funding_sources;
|
||||||
$this->is_settings_page = $is_settings_page;
|
$this->is_settings_page = $is_settings_page;
|
||||||
$this->is_acdc_enabled = $is_acdc_enabled;
|
$this->is_acdc_enabled = $is_acdc_enabled;
|
||||||
$this->billing_agreements_endpoint = $billing_agreements_endpoint;
|
$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();
|
$this->register_admin_assets();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $this->is_paypal_payment_method_page() ) {
|
if ( $this->is_paypal_payment_method_page ) {
|
||||||
$this->register_paypal_admin_assets();
|
$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.
|
* Register assets for PayPal admin pages.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -183,7 +183,8 @@ class WCGatewayModule implements ModuleInterface {
|
||||||
$c->get( 'wcgateway.settings.funding-sources' ),
|
$c->get( 'wcgateway.settings.funding-sources' ),
|
||||||
$c->get( 'wcgateway.is-ppcp-settings-page' ),
|
$c->get( 'wcgateway.is-ppcp-settings-page' ),
|
||||||
$settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ),
|
$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();
|
$assets->register_assets();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,8 @@ class SettingsPagesAssetsTest extends TestCase
|
||||||
array(),
|
array(),
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
$billingAgreementEndpoint
|
$billingAgreementEndpoint,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
when('is_admin')
|
when('is_admin')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue