WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Multiple users – only allow them to see their own posts when logged in?

[Resolved] Multiple users – only allow them to see their own posts when logged in?

  • monkeyfight
    Member

    @monkeyfight

    Hi. I’m creating a site based on WordPress, not a blog as such but I think I’ll be able to use/customise it’s functionality to suit my needs really well.

    One of the first things I need to work out how to do is this…

    Say I only have 2 users for a start, user1 and user2, can I change the admin interface so that user1 can only see his own posts and user2 can only see hers?

    Using the default config of WP2.2 that I’m playing with whoever you’re logged in as you can see all posts when you click on the ‘Manage’ – but I’d like to limit that view to the current logged in user if that’s possible?

    Hope someone can help.

    Thanks a lot,
    Rich

Viewing 13 replies - 1 through 13 (of 13 total)
  • Get the Role Manager plugin and you will be able to define custome roles.

    I’m not convinced Role Manager will work here if the idea is to just show the posts that user wrote in Manage Posts, and I’m not sure there is a plugin that will do this exactly.

    Some of the plugins that limit access to Categories might be made to work.

    I’m guessing you might need to either write your own plugin, or modify the core code that displays the Manage Posts screen.

    Maybe I’ve missed the “what to view” line…
    Is it important what they view or what they can edit?

    For sure, there is such a capability in the RM plugin: “Edit Others Posts”.

    Excellent point about the Edit others posts capability, moshu! Guess we’ll have to see what monkeyfight says ๐Ÿ˜‰

    monkeyfight
    Member

    @monkeyfight

    Cheers for the advice guys. Role Manager looks useful and I may end up using on my project anyway now I know it exists, but it didn’t limit the view in the ‘Manage’ tab to just the posts that the logged in user had created.

    I found this though after some more digging, all you need to do is add this into the edit.php file…

    if (!current_user_can('edit_others_posts'))
    $author = $user_ID;

    And it works perfectly, If I log in as user1 I can only see posts I’ve created as user1!

    I found it here http://wordpress.org/support/topic/96045?replies=4

    Just one question, where in edit.php did you add that code?

    Thanks for the response.

    monkeyfight
    Member

    @monkeyfight

    To be honest I don’t think it matters. But I’m probably very wrong about that ๐Ÿ™‚

    I’m deffinitely no coder so I tried it in a few different places, and it seemed to work just as well wherever I put it.

    As long as it’s somewhere between the <?php require_once('admin.php'); at the top of the file and above the <?php include('admin-footer.php');?> at the bottom it looks like it works.

    I ended up putting it just beneath the line of code that says wp('what_to_show=posts&posts_per_page=15&posts_per_archive_page=-1');

    Hope that helps!

    monkeyfight–I couldn’t get your example to work but this change to wp-admin/edit.php worked better for me:

    changed:
    wp('what_to_show=posts&posts_per_page=15&posts_per_archive_page=-1');

    to

    $thisauthor='';
    if (!current_user_can('edit_others_posts'))
    $thisauthor = '&author=' . $user_ID;
    wp('what_to_show=posts&posts_per_page=15&posts_per_archive_page=-1' . $thisauthor);

    Michael, thanks for your code, wich works fine for me (www.ci-jou.de, wordpress 2.2.3)
    But now the list of the current users posts isn’t paged anymore. Do you know any solution?

    Thanks,
    Rita

    Hi Rita: Does this work for you?

    $thisauthor = '';
    
    if (!current_user_can('edit_others_posts'))
    	{ $thisauthor = '&author=' . $user_ID; }
    
    wp('what_to_show=posts$post_status_q&posts_per_page=15&order=$order&orderby=$orderby' . $thisauthor);

    (changed the wp call back to “default” with MichaelH’s $thisauthor tacked on)

    If you are still interested, I think that I’ve created a WordPress plugin that replicates this functionality without having to edit any WordPress files.

    Manage Your Posts Only WordPress Plugin

    Let me know what you think!

    Hi mincus…
    I’ve many authors and this plugin is perfect.
    Thanks a lot

    Hi, mincus.

    Firstly, thanks a lot for plugin!

    Secondly, can you do the same for the comments page?

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Resolved] Multiple users – only allow them to see their own posts when logged in?’ is closed to new replies.