2

I am a bit of a novice to this so please be patient.

I am trying to create a site with a programmer using wordpress, but not using it for blogs or post.
I am not a programmer myself.

I want people to register for the site, and by default their role will be a modified subscriber. Meaning they will have no access to admin nor to any kind of editing on the site. All they can do is view the pages. Also, I want to restrict them to view only a particular page or pages.

Admin can later go and change their status and make their role to a regular subscriber.

What I am really trying to do is to create a site with a full restrictions.
Users will register, but still don't gain access until their registration is reviewed by the admin and grant access to them.

Is this possible?

1 Answer 1

2

What you need first is to understand User Roles in WordPress.

Then a plugin to manage custom user roles, like User Role Editor or Members.

In the administrative menu Settings > General, set the default role when a user registers to your custom role:
settings general default user role

The plugin Members has more advanced features, but case you were to use URE some extra functions would be necessary to block any access to the site backend. Here wrapped as a plugin, see comments for details.

<?php
/**
 * Plugin Name: Block Admin Access for Certain Roles
 * Version: 0.2
 * Author: brasofilo 
 * Plugin URI: https://wordpress.stackexchange.com/q/57206/12615
 */

/**
 * When a registered user tries to visit a page for which he doesn't have access,
 * i.e.: http:/example.com/wp-admin/plugins.php,
 * WordPress displays a standard WP error message.
 * This will redirect instead of displaying the message:
 * "You do not have sufficient permissions to access this page."
 */
add_action( 'admin_page_access_denied', 'access_denied_wpse_57206' );
function access_denied_wpse_57206()
{
    wp_redirect(home_url());
    exit();
}

/**
 * Redirect users without 'edit_posts' capability if they try to access using an URL
 * of an admin page that they would have capability to do
 * i.e.: http:/example.com/wp-admin/profile.php
 */
add_action( 'admin_init', 'admin_init_wpse_57206' );
function admin_init_wpse_57206()
{
    if( current_user_can( 'edit_posts' ) ) 
        return;

    wp_redirect( home_url() );
    exit();
}

/**
 * Redirect users with 'pending' and 'subscriber' roles to the home url
 */
add_filter( 'login_redirect', 'login_redirect_wpse_57206' );
function login_redirect_wpse_57206( $url )
{
    global $user;
    if ( isset( $user->roles ) )
    {
        $result = array_intersect( $user->roles, array( 'author', 'subscriber' ) );
        if( !empty( $result ) )
            $url = home_url();
    }
    return $url;
}

/**
 * Hide the admin bar for users without 'edit_posts' capability
 */
add_filter( 'show_admin_bar', 'hide_admin_bar_wpse_51831' );
function hide_admin_bar_wpse_51831( $bool )
{
    if( !current_user_can( 'edit_posts' ) )
        $bool = false;

    return $bool;
}

References:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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