Create a WordPress members role and redirect them to a members area
To create a WordPress members role and redirect them to a members area after loginĀ is a simple requirement for many client websites, here are two simple functions to create a new user role, give them some capabilities and redirect them to a members area after they login.
// create a users role with capabilities $new_member_role = add_role('members', 'Member', array( 'read' => true, // True allows that capability 'edit_posts' => true, 'delete_posts' => false, // Use false to explicitly deny )); // redirect the users after they login, be sure to create a page with a slug of members-welcome function wptx_login_redirect_contributors() { if ( current_user_can('members') ){ return '/members-welcome/'; } } add_filter('login_redirect', 'wptx_login_redirect_contributors');
if you need to protect this page from non-logged in users see how to hide a page if a user is not logged in