Xprofile: Just show first Letter of last name
-
I need a filter that will only show the first letter of the users last name
r-1324 Trunk pulls in xprofile fields by field value and field type
while
RC1 pulls in xprofile by field_id field-type and field_value
with field_id i can filter the results:
only show if admin,
if this, do this
etc
how is this possible now that trunk has changed?
-
This seems to work for everything except site wide activity:
function my_fullname_filter($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;
}
add_filter(\’bp_fetch_user_fullname\’,\’my_fullname_filter\’);
The activity displays store the user\’s profile link in the activity table pre-generated and there is no opportunity to filter things that already exist there. You\’ll either have to wipe the activity tables or just wait till they filter out. New activity will have the filtered full name.
sweet! cool
this goes in bp-custom.php I assume?
one more question,
we tried this in both bp-customs.php and bp-xprofile_fielters.php…. didnt work
we’ve changed “Full Name” to be just “First Name” and added a “Last Name” field
I’m assuming that is why this doesnt work…..
thanks
I give up.
If you’ve added a “last name” field, then just add instructions for the field to say “Only enter the first letter of your last name”. Simple as that isn’t it?
thank you for your efforts Burt,
(im gonna keep messin with it… and post it back here once/if i get i working)
I wish it was that simple…. the first and last name are required for other features on the site…. (portal site with social-network skin)
we’ve hidden the last name altogether, but it looks empty only having first name under “general information”
buzzwe.com
field_1 First Name -visible
field_2 Last Name -hidden
field_3 Referred by -hidden / change disabled
hidden in phpmyadmin by changing the is_public 1 to 0
disable changes by adding filter to bp_xprofile_classes.php
(if field_3 and on edit profile screen, hide)
any other ideas?
thank you
Here is what I would do… And what I do mostly on all of my BuddyPress installations…
In your BuddyPress->General Settings, make the “Full Name field name” be called “Display Name” or in your case “First Name/Last Initial”
That way, people know right away what you want shown there. You won’t need to baby sit them because it says right there what you want entered. Most people will follow suit, and the ones that don’t, what’s the diff?
(Notice I use my middle name here on bp.org?)
Then, create extra fields for First Name and Last Name, for yourself to use. Make them visible if you’d like, or whatever.
This way you’re not trying to create a crazy filter to micro manage anything.
This is a custom coding issue. Not a bp issue. I’m turning off the red light on this one.
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; } } ?>
- The topic ‘Xprofile: Just show first Letter of last name’ is closed to new replies.