我正在尝试将当前用户的ip、用户名、登录时间等事件写入日志文件。我已经使用WordPress钩子在php中为各种事件构建了函数,但我不知道如何将它们组合到我的日志函数中。以下是我的代码:
全局$active\\u用户;
/**
* function to get loggedin user\'s username
*/
add_action(\'init\', \'log_file_setup\');
function log_file_setup(){
$path = dirname(__FILE__) . \'/log.txt\';
$file = fopen($path,"w+");
$person = "John\\n";
file_put_contents($path, $person, FILE_APPEND );
}
/**
* function to get loggedin user\'s username
*/
function get_username(){
if(is_user_logged_in()){
$active_user = wp-get-current-user();
$username = $active_user->login;
return $username;
}
}
/**
* function to get loggedin user\'s Role(s)
*/
function get_userole(){
if(is_user_logged_in()){
$active_user = wp-get-current-user();
// I have cast this into an array because the user may have multiple roles
$userroles = ( array ) $active_user->roles;
return $userroles;
}
}