I’m working on a website that assigns different roles to different users – and I’m looking a functionality I would probably best describe as ‘reverse access control‘:

First, users of role “A” are allowed to publish content of type “A”. If a user changes to role “B” he/she is not longer allowed to publish content of type “A”.

Now I would want to find a way to ‘unpublish‘ or ‘hide‘ whatever that user has published while he/she was still assigned the user role “A”. Currently I can think of the following two possible approaches:

  1. All posts are still published, but only the author and admins can see it.
  2. All posts are unpublished when the user role changes.

To me approach 1 sounds more practical – so in case the user switches back to role “A” everything would instantly be visible again.

I had a look at various plugins such as Members and User Role Editor but none seems to have that type of functionality – or am I missing something completely? Any pointers would be appreciated. Thank you!

2 Answers
2

Interesting functionality, you will need something that does this:

  • Will need to use the hook set_user_role to detect when user role change
  • Then will need to query all posts from that user
  • Then use wp_update_post to change the post status

Leave a Reply

Your email address will not be published. Required fields are marked *