mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +08:00
register script for the plugin settings page only
This commit is contained in:
parent
8d5698614d
commit
1eb9643ff3
1 changed files with 43 additions and 13 deletions
|
@ -42,9 +42,44 @@ class SettingsPageAssets {
|
||||||
* Register assets provided by this module.
|
* Register assets provided by this module.
|
||||||
*/
|
*/
|
||||||
public function register_assets() {
|
public function register_assets() {
|
||||||
if ( is_admin() && ! is_ajax() ) {
|
add_action(
|
||||||
$this->register_admin_assets();
|
'admin_enqueue_scripts',
|
||||||
|
function() {
|
||||||
|
if ( ! is_admin() || is_ajax() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $this->is_paypal_payment_method_page() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->register_admin_assets();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
|
||||||
|
$tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_STRING );
|
||||||
|
$section = filter_input( INPUT_GET, 'section', FILTER_SANITIZE_STRING );
|
||||||
|
|
||||||
|
if ( ! 'woocommerce_page_wc-settings' === $screen->id ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'checkout' === $tab && 'ppcp-gateway' === $section;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,17 +88,12 @@ class SettingsPageAssets {
|
||||||
private function register_admin_assets() {
|
private function register_admin_assets() {
|
||||||
$gateway_settings_script_path = trailingslashit( $this->module_path ) . 'assets/js/gateway-settings.js';
|
$gateway_settings_script_path = trailingslashit( $this->module_path ) . 'assets/js/gateway-settings.js';
|
||||||
|
|
||||||
add_action(
|
wp_enqueue_script(
|
||||||
'admin_enqueue_scripts',
|
'ppcp-gateway-settings',
|
||||||
function() use ( $gateway_settings_script_path ) {
|
trailingslashit( $this->module_url ) . 'assets/js/gateway-settings.js',
|
||||||
wp_enqueue_script(
|
array(),
|
||||||
'ppcp-gateway-settings',
|
file_exists( $gateway_settings_script_path ) ? (string) filemtime( $gateway_settings_script_path ) : null,
|
||||||
trailingslashit( $this->module_url ) . 'assets/js/gateway-settings.js',
|
true
|
||||||
array(),
|
|
||||||
file_exists( $gateway_settings_script_path ) ? (string) filemtime( $gateway_settings_script_path ) : null,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue