user_email` is read in thousands of places across the ecosystem, * usually without a null check, so an account with an empty one leaves * warnings and blank "From" headers scattered through other people's code. * An account created before this fork was installed, or by a plugin calling * `wp_insert_user()` directly, can have exactly that. * * Runs late so a plugin that supplies a real address wins. */ add_filter( 'wp_pre_insert_user_data', function ( $data, $update, $user_id ) { if ( ! class_exists( 'SP_Identity' ) ) { return $data; } if ( ! empty( $data['user_email'] ) ) { return $data; } $address = $user_id ? SP_Identity::address_of( (int) $user_id ) : ''; $data['user_email'] = SP_Identity::stub_email( $address ); return $data; }, 20, 3 ); /** * Stop core nagging about an unconfirmed administrator email change. * * The "Your admin email is still , please confirm" prompt sends a * confirmation link to an address that cannot receive it, which makes the * prompt permanent and unactionable. */ add_filter( 'admin_email_check_interval', '__return_zero' ); /** * WooCommerce. * * Its setup wizard and its system-status report both read the store address * out of `woocommerce_email_from_address`, and the onboarding profiler posts * to a remote service with it. Supplying the placeholder lets the wizard * finish; order emails to real customers are unaffected, because those use * the address the customer typed at checkout. */ add_filter( 'pre_option_woocommerce_email_from_address', function ( $value ) { if ( ! empty( $value ) || ! class_exists( 'SP_Settings' ) ) { return $value; } return 'shop@' . SP_Settings::stub_email_domain(); } ); /** * Contact Form 7. * * CF7 validates a form's mail template on save and marks the form as * misconfigured if the "To" address is empty, which it will be on a site with * no admin email. The placeholder makes new forms save cleanly; a site owner * who wants the form to actually deliver replaces it with a real address and * configures SMTP, which is documented in docs/smtp.md. */ add_filter( 'wpcf7_default_template', function ( $template, $prop ) { if ( 'mail' !== $prop || ! is_array( $template ) || ! class_exists( 'SP_Settings' ) ) { return $template; } if ( empty( $template['recipient'] ) ) { $template['recipient'] = 'admin@' . SP_Settings::stub_email_domain(); } return $template; }, 10, 2 ); /* * Note on is_email(): no filter is needed. * * It would be reasonable to assume WordPress rejects a `.invalid` address, * since RFC 2606 reserves that TLD precisely so it can never resolve — and an * earlier version of this file carried a filter to force such addresses * through on that assumption. The assumption is wrong. `is_email()` validates * syntax, not whether a domain could ever exist, so `noreply@…​.invalid` * already passes and the filter never fired. * * Leaving it in would have been worse than useless: a filter that appears to * relax a validation rule, but does not, is exactly the kind of thing someone * later reasons from. Verified against WordPress 7.1.1. */ /** * A short explanation on the plugins screen, next to anything known to want * an address. Better a sentence here than a confused hour later. */ add_action( 'after_plugin_row', function ( $plugin_file ) { static $notes = array( 'woocommerce/woocommerce.php' => 'WooCommerce will work, including checkout. Order emails need SMTP — see docs/smtp.md.', 'contact-form-7/wp-contact-form-7.php' => 'Forms save and submit. Delivery needs SMTP and a real recipient address — see docs/smtp.md.', 'wordpress-seo/wp-seo.php' => 'Yoast works unchanged. Its sitemaps are exported to your name along with everything else.', ); if ( ! isset( $notes[ $plugin_file ] ) || ! is_plugin_active( $plugin_file ) ) { return; } printf( '

%s

', esc_html( $notes[ $plugin_file ] ) ); } );