How to customize admin posts based on the user who is logged in

We are building a site that will have 10-15 photographers posting content.
There will be a common blog + each admin has their own portfolio to manage. “Portfolio galleries” and “portfolio pages” are two custom types and they are categorized using “Artist”, a custom taxonomy.

We would like all admins:

Read More
  1. to be able to see all blog posts
  2. be able to post in the blog
  3. be able to add new “portfolio galleries” and “portfolio pages” and have them automatically tagged with the “artist” taxonomy with the same value as their name (i.e. John Smith will be able to only create portfolio pages and galleries automatically tagged with *Artist = “John Smith”*)
  4. be able to only view portfolio pages and galleries that belong to them (i.e. John Smith will only see portfolio pages and galleries that are marked with *Artist = “John Smith”*)

Finally we would also like to have a couple of “super admins” that will have access to every post on the site.

Any ideas on how to go building something like this? Is it even feasible?


EDIT
Following @בניית אתרים suggestion I have read a bit more about Roles and Capabilities and realized that WordPress already supports out of the box the ability to limit users from editing other people’s posts. All I needed to do was to switch all the users to be Authors instead of Editors.

In brief #1, #2 and #4 from the above list are resolved. I still need to get #3 to work using save_post.

Related posts

Leave a Reply

2 comments

  1. Short: yes you can do that.

    to be able to see all blog posts

    the default editor role can manage to see all posts

    be able to post in the blog

    again the default editor role can manage to see all posts

    be able to add new “portfolio galleries” and “portfolio pages” and have them automatically tagged with > the “artist” taxonomy with the same value as their name (i.e. John Smith).

    For that you can use the save_post hook and automatically add there username as taxonomy.

    be able to only view portfolio pages and galleries that belong to them
    (i.e. John Smith will only see > portfolio pages and galleries that are
    marked with Artist = “John Smith”)

    when registering post types you can define capabilities for that post type and you need to define edit_others_posts as false, also make sure that your post type supports author.

    Finally we would also like to have a
    couple of “super admins” that will
    have access to every post on the site.

    the default admin role is your friend in this case.
    basically most of your issues are with Roles and Capabilities

    hope this helps

  2. If I will be the one building that site, this is what I’ll do for the “View Portfolio Pages and Galleries that belong to them”:

    1.) I’ll create a new page template, say template-portfolio.php inside your themes directory, that goes something like this:

    <?php
    /*
    Template Name: Portfolio
    */
    if(is_user_logged_in() && current_user_can('manage_options'))  //ensure that it is an admin, as per requirements
    {
       global $current_user;
       get_currentuserinfo(); //information shall be stored in $current_user
       // echo 'User ID: ' . $current_user->ID . "n";
    
       query_posts(array('Artists' => $current_user->display_name));
    
        //do the loop here.
    
    }
    else
    {
      wp_redirect(get_bloginfo('url')); //go to home page if not logged in or if not admin
    }
    ?>
    

    2.) I would create a Page in wordpress and assign Portfolio as the Page Template

    3.) I would view the Page using page preview, and if it works, I’ll pat myself in the back 😉

    You can do a variant of the flow here for your other concerns.