• I’m working on a website that assigns different roles to different users. 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 ‘unpublished’ 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:

    All posts are still published, but only the user and admins can see it.
    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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,
    You could use the hook set_user_role to run a function that goes through the list of posts that the user posted and change the published state using wp_update_post.

    Thread Starter tille

    (@tille)

    Thank you for your suggestion! The more I think about it, the less pracical 2) appears to be…?Thinking of an author with hundreds of posts it would probably be close to impossible to re-publish everything once the author has updated his/her membership. So 1) would definitely be the preferred approach

    Only now I see that the numbered bullet list does’nt show numbers –?so I’ll post the two approaches again…

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

    so when you say publish content of type “A”, is that a custom post type?
    if so, on the A post type archive and single template pages, you can test the user’s role and show or hide the posts accordingly.
    If you want the user to still see his own posts on the frontend, you can test if the user is the author of the post and maybe show him some kinds of alert alongside the post that he should reactivate his account.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to unpublish or 'hide' posts when author's user role changes?’ is closed to new replies.