There are heaps and heaps of membership plugins out there, all of them focusing on restricting site content based on the users chosen subscription.
I would however only want the user role to change from “have paid” to “haven’t paid” when the subscription time runs out, still allowing them to view all the site content but only limited to the role capabilities I’ve set previously.
EDIT (for clarification):
My users have a public profile page on which they present themselves and their services. They pay annually to stay public, but if they haven’t payed they should be hidden from the site, i.e change role to “invisible” instead of “public”. Today I do this manually by keeping dates on each user and change their role when needed to, which is quite tedious.
Presumably you’ve saved an expiration data somewhere, so setup a
wp_cron
job to run daily. That job should check the expiration dates, and change the roles for users whose dates are past.I am assuming that the expiration date is stored in user meta and I am guessing at the role slug.
Untested but that should be close. I would alter the time components so that it runs at some low traffic time on your site.