-
Notifications
You must be signed in to change notification settings - Fork 17
Don't send comment emails to disabled users #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
I have an idea for a different approach for this @shawnhooper and you can tell me what you think. I think a better solution would be to apply this globally. By this, I mean if a user is disabled, they should never receive emails, regardless of the source. The comments email (addressed in the PR) is the obvious use case, but I think given other core emails along with plugins that may be activated on the site, a better approach would be to do this on a site-wide level. What I envision this entailing:
This method would, at least in theory, prevent the disabled user(s) from ever getting an email regardless of the source. Definitely open to feedback. |
@jaredatch In theory, I agree with your idea, filtering wp_mail() would be really easy to do, and would stop all email being sent out as long as the plugins were coded to use wp_mail(). My only hesitation would be a case, where, for example, a left a company's web content team, and therefore had their account disabled. But they still work there, and should be receiving the results from a feedback form on the website. This approach would block that email. The solution would be of course just to lower that user's account to Subscriber role or something like that. Thoughts? |
I think that scenario, while possible, is more edge case than the chance of disabled users getting unwanted emails that are sent from non-comment sources. So IMO it's worth proceeding with the risk of that possibly happening. I also agree with that you said - at that point changing the user to subscriber would definitely make more sense. I'm not sure how useful it would be (because I can't really think of a good use case at this moment) but we could always wrap the accounts returned from |
Ooh, I love that combined wp_mail & disabled users filter idea. It would solve both of our concerns. |
@jaredatch I've implemented the changes we discussed. Rather get create a get_disabled_users function, I went with a get_disabled_users_email_addresses function. Since that's what we're dealing with when it comes to wp_mail it was streamlined and easy to do an array_diff on rather than having an array of WP_User objects. |
@shawnhooper thanks! The only thing missing I see which I would like, is the disabled users should be cached in an option. Then when a user is disabled, enabled, or deleted, the option should be updated. The logic behind this is for site performance. On large sites the frequency of Running the query one time, storing the results in an option, then simply maintaining that option after that will allow us to avoid possible performance issues. The options are already autoloaded anyways, so anytime (after the initial build) that a mail fires off and we reference the disabled users, it should be pretty much instant. You've already contributed a ton (thanks!) so I have no problem at all making this adjustment after merging the PR, I just wanted to let you know what my intentions are :) |
@jaredatch Good call, as this data won't change frequently. If you accept the PR for the adding hooks to the plugin, I've already modified the code that saves the Disabled state so that it only updates when a change has been made. This would be a good spot to put the code that resets the option value. You'd also need to trigger it if their email address changes, since the option would contain their email addresses. Cheers. |
This plugin addresses issue #5.
In the process, I also created a generic is_user_disabled() function that checks the usermeta value. This was being done in two places already, and this PR added a third.
(Same PR as submitted yesterday, I just moved this to a branch in my fork so I could work on some other PRs)