/var/www/html_us/wp-content/plugins/wp-smtp/src/Mail/Admin/Notice.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php

namespace SolidWP\Mail\Admin;

use 
SolidWP\Mail\Migration\MigrationVer210;

/**
 * Class Notice
 *
 * Handles the display and dismissal of admin notices for the Solid Mail plugin.
 *
 * @package SolidWP\Mail\Admin
 */
class Notice {

    
/**
     * Meta key to store the dismissed state of the new ownership notice.
     *
     * @var string
     */
    
private string $new_ownership_flag 'solid_mail_notice_new_ownership_dismissed';

    
/**
     * Meta key to store the dismissed state of the migration error notice.
     *
     * @var string
     */
    
private string $migration_error_flag 'solid_mail_notice_migration_error_dismissed';

    
/**
     * Meta key to store the dismissed state of the solid 2.0.0 to 2.1.0 error.
     *
     * @var string
     */
    
private string $migration_200_211_error_flag 'solid_mail_notice_migration_200_211_error_dismissed';

    
/**
     * Handles the AJAX request to dismiss the admin notice.
     *
     * @return void
     */
    
public function dismiss_notice() {
        
$nonce sanitize_text_field$_POST['_wpnonce'] ?? '' );

        
// Verify nonce and return an error if verification fails
        
if ( empty( $nonce ) || ! wp_verify_nonce$nonce'dismiss_solid_mail_notice' ) ) {
            
wp_send_json_error();
        }

        
$flag sanitize_text_field$_POST['flag'] ?? '' );

        
// make sure the flag is allowed before saving.
        
if ( ! empty( $flag )
            && 
in_array(
                
$flag,
                [
                    
$this->new_ownership_flag,
                    
$this->migration_error_flag,
                    
$this->migration_200_211_error_flag,
                ],
                
true
            
)
        ) {
            
update_user_metaget_current_user_id(), $flagtrue );
            
wp_send_json_success();
        }

        
wp_send_json_error();
    }

    
/**
     * Displays the admin notice for the migration issue in version 2.1.0.
     *
     * @return void
     */
    
public function maybe_display_notice_200_211_error() {
        
// Only admin should see this.
        
if ( ! current_user_can'manage_options' ) ) {
            return;
        }

        
// Get the stored migration error message.
        
$flag get_optionMigrationVer210::FLAG_NAME'' );

        
// Check if the user has dismissed the notice or if there is no error.
        
if ( 'yes' !== $flag || get_user_metaget_current_user_id(), $this->migration_200_211_error_flagtrue ) ) {
            return;
        }

        
$nonce wp_create_nonce'dismiss_solid_mail_notice' );
        
?>
        <div class="notice notice-error is-dismissible solid-mail-migration-error-notice">
            <p>
                <?php
                printf
(
                        
/* translators: %s: URL to the legacy settings page */
                    
__// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                        
'There was an issue in version 2.1.0 which affected a small subset of users by erroneously deactivating the Active Connection toggle on the Email Connections Page at Solid Mail → Solid Mail. Please ensure that your active connection is still correctly enabled. <a href="%s">Verify your settings</a>',
                        
'LION'
                    
), // phpcs:ignore StellarWP.XSS.EscapeOutput.OutputNotEscaped
                    
esc_urladmin_url'admin.php?page=solidwp-mail#/providers/edit/legacy_smtp_id' ) )
                )
                
?>
            </p>
        </div>
        <script type="text/javascript">
            ( function ( $ ) {
                $( document ).on( 'click', '.solid-mail-migration-error-notice .notice-dismiss', function () {
                    $.post( ajaxurl, {
                        action: 'dismiss_solid_mail_notice',
                        _wpnonce: '<?= esc_html$nonce ); ?>',
                        flag: '<?= esc_html$this->migration_200_211_error_flag ); ?>'
                    } );
                } );
            } )( jQuery );
        </script>
        <?php
    
}

    
/**
     * Displays the admin notice informing users about the new ownership.
     *
     * Checks if the notice has been dismissed by the current user. If not,
     * it outputs the HTML for the notice and a script to handle its dismissal
     * via AJAX.
     *
     * @return void
     */
    
public function display_notice_new_ownership() {
        
// only admin should see this.
        
if ( ! current_user_can'manage_options' ) ) {
            return;
        }
        
// Check if the user has dismissed the notice
        
if ( get_user_metaget_current_user_id(), $this->new_ownership_flagtrue ) ) {
            return;
        }

        
$nonce wp_create_nonce'dismiss_solid_mail_notice' );
        
?>
        <div class="notice notice-info is-dismissible solid-mail-notice">
            <p><?php esc_html_e'WP SMTP is now Solid Mail and is being maintained and supported by the team from SolidWP.''LION' ); ?>
                <a href="https://go.solidwp.com/wp-smtp-is-now-solid-mail"
                    target="_blank"><?php esc_html_e'Learn more.''LION' ); ?></a>
            </p>
        </div>
        <script type="text/javascript">
            ( function ( $ ) {
                $( document ).on( 'click', '.solid-mail-notice .notice-dismiss', function () {
                    $.post( ajaxurl, {
                        action: 'dismiss_solid_mail_notice',
                        _wpnonce: '<?= esc_attr$nonce ); ?>',
                        flag: '<?= esc_attr$this->new_ownership_flag ); ?>'
                    } );
                } );
            } )( jQuery );
        </script>
        <?php
    
}

    
/**
     * Displays the admin notice if there's a migration error.
     *
     * Checks if the migration error notice has been dismissed by the current user. If not,
     * it outputs the HTML for the notice and a script to handle its dismissal via AJAX.
     *
     * @return void
     */
    
public function display_notice_migration_error() {
        
// Only admin should see this.
        
if ( ! current_user_can'manage_options' ) ) {
            return;
        }

        
// Get the stored migration error message.
        
$migration_error get_option'solid_mail_migration_error''' );

        
// Check if the user has dismissed the notice or if there is no error.
        
if ( empty( $migration_error ) || get_user_metaget_current_user_id(), $this->migration_error_flagtrue ) ) {
            return;
        }

        
$nonce wp_create_nonce'dismiss_solid_mail_notice' );
        
?>
        <div class="notice notice-error is-dismissible solid-mail-migration-error-notice">
            <p><?php esc_html_e'There was an error during the migration process: ''LION' ); ?>
                <?php echo esc_html$migration_error ); ?></p>
        </div>
        <script type="text/javascript">
            ( function ( $ ) {
                $( document ).on( 'click', '.solid-mail-migration-error-notice .notice-dismiss', function () {
                    $.post( ajaxurl, {
                        action: 'dismiss_solid_mail_notice',
                        _wpnonce: '<?= esc_html$nonce ); ?>',
                        flag: '<?= esc_html$this->migration_error_flag ); ?>'
                    } );
                } );
            } )( jQuery );
        </script>
        <?php
    
}
}