Last active
November 19, 2015 08:53
-
-
Save joeydenbraven/db595d1542ceb4f6dccb to your computer and use it in GitHub Desktop.
Close Wordpress wp-admin and redirect all users for own 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 | |
// Put this in functions file | |
function redirect_login_page() { | |
// Closes all forms going to Wordpress admin, make sure you got a form to login on this page because you'll be redirected to this page | |
$login_page = home_url( '/profiles/' ); | |
$page_viewed = basename($_SERVER['REQUEST_URI']); | |
if( $page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') { | |
wp_redirect($login_page); | |
exit; | |
} | |
} | |
add_action('init','redirect_login_page'); | |
function login_failed() { | |
$login_page = home_url( '/login/' ); | |
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( '/login/' ); | |
if( $username == "" || $password == "" ) { | |
wp_redirect( $login_page . "?login=empty" ); | |
exit; | |
} | |
} | |
add_filter( 'authenticate', 'verify_username_password', 1, 3); | |
function logout_page() { | |
$login_page = home_url( '' ); | |
wp_redirect( $login_page . "?login=false" ); | |
exit; | |
} | |
add_action('wp_logout','logout_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 | |
// Use this in template | |
$login = (isset($_GET['login']) ) ? $_GET['login'] : 0; | |
if ( $login === "failed" ) { | |
// do something | |
} elseif ( $login === "empty" ) { | |
// do something | |
} elseif ( $login === "false" ) { | |
// do something | |
} else { | |
// do something | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment