Advertisement
Guest User

kaiser / Wordpress 404-Mail-Notification

a guest
Feb 26th, 2010
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.86 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: 404-Deamon
  4. Plugin URI: http://not-going-to-come-anytime.com
  5. Description: Mails you a 404-Notification. This will even send you an email if you have got a missing favicon. It can be a little bit annoying, when you get mails for all crap of stuff. Feel free to extend the exclusions at the bottom. Currently it only excludes 404 if the admin lands on non-existand URLs or google and yahoo! visits you (props: toscho).
  6. Version: 0.1
  7. Author: Franz Josef Kaiser
  8. Author URI: http://unserkaiser.com
  9. License: GPL2
  10. */
  11.  
  12. // Let's go with WP. The WP-Filter-Deamon will handle this for us (hopefully)
  13. add_filter('404_template', 'notify_404');
  14.  
  15. function notify_404($deamon)
  16. {
  17.     // for Wordpress only: Your WP-URL
  18.     $page_uri = get_bloginfo('url');
  19.         // if you, like me: LOOOOOVE Pods, then go and grap a copy over at http://podscms.com
  20.         if (function_exists(pods_url_variable)) {
  21.             $page_uri_last = pods_url_variable('last');
  22.         }
  23.  
  24.     // or stick with a simple PHP-Function
  25.     // if you don't use WP, then use the following lines
  26.     /*
  27.     * START WP-KILL HERE
  28.     function full_non_wp_uri() {
  29.         $page_uri = 'http';
  30.         if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
  31.             $page_uri .= "://";
  32.         if ($_SERVER["SERVER_PORT"] != "80") {
  33.             $page_uri .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  34.         } else {
  35.             $page_uri .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  36.         }
  37.         return $page_uri;
  38.     }
  39.     */
  40.  
  41.     // non-WP Users won't need to following lines too
  42.     // set up the current User to get some data about him/her
  43.     global $current_user;
  44.     get_currentuserinfo();
  45.         // Let's see, if it's registered User, or an unknown Guest
  46.         if( is_user_logged_in() ) {
  47.             $user_mail = "The User ";
  48.             $user_mail .= $current_user->user_login;
  49.             $user_mail .= " (Mail: ";
  50.             $user_mail .= $current_user->user_email;
  51.             $user_mail .= ") has ";
  52.         } elseif( !is_user_logged_in() ) {
  53.             $user_mail = "A guest has ";
  54.         }
  55.     /* END WP-KILL HERE */
  56.  
  57.     // get some additional data about our users and guest
  58.     // don´t forget to delete the data if it´s no enemy
  59.     // we want to save the privacy of our users and guests
  60.     if(isset($_SERVER['HTTP_USER_AGENT']) {
  61.         $guest_user_agent = addslashes($_SERVER['HTTP_USER_AGENT']);
  62.     }
  63.     if(isset($_SERVER['HTTP_REFERER']) {
  64.         $guest_referer = addslashes($_SERVER['HTTP_REFERER']);
  65.     }
  66.     $guest_req_method = $_SERVER['REQUEST_METHOD'] . ' http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  67.  
  68.     // the WP-way to give you some love
  69.     $to = get_bloginfo('admin_email');
  70.     $subject = "(ae) - 404";
  71.     $message = "Dear Admin!\n\n";
  72.         $message .= "Notification:\n";
  73.         $message .= $user_mail;
  74.         $message .= "tried to reach a page that´s not here (";
  75.         $message .= $page_uri;
  76.         // quick'n'dirrrrty @pods
  77.         if (function_exists(pods_url_variable)) {
  78.             $message .= "/";
  79.             $message .= $page_uri_last;
  80.         }
  81.         $message .= ") aufzurufen.\n\n";
  82.         $message .= "Users Agent:";
  83.         $message .= $guest_user_agent;
  84.         $message .= "\n";
  85.         $message .= "Referer:";
  86.         $message .= $guest_referer;
  87.         $message .= "\n";
  88.         $message .= "Request Method:";
  89.         $message .= $guest_req_method;
  90.         $message .= "\n";
  91.         $message .= "IP: http://ip-lookup.net/?ip=";
  92.         $message .= ;
  93.         $message .= "\n\n";
  94.             $message .= "Yours,\n";
  95.             $message .= "friendly 404-Deamon from the neighborhood\n";
  96.             $message .= "-----------\n";
  97.             $message .= "That´s an automatic mail.\n";
  98.             $message .= "Please don´t answer.\n";
  99.             $message .= "I\'m too shy to reply.\n";
  100.             $message .= "-----------";
  101.  
  102.     $headers = "From: from 404-Deamon with love <fehler_404@aerztejobs10.at>\r\n\\";
  103.     $attachments = '';
  104.  
  105.     $content_type = "text/html";
  106.     apply_filters( 'wp_mail_content_type', $content_type );
  107.  
  108.         if( $current_user->user_email == get_bloginfo('admin_email') ) {
  109.         } elseif( ! ( FALSE !== strpos($_SERVER['REQUEST_URI'], 'noexist' ) or FALSE !== strpos($_SERVER['REQUEST_URI'], 'SlurpConfirm') ) ) {
  110.         } else {
  111.             wp_mail( $to, $subject, $message, $headers, $attachments );
  112.         }
  113.  
  114.     // the PHP & toscho way to give you some love
  115.     /*
  116.     'MIME-Version: 1.0' . "\r\n"
  117.         . 'Content-Type: text/plain; charset=UTF-8' . "\r\n"
  118.         . 'Content-Transfer-Encoding: 8bit' . "\r\n"
  119.         . 'From: from 404-Deamon with love <mail@' . $_SERVER['HTTP_HOST'] . '>' . "\r\n"
  120.         . 'List-Id: "404" 404.List' . "\r\n"
  121.     );
  122.     */
  123.  
  124. // that's all folks
  125. return $deamon;
  126. }
  127. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement