| 1 |
<?php |
| 2 |
|
| 3 |
class Logtivity_User extends Logtivity_Abstract_Logger |
| 4 |
{ |
| 5 |
public function registerHooks() |
| 6 |
{ |
| 7 |
add_action('wp_login', [$this, 'userLoggedIn'], 10, 2); |
| 8 |
add_action('wp_logout', [$this, 'userLoggedOut']); |
| 9 |
add_action( 'user_register', [$this, 'userCreated'], 10, 1 ); |
| 10 |
add_action( 'delete_user', [$this, 'userDeleted'] ); |
| 11 |
add_action( 'profile_update', [$this, 'profileUpdated'], 10, 2 ); |
| 12 |
} |
| 13 |
|
| 14 |
public function userLoggedIn( $user_login, $user ) |
| 15 |
{ |
| 16 |
return Logtivity_Logger::log('User Logged In', null, $user->ID); |
| 17 |
} |
| 18 |
|
| 19 |
public function userLoggedOut($user_id) |
| 20 |
{ |
| 21 |
return (new Logtivity_Logger($user_id)) |
| 22 |
->async(false) |
| 23 |
->setAction('User Logged Out') |
| 24 |
->send(); |
| 25 |
} |
| 26 |
|
| 27 |
public function userCreated($user_id) |
| 28 |
{ |
| 29 |
$user = new Logtivity_WP_User($user_id); |
| 30 |
|
| 31 |
return Logtivity_Logger::log('User Created. [Role: ' . $user->getRole() . ']', [ |
| 32 |
'key' => 'Username', |
| 33 |
'value' => $user->userLogin() |
| 34 |
]); |
| 35 |
} |
| 36 |
|
| 37 |
public function userDeleted($user_id) |
| 38 |
{ |
| 39 |
$user = new Logtivity_WP_User($user_id); |
| 40 |
|
| 41 |
return Logtivity_Logger::log('User Deleted. [Role: ' . $user->getRole() . ']', [ |
| 42 |
'key' => 'Username', |
| 43 |
'value' => $user->userLogin() |
| 44 |
]); |
| 45 |
} |
| 46 |
|
| 47 |
public function profileUpdated($user_id, $old_user_data) |
| 48 |
{ |
| 49 |
$user = new Logtivity_WP_User($user_id); |
| 50 |
|
| 51 |
return Logtivity_Logger::log('Profile Updated. [Role: ' . $user->getRole() . ']', [ |
| 52 |
'key' => 'Username', |
| 53 |
'value' => $user->userLogin() |
| 54 |
]); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
$Logtivity_User = new Logtivity_User; |