Skip to:
Content
Pages
Categories
Search
Top
Bottom

Rename Field Label Depending On Member Type


  • bcanr2d2
    Participant

    @bcanr2d2

    I am trying to get around different fields being required in different member types, by trying to change the label of the field for a specific member type

    When using the following code, it changes the name of the field, and not just the label!
    Any Tips, please.
    I have it visible to all users, and will display in the backend as Cost Per Hour when it is edited (shows the other name when not edited).

    function filter_bp_get_the_profile_field_name( $field_name ) { 
        // make filter magic happen here... 
    
    	$user_id = bp_loggedin_user_id();
    	$bp_user_member_type = bp_get_member_type($user_id);
    
    	// field name (case sensitive)
    //	if ($bp_user_member_type == 'parent'  ) {
    	if( $field_name == 'Cost Per Hour') {
    $field_name = 'Maximum Amount To Pay For Sitting';
    //var_dump($field_name );
    //die("filter_bp_get_the_profile_field_name");
    
    	}
    //	}
        return $field_name; 
    }; 
             
    // add the filter 
    add_filter( 'bp_get_the_profile_field_name', 'filter_bp_get_the_profile_field_name', 10, 1 );
Viewing 5 replies - 1 through 5 (of 5 total)

  • modemlooper
    Moderator

    @modemlooper

    Your code worked for me on user profile and editing in admin


    modemlooper
    Moderator

    @modemlooper

    to check if on edit you can check the current action

    if ( $field_name === 'Cost Per Hour' && 'edit' === bp_current_action() ) {


    bcanr2d2
    Participant

    @bcanr2d2

    Thanks for that. I think I’d actually had the right code to begin with, using the member type to control what would be displayed. I think I’d become a bit tired at that stage of proceedings and hadn’t properly tested everything.

    I did test your code suggestion and it worked without issues as well.

    Now I can work on multiple fields that are required across different types, but give them different labels.


    bcanr2d2
    Participant

    @bcanr2d2

    Whilst this works when the field is already set, I need the labels to change when the user selects the member type drop down BEFORE the field is saved.

    My code is as below, but I am not sure how to get the information from the field before it is set, or if this is the correct function to change them on the fly.

    function filter_bp_get_the_profile_field_name( $field_name ) { 
        // make filter magic happen here... 
    
    	$user_id = bp_loggedin_user_id();
    //	$bp_user_member_type = bp_get_member_type($user_id);
    $bp_user_member_type = $_POST['field_6'];
    //var_dump($bp_user_member_type);
    //var_dump($user_id);
    //die("filter_bp_get_the_profile_field_name");
    	// field name (case sensitive)
    	if ($bp_user_member_type == 'parent'  ) {
    //	if( $field_name == 'Cost Per Hour' && 'edit' === bp_current_action() ){
    switch($field_name) {
    
    case 'Cost Per Hour':
    //if( $field_name == 'Cost Per Hour' ){
    $field_name = 'Maximum Amount To Pay For Sitting Per Hour';
    break;
    
    case 'Maximum Number Of Children Able To Sit':
    $field_name = 'Number Of Children';
    break;
    case 'Age Ranges Of Children Able To Sit':
    $field_name = 'Age Ranges of My Children';
    }
    	} else {
    if ($bp_user_member_type == 'babysitterornanny'  ) {
    switch ($field_name){
    case 'Maximum Number Of Children Able To Sit':
    $field_name = 'Maximum Number of Children I Am Able To Look After';
    break;
    case 'Age Ranges Of Children Able To Sit':
    $field_name = 'Ages of Children I am Able to Sit';
    break;
    }
    }
    }
        return $field_name; 
    }; 
             
    // add the filter 
    add_filter( 'bp_get_the_profile_field_name', 'filter_bp_get_the_profile_field_name', 10, 1 );

    modemlooper
    Moderator

    @modemlooper

    You’d have to use javascript for conditional fields that change based on selection.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar