---
title: Architecture
url: https://lhero.org/portfolio/lh-multiple-roles/architecture/
date: 2026-10-20T15:55:48+11:00
modified: 2026-10-20T15:55:48+11:00
type: lh-portfolio-doc
---

- **Part of:** [LH Multiple Roles](https://lhero.org/portfolio/lh-multiple-roles/)

## Buckets

- **Site**: every role not in another bucket. This is WordPress’s own `role` select and Role column, so core’s own checks on `user-new.php` and `user-edit.php` keep working.
- **Forum**: `bbp_get_dynamic_roles()`. The select uses bbPress’s field name `bbp-forums-role`, so bbPress’s own handlers save it on edit, add-existing, invitation and signup. This plugin only handles clearing it, because bbPress ignores an empty value.
- **Shop**: `customer` and `shop_manager`, limited to roles registered on the site. Saved by this plugin.

## Keeping roles across set\_role()

`WP_User::set_role()` removes every role a user holds. `keep_bucket_roles()` hooks `set_user_role` and, whenever a site role is set, adds back the forum and shop roles from `$old_roles`. This covers the Edit User screen, the bulk Change role action and code such as `wp_update_user()`. Bucket saves that run later (bbPress at `profile_update` 10, this plugin at 20) still apply the user’s new choice.

## Shop role paths

- Edit User: `profile_update` 20.
- Add New User on a single site: `user_register`.
- Add New User on multisite: `signup_user_meta` stores the role, and `wpmu_activate_user` 20 applies it on the signup’s `add_to_blog` site.
- Add Existing User: `invite_user` stores the role in user meta `lh_multiple_roles_pending_shop_role_{blog_id}`, and `added_existing_user` applies it, or reads the posted value when no confirmation is needed.

## Permissions

Editing needs `promote_user` on the target user, and never applies to the editor’s own account. A shop role is offered only when the current user holds every capability in it. A user’s current forum or shop role that the editor could not grant is shown disabled and is left unchanged on save.

## Admin UI

- On the user screens (`user-edit.php`, `user-new.php`, `users.php`), `editable_roles` drops forum and shop roles from the site Role select and from core’s validation of it.
- `get_role_list` drops them from the Role column.
- Forum role and Shop role columns are inserted after Role.
- bbPress’s own Forum Role field (`BBP_Users_Admin::secondary_role_display`, `bbp_add_user_form_role_field`) and column (`user_role_column`, `user_role_row`) are removed on `admin_init` 100. bbPress’s bulk forum-role dropdown and row actions are kept.

## Filters

- `lh_multiple_roles_return_forum_role_slugs`
- `lh_multiple_roles_return_shop_role_slugs`
- `lh_multiple_roles_return_assignable_shop_roles`
- `lh_multiple_roles_init_plugin`