xprofile_set_field_visibility_level

Set the visibility level for this field.

Description

xprofile_set_field_visibility_level( (int) $field_id = 0, (int) $user_id = 0, (string) $visibility_level = '' ); 

Parameters (3)

0. $field_id — Optional. (int)
The ID of the xprofile field.
1. $user_id — Optional. (int)
The ID of the user to whom the data belongs.
2. $visibility_level — Optional. (string) => ''
What the visibity setting should be.

Usage

  1. if ( !function_exists( 'xprofile_set_field_visibility_level' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-xprofile/bp-xprofile-functions.php'; 
  3.  
  4. // The ID of the xprofile field. 
  5. $field_id = -1; 
  6.  
  7. // The ID of the user to whom the data belongs. 
  8. $user_id = -1; 
  9.  
  10. // What the visibity setting should be. 
  11. $visibility_level = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = xprofile_set_field_visibility_level($field_id, $user_id, $visibility_level); 
  15.  

Defined (1)

The function is defined in the following location(s).

/bp-xprofile/bp-xprofile-functions.php  
  1. function xprofile_set_field_visibility_level( $field_id = 0, $user_id = 0, $visibility_level = '' ) { 
  2. if ( empty( $field_id ) || empty( $user_id ) || empty( $visibility_level ) ) { 
  3. return false; 
  4.  
  5. // Check against a whitelist. 
  6. $allowed_values = bp_xprofile_get_visibility_levels(); 
  7. if ( !array_key_exists( $visibility_level, $allowed_values ) ) { 
  8. return false; 
  9.  
  10. // Stored in an array in usermeta. 
  11. $current_visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true ); 
  12.  
  13. if ( !$current_visibility_levels ) { 
  14. $current_visibility_levels = array(); 
  15.  
  16. $current_visibility_levels[$field_id] = $visibility_level; 
  17.  
  18. return bp_update_user_meta( $user_id, 'bp_xprofile_visibility_levels', $current_visibility_levels );