woocommerce-paypal-payments/modules/ppcp-compat/src/CompatModule.php

97 lines
2.5 KiB
PHP
Raw Normal View History

2021-07-15 06:51:37 -05:00
<?php
/**
* The compatibility module.
*
* @package WooCommerce\PayPalCommerce\Compat
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Compat;
use Dhii\Container\ServiceProvider;
use Dhii\Modular\Module\ModuleInterface;
use Interop\Container\ServiceProviderInterface;
use Psr\Container\ContainerInterface;
2021-09-13 16:24:27 +02:00
use WooCommerce\PayPalCommerce\Compat\PPEC\PPECHelper;
2021-07-15 06:51:37 -05:00
/**
* Class CompatModule
*/
class CompatModule implements ModuleInterface {
/**
* Setup the compatibility module.
*
* @return ServiceProviderInterface
*/
public function setup(): ServiceProviderInterface {
return new ServiceProvider(
require __DIR__ . '/../services.php',
require __DIR__ . '/../extensions.php'
);
}
/**
* Run the compatibility module.
*
2021-08-30 08:10:43 +02:00
* @param ContainerInterface|null $c The Container.
2021-07-15 06:51:37 -05:00
*/
2021-08-30 08:10:43 +02:00
public function run( ContainerInterface $c ): void {
$this->initialize_ppec_compat_layer( $c );
$this->fix_site_ground_optimizer_compatibility( $c );
2021-07-15 06:51:37 -05:00
}
/**
* Returns the key for the module.
*
* @return string|void
*/
public function getKey() {
}
/**
* Sets up the PayPal Express Checkout compatibility layer.
*
* @param ContainerInterface|null $container The Container.
* @return void
*/
2022-08-19 19:05:31 +04:00
private function initialize_ppec_compat_layer( ?ContainerInterface $container ): void {
// Process PPEC subscription renewals through PayPal Payments.
$handler = $container->get( 'compat.ppec.subscriptions-handler' );
$handler->maybe_hook();
2021-07-14 15:06:32 -05:00
// Settings.
$ppec_import = $container->get( 'compat.ppec.settings_importer' );
$ppec_import->maybe_hook();
// Inbox note inviting merchant to disable PayPal Express Checkout.
add_action(
'woocommerce_init',
function() {
if ( is_callable( array( WC(), 'is_wc_admin_active' ) ) && WC()->is_wc_admin_active() && class_exists( 'Automattic\WooCommerce\Admin\Notes\Notes' ) ) {
PPEC\DeactivateNote::init();
}
}
);
}
/**
* Fixes the compatibility issue for <a href="https://wordpress.org/plugins/sg-cachepress/">SiteGround Optimizer plugin</a>.
*
* @link https://wordpress.org/plugins/sg-cachepress/
*
* @param ContainerInterface $c The Container.
*/
protected function fix_site_ground_optimizer_compatibility( ContainerInterface $c ): void {
$ppcp_script_names = $c->get( 'compat.plugin-script-names' );
add_filter(
'sgo_js_minify_exclude',
function ( array $scripts ) use ( $ppcp_script_names ) {
return array_merge( $scripts, $ppcp_script_names );
}
);
}
2021-07-15 06:51:37 -05:00
}