Replies
Hi,
Thank you for the response!In other words, did I create a field in the fields option of BB settings? If so, yes. So when they register, if they are a company, they have a field for Company Name.
I’ve been looking at these options but not sure what to change:
From a previous forum topic:
https://buddypress.org/support/topic/how-to-set-display_name-xprofile-custom_field-at-the-user-registration/add_action( ‘bp_core_activated_user’, ‘change_user_defaults’, 99, 3 );
function change_user_defaults($user_id, $key, $user) {if (empty($user_id)) {
$user_id = bp_loggedin_user_id();
}if (empty($user_id)) {
return false;
}$mv_first_name = xprofile_get_field_data(26, $user_id);
$mv_last_name = xprofile_get_field_data(11, $user_id);
$name = $mv_first_name . ‘ ‘ . $mv_last_name;if ($name !== ‘ ‘) {
$args = array(
‘ID’ => $user_id,
‘display_name’ => $name
);
wp_update_user($args);
}
}______
Or
http://hookr.io/functions/bp_get_member_name/_________
Or
https://www.buddyboss.com/resources/reference/functions/bp_get_member_name/function bp_get_member_name() {
global $members_template;// Generally, this only fires when xprofile is disabled.
if ( empty( $members_template->member->fullname ) ) {
// Our order of preference for alternative fullnames.
$name_stack = array(
‘display_name’,
‘user_nicename’,
‘user_login’
);foreach ( $name_stack as $source ) {
if ( !empty( $members_template->member->{$source} ) ) {
// When a value is found, set it as fullname and be done with it.
$members_template->member->fullname = $members_template->member->{$source};
break;
}
}
}$list_fields = bp_xprofile_get_hidden_fields_for_user( $members_template->member->ID, bp_loggedin_user_id() );
if ( empty( $list_fields ) ) {
$full_name = $members_template->member->fullname;
} else {
$last_name_field_id = bp_xprofile_lastname_field_id();
if ( in_array( $last_name_field_id, $list_fields ) ) {
$last_name = $members_template->member->fullname;
$full_name = str_replace( ‘ ‘ . $last_name, ”, $members_template->member->fullname );
} else {
$full_name = $members_template->member->fullname;
}
}/**
* Filters the display name of current member in the loop.
*
* @since BuddyPress 1.2.0
*
* @param string $fullname Display name for current member.
*/
return apply_filters( ‘bp_get_member_name’, trim( $full_name ) );
}Seems like that’s around the topic but I don’t know what to tweak. I do have Snippets installed so easy to drop it in if I could get some help with the code.
Thank you so much in advance! Surely other people want to be able to use a profile field and Display Name?
What would be even better is if:
IF there is a company name, then display that (meta field from xprofile field), and if not let the user choose from First Name, First/Last or nickname. Is that possible?- la on September 2, 2021 at 1:12 am in reply to: Make Custom Profile Tab specific to specific Profile? #40348
Hi Brajesh,
Thank you for the reply.As for #2 you mentioned: the problem with that (I have installed it and spent quite a bit of time with it) it only lets you control the content displayed by role. That doesn’t do me any good. I need the content (a shortcode for a formidable form) to be relevant only for the profile displayed. I’m convinced there must be a way to solve this.
As for #1 you suggested:
1. If you have a shortcode that accepts user id, you can use our tag replacement feature for it.
You can change
[som-shortcode user_id=32]
to
[some-shortcode user_id=”#displayed_user_id#”]Can you explain that in more detail? How would I create the tag replacement?
That sounds hopeful! I’ll check to see if the form shortcode allows for user_id.Thank you!