Skip to:
Content
Pages
Categories
Search
Top
Bottom

Member/User Specific Items using functions.php


  • joelshakespear
    Member

    @joelshakespear

    I need to be able to display content on a specific member/user profile using their user ID as the identifyer. I have tried numerous variations of the following code with no success. It is very probable that I am missing something simple as I am not very versed in php. Thanks in advance!

    `function add_specific_content()
    {
    if (bp_is_user_profile(’28’)) {
    ?>

    Content only to display on member/user ID 28’s profile page.

    <?php
    }
    }
    add_action(‘add_specific_content’);`

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @joelshakespear … I think you are about 4-5 days behind me. I looked into this very same thing and have some code for you to glance over:

    `
    if (bp_get_member_user_id() != 1 /*admin*/ && bp_get_member_user_id() != 35 /*user35*/ && bp_get_member_user_id() != 36 /*user36*/) {
    $members_phoneNumber = bp_get_member_profile_data( ‘field=Phone Number’ );
    if (empty($members_phoneNumber)) $members_phoneNumber = ‘(no phone number entered)’;
    $members_title = bp_get_member_profile_data( ‘field=Title’ );
    if (empty($members_title)) $members_title = ‘(no title entered)’;
    echo ‘

    ‘ . $members_phoneNumber . ‘ | ‘ . $members_title;
    if (is_site_admin()) {
    $user = new WP_User( bp_get_member_user_id() );
    $user_role = ucwords(wp_sprintf_l( ‘%l’, $user->roles ));
    if ($user_role == ‘Bbp_participant’) $user_role = ‘Administrator’;
    echo ‘ | ‘ . $user_role . ‘‘;
    }
    echo ‘

    ‘;
    }
    `

    I use it in the members loop script, but you could probably tear it apart and use it on the member’s page for your needs. Sure hope it helps you out.


    joelshakespear
    Member

    @joelshakespear

    Thanks! That’s probably closer to what I need, but, it doesn’t need to be part of a loop and I don’t need any of the member details displayed.

    I’m trying to basically place an achivement badge on a specific members page. No one else would get that badge, so it would be more like a statement I’ve used before when I need to display a banner or callout on the home/front page. Only for a specific member…

    I’ll try to tweak this into working and see how far I get.


    shanebp
    Moderator

    @shanebp

    You’re trying to do this in a file in theme/members… ?

    Try this:
    `
    if ( bp_displayed_user_id() == 28 ) {
    ?>

    Content only to display on member/user ID 28’s profile page.

    <?php
    }
    `

    btw
    -bp_is_user_profile() does not accept variables, it just checks to see if the viewer is on a profile page and returns a boolean.
    – add_action doesn’t work like that – read https://codex.wordpress.org/Function_Reference/add_action


    joelshakespear
    Member

    @joelshakespear

    Ah! That worked! Thank you!!!
    I ended up putting it in the profile.php under members/single as:

    `

    Content only to display on member/user ID 28’s profile page.

    `

    Thank you both for the help! I still have much to learn!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Member/User Specific Items using functions.php’ is closed to new replies.
Skip to toolbar