Created
July 4, 2014 11:49
-
-
Save fazlurr/f1770c967d298e37263e to your computer and use it in GitHub Desktop.
Create custom login page in wordpress, and hook in functions - http://www.paulund.co.uk/create-your-own-wordpress-login-page
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 | |
// Restrict dashboard access to administrator only | |
add_action( 'admin_init', 'ru_restrict_admin', 1 ); | |
function ru_restrict_admin() | |
{ | |
if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) { | |
wp_redirect( site_url() ); | |
} | |
} | |
// Hook failed login | |
add_action( 'wp_login_failed', 'ru_login_failed' ); | |
function ru_login_failed($user) | |
{ | |
// check what page the login attempt is coming from | |
$referrer = $_SERVER['HTTP_REFERER']; | |
// check that were not on the default login page | |
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') && $user!=null ) { | |
// make sure we don't already have a failed login attempt | |
if ( !strstr($referrer, '?login=failed' )) { | |
// Redirect to the login page and append a querystring of login failed | |
wp_redirect( $referrer . '?login=failed'); | |
} else { | |
wp_redirect( $referrer ); | |
} | |
exit; | |
} | |
} | |
// Login Page Authentication | |
add_action( 'authenticate', 'ru_blank_login'); | |
function ru_blank_login($user) | |
{ | |
// check what page the login attempt is coming from | |
$referrer = $_SERVER['HTTP_REFERER']; | |
$error = false; | |
if($_POST['log'] == '' || $_POST['pwd'] == '') | |
{ | |
$error = true; | |
} | |
// check that were not on the default login page | |
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') && $error ) { | |
// make sure we don't already have a failed login attempt | |
if ( !strstr($referrer, '?login=failed') ) { | |
// Redirect to the login page and append a querystring of login failed | |
wp_redirect( $referrer . '?login=failed' ); | |
} else { | |
wp_redirect( $referrer ); | |
} | |
exit; | |
} | |
} | |
?> |
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 | |
/** | |
* Template Name: User Login | |
*/ | |
$args = array( 'redirect' => site_url() ); | |
if(isset($_GET['login']) && $_GET['login'] == 'failed') | |
{ | |
?> | |
<div id="login-error" style="background-color: #FFEBE8;border:1px solid #C00;padding:5px;"> | |
<p>Login failed: You have entered an incorrect Username or password, please try again.</p> | |
</div> | |
<?php | |
} | |
wp_login_form( $args ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment