I modified/hardcoded the selectbox field in edit prof but is there a better way?
-
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 theedit_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 replacedclass-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
- You must be logged in to reply to this topic.