Helping you Build Your Own Social Network!

Faster, better and easier!

Disable Profile Name Change

(12 posts) (3 voices)

Tags:

No tags yet.


  1. Hi Brajesh,

    I wonder if you can help me please?

    I found some code that you wrote a while back that prevents changes being made to a profile group by the user.

    Here it is:

    <?php if(bp_get_current_profile_group_id()==1):?>
    <ul class="button-nav">
    			<?php bp_profile_group_tabs(); ?>
    		</ul>
    		<div class="clear"></div>
    <?php
    	locate_template(array("members/single/profile/profile-loop.php"),true);?>
    <p><b>Your Username is your identity and We hate to see you changing your identity, so our computer has decided to disable editing it for you.Please Edit all other data in your profile as you wish :)
    </b>
    </p>
    <?php
    else:?>

    The thread is here:

    http://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/how-to-hide-base-group-in-the-edit-profile-panel/

    Is it possible to adapt this so that ONLY the 'name field' (I have it set as display name) cannot be changed? In other words, all profile fields can be edited by the user except for the core name field (field_id 1)

    I've been trying for days to get this to work, but so far drawn a blank.

    Would really appreciate your assistance...

    Thanks in anticipation
    Rob

    Posted 10 months ago #
  2. Hi Rob,
    Thanks for the question.

    I am surprised to see this question as I was writing a detailed tutorial specially on manipulating xprofile fields. What a coincidence.

    Please wait till morning and I will have a complete post that will not require any change in the theme and allow you to do this and a lot of other things.

    Thanks
    Brajesh

    Posted 10 months ago #
  3. Anyway,
    here is the code. Just put this in functions.php and it will automatically hide the fields from editing screen

    add_filter("xprofile_group_fields","bpdev_filter_profile_fields_by_usertype",10,2);
    function bpdev_filter_profile_fields_by_usertype($fields,$group_id){
    
        //only disable these fields on edit page
        if(!bp_is_profile_edit())
            return $fields;
    
        //please change it with the name of fields you don't want to allow editing
       $field_to_remove=array("Name","Website");
    
       $count=count($fields);
       $flds=array();
       for($i=0;$i<$count;$i++){
        if(in_array($fields[$i]->name,$field_to_remove))
                unset($fields[$i]);
    
        else
            $flds[]=$fields[$i];//doh, I did not remember a way to reset the index, so creating a new array
        }
        return $flds;
    
    }

    You can remove as many field as you want by chaging the $field_to_remove array.

    Hope that helps.

    Posted 10 months ago #
  4. Hi Brajesh,

    Thank you so much, that works a treat, and I really appreciate your help with this!

    The reason for me wanting to hide a users 'Display Name' is to create a one name community for each member. My members find it confusing having a name, display name and username...

    I am currently using the plugin by r-a-y that forces usernames across Buddypress, but I think I have a conflict with another plugin and so idealy I would like to disable it if possible.

    What I would like to achieve is when a user registers, their username automatically populates the core 'name field' on the registration page (this will be hidden). So, in my case the field that automatically needs populating is 'Display Name'.

    Here's the javascript I am using to copy the input of signup_username:

    <script type = "text/javascript">
    function copyIt() {
    var x = document.getElementById("signup_username").value;
    document.getElementById("What Goes Here?").value = x;
    }
    </script>

    ...And here's the part of the registration form for choosing a username (notice the onkeyup="copyIt() function appended to the end...)

    <input type="text" name="signup_username" id="signup_username" value="<?php bp_signup_username_value() ?>" onkeyup="copyIt()"/>

    My problem then is with the 'Display Name' input, as I guess this is dynamically generated by buddypress when creating profile fields. Here's the dynamic code for text input types:

    <input type="text" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>" value="<?php bp_the_profile_field_edit_value() ?>" />

    Can you tell me Brajesh, in the javascript provided above, what I should change ("What Goes Here?")to in order for the 'signup_username' input field to secretly populate the 'Display Name' field?

    Or, is there any better way of achieving this?

    Thank you for your assistance
    Rob.

    Posted 10 months ago #
  5. That will always be "field_1"
    Try this for now, I am willing to experiment a little more and post otherways to do it :)

    Posted 10 months ago #
  6. Thanks Brajesh,

    If I put in 'field_1' in the javascript, see below, then the 'Display Name' which is 'field 1' does not automatically populate:

    <script type = "text/javascript">
    function copyIt() {
    var x = document.getElementById("signup_username").value;
    document.getElementById("field_1").value = x;
    }
    </script>

    Do I need to change anything here:

    <input type="text" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>" value="<?php bp_the_profile_field_edit_value() ?>" />

    If I do replace <?php bp_the_profile_field_input_name() ?> with field_1, won't this affect all other text input fields?

    Appreciate all your help, and if you know of a cleaner way of doing this I would be really interested to know.

    Thanks Brajesh
    Rob

    Posted 10 months ago #
  7. Hi Rob, you can use this code. Simply put it anywhere on the register page

    jQuery(document).ready(function(){
        var jq=jQuery;
        jq("#signup_username").live("blur",function(){
            jq("#field_1").val(jq("#signup_username").val());
    
        });
    })

    That will do it.

    Posted 10 months ago #
  8. Thanks again Brajesh.

    However, when I try to copy and paste:

    jQuery(document).ready(function(){
        var jq=jQuery;
        jq("#signup_username").live("blur",function(){
            jq("#field_1").val(jq("#signup_username").val());
    
        });
    })

    Into my register.php, the code above doesn't parse and instead just writes to the screen exactly as above.

    Do I need to wrap the code in something first?

    Thanks as always
    Rob.

    Posted 10 months ago #
  9. Brajesh,

    Sorry, simply by wrapping your code in <script></script> it then populates the Display Name field.

    However, the code now interferes with my Username and Email validation plugin. Can your code be isolated somehow please?

    Thanks
    Rob

    Posted 10 months ago #
  10. Brajesh,

    Problem solved! I disabled the validation plugin and renabled it...

    It seems to work just fine now.

    Really appreciate all your help with this.

    Thanks
    Rob.

    Posted 10 months ago #
  11. Hi Rob,
    sorry could not reply earlier. Glad you solved it :)

    Posted 10 months ago #
  12. thanks a ton for this code Brajesh!

    I don't get it, why do the Buddypress developer make it so that the Name field is required, then even give users the chance to change it whenever they like... But then they refuse to update the name change throughout the network... http://buddypress.trac.wordpress.org/ticket/1774

    It's a really huge misconception, this should be made optional and not force users to enter their name etc etc

    anyways </rant> :)

    Posted 9 months ago #

Reply

You must log in to post.