Support » Plugins » Hacks » Different attachment depending on user role?

  • Hello.
    Im in a bit of a sticky situation right here.. A client of mine has different companies that should be part of his site, and my initial thought is to create user-roles for each different company and put the users into the correct user-role. Now to the “problem”. He wants to have static pages, the same text and images, but the attachments to the page should vary depending on which user-role the user displaying the page has. Is there a plugin for this, or how would I go about implementing this myself?

    Thanks in advance, Christopher

Viewing 14 replies - 1 through 14 (of 14 total)
  • What I need is basically something like the adminpart of this, for user-roles, and then some way of displaying the attachments for the page where the user-role is activated.


    and then

    To add a custom attribute to the user, once logged in you can make the template change depending on the value of the custom attribute


    add data to

    Im not following you a 100%, but I don’t think that is what Im looking for. Thanks for the reply!

    This mean that the custom user attribute can then be tagged in a page they make by using the custom vars available on each page

    add data to

    1) set up admin user
    2) assign attribute value x for company to user
    3) when user makes a page value x is saved with the page metta this will then control y display in the template

    echo 'you are from company1';

    Thanks, however this does not fix my “main problem” with having the attachment lists vary depending on which role/custom var the user has..

    Reading this page will give you the answer you need as you can retrieve the “role/custom” for the user in the template using this, just like my function above

    Yes, that part is clear. But it still does not do anything about the attachment problem. I somehow need to be able to tell each attachment uploaded to each page that it should only be displayed to user-role X.

    Pages -> Add New -> Screen Options (top right of page) -> Custom Fields
    Posts -> Add New -> Screen Options (top right of page) -> Custom Fields

    Make sure this is ticked!

    Scroll down the Custom Fields block should be visible

    use it to Make new var/attributes


    Then for each page or post simply add the URL for the attachment to each of these var/attributes using the information on this page to retrieve this in the template

    That is way to complex for a client to handle..

    I don’t think your understanding me correctly phillbooth.. For each page, I want to have the exactly same content. In the sidebar of this page, I want to load the media files that has been attached to this page. When an administrator uploads a new file, they should have the abilitity to choose which user-role(s) this file should be visible to. Each page should be able to hold multiple files, and view the different files only for the user-role(s) that has been ticked of in the upload phase. The client in this case has different versions of the same documents based on which company their client is associated to.

    Yes I have answered this.

    Ok to break it down a file is uploaded this is done normally.

    On a page or post you add an marker (variable) in the “Custom Fields” section

    variable name will reference the file to download if user type 1
    i.e file1 or file_2


    file1 =
    file2 =

    Then on the template you code it to get this information and the user-role to display the correct file.

    What you need to do is get your head around WP Custom Fields first and then everything will be more simple

    Moderator bcworkz


    Hello all,

    Christopher, I believe phillbooth is pushing the custom fields because it is the easiest way to achieve the functionality you seek. I sense your reluctance is partly you not fully grasping the power of custom fields and partly intuitively knowing custom fields is a bit too clunky for your client. For this application, I agree custom fields is a bit clunky, even if it is easy to implement.

    Unfortunately, your idea of choosing an applicable role during the actual upload, while a good one, may be difficult to implement, as the media uploader is fairly new, and we’re still figuring out how to hack it.

    One thing that would be useful to know is what media are we really talking about? In another place you mention documents. If the upload process is more about selecting files to upload and less about seeing images and entering caption and other meta, I have another idea.

    Take a step back from custom fields and develop a custom meta box instead. While custom fields are basically text fields, meta boxes can be any html content, including pull downs, check boxes, etc. I can see a meta box that looks very much like what phillbooth is suggesting, except next to each role’s text field is an upload button. The button could launch a multi-file upload dialog, the results after the upload process are stored in a comma delimited list in the text field.

    Instead of selecting a role when the file is uploaded, upload all files for a role at one time. Then do the same for the next role. Will this work for your client?

    Then when displaying the sidebar, script retrieves the file list associated with the current user’s role and builds a link list to each file. This will take more coding than phillbooth’s approach, which was almost none. But it should be more intuitive for your client.

    While the primary process is straight forward, adding complete usability will be a project. Such as the ability to delete, modify, or reassign the files that were initially uploaded. These can be incrementally implemented as needed.



    I’m looking for something similar.
    Now I’m trying to use eg attachments plugin to display list of files depending on the user role.
    I want to manage the assigment from the backend media panel with checkboxes.

    Let me know if you have found anything usable.. 😉

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Different attachment depending on user role?’ is closed to new replies.