bb_update_user_setting

Adds or updates a user interface setting value based on setting name.

Description

bb_update_user_setting( (string) $name, (string) $value ); 

Parameters (2)

0. $name (string)
The name of the setting.
1. $value (string)
The value of the setting.

Usage

  1. if ( !function_exists( 'bb_update_user_setting' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-meta.php'; 
  3.  
  4. // The name of the setting. 
  5. $name = ''; 
  6.  
  7. // The value of the setting. 
  8. $value = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_update_user_setting($name, $value); 
  12.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-meta.php  
  1. function bb_update_user_setting( $name, $value ) 
  2. if ( is_null( $value ) || $value === '' ) { 
  3. return; 
  4.  
  5. if ( !$user = bb_get_current_user() ) { 
  6. return; 
  7.  
  8. $name = (string) $name; 
  9. $name = preg_replace( '/[^A-Za-z0-9_]/', '', $name ); 
  10.  
  11. $value = (string) $value; 
  12. $value = preg_replace( '/[^A-Za-z0-9_]/', '', $value ); 
  13.  
  14. $arr[$name] = $value; 
  15.  
  16. foreach ( $arr as $k => $v ) { 
  17. $settings .= $k . '=' . $v . '&'; 
  18. $settings = rtrim( $settings, '&' ); 
  19.  
  20. bb_update_usermeta( $user->ID, 'bb_user_settings', $settings ); 
  21. setcookie( 'bb-user-settings-' . $user->ID, $settings, time() + 31536000, $bb->cookiepath );