/**
 * Return the XProfile field visibility select list for settings.
 *
 * @since 2.0.0
 *
 * @param array|string $args {
 *    Args for the select list.
 *
 *    @type int    $field_id ID of the field to render.
 *    @type string $before   Markup to render before the field.
 *    @type string $before_controls  markup before form controls.
 *    @type string $after    Markup to render after the field.
 *    @type string $after_controls Markup after the form controls.
 *    @type string $class    Class to apply to the field markup.
 *    @type string $label_class Class to apply for the label element.
 *    @type string $notoggle_tag Markup element to use for notoggle tag.
 *    @type string $notoggle_class Class to apply to the notoggle element.
 * }
 * @return string $retval
 */
function bp_profile_get_settings_visibility_select($args = '')
{
    // Parse optional arguments.
    $r = bp_parse_args($args, array('field_id' => bp_get_the_profile_field_id(), 'before' => '', 'before_controls' => '', 'after' => '', 'after_controls' => '', 'class' => 'bp-xprofile-visibility', 'label_class' => 'bp-screen-reader-text', 'notoggle_tag' => 'span', 'notoggle_class' => 'field-visibility-settings-notoggle'), 'xprofile_settings_visibility_select');
    // Empty return value, filled in below if a valid field ID is found.
    $retval = '';
    // Only do-the-do if there's a valid field ID.
    if (!empty($r['field_id'])) {
        // Start the output buffer.
        ob_start();
        // Output anything before.
        echo $r['before'];
        ?>

			<?php 
        if (bp_current_user_can('bp_xprofile_change_field_visibility')) {
            ?>

			<?php 
            echo $r['before_controls'];
            ?>

				<label for="<?php 
            echo esc_attr('field_' . $r['field_id']);
            ?>
_visibility" class="<?php 
            echo esc_attr($r['label_class']);
            ?>
"><?php 
            /* translators: accessibility text */
            _e('Select visibility', 'buddypress');
            ?>
</label>
				<select class="<?php 
            echo esc_attr($r['class']);
            ?>
" name="<?php 
            echo esc_attr('field_' . $r['field_id']);
            ?>
_visibility" id="<?php 
            echo esc_attr('field_' . $r['field_id']);
            ?>
_visibility">

					<?php 
            foreach (bp_xprofile_get_visibility_levels() as $level) {
                ?>

						<option value="<?php 
                echo esc_attr($level['id']);
                ?>
" <?php 
                selected($level['id'], bp_get_the_profile_field_visibility_level());
                ?>
><?php 
                echo esc_html($level['label']);
                ?>
</option>

					<?php 
            }
            ?>

				</select>

			<?php 
            echo $r['after_controls'];
            ?>

			<?php 
        } else {
            ?>

				<<?php 
            echo esc_html($r['notoggle_tag']);
            ?>
 class="<?php 
            echo esc_attr($r['notoggle_class']);
            ?>
"><?php 
            bp_the_profile_field_visibility_level_label();
            ?>
</<?php 
            echo esc_html($r['notoggle_tag']);
            ?>
>

			<?php 
        }
        // Output anything after.
        echo $r['after'];
        // Get the output buffer and empty it.
        $retval = ob_get_clean();
    }
    /**
     * Filters the dropdown list for setting visibility.
     *
     * @since 2.0.0
     *
     * @param string $retval HTML output for the visibility dropdown list.
     * @param array  $r      Parsed arguments to be used with display.
     * @param array  $args   Original passed in arguments to be used with display.
     */
    return apply_filters('bp_profile_settings_visibility_select', $retval, $r, $args);
}
/**
 * Return the XProfile field visibility select list for settings
 *
 * @since BuddyPress (2.0.0)
 */
function bp_profile_get_settings_visibility_select($args = '')
{
    // Parse optional arguments
    $r = bp_parse_args($args, array('field_id' => bp_get_the_profile_field_id(), 'before' => '', 'after' => '', 'class' => 'bp-xprofile-visibility'), 'xprofile_settings_visibility_select');
    // Empty return value, filled in below if a valid field ID is found
    $retval = '';
    // Only do-the-do if there's a valid field ID
    if (!empty($r['field_id'])) {
        // Start the output buffer
        ob_start();
        // Output anything before
        echo $r['before'];
        ?>

			<?php 
        if (bp_current_user_can('bp_xprofile_change_field_visibility')) {
            ?>

				<select class="<?php 
            echo esc_attr($r['class']);
            ?>
" name="<?php 
            echo esc_attr('field_' . $r['field_id']);
            ?>
_visibility">

					<?php 
            foreach (bp_xprofile_get_visibility_levels() as $level) {
                ?>

						<option value="<?php 
                echo esc_attr($level['id']);
                ?>
" <?php 
                selected($level['id'], bp_get_the_profile_field_visibility_level());
                ?>
><?php 
                echo esc_html($level['label']);
                ?>
</option>

					<?php 
            }
            ?>

				</select>

			<?php 
        } else {
            ?>

				<span class="field-visibility-settings-notoggle" title="<?php 
            esc_attr_e("This field's visibility cannot be changed.", 'buddypress');
            ?>
"><?php 
            bp_the_profile_field_visibility_level_label();
            ?>
</span>

			<?php 
        }
        // Output anything after
        echo $r['after'];
        // Get the output buffer and empty it
        $retval = ob_get_clean();
    }
    // Output the dropdown list
    return apply_filters('bp_profile_settings_visibility_select', $retval, $r, $args);
}