Manually adding more membership levels

IMPORTANT NOTES:

  • This involved modifying the code of the WP Full Pay Members plugin.
  • We cannot support customized plugins or add-ons.
  • If up upgrade to a newer version of the add-on your changes will be overwritten

When to use this

The approach described in this guide is meant for those that either want to change the names of the membership levels, or add additional levels. You will need to be comfortable with changing code and have enough knowledge around WordPress etc. to be able to debug issues on your own.

When working with roles and users we recommend using the User Role Editor plugin as covered by this guide


Instructions

This tutorial assumes you have WP Full Stripe Members v1.10.2, which is where the code line numbers are from.

Be mindful of this:

  1. Once a Wordpress role is created, you cannot change its identifier or its name.
  2. You cannot delete a role if it's assigned to at least one user.
  3. Before making changes to the installed plugin, deactivate it.
  4. One of the plan arrays (role_plans) is cached in the options table, and you must force the plugin to reload its options so this option is refreshed.
  5. Only one plan can be assigned to a role currently.

Let's say you'd like to add a new membership role called 'Diamond'.

You'd need to make the following changes in the "include/wpfsm-main.php" file (it's the only file you need to modify):

Step 1: add new role definition

Add the new role in the same place as the other roles (starting on line 13):

const ROLE_NO_ACCESS = 'wpfs_no_access'; 	
const ROLE_BASIC = 'wpfs_basic';
const ROLE_BRONZE = 'wpfs_bronze';
const ROLE_SILVER = 'wpfs_silver';
const ROLE_GOLD = 'wpfs_gold';
const ROLE_DIAMOND = 'wpfs_diamond';
const ROLE_ALL_ACCESS = 'wpfs_all_access';

We use the prefix "wpfs_" to help distinguish from other text strings.

Step 2: Modify setup() function

In the setup() function (starting on line 89) modify the rolePlans, roleRanks, nameRoles arrays:

$this->rolePlans = array(
    self::ROLE_BASIC => null, 
    self::ROLE_BRONZE => null, 
    self::ROLE_SILVER => null, 
    self::ROLE_GOLD => null, 
    self::ROLE_DIAMOND => null, 
    self::ROLE_ALL_ACCESS => null
);

$this->nameRoles = array();
$this->nameRoles[self::resolveRoleNameByCode(self::ROLE_NO_ACCESS)] = self::ROLE_NO_ACCESS;
$this->nameRoles[self::resolveRoleNameByCode(self::ROLE_BASIC)] = self::ROLE_BASIC;
$this->nameRoles[self::resolveRoleNameByCode(self::ROLE_BRONZE)] = self::ROLE_BRONZE;
$this->nameRoles[self::resolveRoleNameByCode(self::ROLE_SILVER)] = self::ROLE_SILVER;
$this->nameRoles[self::resolveRoleNameByCode(self::ROLE_GOLD)] = self::ROLE_GOLD;
$this->nameRoles[self::resolveRoleNameByCode(self::ROLE_DIAMOND)] = self::ROLE_DIAMOND;
$this->nameRoles[self::resolveRoleNameByCode(self::ROLE_ALL_ACCESS)] = self::ROLE_ALL_ACCESS;

$this->roleRanks = array(
    self::ROLE_NO_ACCESS => 0, 
    self::ROLE_BASIC => 1, 
    self::ROLE_BRONZE => 2, 
    self::ROLE_SILVER => 3, 
    self::ROLE_GOLD => 4, 
    self::ROLE_DIAMOND => 5, 
    self::ROLE_ALL_ACCESS => 999999
); 

Step 3: Modify activate() function

In the activate() function (starting on line 353) add the "Diamond" role

add_role(self::ROLE_NO_ACCESS, 'No Access', array('read' => true)); // The no_access role is used to block user from any protected pages (usually on subscription expiry)
add_role(self::ROLE_BASIC, 'Basic', array('read' => true));
add_role(self::ROLE_BRONZE, 'Bronze', array('read' => true));
add_role(self::ROLE_SILVER, 'Silver', array('read' => true));
add_role(self::ROLE_GOLD, 'Gold', array('read' => true));
add_role(self::ROLE_DIAMOND, 'Diamond', array('read' => true));
add_role(self::ROLE_ALL_ACCESS, 'All Access', array('read' => true)); 

Step 4: Modify resolveRoleNameByCode() function

In the resolveRoleNameByCode() function (starting on line 385), add the "Diamond" role to localization

    if ($role === self::ROLE_NO_ACCESS) {
        $resolvedRole =                /* translators: Membership role 'No Access' */
            __('No Access', 'wp-full-stripe-members-admin');
    } elseif ($role === self::ROLE_BASIC) {
        $resolvedRole =                /* translators: Membership role 'Basic' */
            __('Basic', 'wp-full-stripe-members-admin');
    } elseif ($role === self::ROLE_BRONZE) {
        $resolvedRole =                /* translators: Membership role 'Bronze' */
            __('Bronze', 'wp-full-stripe-members-admin');
    } elseif ($role === self::ROLE_SILVER) {
        $resolvedRole =                 /* translators: Membership role 'Silver' */
            __('Silver', 'wp-full-stripe-members-admin');
    } elseif ($role === self::ROLE_GOLD) {
        $resolvedRole =                /* translators: Membership role 'Gold' */
            __('Gold', 'wp-full-stripe-members-admin');
    } elseif ($role === self::ROLE_DIAMOND) {
        $resolvedRole =                /* translators: Membership role 'Diamond' */
            __('Diamond', 'wp-full-stripe-members-admin');
    } elseif ($role === self::ROLE_ALL_ACCESS) {
        $resolvedRole =                /* translators: Membership role 'All Access' */
            __('All Access', 'wp-full-stripe-members-admin');
    } else {
        $roleNames = MM_WPFSM::getInstance()->getWpRoleNames();
        $resolvedRole = MM_WPFSM::translateLabel($roleNames[$role]);
    }
    return $resolvedRole;

Step 5: Modify getWpRoles() function

In the getWpRoles() function (line 531), add the "Diamond" role:

    $wpRoles = array();
    $wpRoles[self::ROLE_NO_ACCESS] = get_role(self::ROLE_NO_ACCESS);
    $wpRoles[self::ROLE_BASIC] = get_role(self::ROLE_BASIC);
    $wpRoles[self::ROLE_BRONZE] = get_role(self::ROLE_BRONZE);
    $wpRoles[self::ROLE_SILVER] = get_role(self::ROLE_SILVER);
    $wpRoles[self::ROLE_GOLD] = get_role(self::ROLE_GOLD);
    $wpRoles[self::ROLE_DIAMOND] = get_role(self::ROLE_DIAMOND);
    $wpRoles[self::ROLE_ALL_ACCESS] = get_role(self::ROLE_ALL_ACCESS);
    return $wpRoles;

Step 6: Force reload of options

Once you've made your changes, you have to force the plugin to reload its configuration when activated.

WP Full Stripe and Members have their options array under the 'fullstripe_options' key, which in turn has a value stored under the 'wpfs_members_version' key. If you remove this key, it forces the plugin to reload its configuration when activated.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us