| @@ -4,9 +4,8 @@ | ||
| 4 | 4 | |
| 5 | 5 | use YayMail\Utils\SingletonTrait; |
| 6 | 6 | use YayMail\Notices\Ajax; |
| 7 | 7 | use YayMail\SupportedPlugins; |
| 8 | -use YayMail\Utils\Logger; | |
| 9 | 8 | |
| 10 | 9 | /** |
| 11 | 10 | * |
| 12 | 11 | * @method static NoticeMain get_instance() |
| @@ -13,19 +12,11 @@ | ||
| 13 | 12 | */ |
| 14 | 13 | class NoticeMain { |
| 15 | 14 | use SingletonTrait; |
| 16 | 15 | |
| 17 | - private $logger; | |
| 18 | - | |
| 19 | - private $supported_plugins; | |
| 20 | - | |
| 21 | 16 | protected function __construct() { |
| 22 | - $this->logger = new Logger(); | |
| 23 | - | |
| 24 | 17 | Ajax::get_instance(); |
| 25 | 18 | |
| 26 | - $this->supported_plugins = SupportedPlugins::get_instance(); | |
| 27 | - | |
| 28 | 19 | $this->init_hooks(); |
| 29 | 20 | } |
| 30 | 21 | |
| 31 | 22 | protected function init_hooks() { |
| @@ -32,31 +23,13 @@ | ||
| 32 | 23 | if ( ! function_exists( 'YayMail\init' ) ) { |
| 33 | 24 | return; |
| 34 | 25 | } |
| 35 | 26 | // 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' ] ); | |
| 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' ] ); | |
| 38 | 30 | } |
| 39 | 31 | |
| 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 | 32 | add_action( |
| 60 | 33 | 'after_plugin_row_' . YAYMAIL_PLUGIN_BASENAME, |
| 61 | 34 | [ $this, 'display_under_plugin_notices' ], |
| 62 | 35 | 10, |
| @@ -78,15 +51,15 @@ | ||
| 78 | 51 | } |
| 79 | 52 | $plugin_data = $plugins[ $key ]; |
| 80 | 53 | $is_yaycommerce_author = isset( $plugin_data['Author'] ) && strpos( $plugin_data['Author'], 'YayCommerce' ) !== false; |
| 81 | 54 | |
| 82 | - $is_yay_wp = strpos( $key, 'yay-wp-email' ) !== false; | |
| 55 | + $is_yaymagic_email_builder = strpos( $key, 'yaymagic-email-builder' ) !== false; | |
| 83 | 56 | return $is_yaycommerce_author && ( |
| 84 | 57 | strpos( $key, 'yaymail-addon' ) !== false || |
| 85 | 58 | strpos( $key, 'email-customizer' ) !== false || |
| 86 | 59 | strpos( $key, 'yaymail-premium-addon' ) !== false || |
| 87 | 60 | strpos( $key, 'yaymail-conditional-logic' ) !== false |
| 88 | - ) && ! $is_yay_wp; | |
| 61 | + ) && ! $is_yaymagic_email_builder; | |
| 89 | 62 | }, |
| 90 | 63 | ARRAY_FILTER_USE_KEY |
| 91 | 64 | ); |
| 92 | 65 | |
| @@ -121,15 +94,16 @@ | ||
| 121 | 94 | * Enqueues a script to modify the plugin row styling in the admin footer. |
| 122 | 95 | */ |
| 123 | 96 | public function enqueue_admin_script() { |
| 124 | 97 | ?> |
| 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 | |
| 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 | |
| 132 | 106 | } |
| 133 | 107 | |
| 134 | 108 | /** |
| 135 | 109 | * Returns the notice to update to new core version. |
| @@ -140,12 +114,31 @@ | ||
| 140 | 114 | esc_html__( 'Please update the YayMail Addons to version 4.0 or later to ensure compatibility and optimal performance.', 'yaymail' ), |
| 141 | 115 | ); |
| 142 | 116 | } |
| 143 | 117 | |
| 144 | - public function render_suggest_addons_notice() { | |
| 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 | + } | |
| 145 | 138 | /* List out the 3rd-party that need our addon*/ |
| 146 | 139 | $addon_needed_plugins = []; |
| 147 | - foreach ( $this->supported_plugins->get_addon_supported_plugins() as $addon_namespace => $addon ) { | |
| 140 | + foreach ( SupportedPlugins::get_instance()->get_addon_supported_plugins() as $addon_namespace => $addon ) { | |
| 148 | 141 | if ( ! empty( $addon['is_3rd_party_installed'] ) && empty( $addon['installation_status']['is_active'] ) ) { |
| 149 | 142 | $addon_needed_plugins[ $addon_namespace ] = $addon; |
| 150 | 143 | } |
| 151 | 144 | } |
| @@ -162,5 +155,5 @@ | ||
| 162 | 155 | if ( ! empty( $pro_needed_plugins ) ) { |
| 163 | 156 | include YAYMAIL_PLUGIN_PATH . 'templates/notices/upgrade.php'; |
| 164 | 157 | } |
| 165 | 158 | } |
| 166 | -} | |
| 159 | +} | |