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-top-bar-banner.php
wp-2fa / includes / classes / Admin Last commit date
AdminSettings 6 days ago Controllers 6 days ago Fly-Out 6 days ago Helpers 6 days ago Methods 6 days ago Settings 6 days ago SettingsPages 6 days ago Views 6 days ago class-about-us.php 6 days ago class-docs-and-support.php 6 days ago class-free-support-notice.php 6 days ago class-help-contact-us.php 6 days ago class-license-page.php 6 days ago class-new-interface-notice.php 6 days ago class-plugin-updated-notice.php 6 days ago class-premium-features.php 6 days ago class-profile-section-renderer.php 6 days ago class-settings-page.php 6 days ago class-setup-wizard.php 6 days ago class-top-bar-banner.php 6 days ago class-user-listing.php 6 days ago class-user-notices.php 6 days ago class-user-profile.php 6 days ago class-user-registered.php 6 days ago class-wizard-integration.php 6 days ago index.php 6 days ago
class-top-bar-banner.php
161 lines
1 <?php
2 /**
3 * Top bar banner displayed on all WP 2FA admin pages.
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 namespace WP2FA\Admin;
13
14 use WP2FA\Admin\Helpers\WP_Helper;
15 use WP2FA\Licensing\Licensing_Factory;
16
17 if ( ! class_exists( '\WP2FA\Admin\Top_Bar_Banner' ) ) {
18 /**
19 * Top_Bar_Banner - Renders a persistent top bar on all plugin admin pages.
20 *
21 * @since 4.0.0
22 */
23 class Top_Bar_Banner {
24
25 /**
26 * Initialize the top bar banner hooks.
27 *
28 * @return void
29 *
30 * @since 4.0.0
31 */
32 public static function init() {
33 \add_action( 'in_admin_header', array( __CLASS__, 'render' ) );
34 \add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_styles' ) );
35 }
36
37 /**
38 * Enqueue the top bar CSS only on plugin pages.
39 *
40 * @return void
41 *
42 * @since 4.0.0
43 */
44 public static function enqueue_styles() {
45 $screen = \get_current_screen();
46 if ( ! $screen || ! \in_array( $screen->base, WP_Helper::PLUGIN_PAGES, true ) ) {
47 return;
48 }
49
50 \wp_enqueue_style(
51 'wp2fa-top-bar-banner',
52 WP_2FA_URL . 'includes/assets/css/top-bar-banner.css',
53 array(),
54 WP_2FA_VERSION
55 );
56 }
57
58 /**
59 * Render the top bar banner.
60 *
61 * @return void
62 *
63 * @since 4.0.0
64 */
65 public static function render() {
66 $screen = \get_current_screen();
67 if ( ! $screen || ! \in_array( $screen->base, WP_Helper::PLUGIN_PAGES, true ) ) {
68 return;
69 }
70
71 $is_premium = self::is_premium();
72 $update_info = self::get_update_info();
73 $has_update = ! empty( $update_info );
74 $update_url = $has_update ? self::get_update_url() : '';
75 $new_version = $has_update ? $update_info['new_version'] : '';
76 $release_url = 'https://melapress.com/wordpress-2fa/releases/?#utm_source=plugin&utm_medium=wp2fa&utm_campaign=topbar_releasenotes';
77 $changelog_url = 'https://melapress.com/support/kb/wp-2fa-plugin-changelog/?#utm_source=plugin&utm_medium=wp2fa&utm_campaign=topbar_changelog';
78 $upgrade_url = 'https://melapress.com/wordpress-2fa/pricing/?utm_source=plugin&utm_medium=wp2fa&utm_campaign=upgrade_to_premium_top_banner';
79 ?>
80 <div id="wp2fa-top-bar-banner">
81 <div class="wp2fa-top-bar-inner">
82 <div class="wp2fa-top-bar-left">
83 <img src="<?php echo \esc_url( WP_2FA_URL . 'dist/images/wizard-logo.png' ); ?>" alt="WP 2FA" class="wp2fa-top-bar-logo">
84 <span class="wp2fa-top-bar-title">WP 2FA</span>
85 <?php if ( $has_update ) : ?>
86 <span class="wp2fa-top-bar-update-badge">
87 <span class="wp2fa-update-dot"></span>
88 <?php
89 printf(
90 /* translators: %s: new version number */
91 \esc_html__( 'Version %s available!', 'wp-2fa' ),
92 \esc_html( $new_version )
93 );
94 ?>
95 <a href="<?php echo \esc_url( $update_url ); ?>" class="wp2fa-update-link"><?php \esc_html_e( 'Update Now', 'wp-2fa' ); ?></a>
96 </span>
97 <?php endif; ?>
98 </div>
99 <div class="wp2fa-top-bar-right">
100 <span class="wp2fa-top-bar-version"><?php echo \esc_html( 'v.' . WP_2FA_VERSION ); ?></span>
101 <span class="wp2fa-top-bar-separator">|</span>
102 <a href="<?php echo \esc_url( $release_url ); ?>" class="wp2fa-top-bar-link" target="_blank" rel="noopener noreferrer"><?php \esc_html_e( 'Release Notes', 'wp-2fa' ); ?></a>
103 <span class="wp2fa-top-bar-separator">|</span>
104 <a href="<?php echo \esc_url( $changelog_url ); ?>" class="wp2fa-top-bar-link" target="_blank" rel="noopener noreferrer"><?php \esc_html_e( 'Changelog', 'wp-2fa' ); ?></a>
105 <?php if ( ! $is_premium ) : ?>
106 <a href="<?php echo \esc_url( $upgrade_url ); ?>" class="wp2fa-top-bar-upgrade" target="_blank" rel="noopener noreferrer"><?php \esc_html_e( 'Upgrade to Premium', 'wp-2fa' ); ?></a>
107 <?php endif; ?>
108 </div>
109 </div>
110 </div>
111 <?php
112 }
113
114 /**
115 * Check if the current installation is premium.
116 *
117 * @return bool
118 *
119 * @since 4.0.0
120 */
121 private static function is_premium(): bool {
122 if ( class_exists( '\WP2FA\Licensing\Licensing_Factory' ) ) {
123 return Licensing_Factory::has_active_valid_license();
124 }
125 return false;
126 }
127
128 /**
129 * Get plugin update information if available.
130 *
131 * @return array Empty array if no update, otherwise contains 'new_version'.
132 *
133 * @since 4.0.0
134 */
135 private static function get_update_info(): array {
136 $update_plugins = \get_site_transient( 'update_plugins' );
137 if ( ! empty( $update_plugins->response ) && isset( $update_plugins->response[ WP_2FA_BASE ] ) ) {
138 $plugin_data = $update_plugins->response[ WP_2FA_BASE ];
139 return array(
140 'new_version' => isset( $plugin_data->new_version ) ? $plugin_data->new_version : '',
141 );
142 }
143 return array();
144 }
145
146 /**
147 * Get the URL to trigger the plugin update.
148 *
149 * @return string
150 *
151 * @since 4.0.0
152 */
153 private static function get_update_url(): string {
154 return \wp_nonce_url(
155 \self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . WP_2FA_BASE ),
156 'upgrade-plugin_' . WP_2FA_BASE
157 );
158 }
159 }
160 }
161