Skip to:
Content
Pages
Categories
Search
Top
Bottom

s2member integration

  • @wood2695

    Member

    Has anyone had success in integrating the s2Member plugin into a WordPress site with a bbPress forum?

    There has got to be a way to map the custom 2sM roles (ie. s2Member Level 4) to the standard WP “Subscriber” role for purposes of the bbPress platform, but I certainly haven’t figured it out yet.

Viewing 25 replies - 1 through 25 (of 28 total)
  • @kevinjohngallagher

    Member

    In theory, you’d need either:

    1) Deep Integration with WordPress, so you could query the WP DB on forum load

    or

    2) Write some custom code for the s2Member callback API (which it supports) to add a field to the bbPress database.

    Shouldn’t be horribly difficult; but so far, no-ones asked about it here so I can’t point you towards any examples.

    @wood2695

    Member

    Thanks for the quick response. I’ve already done the deep integration, so I’m partially there on number 1, I guess. I’ll look into how to accomplish your suggestion before I ask you to hold my hand :)

    At the same time, if you’ve got a link/resource that might point me in the right direction, that would be sweet too.

    Thanks man.

    @kevinjohngallagher

    Member

    I’ve sadly none. You’re the first person to ask about this.

    You’d basically need to set up a s2M roles to Forums relationship in a table somewhere, and then query it.

    It would greatly depend on how you wanted to run it.

    i.e. Would different levels see different forums? Or would they just not see the topics in forums but know they are there, or would they just not see the answers to topics in certain forums etc etc.

    I’m guessing a little, but the easiest way to make it work with bbPress would be to write into the actual theme files testing against the s2Mrole. Shouldn’t be too horrible if you know your way around.

    @wood2695

    Member

    And sadly, I don’t know my way around querying tables, but I’ll figure it out. Quite simply I want any s2M role to be mapped to a general member role (in bbPress) as I’ve set the forum up to only be different if you’re a logged-in member or not. Currently all s2M roles come in to bbPress as Inactive (no role).

    Thanks again for your input. I’ll post a solution here if/when I find it.

    @kevinjohngallagher

    Member

    bbPress has no way of setting up roles to forums like every other forum out there has.

    So if you’re hoping to say set “contributors” to see everything and then set your s2M to move people from members to contributors on the WordPress side I’m afraid you can’t – bbPress doesn’t come with that basic forum functionality.

    In that regard, and with all due respect (you’d be amazed how very few people are as polite as you are), doing anything out-with the “plug and play” variety with bbPress unless you really know your way around PHP/WP-theming and functions is not going to happen.

    Now you may be able to take one of Zaerl’s plugins which allows the setting of show/hide/moderate certain forums and adapt it. Or you could contact Zaerl for some custom work (i’ve no idea if they do this btw – its just where I’d start).

    If you’re going on your own, keep posting back, we’ll help when and where we can :)

    @wood2695

    Member

    Heh, thanks. If I’m understanding you correctly, then I’m ahead of you on the basic forum functionality… I do have Zaerl Visibility plugged in (and working wonderfully) and that’s why my task-at-hand is mapping all the s2M roles to that of bbPress Member within bbPress. I don’t think I’m too far off here, just a bit out of my experience, but I’m up to the challenge.

    I do find it funny that I’m the first to inquire about this. Not that I’m surprised, by the lack of results on some searching. But I love bbPress and s2Memeber seems like a very solid and well supported plugin (and free doesn’t hurt!)

    @wood2695

    Member

    Well I’ve spent a day on this that I didn’t have to spare and have come up with nothing. So I’m crying mercy. Admittedly, this is over my head.

    KJG- while your solutions sound plausible (though I haven’t really found out where to start) I had another guy suggest that I try just making s2M fill bbPress roles while it creates roles for itself for a particular user. To my untrained ear, this seems like a simpler and more direct solution.

    Perhaps I’m wrong there and still don’t really know where to start with that, but I see in my wp_usermeta that users added through WP have wp_capabilities and bb_capabilities, but a user added through s2M doesn’t have any bb_capabilities (duh!). So, how can I add that to the table when it’s adding it’s own custom wp_capabilites? Or KJG, is that the gist of what you were suggesting, only handling that on forum load rather than the initial table creation?

    I realize that is more of a plugin functionality support question, but I’ve not heard back on the s2M forum and methinks they have other priorities there while ramping up for a pro version launch.

    So this is a plea to anyone that might catch this thread and know what they’re doing with user role tables. I’m stumped. Much appreciated.

    @kevinjohngallagher

    Member

    Nah that sounds good mate. It’s basically what I was suggesting here:

    2) Write some custom code for the s2Member callback API (which it supports) to add a field to the bbPress database.

    Basically, what you want to do is look for the bit of code in the s2M files that writes to the wp_capabilities table, and copy it on a new line with bb_capabilities.

    Or if you don’t want to go hacking around (totally understandable), make your “landing page” when people finishing paying/signing up via s2M have a bit of code that copies the last row from the wp_capabilities into bb_capabilities. This method means you wouldn’t have to touch the core of WP/bbP/s2M – but would still work.

    Doesn’t matter that this isn’t a core question mate, you’re helping us break a bit of new ground here, and we’re always interested in that. bbPress isn’t feature rich, so we like to know when it’s bene extended in a way we all hadn’t thought of :) And you’re polite – we like that :)

    @wood2695

    Member

    And you’re darn quick on the reply… I LIKE THAT!

    Lemme poke around for what you suggested. I’ve tried looking for those a bit, but they’re clearly not coded as clear as “wp_capabilities”. I’ve found the labels for the roles that I suspect might be where it’s generating the table data, but don’t see the code that specifies where to populate it. Even then, I see no mention of the table prefix (wp_) so I’m not sure that if I even found capabilities, I’d know how to add a bb_capabilities.

    My gut says that the hack to the s2M files is the way to go, so I’ll keep looking there.

    Thanks.

    @kevinjohngallagher

    Member

    ah, gotcha, you’re looking for something like:

    $wpdb->

    and the word capabilities, there wont be a “wp_capabilites”.

    It’s to allow poeple who change their databse prefix

    @wood2695

    Member

    That helps. This seems to be the code that is placing the custom user role into the wp_capabilities (from register-access.php, for ref). I suppose I could amend this to make all s2M members simply a “subscriber” which would serve my immediate needs (in theory). But I’d prefer to keep the custom roles for later down the road.

    else if (is_admin () && preg_match ("/wp-admin/user-new.php/", $_POST["_wp_http_referer"]) && preg_match ("/^(subscriber|s2member_level[1-4])$/", ($role = $user->roles[0])))<br />
    {<br />
    $processed = "yes"; /* Mark this as yes, to indicate that a routine was successfully processed. */<br />
    /**/<br />
    $level = ($role === "subscriber") ? "0" : preg_replace ("/^s2member_level/", "", $role);

    What I can’t figure out is how to add to this a bb_capabilities row/value.

    @kevinjohngallagher

    Member
    <br />
    <pre><code>// Line 358 if ($ccaps) /* Add custom capabilities. */
    foreach (preg_split ("/[rnts;,]+/", $ccaps) as $ccap)
    if (strlen ($ccap)) /* Don't add empty capabilities. */
    $user->add_cap ("access_s2member_ccap_" . trim (strtolower ($ccap)));

    It’s the ” $user->add_cap ” That adds the capabilities to wordpress.

    That said, I think the best thing to do would be to follow this:

    1) Select * from wp_capabilities where User_id = User_id

    2) for each ($row) insert into bb_capabilites blah blah blah

    that way you don’t need to know what the s2M is doing, you just need to copy the data from wp_cap to bb_cap when you’re done :)

    @wood2695

    Member

    Right. Of course! :) Seriously, I’m afraid I’m totally lost. I understand your logic, but my lack of PHP skills are shining bright. I’m an art director that had (until now) been successful hacking at standard WP PHP, but am clearly in over my head now. “Select the whozit and insert it into the whatzit now?” :D

    You’ve been very kind and I’ve never been one to straight up ask for the answer to be spelled out for me. I understand if you don’t want to give up any untested/theoretical code, especially as it pertains to a 3rd party plugin. (unless your last suggestion was to code that elsewhere??) But I do find myself against a deadline and have got to continue adding content and styling or my client is gonna kill me! Believe me, I’d rather work on solving problems all day so I can learn from them.

    So, I guess I’m going to have to launch this weekend (client has a conference) and just manually change bbPress user roles on new subscribers (lo-fi and lame, by me) until I have more time next week to dedicate to this solution.

    Cheers bud.

    @kevinjohngallagher

    Member

    I’m sadly on an iPhone so not in a position to knock out code.

    I’ll throw something together later today that should help.

    @wood2695

    Member

    If you did that, I would be humbly in your debt. Though I won’t hold it against you if you don’t have the time to solve my problems :)

    FWIW… I’ve found at least one other individual over on the s2M forum that could probably benefit from the solution. At least I know I’m not alone!

    Your help is much appreciated.

    @kevinjohngallagher

    Member

    Righty ho, so while I can’t test my code (on iPhone sorry), I can help shed some more light on this.

    First Off: there is not (that I can see) a table called wp_capabilities. There is just a meta_key called “wp_capabilities” in the wp_usermata table. That actually makes some sense

    The good news here is, that it’s a 1 to 1 relationship so easy to copy over.

    // Show Database Errors

    // Comment this line out when going live :)

    $wpdb->show_errors();

    // 99 times out of 100 this is overkill

    // I’m just being on the safe side

    //

    // It checks what the current user ID is

    if ( !$user_id ) {

    $current_user = wp_get_current_user();

    $user_id = $current_user->ID;

    } else {

    $user_id = (int) $user_id;

    }

    // Connects to the database

    // Retrieves the value for this user for wp_capabilities

    $user_cap = $wpdb->get_row( “SELECT meta_value FROM wp_usermeta WHERE user_id=$user_id AND meta_key=’wp_capabilities’ LIMIT 1” );

    // Checks to see if the user already has a bb_capabilities

    // If it does we’ll overwrite it

    // If it doesn’t we’ll add a new one.

    $user_cap_in_bb_meta = $wpdb->get_row( “SELECT meta_value FROM bb_usermeta WHERE user_id=$user_id AND meta_key=’bb_capabilities’ LIMIT 1” );

    if ($user_cap_in_bb_meta)

    {

    // update bbPress database

    $wpdb->query(“UPDATE bb_usermeta SET meta_value='”. $user_cap->meta_value .”‘ WHERE user_id=”. $user_id .” AND meta_key= ‘bb_capabilities’ “);

    } else {

    // Add a new row to the bbPress database

    $wpdb->query(“INSERT INTO bb_usermeta (user_id, meta_key, meta_value) VALUES (“. $user_id .”, bb_capabilities, ‘”. $user_cap->meta_value .”‘) “);

    }

    // Print all Database errors

    // Comment this line out when going live :)

    $wpdb->print_error();

    // Hide Database Errors

    // Comment this line out when going live :)

    $wpdb->hide_errors();

    Now, the disclaimer. This rather unsurprisingly hasn’t been tested by me, and my contain (will contain) a crazy amount of typos.

    What it does is relaly simple. It copies the wp_capabilities and pastes them as bb_capabilities in the bbpress table. In terms of your initial goal, firing this code once the s2M stuff is finished will achieve that goal (basically, copy and paste it on the landing/finished/thanks/congrats page).

    A quick word of warning. If you’ve been using Zaerl’s plugin or anything else that utilises the “bb_capabilities” meta_key then this will overwrite it. Now as it’s overwriting it with whats in the WordPress database, it’s very unlikely to cause issues.

    But if you’ve set up something funny with a bbPress Plugin then you might end up overwriting it. In theory, this shouldn’t happen because the user is registered via s2M, so that’ll be it’s first time in the bbPress database – but I’m just giving you a heads up.

    I may write this, with all the failsafe functionality, into a WP/bbPress plugin if I get time in a few weeks. But I’m also a tad wary of encroaching onto ground Zaerl’s been excelling in. Good code doesn’t need my size 13s stomping all over it.

    Ok mate, try this and throw me back any errors.

    @kevinjohngallagher

    Member

    Oh for the love of @****

    Apparently bbPress, in it’s infinate wisdom, is now turning every tag opening and closing, even those in and backticks and [blockquote] into screen written &amp;gt.

    I wouldn’t mind if the damn thing would write the HTML as &amp;gt so it at least looked right on the screen, but no…

    I’ll try and cope and paste it into a paste bin thing for you wood2695

    Grrrrrr

    [code] and backticks and [blockquote] into screen written &amp;gt.

    I wouldn’t mind if the damn thing would write the HTML as &amp;gt so it at least looked right on the screen, but no…

    I’ll try and cope and paste it into a paste bin thing for you wood2695

    Grrrrrr

    @kevinjohngallagher

    Member

    http://pastebin.com/SCaVcefq

    Sorry about that bro, if I’m not marked as a spammer, try the above link for the code

    @wood2695

    Member

    Hey man, I’m still with ya here. Gimme a few to digest and implement. I’ll post with developments, but in the meantime THANKS FOR YOUR TIME.

    @wood2695

    Member

    I sent you an email.

    @wood2695

    Member

    Okay kids, here’s the solution that I’ve landed on. First, major props to kevinjohngallagher for taking the time to work this out with me. Second, the solution that I’ve come up with is not based on the previously mentioned code. I believe the code that kev had theorized was based on a flow of how s2M handled the end of the registration that wasn’t entirely correct (ie. no actual ‘thank you’ page). Perhaps this was something that could have been set up as such, but I abandoned that for another train of thought, which was… “if bbPress is reassigning bbP-specific roles based on the standard WP roles, so why can’t it do it for other non-WP-specific roles??”

    So to accomplish this, I’ve made edits to two core bbP files. As kev said to me and I agree… “Usual disclaimer about editing the core blah blah blah.” This will likely need to be re-done again if/when I ever update bbPress, but for the time being, it is working splendidly. With all that said, I may be the only one trying to do this integration, but for anyone down the road that is trying to develop a member site with s2Member + WordPress + bbPress forum, here’s my solution (oh, and also based on a ‘deep integration’ of WP/bbP)…

    in /bb-admin/options-wordpress.php, I added

    <br />
    $wpRoles = array(<br />
    'administrator' => __('WordPress Administrator'),<br />
    'editor' => __('WordPress Editor'),<br />
    'author' => __('WordPress Author'),<br />
    'contributor' => __('WordPress Contributor'),<br />
    'subscriber' => __('WordPress Subscriber')<strong>,<br />
    's2member_level4'=> __('s2Member Level 4'),<br />
    's2member_level3'=> __('s2Member Level 3'),<br />
    's2member_level2'=> __('s2Member Level 2'),<br />
    's2member_level1'=> __('s2Member Level 1')</strong><br />
    );<br />

    and then in /bb-includes/functions.bb-users.php, I added

    <br />
    static $wordpress_userlevel_map = array(<br />
    'administrator' => 10,<br />
    'editor' => 7,<br />
    'author' => 2,<br />
    'contributor' => 1,<br />
    'subscriber' => 0<strong>,<br />
    's2member_level4'=> 0,<br />
    's2member_level3'=> 0,<br />
    's2member_level2'=> 0,<br />
    's2member_level1'=> 0</strong><br />
    );<br />

    Because again, as far as the forum is concerned, I’m only really interested in differentiating whether a user is a logged-in member or not and show/hide the forums/topics/whatever using the zearl Visibility plugin based on that.

    This maps all s2M roles to that of a member in bbPress. Roles may then be changed using the dropdowns in bbPress > Settings > WordPress Integration.

    Cheers.

    @wood2695

    Member

    Aw crap. Same issue that kev was running into earlier, where the forum is turning all “greater than” characters into $gt. So all those “=&amp;gt”s above should read…

    —/

    (equal sign + greater than sign)

    Pain in the… :)

    @drcoach

    Member

    First, thanks to all for the thought and information you’ve put out here. As someone who is trying to do exactly what wood2695 is attempting – it’s really helpful. I have just tried wood2695’s suggestion of adding the code given to

    in /bb-admin/options-wordpress.php, I added

    $wpRoles = array(

    ‘administrator’ => __(‘WordPress Administrator’),

    ‘editor’ => __(‘WordPress Editor’),

    ‘author’ => __(‘WordPress Author’),

    ‘contributor’ => __(‘WordPress Contributor’),

    ‘subscriber’ => __(‘WordPress Subscriber’),

    ‘s2member_level4’=> __(‘s2Member Level 4’),

    ‘s2member_level3’=> __(‘s2Member Level 3’),

    ‘s2member_level2’=> __(‘s2Member Level 2’),

    ‘s2member_level1’=> __(‘s2Member Level 1’)

    );

    and then in /bb-includes/functions.bb-users.php, I added

    static $wordpress_userlevel_map = array(

    ‘administrator’ => 10,

    ‘editor’ => 7,

    ‘author’ => 2,

    ‘contributor’ => 1,

    ‘subscriber’ => 0,

    ‘s2member_level4’=> 0,

    ‘s2member_level3’=> 0,

    ‘s2member_level2’=> 0,

    ‘s2member_level1’=> 0

    );

    However, after I did that my forum turned to a white page for both logged in and logged out users. Any ideas?

    @kevinjohngallagher

    Member

    “White pages” means you’ve got a 500 server error.

    If you open up your server error log it will say what’s going wrong.

    Your code to me looks fine, as much as anyone can tell with the way this bbPress forum is currently handling code output :(

    @wood2695

    Member

    Hey drcoach. Hoping it might help you, I’ve dumped my edits into pastebin to avoid the bbPress forum’s reformatting. I’ve also added a few placement notes. http://pastebin.com/uZwUJCtA

    Only 2 things that I could think of (with my limited knowledge of it all) is:

    1) Is your setup a “deep integration” of WP+bbP?

    2) The code that I said to add included some stuff that was already there (I guess “edit” would have been a better term). Only the “strong” code was the addition. The code I placed on pastebin includes notes on existing and unchanging lines and what &amp; where to add. (sorry if you already understood that, I’m just trying to think of mistakes I might have made)

    I hope that helps and good luck!

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