Blog

Options for Drupal Expiring Roles

Jason Narog
, Drupal Developer

Content management systems such as Drupal, WordPress, and Joomla are a great foundation for membership sites. You create content, set up who can view the content, and for how long, set up some sort of payment gateway and you’re off and running. But for a recurring membership site, trial based site, or anything that requires the ability to remove users after a certain time period, its crucial for success to have some sort of expiring roles system.

As with anything in Drupal, there are multiple ways to accomplish this goal. If you already have the rules module enabled on your site, you can use rules and rules scheduler to accomplish your goal without having to go download any additional modules. Please note that rules scheduler needs to be enabled on your modules page (or via drush) separately from the rules module.

Your basic setup using rules would involve setting up a rules component to remove the role, a rule that occurs when user account is created (or something similar), and an action to schedule your component to execute on a specific date of your choosing. You would pass something like the UID (or user ID) to the scheduler to execute. You can also use rules in tandem with other user activity modules to move your user from one role to another if so inclined, making this a very useful solution for additional functionality.

Drupal 6 and 7 (7 in beta) also has a module available known as role expire. The role expire module allows you to set a default duration for each role directly on the edit role page. Administrators would be able to set up a role such as “trial user” then set the duration, that way every “trial user” would be able to browse the site for x amount of days before having their access revoked.

If you are using Drupal Commerce, the Commerce License module wlll allow you to sell user roles on your site. This module allows you to sell your roles for either a limited or unlimited amount of time, making it a great addition to membership sites using Drupal Commerce.

Once you have expiring roles in place it’s time to pick a node privacy module. There are a ton available, with a Drupal page dedicated to listing many of your available options. If you need field level specific settings, such as displaying a field for all visitors, then another field for specific roles, the Field Permissions module may be up your alley. The module you choose for node visibility will be dependent upon your current setup, how many nodes you’ve already created, and what sort of content protection you are looking for. The task is much easier if you’re starting from scratch on a brand new site and know exactly what you want to show to whom.

If you plan ahead, or specify your goals before setting out on creating any sort of privacy setup in Drupal, your project will go that much smoother. Determine how many different user roles you want beforehand, what they can see, what they can do, and how long they last in that particular role.

 

► Website not looking or working right?
► Tell us about it.

 

Add new comment