是否可以获取在wp-admin中正在编辑的配置文件的用户ID?
如果您正在编辑用户(例如:./wp-admin/user-edit.php?user_id=427),我知道它在URL中。始终可以$ _GET ['user_id']检索用户的ID。
是否有简单或广泛的方法来检索正在wp-admin中编辑的当前用户配置文件的用户ID?
答案 0 :(得分:1)
您已经声明可以通过ID
获得$_GET
...
另一种方法是通过get_current_user_id()
-假设您是正在编辑的用户。 (@cabrerahector)
https://developer.wordpress.org/reference/functions/get_current_user_id/
另一种方法是挂在edit_user_profile_update
动作挂钩上,它将当前编辑的用户传递到您的回调函数中。这可能仅在编辑个人资料以外的个人资料时才有效。
do_action( 'edit_user_profile_update', my_user_function() )
function my_user_function(int $user_id){
// $user_id is currently edited user
}
https://developer.wordpress.org/reference/hooks/edit_user_profile_update/