Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display first name and last initial


  • shemakeswebsites
    Participant

    @shemakeswebsites

    Hello everyone. I’m using the following snippet that will display the first name and last initial for users in buddypress. However, in bbpress it has no effect. Any ideas on how I could edit this to get it to work for bbpress? I’m so sad that something like this isn’t a default option.

    $changeLastInitial = new changeLastInitial;
    add_filter('bp_displayed_user_fullname', array(
        $changeLastInitial,
        'last_initial'
    ), 7, 1);
    add_filter('bp_get_member_name', array(
        $changeLastInitial,
        'last_initial'
    ), 7, 1);
    add_filter('bp_get_the_profile_field_value', array(
        $changeLastInitial,
        'last_initial_xprofle'
    ), 7, 3);
    add_filter('bp_core_get_user_displayname', array(
        $changeLastInitial,
        'bp_core_get_user_displayname'
    ), 7, 2);
    
    class changeLastInitial
    {
        function bp_core_get_user_displayname($name, $id)
        {
            $name = $this->last_initial($name);
            return $name;
        }
        function last_initial_xprofle($value, $type, $id)
        {
            if ($id == 1) {
                $value = $this->last_initial($value);
            }
            return $value;
        }
        function last_initial($name)
        {
            $name_a = explode(' ', $name);
            // if there is at least two parts to the name
            if (count($name_a) == 2) {
                // replace the last part of the name with the first letter of the last part
                $name_a[count($name_a) - 1] = substr($name_a[count($name_a) - 1], 0, 1);
                // put it all back together
                $name  = implode(' ', $name_a).".";
            }
            return $name;
        }
    }
    
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar