Skip to content

Instantly share code, notes, and snippets.

@thefrosty
Last active August 29, 2015 14:07
Show Gist options
  • Save thefrosty/237bcceb63960bd8f524 to your computer and use it in GitHub Desktop.
Save thefrosty/237bcceb63960bd8f524 to your computer and use it in GitHub Desktop.
WordPress page template redirects: https://extendd.com/plugin/custom-login-page-template/
/**
* Function Name: front_end_login_fail.
* Description: This redirects the failed login to the custom login page
* instead of default login page with a modified url
*/
add_action( 'wp_login_failed', 'front_end_login_fail' );
function front_end_login_fail( $username ) {
$setting = class_exists( 'custom_login_pro_admin' ) ? get_option( CUSTOMLOGINPRO . '_settings' ) : get_option( CUSTOMLOGIN_PAGE_TEMPLATE()->id );
// Getting URL of the login page
$referrer = $_SERVER['HTTP_REFERER'];
// 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( get_permalink( $setting['login_page_id'] ) );
// Not working yet...
add_filter( 'login_page_messages', function() {
return 'FAILED';
});
exit;
}
}
/**
* Function Name: check_username_password.
* Description: This redirects to the custom login page if user name or
* password is empty with a modified url
*/
add_action( 'authenticate', 'check_username_password', 1, 3 );
function check_username_password( $login, $username, $password ) {
$setting = class_exists( 'custom_login_pro_admin' ) ? get_option( CUSTOMLOGINPRO . '_settings' ) : get_option( CUSTOMLOGIN_PAGE_TEMPLATE()->id );
// Getting URL of the login page
$referrer = $_SERVER['HTTP_REFERER'];
// 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' ) ) {
if ( $username == "" || $password == "" ){
wp_redirect( get_permalink( $setting['login_page_id'] ) );
// Not working yet...
add_filter( 'login_page_messages', function() {
return 'ERROR';
});
exit;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment