• Skip to content

WebInRedWebInRed

Wordpress internet marketing e non solo

Aprile 12, 2020 by MarcoTheRed Leave a Comment

Elementor: trucchi e soluzioni

Login di elementor: Redirect sbagliato dopo inserimento errato di password o username

// Redirect the user back to the login page after the login failed, and add a $_GET parameter to let us know. Courtesy of WordPressFlow.com
    add_action( 'wp_login_failed', 'elementor_form_login_fail', 9999999 );
    function elementor_form_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') )) {
            //redirect back to the referrer page, appending the login=failed parameter and removing any previous query strings
            //maybe could be smarter here and parse/rebuild the query strings from the referrer if they are important
            wp_redirect(preg_replace('/\?.*/', '', $referrer) . '/?login=failed' );
            exit;
        }
    }
    // This is also important. Make sure that the redirect still runs if the username and/or password are empty.
    add_action( 'wp_authenticate', 'elementor_form_login_empty', 1, 2 );
    function elementor_form_login_empty( $username, $pwd ) {
        $referrer = $_SERVER['HTTP_REFERER'];  // where did the post submission come from?
     if ( empty( $username ) || empty( $pwd ) ) {
        if ((!strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') )) {
            //redirect back to the referrer page, appending the login=failed parameter and removing any previous query strings
            //maybe could be smarter here and parse/rebuild the query strings from the referrer if they are important
            wp_redirect(preg_replace('/\?.*/', '', $referrer) . '/?login=failed' );
            exit;
        }
       exit();
     }
    }
    function generate_login_fail_messaging(){
        ob_start();
        if($_GET['login'] == 'failed'){
        echo '<div class="message_login_fail" style="background-color: #ca5151;color: #ffffff;display: block;margin-bottom: 20px;text-align: center;padding: 9px 15px; width: fit-content;margin: 0 auto;"><span style="color: #ca5151;background-color: #fff;width: 20px;height: 20px;display: inline-flex;align-items: center;justify-content: center;font-weight: 900;border-radius: 50%;margin-right: 10px;">!</span>Sembra che tu abbia inserito una email o una password sbagliata. Controlla i tuoi dati e riprova.</div>';
        }
        $return_string = ob_get_contents();
        ob_end_clean();
        return $return_string;
    }
    add_shortcode('login_fail_messaging', 'generate_login_fail_messaging');

Dopo aver inserito questa parte di codice nel file function.php

inseriamo uno shortcode sopra il form di login: [login_fail_messaging]

e creiamo lo shortcode nel file function.php

function generate_login_fail_messaging(){
ob_start();
if($_GET['login'] == 'failed'){
echo '!Sembra che tu abbia inserito una email o passoword sbagliata. Controlla i tuoi dati e riprova.';
}
$return_string = ob_get_contents();
ob_end_clean();
return $return_string;
}
add_shortcode('login_fail_messaging', 'generate_login_fail_messaging');

function generate_login_fail_messaging(){
ob_start();
if($_GET['login'] == 'failed'){
echo '!Sembra che tu abbia inserito una email o passoword sbagliata. Controlla i tuoi dati e riprova.';
}
$return_string = ob_get_contents();
ob_end_clean();
return $return_string;
}
add_shortcode('login_fail_messaging', 'generate_login_fail_messaging');

Filed Under: wordpress

Reader Interactions

Lascia un commento Annulla risposta

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Copyright © 2023 · Hello Pro on Genesis Framework · WordPress · Log in