Веднага ти давам идея за Plugin - мързи ме да ги пиша сам
Имам остра нужда от известяване по email за това кога администратор се логва и от къде точно. Изпращам ти и кода:
define('ADMIN_LOGIN_NOTIFY_MESSAGE', 'Admin login on XXXX.bg with user %1$s on %2$s from %3$s');
define('ADMIN_LOGIN_NOTIFY_FROM_HEADER', 'From: XXXX.bg <
[email protected]>' . "\r\n");
define('ADMIN_LOGIN_NOTIFY_MAIL_TO', '
[email protected]');
// Track admin logins
//------------------------------------------------------------------------
function track_admin_login($user_login, $user) {
if ( user_can($user, 'manage_options') )
{
$headers = ADMIN_LOGIN_NOTIFY_FROM_HEADER;
$ip = '';
$sources = array (
'REMOTE_ADDR',
'HTTP_X_FORWARDED_FOR',
'HTTP_CLIENT_IP',
);
foreach ( $sources as $source ) {
if ( isset ( $_SERVER[ $source ] ) ) {
$ip = $_SERVER[ $source ];
} elseif ( getenv( $source ) ) {
$ip = getenv( $source );
}
}
$infoByIP = json_decode(file_get_contents("http://ipinfo.io/{$ip}"));
$eof = "\r\n";
$message = "";
$message .= sprintf(ADMIN_LOGIN_NOTIFY_MESSAGE, $user_login, date('d.m.Y H:i:s', current_time('timestamp') ), $ip ) . $eof;
$message .= "IP: $ip". $eof;
$message .= "Location: $infoByIP->city, $infoByIP->region, $infoByIP->country" . $eof;
$message .= "Network: $infoByIP->org". $eof;
$message .= 'Trace IP:
http://whatismyipaddress.com/ip/' . $ip . " " . $eol;
$message .= 'Trace IP:
http://www.ip-tracker.org/locator/ip-lookup.php?ip=' . $ip;
wp_mail(
ADMIN_LOGIN_NOTIFY_MAIL_TO,
sprintf(ADMIN_LOGIN_NOTIFY_MESSAGE, $user_login, date('d.m.Y H:i:s', current_time('timestamp') ), $ip ),
$message,
$headers);
}
}
add_action('wp_login', 'track_admin_login', 10, 2);
//------------------------------------------------------------------------