{"id":46601,"date":"2026-09-30T08:02:28","date_gmt":"2026-09-30T08:02:28","guid":{"rendered":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/?p=46601"},"modified":"2026-10-10T20:03:41","modified_gmt":"2026-10-10T20:03:41","slug":"wordpress-security-updates-email-alert","status":"publish","type":"post","link":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wordpress-security-updates-email-alert\/","title":{"rendered":"WordPress Security Updates Email Alert Without a Plugin"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">WordPress security releases now get attacked within hours. After the recent core security release, attackers were probing sites the same day the patch shipped. If you look after client sites, or if you\u2019ve hidden update notices from editors, you can easily miss a pending update for days. WordPress only emails you after it runs a background auto-update. It doesn\u2019t email you when an update is waiting for you to install it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This snippet emails the site admin when a core, plugin or theme update is pending. It lists each item with its installed and new versions and links to <strong>Dashboard \u2192 Updates<\/strong>. It sends one email per new set of updates, not one every day, so people keep reading it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The snippet<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Save this as <code>wp-content\/mu-plugins\/dpc-update-alerts.php<\/code>. Using an mu-plugin means nobody can deactivate it from the Plugins screen. It also works in a normal plugin, your theme\u2019s <code>functions.php<\/code> or Scripts Organizer (see below).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\/**\n * Plugin Name: DPC Update Alerts\n * Description: Emails the site admin once when core, plugin or theme updates are pending.\n *\/\n\ndefined( 'ABSPATH' ) || exit;\n\nadd_action( 'init', 'dpc_update_alert_schedule' );\nfunction dpc_update_alert_schedule(): void {\n\tif ( ! wp_next_scheduled( 'dpc_update_alert_check' ) ) {\n\t\twp_schedule_event( time() + HOUR_IN_SECONDS, 'twicedaily', 'dpc_update_alert_check' );\n\t}\n}\n\nadd_action( 'dpc_update_alert_check', 'dpc_update_alert_run' );\n\n\/**\n * Collect pending updates from the transients WordPress already maintains.\n *\n * @return string&#91;&#93; One human-readable line per pending update.\n *\/\nfunction dpc_update_alert_pending(): array {\n\t$items = array();\n\n\t$core = get_site_transient( 'update_core' );\n\tif ( isset( $core-&gt;updates ) &amp;&amp; is_array( $core-&gt;updates ) ) {\n\t\tforeach ( $core-&gt;updates as $offer ) {\n\t\t\tif ( isset( $offer-&gt;response, $offer-&gt;current ) &amp;&amp; 'upgrade' === $offer-&gt;response ) {\n\t\t\t\t$items&#91;&#93; = sprintf( 'WordPress core: %s -&gt; %s', get_bloginfo( 'version' ), $offer-&gt;current );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t$plugins = get_site_transient( 'update_plugins' );\n\tif ( ! empty( $plugins-&gt;response ) &amp;&amp; is_array( $plugins-&gt;response ) ) {\n\t\tif ( ! function_exists( 'get_plugins' ) ) {\n\t\t\trequire_once ABSPATH . 'wp-admin\/includes\/plugin.php';\n\t\t}\n\t\t$installed = get_plugins();\n\t\tforeach ( $plugins-&gt;response as $file =&gt; $data ) {\n\t\t\t$data    = (object) $data;\n\t\t\t$name    = $installed&#91; $file &#93;&#91;'Name'&#93; ?? ( $data-&gt;slug ?? $file );\n\t\t\t$current = $installed&#91; $file &#93;&#91;'Version'&#93; ?? '?';\n\t\t\t$items&#91;&#93; = sprintf( 'Plugin %s: %s -&gt; %s', $name, $current, $data-&gt;new_version ?? '?' );\n\t\t}\n\t}\n\n\t$themes = get_site_transient( 'update_themes' );\n\tif ( ! empty( $themes-&gt;response ) &amp;&amp; is_array( $themes-&gt;response ) ) {\n\t\tforeach ( $themes-&gt;response as $stylesheet =&gt; $data ) {\n\t\t\t$data    = (array) $data;\n\t\t\t$theme   = wp_get_theme( $stylesheet );\n\t\t\t$name    = $theme-&gt;exists() ? $theme-&gt;get( 'Name' ) : $stylesheet;\n\t\t\t$current = $theme-&gt;exists() ? $theme-&gt;get( 'Version' ) : '?';\n\t\t\t$items&#91;&#93; = sprintf( 'Theme %s: %s -&gt; %s', $name, $current, $data&#91;'new_version'&#93; ?? '?' );\n\t\t}\n\t}\n\n\treturn array_map( 'wp_strip_all_tags', $items );\n}\n\n\/**\n * Email the pending list, but only when it differs from the last email.\n *\n * @return bool True when an email was sent.\n *\/\nfunction dpc_update_alert_run(): bool {\n\t$items = dpc_update_alert_pending();\n\n\tif ( ! $items ) {\n\t\tdelete_option( 'dpc_update_alert_last' );\n\t\treturn false;\n\t}\n\n\t$fingerprint = md5( implode( '|', $items ) );\n\tif ( get_option( 'dpc_update_alert_last' ) === $fingerprint ) {\n\t\treturn false;\n\t}\n\n\t$recipients = (array) apply_filters( 'dpc_update_alert_recipients', array( get_option( 'admin_email' ) ) );\n\t$recipients = array_filter( array_map( 'sanitize_email', $recipients ), 'is_email' );\n\tif ( ! $recipients ) {\n\t\treturn false;\n\t}\n\n\t$site    = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );\n\t$subject = sprintf( '&#91;%s&#93; %d update(s) waiting', $site, count( $items ) );\n\t$body    = sprintf(\n\t\t'Pending updates on %1$s:%2$s%2$s- %3$s%2$s%2$sReview and install them: %4$s',\n\t\thome_url( '\/' ),\n\t\tPHP_EOL,\n\t\timplode( PHP_EOL . '- ', $items ),\n\t\tadmin_url( 'update-core.php' )\n\t);\n\n\t$sent = wp_mail( $recipients, $subject, $body );\n\tif ( $sent ) {\n\t\tupdate_option( 'dpc_update_alert_last', $fingerprint, false );\n\t}\n\n\treturn $sent;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Add it with Scripts Organizer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/dplugins.com\/downloads\/scripts-organizer\/\">Scripts Organizer<\/a> go to <strong>Code Blocks \u2192 Add New<\/strong> and give the block a name. Set <strong>Trigger location<\/strong> to <strong>Everywhere<\/strong>, tick <strong>PHP<\/strong> under <strong>Script location<\/strong>, paste the code into the PHP editor and publish. Leave <strong>Action\/Hook<\/strong> empty. <strong>Everywhere<\/strong> is needed because WP-Cron runs the check in a background request to <code>wp-cron.php<\/code>, which is neither wp-admin nor a front-end page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The plugin header comment is harmless there. If you switch the code block off later, the scheduled event stays in WP-Cron without a callback and does nothing; remove it with <code>wp cron event delete dpc_update_alert_check<\/code> if you want a clean list.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How it works<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>WordPress already checks WordPress.org for updates about twice a day. It stores the results in the <code>update_core<\/code>, <code>update_plugins<\/code> and <code>update_themes<\/code> site transients. The snippet only reads those transients, so it makes no extra HTTP requests.<\/li>\n\n\n<li><code>dpc_update_alert_schedule()<\/code> registers a <code>twicedaily<\/code> WP-Cron event, the same interval as the core check.<\/li>\n\n\n<li><code>dpc_update_alert_pending()<\/code> turns the transients into one line per item, such as <code>Plugin Contact Form: 5.9.1 -&gt; 5.9.2<\/code>. It gets names and installed versions from <code>get_plugins()<\/code> and <code>wp_get_theme()<\/code>, and strips tags in case a header contains markup.<\/li>\n\n\n<li><code>dpc_update_alert_run()<\/code> hashes the list and saves the hash in a non-autoloaded option. It sends an email only when the hash changes. When everything is up to date, it deletes the option, so the next update triggers a new email.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Customise it<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To send the alert to an agency inbox instead of, or as well as, the admin email, add this filter:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_filter( 'dpc_update_alert_recipients', function ( array $to ): array {\n\t$to&#91;&#93; = 'alerts@example.com';\n\treturn $to;\n} );<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For faster alerts, change <code>twicedaily<\/code> to <code>hourly<\/code>. The data only changes when WordPress runs its own update check.<\/li>\n\n\n<li>To send a daily reminder until updates are installed, remove the fingerprint check.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Gotchas<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>WP-Cron only runs when someone visits the site. On low-traffic sites, set <code>DISABLE_WP_CRON<\/code> and call <code>wp-cron.php<\/code> from a real server cron job.<\/li>\n\n\n<li>The update data doesn\u2019t say which releases are security fixes. For official announcements, follow the <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/wordpress.org\/news\/category\/security\/\">Security category on WordPress.org News<\/a>, which has its own RSS feed.<\/li>\n\n\n<li>If a vulnerable plugin has no fix yet, deactivating it is usually safer than waiting. This alert tells you the fix has shipped.<\/li>\n\n\n<li>If you used <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/disable-wordpress-core-plugins-and-themes-updates-and-admin-notices\/\">Disable WordPress core, plugins and themes updates<\/a> to block update checks, the transients stay empty and this snippet never sends anything. If you only hid the admin notices, it still works.<\/li>\n\n\n<li>In a normal plugin, clear the event on deactivation with <code>wp_clear_scheduled_hook( 'dpc_update_alert_check' )<\/code>.<\/li>\n\n\n<li>For another admin email built the same way, see <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/notify-admin-when-new-account-is-created\/\">Notify Admin When New Account Is Created<\/a>.<\/li>\n\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>Get one email when WordPress core, plugin or theme updates are waiting, and no repeat emails until the list changes. A small mu-plugin, no extra plugin.<\/p>\n","protected":false},"author":1,"featured_media":46770,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"WordPress Security Updates Email Alert Without a Plugin","description":"Get one email when WordPress core, plugin or theme updates are waiting, and no repeat emails until the list changes. A small mu-plugin, no extra plugin."},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"footnotes":""},"categories":[130,3],"tags":[148,144,145,147,146],"dpc_library":[204],"class_list":["post-46601","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-security","category-wordpress","tag-mu-plugin","tag-security","tag-updates","tag-wp_mail","tag-wp-cron"],"_links":{"self":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/comments?post=46601"}],"version-history":[{"count":2,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46601\/revisions"}],"predecessor-version":[{"id":46769,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46601\/revisions\/46769"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media\/46770"}],"wp:attachment":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media?parent=46601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/categories?post=46601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/tags?post=46601"},{"taxonomy":"dpc_library","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/dpc_library?post=46601"}],"curies":[{"name":"wp","href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}