a8cteam51 / safety-net

Scrub options, deactivate denylisted plugins, and delete user data on development sites.
17 stars 1 forks source link

Change filter to `pre_wp_mail` #85

Closed fmfernandes closed 1 year ago

fmfernandes commented 1 year ago

Safety Net was throwing a fatal:

[02-Mar-2023 19:01:47 UTC] PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function SafetyNet\Admin\stop_emails(), 1 passed in /wp/wp-includes/class-wp-hook.php on line 308 and exactly 2 expected in /plugins/safety-net/includes/admin.php:416

We changed from using wp_mail to pre_wp_mail on #71 but looks like it was moved back to wp_mail on #68.

The filter then became add_filter( 'wp_mail', __NAMESPACE__ . '\stop_emails', 10, 1 ); but the stop_emails function expects two parameters.

Testing instructions

You can try to send an email when Safety Net is active:

add_action( 'init', function() {
    wp_mail( 'test@example.com', 'subject', 'message' );
} );

Before applying this patch, a fatal will be shown. Checking debug.log where Safety Net should log it's email blocked message will not be present as well.

After applying this patch, the email should be properly blocked and the log entry Email blocked: subject will be present on the file.

NickGreen commented 1 year ago

Good catch. We both agree that it was changed back accidentally. LGTM, feel free to merge.