| 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'], 10, 1); |
| 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 |
$logtivityUser = new Logtivity_WP_User($user->ID); |
| 17 |
|
| 18 |
return (new Logtivity_Logger($user)) |
| 19 |
->setAction('User Logged In') |
| 20 |
->setContext($logtivityUser->getRole()) |
| 21 |
->send(); |
| 22 |
} |
| 23 |
|
| 24 |
public function userLoggedOut($user_id) |
| 25 |
{ |
| 26 |
if ($user_id == 0) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
$user = new Logtivity_WP_User($user_id); |
| 31 |
|
| 32 |
return (new Logtivity_Logger($user_id)) |
| 33 |
->setAction('User Logged Out') |
| 34 |
->setContext($user->getRole()) |
| 35 |
->send(); |
| 36 |
} |
| 37 |
|
| 38 |
public function userCreated($user_id) |
| 39 |
{ |
| 40 |
$log = Logtivity_Logger::log(); |
| 41 |
|
| 42 |
if (!is_user_logged_in()) { |
| 43 |
$log->setUser($user_id); |
| 44 |
} |
| 45 |
|
| 46 |
$user = new Logtivity_WP_User($user_id); |
| 47 |
|
| 48 |
$log->setAction('User Created') |
| 49 |
->setContext($user->getRole()) |
| 50 |
->addMeta('Username', $user->userLogin()) |
| 51 |
->send(); |
| 52 |
} |
| 53 |
|
| 54 |
public function userDeleted($user_id) |
| 55 |
{ |
| 56 |
$user = new Logtivity_WP_User($user_id); |
| 57 |
|
| 58 |
return Logtivity_Logger::log() |
| 59 |
->setAction('User Deleted') |
| 60 |
->setContext($user->getRole()) |
| 61 |
->addMeta('Username', $user->userLogin()) |
| 62 |
->send(); |
| 63 |
} |
| 64 |
|
| 65 |
public function profileUpdated($user_id, $old_user_data) |
| 66 |
{ |
| 67 |
$user = new Logtivity_WP_User($user_id); |
| 68 |
|
| 69 |
return Logtivity_Logger::log() |
| 70 |
->setAction('Profile Updated') |
| 71 |
->setContext($user->getRole()) |
| 72 |
->addMeta('Username', $user->userLogin()) |
| 73 |
->send(); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
$Logtivity_User = new Logtivity_User; |