/** * Saves and restores user interface settings stored in a cookie. * * 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. * * @package bbPress * @subpackage Meta * @since 1.0 */ function bb_user_settings() { if (!defined('BB_IS_ADMIN') || !BB_IS_ADMIN) { return; } if (defined('DOING_AJAX')) { return; } if (!($user = bb_get_current_user())) { return; } $settings = bb_get_usermeta($user->ID, 'bb_user_settings'); if (isset($_COOKIE['bb-user-settings-' . $user->ID])) { $cookie = preg_replace('/[^A-Za-z0-9=&_]/', '', $_COOKIE['bb-user-settings-' . $user->ID]); if (!empty($cookie) && strpos($cookie, '=')) { if ($cookie == $settings) { return; } $last_time = (int) bb_get_usermeta($user->ID, 'bb_user_settings_time'); $saved = isset($_COOKIE['bb-user-settings-time-' . $user->ID]) ? preg_replace('/[^0-9]/', '', $_COOKIE['bb-user-settings-time-' . $user->ID]) : 0; if ($saved > $last_time) { bb_update_usermeta($user->ID, 'bb_user_settings', $cookie); bb_update_usermeta($user->ID, 'bb_user_settings_time', time() - 5); return; } } } setcookie('bb-user-settings-' . $user->ID, $settings, time() + 31536000, $bb->cookiepath); setcookie('bb-user-settings-time-' . $user->ID, time(), time() + 31536000, $bb->cookiepath); }
function li_get_prompt_status_by_userid($u_id) { $prompt_email = bb_get_usermeta($u_id, 'prompt_email'); return $prompt_email == '1' ? true : false; }
function bb_apply_wp_role_map_to_user($user, $reload = true) { // Expects only user ids if (!is_numeric($user)) { return; } $user = (int) $user; if (!($wordpress_table_prefix = bb_get_option('wp_table_prefix'))) { return; } if ($wordpress_mu_primary_blog_id = bb_get_option('wordpress_mu_primary_blog_id')) { $wordpress_table_prefix .= $wordpress_mu_primary_blog_id . '_'; } if (!($wordpress_roles_map = bb_get_option('wp_roles_map'))) { return; } global $bbdb; global $wp_roles; global $bb; static $bbpress_roles_map = false; if (!$bbpress_roles_map) { $bbpress_roles_map = array(); foreach ($wp_roles->get_names() as $_bbpress_role => $_bbpress_rolename) { $bbpress_roles_map[$_bbpress_role] = 'subscriber'; } unset($_bbpress_role, $_bbpress_rolename); $bbpress_roles_map = array_merge($bbpress_roles_map, array_flip($wordpress_roles_map)); unset($bbpress_roles_map['inactive'], $bbpress_roles_map['blocked']); } static $wordpress_userlevel_map = array('administrator' => 10, 'editor' => 7, 'author' => 2, 'contributor' => 1, 'subscriber' => 0); $bbpress_roles = bb_get_usermeta($user, $bbdb->prefix . 'capabilities'); $wordpress_roles = bb_get_usermeta($user, $wordpress_table_prefix . 'capabilities'); if (!$bbpress_roles && is_array($wordpress_roles)) { $bbpress_roles_new = array(); foreach ($wordpress_roles as $wordpress_role => $wordpress_role_value) { if ($wordpress_roles_map[strtolower($wordpress_role)] && $wordpress_role_value) { $bbpress_roles_new[$wordpress_roles_map[strtolower($wordpress_role)]] = true; } } if (count($bbpress_roles_new)) { bb_update_usermeta($user, $bbdb->prefix . 'capabilities', $bbpress_roles_new); if ($reload) { header('Location: ' . bb_get_uri(null, null, BB_URI_CONTEXT_HEADER)); exit; } } } elseif (!$wordpress_roles && is_array($bbpress_roles)) { $wordpress_roles_new = array(); foreach ($bbpress_roles as $bbpress_role => $bbpress_role_value) { if ($bbpress_roles_map[strtolower($bbpress_role)] && $bbpress_role_value) { $wordpress_roles_new[$bbpress_roles_map[strtolower($bbpress_role)]] = true; $wordpress_userlevels_new[] = $wordpress_userlevel_map[$bbpress_roles_map[strtolower($bbpress_role)]]; } } if (count($wordpress_roles_new)) { bb_update_usermeta($user, $wordpress_table_prefix . 'capabilities', $wordpress_roles_new); bb_update_usermeta($user, $wordpress_table_prefix . 'user_level', max($wordpress_userlevels_new)); } } }
function nospamuser_maybe_set_user_ip_field() { if (bb_is_user_logged_in() && !bb_get_usermeta(bb_get_current_user_info('ID'), 'nospamuser_ip')) { nospamuser_set_user_ip_field(bb_get_current_user_info('ID')); } }