Ad

How To Add Permission To Edit Only One Record In Own Plugin

- 1 answer

I have own plugin where I store pubs and I want to allow pub owners to manage their site. I have no idea how to do it. How to show for specific backend user only his record?

Ad

Answer

You have two options.

  1. You can add a user_id (or owner_id) column to the pubs table. That would mean every pub belongs to a user. You would also have to add a way to define admin users. Most simple solution would be to ad is_admin column to users table. The next simplest solution is to have a role column in users and one of the roles would be "admin" (or a number that represents "admin"). Then you would use some nice application code to make all this work.

  2. You can make a user_pub table that would act as a link table that allows a many-to-many relationship between users and pubs. And you would have to make sure (in app code) that non-admin users don't have links to multiple pubs.

Option 2 is more flexible but if you don't need that much flexibility (now or in the future) option 1 is simpler.

Ad
source: stackoverflow.com
Ad