WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create a membership site on WP where each members will have access to only specific pages created for them. I mean just a member is allowed to view content on a page while that page is restricted to others. I just to grant on a member access to a page. I don't know if this is possible with the help any plugin

share|improve this question

The same concept as Dominic's (no need of a members plugin) but expanded to use a Meta Box, visible only for Admins, with a dropdown list with all the users (with exceptions).

Code borrowed and adapted from this answer. Put in functions.php:

// List Users
add_action( 'admin_init', 'wpse_33725_users_meta_init' );
// Save Meta Details
add_action( 'save_post', 'wpse_33725_save_userlist' );

function wpse_33725_users_meta_init()
    if( current_user_can( 'administrator' ) )
        add_meta_box( 'users-meta', 'Authorized User', 'wpse_33725_users_meta_box', 'page', 'side', 'high' );

function wpse_33725_users_meta_box()
    global $post;
    $custom = get_post_custom( $post->ID );
    $users = $custom["users"][0];

    // prepare arguments
    $user_args  = array(
        // exclude users from the list using an array of ID's
        'exclude' => array(1),
        // order results by display_name
        'orderby' => 'display_name'
    // Create the WP_User_Query object
    $wp_user_query = new WP_User_Query($user_args);
    // Get the results
    $authors = $wp_user_query->get_results();
    // Check for results
    if ( !empty($authors) )
        // Name is your custom field key
        echo "<select name='users'>";
        echo '<option value=0>All</option>';
        // loop trough each author
        foreach ( $authors as $author )
            $author_id = get_post_meta( $post->ID, 'users', true );
            $author_selected = ( $author_id == $author->ID ) ? 'selected="selected"' : '';
            echo '<option value='.$author->ID.' '.$author_selected.'>'.$author->user_nicename.'</option>';
            echo "</select>";
        echo 'No authors found';

function wpse_33725_save_userlist()
    global $post;

    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
        return $post->ID;

    update_post_meta( $post->ID, "users", $_POST["users"] );

For checking permissions, this works outside the loop in page.php:

$the_user = get_post_meta( $wp_query->post->ID, 'users', true );

if( '0' == $the_user || empty( $the_user ) ) 
    echo "this is a public page";
    if( get_current_user_id() == $the_user ) 
        echo "this page is for you";
        header("Status: 302");
share|improve this answer

I would also recommend checking out plugins such as paid memberships pro (free), Premise Landing Pages (paid) and restrict content pro (paid). These all could solve your problem.

share|improve this answer
Please at least provide links to the plugins you mention. – s_ha_dum Mar 31 '13 at 23:14

You could add the IDs of allowed users to a custom field on certain pages. Then use get_current_user_id() and see if it's a match before showing the content.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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