class-wc-payments-subscriptions-plugin-notice-manager.php
2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* Class WC_Payments_Subscriptions_Plugin_Notice_Manager
*
* @package WooCommerce\Payments
*/
defined( 'ABSPATH' ) || exit;
/**
* A class to handle the displaying of a warning notice when admin deactivate the WC Subscriptions extension.
*/
class WC_Payments_Subscriptions_Plugin_Notice_Manager {
use WC_Payments_Subscriptions_Utilities;
/**
* Initialize the class and attach callbacks.
*/
public function __construct() {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts_and_styles' ], 100 );
add_action( 'admin_footer', [ $this, 'output_notice_template' ] );
}
/**
* Determines if the current screen is the admin plugins screen.
*
* @return bool Whether the current request is for the admin plugins screen.
*/
private function is_admin_plugins_screen() {
if ( ! is_admin() ) {
return false;
}
$screen = get_current_screen();
return $screen && 'plugins' === $screen->id;
}
/**
* Enqueues the admin scripts needed on the plugins screen.
*/
public function enqueue_scripts_and_styles() {
if ( ! $this->is_admin_plugins_screen() ) {
return;
}
// The backbone modal requires the WC admin styles to be loaded.
wp_enqueue_style( 'woocommerce_admin_styles' );
wp_register_script(
'wcpay-subscriptions-plugin',
plugins_url( 'includes/subscriptions/assets/js/plugin-page.js', WCPAY_PLUGIN_FILE ),
[ 'jquery', 'wc-backbone-modal' ],
WCPAY_VERSION_NUMBER,
true
);
wp_enqueue_script( 'wcpay-subscriptions-plugin' );
// Enqueue script data - does this store have active WCPay subscriptions?
$script_data = [
'store_has_active_wcpay_subscriptions' => WC_Payments_Subscription_Service::store_has_active_wcpay_subscriptions(),
];
wp_localize_script( 'wcpay-subscriptions-plugin', 'wcpay_subscriptions_plugin_screen_data', $script_data );
wp_register_style(
'wcpay-subscriptions-plugin-styles',
plugins_url( 'includes/subscriptions/assets/css/plugin-page.css', WCPAY_PLUGIN_FILE ),
[],
WCPAY_VERSION_NUMBER
);
wp_enqueue_style( 'wcpay-subscriptions-plugin-styles' );
}
/**
* Enqueues templates for plugin deactivation warnings on the admin plugin screen.
*/
public function output_notice_template() {
if ( $this->is_admin_plugins_screen() ) {
wc_get_template( 'html-subscriptions-plugin-notice.php', [], '', dirname( __DIR__ ) . '/subscriptions/templates/' );
wc_get_template( 'html-wcpay-deactivate-warning.php', [], '', dirname( __DIR__ ) . '/subscriptions/templates/' );
}
}
}