Created
June 5, 2019 20:40
-
-
Save stefanRepac/3d7e088f18593b59116ae46f3efb0281 to your computer and use it in GitHub Desktop.
Custom WP Login /w redirection and error fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function custom_login_shortcode() { | |
| if ( ! is_user_logged_in() ) { // Display WordPress login form: | |
| $args = array( | |
| 'redirect' => home_url() . '/alumni/', | |
| 'form_id' => 'loginform-custom', | |
| 'label_username' => __( 'Korisničko ime ili Email' ), | |
| 'label_password' => __( 'Lozinka' ), | |
| 'label_remember' => __( 'Zapamti me' ), | |
| 'label_log_in' => __( 'Prijavi se' ), | |
| 'remember' => true | |
| ); | |
| wp_login_form( $args ); | |
| echo '<a href="' . wp_lostpassword_url( get_permalink() ) . '">' . __( "Izgubili ste lozinku?" ) . '</a>'; | |
| $login = (isset($_GET['login']) ) ? $_GET['login'] : 0; | |
| if ( $login === "failed" ) { | |
| echo '<p class="login-msg"><strong>ERROR:</strong> Invalid username and/or password.</p>'; | |
| } elseif ( $login === "empty" ) { | |
| echo '<p class="login-msg"><strong>ERROR:</strong> Username and/or Password is empty.</p>'; | |
| } elseif ( $login === "false" ) { | |
| echo '<p class="login-msg"><strong>ERROR:</strong> You are logged out.</p>'; | |
| } | |
| echo '<div class="login-wrap" style="margin-top: 50px;">'; | |
| echo "<h4><strong>Nemate profil?</strong></h4>"; | |
| echo "<h5>Postanite deo Alumni kluba</h5></br>"; | |
| echo '<a class="btn-full btn-border"> KREIRAJ NALOG </a>'; | |
| echo "</div>"; | |
| } else { // If logged in: | |
| wp_loginout( home_url() . '/alumni/' ); // Display "Log Out" link. | |
| echo " | "; | |
| wp_register('', ''); // Display "Site Admin" link. | |
| } | |
| } | |
| add_shortcode( 'custom-login', 'custom_login_shortcode' ); | |
| function login_failed() { | |
| $login_page = home_url( 'alumni/pridruzite-se/prijavi-se/' ); | |
| wp_redirect( $login_page . '?login=failed' ); | |
| exit; | |
| } | |
| // add_action( 'wp_login_failed', 'login_failed' ); | |
| function verify_username_password( $user, $username, $password ) { | |
| $login_page = home_url( 'alumni/pridruzite-se/prijavi-se/' ); | |
| if( $username == "" || $password == "" ) { | |
| wp_redirect( $login_page . "?login=empty" ); | |
| exit; | |
| } | |
| } | |
| // add_filter( 'authenticate', 'verify_username_password', 1, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment