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.
Shows the test post status changed from published to draft when the user role changes from editor to subscriber ( customer ).