Last active
January 5, 2020 15:26
-
-
Save JRyven/ff57e5ee6acb1f121240211c9f048be0 to your computer and use it in GitHub Desktop.
Login
This file contains 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 | |
//BUILD LOGIN | |
function bpm_custom_login_shortcode( $atts, $content = null ) { | |
if( ! is_user_logged_in() ) : | |
$a = shortcode_atts( array( | |
'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], | |
'label_username' => __( 'Username or email address' ), | |
'label_password' => __( 'Password' ), | |
'label_remember' => __( 'Remember Me' ), | |
'label_log_in' => __( 'Log In' ), | |
'remember_checked' => true, | |
), $atts ); | |
$args = array( | |
'echo' => false, | |
'remember' => true, | |
'redirect' => esc_url( $a['redirect'] ), | |
'label_username' => esc_attr( $a['label_username'] ), | |
'label_password' => esc_attr( $a['label_password'] ), | |
'label_remember' => esc_attr( $a['label_remember'] ), | |
'label_log_in' => esc_attr( $a['label_log_in'] ), | |
'value_remember' => $a['remember_checked'] | |
); | |
return wp_login_form( $args ); | |
else: | |
return | |
' | |
You are already logged in. | |
'; | |
endif; | |
} | |
add_shortcode( 'bpm_login', 'bpm_custom_login_shortcode' ); | |
// ALLOW LOGIN | |
add_action('check_admin_referer', 'logout_without_confirm', 10, 2); | |
function logout_without_confirm($action, $result) | |
{ | |
/** | |
* Allow logout without confirmation | |
*/ | |
if ($action == "log-out" && !isset($_GET['_wpnonce'])) { | |
$redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '/'; | |
$location = str_replace('&', '&', wp_logout_url($redirect_to)); | |
header("Location: $location"); | |
die; | |
} | |
} | |
// INCLUDE PASSWORD RESET | |
add_action( 'login_form_bottom', 'add_lost_password_link' ); | |
function add_lost_password_link() { | |
return '<a class="login-lostpass" href="/wp-login.php?action=lostpassword">Lost Password?</a>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment