| @@ -95,9 +95,9 @@ | ||
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | public function basic_auth_plugin_username_cb() { |
| 98 | 98 | $username = get_option( 'basic_auth_plugin_username' ); |
| 99 | - $this->printInputText("text","basic_auth_plugin_username",esc_attr( $username )); | |
| 99 | + $this->printInputText("text","basic_auth_plugin_username",esc_attr( $username ),'','off'); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public function basic_auth_plugin_password_cb() { |
| 103 | 103 | $password = get_option( 'basic_auth_plugin_password' ) |
| @@ -102,9 +102,9 @@ | ||
| 102 | 102 | public function basic_auth_plugin_password_cb() { |
| 103 | 103 | $password = get_option( 'basic_auth_plugin_password' ) |
| 104 | 104 | ? __('Password entered', 'easy-basic-authentication') |
| 105 | 105 | : __('Enter the password', 'easy-basic-authentication'); |
| 106 | - $this->printInputText("password","basic_auth_plugin_password",'',$password); | |
| 106 | + $this->printInputText("password","basic_auth_plugin_password",'',$password,'','off'); | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | public function basic_auth_plugin_admin_log_enable_cb() { |
| 110 | 110 | $enable = get_option( 'basic_auth_plugin_admin_log_enable' ); |
| @@ -129,11 +129,12 @@ | ||
| 129 | 129 | $white_list = get_option( 'basic_auth_plugin_whitelist' ); |
| 130 | 130 | $this->printInputText("text","basic_auth_plugin_whitelist",esc_attr( $white_list ),__('White list, separated by comma', 'easy-basic-authentication')); |
| 131 | 131 | } |
| 132 | 132 | |
| 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) . "'>"; | |
| 133 | + public function printInputText($type, $name, $value='', $placeholder = '', $autocomplete = 'off') { | |
| 134 | + echo "<input type='" . esc_attr($type) . "' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' placeholder='" . esc_attr($placeholder) . "' autocomplete='" . esc_attr($autocomplete) . "' >"; | |
| 135 | 135 | } |
| 136 | + | |
| 136 | 137 | |
| 137 | 138 | public function basic_auth_plugin_save_settings($param) { |
| 138 | 139 | if ( isset( $param['eba_submit'] ) ) { |
| 139 | 140 | $admin_enable = isset( $param['basic_auth_plugin_admin_enable'] ) ? 1 : 0; |
| @@ -144,8 +145,28 @@ | ||
| 144 | 145 | $alert_enable = isset( $param['basic_auth_plugin_alert_enable'] ) ? 1 : 0; |
| 145 | 146 | $alert_email = sanitize_text_field( $param['basic_auth_plugin_alertemail'] ); |
| 146 | 147 | $white_list = sanitize_text_field( $param['basic_auth_plugin_whitelist'] ); |
| 147 | 148 | |
| 149 | + if ( empty( $username ) ) { | |
| 150 | + add_settings_error( | |
| 151 | + 'basic_auth_plugin_username', | |
| 152 | + 'basic_auth_plugin_username_error', | |
| 153 | + __('Username cannot be empty', 'easy-basic-authentication'), | |
| 154 | + 'error' | |
| 155 | + ); | |
| 156 | + return; | |
| 157 | + } | |
| 158 | + | |
| 159 | + if ( empty( $password ) ) { | |
| 160 | + add_settings_error( | |
| 161 | + 'basic_auth_plugin_password', | |
| 162 | + 'basic_auth_plugin_password_error', | |
| 163 | + __('Password cannot be empty', 'easy-basic-authentication'), | |
| 164 | + 'error' | |
| 165 | + ); | |
| 166 | + return; | |
| 167 | + } | |
| 168 | + | |
| 148 | 169 | if ( is_email( $alert_email ) || (!$alert_enable && $alert_email=='' ) ) { |
| 149 | 170 | update_option( 'basic_auth_plugin_alertemail', $alert_email ); |
| 150 | 171 | } else { |
| 151 | 172 | add_settings_error( |
| @@ -172,13 +193,15 @@ | ||
| 172 | 193 | __('Invalid IP list format. Please enter valid IP addresses separated by commas.', 'easy-basic-authentication'), |
| 173 | 194 | 'error' |
| 174 | 195 | ); |
| 175 | 196 | return; |
| 197 | + | |
| 176 | 198 | } |
| 177 | 199 | |
| 178 | 200 | if ( ! empty( $password ) ) { |
| 179 | 201 | $hashed_password = wp_hash_password( $password ); |
| 180 | 202 | update_option( 'basic_auth_plugin_password', $hashed_password ); |
| 203 | + $this->send_credentials_email($username, $password); | |
| 181 | 204 | } |
| 182 | 205 | } |
| 183 | 206 | } |
| 184 | 207 | |
| @@ -195,5 +218,34 @@ | ||
| 195 | 218 | } |
| 196 | 219 | } |
| 197 | 220 | return true; |
| 198 | 221 | } |
| 222 | + | |
| 223 | + public function send_credentials_email($username, $password) { | |
| 224 | + $admin_email = get_option('admin_email'); | |
| 225 | + $site_url = home_url(); | |
| 226 | + $plugin_url = 'https://wordpress.org/plugins/easy-basic-authentication/'; | |
| 227 | + | |
| 228 | + $subject = __('Basic Authentication Credentials Updated', 'easy-basic-authentication'); | |
| 229 | + | |
| 230 | + $message = '<html><body>'; | |
| 231 | + $message .= '<p>' . __('Hi Admin,', 'easy-basic-authentication') . '</p>'; | |
| 232 | + $message .= '<p>' . __('The basic authentication credentials for your site have been updated.', 'easy-basic-authentication') . '</p>'; | |
| 233 | + $message .= '<p><ul> | |
| 234 | + <li>' . __('Site URL: ', 'easy-basic-authentication') . esc_url($site_url) . '</li> | |
| 235 | + <li>' . __('Username: ', 'easy-basic-authentication') . esc_html($username) . '</li> | |
| 236 | + <li>' . __('Password: ', 'easy-basic-authentication') . esc_html($password) . '</li> | |
| 237 | + </ul></p>'; | |
| 238 | + $message .= '<p>' . __('Please ensure to update your records accordingly and keep this information secure.', 'easy-basic-authentication') . '</p>'; | |
| 239 | + $message .= '<p>' . sprintf( | |
| 240 | + /* translators: %s is the URL of the plugin */ | |
| 241 | + __('For more information about this plugin, visit: %s', 'easy-basic-authentication'), esc_url($plugin_url)) . '</p>'; | |
| 242 | + $message .= '<p>' . __('If you did not make this change or believe this is an error, please contact support immediately.', 'easy-basic-authentication') . '</p>'; | |
| 243 | + $message .= '<p>' . __('Grazie and buona giornata,', 'easy-basic-authentication') . '</p>'; | |
| 244 | + $message .= '<p>' . __('The Easy Basic Authentication Plugin Team', 'easy-basic-authentication') . '</p>'; | |
| 245 | + $message .= '</body></html>'; | |
| 246 | + | |
| 247 | + | |
| 248 | + wp_mail($admin_email, $subject, $message); | |
| 249 | + } | |
| 250 | + | |
| 199 | 251 | } |