WordPress.org

Forums

Different attachment depending on user role? (15 posts)

  1. mYrAn
    Member
    Posted 2 years ago #

    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

  2. mYrAn
    Member
    Posted 2 years ago #

    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.

  3. phillbooth
    Member
    Posted 2 years ago #

    Consider

    http://codex.wordpress.org/Function_Reference/wp_create_user

    and then

    http://codex.wordpress.org/Function_Reference/wp_insert_user

    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

    http://codex.wordpress.org/Class_Reference/WP_User

    $current_user->customvar;

    add data to http://codex.wordpress.org/Post_Meta_Data_Section

  4. mYrAn
    Member
    Posted 2 years ago #

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

  5. phillbooth
    Member
    Posted 2 years ago #

    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 http://codex.wordpress.org/Post_Meta_Data_Section

    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

    if($current_user->customvar=='company1'){
    echo 'you are from company1';
    }else{
    }

    http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/

  6. mYrAn
    Member
    Posted 2 years ago #

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

  7. phillbooth
    Member
    Posted 2 years ago #

    Reading this page http://codex.wordpress.org/Class_Reference/WP_User 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

  8. mYrAn
    Member
    Posted 2 years ago #

    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.

  9. phillbooth
    Member
    Posted 2 years ago #

    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

    Attachment_for_user_type_1
    Attachment_for_user_type_2
    Attachment_for_user_type_3

    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

    http://codex.wordpress.org/Post_Meta_Data_Section

  10. mYrAn
    Member
    Posted 2 years ago #

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

  11. phillbooth
    Member
    Posted 2 years ago #

  12. mYrAn
    Member
    Posted 2 years ago #

    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.

  13. phillbooth
    Member
    Posted 2 years ago #

    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

    so

    file1 = http://mywebsite.com/media/myvideofile1.wmv
    file2 = http://mywebsite.com/media/myvideofile2.wmv

    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

  14. bcworkz
    Member
    Posted 2 years ago #

    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.

  15. M Szatkowski
    Member
    Posted 1 year ago #

    @mYrAn
    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.. ;)

Topic Closed

This topic has been closed to new replies.

About this Topic