Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am succesfully pre populating logged in user wordpress user meta into gravity forms, but I can't find a way how to prepopulate buddypress profile data into gravity forms.

Goal

I want to be able to pull from Buddypress Profile data for the logged in user to populate the fields in Gravity forms such as Phone, Address, Country, Province etc.

Conclusion

I hope that buddypress member profile fields works very similarly as wordpress user_meta does, I tried many combinations which I have found on the net and nothing works for me - (for example the name of one of the fields in buddypress profile fields is Phone - group_id=5&field_id=59 - this is the slug from edit profile page, which should say that Phone's fields number is 59 and group 5(I don't know if it is important):

This is the code which should be pulling Buddypress xprofile fields which unfortunately doesn't work.

add_filter("form_field_value_phone", "populate_phone");
function populate_phone() {
    $current_user = wp_get_current_user();
    $current_user_id = $current_user->ID;
    $phone = bp_profile_field_data( array('user_id'=>$current_user_id,'field'=>'Phone' ));
    return $phone;
}

This is working "wordpress" user meta data fields in functions.php

// populate the field with "user_firstname" as the population parameter with the "first_name" of the current user
    add_filter('gform_field_value_user_firstname', create_function("", '$value = populate_usermeta(\'first_name\'); return $value;' ));

// populate the field with "user_lastname" as the population parameter with the "last_name" of the current user
        add_filter('gform_field_value_user_lastname', create_function("", '$value = populate_usermeta(\'last_name\'); return $value;' ));

// this function is called by both filters and returns the requested user meta of the current user
        function populate_usermeta($meta_key){
            global $current_user;
            return $current_user->__get($meta_key);
        }
share|improve this question

closed as off-topic by kaiser Aug 1 at 23:29

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

Why don't you use xprofile_get_field($field_id) or xprofile_get_field_data($field, $user_id)? They are there in the BuddyPress code to give you fields data.

share|improve this answer
    
Thanks for your respond @slaffik, I am using gravity forms for 4 custom post types as portfolio,job board-searching-offering jobs, all of them use GF to create applicant,portfolio, employeretc. pages which should be fill out more than once,that's why I was thinking to make it more easy for people to fill out once first buddypress fields with basic data and then easily fill out every job request-offer form by auto populating half of the form with the basic data from members profile fields, I need to get those data into gravity form's fields, not in buddypress. –  Daniel Foltynek Jul 8 '13 at 19:43
    
I would like to use buddypress members fields to store all data of people which will then, when logged in use those data to dynamically populate them across the site when creating 4 different custom post types , for example lapdancers searches for job in the club, club advertise their club job offer,to make it easier the girl creates CPT portfolio first with all personal data which sends to buddypress fields DB, then when she wants to search for a job, she can create job request to work somewhere, then she can fill out job-search form and there her data can be dynamically populated –  Daniel Foltynek Jul 8 '13 at 19:57
up vote 1 down vote accepted

For somebody who will need it too, I got that working with this snippet (it works with text fields, dropdown should be different):

    add_filter("gform_field_value_city", "populate_city");
function populate_city($value){
     global $current_user;
     get_currentuserinfo();
     return xprofile_get_field_data('city', $current_user->ID);
}

and Gravity Forms

Parameter Name = city
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.