| @@ -45,9 +45,15 @@ | ||
| 45 | 45 | '7' => array( |
| 46 | 46 | 'id' => 'basic-auth-plugin-white-list', |
| 47 | 47 | 'title' => __('Ip White list', 'easy-basic-authentication'), |
| 48 | 48 | 'callback' => 'basic_auth_plugin_whitelist_cb', |
| 49 | - ) | |
| 49 | + ), | |
| 50 | + '8' => array( | |
| 51 | + 'id' => 'basic-auth-plugin-remove-data-after-uninstall', | |
| 52 | + 'title' => __('Remove plugin data after uninstall', 'easy-basic-authentication'), | |
| 53 | + 'callback' => 'basic_auth_plugin_remove_data_after_uninstall_cb', | |
| 54 | + ), | |
| 55 | + | |
| 50 | 56 | ); |
| 51 | 57 | } |
| 52 | 58 | |
| 53 | 59 | public function basic_auth_plugin_settings_init() { |
| @@ -95,16 +101,17 @@ | ||
| 95 | 101 | } |
| 96 | 102 | |
| 97 | 103 | public function basic_auth_plugin_username_cb() { |
| 98 | 104 | $username = get_option( 'basic_auth_plugin_username' ); |
| 99 | - $this->printInputText("text","basic_auth_plugin_username",esc_attr( $username )); | |
| 105 | + $this->printInputText("text","basic_auth_plugin_username",esc_attr( $username ),'','off'); | |
| 100 | 106 | } |
| 101 | 107 | |
| 102 | 108 | public function basic_auth_plugin_password_cb() { |
| 103 | - $password = get_option( 'basic_auth_plugin_password' ) | |
| 104 | - ? __('Password entered', 'easy-basic-authentication') | |
| 105 | - : __('Enter the password', 'easy-basic-authentication'); | |
| 106 | - $this->printInputText("password","basic_auth_plugin_password",'',$password); | |
| 109 | + $password = get_option( 'basic_auth_plugin_password' ); | |
| 110 | + ?> | |
| 111 | + <input type="password" name="basic_auth_plugin_password" value="" placeholder="<?php esc_attr_e('Enter the password', 'easy-basic-authentication'); ?>" autocomplete="off"> | |
| 112 | + <p class="description"><?php esc_html_e('Leave blank to keep the current password.', 'easy-basic-authentication'); ?></p> | |
| 113 | + <?php | |
| 107 | 114 | } |
| 108 | 115 | |
| 109 | 116 | public function basic_auth_plugin_admin_log_enable_cb() { |
| 110 | 117 | $enable = get_option( 'basic_auth_plugin_admin_log_enable' ); |
| @@ -129,12 +136,20 @@ | ||
| 129 | 136 | $white_list = get_option( 'basic_auth_plugin_whitelist' ); |
| 130 | 137 | $this->printInputText("text","basic_auth_plugin_whitelist",esc_attr( $white_list ),__('White list, separated by comma', 'easy-basic-authentication')); |
| 131 | 138 | } |
| 132 | 139 | |
| 133 | - public function printInputText($tipe, $name, $value='', $placeholder = '') { | |
| 134 | - echo "<input type='" . esc_attr($tipe) . "' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' placeholder='" . esc_attr($placeholder) . "'>"; | |
| 140 | + public function basic_auth_plugin_remove_data_after_uninstall_cb() { | |
| 141 | + $enable = get_option( 'basic_auth_plugin_remove_data_after_uninstall' ); | |
| 142 | + ?> | |
| 143 | + <input type="checkbox" name="basic_auth_plugin_remove_data_after_uninstall" value="1" <?php checked( $enable, 1 ); ?>> | |
| 144 | + <?php | |
| 135 | 145 | } |
| 136 | 146 | |
| 147 | + public function printInputText($type, $name, $value='', $placeholder = '', $autocomplete = 'off') { | |
| 148 | + echo "<input type='" . esc_attr($type) . "' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' placeholder='" . esc_attr($placeholder) . "' autocomplete='" . esc_attr($autocomplete) . "' >"; | |
| 149 | + } | |
| 150 | + | |
| 151 | + | |
| 137 | 152 | public function basic_auth_plugin_save_settings($param) { |
| 138 | 153 | if ( isset( $param['eba_submit'] ) ) { |
| 139 | 154 | $admin_enable = isset( $param['basic_auth_plugin_admin_enable'] ) ? 1 : 0; |
| 140 | 155 | $enable = isset( $param['basic_auth_plugin_enable'] ) ? 1 : 0; |
| @@ -143,9 +158,25 @@ | ||
| 143 | 158 | $log_enable = isset( $param['basic_auth_plugin_admin_log_enable'] ) ? 1 : 0; |
| 144 | 159 | $alert_enable = isset( $param['basic_auth_plugin_alert_enable'] ) ? 1 : 0; |
| 145 | 160 | $alert_email = sanitize_text_field( $param['basic_auth_plugin_alertemail'] ); |
| 146 | 161 | $white_list = sanitize_text_field( $param['basic_auth_plugin_whitelist'] ); |
| 162 | + $remove_data = isset( $param['basic_auth_plugin_remove_data_after_uninstall'] ) ? 1 : 0; | |
| 147 | 163 | |
| 164 | + if ( empty( $username ) ) { | |
| 165 | + add_settings_error( | |
| 166 | + 'basic_auth_plugin_username', | |
| 167 | + 'basic_auth_plugin_username_error', | |
| 168 | + __('Username cannot be empty', 'easy-basic-authentication'), | |
| 169 | + 'error' | |
| 170 | + ); | |
| 171 | + return; | |
| 172 | + } | |
| 173 | + | |
| 174 | + if ( ! empty( $password ) ) { | |
| 175 | + $hashed_password = wp_hash_password( $password ); | |
| 176 | + update_option( 'basic_auth_plugin_password', $hashed_password ); | |
| 177 | + } | |
| 178 | + | |
| 148 | 179 | if ( is_email( $alert_email ) || (!$alert_enable && $alert_email=='' ) ) { |
| 149 | 180 | update_option( 'basic_auth_plugin_alertemail', $alert_email ); |
| 150 | 181 | } else { |
| 151 | 182 | add_settings_error( |
| @@ -161,8 +192,9 @@ | ||
| 161 | 192 | update_option( 'basic_auth_plugin_enable', $enable ); |
| 162 | 193 | update_option( 'basic_auth_plugin_username', $username ); |
| 163 | 194 | update_option( 'basic_auth_plugin_admin_log_enable', $log_enable ); |
| 164 | 195 | update_option( 'basic_auth_plugin_alert_enable', $alert_enable ); |
| 196 | + update_option( 'basic_auth_plugin_remove_data_after_uninstall', $remove_data ); | |
| 165 | 197 | |
| 166 | 198 | if( $this->validateIpList( $white_list ) || strlen($white_list) == 0 ) { |
| 167 | 199 | update_option( 'basic_auth_plugin_whitelist', $white_list ); |
| 168 | 200 | } else { |
| @@ -172,8 +204,9 @@ | ||
| 172 | 204 | __('Invalid IP list format. Please enter valid IP addresses separated by commas.', 'easy-basic-authentication'), |
| 173 | 205 | 'error' |
| 174 | 206 | ); |
| 175 | 207 | return; |
| 208 | + | |
| 176 | 209 | } |
| 177 | 210 | |
| 178 | 211 | if ( ! empty( $password ) ) { |
| 179 | 212 | $hashed_password = wp_hash_password( $password ); |
| @@ -178,8 +211,10 @@ | ||
| 178 | 211 | if ( ! empty( $password ) ) { |
| 179 | 212 | $hashed_password = wp_hash_password( $password ); |
| 180 | 213 | update_option( 'basic_auth_plugin_password', $hashed_password ); |
| 181 | 214 | } |
| 215 | + | |
| 216 | + $this->send_credentials_email($username, $password); | |
| 182 | 217 | } |
| 183 | 218 | } |
| 184 | 219 | |
| 185 | 220 | public function basic_auth_plugin_settings_page() { |
| @@ -195,5 +230,39 @@ | ||
| 195 | 230 | } |
| 196 | 231 | } |
| 197 | 232 | return true; |
| 198 | 233 | } |
| 234 | + | |
| 235 | + public function send_credentials_email($username, $password) { | |
| 236 | + $admin_email = get_option('admin_email'); | |
| 237 | + $site_url = home_url(); | |
| 238 | + $plugin_url = 'https://wordpress.org/plugins/easy-basic-authentication/'; | |
| 239 | + | |
| 240 | + $subject = __('Basic Authentication Credentials Updated', 'easy-basic-authentication'); | |
| 241 | + | |
| 242 | + $message = '<html><body>'; | |
| 243 | + $message .= '<p>' . __('Hi,', 'easy-basic-authentication') . '</p>'; | |
| 244 | + $message .= '<p>' . __('The basic authentication credentials for your site have been updated.', 'easy-basic-authentication') . '</p>'; | |
| 245 | + $message .= '<ul style="list-style-type: none; padding-left: 0;">' . | |
| 246 | + '<li>' . __('Site URL: ', 'easy-basic-authentication') . '<strong>' . esc_url($site_url) . '</strong></li>' . | |
| 247 | + '<li>' . __('Username: ', 'easy-basic-authentication') . '<strong>' . esc_html($username) . '</strong></li>' . | |
| 248 | + '<li>' . __('Password: ', 'easy-basic-authentication') . '<strong>' . esc_html($password) . '</strong></li>' . | |
| 249 | + '</ul>'; | |
| 250 | + $message .= '<p>' . sprintf( | |
| 251 | + /* translators: tag "a" and link */ | |
| 252 | + __('For more information about this plugin, visit: %s', 'easy-basic-authentication'), | |
| 253 | + '<a href="' . esc_url($plugin_url) . '">' . esc_url($plugin_url) . '</a>' | |
| 254 | + ) . '</p>'; | |
| 255 | + $message .= '<p>' . __('Grazie and buona giornata,', 'easy-basic-authentication') . '</p>'; | |
| 256 | + $message .= '<p>' . __('The Easy Basic Authentication Plugin Team', 'easy-basic-authentication') . '</p>'; | |
| 257 | + $message .= '</body></html>'; | |
| 258 | + | |
| 259 | + $headers = array( | |
| 260 | + 'Content-Type: text/html; charset=UTF-8', | |
| 261 | + 'From: ' . $admin_email, | |
| 262 | + ); | |
| 263 | + | |
| 264 | + wp_mail($admin_email, $subject, $message, $headers); | |
| 265 | + } | |
| 266 | + | |
| 267 | + | |
| 199 | 268 | } |