PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.6
YayMail – WooCommerce Email Customizer v4.4.6
4.4.6 4.4.5 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 All 57 releases
yaymail / src / Notices / NoticeMain.php

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

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