Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to Integrate s2Members and BuddyPress Registration?


  • willallen83
    Participant

    @willallen83

    Hi!

    I am using WordPress 4.8.3, BuddyPress 2.9.2, and s2Member 170722
    at http://gatetest2.aishasalem.com

    I am doing everything that I can to integrate BuddyPress and s2Memeber.

    I am hoping to get a smooth registration process going. With a free membership and a paid membership, s2member_level1. It seems no matter what I do, the registration process is ugly, and they don’t really talk to each other.

    Currenlty, I am trying the code out from this post https://codex.buddypress.org/developer/user-submitted-guides/useful_func_s2_bp/. It seems very promising. I have modified the code a little AND had to add some code to disable the buddypress automatic redirect from the default wordpress registration page.

    Here is my code (slightly modified from the one in the post, as I want to add this for all members, not just level2).

    // disable BuddyPress redirect from default reg page
    function my_disable_bp_registration() {
      remove_action( 'bp_init',    'bp_core_wpsignup_redirect' );
      // remove_action( 'bp_screens', 'bp_core_screen_signup' );
    }
    add_action( 'bp_loaded', 'my_disable_bp_registration' );
    add_filter( 'bp_get_signup_page', "firmasite_redirect_bp_signup_page");
    function firmasite_redirect_bp_signup_page($page ){
        return bp_get_root_domain() . '/wp-signup.php';
    }
    
    // Function to populate BP Profile Fields w/ S2member Fields.
    add_action('wp_login','s2_profile_field_update',10,2);
    function s2_profile_field_update() {
      global $current_user;
      //Array of xprofile field names
      $xprofile_fields = array('Last Name','Country','Introduce yourself to Aisha Salem');
      //Array of s2member field slugs
      $s2member_fields = array('last_name','user_country','member_letter_aisha');
      //Populates BP with S2 info
      get_currentuserinfo();
      // if( current_user_is("s2member_level1") ) {
           for($i = 0; $i < sizeof($xprofile_fields); $i++) {
              if(xprofile_get_field_data($xprofile_fields[i], $current_user->id) == '' && get_user_field($s2member_fields[i]) != '' )  {
                  xprofile_set_field_data($xprofile_fields[i], $current_user->id, get_user_field($s2member_fields[i]) );
               }
           }
      // }
    }

    After this, nothing has really changed. I am not sure about the details.
    Like:

    • Where exactly do I get the xprofile field names?
    • Where exactly do I get the s2Member field slugs?
    • Do I need to create these custom fileds with the same names in both BuddyPress and s2Members? (Which is what I have tried, so I am guessing no, or I am just doing it wrong…)

    So, as I understand it, with this code. I use the s2Member registration process and the next time the user loggs in, it is updated to their BuddyPress profile.

    Please let me know if I am not understanding this. AND PLEASE help me to understand how to do this correctly.

    Thank you so much!

Viewing 3 replies - 1 through 3 (of 3 total)

  • Boone Gorges
    Keymaster

    @boonebgorges

    Hi @willallen83 – I’m afraid I haven’t integrated with s2member in many years, so I can’t provide exact advice. But briefly, it appears that the code above is meant to sync the $s2member_fields fields – which I assume are defined somewhere in s2member – to the corresponding members of the $xprofile_fields array. The latter fields are created in Dashboard > Users > Profile fields; make sure the names (like ‘Last Name’) match exactly, or the lookup will fail.

    Note also that it may be more reliable to fetch user info from the values passed by the ‘wp_login’ hook to the function. So something like this:

    
    function s2_profile_field_update( $user_login, $user ) {
      //Array of xprofile field names
      $xprofile_fields = array('Last Name','Country','Introduce yourself to Aisha Salem');
      //Array of s2member field slugs
      $s2member_fields = array('last_name','user_country','member_letter_aisha');
      //Populates BP with S2 info
      get_currentuserinfo();
      // if( current_user_is("s2member_level1") ) {
           for($i = 0; $i < sizeof($xprofile_fields); $i++) {
              if(xprofile_get_field_data($xprofile_fields[i], $user->id) == '' && get_user_field($s2member_fields[i]) != '' )  {
                  xprofile_set_field_data($xprofile_fields[i], $user->id, get_user_field($s2member_fields[i]) );
               }
           }
      // }
    }
    

    Note that, according to this code, it’ll only update the BP xprofile fields if they’re empty. You’ll have to remove that check if you always want s2member values to take precedence.

    Beyond this, your best bet for figuring out why this is not working is to place some debug statements at various points. Use error_log() or good old-fashioned var_dump() to make sure (a) the function is actually firing at ‘wp_login’, (b) the xprofile field values are actually being fetched properly, (c) the get_user_field() function is fetching data properly, and from the correct user https://s2member.com/kb-article/user-custom-fields-via-php-code/#toc-460a2dd2, etc.


    willallen83
    Participant

    @willallen83

    @boonebgorges Thank you so much!! I really appreciate your help and quick response.

    Even if this doesn’t work for me, just to understand how better to debug in PHP (with wordpress) is AMAZING! (While I am not new to coding, I am new to PHP and WordPress).

    Thanks again 🙂


    Boone Gorges
    Keymaster

    @boonebgorges

    @willallen83 You’re welcome! Please feel free to report back here – or update the codex page – once you’ve got updated instructions. Good luck!

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