User Levels/Roles and Capabilities

Quick Example of a User Role Change

$user_id = 123;
$user = new WP_User($user_id);

Where s2member_level1 could be any Role that you've configured in your WordPress installation.

Here are the most common Roles



Adding/Removing Individual User Capabilities

$user_id = 123;
$user = new WP_User($user_id);

Automating Changes via a CRON Job

If you wanted to loop through all of your Users in a CRON job, or in some other custom coding project, you might do something like this.

Create this directory and file: /wp-content/mu-plugins/my-cron-job.php

add_action('init', function ()
    if(!empty($_GET['my_cron_job']) && $_GET['my_cron_job'] === 'secret-cron-job-key')
        foreach(get_users() as $user)
            $user         = new WP_User($user->ID);
            $_10_days_ago = strtotime('-10 days');
            if(s2member_registration_time($user->ID) <= $_10_days_ago)
                # A Member for at least 10 days.
                # Promote them now to Level #2.

Now create a CRON job that calls this URL periodically (once a day perhaps).

Be very careful that you do not modify the Administrator's Role on the site. If you do, you may lose access to your WordPress Dashboard. If this happens, you can set the Role for your account back to an administrator.

$user = new WP_User('admin'); // Whatever your Username is.

Post/Page Levels/Roles and Capabilities

Example of a Post/Page Level Restriction Change

The following example will add two Post IDs and two Page IDs to the ones already protected by a Level 1 restriction.

add_action('ws_plugin__s2member_after_loaded', function(){
    $options = &$GLOBALS['WS_PLUGIN__']['s2member']['o'];

    $options['level1_posts'] .= ',5664,2232'; // Add these Post IDs to those that are already protected.
    $options['level1_pages'] .= ',4688,3320'; // Add these Page IDs to those that are already protected.

    update_option('ws_plugin__s2member_options', $options);

See also:

Example of a Post/Page Capabilities Restriction Change

The following example will set two Custom Capability requirements (pro and unlimited) for a Post with ID 123.

$ccaps_required = array('pro', 'unlimited');
update_post_meta(123, 's2member_ccaps_req', $ccaps_required);

See also: