Skip to:
Content
Pages
Categories
Search
Top
Bottom

How would i disable users ability to change their names from profile?


  • mcpeanut
    Participant

    @mcpeanut

    sup, i really want to get rid of this ability for my users, i want the name to still be displayed on their profiles i just don’t want them to be able to change their real name once signed up as i have made first name and last name mandatory upon sign up, can you help me out or point me in the right direction on this?

Viewing 5 replies - 1 through 5 (of 5 total)

  • mcpeanut
    Participant

    @mcpeanut

    its ok i posted to soon, after searching for an answer for ages i stumbled upon a working one just now, always the damn case lmao.

    If you want to do the same here is the code i came across

    add_action( 'xprofile_data_before_save', 'disable_name_change' );
    
    function disable_name_change( $data ) {
    
    if ( 1 == $data->field_id )
    
    	$data->field_id = false;
    
    	return $data;
    
    }

    This seems to work ok from initial testing, it could be better though meaning this still lets users type a new name into the profile field but clicking on the save changes button it will now give them an error saying ‘There was a problem updating some of your profile information. Please try again.’

    ideally i would rather them not have the option to even try to change it either , if anyone has a better solution give us a shout please, thx


    danbp
    Moderator

    @danbp

    hi @mcpeanut,

    this snippet useable from BP 2.0.1 and above, can be added to bp-custom.php
    it will hide the field ID 1 which is the default Name field to all, except site admin.

    it will also avoid the user to edit that field. So if you use this, i recommand you tell them on register page that once they entered a name it they could change it later. You can than ask them $$$$ to do it. 😀

    function bpfr_hide_profile_field_group( $retval ) {
    	if ( bp_is_active( 'xprofile' ) ) :	
    	
    	// hide profile group/field to all except admin	
    	if ( !is_super_admin() ) {		
    		//exlude fields, separated by comma
    		$retval['exclude_fields'] = '1';  
    		//exlude field groups, separated by comma
    		$retval['exclude_groups'] = '1'; 			
    	} 
    	return $retval;		
    	
    	endif;
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_hide_profile_field_group' );

    More here:

    Using bp_parse_args() to filter BuddyPress template loops


    mcpeanut
    Participant

    @mcpeanut

    @danbp n1 dan, i will try it in next hour or so, haha i love the charging of $$$$ to change their own names hahahaha, that tickled me.

    What i want to do is allow them to change usernames and not their real names tbh, i know im doing things backwards but hey..lol, besides brajesh seems to have a neat plugin to allow usernames to be changed, i have disabled signing in with them so this is ideal as now users have to use their emails to sign in.


    mcpeanut
    Participant

    @mcpeanut

    im not a big fan of the whole username thing, maybe im just old fashioned…i dunno!! lol


    mcpeanut
    Participant

    @mcpeanut

    cheers dan the code is a much better solution than the one i was using earlier bud ;

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How would i disable users ability to change their names from profile?’ is closed to new replies.
Skip to toolbar