Skip to:
Content
Pages
Categories
Search
Top
Bottom

profile field


  • cammac1
    Participant

    @cami780w

    Hi,
    I’m using BuddyPress and the result that I’d like to reach is modifying a field in the user profile page (http://yourSite/members/userName). So far I’ve found bp_after_profile_content and bp_before_profile_content but what I want is affecting one field inside the profile_fields_content. I’m not using any custom field and I can’t find a solution. Does any of you have any idea? I’m in function.php of a child theme and my function so far is this one:

    function get_member_field_test($data){
    $data = bp_get_member_profile_data( ‘field=lname’ );
    if ( strlen($data) > 3){
    $data = substr($data,0, 3).’…’;
    return $data;
    }
    }add_action(‘bp_before_profile_content’,’get_member_field_test’);

    thanks in advance

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

  • shanebp
    Moderator

    @shanebp

    Please use the code button when posting code.

    Try using this filter hook:
    apply_filters( 'bp_get_the_profile_field_value', $field->data->value, $field->type, $field->id );

    To adjust the value returned by: bp_the_profile_field_value()

    For reference: that hook is found in: buddypress\bp-xprofile\bp-xprofile-template.php


    cammac1
    Participant

    @cami780w

    thanks for the answer! but could you be a bit more specific? I’m a beginner in BuddyPress and I’m having hard times understand it properly. I tried to use the filter but if I remove the add_action (apparently) it won’t affect anything and if I use it, it removes half of the content in the profile page.
    thanks


    shanebp
    Moderator

    @shanebp

    Delete your use of the add_action.

    Research how to use a filter in WordPress.

    Try :

    function cami_field_value( $value, $type, $field_id ) {
    
         if ( $field_id == 123 ) {  // change 123 to the id of the field you want to change
             // adjust $value 
         }
    
         return $value;
    }
    add_filter( 'bp_get_the_profile_field_value', 'cami_field_value', 1, 3 );

    cammac1
    Participant

    @cami780w

    Oh my god, it works perfectly !!!! Thank you so much!! You are gorgeous!

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