does anyone tried creating a login form specifically for Subscribers? meaning if the user roles are admins, contributors, authors are not able to login on that said form only subscriber users. Thanks!

  • By login do you mean access to the dashboard, just plain login in. If its plain login you want, you could try to check the user role of the user who is trying to log in, if the user is not a subscriber, send them a message stating that they are not able to login and destroy their session
    – bagpipper
    Oct 17 '16 at 10:13
  • i think that's a good idea. do you have some code snippet on checking the user role after logging in?
    – Sayroose
    Oct 17 '16 at 10:28

Here is a snipped. Make sure to run this code after the users are logged in

//To get logged in user information
$user = wp_get_current_user();
//Condition to check weather user is subscriber or not
if ( in_array( 'subscriber', (array) $user->roles ) ) {
    //The user has the "subscriber" role
 // redirect user to different section and end their session
 wp_logout(); // user is logged out
 wp_redirect( home_url( '/' ) ); // user is redirected to home page

Do let me know if this works for you or not

  • How do i call this function?
    – Sayroose
    Oct 18 '16 at 3:15
  • this is how i call the login form function : <?php jr_login_form_2( $action, $redirect); ?> and inside that function:
    – Sayroose
    Oct 18 '16 at 3:22
  • code function jr_login_form_2( $action = '', $redirect = '' ) { global $posted; // make sure there's the correct url if ( ! $action ) $action = site_url('wp-login.php'); if ( ! $redirect ) $redirect = admin_url(); ?> `code'
    – Sayroose
    Oct 18 '16 at 3:24
  • @Sayroose This is an independent code you can use it hook it in init or any other hook provided by wordpress As for function. I do not understand why you are using a it and for what purpose
    – bagpipper
    Oct 21 '16 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.