Extract module flag check

This commit is contained in:
Alex P 2023-12-20 08:56:23 +02:00
parent 31c90c149e
commit 16fbb5b4d1
No known key found for this signature in database
GPG key ID: 54487A734A204D71
2 changed files with 13 additions and 4 deletions

View file

@ -5,6 +5,7 @@
* @package WooCommerce\PayPalCommerce * @package WooCommerce\PayPalCommerce
*/ */
use WooCommerce\PayPalCommerce\PayLaterBlock\PayLaterBlockModule;
use WooCommerce\PayPalCommerce\PluginModule; use WooCommerce\PayPalCommerce\PluginModule;
return function ( string $root_dir ): iterable { return function ( string $root_dir ): iterable {
@ -66,10 +67,7 @@ return function ( string $root_dir ): iterable {
$modules[] = ( require "$modules_dir/ppcp-save-payment-methods/module.php" )(); $modules[] = ( require "$modules_dir/ppcp-save-payment-methods/module.php" )();
} }
if ( apply_filters( if ( PayLaterBlockModule::is_enabled() ) {
'woocommerce.feature-flags.woocommerce_paypal_payments.paylater_block_enabled',
getenv( 'PCP_PAYLATER_BLOCK' ) !== '0'
) ) {
$modules[] = ( require "$modules_dir/ppcp-paylater-block/module.php" )(); $modules[] = ( require "$modules_dir/ppcp-paylater-block/module.php" )();
} }

View file

@ -19,6 +19,17 @@ use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
* Class PayLaterBlockModule * Class PayLaterBlockModule
*/ */
class PayLaterBlockModule implements ModuleInterface { class PayLaterBlockModule implements ModuleInterface {
/**
* Returns whether the block should be loaded.
*/
public static function is_enabled(): bool {
return apply_filters(
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
'woocommerce.feature-flags.woocommerce_paypal_payments.paylater_block_enabled',
getenv( 'PCP_PAYLATER_BLOCK' ) !== '0'
);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */