Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Last active July 26, 2022 14:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KaineLabs/6f86315ba12123ebcf461f71923d0782 to your computer and use it in GitHub Desktop.
Save KaineLabs/6f86315ba12123ebcf461f71923d0782 to your computer and use it in GitHub Desktop.
Disable Buddypress Name Field
<?php
/**
* Change Name field With Username.
*/
function my_member_username() {
global $members_template;
return $members_template->member->user_login;
}
add_filter( 'bp_member_name' , 'my_member_username' );
/**
* Change FullName field With Username.
*/
function my_bp_displayed_user_fullname( $fullname ) {
if ( ! bp_is_user() ) {
return $fullname;
}
global $bp;
return isset( $bp->displayed_user->userdata->user_login ) ? $bp->displayed_user->userdata->user_login : $fullname;
}
add_filter( 'bp_displayed_user_fullname' , 'my_bp_displayed_user_fullname' );
/**
* Header Script
*/
function yzc_sync_username_and_name_fields() {
?>
<script>
var url = document.location.href;
jQuery(document).ready( function() {
//copy profile name to account name during registration
if ( url.indexOf( "register/" ) >= 0 ) {
jQuery( 'label[for=field_1],#field_1' ).css( 'display', 'none' );
jQuery( '#signup_username' ).blur( function() {
jQuery( '#field_1' ).val( jQuery( "#signup_username" ).val());
});
}
});
</script>
<style type="text/css">
#profile-details-section .logy-section-title,
.editfield.field_1 {
display: none;
}
</style>
<?php
}
add_action( 'wp_head', 'yzc_sync_username_and_name_fields' );
@sohan-wp
Copy link

Good . it has worked .But i want to disable buddypress "username" fields and replace "Name" fields . can you do that please .

@LeviZell
Copy link

LeviZell commented Apr 25, 2019

I get the following error with this code

Notice: Trying to get property of non-object in /home/user/public_html/wp-content/plugins/bp-custom.php on line 18

@LeviZell
Copy link

LeviZell commented Apr 25, 2019

Changing line 18 from
return $members_template->member->user_login;
to
return $bp->displayed_user->fullname;
cleared the error for me. Hopefully that still works with everything.

@KaineLabs
Copy link
Author

Changing line 18 from
return $members_template->member->user_login;
to
return $bp->displayed_user->fullname;
cleared the error for me. Hopefully that still works with everything.

Sorry for the late reply i just saw your message, done i updated the code.

@geekparadize
Copy link

I get the following error with this code

An invalid form control with name='field_1' is not focusable.

@Os-nash
Copy link

Os-nash commented Jul 26, 2022

I'm getting this error:

"An invalid form control with name='field_1' is not focusable"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment