Skip to:
Content

BuddyPress.org

Changeset 5789


Ignore:
Timestamp:
02/15/2012 08:33:09 PM (13 years ago)
Author:
boonebgorges
Message:

First pass at per-field visibility/privacy for XProfile:

  • Allows admins to set default levels for specific fields
  • Allows users to set visibility/privacy on a field-by-field basis
  • Modifies the profile templates to show markup for editing visibility status

See #3695

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-themes/bp-default/_inc/css/default.css

    r5615 r5789  
    3535    6.8 - Headers, Lists and Tabs - Activity, Groups, Blogs, Forums
    3636    6.9 - Private Messaging Threads
     37    6.10 - Extended Profiles
    3738--------------------------------------------------------------*/
    3839
     
    22932294    overflow: auto;
    22942295}
    2295 div.profile h4 {
    2296     margin-bottom: auto;
    2297     margin-top: 15px;
    2298 }
    2299 #profile-edit-form ul.button-nav {
    2300     margin-top: 15px;
    2301 }
    23022296
    23032297
     
    23662360    text-align: right;
    23672361}
     2362
     2363/*--------------------------------------------------------------
     23646.9 - Extended Profiles
     2365--------------------------------------------------------------*/
     2366
     2367div.profile h4 {
     2368    margin-bottom: auto;
     2369    margin-top: 15px;
     2370}
     2371#profile-edit-form ul.button-nav {
     2372    margin-top: 15px;
     2373}
     2374body.no-js .field-privacy-settings-toggle,
     2375body.no-js .field-privacy-settings-close {
     2376    display: none;
     2377}
     2378.field-privacy-settings {
     2379    display: none;
     2380}
     2381    body.no-js .field-privacy-settings {
     2382        display: block;
     2383    }
     2384.current-privacy-level {
     2385    font-weight: bold;
     2386}
     2387.field-privacy-settings-toggle a,
     2388.field-privacy-settings a {
     2389    font-size: .9em;
     2390}
  • trunk/bp-themes/bp-default/_inc/global.js

    r5756 r5789  
    808808    });
    809809
     810    /** Profile Privacy Settings *********************************/
     811   
     812    jq('.privacy-toggle-link').click( function() {
     813        var toggle_div = jq(this).parent();
     814       
     815        jq(toggle_div).slideUp( 200, function(){
     816            jq(toggle_div).siblings('.field-privacy-settings').slideDown(200);
     817        });
     818       
     819        return false;
     820    } );
     821
     822    jq('.field-privacy-settings-close').click( function() {
     823        var settings_div = jq(this).parent();
     824       
     825        jq(settings_div).slideUp( 200, function(){
     826            jq(settings_div).siblings('.field-privacy-settings-toggle').slideDown(200);
     827        });
     828       
     829        return false;
     830    } );
     831
     832
    810833    /** Friendship Requests **************************************/
    811834
  • trunk/bp-themes/bp-default/members/single/profile/edit.php

    r5737 r5789  
    113113
    114114                <?php endif; ?>
     115               
     116                <?php /* The fullname field is always public */ ?>
     117                <?php if ( 1 != bp_get_the_profile_field_id() ) : ?>
     118                    <div class="field-privacy-settings-toggle" id="field-privacy-settings-toggle-<?php bp_the_profile_field_id() ?>">
     119                        <?php printf( __( 'This field can be seen by: <span class="current-privacy-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_privacy_level_label() ) ?> <a href="#" class="privacy-toggle-link">Change</a>
     120                    </div>
     121                   
     122                    <div class="field-privacy-settings" id="field-privacy-settings-<?php bp_the_profile_field_id() ?>">
     123                        <label for="field-privacy"><?php _e( 'Who can see this field?', 'buddypress' ) ?></label>
     124                       
     125                        <?php bp_profile_privacy_radio_buttons() ?>
     126                       
     127                        <a class="field-privacy-settings-close" href="#"><?php _e( 'Close', 'buddypress' ) ?></a>
     128                    </div>
     129                <?php endif ?>
    115130
    116131                <?php do_action( 'bp_custom_profile_edit_fields' ); ?>
  • trunk/bp-xprofile/bp-xprofile-admin.php

    r5751 r5789  
    263263
    264264                unset( $_GET['mode'] );
     265               
    265266                xprofile_admin( $message, $type );
    266267            } else {
     
    270271                if ( 1 == $field_id )
    271272                    bp_update_option( 'bp-xprofile-fullname-field-name', $field->name );
     273
     274                if ( !empty( $_POST['default-privacy'] ) ) {
     275                    bp_xprofile_update_field_meta( $field_id, 'default_privacy', $_POST['default-privacy'] );
     276                }
    272277
    273278                unset( $_GET['mode'] );
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r5750 r5789  
    115115
    116116        $defaults = array(
    117             'profile_group_id'  => false,
    118             'user_id'           => bp_displayed_user_id(),
    119             'hide_empty_groups' => false,
    120             'hide_empty_fields' => false,
    121             'fetch_fields'      => false,
    122             'fetch_field_data'  => false,
    123             'exclude_groups'    => false,
    124             'exclude_fields'    => false
     117            'profile_group_id'    => false,
     118            'user_id'             => bp_displayed_user_id(),
     119            'hide_empty_groups'   => false,
     120            'hide_empty_fields'   => false,
     121            'fetch_fields'        => false,
     122            'fetch_field_data'    => false,
     123            'fetch_privacy_level' => false,
     124            'exclude_groups'      => false,
     125            'exclude_fields'      => false
    125126        );
    126127
     
    152153        if ( empty( $group_ids ) )
    153154            return $groups;
    154 
    155         $exclude_fields_sql = '';
    156         if ( !empty( $exclude_fields ) )
    157             $exclude_fields_sql = $wpdb->prepare( "AND id NOT IN ({$exclude_fields})" );
     155       
     156        // Support arrays and comma-separated strings
     157        if ( !empty( $exclude_fields ) && !is_array( $exclude_fields ) ) {
     158            $exclude_fields = explode( ',', $exclude_fields );
     159        }
     160       
     161        // Sanitization - ensure that each field_id passed is an integer
     162        $exclude_fields_cs = array();
     163        foreach( (array)$exclude_fields as $exclude_field ) {
     164            $efint = (int)$exclude_field;
     165            if ( !empty( $efint ) ) {
     166                $exclude_fields_cs[] = $efint;
     167            }
     168        }
     169       
     170        // Privacy - Handled here so as not to be overridden by sloppy use of the
     171        // exclude_fields parameter. See bp_xprofile_get_hidden_fields_for_user()
     172        $exclude_fields_cs = array_merge( $exclude_fields_cs, bp_xprofile_get_hidden_fields_for_user( $user_id ) );
     173       
     174        $exclude_fields_cs = implode( ',', $exclude_fields_cs );
     175       
     176        if ( !empty( $exclude_fields_cs ) ) {
     177            $exclude_fields_sql = $wpdb->prepare( "AND id NOT IN ({$exclude_fields_cs})" );
     178        } else {
     179            $exclude_fields_sql = '';
     180        }
    158181
    159182        // Fetch the fields
     
    173196
    174197            if ( !empty( $field_ids ) )
    175                 $field_data = $wpdb->get_results( $wpdb->prepare( "SELECT field_id, value FROM {$bp->profile->table_name_data} WHERE field_id IN ( {$field_ids_sql} ) AND user_id = %d", $user_id ) );
     198                $field_data = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_id, value FROM {$bp->profile->table_name_data} WHERE field_id IN ( {$field_ids_sql} ) AND user_id = %d", $user_id ) );
    176199
    177200            // Remove data-less fields, if necessary
     
    211234
    212235                        // Assign correct data value to the field
    213                         if ( $field->id == $data->field_id )
     236                        if ( $field->id == $data->field_id ) {
    214237                            $fields[$field_key]->data->value = $data->value;
     238                            $fields[$field_key]->data->id = $data->id;
     239                        }
    215240                    }
     241                }
     242                       
     243                if ( $fetch_privacy_level ) {
     244                    $fields = self::fetch_privacy_level( $user_id, $fields );
    216245                }
    217246            }
     
    264293        return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET group_order = %d WHERE id = %d", $position, $field_group_id ) );
    265294    }
    266 
     295   
     296    /**
     297     * Fetch the field privacy level for the returned fielddata
     298     */
     299    function fetch_privacy_level( $user_id, $fields ) {
     300        global $wpdb, $bp;
     301       
     302        // Get the user's privacy level preferences
     303        $privacy_levels = get_user_meta( $user_id, 'bp_xprofile_privacy_levels', true );
     304       
     305        foreach( (array)$fields as $key => $field ) {
     306            // Look to see if the user has set the privacy for this field
     307            if ( isset( $privacy_levels[$field->id] ) ) {
     308                $field_privacy = $privacy_levels[$field->id];
     309            } else {
     310                // If not, bring up the admin-set defaults
     311                if ( !isset( $default_privacy_levels ) ) {
     312                    $default_privacy_levels = self::fetch_default_privacy_levels();
     313                }
     314               
     315                // If no admin-set default is saved, fall back on a global default
     316                $field_privacy = !empty( $default_privacy_levels[$field->id] ) ? $default_privacy_levels[$field->id] : apply_filters( 'bp_xprofile_default_privacy_level', 'public' );
     317            }
     318           
     319            $fields[$key]->privacy_level = $field_privacy;
     320        }
     321       
     322        return $fields;
     323    }
     324   
     325    /**
     326     * Fetch the admin-set default privacy levels for all fields
     327     */
     328    function fetch_default_privacy_levels() {
     329        global $wpdb, $bp;
     330       
     331        $levels = $wpdb->get_results( $wpdb->prepare( "SELECT object_id, meta_value FROM {$bp->profile->table_name_meta} WHERE object_type = 'field' AND meta_key = 'default_privacy'" ) );
     332       
     333        // Arrange so that the field id is the key and the privacy level the value
     334        $default_privacy_levels = array();
     335        foreach( $levels as $level ) {
     336            $default_privacy_levels[$level->object_id] = $level->meta_value;
     337        }
     338       
     339        return $default_privacy_levels;
     340    }
     341   
    267342    /* ADMIN AREA HTML.
    268343    * TODO: Get this out of here and replace with standard loops
     
    344419    var $order_by;
    345420    var $is_default_option;
     421    var $default_privacy;
    346422
    347423    var $data;
     
    381457                $this->data          = $this->get_field_data( $user_id );
    382458            }
     459           
     460            $this->default_privacy = bp_xprofile_get_meta( $id, 'field', 'default_privacy' );
     461           
     462            if ( empty( $this->default_privacy ) ) {
     463                $this->default_privacy = 'public';
     464            }
    383465        }
    384466    }
     
    639721            if ( $this->type != $type ) {
    640722                $class = 'display: none;';
     723            }
     724           
     725            if ( empty( $this->default_privacy ) ) {
     726                $this->default_privacy = 'public';
    641727            }
    642728
     
    788874                    <?php } ?>
    789875
     876                    <?php /* The fullname field cannot be hidden */ ?>
     877                    <?php if ( 1 != $this->id ) : ?>
     878
     879                        <div id="titlediv">
     880                            <h3><label for="default-privacy"><?php _e( "Default Privacy Level", 'buddypress' ); ?></label></h3>
     881                            <div id="titlewrap">
     882                                <ul>
     883                                <?php foreach( bp_xprofile_get_privacy_levels() as $level ) : ?>
     884                                    <li><input type="radio" name="default-privacy" value="<?php echo esc_attr( $level['id'] ) ?>" <?php checked( $this->default_privacy, $level['id'] ) ?>> <?php echo esc_html( $level['label'] ) ?></li>
     885                                <?php endforeach ?>
     886                                </ul>
     887                            </div>
     888                        </div>
     889                   
     890                    <?php endif ?>
     891
    790892                    <p class="submit">
    791893                        <input type="hidden" name="field_order" id="field_order" value="<?php echo esc_attr( $this->field_order ); ?>" />
     
    9681070        return $profile_data;
    9691071    }
     1072   
     1073    /**
     1074     * Get the user's field data id by the id of the xprofile field
     1075     *
     1076     * @param int $field_id
     1077     * @param int $user_id
     1078     * @return int $fielddata_id
     1079     */
     1080    function get_fielddataid_byid( $field_id, $user_id ) {
     1081        global $wpdb, $bp;
     1082       
     1083        if ( empty( $field_id ) || empty( $user_id ) ) {
     1084            $fielddata_id = 0;
     1085        } else {
     1086            $fielddata_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id ) );
     1087        }
     1088       
     1089        return $fielddata_id;
     1090    }
    9701091
    9711092    function get_value_byid( $field_id, $user_ids = null ) {
  • trunk/bp-xprofile/bp-xprofile-functions.php

    r5729 r5789  
    251251}
    252252
     253/**
     254 * Set the privacy level for this field
     255 *
     256 * @param int $field_id The ID of the xprofile field
     257 * @param int $user_id The ID of the user to whom the data belongs
     258 * @param string $privacy_level
     259 * @return bool True on success
     260 */
     261function xprofile_set_field_privacy_level( $field_id = 0, $user_id = 0, $privacy_level = '' ) {
     262    if ( empty( $field_id ) || empty( $user_id ) || empty( $privacy_level ) ) {
     263        return false;
     264    }
     265   
     266    // Get the fielddata id
     267    $fielddata_id = BP_XProfile_ProfileData::get_fielddataid_byid( $field_id, $user_id );
     268   
     269    if ( empty( $fielddata_id ) ) {
     270        return false;
     271    }
     272   
     273    // Check against a whitelist
     274    $allowed_values = bp_xprofile_get_privacy_levels();
     275    if ( !array_key_exists( $privacy_level, $allowed_values ) ) {
     276        return false;
     277    }
     278   
     279    // Stored in an array in usermeta
     280    $current_privacy_levels = get_user_meta( $user_id, 'bp_xprofile_privacy_levels', true );
     281   
     282    if ( !$current_privacy_levels ) {
     283        $current_privacy_levels = array();
     284    }
     285   
     286    $current_privacy_levels[$field_id] = $privacy_level;
     287   
     288    return update_user_meta( $user_id, 'bp_xprofile_privacy_levels', $current_privacy_levels );
     289}
     290
    253291function xprofile_delete_field_data( $field, $user_id ) {
    254292    if ( is_numeric( $field ) )
     
    606644}
    607645
     646/**
     647 * Get privacy levels out of the $bp global
     648 *
     649 * @return array
     650 */
     651function bp_xprofile_get_privacy_levels() {
     652    global $bp;
     653   
     654    return apply_filters( 'bp_xprofile_get_privacy_levels', $bp->profile->privacy_levels );
     655}
     656
     657/**
     658 * Get the ids of fields that are hidden for this displayed/loggedin user pair
     659 *
     660 * This is the function primarily responsible for profile field privacy. It works by determining
     661 * the relationship between the displayed_user (ie the profile owner) and the current_user (ie the
     662 * profile viewer). Then, based on that relationship, we query for the set of fields that should
     663 * be excluded from the profile loop.
     664 *
     665 * @since 1.6
     666 * @see BP_XProfile_Group::get()
     667 * @uses apply_filters() Filter bp_xprofile_get_hidden_fields_for_user to modify privacy levels,
     668 *   or if you have added your own custom levels
     669 *
     670 * @param int $displayed_user_id The id of the user the profile fields belong to
     671 * @param int $current_user_id The id of the user viewing the profile
     672 * @return array An array of field ids that should be excluded from the profile query
     673 */
     674function bp_xprofile_get_hidden_fields_for_user( $displayed_user_id = 0, $current_user_id = 0 ) {
     675    if ( !$displayed_user_id ) {
     676        $displayed_user_id = bp_displayed_user_id();
     677    }
     678   
     679    if ( !$displayed_user_id ) {
     680        return array();
     681    }
     682   
     683    if ( !$current_user_id ) {
     684        $current_user_id = bp_loggedin_user_id();
     685    }
     686   
     687    // @todo - This is where you'd swap out for current_user_can() checks
     688   
     689    if ( $current_user_id ) {
     690        // Current user is logged in
     691        if ( $displayed_user_id == $current_user_id ) {
     692            // If you're viewing your own profile, nothing's private
     693            $hidden_fields = array();   
     694           
     695        } else if ( bp_is_active( 'friends' ) && friends_check_friendship( $displayed_user_id, $current_user_id ) ) {
     696            // If the current user and displayed user are friends, show all
     697            $hidden_fields = array();
     698           
     699        } else {
     700            // current user is logged-in but not friends, so exclude friends-only   
     701            $hidden_levels = array( 'friends' );           
     702            $hidden_fields = bp_xprofile_get_fields_by_privacy_levels( $displayed_user_id, $hidden_levels );
     703        }
     704       
     705    } else {
     706        // Current user is not logged in, so exclude friends-only and loggedin
     707        $hidden_levels = array( 'friends', 'loggedin' );
     708        $hidden_fields = bp_xprofile_get_fields_by_privacy_levels( $displayed_user_id, $hidden_levels );
     709    }
     710   
     711    return apply_filters( 'bp_xprofile_get_hidden_fields_for_user', $hidden_fields, $displayed_user_id, $current_user_id );
     712}
     713
     714/**
     715 * Fetch an array of the xprofile fields that a given user has marked with certain privacy levels
     716 *
     717 * @since 1.6
     718 * @see bp_xprofile_get_hidden_fields_for_user()
     719 *
     720 * @param int $user_id The id of the profile owner
     721 * @param array $levels An array of privacy levels ('public', 'friends', 'loggedin', etc) to be
     722 *    checked against
     723 * @return array $field_ids The fields that match the requested privacy levels for the given user
     724 */
     725function bp_xprofile_get_fields_by_privacy_levels( $user_id, $levels = array() ) {
     726    if ( !is_array( $levels ) ) {
     727        $levels = (array)$levels;
     728    }
     729   
     730    $user_privacy_levels = get_user_meta( $user_id, 'bp_xprofile_privacy_levels', true );
     731   
     732    $field_ids = array();
     733    foreach( (array)$user_privacy_levels as $field_id => $field_privacy ) {
     734        if ( in_array( $field_privacy, $levels ) ) {
     735            $field_ids[] = $field_id;
     736        }
     737    }
     738   
     739    // Never allow the fullname field to be excluded
     740    if ( in_array( 1, $field_ids ) ) {
     741        $key = array_search( 1, $field_ids );
     742        unset( $field_ids[$key] );
     743    }
     744   
     745    return $field_ids;
     746}
     747
     748
    608749?>
  • trunk/bp-xprofile/bp-xprofile-loader.php

    r5705 r5789  
    1515
    1616class BP_XProfile_Component extends BP_Component {
     17    /**
     18     * The acceptable privacy levels for xprofile fields.
     19     * @since 1.6
     20     * @see bp_xprofile_get_privacy_levels()
     21     */
     22    var $privacy_levels = array();
    1723
    1824    /**
     
    8389            'datebox'
    8490        ) );
     91       
     92        // Register the privacy levels. See bp_xprofile_get_privacy_levels() to filter     
     93        $this->privacy_levels = array(
     94            'public'  => array(
     95                'id'    => 'public',
     96                'label' => __( 'Anyone', 'buddypress' )
     97            ),
     98            'loggedin' => array(
     99                'id'    => 'loggedin',
     100                'label' => __( 'Logged In Users', 'buddypress' )
     101            )
     102        );
     103       
     104        if ( bp_is_active( 'friends' ) ) {
     105            $this->privacy_levels['friends'] = array(
     106                'id'    => 'friends',
     107                'label' => __( 'My Friends', 'buddypress' )
     108            );
     109        }
    85110
    86111        // Tables
  • trunk/bp-xprofile/bp-xprofile-screens.php

    r5729 r5789  
    114114                else
    115115                    do_action( 'xprofile_profile_field_data_updated', $field_id, $value );
     116               
     117                // Save the privacy level
     118                $privacy_level = !empty( $_POST['field_' . $field_id . '_privacy'] ) ? $_POST['field_' . $field_id . '_privacy'] : 'public';
     119                xprofile_set_field_privacy_level( $field_id, bp_displayed_user_id(), $privacy_level );
    116120            }
    117121
  • trunk/bp-xprofile/bp-xprofile-template.php

    r5762 r5789  
    2525    var $user_id;
    2626
    27     function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) {
     27    function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false, $fetch_privacy_level = false ) {
    2828        $this->groups = BP_XProfile_Group::get( array(
    29             'profile_group_id'  => $profile_group_id,
    30             'user_id'           => $user_id,
    31             'hide_empty_groups' => $hide_empty_groups,
    32             'hide_empty_fields' => $hide_empty_fields,
    33             'fetch_fields'      => $fetch_fields,
    34             'fetch_field_data'  => $fetch_field_data,
    35             'exclude_groups'    => $exclude_groups,
    36             'exclude_fields'    => $exclude_fields
     29            'profile_group_id'    => $profile_group_id,
     30            'user_id'             => $user_id,
     31            'hide_empty_groups'   => $hide_empty_groups,
     32            'hide_empty_fields'   => $hide_empty_fields,
     33            'fetch_fields'        => $fetch_fields,
     34            'fetch_field_data'    => $fetch_field_data,
     35            'fetch_privacy_level' => $fetch_privacy_level,
     36            'exclude_groups'      => $exclude_groups,
     37            'exclude_fields'      => $exclude_fields
    3738        ) );
    3839
     
    157158    // or this is a registration page
    158159    $hide_empty_fields_default = ( !is_network_admin() && !is_admin() && !bp_is_user_profile_edit() && !bp_is_register_page() );
    159 
     160   
     161    // We only need to fetch privacy levels when viewing your own profile
     162    if ( bp_is_my_profile() || bp_current_user_can( 'bp_moderate' ) ) {
     163        $fetch_privacy_level_default = true;
     164    } else {
     165        $fetch_privacy_level_default = false;
     166    }
     167   
    160168    $defaults = array(
    161         'user_id'           => bp_displayed_user_id(),
    162         'profile_group_id'  => false,
    163         'hide_empty_groups' => true,
    164         'hide_empty_fields' => $hide_empty_fields_default,
    165         'fetch_fields'      => true,
    166         'fetch_field_data'  => true,
    167         'exclude_groups'    => false, // Comma-separated list of profile field group IDs to exclude
    168         'exclude_fields'    => false  // Comma-separated list of profile field IDs to exclude
     169        'user_id'             => bp_displayed_user_id(),
     170        'profile_group_id'    => false,
     171        'hide_empty_groups'   => true,
     172        'hide_empty_fields'   => $hide_empty_fields_default,
     173        'fetch_fields'        => true,
     174        'fetch_field_data'    => true,
     175        'fetch_privacy_level' => $fetch_privacy_level_default,
     176        'exclude_groups'      => false, // Comma-separated list of profile field group IDs to exclude
     177        'exclude_fields'      => false  // Comma-separated list of profile field IDs to exclude
    169178    );
    170179
     
    172181    extract( $r, EXTR_SKIP );
    173182
    174     $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields );
     183    $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields, $fetch_privacy_level );
    175184    return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template );
    176185}
     
    698707    }
    699708
     709/**
     710 * Echo the privacy level of this field
     711 */
     712function bp_the_profile_field_privacy_level() {
     713    echo bp_get_the_profile_field_privacy_level();
     714}
     715    /**
     716     * Return the privacy level of this field
     717     */
     718    function bp_get_the_profile_field_privacy_level() {
     719        global $field;
     720       
     721        $retval = !empty( $field->privacy_level ) ? $field->privacy_level : 'public';
     722       
     723        return apply_filters( 'bp_get_the_profile_field_privacy_level', $retval );
     724    }
     725
     726/**
     727 * Echo the privacy level label of this field
     728 */
     729function bp_the_profile_field_privacy_level_label() {
     730    echo bp_get_the_profile_field_privacy_level_label();
     731}
     732    /**
     733     * Return the privacy level label of this field
     734     */
     735    function bp_get_the_profile_field_privacy_level_label() {
     736        global $field;
     737       
     738        $level  = !empty( $field->privacy_level ) ? $field->privacy_level : 'public';
     739        $fields = bp_xprofile_get_privacy_levels();
     740       
     741        return apply_filters( 'bp_get_the_profile_field_privacy_level_label', $fields[$level]['label'] );
     742    }
     743
     744
    700745function bp_unserialize_profile_field( $value ) {
    701746    if ( is_serialized($value) ) {
     
    840885}
    841886
     887/**
     888 * Echo the field privacy radio buttons
     889 */
     890function bp_profile_privacy_radio_buttons() {
     891    echo bp_profile_get_privacy_radio_buttons();
     892}
     893    /**
     894     * Return the field privacy radio buttons
     895     */
     896    function bp_profile_get_privacy_radio_buttons() {       
     897        $html = '<ul class="radio">';
     898       
     899        foreach( bp_xprofile_get_privacy_levels() as $level ) {
     900            $checked = $level['id'] == bp_get_the_profile_field_privacy_level() ? ' checked="checked" ' : '';
     901           
     902            $html .= '<li><input type="radio" name="field_' . bp_get_the_profile_field_id() . '_privacy" value="' . esc_attr( $level['id'] ) . '"' . $checked . '> ' . esc_html( $level['label'] ) . '</li>';
     903        }
     904       
     905        $html .= '</ul>';
     906       
     907        return apply_filters( 'bp_profile_get_privacy_radio_buttons', $html );
     908    }
    842909?>
Note: See TracChangeset for help on using the changeset viewer.