Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mail_notification($except = ['94.112.194.89', '127.0.0.1']) {
- $user = wp_get_current_user()->display_name;
- $hash = md5(!empty($user) ? $user : 'anonymous');
- /** Pokud nejsou aktivní $_SESSION, aktivuj je */
- if($_SESSION === null) session_start();
- /** Pokud se uživatel přihlásil dodatečně, resetuj notifikaci */
- if(isset($_SESSION['insessionmail']) && isset($hash) && $hash !== $_SESSION['insessionmail']) unset($_SESSION['insessionmail']);
- /** Pokud IP není vyjmuta, notifikce nebyla odeslána a request není na admin rozhraní, vytvoř notifikci */
- if(!is_admin() && !in_array($_SERVER['REMOTE_ADDR'], $except) && !isset($_SESSION['insessionmail'])) {
- if(!empty($user)) {
- $message = 'Web právě ' . (strpos($user, 'ová') !== false ? 'navštívila' : 'navštívil') . ' ' . $user;
- } else {
- $message = 'Web právě navštívil nepřihlášený uživatel.';
- }
- /** Pokud je notifikace rozhraním WordPress odeslána, nastav $_SESSION['insessionmail'] */
- if(wp_mail('barveramartin@gmail.com', 'Nový návštěvník webu', $message)) $_SESSION['insessionmail'] = $hash;
- }
- }
- add_action('init', 'mail_notification', 25);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement