fix(alerts): stop non-stop email alerts - #2007
Open
faisalahammad wants to merge 1 commit into
Open
Conversation
Throttle email alerts to one send per 5 minutes per alert, and remove alert configuration, options, and scheduled jobs on plugin uninstall. Repeating matching records no longer flood the inbox, and deleting the plugin no longer leaves enabled alerts behind to fire again. Fixes xwp#1855
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1855.
Email alerts fired on every matching record with no limit. A user whose alert matched routine settings records received an email every few minutes on every page load, and deleting the alerts or the plugin did not stop it: alert posts survived deletion because the plugin ships no uninstall routine (data removal was disabled in 3.9.3), so a reinstall brought the old alerts back.
Repro: create an email alert on Settings > Updated, then change any whitelisted setting the way a plugin does on page load. Stream inserts a matching record per request and
Alert_Type_Email::alert()callswp_mail()for each one. Trash or delete the alert, then deactivate and delete the plugin, and emails stop only until the alert post is found in the database again on the next install.This PR adds a per-alert send throttle and restores cleanup on plugin deletion.
Changes
alerts/class-alert-type-email.phpBefore:
After:
Why: one email per alert per 300 seconds bounds the flood while the trigger keeps matching. The interval is filterable with the new
wp_stream_alert_email_throttlefilter,0restores the old per-record behavior. The last-sent time lives in a separate_wp_stream_email_last_sentpost meta key, so it does not appear inalert_metaoutput such as thestream/get-alertsability.uninstall.php(new)Why: deleting the plugin now removes all
wp_stream_alertsposts on every site of a network, Stream options per site and network site options (wp_stream,wp_stream_network,wp_stream_db*), Stream user meta, and the WP-Cron and Action Scheduler purge/reset events. Deletes use core APIs (wp_delete_post,delete_option,delete_user_meta,delete_site_option) so hooks and object caches stay consistent; a reinstall can no longer resurrect old alerts. Thewp_streamandwp_streammetalog tables are kept, following the data-removal decision from 3.9.3.One note for the reporter of #1855: the cleanup runs when the fixed version is deleted from the Plugins screen. A site already affected by 4.1.2 needs one reinstall-then-delete cycle to clear the leftover alert posts.
Testing
Automated:
Test_Alert_Type_Emailcovers: send allowed with no prior email, blocked within the interval, allowed after the interval,0interval sends every time, and one real send per window through a mocked mailer.npm run test:php,npm run test:php-multisite).npm run lint:phpandnpm run lint:php-tests: 0 errors.Manual:
Checklist
contributing.md).Release Changelog
wp_stream_alert_email_throttlefilter to change or disable the interval.Release Checklist
masterbranch.readme.txt.stream.php.Stable taginreadme.txt.classes/class-plugin.php.Change
[ ]to[x]to mark the items as done.