You are here

function cf_current_user in Common Functionality 7

Same name and namespace in other branches
  1. 7.2 cf.module \cf_current_user()

Provide a safe way to get the current user.

This is a fowards-compatible function of the 7.x-2.x versions.

Why: This is to easy to accidentally do: 'if ($user->uid = 1) {'

The global $user data may also not have contrib modules data included, so accessing $user directly is generally not a good idea. This function seems rather waseteful given its simplicity. It may be better if drupal core would allow $uid to be left empty such that the user_load() function would handle accessing the global $user->id if $uid is empty.

See: http://drupal.org/node/57287 See: http://api.drupal.org/api/drupal/developer--globals.php/global/user/7#co...

Parameters

bool $reset: TRUE to reset the internal cache and load from the database. FALSE (default) to load from the internal cache, if set.

array $function_history: (optional) An array of function names, ie: array('0' => 'my_function_name').

Return value

A copy of the global variable $user. Changes to this variable will not be retained.

4 calls to cf_current_user()
cf_init in ./cf.module
Implements hook_init().
cf_node_create in modules/cf_node/cf_node.module
Programatically creates a node of the form type and returns any errors. This flushes the error buffer allowing for multiple calls. This will always return an array.
cf_theme_get_variables in modules/cf_theme/cf_theme.module
Returns an array of variables to be used by a given theme.
cf_user_get_rids in modules/cf_user/cf_user.module
Provide a simple way to get the roles ids for the current or specified user.

File

./cf.module, line 127

Code

function cf_current_user($reset = FALSE) {
  return cf_get_user($reset);
}