This tutorial provides the code which enables you to delete all posts ( and change capabilities ) for any user role if the subscribers role changes to customer.
The code has been written for a member based on this question :
I am using WooCommerce subscriptions. And members are able to create an entry to a custom post type from the front end if they have an active subscription. That works fine. However when they do not renew their subscription, their post remains on the site and we need to manually remove the post.The post can’t remain as the value of the subscription is in being able to have the post on the site (essentially, an entry in a directory on the front end). So I need a code which works along the lines of… If a subscriber’s subscription expires, THEN remove the post by that subscriber in custom post type “author”. When a person becomes a subscriber, they are given a new user role in WP “subscriber”. When their subscription expires they are reverted back to a standard role (called “customer”).
Shows how the subscriber can publish posts which are deleted when the subscriber role is changed to the customer role with read only capability.
Step 1: Here’s the 1st of 3 code snippets you can copy & paste to the end of your child themes functions file.
The code above create a new role named customer with the read capability only.
Step 3 :
The code above modifies the default subscriber role so subscribers can edit, publish and delete their own posts.
Move Posts To Draft When Subscription Expires
If you would rather keep all users posts and move them to draft instead of delete them, use this code.