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