BuddyDev

Search

[Resolved] Buddypress – How to Hide / Restrict Primary Name field?

  • Participant
    Level: Initiated
    Posts: 16
    Ekiz on #12706

    Hi,

    I want to hide the primary field from the users and restrict the editing. – (Profile>Settings page)

    It can be hidden with CSS but this method can be easily hacked and edited with the browser console.

    I’m waiting for your help.

    THANKS…

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #12709

    Hi Ekiz,
    Please put this code in your bp-custom.php

    
    
    /**
     * Don't allow changing full name on BuddyPress Edit profile.
     *
     * Pre-process $_POST and overwrite the full name field data to avoid update by users.
     */
    function buddydev_overwrite_name_update() {
    	if ( empty( $_POST['field_ids'] ) || is_super_admin() ) { //allow super admins.
    		return;
    	}
    
    	$field_id = bp_xprofile_fullname_field_id();
    	$field    = 'field_' . $field_id;
    
    	if ( empty( $_POST[ $field ] ) ) {
    		return; //not set.
    	}
    
    	// Check the field group exists.
    	if ( ! bp_is_action_variable( 'group' ) || ! xprofile_get_field_group( bp_action_variable( 1 ) ) ) {
    		return;
    	}
    
    	// overwrite with raw value.
    	// avoiding displayed_user_name and get_field_data as they provide extra filtering.
    	$_POST[ $field ] = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field_id, bp_displayed_user_id() ) );
    }
    
    add_action( 'bp_screens', 'buddydev_overwrite_name_update', 2 );
    

    That will do it for you.

    You can hide the field using css. User edit’s won’t have any effect.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 16
    Ekiz on #12721
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #12722
    This reply has been marked as private.
  • Participant
    Level: Initiated
    Posts: 16
    Ekiz on #12741
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #12743

    Thank you.

The topic ‘ [Resolved] Buddypress – How to Hide / Restrict Primary Name field?’ is closed to new replies.

This topic is: resolved