Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Last active November 22, 2018 17:39
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wpscholar/4665879 to your computer and use it in GitHub Desktop.
WordPress function for redirecting users based on custom user meta
<?php
/**
* WordPress function for redirecting users based on custom user meta
*/
function my_login_redirect( $url, $request, $user ){
if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if( 'cool' == get_user_meta( $user->ID, '_is_cool', true ) ) {
$url = home_url('/cool-people-only/');
}
}
return $url;
}
add_filter('login_redirect', 'my_login_redirect', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment