Skip to:
Content
Pages
Categories
Search
Top
Bottom

Fix for users of s2member and bbPress 2.2

  • There’s roles issues with s2member and the new released version of bbPress 2.2. I created a small little plugin that along with the “repair” tools bbPress makes available applies new roles to all the existing users you have with s2member roles.

    Go here for the plugin -> https://gist.github.com/4120493 – make sure you read the instructions at top of file.

Viewing 25 replies - 1 through 25 (of 33 total)

  • rossagrant
    Participant

    @rossagrant

    nerrad, that is fantastic, and thank you so much for sharing it.

    So if this assigns roles to existing members, how do we deal with new sign-ups?

    JJ, do you reckon this is a future-proof solution?

    hmm … sorry if it’s already in this thread but do new signups in s2member (for various s2member roles) get the default bbPress role added (if that’s selected in the bbPress forums options)? There is an “Auto role” checkbox in `options-general.php?page=bbpress` that when checked is supposed to automatically assign default roles to new, registered users upon visiting the site…. I’ll have to check into that and see if new s2member registered users get that default role…

    confirmed… new s2member users DO NOT have a bbPress role added. Gonna modify the plugin I referenced above now.

    kk I updated the plugin referenced in the gist above (load the filter earlier via plugins_loaded). You’ll need to leave the plugin I added live, but it will handle new s2member registrations AND eliminates the need to visit tools->forums


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    Any idea why bbPress’s bbp_set_current_user_default_role() function isn’t working?

    because s2member adds users to their own role and the map being referenced in bbp_get_user_role_map() doesn’t account for the s2member roles. So to fix I just added s2member roles to the map.

    which of course means that ANY plugin that adds users to different roles than what bbPress expects won’t have a default forum role applied.

    jjj want me to create a ticket in trac for this? I have some suggestions on how to improve this so it works with other membership plugins?


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    @nerrad – yes please, a trac ticket would be great.

    To clarify, you’re saying that s2member does not add itself to WordPress’s editable roles array, using WP_Roles->add_role() ?

    s2member does do that. But for whatever reason, those roles aren’t being picked up by bbp_set_current_user_default_role() (via $bbp->current_user->roles)


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    My first guess is s2member hooks in too late, or some other plugin is loading the current user way too early in the stack. bbPress doesn’t perform any of those actions until it expects WordPress to make them happen naturally.

    If the current_user is loaded before the ‘after_setup_theme’ action is called (because of an is_super_admin() check, a call to current_user_can(), etc…) bbPress fails gracefully, and waits until it’s time. If S2member waits until init to add its roles, or if the WP_Roles array doesn’t include the s2Member roles by the time ‘after_setup_theme’ has fired, $wp->init(); will get called, loading the current user, and bbPress will map the roles accordingly.

    Another possible problem is bbp_get_user_role_map() not mapping custom roles; it only maps to WordPress core roles. A possible fix to bbp_set_current_user_default_role() would be to array_diff() editable_roles() vs bbp_get_dynamic_roles(), loop through them, use the map where it matters, and use the default role otherwise.

    ticket created -> https://bbpress.trac.wordpress.org/ticket/2042 – I’ll do some more investigation and will post comments/suggestions in the ticket.

    see the comments posted in the ticket jjj, the problem is that a role created by a plugin isn’t in the default map, and thus it won’t get handled (b/c any roles not in the default wp_roles don’t get handled). I added a patch to the ticket.

    [edit: my brain is mush and translating to really bad grammar]


    kraigg
    Participant

    @kraigg

    Is there a similar fix or plugin for people using User Role Editor?

    I had a look at http://www.s2member.com/forums/topic/dont-upgrade-to-bbpress-2-2/ and made sure to select Spectate and ticked the same role capabilities as http://hands-4-life.de/s2member_level1.jpg but none of the users, except Administrators, can post a new topic or reply.

    I can only get it working for individual users if I manually go into the user’s profile (Admin Dashboard > Users > All Users > Edit ) and set their Forum Role as ‘Participant’.


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    bbPress 2.2.1 is incoming, to fix this bug.


    kraigg
    Participant

    @kraigg

    Thank you JJJ!


    tzeldin88
    Participant

    @tzeldin88

    I have a similar problem (though not related to s2member). I have a custom Site Role (called “Student”), which I had enabled to participate in the Forums, by assigning the necessary Capabilities (using the Members plugin from Justin Tadlock). This worked fine in bbPress v2.1.2.

    But I just updated to bbPress v2.2.1, and now bbPress has a new concept of Forum Roles, separate from (but somehow related to) Site Roles. So now all my Student users are unable to participate anymore!

    I do NOT want to have to manually set the new Forum Role for each Student. Instead, I tried using the Members plugin to (again) add the necessary Capabilities to my Student role, to match those of bbPress’s new Participant role. I did this by matching the checkboxes displayed by the Members plugin. But this did not work. In fact the Members plugin shows that a Participant has 28 Capabilities, though only 8 are actually “checked”. So are some of a Participant’s capabilities somehow HIDDEN? Can I somehow tell bbPress to use my Student role?

    Hoping for help on this.


    tzeldin88
    Participant

    @tzeldin88

    To clarify my question above — According to this (https://bbpress.org/forums/topic/spectator-and-visitor-someone-can-explain-this-roles/) the Capabilities of a Participant are:
    – assign_topic_tags
    – edit_replies
    – edit_topics
    – participate
    – publish_replies
    – publish_topics
    – read_private_forums
    – spectate

    So I assigned those same Capabilities to a different role — a custom role called Student — but the Student still can’t actually participate in the forum.

    (I used Justin Tadlock’s Members plugin to create the custom role, and assign the capabilities.)

    Thanks! -Todd


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    @tzeldin88 – There’s a tool to batch the user forum role process, in Tools > Forums

    It’s likely the custom roles you’re making won’t work, at least I haven’t tried it yet myself. While it’s not impossible to make work, I don’t think it’s a great setup for the future of your site.

    WordPress purposely excludes a UI for roles and capabilities because they’re easy to muck up, and difficult to reset back to stock.


    tzeldin88
    Participant

    @tzeldin88

    Hi JJJ, thanks for the rapid reply! Just to clarify:

    I’m already using this custom role (Student) in other ways throughout the site, so I can’t scrap it. Participating in the Forum was one of the things a Student could do, and participation in the Forum was restricted to ONLY Students.

    I don’t actually have many Students yet, so I can actually just delete and re-add them, to fix any wrong/old capabilities, and avoid any “resetting”.

    The issue is really more about simplifying the process for my client (the site admin) — so he doesn’t need to set a Student’s role in two different fields, in the admin: the normal wp Role field, and now this new Forum Role drop-down (which is at the bottom of the profile screen).

    So I think I need the DEFAULT bbPress Role to be Spectator (for public / non-logged-in users, and another custom role, called Schools), so they can’t participate.

    And I’d like my Student role to have the same (EFFECTIVE) Capabilities as a Participant, so the site-admin doesn’t need to set that separately. But it sounds like you’re saying that’s just not really possible, even though the Members plugin SEEMS able to assign the capabilities correctly.

    Thanks again for your time and attention.
    -Todd


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    @tzeldin88 – Again, difficult to be confident, but you could filter bbPress’s role mapping, to add custom comparisons for your newly created roles. Then bbPress will just naturally make:

    X site role = Y forum role

    with each new user that visits the site.

    The filter you’d want to use, is bbp_get_user_role_map. It looks like this:

    /**
     * Return a map of WordPress roles to bbPress roles. Used to automatically grant
     * appropriate bbPress roles to WordPress users that wouldn't already have a
     * role in the forums. Also guarantees WordPress admins get the Keymaster role.
     *
     * @since bbPress (r4334)
     *
     * @return array Filtered array of WordPress roles to bbPress roles
     */
    function bbp_get_user_role_map() {
    
    	// Get the default role once here
    	$default_role = bbp_get_default_role();
    
    	// Return filtered results, forcing admins to keymasters.
    	return (array) apply_filters( 'bbp_get_user_role_map', array (
    		'administrator' => bbp_get_keymaster_role(),
    		'editor'        => $default_role,
    		'author'        => $default_role,
    		'contributor'   => $default_role,
    		'subscriber'    => $default_role
    	) );
    }

    tzeldin88
    Participant

    @tzeldin88

    Wow! Bingo! THANK YOU JJJ. Super simple fix too. Here’s what I did, if this helps anyone else:

    add_filter('bbp_get_user_role_map','my_bbPress_role_map');
    function my_bbPress_role_map($role_map){
    $role_map['student'] = bbp_get_participant_role();
    return $role_map;
    }

    This is added to my functions.php.


    plannerguy
    Participant

    @mdlepage

    @JJJ – need help in the same regard.

    I’m using amember and not s2member – and I need to block users from bbpress when their subscription becomes inactive (which means they are assigned a WP role of “amember expired” by amember).

    Will JJJ’s code or tzelding88’s code above achieve this? Will it sustain mapping so that when a user’s WP role changes, bbpress’s role changes as well?

    Many thanks.


    WebSharks
    Participant

    @websharks

    Thanks to everyone for reporting this compatibility issue between s2Member and bbPress v2.2+.

    I’m Jason Caldwell, a developer over here at s2Member.com.

    The latest release of s2Member includes a fix for this compatibility issue.

    (s2Member/s2Member Pro) Compatiblity.
    Updated to support Dynamic Roles introduced in bbPress® v2.2. Discussed in this thread. Also see changelog: http://www.s2member.com/changelog/#s2-changes-v121201

    Please let us know through the forums at s2Member.com if you have any further trouble. Thanks again!


    WebSharks
    Participant

    @websharks

    For those having problems with Roles/Capabilities where s2Member/bbPress is concerned, you might want to take a look at this thread for some helpful tips. We’ve been working with some folks on this lately, so perhaps this thread will save you some grey hair 🙂

    See: http://www.s2member.com/forums/topic/uninstalling-s2member-causes-permission-issue/#post-35231

Viewing 25 replies - 1 through 25 (of 33 total)
  • You must be logged in to reply to this topic.
Skip to toolbar