Exactly when is a user's meta data loaded? I'm using many get_user_meta()
calls for the current user. If all of a logged in user's meta data is loaded anyway, then this type of call is not a problem.
1 Answer
This page gives you a typical wordpress load http://codex.wordpress.org/Plugin_API/Action_Reference
You can see, the current user is available after the theme is setup but before init. If you are calling these functions within the theme then you will be fine. Otherwise make sure any functions that reference the current user are called using hooks that run after the set_current_user
hook. The best hook to use will vary depending on the specifics of what you're trying to do.
-
I want to run a function on every pageload to check the current user's metadata. Function must run on front-end and admin pages. What is the best hook to use for this?– HenrikCommented Mar 5, 2015 at 16:41
-
-
It get's the current user's meta data key 'foobar' and updates it depending on the value of the key.– HenrikCommented Mar 5, 2015 at 17:00
-
Your best bet is
wp_loaded
, it runs on all page types and you'll have access to pretty much all wordpress functions. Commented Mar 5, 2015 at 17:03