Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom profile properties


  • jreeve
    Participant

    @jreeve

    I’m trying to customize the Buddypress profile fields. Specifically, I’m trying to write a plugin so that users won’t be able to edit their name fields from within “Edit my Profile.” I can’t seem to find the right hooks for this task. Does anyone know how I would go about this?

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

  • shanebp
    Moderator

    @shanebp

    The easiest path is just to add a conditional to an override of this template:
    buddypress\bp-templates\bp-legacy\buddypress\members\single\profile\edit.php

    The name field is, I believe, always:
    input type="text" name="field_1" id="field_1"

    So in the template, change this:
    if ( 'textbox' == bp_get_the_profile_field_type() )

    to:
    if ( 'textbox' == bp_get_the_profile_field_type() && 'field_1' != bp_get_the_profile_field_input_name() )

    and add an ‘else’ to just show the name value – bp_the_profile_field_edit_value()


    jreeve
    Participant

    @jreeve

    Great. Where/how can I override that template?


    shanebp
    Moderator

    @shanebp

    Copy it to your theme or child-theme

    See ‘Overloading Template Compatibility theme files’ here:

    Theme Compatibility & Template Files


    jreeve
    Participant

    @jreeve

    Thanks. Although it looks like adding && 'field_1' != bp_get_the_profile_field_input_name() ) has an unexpected effect: with this in place, changing any other editable field and saving it causes the user’s full name to be overwritten by his username slug, i.e. the name “Jonathan Reeve” is overwritten by “jreeve.” I can’t figure out what’s causing this.


    jreeve
    Participant

    @jreeve

    I *sort of* got it to work with this hack, although I can’t figure out a way to truly remove the input tag, since it seems to be necessary:

    
                              <?php if ( 'textbox' == bp_get_the_profile_field_type() ) :  ?>
    
    					<?php if ( 'Name' == bp_get_the_profile_field_name() ) : ?> <!-- Don't allow users to edit their names. --> 
    
    						<label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
    						<!-- Dummy input, disabled in CSS, because otherwise saving anything causes the user's full name to be overwritten with the username. --> 
    						<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(); ?>" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?> style="display: none;"/> 
    						<!-- The thing that actually displays. --> 
    						<p id="name"><?php bp_the_profile_field_edit_value();?></p> 
    
    					<?php else : ?> 
    
    						<label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
    						<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(); ?>" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>/>
    
    					<?php endif; ?>
    
    				<?php endif; ?>
    

    shanebp
    Moderator

    @shanebp

    Sorry, I forgot to consider the save functions.

    Interesting problem.

    There are a lot of action / filter hooks in bp-xprofile-classes.
    You should be able to add the name field to the $_POST before it starts processing, so that you don’t need an input.
    Or overwrite the ‘old’ name into that field value so that the new value isn’t saved, although that’s probably more confusing to the user than just hiding the input via css.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom profile properties’ is closed to new replies.
Skip to toolbar