Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Development


  • MattDotNet
    Participant

    @mattdotnet

    Hello,

    I’m trying to develop an integration among BuddyPress and VikAppointments for one of our customers. This is the first time I dig into the BuddyPress framework and I’m unable to figure out how the fields-data mapping works.

    I tried to use the bp_profile_field_data function, but I get an error saying the latter hasn’t been declared. Doesn’t BP use a sort of autoloader?

    I also tried to look at the database structure, and in the user meta table I noticed that the values of the custom fields are structured in the following way:

    `
    meta_key | meta_value
    wbbpp_1715763478_1715763523 | Ford
    wbbpp_1715763478_1717482765 | Abarth
    `

    What do 1715763478, 1715763523 and 1717482765 stand for? I’m unable to see those identifier in other tables used by BP.

    There’s also a wbbpp_userdata record containing a serialized version of all the custom fields. But the problem is that if I manually edit those details, the new values are not applied in the front-end.

    In a few words I would like to know:

    • How can I retrieve the user custom fields?
    • How can I update the user custom fields?

    I’ll be waiting for some clarifications.

    Best Regards
    Matteo

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

  • Varun Dubey
    Participant

    @vapvarun

    @mattdotnet BuddyPress does not save profile field values inside the user meta
    you can fetch them using the following approach and sync them with your requirement

        $field_name_gender = 'Gender'; // Replace with your actual xProfile field name
        $field_name_location = 'Location'; // Replace with your actual xProfile field name
    
        // Get the xProfile field values
        $gender_value = xprofile_get_field_data($field_name_gender, $user_id);
        $location_value = xprofile_get_field_data($field_name_location, $user_id);

    MattDotNet
    Participant

    @mattdotnet

    Thanks for your reply. The problem is that I’m getting the following error message:

    Fatal error: Uncaught Error: Call to undefined function xprofile_get_field_data()

    I’ve also tried to use the following code to auto-load the BuddyPress dependencies:
    require_once WP_PLUGIN_DIR . '/buddypress/bp-loader.php';

    What’s the correct way to auto-boot BuddyPress?


    Varun Dubey
    Participant

    @vapvarun

    Ensure the BuddyPress plugin is active and add custom code in child theme functions.php or a custom plugin or using the code snippet plugin. xprofile_get_field_data is a valid function https://hooks.wbcomdesigns.com/reference/functions/xprofile_get_field_data/


    MattDotNet
    Participant

    @mattdotnet

    It keeps throwing the same error: The function does not exist. I’m already developing a plugin and I’m inside a init callback.

    Hasn’t BP been auto-loaded yet at this stage?

    I also tried to recursively auto-load every single file contained in the buddypress/ folder. But this is not enough as I encounter other dependency errors. Therefore there must be a function/method/class to invoke in order to properly set up the system.


    Varun Dubey
    Participant

    @vapvarun

    First, ensure that BuddyPress is loaded and initialized before your plugin tries to call its functions. Since BuddyPress hooks its initialization to WordPress bp_init action, which typically fires on wp or init at a priority of 10, you should ensure your hook runs after this or directly on bp_init with a lower priority (higher number).

    You can try to debug like this.

    function my_custom_buddypress_function() {
        if ( ! function_exists('xprofile_get_field_data') ) {
            error_log('BuddyPress xprofile component has not been loaded yet.');
        } else {
            // Your code here
        }
    }
    
    add_action('bp_init', 'my_custom_buddypress_function', 20);

    MattDotNet
    Participant

    @mattdotnet

    Nothing has changed. This is the code I’ve tried to use.

    function my_custom_buddypress_function() {
        var_dump(__FUNCTION__);
        if ( ! function_exists('xprofile_get_field_data') ) {
            echo '<pre>BuddyPress xprofile component has not been loaded yet.</pre>';
        } else {
            echo '<pre>';
            var_dump(xprofile_get_field_data('Targa', wp_get_current_user()->ID));
            echo '</pre>';
        }
        exit;
    }
    
    add_action('bp_init', 'my_custom_buddypress_function', 20);

    And this is the output I received:

    string(29) “my_custom_buddypress_function”
    BuddyPress xprofile component has not been loaded yet.

    BuddyPress 12.5.0 is installed and active.


    MattDotNet
    Participant

    @mattdotnet

    You can mark this ticket as resolved. I figured out by myself how to retrieve the fields directly from the database.

    Thanks for your assistance anyway.

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