Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to filter “User Nicename”


  • imborx
    Participant

    @imborx

    Hi guys,

    I’m trying to add some content after the “user nicename” but I’m not able to do it. I achieve with “mentioname” with a forum tweak using this filter:

    add_action( 'bp_get_displayed_user_mentionname', 'yzc_add_xprofile_field_data_in_profile_header' );

    But I’m not able to do it with “user nicename” (I tried with bp_get_displayed_user_nicename and any other posible combination):

    What I need to filter

    Thanks a lot!

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

  • shanebp
    Moderator

    @shanebp

    Nicename is not a BuddyPress field.
    It is a field in the WP users table.
    You need to use a WP function like:
    https://codex.wordpress.org/Function_Reference/get_userdata


    imborx
    Participant

    @imborx

    Thank you @shanebp !! I check that link and tried multiple options for around an hour but I’m quite lost.

    How can I apply that usernice name into this code?

    function yzc_add_xprofile_field_data_in_profile_header( $name ) {

    if ( bp_is_user() ) {
    $field_data = xprofile_get_field_data( ‘Age’, bp_displayed_user_id() );
    if ( ! empty( $field_data ) ) {
    return $name . ‘, <span class=”bp-user-age”>’ . $field_data . ‘</span>’;
    }
    }

    return $name;

    }

    add_action( ‘bp_get_displayed_user_mentionname’, ‘yzc_add_xprofile_field_data_in_profile_header’ );

    Thanks again 🙂


    shanebp
    Moderator

    @shanebp

    Please use the code button when posting code.

    $user_info = get_userdata(  bp_displayed_user_id() );
    $nicename = $user_info->user_nicename;

    imborx
    Participant

    @imborx

    Hi again,

    So I suppose that I need to place that two lines of code after add_action, right?

    if ( bp_is_user() ) {
    $field_data = xprofile_get_field_data( ‘Age’, bp_displayed_user_id() );
    if ( ! empty( $field_data ) ) {
    return $name . ‘, <span class=”bp-user-age”>’ . $field_data . ‘</span>’;
    }
    }
    
    return $name;
    
    }
    
    add_action( ‘<strong>$user_info = get_userdata(  bp_displayed_user_id() );
    $nicename = $user_info->user_nicename;</strong>
    ’, ‘yzc_add_xprofile_field_data_in_profile_header’ );

    Cash Home Buyers Pro
    Participant

    @cashhomebuyer

    Cash Home Buyers Pro is a based home buying service that provides quick sale solutions to those who need to sell their house fast. We buy houses San Jose

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