code-snippets
code-snippets copied to clipboard
Not able to get this specific code snippet to work.
Hey
Here is a code snippet that should work with the Code Snippet plugin, but I have yet been able to get it to work.
The snippet should stop all the success e-mails when a plugin has been auto updated.
add_filter( 'auto_plugin_update_send_email', 'plugin_update_email_on_failure', 10, 2 );
/**
* Sends plugin update emails only when at least one plugin update has failed.
*
* @param bool $enabled Whether the plugin update email is enabled.
* @param array $update_results An array of update results.
* @return bool
*/
function plugin_update_email_on_failure( $enabled, $update_results ) {
foreach ( $update_results as $update_result ) {
if ( true !== $update_result->result ) {
return true;
}
}
return false;
}
See the WordPress Slack channel for Core-Auto-updates. https://wordpress.slack.com/archives/CULBN711P/p1656468319331729
Hi @paaljoachim,
Have you confirmed that this snippet works by adding through an alternative method? Is it just through Code Snippets that it stops working?
Hey @sheabunge
I mentioned this on Slack July 4th. https://wordpress.slack.com/archives/CULBN711P/p1656891048463909 paaljoachim I will run the code snippet in the "Run snippet everywhere" option. I am testing out the snippet using the code snippet plugin.
afragen I don't know how the code snippet plugin works but it might cause the filter to run too late.
Hey Andy It (plugin options) has auto set a priority of 10. I can change that number.
afragen My point is there is now one additional potential point of failure. Try running the plugin as a plugin.
I have gone ahead and I am currently testing the plugin mentioned on Slack of the same code. https://gist.github.com/afragen/e2f40ed2e71e590a127e8adc1db05948
I will update this issue when I know more.
Sounds good, please keep us updated. For reference, snippets run on the plugins_loaded
hook, so anything earlier than that is unfortunately inaccessible.
I added this plugin: https://gist.github.com/afragen/e2f40ed2e71e590a127e8adc1db05948 To a few sites and I have not noticed any success plugin e-mails from these. So from what I see the plugin works but for whatever reason the code snippet is not.
My conclusion is that for whatever reason the plugin does work but the code snippet does not.
Regarding:
For reference, snippets run on the plugins_loaded hook, so anything earlier than that is unfortunately inaccessible.
Will a plugin run earlier compared to a code snippet?
Lately the code snippet has been working. Which is of course great to see! I do not know why it did not work initially for the various sites I used it on.
I will continue using the code snippet over another period to see that it continue working. I will leave this issue open a little longer. Then close it.
It seems to now be working nicely, so that I will close this issue.
Thank you for checking back and confirming. Glad to hear that it is sorted now, though it's strange that it seems to have started working without any intervention on our part.
I agree. I do not know if there was something with the cache (I many times blame the cache for weirdness) or something else.