Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] How to add certain profile fields in a Buddypress member profile header.

  • Avatar of Kookidooki
    Kookidooki
    Participant

    @kookidooki

    Hello guys,

    How do I add certain profile fields in a Buddypress member profile header?

    Thx in advance,

    Kookidooki

Viewing 23 replies - 1 through 23 (of 23 total)
  • Avatar of Roger Coathup
    Roger Coathup
    Participant

    @rogercoathup

    Have a look at the member-header.php file in bp-default theme. It documents how to add fields.

    Follow those instructions to add them in the member-header equivalent in your child or standalone theme… or add them in an action hooked on to bp_profile_header_meta

    Avatar of Kookidooki
    Kookidooki
    Participant

    @kookidooki

    Hello Roger,

    What version of Buddypress are you using cause I couldn’t find the files member-header.php and bp-default theme.

    I’m using the latest version of Buddypress.

    Thx in advance,
    Kookidooki.

    Avatar of Roger Coathup
    Roger Coathup
    Participant

    @rogercoathup

    Every BuddyPress version from 1.0.1 to 1.5.6 comes with bp-default as part of the plugin package.

    Start with the documentation on theming BuddyPress: http://codex.buddypress.org/theme-development/the-bp-default-theme/

    Also, look at the BuddyPress files in your plugin directory.

    Avatar of Kookidooki
    Kookidooki
    Participant

    @kookidooki

    Hello Roger,

    Thank you, I’ve found the files!

    I’m not tech savvy….. Maybe you could help me with the following issue:

    I’ve created profile fields named “Location” and “Hobbies” in Buddypress>Profile Fields.
    How do I display these fields in the member’s header just below the name of a profile.
    Pls could you provide me the code and step-by-step instructions?

    Thx in advance,
    Kookidooki.

    Avatar of Roger Coathup
    Roger Coathup
    Participant

    @rogercoathup

    If you are not tech savvy, it sounds like you would be best to hire a developer to do this development work.

    It would also be helpful if you posted full information on here – like the theme you are trying to modify – I notice you have asked the same question on the Frisco theme forums

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    @kookidooki Are you using the bp-default theme or a custom one here? Providing all pertinent detail is very important. Rogers guidance in his first post pointed out that there are actually instructions on how to add further xprofile fields, if you have created new profile fields then it should now be a simple matter of following the guide in the member-header file, let us know if that is proving an issue and perhaps provide an example of the code you are trying to add.

    Avatar of Kookidooki
    Kookidooki
    Participant

    @kookidooki

    Hello guys,

    Yes I’m using the Frisco theme for Buddypress and I’m completely at lost :-)
    and I was not aware that the Frisco theme was a child-theme.

    I’m now figuring out how to add my created profile fields “Location” and “Hobbies” in the member’s header.

    Avatar of Kookidooki
    Kookidooki
    Participant

    @kookidooki

    Hello guys,

    I’ve found and added this code in member-header.php and it’s almost working:
    `

    Location: </span
    Hobbies:

    `

    The location is displayed correctly, but hobbies are displayed as”Hobbies: array”.
    I’ve checked profile field Hobbies; Field type= Multi select Box. This might be the problem if you use this option.

    1. How do I display the selected boxes?
    2. Do I have to copy the above mentioned code to the Frisco theme? If so where?

    Avatar of Roger Coathup
    Roger Coathup
    Participant

    @rogercoathup

    Yes, we’ve also noticed a problem with bp_profile_field_data() and select boxes, drop down fields, etc.

    The following workaround should handle that field for you:

    This article may help you:

    http://bp-tricks.com/snippets/displaying-certain-profile-fields-on-your-members-profile-page/

    Note: @shanebp suggestion of using the unserialize function (see the comments), should also do the trick for you.

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    Try using:
    `bp_member_profile_data()`

    works for me!

    Avatar of shanebpdev
    shanebp
    Participant

    @shanebp

    @rogercoathup
    In 1.6, you can use

    `
    xprofile_get_field_data( $field, $user_id = 0, $multi_format = ‘array’ )
    `
    From bp-xprofile/bp-xprofile-functions.php.

    To get a comma-separated string, use the other $multi_format option which will implode the array for you
    `
    xprofile_get_field_data( $field, $user_id = 0, $multi_format = ‘comma’ )
    `

    Avatar of Roger Coathup
    Roger Coathup
    Participant

    @rogercoathup

    @shanebp @hnla -

    As Hugo points out, we can also use (since 1.5.somethingorother) bp_member_profile_data(), defined in bp-members-template.php

    The comments in member-header.php should be updated!

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    @shanebp xprofile_get_field_data() is useful if outside of a loop, but this issue is in a members loop so the above function appropriate – but as Roger says why on earth do we still guide people to use bp_profile_field_data() if it effectively doesn’t work?

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    http://buddypress.trac.wordpress.org/ticket/4319 asks the question whether comments shouldn’t be updated.

    Avatar of Kookidooki
    Kookidooki
    Participant

    @kookidooki

    Hello guys,

    Thank you for your help; I really appreciate that.

    In bp-members-template.php and bp_member_profile_data I’ve found this code at line 596-632:

    `function bp_member_profile_data( $args = ” ) {
    echo bp_get_member_profile_data( $args );
    }
    function bp_get_member_profile_data( $args = ” ) {
    global $bp, $members_template;

    if ( !bp_is_active( ‘xprofile’ ) )
    return false;

    // Declare local variables
    $data = false;
    $user_id = 0;

    // Guess at default $user_id
    if ( !empty( $members_template->member->id ) )
    $user_id = $members_template->member->id;
    elseif ( !empty( $bp->displayed_user->id ) )
    $user_id = $bp->displayed_user->id;

    $defaults = array(
    ‘field’ => false, // Field name
    ‘user_id’ => $user_id
    );

    $r = wp_parse_args( $args, $defaults );
    extract( $r, EXTR_SKIP );

    // Populate the user if it hasn’t been already.
    if ( empty( $members_template->member->profile_data ) && method_exists( ‘BP_XProfile_ProfileData’, ‘get_all_for_user’ ) )
    $members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id );

    // Get the field data if there is data to get
    if ( !empty( $members_template->member->profile_data ) )
    $data = xprofile_format_profile_field( $members_template->member->profile_data[$field], $members_template->member->profile_data[$field] );

    return apply_filters( ‘bp_get_member_profile_data’, $data );
    }`

    Is this the code you’re talking about and what should be modified?

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    Why are you looking in bp core files? Dont! :) Please read through the thread again all the answers are there – you need to be working in /single/members-header.php

    Avatar of Kookidooki
    Kookidooki
    Participant

    @kookidooki

    Hello guys,

    It works!!!
    I’ve replaced in /single/members-header.php the code bp_profile_field_data() by bp_member_profile_data() and it works great!

    Thank you guys!!

    Avatar of Kookidooki
    Kookidooki
    Participant

    @kookidooki

    I’ve made a summary for others and as a reminder:

    This is the code you must add around line 30 in wp-content/plugins/buddypress/bp-themes/bp-default/members/single/member-header.php:
    `

    Location:
    Hobbies:

    <a href="”>Url:

    `

    And how do I make the url clickable?

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    Glad it’s working, wasn’t that hard in the end :) thanks for posting your example.

    i’ve opened a ticket to see if the comment text in the file can be amended with new example.

    Avatar of Roger Coathup
    Roger Coathup
    Participant

    @rogercoathup

    To make the URL clickable, add an anchor tag and use bp_get_member_profile_data() to get the value for the href attribute.

    Avatar of Kookidooki
    Kookidooki
    Participant

    @kookidooki

    Hello Roger,

    I’ve used your code bp_get_member_profile_data, but it failed and found out that his code is the solution:
    `

    <a href="”>Url:

    `

    I know what you’re thinking: what a weird code …. but anyway it’s working. :-)

    Avatar of Roger Coathup
    Roger Coathup
    Participant

    @rogercoathup

    Yes, you need to echo the value returned by bp_get_member_profile_data(), or just use bp_profile_field_data() as you’ve done

    Avatar of Kookidooki
    Kookidooki
    Participant

    @kookidooki

    Thank you Roger et al.

    You / we can close this topic.

    Best regards,

    Kookidooki.

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

You must be logged in to reply to this topic.