Irgendwie will der Cron nicht laufen. Beim ersten Start macht er einmal was, aber danach kommt nichts mehr. Hatte für Testzwecke einfach mal an den Anfang von checkPluginUpdates() einen E-Mail-Versand gesetzt und darberhinaus div. Plugins auf niedrigere Versionen runter gestellt.
Zwei Anmerkungen:
- Die Update-Plugins Funktion ist noch nicht anonymisiert
- Die Empfänger E-Mail-Adresse wird über die Konstante RECIPIENT am Anfang gesetzt.
Hier mal der komplette Code. Vielleicht hat jemand noch eine Idee
PHP-Code:
<?php
/*
Plugin Name: Mail On Update
Plugin URI: http://www.svenkubiak.de/mailonupdate
Description: Sends an E-Mail if a newer version of a plugin is available in the wordpress directory
Version: 1.0beta
Author: Sven Kubiak
Author URI: http://www.svenkubiak.de
Copyright 2008 Sven Kubiak
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
global $wp_version;
define('MOUISWP23', version_compare($wp_version, '2.3', '>='));
define('RECIPIENT','MAIL AT DOMAIN PUNKT DE');
class MailOnUpdate {
function mailonupdate()
{
//do not run if wordpress is too old
if (!MOUISWP23)
return;
//load loanguage file
//if (function_exists('load_plugin_textdomain'))
//load_plugin_textdomain('mou', PLUGINDIR.'/mailonupdate');
if (!wp_next_scheduled('scheduledCheckUpdates'))
wp_schedule_event( time(), 'hourly', 'scheduledCheckUpdates' );
add_action('scheduledCheckUpdates', array(&$this, 'checkPluginUpdates'));
}
function checkPluginUpdates()
{
global $wp_version;
if ( !function_exists('fsockopen') )
return false;
$plugins = get_plugins();
$active = get_option( 'active_plugins' );
$current = get_option( 'update_plugins' );
$new_option = '';
$new_option->last_checked = time();
$plugin_changed = false;
foreach ( $plugins as $file => $p ) {
$new_option->checked[ $file ] = $p['Version'];
if ( !isset( $current->checked[ $file ] ) ) {
$plugin_changed = true;
continue;
}
if ( strval($current->checked[ $file ]) !== strval($p['Version']) )
$plugin_changed = true;
}
if (
isset( $current->last_checked ) &&
3600 > ( time() - $current->last_checked ) &&
!$plugin_changed
)
return false;
$to_send->plugins = $plugins;
$to_send->active = $active;
$send = serialize( $to_send );
$request = 'plugins=' . urlencode( $send );
$http_request = "POST /plugins/update-check/1.0/ HTTP/1.0\r\n";
$http_request .= "Host: api.wordpress.org\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n";
$http_request .= "Content-Length: " . strlen($request) . "\r\n";
$http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n";
$http_request .= "\r\n";
$http_request .= $request;
$response = '';
if( false != ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3) ) && is_resource($fs) ) {
fwrite($fs, $http_request);
while ( !feof($fs) )
$response .= fgets($fs, 1160); // One TCP-IP packet
fclose($fs);
$response = explode("\r\n\r\n", $response, 2);
}
$response = unserialize( $response[1] );
if ( $response )
$new_option->response = $response;
update_option( 'update_plugins', $new_option );
$current = get_option( 'update_plugins' );
$message = '';
foreach ( $current->response as $plugin_file => $update_data ) {
if ( empty($update_data->package) ){
$message .= __('Name:')." ".$plugins[$plugin]['Name']."\n";
$message .= __('Version:')." ".$update_data->new_version."\n";
$message .= "\n\n";
}
}
$this->sendMailNotification(RECIPIENT,__('New updates available','mou'),$message);
}
function sendMailNotification($recipient, $subject, $message)
{
//set body
$body = __('There are updates available for the following plugins:');
$body .= "\n\n".$message;
//set header
$subject = '[' . get_bloginfo('name') . '] ' . $subject;
$bloginfo = str_replace('"', "'", get_bloginfo('name'));
$charset = get_settings('blog_charset');
$headers = "From: \"{$bloginfo}\" <noreply>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset=\"{$charset}\"\n";
//send e-mail
wp_mail($recipient, $subject, $body, $headers);
}
}
if (class_exists('MailOnUpate'))
$mou = new MailOnUpdate();
?>