Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Assign wp_die to a specific user role

  • @icepin

    Participant

    My buddypress community is available only for registered users and new user can register only using an invitation code so I created a new user role called “Banned” using User Role Editor plugin and I want all the users assigned to this user role to get the wp_die() along with a custom message when they log in.
    Anyone got an idea how this piece of code can be written?

    Cheers,

Viewing 1 replies (of 1 total)
  • @icepin

    Participant

    Based on David Carson’s snippet for making the website available only for users, came up with this and it does the job for me so…. maybe others will find it useful:

    // Declare Ban Users by Role function
    function ban_user(){
    global $bp, $bp_unfiltered_uri;

    // If user is logged in and
    if (is_user_logged_in() &&
    (
    // The current user role is banned
    current_user_can('banned')
    )

    ) {
    // Display the error message
    wp_die('You are banned.');
    }
    }

    add_action( 'wp', 'ban_user', 3 );

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Assign wp_die to a specific user role’ is closed to new replies.
Skip to toolbar