Skip to content

Instantly share code, notes, and snippets.

@chrisdavidmiles
Created June 13, 2025 00:21
Show Gist options
  • Save chrisdavidmiles/329330966b38475b79f6c5b05548f5f2 to your computer and use it in GitHub Desktop.
Save chrisdavidmiles/329330966b38475b79f6c5b05548f5f2 to your computer and use it in GitHub Desktop.
WordPress Plugin: Plugin Update Notifications
<?php
/**
* Plugin Name: Plugin Update Notifications
* Description: Sends notifications when plugin updates are available via Email, Discord webhook, or ntfy.sh webhook.
* Version: 1.0
* Update URI: false
*/
defined('ABSPATH') || exit; // Exit if accessed directly
class Plugin_Update_Notifications {
// Notification method: 'email', 'discord', or 'ntfy'
private $notification_method = 'ntfy';
// Discord webhook URL (replace with your webhook URL)
private $discord_webhook_url = 'https://discord.com/api/webhooks/123/w3bh00k_t0k3n';
// ntfy.sh webhook URL (replace with your ntfy.sh URL)
private $ntfy_webhook_url = 'https://ntfy.sh/miles-cool-plugin-update-demo';
public function __construct() {
add_action('set_site_transient_update_plugins', [$this, 'check_plugin_updates']);
}
public function check_plugin_updates($transient) {
if (empty($transient->response)) {
return;
}
$updates_available = [];
foreach ($transient->response as $plugin_file => $plugin_data) {
$plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_file);
$updates_available[] = $plugin_info['Name'] . ' (' . $plugin_info['Version'] . ' → ' . $plugin_data->new_version . ')';
}
if (!empty($updates_available)) {
$message = "Plugin updates available:\n\n" . implode("\n", $updates_available);
$this->send_notification($message);
}
}
private function send_notification($message) {
switch ($this->notification_method) {
case 'email':
$this->send_email($message);
break;
case 'discord':
$this->send_discord($message);
break;
case 'ntfy':
$this->send_ntfy($message);
break;
}
}
private function send_email($message) {
$subject = 'Plugin Updates Available';
$admin_email = get_option('admin_email');
wp_mail($admin_email, $subject, $message);
}
private function send_discord($message) {
$payload = json_encode([
'username' => 'WP Plugin Notifier',
'content' => $message
]);
wp_remote_post($this->discord_webhook_url, [
'headers' => ['Content-Type' => 'application/json'],
'body' => $payload,
'timeout' => 10,
]);
}
private function send_ntfy($message) {
wp_remote_post($this->ntfy_webhook_url, [
'body' => $message,
'timeout' => 10,
]);
}
}
new Plugin_Update_Notifications();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment