WCMS 3 Advent calendar #21: automatically expiring roles

Tuesday, December 21, 2021
by Kevin Paxman

Do you know that you can automatically expire roles assigned to a user? Users with the site owner role can choose to enter expiration dates for any available role. (Note that a bug in WCMS 3 means that as of this writing, you must save the user with the role selected before you can enter the expiration date.)

screenshot of a role being set to expire


These dates can be written in almost any format. (For the technical, it must be able to be parsed by strtotime.) The following are all acceptable formats, as long as the date is in the future:

  • 2022-01-30
  • 07/06/2022 (as long as your intent is month/day/year)
  • last day of April 2022
  • 2 months 1 week
  • June 1 - 1 day
  • next Monday
  • yesterday + 300 days

There are some things you'd think might work, but don't. For example, none of these are acceptable:

  • next May
  • Christmas
  • 300 days from yesterday
  • at the next full moon

If you just enter a date, the role will automatically expire as soon as that day begins. You can add a time as well to have the expiry end at some point during the day. You have some flexibility here as well - for example, you can enter "4pm" instead of entering "16:00:00".

Enabled roles with no expiry are active until the role is manually removed.

Once you save the user, the date and time will convert to the standard format.

screenshot of a role that has been set to expire
a decorative line

How did you like this tip? Is this something you are already doing, or maybe something you will look to adapt? Are you inspired with suggestions for future tips? Send us feedback!