| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Modules\ActivityLogs\Hooks; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Modules\ActivityLogs\Inc\Hooks_Base; |
| 6 |
|
| 7 |
// no direct access allowed |
| 8 |
if (!defined('ABSPATH')) exit; |
| 9 |
|
| 10 |
class WP_Adminify_Logs_Users extends Hooks_Base |
| 11 |
{ |
| 12 |
public function __construct() |
| 13 |
{ |
| 14 |
parent::__construct(); |
| 15 |
add_action('wp_login', [$this, 'hooks_wp_login'], 10, 2); |
| 16 |
add_action('clear_auth_cookie', [$this, 'hooks_clear_auth_cookie']); |
| 17 |
add_action('delete_user', [$this, 'hooks_delete_user']); |
| 18 |
add_action('user_register', [$this, 'hooks_user_register']); |
| 19 |
add_action('profile_update', [$this, 'hooks_profile_update']); |
| 20 |
add_filter('wp_login_failed', [$this, 'hooks_wrong_password']); |
| 21 |
} |
| 22 |
|
| 23 |
public function hooks_wp_login($user_login, $user) |
| 24 |
{ |
| 25 |
adminify_activity_logs(array( |
| 26 |
'action' => 'logged_in', |
| 27 |
'object_type' => 'User', |
| 28 |
'user_id' => $user->ID, |
| 29 |
'object_id' => $user->ID, |
| 30 |
'object_name' => $user->user_nicename, |
| 31 |
)); |
| 32 |
} |
| 33 |
|
| 34 |
public function hooks_user_register($user_id) |
| 35 |
{ |
| 36 |
$user = get_user_by('id', $user_id); |
| 37 |
|
| 38 |
adminify_activity_logs(array( |
| 39 |
'action' => 'created', |
| 40 |
'object_type' => 'User', |
| 41 |
'object_id' => $user->ID, |
| 42 |
'object_name' => $user->user_nicename, |
| 43 |
)); |
| 44 |
} |
| 45 |
public function hooks_delete_user($user_id) |
| 46 |
{ |
| 47 |
$user = get_user_by('id', $user_id); |
| 48 |
|
| 49 |
adminify_activity_logs(array( |
| 50 |
'action' => 'deleted', |
| 51 |
'object_type' => 'User', |
| 52 |
'object_id' => $user->ID, |
| 53 |
'object_name' => $user->user_nicename, |
| 54 |
)); |
| 55 |
} |
| 56 |
|
| 57 |
public function hooks_clear_auth_cookie() |
| 58 |
{ |
| 59 |
$user = wp_get_current_user(); |
| 60 |
|
| 61 |
if (empty($user) || !$user->exists()) { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
adminify_activity_logs(array( |
| 66 |
'action' => 'logged_out', |
| 67 |
'object_type' => 'User', |
| 68 |
'user_id' => $user->ID, |
| 69 |
'object_id' => $user->ID, |
| 70 |
'object_name' => $user->user_nicename, |
| 71 |
)); |
| 72 |
} |
| 73 |
|
| 74 |
public function hooks_profile_update($user_id) |
| 75 |
{ |
| 76 |
$user = get_user_by('id', $user_id); |
| 77 |
|
| 78 |
adminify_activity_logs(array( |
| 79 |
'action' => 'updated', |
| 80 |
'object_type' => 'User', |
| 81 |
'object_id' => $user->ID, |
| 82 |
'object_name' => $user->user_nicename, |
| 83 |
)); |
| 84 |
} |
| 85 |
|
| 86 |
public function hooks_wrong_password($username) |
| 87 |
{ |
| 88 |
adminify_activity_logs(array( |
| 89 |
'action' => 'wrong_password', |
| 90 |
'object_type' => 'User', |
| 91 |
'user_id' => 0, |
| 92 |
'object_id' => 0, |
| 93 |
'object_name' => $username, |
| 94 |
)); |
| 95 |
} |
| 96 |
} |
| 97 |
|