示例#1
0
/**
 * Add a new role
 *
 * Usage: add_role( 'super-editor', 'Super Editor', array( 'level_0' => true ) );
 *
 * @param string $role Role name
 * @param string $name Display name for the role
 * @param array $capabilities Key/value array of capabilities for the role
 */
function add_role($role, $name, $capabilities)
{
    if (function_exists('wpcom_vip_add_role')) {
        wpcom_vip_add_role($role, $name, $capabilities);
    } else {
        global $wp_user_roles;
        $role_obj = get_role($role);
        if (!$role_obj) {
            \add_role($role, $name, $capabilities);
            if (!isset($wp_user_roles[$role])) {
                $wp_user_roles[$role] = array('name' => $name, 'capabilities' => $capabilities);
            }
        } else {
            merge_role_caps($role, $capabilities);
        }
    }
}
 protected static function add_role()
 {
     if (function_exists('wpcom_vip_add_role')) {
         wpcom_vip_add_role(self::VIP_SUPPORT_ROLE, __('VIP Support', 'a8c_vip_support'), array('read' => true));
         wpcom_vip_add_role(self::VIP_SUPPORT_INACTIVE_ROLE, __('VIP Support (inactive)', 'a8c_vip_support'), array('read' => true));
     } else {
         add_role(self::VIP_SUPPORT_ROLE, __('VIP Support', 'a8c_vip_support'), array('read' => true));
         add_role(self::VIP_SUPPORT_INACTIVE_ROLE, __('VIP Support (inactive)', 'a8c_vip_support'), array('read' => true));
     }
 }
/**
 * Duplicate an existing role and modify some caps
 *
 * Usage: wpcom_vip_duplicate_role( 'administrator', 'station-administrator', 'Station Administrator', array( 'manage_categories' => false ) );
 *
 * @param string $from_role Role name
 * @param string $to_role_slug Role name
 * @param string $to_role_name Display name for the role
 * @param array $modified_caps Key/value array of capabilities for the role
 */
function wpcom_vip_duplicate_role($from_role, $to_role_slug, $to_role_name, $modified_caps)
{
    $caps = array_merge(wpcom_vip_get_role_caps($from_role), $modified_caps);
    wpcom_vip_add_role($to_role_slug, $to_role_name, $caps);
}
示例#4
0
 /**
  * Adds the student role
  */
 public function hsinsider_add_role()
 {
     wpcom_vip_add_role($this->role, __('Student'), array('read' => true, 'edit_posts' => true, 'upload_files' => true, 'edit_published_posts' => false, 'level_1' => true));
 }