Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 1 replies (of 1 total)
  • @asbrown

    Participant

    i know this thread is ancient but I needed the same thing so heres some code if you need it as well

    <?php
    /*
    Plugin Name: BuddyPress change last initial
    Plugin URI: http://wpfixr.com
    Description: Change the last name to use only the first initial
    Author: Anthony Brown
    Version: 1.0.0
    Author URI: http://wpfixr.com
    */
    $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 1 replies (of 1 total)
Skip to toolbar