Liebe Leute,
weil ich´s gerade brauche, hab ich mir eine Funktion für 404-E-Mails geschrieben. Jetzt wollte ich´s ein wenig globaler verwendbar machen und hab schnell ein Plug-In draus gemacht. Ich hoffe jemand von Euch hat Zeit es zu testen: Code in whatever.php kopieren, hochladen in den PlugIn-Ordner und aktivieren. Dann (als nicht-Admin-User) eine nicht vorhandene Seite aufrufen und die E-Mail Adresse, die unter den Blog-Einstellungen angegeben ist, abrufen. Dort sollte dann eine E-Mail ankommen.
PHP
<?php
/*
Plugin Name: 404-Deamon
Plugin URI: http://not-going-to-come-anytime.com
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.
Version: 0.1
Author: Franz Josef Kaiser
Author URI: http://unserkaiser.com
License: GPL2
*/
if(is_404()) {
function cur_page_url() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
global $current_user;
get_currentuserinfo();
if( is_user_logged_in() ) {
$user_mail = "The User ";
$user_mail .= $current_user->user_login;
$user_mail .= " (Mail: ";
$user_mail .= $current_user->user_email;
$user_mail .= ") has ";
} elseif( !is_user_logged_in() ) {
$user_mail = "A guest has ";
}
$page_name = cur_page_url();
$to = get_bloginfo('admin_email');
$subject = "(ae) - 404";
$message = "Dear Admin!\n\n";
$message .= "Notification:\n";
$message .= $user_mail;
$message .= "tried to reach a page that´s not here (";
$message .= $page_name;
$message .= ").\n\n";
$message .= "Yours,\n";
$message .= "friendly 404-Deamon from the neighborhood\n";
$message .= "-----------\n";
$message .= "That´s an automatic mail.\n";
$message .= "Please don´t answer.\n";
$message .= "-----------";
$headers = "From: 404-Deamon: Missing <404@example.com>\r\n\\";
$attachments = '';
$content_type = "text/html";
apply_filters( 'wp_mail_content_type', $content_type );
if( $current_user->user_email == get_bloginfo('admin_email') ) { } else {
wp_mail( $to, $subject, $message, $headers, $attachments );
}
}
?>
Alles anzeigen
Viel Vergnügen!
Ps. Sollte bereits ein PlugIn vorhanden sein, dass die E-Mail Adresse des Blogs verändert, so kommt die im PlugIn eingetragene nicht zur Anwendung.