Title: Refreshing get_currentuserinfo
Last modified: August 20, 2016

---

# Refreshing get_currentuserinfo

 *  Resolved [redrocksrover2](https://wordpress.org/support/users/redrocksrover2/)
 * (@redrocksrover2)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/refreshing-get_currentuserinfo/)
 * Hi,
 * I have created a custom user Account Settings page that lets WP users update 
   their account information including additional custom fields that get attached
   to that user’s metadata. One of the fields that can be updated is the user’s 
   email address.
 * I display the currently logged in user’s email address in my header.php file.
   I use `get_currentuserinfo` to display the currently logged-in user’s email address
   in the header that is displayed on all pages throughout the site.
 * When the user updates the email address of their account by submitting my Account
   Settings form, the form confirms that the email address is unique, and displays
   a “Your profile has been updated” message after the successful update (the PHP
   form evaluates itself, displays errors, and accomplishes the `wp_update_user`
   and `update_user_meta` functions). The problem I’m encountering is that when 
   the form page evaluates itself and successfully updates the user record, the 
   email address in the header.php file isn’t updated to reflect the changed email
   address. I’ve tried resetting the WP auth cookie at the time that the profile
   is updated, but that doesn’t cause header.php to pick up the new email address.
   So far the only way I can get the web page (and thus header.php) to display the
   new email address is to reload the page in the browser.
 * I suppose I could have the account settings page redirect to itself after a successful
   user profile update, but I’m not sure if that’s necessary or the best way to 
   accomplish what I’m trying to do.
 * Any suggestions for the best way to accomplish what I intend, e.g. that a successful
   update of the user’s email address is reflected in my header.php file after the
   update?

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [billibones](https://wordpress.org/support/users/billibones/)
 * (@billibones)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/refreshing-get_currentuserinfo/#post-3383339)
 * Could you not write the new value to a SESSION variable and then pass it along
   that way?
    (ie.
 *     ```
       <?
       session_start;
       if (isset($_SESSION['oldEmail']))
       {
       // user submits form ... new email is written to a variable $newEmail
       // do your update_user_meta etc updates to the DB ...
       // I think session_register is deprecated now
       // query the user table and get your newly updated email address for the ID of the user
       // $resObj-> mysql_fetch_object the new email and register it in a temp session variable.
   
       $_SESSION['newEmail'] = $resObj->user_meta_field_name;
       $newEmail = $_SESSION['newEmail'];
       $oldEmail = $_SESSION['oldEmail'];
       $oldEmail = $newEmail;
       }
       ?>
       ... carry on ...
       ```
   
 * Also sessions are specific to the web address in which you are submitting the
   data and the cookie ID needs to be set the same otherwise you are forced to carry
   the session over in the URL itself to the next the next location for evaluation:
   so if you are at [http://yourplace.com](http://yourplace.com) and your post to
   [http://www.youplace.com](http://www.youplace.com) you will have problems. Keep
   the URL exact if it isnt that way already. (ie. `<?php echo htmlentities($_SERVER['
   REQUEST_URI']); ?>`)
 * This probably a little archaic, and not even certain it will work but just some
   initial thoughts.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/refreshing-get_currentuserinfo/#post-3383349)
 * I could be wrong, but I believe all WP user settings are cached to minimize DB
   hits. Part of the solution could involve flushing the cache and forcing it to
   reload, which is what reloading the page does. Or there’s probably a way to update
   specific cache data. Once the cache is correct, the currentuserinfo function 
   will return current data.
 * Not a complete answer, but at least a likely fruitful avenue to follow.
 *  Thread Starter [redrocksrover2](https://wordpress.org/support/users/redrocksrover2/)
 * (@redrocksrover2)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/refreshing-get_currentuserinfo/#post-3383353)
 * I’m still working on a solution to my question, and it will likely have to include
   PHP sessions per _billibones_. WordPress’s internal cache is not persistent from
   page to page, and the only way to make it so is to use a plugin.
 * There are some issues with WordPress and PHP sessions that I’m working around,
   and once I’ve ironed out what works, I’ll post back. Currently I can set PHP 
   session variables and output them, but regenerating a session with updated variables
   after submitting a form has been vexing. For some reason WordPress is either 
   holding on to the header data, or I’m not regenerating the session in the right
   place in my code.
 *  [billibones](https://wordpress.org/support/users/billibones/)
 * (@billibones)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/refreshing-get_currentuserinfo/#post-3383356)
 * Hey Red, I’ve got one site that currently uses custom user meta, Im looking through
   that code to see what I did to navigate this situation and Ill post back … Hopefully
   we’ll find a resolution.
 * Cheers
 *  [billibones](https://wordpress.org/support/users/billibones/)
 * (@billibones)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/refreshing-get_currentuserinfo/#post-3383361)
 * I think I was heading down the wrong route with looking at a modified plugin 
   of extra_user_details ( i thought maybe serializing the data/unserializing may
   have had something to do with it but i think I am offbase with that thinking.)…
   I did find a topic below that seems to deal with similar headache’s with sessions
   and WP … maybe it will help.
 *  [billibones](https://wordpress.org/support/users/billibones/)
 * (@billibones)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/refreshing-get_currentuserinfo/#post-3383363)
 * Hey I did find this out there though that might apply to your situation.
 * Adding a function to your template functions.php file:
 *     ```
       function session_manager(){
       	if (!session_id()){
       		session_start();
       		}
       	$_SESSION['email'] = $_POST['email'];
       	}
       ```
   
 * Then calling it on the page with your form when the form is posted using add_action
 *     ```
       include 'TEMPLATEPATH . /functions.php';
       add_action('init', 'session_manager');
       .. update user meta etc ... with user inputed data etc ...
       ```
   
 * This was from a post here in the forums from 2 years ago regarding a seperate
   issue with sessions.
 *  Thread Starter [redrocksrover2](https://wordpress.org/support/users/redrocksrover2/)
 * (@redrocksrover2)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/refreshing-get_currentuserinfo/#post-3383367)
 * [@billibones](https://wordpress.org/support/users/billibones/) – Thanks for the
   pointers.
 * I’ve been able to get this to work – let’s just say it’s good to pay attention
   to where the PHP session data is set and regenerated 😉 I had been overwriting
   my new session data with old variable values. Ahem.
 * For others who might be interested:
 * 1) Out of the box WordPress doesn’t respond to PHP sessions without altering 
   the config.php file or the functions.php file. This article was helpful to me:
   [http://devondev.com/2012/02/03/using-the-php-session-in-wordpress/](http://devondev.com/2012/02/03/using-the-php-session-in-wordpress/)
 * 2) Once I had set up functions to start PHP sessions and destroy them on login
   or logout, I was able to manipulate session variables via `$_SESSION['key']` 
   in either my header.php file — or in my particular case where I am processing
   form data and want the new values submitted by the user to update the session
   variables — at the top of my form after the `$_POST` data has been processed,
   but before WP’s header.php file is output. This way my header.php file picks 
   up the new values of the PHP session variables.
 * 3) This also gives you the ability to use any of the other PHP session functions
   such as `session_regenerate_id()`.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Refreshing get_currentuserinfo’ is closed to new replies.

## Tags

 * [header](https://wordpress.org/support/topic-tag/header/)
 * [user_email](https://wordpress.org/support/topic-tag/user_email/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 7 replies
 * 3 participants
 * Last reply from: [redrocksrover2](https://wordpress.org/support/users/redrocksrover2/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/refreshing-get_currentuserinfo/#post-3383367)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
