[英]wordpress - track when user data updated - hook not working
On the front end of the site there is the facility to edit / update user details which is done via AJAX. 在站点的前端,可以通过AJAX完成编辑/更新用户详细信息的功能。
I want to track the last time user data is updated and have written a simple function for this. 我想跟踪上次用户数据更新的时间,并为此编写了一个简单的函数。 However this isn't working and I am not even sure if the function is being executed.
但是,这是行不通的,我什至不确定函数是否正在执行。 I have tried using the following hooks but none work.
我试过使用以下挂钩,但是没有用。
update_user_meta, updated_user_meta, profile_update update_user_meta,updated_user_meta,profile_update
Can anyone see what I am doing wrong? 谁能看到我在做什么错?
//add date / time to user meta data when details are updated
add_action( 'update_user_meta', 'updated_user_details' );
function updated_user_details(){
$user_id = get_current_user_id();
$datetime = date('Y-m-d H:i:s');
update_user_meta( $user_id, 'updated', $datetime );
}
There are two things wrong with this code that I can see straight away. 我可以立即看到此代码有两点错误。
Firstly, do_action
is used to create actions, rather than hook into them. 首先,
do_action
用于创建动作,而不是挂钩它们。 To hook into them, you'll need to use add_action
( See here ) 为了吸引他们,您需要使用
add_action
( 请参阅此处 )
Secondly, as far as I can see, wp_update_user
isn't a valid action that you can hook into. 其次,据我
wp_update_user
, wp_update_user
不是您可以加入的有效操作。 I think what you're looking for is updated_{$meta_type}_meta
( See here ) 我认为您要查找的是
updated_{$meta_type}_meta
( 请参阅此处 )
So it would be something more like: 因此,它将更像是:
add_action( 'updated_user_meta', 'updated_user_details' );
function updated_user_details($meta_id, $object_id, $meta_key, $_meta_value){
$user_id = get_current_user_id();
//check to see if 'updated' field exists
$updated= get_user_meta($user_id, 'updated', TRUE);
//if yes update date /time
$datetime = date('Y-m-d H:i:s');
update_user_meta( $user_id, 'updated', $datetime );
}
Note: This hasn't been tested but should give you some idea and some refs. 注意:这尚未经过测试,但应该给您一些想法和参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.