Last active
September 18, 2018 15:34
-
-
Save cliffordp/35d74c3bceec9fbd10547b5d1ba988e5 to your computer and use it in GitHub Desktop.
WordPress: Redirect users with 'read' capability (e.g. Subscribers) to Dashboard instead of Profile.
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 | |
/** | |
* Redirect users with 'read' capability (e.g. Subscribers) to Dashboard instead of Profile. | |
* | |
* @link https://gist.github.com/cliffordp/35d74c3bceec9fbd10547b5d1ba988e5 This snippet. | |
* @link https://core.trac.wordpress.org/ticket/44960 Hopefully won't need this snippet in the future. | |
* @link https://github.com/WordPress/WordPress/blob/4.9.8/wp-login.php#L965 The code we are overriding. | |
* | |
* @param string $location | |
* | |
* @return string | |
*/ | |
add_filter( | |
'wp_redirect', function ( $location ) { | |
if ( | |
admin_url( 'profile.php' ) === $location | |
&& '/wp-login.php' === substr( $_SERVER['REQUEST_URI'], 0, 13 ) | |
&& ! empty( $_POST['wp-submit'] ) | |
&& ! empty( $_POST['redirect_to'] ) | |
&& admin_url() === $_POST['redirect_to'] | |
) { | |
$location = admin_url(); | |
} | |
return $location; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment