Changing Roles/Capabilities via PHP
Posted: March 4th, 2011, 10:45 pm
Quick example of a Role change:
Where "s2member_level1", could be any Role that you've configured in your WordPress installation.
Here are the most common Roles:
Quick example of adding/removing individual Capabilities:
- Code: Select all
<?php
$user_id = "123";
$user = new WP_User($user_id);
$user->set_role("s2member_level1");
?>
Where "s2member_level1", could be any Role that you've configured in your WordPress installation.
Here are the most common Roles:
subscriber
s2member_level1
s2member_level2
s2member_level3
s2member_level4
author
contributor
administrator
editor
Quick example of adding/removing individual Capabilities:
- Code: Select all
<?php
$user_id = "123";
$user = new WP_User($user_id);
$user->add_cap("access_s2member_level0");
$user->add_cap("access_s2member_level1");
$user->add_cap("access_s2member_ccap_music");
$user->add_cap("access_s2member_ccap_videos");
$user->remove_cap("access_s2member_level2");
?>