custom aMember fields -> WordPress BuddyPress xprofile fields

Discussion in 'aMember Pro v.4' started by cmireles, Feb 26, 2013.

  1. cmireles

    cmireles New Member

    Joined:
    Jul 5, 2012
    Messages:
    22
    Hi there, is there a way to copy aMember fields to BuddyPress xprofile fields when someone edits their info in aMember? I assume since aMember does this for the standard WordPress user fields, I can extend this to cover other custom xprofile fields in BuddyPress? Can you tell me where to start?

    Thanks, Jon
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Jon,
    This is possible as customization.
    You can modify query which create profile in buddypress. Check /amember/application/default/plugins/protect/wordpress.php function updateBuddyPressProfile(Am_Record $record)
  3. gswaim

    gswaim CGI-Central Partner

    Joined:
    Jul 2, 2003
    Messages:
    641
    Currently only First Name, Last Name, Username, Password, and eMail are pushed from aMember to WordPress. While this is possible with customization, as stated by Alexander, IMHO it might be better to keep not do it that way.

    There is a trend in web design to keep the initial site registration process simple and only capture minimal information. If you try to gather too much information during registration you risk creating a non-completer.

    I would catch only First Name, Last Name, Username, Password, and eMail during initial registration and use the Achievements for WordPress plugin to redirect the user to the BuddyPress profile page on their first login. You can even use this plugin to encourage them to provide additional information by offering them recognition and badges.

    Also there seems to be lot of changes to the profile area. The last update (1.7 - still beta at the moment) allows the admin or user to control the visibility of each profile field.
  4. cmireles

    cmireles New Member

    Joined:
    Jul 5, 2012
    Messages:
    22
    Thanks guys. Grant, this is how I sort of planned things.. a minimal aMember registration, then have users manage their extended profile in buddypress. This also works well as there are plugins for the mailchimp integration I need to implement.

    However, as I thought about this, I wondered if the eventual admins would want at least contact info (phone, address, zip, etc) in aMember for use in managing members within aMember as opposed to the BP community. I thought if I could map all the fields from aMember -> BuddyPress, then with the use of not required fields could push everything from aMember -> BuddyPress -> MailChimp. Users would only use the aMember profile to edit info.

    I suppose if I did it the way you suggest, member correspondence could be done via mailchimp which would have access to all those fields already.
  5. gswaim

    gswaim CGI-Central Partner

    Joined:
    Jul 2, 2003
    Messages:
    641
    Sounds like you plan on using a MailChimp plugin with WordPress. It is better to use the aMember -> MailChimp integration. Most of the BuddyPress profile information would be irrelevant to the implementation of an eMail campaign. In most cases you are sending newsletters based on a user and their membership products. All that information already exists in aMember.
  6. cmireles

    cmireles New Member

    Joined:
    Jul 5, 2012
    Messages:
    22
    Grant, shoot, ok where is the mailchimp integration? Is that built-in or additional? Now, I'm doubting my whole plan here. The problem is, how to split up the user profile info if at all? If I just use the aMember data -> mailchimp, then I don't have all the sorting ability of all the other buddypress data...​
  7. gswaim

    gswaim CGI-Central Partner

    Joined:
    Jul 2, 2003
    Messages:
    641
    It is part of core.
    1. Go to "Setup/Configurations" in the Admin CP
    2. Click on "Plugins" in the top menu bar
    3. Choose "Newsletters" from the "Enabled Modules" drop down menu
    4. Save the screen
    5. Then choose "mailchimp" from the "Newsletter Plugins" drop down menu towards the bottom of the page
    6. Then Save the page
    7. Then go to the "MailChimp" button in the top meu bar
    8. Follow the instructions at the bottom of the page to link aMember to your MailChimp account.
    9. Then create a mail list in MailChimp for each subscription product.
    10. You will be able to assign a membership product to the matching list in MailChimp.
    This will allow you to send out newsletters for each subscription product. All the data in BuddyPress is for the benefit of the site members and building social connections.
  8. cmireles

    cmireles New Member

    Joined:
    Jul 5, 2012
    Messages:
    22
    Grant,

    Thanks very much, working great.
  9. gswaim

    gswaim CGI-Central Partner

    Joined:
    Jul 2, 2003
    Messages:
    641
    Glad it worked out. The documentation will be improving soon, so it should be easier for the next person.
  10. cmireles

    cmireles New Member

    Joined:
    Jul 5, 2012
    Messages:
    22
    Alex, I see the function in wordpress.php. Can you elaborate a bit on using this function to write additional buddypress fields? If I have a field in aMember called graduationYear which is BuddyPress field_23, how and where would I call this function?

    Thanks! Jon
  11. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Here is an example how you can populate that field:
    PHP:
            function updateBuddyPressProfile(Am_Record $record)
            {
                
    $user $this->findAmember($record);
                if (!
    $this->_db->selectCell('select count(*) from ?_bp_xprofile_data where user_id=? and field_id=1'$record->pk()))
                    
    $this->_db->query('
                        INSERT INTO ?_bp_xprofile_data
                        (user_id, value, field_id, last_updated, field_23)
                        VALUES
                        (?, ?, 1, now(), ?) 
                        '
    $record->pk(), $record->display_name$user->get('graduationYear')
                    );
            }

  12. cmireles

    cmireles New Member

    Joined:
    Jul 5, 2012
    Messages:
    22
    Alex,

    I've tried to work around this but my client is requiring first name, last name in buddypress for sorting and usage on that end of things, so I'm back to this thread. I'm fiddling with my site.php to create a hook after user update and user add. I'm sorry I'm so unfamiliar with this, and I know this is wrong, but looking to do the following functionality-wise. I did get the hook to register.. that's about it :)

    PHP:
    //update first and last name in buddypress on insert / update
    $di Am_Di::getInstance();
    $di->hook->add(Am_Event::USER_AFTER_UPDATE'update_buddypress_user');
     
    function 
    update_buddypress_user(Am_Event_userAfterUpdate $event)
    {
        
    $am_user $event->getUser();
       
        
    $wp_user Am_Di::getInstance()->db->query("SELECT * FROM wp_users WHERE login='".$am_user->login."'");
       
        
    Am_Di::getInstance()->db->query("
            INSERT INTO wp_bp_xprofile_data
            (user_id, value, field_id, last_updated)
            VALUES
            ('"
    .$wp_user->id."', '".$am_user->name_f."', 32, now()),
            ('"
    .$wp_user->id."', '".$am_user->name_l."', 33, now())
        "
    );
    }

    Also, how do I output something like print_r ($am_user)?
  13. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Contact me in helpdesk, I think first & last name support should be added to default plugin so I will implement this mod.
  14. cmireles

    cmireles New Member

    Joined:
    Jul 5, 2012
    Messages:
    22
    Alexander, actually, I don't think this is possible... I said buddypress but I mean xprofile. Buddypress does not have a first / last field, only display name, so your plugin is actually doing everything possible already. Since the first/last has to be an xprofile field, and added or not per install, the id will never be consistent.. Unless you have another idea about it...

    Thanks, Jon
  15. cmireles

    cmireles New Member

    Joined:
    Jul 5, 2012
    Messages:
    22
    Alexander,

    On further inspection, you're right. There are not first and last fields, but by default, field_id #1 is the buddypress field for 'Full Name'. It looks like on saving a user, amember does write display_name to wp_users table but does not write to the name field_id 1 in table wp_bp_xprofile_data, am I right? It would be helpful for this to happen, and I guess to write other fields in buddypress as well. If you can help me with the code in site.php that would be best for me since I might need to write other buddypress fields, or if you want to do the integration that's your call of course - I will add a note in help desk.

    Thanks, Jon

Share This Page