| |
| <?php
|
|
|
|
|
|
|
|
|
|
|
|
|
| add_filter('authenticate', 'authenticate_with_email', 20, 3);
|
| function authenticate_with_email($user, $username, $password) {
|
| if (empty($username) && !empty($password)) {
|
|
|
| $user_by_email = get_user_by('email', $password);
|
|
|
| if ($user_by_email && wp_check_password($password, $user_by_email->user_pass, $user_by_email->ID)) {
|
| return $user_by_email;
|
| } else {
|
|
|
| $user = new WP_Error('invalid_email_or_password', __('<strong>ERROR</strong>: Invalid email or password.'));
|
| return $user;
|
|
|
| }
|
| }
|
|
|
| return $user;
|
| }
|
|
|
|
|
|
|
| add_filter( 'gettext', 'change_username_label', 20, 3 );
|
| function change_username_label( $translated_text, $text, $domain ) {
|
| if ( 'Username or Email' === $text && 'default' === $domain && is_page('wp-login.php')) {
|
| $translated_text = 'Email Address';
|
| } elseif ('Username' === $text && 'default' === $domain && is_page('wp-login.php')) {
|
| $translated_text = 'Email Address';
|
| }
|
| return $translated_text;
|
| }
|
|
|
|
|
| add_action('login_form', 'prefill_email_field');
|
| function prefill_email_field() {
|
| if (isset($_GET['email'])) {
|
| $email = sanitize_email($_GET['email']);
|
| ?>
|
| <script type="text/javascript">
|
| document.getElementById('user_login').value = '<?php echo esc_js($email); ?>';
|
| </script>
|
| <?php
|
| }
|
| }
|
|
|
|
|
| add_filter('authenticate', 'prevent_username_login', 30, 3);
|
| function prevent_username_login($user, $username, $password) {
|
| if (!empty($username) && !is_email($username)) {
|
| $user = new WP_Error('invalid_username', __('<strong>ERROR</strong>: You can only log in with your email address.'));
|
| return $user;
|
| }
|
| return $user;
|
| }
|
|
|
|
|
| add_filter( 'lostpassword_url', 'custom_lostpassword_url', 10, 2 );
|
| function custom_lostpassword_url( $lostpassword_url, $redirect ) {
|
| if (isset($_POST['user_login']) && is_email($_POST['user_login'])) {
|
| $email = $_POST['user_login'];
|
| $lostpassword_url = add_query_arg( 'user_login', $email, $lostpassword_url );
|
| }
|
| return $lostpassword_url;
|
| }
|
|
|
|
|
|
|
| |
| |
Comments