Last active
November 1, 2017 09:06
-
-
Save ivanbogomoloff/1aabb81912ed0b1e00f302fe3f6c2db6 to your computer and use it in GitHub Desktop.
Wordpress override login, logout urls and remove wp login php
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
//Cop wp-login.php into any_login_admin_page.php | |
//then delete wp-login.php | |
//then write this... | |
add_filter('login_url', function($login_url, $redirect = '', $force_reauth = false) { | |
$login_url = site_url( '/any_login_admin_page.php', 'login' ); | |
if ( ! empty( $redirect ) ) { | |
$login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_url ); | |
} | |
if ( $force_reauth ) { | |
$login_url = add_query_arg( 'reauth', '1', $login_url ); | |
} | |
return $login_url; | |
}); | |
add_filter('logout_url', function($logout_url, $redirect = '') { | |
$args = array( 'action' => 'logout' ); | |
$args['redirect_to'] = urlencode( '/' ); | |
$logout_url = add_query_arg($args, site_url( '/any_login_admin_page.php', 'login' )); | |
$logout_url = wp_nonce_url( $logout_url, 'log-out' ); | |
return $logout_url; | |
}); | |
//close redirect wp-admin to login page | |
add_filter('nocache_headers', function() { | |
if(strpos($_SERVER['REQUEST_URI'], '/wp-admin') === 0 && !is_user_logged_in()) { | |
header("HTTP/1.0 404 Not Found"); | |
get_template_part( 404 ); | |
exit(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment