PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.8.0
WP 2FA – Two-factor authentication for WordPress v2.8.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-plugin-updated-notice.php
wp-2fa / includes / classes / Admin Last commit date
Controllers 1 year ago Fly-Out 1 year ago Helpers 1 year ago Methods 1 year ago SettingsPages 1 year ago Views 1 year ago class-help-contact-us.php 1 year ago class-plugin-updated-notice.php 1 year ago class-premium-features.php 1 year ago class-settings-page.php 1 year ago class-setup-wizard.php 1 year ago class-user-listing.php 1 year ago class-user-notices.php 1 year ago class-user-profile.php 1 year ago class-user-registered.php 1 year ago index.php 1 year ago
class-plugin-updated-notice.php
132 lines
1 <?php
2 /**
3 * Responsible for WP2FA update notices.
4 *
5 * @package wp2fa
6 * @subpackage user-utils
7 * @copyright 2024 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\Utils\Settings_Utils;
15
16 /**
17 * Plugin_Updated_Notice class with user notification filters
18 *
19 * @since 2.7.0
20 */
21 if ( ! class_exists( '\WP2FA\Admin\Plugin_Updated_Notice' ) ) {
22 /**
23 * Plugin_Updated_Notice - Class for displaying notices to our users.
24 */
25 class Plugin_Updated_Notice {
26
27 /**
28 * Lets set things up
29 *
30 * @since 2.7.0
31 */
32 public static function init() {
33 add_action( 'admin_init', array( __CLASS__, 'on_plugin_update' ), 10 );
34 add_action( 'admin_notices', array( __CLASS__, 'plugin_update_banner' ) );
35 add_action( 'network_admin_notices', array( __CLASS__, 'plugin_update_banner' ) );
36 add_action( 'wp_ajax_dismiss_update_notice', array( __CLASS__, 'dismiss_update_notice' ) );
37 }
38
39 /**
40 * The nag content
41 *
42 * @since 2.7.0
43 * @return void
44 */
45 public static function plugin_update_banner() {
46 $screen = get_current_screen();
47 $correct_screen = ( 'toplevel_page_wp-2fa-policies-network' === $screen->base || 'toplevel_page_wp-2fa-policies' === $screen->base ) ? true : false;
48
49 if ( $correct_screen && Settings_Utils::get_option( 'wp_2fa_update_notice_needed', false ) ) {
50 /* translators: %s: version number. */
51 printf( '<div id="wp_2fa_update_notice" class="notice notice-success is-dismissible"><img src="' . esc_url( WP_2FA_URL . 'dist/images/wp-2fa-square.png' ) . '"><p><strong>' . esc_html__( 'Thank you for updating WP 2FA.', 'wp-2fa' ) . '</strong></p><p>' . esc_html__( 'This is version %s. Check out the release notes to see what is new and improved in this update.', 'wp-2fa' ) . '</p><a href="https://melapress.com/wordpress-2fa/releases/" target="_blank" class="button button-primary dismiss_update_notice" data-dismiss-nonce="%2s">' . esc_html__( 'Release notes', 'wp-2fa' ) . '</a></p></div>', WP_2FA_VERSION, wp_create_nonce( 'wp_2fa_dismiss_update_notice_nonce' ) );
52 ?>
53 <script type="text/javascript">
54 //<![CDATA[
55 jQuery(document).ready(function( $ ) {
56 jQuery( 'body' ).on( 'click', 'a.dismiss_update_notice, #wp_2fa_update_notice .notice-dismiss', function ( e ) {
57 var nonce = jQuery( '#wp_2fa_update_notice [data-dismiss-nonce]' ).attr( 'data-dismiss-nonce' );
58
59 jQuery.ajax({
60 type: 'POST',
61 url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
62 async: true,
63 data: {
64 action: 'dismiss_update_notice',
65 nonce : nonce,
66 },
67 success: function ( result ) {
68 jQuery( '#wp_2fa_update_notice' ).slideUp( 300 );
69 }
70 });
71 });
72 });
73 //]]>
74 </script>
75 <style>
76 #wp_2fa_update_notice {
77 border: 2px solid #0f5cf2
78 }
79 #wp_2fa_update_notice .button-primary {
80 background: #0f5cf2;
81 border-color: #0f5cf2;
82 }
83 #wp_2fa_update_notice img {
84 float: left;
85 max-width: 100px;
86 margin: 10px 12px 10px 0;
87 }
88 </style>
89 <?php
90 }
91 }
92
93 /**
94 * Redirects user to admin on plugin update.
95 *
96 * @since 2.7.0
97 * @return void
98 */
99 public static function on_plugin_update() {
100 if ( Settings_Utils::get_option( 'wp_2fa_update_redirection_needed', false ) ) {
101 delete_site_option( 'wp_2fa_update_redirection_needed' );
102 update_site_option( 'wp_2fa_update_notice_needed', true );
103 $args = array(
104 'page' => 'wp-2fa-policies',
105 );
106 $url = add_query_arg( $args, network_admin_url( 'admin.php' ) );
107 wp_safe_redirect( $url );
108 exit;
109 }
110 }
111
112 /**
113 * Handle notice dismissal.
114 *
115 * @since 2.7.0
116 * @return void
117 */
118 public static function dismiss_update_notice() {
119 // Grab POSTed data.
120 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : false;
121 // Check nonce.
122 if ( ! current_user_can( 'manage_options' ) || empty( $nonce ) || ! $nonce || ! wp_verify_nonce( $nonce, 'wp_2fa_dismiss_update_notice_nonce' ) ) {
123 wp_send_json_error( esc_html__( 'Nonce Verification Failed.', 'wp-2fa' ) );
124 }
125
126 delete_site_option( 'wp_2fa_update_notice_needed' );
127
128 wp_send_json_success( esc_html__( 'Complete.', 'wp-2fa' ) );
129 }
130 }
131 }
132