PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 4.0.0
WP 2FA – Two-factor authentication for WordPress v4.0.0
4.0.0 1.7.1 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.8.0 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0 3.0.1 3.1.0 3.1.1 3.1.1.2 trunk 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.7.0
wp-2fa / includes / classes / Admin / class-free-support-notice.php
wp-2fa / includes / classes / Admin Last commit date
AdminSettings 5 days ago Controllers 5 days ago Fly-Out 5 days ago Helpers 5 days ago Methods 5 days ago Settings 5 days ago SettingsPages 5 days ago Views 5 days ago class-about-us.php 5 days ago class-docs-and-support.php 5 days ago class-free-support-notice.php 5 days ago class-help-contact-us.php 5 days ago class-license-page.php 5 days ago class-new-interface-notice.php 5 days ago class-plugin-updated-notice.php 5 days ago class-premium-features.php 5 days ago class-profile-section-renderer.php 5 days ago class-settings-page.php 5 days ago class-setup-wizard.php 5 days ago class-top-bar-banner.php 5 days ago class-user-listing.php 5 days ago class-user-notices.php 5 days ago class-user-profile.php 5 days ago class-user-registered.php 5 days ago class-wizard-integration.php 5 days ago index.php 5 days ago
class-free-support-notice.php
201 lines
1 <?php
2 /**
3 * Shows a support notice banner to free users on the new interface.
4 *
5 * @package wp2fa
6 * @subpackage admin
7 * @copyright 2026 Melapress
8 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
9 * @link https://wordpress.org/plugins/wp-2fa/
10 */
11
12 declare(strict_types=1);
13
14 namespace WP2FA\Admin;
15
16 use WP2FA\Utils\Settings_Utils;
17 use WP2FA\Admin\Helpers\WP_Helper;
18 use WP2FA\Admin\Settings_Page;
19 use WP2FA\Licensing\Licensing_Factory;
20
21 defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
22
23 if ( ! class_exists( '\WP2FA\Admin\Free_Support_Notice' ) ) {
24
25 /**
26 * Displays a dismissible info banner offering free email support to free edition users
27 * who are using the new interface (fresh installs or upgrades that switched).
28 *
29 * @since 4.0.0
30 */
31 class Free_Support_Notice {
32
33 /**
34 * Option name for dismiss state.
35 *
36 * @var string
37 */
38 private const DISMISS_OPTION = 'wp_2fa_free_support_notice_dismissed';
39
40 /**
41 * Initialize hooks.
42 *
43 * @return void
44 */
45 public static function init() {
46 // Only for free users.
47 if ( Licensing_Factory::has_active_valid_license() ) {
48 return;
49 }
50
51 // Only when new interface is enabled.
52 if ( ! Settings_Page::is_new_interface_enabled() ) {
53 return;
54 }
55
56 // Already dismissed.
57 if ( Settings_Utils::get_option( self::DISMISS_OPTION, false ) ) {
58 return;
59 }
60
61 \add_action( 'admin_notices', array( __CLASS__, 'render_banner' ) );
62 \add_action( 'network_admin_notices', array( __CLASS__, 'render_banner' ) );
63 \add_action( 'wp_ajax_wp2fa_dismiss_free_support_notice', array( __CLASS__, 'ajax_dismiss' ) );
64 }
65
66 /**
67 * AJAX handler to dismiss the banner.
68 *
69 * @return void
70 */
71 public static function ajax_dismiss() {
72 $nonce = isset( $_POST['nonce'] ) ? \sanitize_text_field( \wp_unslash( $_POST['nonce'] ) ) : '';
73
74 if ( ! \current_user_can( 'manage_options' ) || ! \wp_verify_nonce( $nonce, 'wp2fa_free_support_notice' ) ) {
75 \wp_send_json_error( \esc_html__( 'Nonce verification failed.', 'wp-2fa' ) );
76 }
77
78 Settings_Utils::update_option( self::DISMISS_OPTION, true );
79
80 \wp_send_json_success();
81 }
82
83 /**
84 * Renders the banner on plugin admin pages.
85 *
86 * @return void
87 */
88 public static function render_banner() {
89 if ( ! \current_user_can( 'manage_options' ) ) {
90 return;
91 }
92
93 // Only show on WP 2FA plugin pages.
94 $screen = \get_current_screen();
95 if ( ! $screen || ! \in_array( $screen->id, WP_Helper::PLUGIN_PAGES, true ) ) {
96 return;
97 }
98
99 $nonce = \wp_create_nonce( 'wp2fa_free_support_notice' );
100 ?>
101 <div class="wp2fa-free-support-banner" id="wp2fa-free-support-banner">
102 <div class="wp2fa-free-support-banner__content">
103 <span class="wp2fa-free-support-banner__icon" aria-hidden="true">
104 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
105 <path d="M10 0C4.477 0 0 4.477 0 10s4.477 10 10 10 10-4.477 10-10S15.523 0 10 0zm1 15H9v-2h2v2zm0-4H9V5h2v6z" fill="#2271b1"/>
106 </svg>
107 </span>
108 <div class="wp2fa-free-support-banner__text">
109 <strong><?php \esc_html_e( 'New interface. We\'re here to help.', 'wp-2fa' ); ?></strong>
110 <span>
111 <?php
112 printf(
113 /* translators: %s: email link */
114 \esc_html__( 'WP 2FA 4.0 now has a completely redesigned interface. To help with the transition, we\'re temporarily offering free one-to-one email support to all users, including the free edition users. Contact us on %s if you need any assistance.', 'wp-2fa' ),
115 '<a href="mailto:support@melapress.com">support@melapress.com</a>'
116 );
117 ?>
118 </span>
119 </div>
120 </div>
121 <button type="button" class="wp2fa-free-support-banner__close" id="wp2fa-free-support-banner-close" aria-label="<?php \esc_attr_e( 'Dismiss', 'wp-2fa' ); ?>">&times;</button>
122 </div>
123 <style>
124 .wp2fa-free-support-banner {
125 display: flex;
126 align-items: flex-start;
127 justify-content: space-between;
128 background: #f0f6fc;
129 border: 1px solid #c3c4c7;
130 border-left-color: #2271b1;
131 border-left-width: 4px;
132 border-radius: 2px;
133 padding: 12px 16px;
134 margin: 10px 20px 16px 0;
135 gap: 12px;
136 }
137 .wp2fa-free-support-banner__content {
138 display: flex;
139 align-items: flex-start;
140 gap: 10px;
141 flex: 1;
142 min-width: 0;
143 }
144 .wp2fa-free-support-banner__icon {
145 flex-shrink: 0;
146 margin-top: 2px;
147 }
148 .wp2fa-free-support-banner__icon svg {
149 display: block;
150 }
151 .wp2fa-free-support-banner__text {
152 font-size: 13px;
153 color: #50575e;
154 line-height: 1.6;
155 }
156 .wp2fa-free-support-banner__text strong {
157 display: block;
158 color: #1d2327;
159 font-size: 14px;
160 margin-bottom: 2px;
161 }
162 .wp2fa-free-support-banner__text a {
163 color: #2271b1;
164 text-decoration: underline;
165 }
166 .wp2fa-free-support-banner__close {
167 background: none;
168 border: none;
169 font-size: 20px;
170 line-height: 1;
171 color: #787c82;
172 cursor: pointer;
173 padding: 4px 8px;
174 border-radius: 3px;
175 flex-shrink: 0;
176 }
177 .wp2fa-free-support-banner__close:hover,
178 .wp2fa-free-support-banner__close:focus {
179 color: #1d2327;
180 background: #dcdcde;
181 outline: none;
182 }
183 </style>
184 <script>
185 (function() {
186 var banner = document.getElementById('wp2fa-free-support-banner');
187 if (!banner) return;
188 document.getElementById('wp2fa-free-support-banner-close').addEventListener('click', function() {
189 banner.style.display = 'none';
190 var xhr = new XMLHttpRequest();
191 xhr.open('POST', '<?php echo \esc_url( \admin_url( 'admin-ajax.php' ) ); ?>', true);
192 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
193 xhr.send('action=wp2fa_dismiss_free_support_notice&nonce=' + encodeURIComponent('<?php echo \esc_attr( $nonce ); ?>'));
194 });
195 })();
196 </script>
197 <?php
198 }
199 }
200 }
201