Skip to:
Content
Pages
Categories
Search
Top
Bottom

User profile privacy radio buttons are 'grayed out'

  • @tux-kapono

    Participant

    BuddyPress 1.6.5. I’m only able to change my profile field privacy settings for ‘First name’, but nothing else. The ‘Anyone’, ‘Logged In Users’ and ‘My Friends’ radio buttons are there, but I can’t select them. There’s a weird bug where if I’m in the ‘Last name’ field and I try to change the privacy, it actually changes the settings in ‘First Name’ instead.

Viewing 4 replies - 1 through 4 (of 4 total)
  • @tux-kapono

    Participant

    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?

    @jalejo08

    Participant

    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.

    @jalejo08

    Participant

    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.

    @jalejo08

    Participant

    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()”

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘User profile privacy radio buttons are 'grayed out'’ is closed to new replies.
Skip to toolbar