1

Is there a simple way to temporarily stop a user role logging in with wordpress?

For example, if I have a user role called media, how can I block them from logging in?

I would like a custom message to appear on the website, for example like 'Site undergoing maintenance'

So it looks like this... http://i.imgur.com/nDf7a.jpg

The reason why, is because my website is completely locked down from the public using this function...

// LOCK DOWN
add_action('get_header', 'wpq_member_only_site');
function wpq_member_only_site() {
    // logged in users or visits to a specified page are allowed
    if ( !is_user_logged_in() ) {

        $redirect_after_login = get_home_url();

        // the URL where login/registration takes place
        $login_url = wp_login_url( $redirect_after_login );

        // redirect visitors
        wp_redirect( $login_url, 302 );
        exit;
    }
}

But I need to do some maintenence and I'm after a simple way to lock all users out that are the role media

This is because I wan't administrators and editors to still have access, but not media.

Can any one help please?

Thanks Josh

3

With a some digging and learning, I managed to combine various help and create these 2 functions...

// MAINTAINANCE MODE
function site_maintenance() {
    if ( current_user_can('media') || current_user_can('genpo') ) {

       $logout_url = wp_login_url().'?mode=maintainance';
       wp_logout();
       wp_redirect( $logout_url, 302 );

    }     
}
add_action('get_header', 'site_maintenance');

// CUSTOM LOGIN MESSAGES
function my_login_message() {

    if( $_GET['mode'] == 'maintainance' ){
        $message = '<p class="message"><b>Site undergoing maintainance.</b></p>';
        return $message;
    }

}
add_filter('login_message', 'my_login_message');
2

Add in a check for a capability that admins and editors share:

add_action( 'get_header', 'wpse81659_maintenance' );
function wpse81659_maintenance() {
    if ( ! current_user_can( 'publish_pages' ) || ! is_user_logged_in() )
        die( 'Site undergoing maintenance' );
}
  • Thanks diggy. I will use this if no other solution comes in, but I would ideally like the message to appear here, so it looks like this... i.imgur.com/nDf7a.jpg - Thank you very much for your suggestion. – Joshc Jan 15 '13 at 14:59
2

I created a simple plugin that will allow you to do this without messing around with code. The message displayed to disabled users is also filterable.

http://wordpress.org/plugins/disable-users/

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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