#2103 closed defect (bug) (fixed)
bbp_set_current_user_default_role() on switch_blog is breaking new blog signups
Reported by: | boonebgorges | Owned by: | |
---|---|---|---|
Milestone: | 2.3 | Priority: | high |
Severity: | major | Version: | 2.1 |
Component: | API - Roles/Capabilities | Keywords: | needs-patch |
Cc: | boone@… |
Description
(I've only tested the following via the BP create-a-blog interface, but it looks like the problem is BP-independent.)
Basically, bbPress is forcing blog creators from the Administrator role to Participant, or to have no role at all.
When creating a blog, wpmu_create_blog()
calls switch_to_blog()
, which in turn calls (through the switch_blog
hook) the bbp_set_current_user_default_role()
function. This happens just before wpmu_create_blog()
calls add_user_to_blog()
. But this latter call doesn't happen correctly because of something bbPress is doing. I turned on debug mode and noticed that I was getting a PHP warning in bbg_get_user_blog_role()
(I think that your filter on editable_roles
is broken), so that might be part of what's going on.
If I do the following, the problem is fixed:
remove_action( 'switch_blog', 'bbp_set_current_user_default_role' );
Sorry I don't have more debug info or a suggested fix - I've run out of time at the moment, but wanted to point out the problem before I forgot about it.
This was a brute-force attempt at making sure bbPress roles and capabilities were always available, as switch_to_blog reinitializes the WP_Roles object in such a way that it cannot be reliably hooked in to.
The problem this attempts to solve, is situations where switch_to_blog() is used, restore_current_blog() does not repopulate the original roles and capabilities, but rather reloads them from the database without any actions. This effectively wipes out bbPress's dynamic roles, causing currently logged in users to appear not to have the correct role & caps.
I see two possible solutions:
As I type this, I think the second option makes the most sense, and is the most thorough.