Move Users Posts To Draft When User Role Changes After Expired Subscription

The code in this tutorial is a extension of the code in this tutorial which enables you to delete the posts of users when their role changes.

When the role of the user is changed to customer ( customer being a custom role ), the status of all posts published by the user will change from published to draft.

So rather than delete the posts when a users subscription expires, this code changes the status of the posts from published to draft.

Here’s the code you can paste at the end of your child themes functions file or in a Must Use plugin.

Demo Video

Shows the test post status changed from published to draft when the user role changes from editor to subscriber ( customer ).


Comments

4 responses to “Move Users Posts To Draft When User Role Changes After Expired Subscription”

  1. Paul Matthew Avatar
    Paul Matthew

    Thanks for checking Brad. Does it only work if the user has one role on the site? My users have 3-4 different roles.

    1. I only tested with editor. You can try and see if it works with other roles, it might. You are welcome to order a custom extension of this code to work with CPT’s. I estimate 1 hour of work https://wpsites.net/product/hourly-consulting/

  2. Paul Matthew Avatar
    Paul Matthew

    Hi Brad,

    This is exactly what I need, but it’s not working for me.

    Posts should be set to draft is a user has the role called “expired”
    The post type that is called “gd_place”

    Any idea what I need to change in my code?

    1. Hi Paul. I re-tested the code and it does exactly as shown in the demo videos, description and/or screenshots. https://youtu.be/rNhjUirS-74

      I also tested it using a CPT and it works as long as the editor is publishing a new single CPT NOT a standard post. To make it work with standard posts when using a CPT requires code modification and testing.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.