woocommerce-paypal-payments/modules/ppcp-wc-gateway/src/Assets/class-settingspageassets.php

70 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/**
* Register and configure assets provided by this module.
2021-03-25 13:55:43 +02:00
*
* @package WooCommerce\PayPalCommerce\WcGateway\Assets
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
2021-03-25 13:55:43 +02:00
/**
* Class SettingsPageAssets
*/
2021-03-25 13:45:57 +02:00
class SettingsPageAssets {
/**
2021-03-25 13:55:43 +02:00
* The URL of this module.
*
* @var string
*/
private $module_url;
2021-03-25 14:29:56 +02:00
/**
* The filesystem path to the module dir.
*
* @var string
*/
private $module_path;
/**
* Assets constructor.
2021-03-25 13:45:57 +02:00
*
* @param string $module_url The url of this module.
2021-03-25 14:29:56 +02:00
* @param string $module_path The filesystem path to this module.
*/
2021-03-25 14:29:56 +02:00
public function __construct( string $module_url, string $module_path ) {
$this->module_url = $module_url;
2021-03-25 14:29:56 +02:00
$this->module_path = $module_path;
}
/**
* Register assets provided by this module.
*/
public function register_assets() {
2021-03-25 13:45:57 +02:00
if ( is_admin() && ! is_ajax() ) {
$this->register_admin_assets();
}
}
/**
* Register assets for admin pages.
*/
private function register_admin_assets() {
2021-03-25 14:29:56 +02:00
$gateway_settings_script_path = trailingslashit($this->module_path) . 'assets/js/gateway-settings.js';
2021-03-25 13:45:57 +02:00
add_action(
'admin_enqueue_scripts',
2021-03-25 14:29:56 +02:00
function() use ($gateway_settings_script_path) {
2021-03-25 13:45:57 +02:00
wp_enqueue_script(
'ppcp-gateway-settings',
trailingslashit( $this->module_url ) . 'assets/js/gateway-settings.js',
array(),
2021-03-25 14:29:56 +02:00
file_exists($gateway_settings_script_path) ? (string) filemtime($gateway_settings_script_path) : null,
2021-03-25 13:45:57 +02:00
true
);
}
);
}
2021-03-25 13:45:57 +02:00
}