Okay
  Public Ticket #2985147
Row access to users based on relation to post type
Closed

Comments

  • Nick started the conversation

    In our system we have users which are related to one or more Clubs (a club is a custom post type in our system). This relationship is managed via ACF. We also have a members table which we would like to be editable by only users who have been attached to that particular club. The members table would have a post_id column to represent this relationship between the member and the club.

    I saw how to restrict editing based on the user_id using your plugin, but our use case is a bit different. Is this possible with your plugin to restrict view/editing based on a relationship, either out of the box, or via hooks/filters?

  •  2,572
    Aleksandar replied

    Hello Nick

    Thank you for your interest in our plugin.

    If the dependency is a user role, for example, we could make it work.

    If I have this table:

    5458776907.png

    This is a manual table which has manually entered IDs from wp_users and roles from wp_usermeta:

    7855603551.png
    6462766399.png
    7686895681.png

    So, then I go to create an SQL query based table which will display entries based on user roles using this query:

    SELECT  new_table.id AS ID,
            new_table.role AS Role,
            new_table.product AS Product,
            new_table.amount AS Amount
    FROM wp_wpdatatable_6 AS new_table
    JOIN wp_usermeta AS new_table_1
    ON new_table_1.user_id = %CURRENT_USER_ID%
    AND new_table_1.meta_value LIKE CONCAT('%', new_table.role, '%')
    

    When I'm logged in with user ID = 1, I see this:

    9999185249.png

    When I'm logged in with user ID = 4, I see the same thing. And when I'm logged in as one of the subscribers, I can only see the rows where role = subscriber:

    2907856651.png

    The only difference is that as subscriber I don't have access to back-end, so this confirms it is working on both front and back.

    So, we're only left with hiding unnecessary columns, adding names, and so on.

    Hope this helps.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables