Skip to:
Content

bbPress.org

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#2103 closed defect (bug) (fixed)

bbp_set_current_user_default_role() on switch_blog is breaking new blog signups

Reported by: boonebgorges's profile 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.

Change History (5)

#1 @boonebgorges
12 years ago

  • Cc boone@… added

#2 @johnjamesjacoby
12 years ago

  • Component changed from General to Roles/Capabilities
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 2.3
  • Priority changed from normal to high

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:

  • Only call this in the 'switch_blog' action inside of restore_current_blog().
  • Hook into 'option_' . $wpdb->prefix . 'user_roles', and append the dynamic roles there. This would guarantee proper role initialization across all blogs on a multisite network where bbPress is active, and not be such a brute force hack.

As I type this, I think the second option makes the most sense, and is the most thorough.

#3 @johnjamesjacoby
12 years ago

See: bbp_filter_user_roles_option()

#4 @johnjamesjacoby
12 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [4591]) Remove 'switch_blog' hook for bbp_set_current_user_default_role(). Causing issues with multisite creation. Fixes #2103.

#5 @johnjamesjacoby
12 years ago

(In [4592]) Add additional phpdoc note to _bbp_reinit_dynamic_roles(). See #2103.

Note: See TracTickets for help on using tickets.