bb_user_settings

Saves and restores user interface settings stored in a cookie.

Description

bb_user_settings(); 

Checks if the current user-settings cookie is updated and stores it. When no cookie exists (different browser used), adds the last saved cookie restoring the settings.


Usage

  1. if ( !function_exists( 'bb_user_settings' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-meta.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bb_user_settings(); 
  7.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-meta.php  
  1. function bb_user_settings() 
  2. if ( !defined( 'BB_IS_ADMIN' ) || !BB_IS_ADMIN ) { 
  3. return; 
  4.  
  5. if ( defined( 'DOING_AJAX' ) ) { 
  6. return; 
  7.  
  8. if ( !$user = bb_get_current_user() ) { 
  9. return; 
  10.  
  11. $settings = bb_get_usermeta( $user->ID, 'bb_user_settings' ); 
  12.  
  13. if ( isset( $_COOKIE['bb-user-settings-' . $user->ID] ) ) { 
  14. $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['bb-user-settings-' . $user->ID] ); 
  15.  
  16. if ( !empty( $cookie ) && strpos( $cookie, '=' ) ) { 
  17. if ( $cookie == $settings ) { 
  18. return; 
  19.  
  20. $last_time = (int) bb_get_usermeta( $user->ID, 'bb_user_settings_time' ); 
  21. $saved = isset( $_COOKIE['bb-user-settings-time-' . $user->ID] ) ? preg_replace( '/[^0-9]/', '', $_COOKIE['bb-user-settings-time-' . $user->ID] ) : 0; 
  22.  
  23. if ( $saved > $last_time ) { 
  24. bb_update_usermeta( $user->ID, 'bb_user_settings', $cookie ); 
  25. bb_update_usermeta( $user->ID, 'bb_user_settings_time', time() - 5 ); 
  26. return; 
  27.  
  28. setcookie( 'bb-user-settings-' . $user->ID, $settings, time() + 31536000, $bb->cookiepath ); 
  29. setcookie( 'bb-user-settings-time-' . $user->ID, time(), time() + 31536000, $bb->cookiepath );