简体   繁体   English

为WordPress中当前登录的用户设置临时变量

[英]Set temporary variables for current logged in user in WordPress

If my user can login from different browsers, concurrently, how can I save a temporary variable (a special format random variable or a device specific id) for each session and access it later in codex? 如果我的用户可以同时从不同的浏览器登录,那么如何为每个会话保存一个临时变量(特殊格式的随机变量或设备特定的ID)并稍后在Codex中访问它?

I can't use update_user_meta and get_user_meta, because user meta is user based, not session based. 我不能使用update_user_meta和get_user_meta,因为用户元是基于用户的,而不是基于会话的。

You could use user meta. 您可以使用用户元。

See update_user_meta and get_user_meta . 参见update_user_metaget_user_meta

The current user id can be retrieved with get_current_user_id to set and then get values associated with a given user. 可以使用get_current_user_id检索当前用户ID以进行设置,然后获取与给定用户关联的值。

The only gotcha is when using get_user_meta (or any other get meta function in WordPress), is be sure to set $single to true , otherwise you'll get an array with just one value. 唯一的麻烦是使用get_user_meta(或WordPress中的任何其他get meta函数)时,请确保将$single设置$single true ,否则您将获得仅包含一个值的数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM