PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.2
YayMail – WooCommerce Email Customizer v4.4.2
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / Notices / NoticeMain.php

NoticeMain.php in YayMail – WooCommerce Email Customizer 4.4.2, at src/Notices/NoticeMain.php

167 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Notices;
4
5 use YayMail\Utils\SingletonTrait;
6 use YayMail\Notices\Ajax;
7 use YayMail\SupportedPlugins;
8 use YayMail\Utils\Logger;
9
10 /**
11 *
12 * @method static NoticeMain get_instance()
13 */
14 class NoticeMain {
15 use SingletonTrait;
16
17 private $logger;
18
19 private $supported_plugins;
20
21 protected function __construct() {
22 $this->logger = new Logger();
23
24 Ajax::get_instance();
25
26 $this->supported_plugins = SupportedPlugins::get_instance();
27
28 $this->init_hooks();
29 }
30
31 protected function init_hooks() {
32 if ( ! function_exists( 'YayMail\init' ) ) {
33 return;
34 }
35 // Show recommendation notice
36 if ( time() >= (int) get_option( 'yaymail_next_recommendation_suggest_addons_notice_time' ) ) {
37 add_action( 'admin_notices', [ $this, 'render_suggest_addons_notice' ] );
38 }
39
40 if ( time() >= (int) get_option( 'yaymail_next_recommendation_upgrade_notice_time' ) ) {
41 add_action( 'admin_notices', [ $this, 'render_upgrade_notice' ] );
42 }
43
44 if ( is_admin() ) {
45 if ( time() >= (int) get_option( 'yaymail_next_recommendation_notice_time' ) || time() >= (int) get_option( 'yaymail_next_recommendation_suggest_addons_notice_time' ) || time() >= (int) get_option( 'yaymail_next_recommendation_upgrade_notice_time' ) ) {
46 wp_enqueue_script( 'yaymail-notice', YAYMAIL_PLUGIN_URL . 'assets/scripts/notice.js', [ 'jquery' ], yaymail_version(), false );
47 }
48
49 wp_localize_script(
50 'yaymail-notice',
51 'yaymail_notice',
52 [
53 'admin_ajax' => admin_url( 'admin-ajax.php' ),
54 'nonce' => wp_create_nonce( 'yaymail_nonce' ),
55 ]
56 );
57 }
58
59 add_action(
60 'after_plugin_row_' . YAYMAIL_PLUGIN_BASENAME,
61 [ $this, 'display_under_plugin_notices' ],
62 10,
63 2
64 );
65 }
66
67
68
69 public function display_under_plugin_notices( $plugin_file ) {
70
71 $plugins = get_plugins();
72
73 $yaymail_addons = array_filter(
74 $plugins,
75 function ( $key ) use ( $plugins ) {
76 if ( ! is_string( $key ) ) {
77 return false;
78 }
79 $plugin_data = $plugins[ $key ];
80 $is_yaycommerce_author = isset( $plugin_data['Author'] ) && strpos( $plugin_data['Author'], 'YayCommerce' ) !== false;
81
82 $is_yay_wp = strpos( $key, 'yay-wp-email' ) !== false;
83 return $is_yaycommerce_author && (
84 strpos( $key, 'yaymail-addon' ) !== false ||
85 strpos( $key, 'email-customizer' ) !== false ||
86 strpos( $key, 'yaymail-premium-addon' ) !== false ||
87 strpos( $key, 'yaymail-conditional-logic' ) !== false
88 ) && ! $is_yay_wp;
89 },
90 ARRAY_FILTER_USE_KEY
91 );
92
93 $addon_info = [];
94 foreach ( $yaymail_addons as $plugin_path => $plugin_data ) {
95 if ( is_plugin_active( $plugin_path ) && version_compare( $plugin_data['Version'], '4.0', '<' ) ) {
96 $addon_info[] = [
97 'name' => $plugin_data['Name'],
98 'version' => $plugin_data['Version'],
99 ];
100 }
101 }
102
103 if ( empty( $addon_info ) ) {
104 return;
105 }
106
107 $wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
108
109 add_action( 'admin_footer', [ $this, 'enqueue_admin_script' ] );
110
111 echo wp_kses_post(
112 '<tr class="plugin-update-tr' . ( is_plugin_active( $plugin_file ) ? ' active' : '' ) . '">
113 <td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange">'
114 . $this->get_addon_update_notice()
115 . '</td>
116 </tr>'
117 );
118 }
119
120 /**
121 * Enqueues a script to modify the plugin row styling in the admin footer.
122 */
123 public function enqueue_admin_script() {
124 ?>
125 <script>
126 document.addEventListener('DOMContentLoaded', function() {
127 var pluginRow = document.querySelector('tr[data-plugin="<?php echo esc_js( YAYMAIL_PLUGIN_BASENAME ); ?>"]');
128 if (pluginRow) pluginRow.classList.add('update');
129 });
130 </script>
131 <?php
132 }
133
134 /**
135 * Returns the notice to update to new core version.
136 */
137 protected function get_addon_update_notice() {
138 return sprintf(
139 '<div class="notice inline notice-error notice-alt"><p>%s</p></div>',
140 esc_html__( 'Please update the YayMail Addons to version 4.0 or later to ensure compatibility and optimal performance.', 'yaymail' ),
141 );
142 }
143
144 public function render_suggest_addons_notice() {
145 /* List out the 3rd-party that need our addon*/
146 $addon_needed_plugins = [];
147 foreach ( $this->supported_plugins->get_addon_supported_plugins() as $addon_namespace => $addon ) {
148 if ( ! empty( $addon['is_3rd_party_installed'] ) && empty( $addon['installation_status']['is_active'] ) ) {
149 $addon_needed_plugins[ $addon_namespace ] = $addon;
150 }
151 }
152
153 if ( ! empty( $addon_needed_plugins ) ) {
154 include YAYMAIL_PLUGIN_PATH . 'templates/notices/suggest-addons.php';
155 }
156 }
157
158 public function render_upgrade_notice() {
159
160 $pro_needed_plugins = $this->supported_plugins->get_pro_supported_plugins();
161
162 if ( ! empty( $pro_needed_plugins ) ) {
163 include YAYMAIL_PLUGIN_PATH . 'templates/notices/upgrade.php';
164 }
165 }
166 }
167