Skip to:
Content
Pages
Categories
Search
Top
Bottom

I modified/hardcoded the selectbox field in edit prof but is there a better way?


  • panosa1973
    Participant

    @panosa1973

    This is happening in a member’s edit profile page. My goal was to grab the field Height, which is in centimeters, convert it to feet and inches and then output the result on the screen. After a couple of hours of digging I ended up in class-bp-xprofile-field-type-selectbox.php and the edit_field_options_html( array $args = array() ) {... function. I saw that the label and the name of the <option> is the same: `$html .= apply_filters( ‘bp_get_the_profile_field_options_select’, ‘<option’ . $selected . ‘ value=”‘ . esc_attr( stripslashes( $options[$k]->name ) ) . ‘”>’ . esc_attr( stripslashes( $options[$k]->name ) ) . ‘</option>’, $options[$k], $this->field_obj->id, $selected, $k );
    }
    echo $html;`.
    This made me think that it’s not possible to change that through a hook because it’s the same value in both places ($options[$k]->name) so I hardcoded what I wanted to do like so:

    if ( $this->field_obj->id === 24 ) {
      $option_label = translate_height_in_inches( $options[$k]->name );
    } else {
      $option_label = esc_attr( stripslashes( $options[$k]->name ));	
    }
    $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . esc_attr( stripslashes( $options[$k]->name ) ) . '">' . $option_label . '</option>', $options[$k], $this->field_obj->id, $selected, $k );
    }
    echo $html;

    I then copied class-bp-xprofile-field-type-selectbox.php in my theme’s BuddyPress folder, /wp-content/themes/my_theme/buddypress/bp-xprofile/classes but nothing was happening so I backed up and replaced class-bp-xprofile-field-type-selectbox.php in its original place which is not good because it can be overwritten during an update. Is there a different way to do this or is this it?

    Thanks in advance,
    -Panos

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

  • panosa1973
    Participant

    @panosa1973

    I’m realizing I might nor be clear. I want to leave the value of the option as is and just convert the part that’s showing up in the drop-down menu.
    Thanks.


    mohantyt
    Participant

    @mohantyt

    Hello @panosa1973,

    Is it possible for you to give me the website link, where you had implement that? I need help in implement the same. But i am not able to implement this.

    Thanks,
    Tushar


    Varun Dubey
    Participant

    @vapvarun

    @panosa1973 You can try to override the class using bp_xprofile_get_field_types filter

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