logo

$5
Restricting particular pages to particular users (not just roles)

Hi

I need to be able to restrict certain menu items and pages to particular users only.

Please note: I am not talking about limiting access to particular roles, but individual users.

Example: I have 2 users, Alan and Bob, who are both customers of mine. When Alan logs in, a menu item called Alan's Pages appears. He can click on this menu item, and see a page or a list of pages relating to his account. Typically, these might contain invoices and quotes exclusive to him, and commercially confidential.

Meanwhile, Bob logs in. Bob now sees a menu item called Bob's Pages etc, but he doesn't see Alan's Pages, and doesn't even know that Alan exists. Likewise, Alan will not see Bob's Pages, nor know that he exists.

Can someone help please? I'm pretty certain that I can't do this out of the box, but am presuming that a combination of custom fields (or possibly just categories) and a couple of lines of code will do the trick. Alternatively, if there is a plugin (premium or free) that will achieve this, I'd love to know.

Thanks.

Andy Lynam | 09/01/10 at 1:36pm | Edit


(6) Possible Answers Submitted...

  • avatar
    Last edited:
    09/01/10
    1:45pm
    Monster Coder says:

    hello,
    I did not hear any plugin for this purpose! But you can hire a wordpress developer to develop a plugin for you!

    If you want to show specific page to specific user, it can be simple. Just ask your developer to make a plugin where you can allow access of specifc user to specific page! like:
    PAGE X is visible to user x, user y, user z
    PAGE Y is visable to user x, user z

    etc. !

    It would be quite simple!

    But if you need stuffs like invoicing or custom things (rather than post/page), it gonna be quite medium to big sized plugins!

    cheers!

    • 09/01/10 1:50pm

      Andy Lynam says:

      No, the invoices etc are just examples of the sort of content that might be contained there, to give an indication of why this content would be private. They are not part of this problem.

    • 09/01/10 1:54pm

      Monster Coder says:

      ok, then if pages/posts are the concerned, a plugin with admin page to define the accesses will be best for you! There are ways in wordpress to restrict contents to user!

  • avatar
    Last edited:
    09/10/10
    2:29pm
    Pippin Williamson says:

    You could do something like this:


    if ( is_user_logged_in() && is_author('Alan') )
    {
    show content here
    } else {
    show error message
    }

  • avatar
    Last edited:
    09/01/10
    1:55pm
    Eddie Moya says:

    You might be able to use custom fields to restrict the pages.

    Each of the pages your describing would have a custom field set to something like
    user_permitted = <username>
    So, in the page template itself, you could use get_post_meta to check if the <username> is the name of the person logged in.

    On the other hand, you could leverage the wordpress a different way. You could have the user set as the author of that page - then simply have the content of that page generated based off data associated with that user. As user meta, or in the options table. Several possibilities lend themselves.

    I assume you already have most of what you described - since I cant imagine your asking for someone two explain or create all that for $5. As such, if you explain a bit more of how its set up, I might be able to get more specific as to what to do.


    EDIT
    ----
    Scratch the bit about making the user an author of the page.. that would be unnecessary. In general, you just need to associate the content, with a username or user id. From there, making a page that displays that information based on the current user is fairly simple.

    Previous versions of this answer: 09/01/10 at 1:55pm

  • avatar
    Last edited:
    09/01/10
    1:53pm
    Maor Barazany says:

    I assume something like that might be achieved adding custom post type and add a fileld with the user name (you may even use the built in author filed for example).
    Than in the code that renders the UI of that content type you may determine which user is logged in and show posts from the type that matches the username that is logged in with the field that assigns the post to the user.

    Than the user Bob will see only his custom posts and user Allan will see only his.

  • avatar
    Last edited:
    09/01/10
    1:58pm
    Khanh Cao says:

    In your page template (default page.php), you can add a list of user names as custom fields and check the current user against them.

    To get the list of users (as custom fields), use get_post_meta()

    WP Custom Fields Codex

    To get the current user use:


    $current_user = wp_get_current_user();
    $id = $current_user->ID;
    $user_name = $current_user->user_login;


    For example:

    $current_user = wp_get_current_user();
    $users = get_post_meta(get_the_ID(), 'users', false);
    $accepted = false;
    if (is_array($users))
    {
    foreach ($users as $user)
    {
    if ($current_user->user_login == $user)
    {
    $accepted = true;
    }
    }
    }

    if (!$accepted)
    {
    // stop showing the page
    }

    Previous versions of this answer: 09/01/10 at 1:58pm

  • avatar
    Last edited:
    09/01/10
    2:20pm
    Roberto Mas says:

    Check out this plugin it could serve your needs http://wordpress.org/extend/plugins/role-scoper/

This question has expired.





Current status of this question: Completed