PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.2
YayMail – WooCommerce Email Customizer v4.3.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.3.2, at src/Notices/NoticeMain.php

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