The same thing for registering – see bristolrising.com/register. Notice how changing the privacy choices for ‘Do you work or have worked within an hour of Bristol? (required)’ doesn’t affect that field, but the one above it?
The issue is in the core of the xprofile fields integration that have been added to buddypress with errors.
The problem is in the bp-xprofile-template.php file in the method bp_profile_get_visibility_radio_buttons()
Currently that function is rendering the visibility levels as radiobuttons, but is using the same id for all radiobuttons, so, if you want to allow multiple field with visibility options, the current version don’t works because the IDs of each radiobutton is repeated.
The current code of this method is:
foreach( bp_xprofile_get_visibility_levels() as $level ) {
$checked = $level['id'] == bp_get_the_profile_field_visibility_level() ? ' checked="checked" ' : '';
$html .= '<li><label for="see-field_' . esc_attr( $level['id'] ) . '"><input type="radio" id="see-field_' . esc_attr( $level['id'] ) . '" name="field_' . bp_get_the_profile_field_id() . '_visibility" value="' . esc_attr( $level['id'] ) . '"' . $checked . ' /> ' . esc_html( $level['label'] ) . '</label></li>';
}
and the correct way to do it should be:
foreach( bp_xprofile_get_visibility_levels() as $level ) {
$checked = $level['id'] == bp_get_the_profile_field_visibility_level() ? ' checked="checked" ' : '';
$html .= '<li><label for="see-field_' . esc_attr( $level['id'] ) . '"><input type="radio" id="see-field_' . esc_attr( $level['id'] ) . '" name="field_' . bp_get_the_profile_field_id() . '_visibility" value="' . esc_attr( $level['id'] ) . '"' . $checked . ' /> ' . esc_html( $level['label'] ) . '</label></li>';
}
Notice how I’m adding the correct ID for each radiobutton, thus the visibility options for each field will have the respective ID and will works!
I’m not sure why this issue is not related in the bugs list.
Sorry, the correct code with the different ID implementation is:
foreach( bp_xprofile_get_visibility_levels() as $level ) {
$checked = $level['id'] == bp_get_the_profile_field_visibility_level() ? ' checked="checked" ' : '';
$html .= '<li><label for="see-field_' . esc_attr( $level['id'] ) . '_'.bp_get_the_profile_field_id().'"><input type="radio" id="see-field_' . esc_attr( $level['id'] ) . '_'.bp_get_the_profile_field_id().'" name="field_' . bp_get_the_profile_field_id() . '_visibility" value="' . esc_attr( $level['id'] ) . '"' . $checked . ' /> ' . esc_html( $level['label'] ) . '</label></li>';
}
Check the id attribute for the radio input.
Also I have added a javascript function to change dynamically the name of the Visibility option in the toogle state, so, now, If you click on the Change Link, select other radio and click on close, you will see the new visibility option.
this is the javascript function:
function changeVisibilityLabel( id, txt ) {
sp = jQuery('#field-visibility-settings-toggle-'+id).find('.current-visibility-level');
sp.text(txt);
}
and the change to the xprofile template:
foreach( bp_xprofile_get_visibility_levels() as $level ) {
$checked = $level['id'] == bp_get_the_profile_field_visibility_level() ? ' checked="checked" ' : '';
$html .= "\n".'<li><label for="see-field_' . esc_attr( $level['id'] ) . '_'.bp_get_the_profile_field_id().'" onclick="changeVisibilityLabel('.bp_get_the_profile_field_id().', \''.esc_html( $level['label'] ).'\')"><input type="radio" id="see-field_' . esc_attr( $level['id'] ) . '_'.bp_get_the_profile_field_id().'" name="field_' . bp_get_the_profile_field_id() . '_visibility" value="' . esc_attr( $level['id'] ) . '"' . $checked . ' /> ' . esc_html( $level['label'] ) . '</label></li>';
}
Of course, this change is in the same function “bp_profile_get_visibility_radio_buttons()”