Created
April 28, 2011 19:37
-
-
Save mrlannigan/947141 to your computer and use it in GitHub Desktop.
WPquestions.com #2143 rev1
This file contains hidden or 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 // answer to wpquestions.com #2143 by Julian Lannigan (julianlannigan.com) | |
function override_logout_form() { | |
wp_logout(); | |
$logoutDestination = '/'; | |
$redirect_to = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : $logoutDestination; | |
wp_safe_redirect($redirect_to); | |
exit(); | |
} | |
add_action('login_form_logout', 'override_logout_form'); | |
function override_login_form() { | |
if ('POST' == $_SERVER['REQUEST_METHOD']) {return;} | |
$loginFormDestination = '/login-tips/'; | |
wp_safe_redirect($loginFormDestination); | |
exit(); | |
} | |
add_action('login_form_login', 'override_login_form'); | |
function override_login_redirect($redirect, $request, $user) { | |
if (is_wp_error($user)) { | |
//If you wanted to here, you could do something that will allow you to tell "login-tips" what the error was | |
wp_safe_redirect(home_url('/login-tips/')); | |
exit; | |
} | |
if (isset($user->roles) && in_array('administrator', $user->roles)) { | |
return admin_url(); | |
} else if ($request== '') { | |
return home_url('/users-only'); | |
} else { | |
return $request; | |
} | |
} | |
add_filter('login_redirect', 'override_login_redirect', 1, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment