Use plugin version as asset version

This commit is contained in:
Alex P 2022-02-17 18:51:24 +02:00
parent 651099705a
commit 0c07ebd629
11 changed files with 72 additions and 24 deletions

View file

@ -73,6 +73,7 @@ return array(
$currency = $container->get( 'api.shop.currency' );
return new SmartButton(
$container->get( 'button.url' ),
$container->get( 'ppcp.asset-version' ),
$container->get( 'session.handler' ),
$settings,
$payer_factory,

View file

@ -44,6 +44,13 @@ class SmartButton implements SmartButtonInterface {
*/
private $module_url;
/**
* The assets version.
*
* @var string
*/
private $version;
/**
* The Session Handler.
*
@ -125,6 +132,7 @@ class SmartButton implements SmartButtonInterface {
* SmartButton constructor.
*
* @param string $module_url The URL to the module.
* @param string $version The assets version.
* @param SessionHandler $session_handler The Session Handler.
* @param Settings $settings The Settings.
* @param PayerFactory $payer_factory The Payer factory.
@ -140,6 +148,7 @@ class SmartButton implements SmartButtonInterface {
*/
public function __construct(
string $module_url,
string $version,
SessionHandler $session_handler,
Settings $settings,
PayerFactory $payer_factory,
@ -155,6 +164,7 @@ class SmartButton implements SmartButtonInterface {
) {
$this->module_url = $module_url;
$this->version = $version;
$this->session_handler = $session_handler;
$this->settings = $settings;
$this->payer_factory = $payer_factory;
@ -406,7 +416,7 @@ class SmartButton implements SmartButtonInterface {
'ppcp-hosted-fields',
untrailingslashit( $this->module_url ) . '/assets/css/hosted-fields.css',
array(),
1
$this->version
);
}
if ( $load_script ) {
@ -414,7 +424,7 @@ class SmartButton implements SmartButtonInterface {
'ppcp-smart-button',
untrailingslashit( $this->module_url ) . '/assets/js/button.js',
array( 'jquery' ),
'1.3.2',
$this->version,
true
);

View file

@ -131,6 +131,7 @@ return array(
$login_seller_endpoint = $container->get( 'onboarding.endpoint.login-seller' );
return new OnboardingAssets(
$container->get( 'onboarding.url' ),
$container->get( 'ppcp.asset-version' ),
$state,
$container->get( 'onboarding.environment' ),
$login_seller_endpoint

View file

@ -25,6 +25,13 @@ class OnboardingAssets {
*/
private $module_url;
/**
* The assets version.
*
* @var string
*/
private $version;
/**
* The State.
*
@ -50,18 +57,21 @@ class OnboardingAssets {
* OnboardingAssets constructor.
*
* @param string $module_url The URL to the module.
* @param string $version The assets version.
* @param State $state The State object.
* @param Environment $environment The Environment.
* @param LoginSellerEndpoint $login_seller_endpoint The LoginSeller endpoint.
*/
public function __construct(
string $module_url,
string $version,
State $state,
Environment $environment,
LoginSellerEndpoint $login_seller_endpoint
) {
$this->module_url = untrailingslashit( $module_url );
$this->version = $version;
$this->state = $state;
$this->environment = $environment;
$this->login_seller_endpoint = $login_seller_endpoint;
@ -79,14 +89,14 @@ class OnboardingAssets {
'ppcp-onboarding',
$url,
array(),
1
$this->version
);
$url = untrailingslashit( $this->module_url ) . '/assets/js/settings.js';
wp_register_script(
'ppcp-settings',
$url,
array(),
1,
$this->version,
true
);
@ -95,7 +105,7 @@ class OnboardingAssets {
'ppcp-onboarding',
$url,
array( 'jquery' ),
1,
$this->version,
true
);
wp_localize_script(

View file

@ -22,7 +22,8 @@ return array(
},
'vaulting.assets.myaccount-payments' => function( ContainerInterface $container ) : MyAccountPaymentsAssets {
return new MyAccountPaymentsAssets(
$container->get( 'vaulting.module-url' )
$container->get( 'vaulting.module-url' ),
$container->get( 'ppcp.asset-version' )
);
},
'vaulting.payment-tokens-renderer' => static function (): PaymentTokensRenderer {

View file

@ -23,15 +23,25 @@ class MyAccountPaymentsAssets {
*/
private $module_url;
/**
* The assets version.
*
* @var string
*/
private $version;
/**
* MyAccountPaymentsAssets constructor.
*
* @param string $module_url The URL to the module.
* @param string $version The assets version.
*/
public function __construct(
string $module_url
string $module_url,
string $version
) {
$this->module_url = untrailingslashit( $module_url );
$this->version = $version;
}
/**
@ -44,7 +54,7 @@ class MyAccountPaymentsAssets {
'ppcp-vaulting-myaccount-payments',
untrailingslashit( $this->module_url ) . '/assets/js/myaccount-payments.js',
array( 'jquery' ),
'1',
$this->version,
true
);
}

View file

@ -25,11 +25,11 @@ class SettingsPageAssets {
private $module_url;
/**
* The filesystem path to the module dir.
* The assets version.
*
* @var string
*/
private $module_path;
private $version;
/**
* The bearer.
@ -42,13 +42,13 @@ class SettingsPageAssets {
* Assets constructor.
*
* @param string $module_url The url of this module.
* @param string $module_path The filesystem path to this module.
* @param string $version The assets version.
* @param Bearer $bearer The bearer.
*/
public function __construct( string $module_url, string $module_path, Bearer $bearer ) {
$this->module_url = $module_url;
$this->module_path = $module_path;
$this->bearer = $bearer;
public function __construct( string $module_url, string $version, Bearer $bearer ) {
$this->module_url = $module_url;
$this->version = $version;
$this->bearer = $bearer;
}
/**
@ -102,13 +102,11 @@ class SettingsPageAssets {
* @param Bearer $bearer The bearer.
*/
private function register_admin_assets( Bearer $bearer ) {
$gateway_settings_script_path = trailingslashit( $this->module_path ) . 'assets/js/gateway-settings.js';
wp_enqueue_script(
'ppcp-gateway-settings',
trailingslashit( $this->module_url ) . 'assets/js/gateway-settings.js',
array(),
file_exists( $gateway_settings_script_path ) ? (string) filemtime( $gateway_settings_script_path ) : null,
$this->version,
true
);

View file

@ -74,7 +74,7 @@ class WCGatewayModule implements ModuleInterface {
if ( $c->has( 'wcgateway.url' ) ) {
$assets = new SettingsPageAssets(
$c->get( 'wcgateway.url' ),
$c->get( 'wcgateway.absolute-path' ),
$c->get( 'ppcp.asset-version' ),
$c->get( 'api.bearer' )
);
$assets->register_assets();

View file

@ -156,7 +156,8 @@ return array(
'webhook.status.assets' => function( ContainerInterface $container ) : WebhooksStatusPageAssets {
return new WebhooksStatusPageAssets(
$container->get( 'webhook.module-url' )
$container->get( 'webhook.module-url' ),
$container->get( 'ppcp.asset-version' )
);
},

View file

@ -26,15 +26,25 @@ class WebhooksStatusPageAssets {
*/
private $module_url;
/**
* The assets version.
*
* @var string
*/
private $version;
/**
* WebhooksStatusPageAssets constructor.
*
* @param string $module_url The URL to the module.
* @param string $version The assets version.
*/
public function __construct(
string $module_url
string $module_url,
string $version
) {
$this->module_url = untrailingslashit( $module_url );
$this->version = $version;
}
/**
@ -47,14 +57,14 @@ class WebhooksStatusPageAssets {
'ppcp-webhooks-status-page-style',
untrailingslashit( $this->module_url ) . '/assets/css/status-page.css',
array(),
'1'
$this->version
);
wp_register_script(
'ppcp-webhooks-status-page',
untrailingslashit( $this->module_url ) . '/assets/js/status-page.js',
array(),
'1',
$this->version,
true
);