Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active September 18, 2018 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/35d74c3bceec9fbd10547b5d1ba988e5 to your computer and use it in GitHub Desktop.
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.
<?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