Referencing $bp from another site

We are creating WP users from a CodeIgniter membership management system and would like to populate and update a few bp profile fields at the same time.

Have found these functions;-

xprofile_set_field_data

xprofile_get_field_data

Looking promising so far.

Have got stuck thus far:-

$wppath = $this->config->item('wppath');

require($wppath.'wp-blog-header.php');

require($wppath.'wp-content/plugins/buddypress/bp-loader.php');

global $bp;

$profile_data = get_all_for_user((int)2);

Which gives:-

Call to undefined function get_all_for_user()

can anyone help please?

  • cannycookie
    • WPMU DEV Initiate

    Thanks,

    I have the core function @782 as get all notifications – get_all_for_user()

    and get all of the profile information for a specific user on 1066 – get_all_for_user()

    Is that right?

    have tried adding this :-

    require(‘wp-content/plugins/buddypress/bp-core/bp-core-classes.php’:wink:;

    require(‘wp-content/plugins/buddypress/bp-xprofile/bp-xprofile-classes.php’:wink:;

    $profile_data = get_all_for_user((int)2);

    But get an error:-

    Fatal error: Cannot redeclare class BP_Embed in ../wp-content/plugins/buddypress/bp-core/bp-core-classes.php on line 1286

    I’m not sure how to go about including the BP reference.

  • cannycookie
    • WPMU DEV Initiate

    Hi Tim,

    Thanks for that, sadly not much help – I’m not creating a WP plugin but a CodeIgniter App which connects to WP.

    However – I have managed to figure this one out. The key was the BP-XProfile-Classes.php file.

    So if anyone’s interested in updating BP profile fields remotely here’s how:-

    //Use these ID's for testing, the WPuserID to update and our system memberID
    $wpuserid = 2;
    $ourmemberid = 1269;

    //load our member and his professional information
    $this->load->model('Member_model','member');
    $this->member->load((int)$ourmemberid);
    $memberinfo = $this->member->getMemberProf();

    //Setup an array mapping our fields to BuddyPress field ID's
    $fieldids = array(
    'OccupationRole' => 4,
    'OccupationPrimaryIndustry' => 5,
    'Books' => 7
    );

    //Create a new profile data object
    $profile = new BP_XProfile_ProfileData();

    //Loop through our array and update BuddyPress Profile fields with our data.
    foreach($fieldids as $ourfield => $bpfieldid) {
    $profile->populate($bpfieldid,$userid);
    $ourvalue = $memberinfo->$ourfield;
    $profile->value = $ourvalue;
    $profile->save();
    }

    Hope thats useful to someone in the future :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.