I know I can limit user editing to own data, or leave it open to all users.
But I'm using WPDataTables inside Groups, so I'ld like to allow anyone who has membership of a Group, to see and edit the WPdatatable content, but not anyone outside the Group.
I can add a column that includes each Group's unique slug, and I can also access the wp_groups table which links User-ID's to slugs, but I cant think of how to automatically filter the tables to allow Group member restriction.
Has anyone else solved this already? Any suggestions?
You can only use our "Users see and edit only own data" feature to do this, but I believe we could make it work. If the dependency is a user role, for example, we could make it work.
If I have this table:
This is a manual table which has manually entered IDs from wp_users and roles from wp_usermeta:
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:
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:
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.
Thanks you so much for this solution. I tried it with my own data and had trouble replicating your result.
So I tried to test it with an identical version of your data in a fresh manual table (just a couple of my own column names) and I still don't get the same result as you. See attached.
My usermeta table has Users with various meta-value roles such as "administrator", "s2member_leve4" etc. under wp_capabilities - identical to yours.
But even with just 2 "administrator" users listed in the data, and "edit own data" checked in both tables, the table renders with only the current user data.
I don't get any errors, but the Users still cant see anything but their own data.
Are there any other table settings critical to this working?
We are located in Serbia and our working time is from 10:00 to 17:00 CET. business days.
Aleksandar is assign on our other products this week, so I will help you out.
Based on your explanation I can see that you turn on option User can see only data on table create from SQL query and that is the reason why you get those results. Please turn it off and you will get results like Aleksandar.
Please note that editing for this table will have issues or probably will not work because of the query.
Thanks for your reply - you're absolutely right, I don't know why I misunderstood that - thanks.
Unfortunately using the member role as the dependency wont solve my problem, but at least Aleks' principle works. I have to find a way to use the Group Name or Group Slug as the dependency. Which I guess I may be able to do by joining a third table, I'll keep trying.
Hi, any ideas or suggestions?
I know I can limit user editing to own data, or leave it open to all users.
But I'm using WPDataTables inside Groups, so I'ld like to allow anyone who has membership of a Group, to see and edit the WPdatatable content, but not anyone outside the Group.
I can add a column that includes each Group's unique slug, and I can also access the wp_groups table which links User-ID's to slugs, but I cant think of how to automatically filter the tables to allow Group member restriction.
Has anyone else solved this already? Any suggestions?
AJ
Hello AJ
You can only use our "Users see and edit only own data" feature to do this, but I believe we could make it work. If the dependency is a user role, for example, we could make it work.
If I have this table:
This is a manual table which has manually entered IDs from wp_users and roles from wp_usermeta:
So, then I go to create an SQL query based table which will display entries based on user roles using this query:
When I'm logged in with user ID = 1, I see this:
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:
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 | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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
Hi Aleksander,
Thanks you so much for this solution. I tried it with my own data and had trouble replicating your result.
So I tried to test it with an identical version of your data in a fresh manual table (just a couple of my own column names) and I still don't get the same result as you. See attached.
My usermeta table has Users with various meta-value roles such as "administrator", "s2member_leve4" etc. under wp_capabilities - identical to yours.
But even with just 2 "administrator" users listed in the data, and "edit own data" checked in both tables, the table renders with only the current user data.
I don't get any errors, but the Users still cant see anything but their own data.
Are there any other table settings critical to this working?
Hi Andrew,
Sorry for late response.
We are located in Serbia and our working time is from 10:00 to 17:00 CET. business days.
Aleksandar is assign on our other products this week, so I will help you out.
Based on your explanation I can see that you turn on option User can see only data on table create from SQL query and that is the reason why you get those results. Please turn it off and you will get results like Aleksandar.
Please note that editing for this table will have issues or probably will not work because of the query.
Best regards.
Kind Regards,
Isidora Markovic
wpDataTables: FAQ | Facebook | Twitter | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Amelia demo sites | Docs
You can try our wpDataTables add-ons before purchase on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables
Hi Milan,
Thanks for your reply - you're absolutely right, I don't know why I misunderstood that - thanks.
Unfortunately using the member role as the dependency wont solve my problem, but at least Aleks' principle works. I have to find a way to use the Group Name or Group Slug as the dependency. Which I guess I may be able to do by joining a third table, I'll keep trying.
Hi Andrew,
You are welcome.
I believe that you need to modify query to get results what you need.
If you have any other issue or question please open new ticket, and we help you out.
Best regards.
Kind Regards,
Isidora Markovic
wpDataTables: FAQ | Facebook | Twitter | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Amelia demo sites | Docs
You can try our wpDataTables add-ons before purchase on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables