Ticket #3695: 3695.002.patch
File 3695.002.patch, 25.1 KB (added by , 13 years ago) |
---|
-
bp-themes/bp-default/_inc/css/default.css
diff --git bp-themes/bp-default/_inc/css/default.css bp-themes/bp-default/_inc/css/default.css index fd87026..5e6bea6 100644
Hello, this is the BuddyPress Default theme stylesheet. 34 34 6.7 - Topics and Tables - Forums and General 35 35 6.8 - Headers, Lists and Tabs - Activity, Groups, Blogs, Forums 36 36 6.9 - Private Messaging Threads 37 6.10 - Extended Profiles 37 38 --------------------------------------------------------------*/ 38 39 39 40 /*-------------------------------------------------------------- … … div.item-list-tabs ul li.feed a { 2292 2293 #admins-list li { 2293 2294 overflow: auto; 2294 2295 } 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 }2302 2296 2303 2297 2304 2298 /*-------------------------------------------------------------- … … div#message-thread div.message-content { 2364 2358 } 2365 2359 div#message-thread div.message-options { 2366 2360 text-align: right; 2361 } 2362 2363 /*-------------------------------------------------------------- 2364 6.9 - Extended Profiles 2365 --------------------------------------------------------------*/ 2366 2367 div.profile h4 { 2368 margin-bottom: auto; 2369 margin-top: 15px; 2370 } 2371 #profile-edit-form ul.button-nav { 2372 margin-top: 15px; 2373 } 2374 body.no-js .field-privacy-settings-toggle, 2375 body.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; 2367 2390 } 2391 No newline at end of file -
bp-themes/bp-default/_inc/global.js
diff --git bp-themes/bp-default/_inc/global.js bp-themes/bp-default/_inc/global.js index 527650a..fe65495 100644
jq(document).ready( function() { 807 807 return false; 808 808 }); 809 809 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 810 833 /** Friendship Requests **************************************/ 811 834 812 835 /* Accept and Reject friendship request buttons */ -
bp-themes/bp-default/members/single/profile/edit.php
diff --git bp-themes/bp-default/members/single/profile/edit.php bp-themes/bp-default/members/single/profile/edit.php index 05a3665..b012a61 100644
if ( bp_has_profile( 'profile_group_id=' . bp_get_current_profile_group_id() ) ) 112 112 </div> 113 113 114 114 <?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 ?> 115 130 116 131 <?php do_action( 'bp_custom_profile_edit_fields' ); ?> 117 132 -
bp-xprofile/bp-xprofile-admin.php
diff --git bp-xprofile/bp-xprofile-admin.php bp-xprofile/bp-xprofile-admin.php index 55add6d..04fe3d3 100644
function xprofile_admin_manage_field( $group_id, $field_id = null ) { 262 262 $type = 'error'; 263 263 264 264 unset( $_GET['mode'] ); 265 265 266 xprofile_admin( $message, $type ); 266 267 } else { 267 268 $message = __( 'The field was saved successfully.', 'buddypress' ); … … function xprofile_admin_manage_field( $group_id, $field_id = null ) { 270 271 if ( 1 == $field_id ) 271 272 bp_update_option( 'bp-xprofile-fullname-field-name', $field->name ); 272 273 274 if ( !empty( $_POST['default-privacy'] ) ) { 275 bp_xprofile_update_field_meta( $field_id, 'default_privacy', $_POST['default-privacy'] ); 276 } 277 273 278 unset( $_GET['mode'] ); 274 279 275 280 do_action( 'xprofile_fields_saved_field', $field ); -
bp-xprofile/bp-xprofile-classes.php
diff --git bp-xprofile/bp-xprofile-classes.php bp-xprofile/bp-xprofile-classes.php index 2450811..b801823 100644
class BP_XProfile_Group { 114 114 global $wpdb, $bp; 115 115 116 116 $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 125 126 ); 126 127 127 128 $r = wp_parse_args( $args, $defaults ); … … class BP_XProfile_Group { 151 152 152 153 if ( empty( $group_ids ) ) 153 154 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 } 158 181 159 182 // Fetch the fields 160 183 $fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, name, description, type, group_id, is_required FROM {$bp->profile->table_name_fields} WHERE group_id IN ( {$group_ids} ) AND parent_id = 0 {$exclude_fields_sql} ORDER BY field_order" ) ); … … class BP_XProfile_Group { 172 195 $field_ids_sql = implode( ',', (array) $field_ids ); 173 196 174 197 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 ) ); 176 199 177 200 // Remove data-less fields, if necessary 178 201 if ( !empty( $hide_empty_fields ) ) { … … class BP_XProfile_Group { 210 233 foreach( (array) $field_data as $data ) { 211 234 212 235 // Assign correct data value to the field 213 if ( $field->id == $data->field_id ) 236 if ( $field->id == $data->field_id ) { 214 237 $fields[$field_key]->data->value = $data->value; 238 $fields[$field_key]->data->id = $data->id; 239 } 215 240 } 216 241 } 242 243 if ( $fetch_privacy_level ) { 244 $fields = self::fetch_privacy_level( $user_id, $fields ); 245 } 217 246 } 218 247 } 219 248 … … class BP_XProfile_Group { 263 292 264 293 return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET group_order = %d WHERE id = %d", $position, $field_group_id ) ); 265 294 } 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 267 342 /* ADMIN AREA HTML. 268 343 * TODO: Get this out of here and replace with standard loops 269 344 */ … … class BP_XProfile_Field { 343 418 var $option_order; 344 419 var $order_by; 345 420 var $is_default_option; 421 var $default_privacy; 346 422 347 423 var $data; 348 424 var $message = null; … … class BP_XProfile_Field { 380 456 if ( $get_data && $user_id ) { 381 457 $this->data = $this->get_field_data( $user_id ); 382 458 } 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 } 383 465 } 384 466 } 385 467 … … class BP_XProfile_Field { 639 721 if ( $this->type != $type ) { 640 722 $class = 'display: none;'; 641 723 } 724 725 if ( empty( $this->default_privacy ) ) { 726 $this->default_privacy = 'public'; 727 } 642 728 643 729 ?> 644 730 … … class BP_XProfile_Field { 787 873 788 874 <?php } ?> 789 875 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 790 892 <p class="submit"> 791 893 <input type="hidden" name="field_order" id="field_order" value="<?php echo esc_attr( $this->field_order ); ?>" /> 792 894 <input type="submit" value="<?php _e( 'Save', 'buddypress' ); ?>" name="saveField" id="saveField" style="font-weight: bold" class="button-primary" /> … … class BP_XProfile_ProfileData { 967 1069 968 1070 return $profile_data; 969 1071 } 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 } 970 1091 971 1092 function get_value_byid( $field_id, $user_ids = null ) { 972 1093 global $wpdb, $bp; -
bp-xprofile/bp-xprofile-functions.php
diff --git bp-xprofile/bp-xprofile-functions.php bp-xprofile/bp-xprofile-functions.php index ed0ee2e..d047126 100644
function xprofile_set_field_data( $field, $user_id, $value, $is_required = false 250 250 return $field->save(); 251 251 } 252 252 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 */ 261 function 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 253 291 function xprofile_delete_field_data( $field, $user_id ) { 254 292 if ( is_numeric( $field ) ) 255 293 $field_id = $field; … … function bp_xprofile_fullname_field_name() { 605 643 return apply_filters( 'bp_xprofile_fullname_field_name', BP_XPROFILE_FULLNAME_FIELD_NAME ); 606 644 } 607 645 646 /** 647 * Get privacy levels out of the $bp global 648 * 649 * @return array 650 */ 651 function 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 */ 674 function 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 */ 725 function 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 608 749 ?> -
bp-xprofile/bp-xprofile-loader.php
diff --git bp-xprofile/bp-xprofile-loader.php bp-xprofile/bp-xprofile-loader.php index 731bc95..5c6005e 100644
class BP_XProfile_Component extends BP_Component { 82 82 'multiselectbox', 83 83 'datebox' 84 84 ) ); 85 86 $this->privacy_levels = apply_filters( 'xprofile_default_privacy_levels', array( 87 'public' => array( 88 'id' => 'public', 89 'label' => __( 'Anyone', 'buddypress' ) 90 ), 91 'loggedin' => array( 92 'id' => 'loggedin', 93 'label' => __( 'Logged In Users', 'buddypress' ) 94 ) 95 ) ); 96 97 98 if ( bp_is_active( 'friends' ) ) { 99 $this->privacy_levels['friends'] = array( 100 'id' => 'friends', 101 'label' => __( 'My Friends', 'buddypress' ) 102 ); 103 } 85 104 86 105 // Tables 87 106 $global_tables = array( -
bp-xprofile/bp-xprofile-screens.php
diff --git bp-xprofile/bp-xprofile-screens.php bp-xprofile/bp-xprofile-screens.php index 0d5ffb1..aa72646 100644
function xprofile_screen_edit_profile() { 113 113 $errors = true; 114 114 else 115 115 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 ); 116 120 } 117 121 118 122 do_action( 'xprofile_updated_profile', bp_displayed_user_id(), $posted_field_ids, $errors ); -
bp-xprofile/bp-xprofile-template.php
diff --git bp-xprofile/bp-xprofile-template.php bp-xprofile/bp-xprofile-template.php index b1c5268..5161bcc 100644
class BP_XProfile_Data_Template { 24 24 var $in_the_loop; 25 25 var $user_id; 26 26 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 ) { 28 28 $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 37 38 ) ); 38 39 39 40 $this->group_count = count($this->groups); … … function bp_has_profile( $args = '' ) { 156 157 // Only show empty fields if we're on the Dashboard, or we're on a user's profile edit page, 157 158 // or this is a registration page 158 159 $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 160 168 $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 169 178 ); 170 179 171 180 $r = wp_parse_args( $args, $defaults ); 172 181 extract( $r, EXTR_SKIP ); 173 182 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 ); 175 184 return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template ); 176 185 } 177 186 … … function bp_the_profile_field_is_required() { 697 706 return apply_filters( 'bp_get_the_profile_field_is_required', (bool) $retval ); 698 707 } 699 708 709 /** 710 * Echo the privacy level of this field 711 */ 712 function 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 */ 729 function 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 700 745 function bp_unserialize_profile_field( $value ) { 701 746 if ( is_serialized($value) ) { 702 747 $field_value = maybe_unserialize($value); … … function bp_edit_profile_button() { 839 884 ) ); 840 885 } 841 886 887 /** 888 * Echo the field privacy radio buttons 889 */ 890 function 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 } 842 909 ?>