Use the 'ppcp.path-to-plugin-folder' config

This commit is contained in:
Narek Zakarian 2025-07-04 19:27:26 +04:00
parent 943a0d197c
commit 86cae6ca4a
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7
4 changed files with 20 additions and 15 deletions

View file

@ -102,7 +102,7 @@ class PayLaterBlockModule implements ServiceModule, ExtendingModule, ExecutableM
);
register_block_type(
dirname( realpath( __FILE__ ) ?: __FILE__, 2 ),
$c->get( 'ppcp.path-to-plugin-folder' ) . 'modules/ppcp-paylater-block/',
array(
'render_callback' => function ( array $attributes ) use ( $c ) {
$renderer = $c->get( 'paylater-block.renderer' );

View file

@ -192,10 +192,10 @@ class PayLaterWCBlocksModule implements ServiceModule, ExtendingModule, Executab
return;
}
$path = realpath( __FILE__ ) ?: __FILE__;
$path_to_module_js_folder = $c->get( 'ppcp.path-to-plugin-folder' ) . 'modules/ppcp-paylater-wc-blocks/resources/js/';
register_block_type(
dirname( $path, 2 ) . '/resources/js/CartPayLaterMessagesBlock',
$path_to_module_js_folder . 'CartPayLaterMessagesBlock',
array(
'render_callback' => function ( array $attributes ) use ( $c ) {
return PayLaterWCBlocksUtils::render_paylater_block(
@ -209,7 +209,7 @@ class PayLaterWCBlocksModule implements ServiceModule, ExtendingModule, Executab
);
register_block_type(
dirname( $path, 2 ) . '/resources/js/CheckoutPayLaterMessagesBlock',
$path_to_module_js_folder . 'CheckoutPayLaterMessagesBlock',
array(
'render_callback' => function ( array $attributes ) use ( $c ) {
return PayLaterWCBlocksUtils::render_paylater_block(

View file

@ -59,6 +59,8 @@ class ScriptDataHandler {
*/
protected PartnerAttribution $partner_attribution;
protected string $path_to_module_assets_folder;
/**
* ScriptDataHandler constructor.
*
@ -69,6 +71,7 @@ class ScriptDataHandler {
* @param string $merchant_id The merchant ID.
* @param array $button_language_choices The button language choices.
* @param PartnerAttribution $partner_attribution The partner attribution object.
* @param string $path_to_module_assets_folder The path to mpdule assets folder.
*/
public function __construct(
Settings $settings,
@ -77,15 +80,17 @@ class ScriptDataHandler {
string $store_country,
string $merchant_id,
array $button_language_choices,
PartnerAttribution $partner_attribution
PartnerAttribution $partner_attribution,
string $path_to_module_assets_folder
) {
$this->settings = $settings;
$this->settings_url = $settings_url;
$this->paylater_is_available = $paylater_is_available;
$this->store_country = $store_country;
$this->merchant_id = $merchant_id;
$this->button_language_choices = $button_language_choices;
$this->partner_attribution = $partner_attribution;
$this->settings = $settings;
$this->settings_url = $settings_url;
$this->paylater_is_available = $paylater_is_available;
$this->store_country = $store_country;
$this->merchant_id = $merchant_id;
$this->button_language_choices = $button_language_choices;
$this->partner_attribution = $partner_attribution;
$this->path_to_module_assets_folder = $path_to_module_assets_folder;
}
/**
@ -109,7 +114,7 @@ class ScriptDataHandler {
*
* @psalm-suppress UnresolvableInclude
*/
$script_asset_file = require dirname( realpath( __FILE__ ) ?: __FILE__, 3 ) . '/assets/index.asset.php';
$script_asset_file = require $this->path_to_module_assets_folder . '/index.asset.php';
$module_url = $this->settings_url;
@ -128,7 +133,7 @@ class ScriptDataHandler {
);
/** @psalm-suppress UnresolvableInclude */
$style_asset_file = require dirname( realpath( __FILE__ ) ?: __FILE__, 3 ) . '/assets/style.asset.php';
$style_asset_file = require $this->path_to_module_assets_folder . '/style.asset.php';
wp_register_style(
'ppcp-admin-settings',

View file

@ -105,7 +105,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
$module_url = $container->get( 'settings.url' );
/** @psalm-suppress UnresolvableInclude */
$script_asset_file = require dirname( realpath( __FILE__ ) ?: __FILE__, 2 ) . '/assets/switchSettingsUi.asset.php';
$script_asset_file = require $container->get( 'ppcp.path-to-plugin-folder' ) . 'modules/ppcp-settings/assets/switchSettingsUi.asset.php';
wp_register_script(
'ppcp-switch-settings-ui',