Come posso reindirizzare l'utente dopo aver inserito una password errata?
6 risposta
- voti
-
- 2011-04-26
wp_login_form()
crea unmodulo con un attributo di azionesite_url/wp-login.php
,il che significa che quandofai clic sulpulsante diinvioilmodulo vienepubblicatosite_url/wp-login.php
cheignora redirect_toin caso dierrori (come lapassworderrata) quindineltuo casotorna a utilizzare unplugin o ricrea l'interoprocesso di accessoe in questomodo avraiil controllo suglierrori,dai un'occhiata a Verificailnome utente correttonelmodulo di accessopersonalizzato che è una domandamolto simile.wp_login_form()
creates a form with an action attribute ofsite_url/wp-login.php
, which means that when you click the submit button the form is posted tosite_url/wp-login.php
which ignores redirect_to on errors (like wrong password) so in your case either go back to using a plugin or recreate the whole login process and that way you will have control on errors, take a look at Check for correct username on custom login form which is very similar question. -
- 2012-06-08
Sono venuto qui da Google.Ma la rispostanonmi ha soddisfatto.Stavo cercando unpo 'ditempoe hotrovato una soluzionemigliore.
Aggiungilo altuo functions.php :
add_action( 'wp_login_failed', 'my_front_end_login_fail' ); // hook failed login function my_front_end_login_fail( $username ) { $referrer = $_SERVER['HTTP_REFERER']; // where did the post submission come from? // if there's a valid referrer, and it's not the default log-in screen if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) { wp_redirect( $referrer . '?login=failed' ); // let's append some information (login=failed) to the URL for the theme to use exit; } }
I came here from google. But the answer didn't satisfy me. I was looking for a while and found a better solution.
Add this to your functions.php:
add_action( 'wp_login_failed', 'my_front_end_login_fail' ); // hook failed login function my_front_end_login_fail( $username ) { $referrer = $_SERVER['HTTP_REFERER']; // where did the post submission come from? // if there's a valid referrer, and it's not the default log-in screen if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) { wp_redirect( $referrer . '?login=failed' ); // let's append some information (login=failed) to the URL for the theme to use exit; } }
-
Grazie Alexey,loproverò (dato che sto ancora utilizzando unplugin)Thanks Alexey, I will test this (as I'm still using a plugin)
- 0
- 2012-06-19
- Steven
-
La soluzione di Alexeyfunziona quando vengonoinserite credenzialierrate,ma sfortunatamentefallisce quando l'utente dimentica diinserirenome utente opassword.Apparentemente Wordpressnontentanemmeno di accedere all'utentein questo caso,quindi l'azione wp_login_failednon vieneeseguita.Alexey's solution works when wrong credentials are entered, but unfortunately fails when the user forgets to enter username or password. Apparently Wordpress doesn't even try to log the user in in this case, so wp_login_failed action is not performed.
- 9
- 2012-09-12
- Szczepan Hołyszewski
-
Vorrei utilizzare wp_get_referer () quiper risparmiaretempo: http://codex.wordpress.org/Function_Reference/wp_get_refererI would use wp_get_referer() here to save some time: http://codex.wordpress.org/Function_Reference/wp_get_referer
- 1
- 2013-07-03
- Jake
-
Inoltre,qui usi sicuramente add_query_arg,quindi wp_redirect dovrebbeessere: "wp_redirect (add_query_arg ('login','failed',$ referrer));"Also, you definitely use add_query_arg here, so the wp_redirect should be: "wp_redirect( add_query_arg('login', 'failed', $referrer) );"
- 2
- 2013-07-03
- Jake
-
- 2013-05-09
Una soluzioneperilpunto di Szczepan Hołyszewski sui campi vuotinella soluzione accettata,il seguentejQueryimpedirà di andare allapagina wp-login standard: (aggiungi almodello dellapagina di accesso ofooter.php)
jQuery("#loginform-custom").submit(function(){ var isFormValid = true; jQuery("input").each(function() { if (jQuery.trim($(this).val()).length == 0){ jQuery(this).addClass("submit_error"); isFormValid = false; } else { jQuery(this).removeClass("submit_error"); } }); return isFormValid; });
A solution for Szczepan Hołyszewski's point about empty fields in the accepted solution, the following jQuery will prevent going to the standard wp-login page: (add to login page template or footer.php)
jQuery("#loginform-custom").submit(function(){ var isFormValid = true; jQuery("input").each(function() { if (jQuery.trim($(this).val()).length == 0){ jQuery(this).addClass("submit_error"); isFormValid = false; } else { jQuery(this).removeClass("submit_error"); } }); return isFormValid; });
-
- 2013-02-26
Un'aggiunta alla risposta di Alexey.Puoi aggiungere unafunzionejqueryper verificare che uno dei campinon sia vuoto.In questomodoilmodulonon verràinviato ameno chenon ci sia qualcosa da controllare,impedendo a WordPress di reindirizzare a/wp-login.php.
<script> $("#wp-submit").click(function() { var user = $("input#user_login").val(); if (user == "") { $("input#user_login").focus(); return false; } }); </script>
Non sono ancora sicuro di come correggere l'aspetto dellapassword dimenticata
One addition to Alexey's answer. You can add a jquery function to check that one of the fields is not blank. That way the form will not submit unless there is something to check, preventing WordPress from redirecting to /wp-login.php.
<script> $("#wp-submit").click(function() { var user = $("input#user_login").val(); if (user == "") { $("input#user_login").focus(); return false; } }); </script>
Still not sure how to fix the forgot password aspect
-
Tienipresente che WordPress caricajQueryin modalità "No Conflict".L'alias "$"nonfunziona.Please be aware that WordPress loads jQuery in "No Conflict" mode. The `$` alias does not work.
- 3
- 2013-02-26
- s_ha_dum
-
Devi anche considerare che l'utentepreme [invio]e nonfa clic sulpulsante di accesso.Inoltre,ènecessario controllare anche lapassword vuota.You also have to consider that user hits [enter] and not clicking t he login button. Also, you need to check for blank password as well.
- 0
- 2013-02-26
- Steven
-
- 2020-08-30
Quanto segue hafunzionatoperme. Entrambi questi hookpossonoesseretrovatinellafunzione
wp_authenticate
all'interno diwp-includes/puggabel.php
.- Controllatramiteilfiltro
authenticate
senelmodulo di accessomancailnome utente o lapassword.
function wpse_15633_redirectMissingDataLoginForm($user, $username, $password) { $errors = []; empty(trim($password)) && $errors[] = 'password_empty'; empty(trim($username)) && $errors[] = 'username_empty'; if (! empty($errors)) { $redirect_url = add_query_arg([ 'errors' => join(',', $errors), ], site_url('login', 'login_post')); if (wp_safe_redirect($redirect_url)) { exit; } } return $user; } add_filter('authenticate', 'wpse_15633_redirectMissingDataLoginForm', 10, 3);
- Verificatramite l'azione
wp_login_failed
se l'autenticazione delnome utentee dellapasswordfornitinon è riuscita.
function wpse_15633_redirectFailedLoginForm($username, $error) { $redirect_url = add_query_arg([ 'errors' => $error->get_error_code(), ], site_url('login', 'login_post')); if (wp_safe_redirect($redirect_url)) { exit; } } add_action('wp_login_failed', 'wpse_15633_redirectFailedLoginForm', 10, 2);
The following worked for me. Both of these hooks can be found within the function
wp_authenticate
withinwp-includes/puggabel.php
.- Check via the
authenticate
filter if the login form is missing the username or password.
function wpse_15633_redirectMissingDataLoginForm($user, $username, $password) { $errors = []; empty(trim($password)) && $errors[] = 'password_empty'; empty(trim($username)) && $errors[] = 'username_empty'; if (! empty($errors)) { $redirect_url = add_query_arg([ 'errors' => join(',', $errors), ], site_url('login', 'login_post')); if (wp_safe_redirect($redirect_url)) { exit; } } return $user; } add_filter('authenticate', 'wpse_15633_redirectMissingDataLoginForm', 10, 3);
- Check via the
wp_login_failed
action if the authentication of the supplied username and password has failed.
function wpse_15633_redirectFailedLoginForm($username, $error) { $redirect_url = add_query_arg([ 'errors' => $error->get_error_code(), ], site_url('login', 'login_post')); if (wp_safe_redirect($redirect_url)) { exit; } } add_action('wp_login_failed', 'wpse_15633_redirectFailedLoginForm', 10, 2);
-
- 2018-05-11
jQuery("#loginform-custom").submit(function(){ var isFormValid = true; jQuery("input").each(function() { if (jQuery.trim($(this).val()).length == 0){ jQuery(this).addClass("submit_error"); isFormValid = false; } else { jQuery(this).removeClass("submit_error"); } }); return isFormValid; });
jQuery("#loginform-custom").submit(function(){ var isFormValid = true; jQuery("input").each(function() { if (jQuery.trim($(this).val()).length == 0){ jQuery(this).addClass("submit_error"); isFormValid = false; } else { jQuery(this).removeClass("submit_error"); } }); return isFormValid; });
-
Perfavore ** [modifica] latua risposta **e aggiungi una spiegazione: **perché ** questopotrebbe risolvereilproblema?Please **[edit] your answer**, and add an explanation: **why** could that solve the problem?
- 0
- 2018-05-11
- fuxia
Sto utilizzando
wp_login_form()
per visualizzareilmodulo di accessoin unafinestra di dialogojQuery.Se l'utenteinserisce unapassworderrata,vieneindirizzato albackend.Non lo voglio.C'è unmodopernotificare all'utente che hainserito unapassword sbagliatae rimanere ancora sulla stessapagina?
Prima che arrivasse
wp_login_form()
stavo usando unplugin.Spero unpo 'dipoterevitare di utilizzare unpluginper questo.Ilmio codice: