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 ); /** * Plugins that check "is this a real email?" during their own setup. * * `is_email()` correctly rejects a `.invalid` address — the domain is * reserved precisely so that it fails. That correctness is a problem for a * setup wizard that refuses to advance, so `.invalid` addresses under *this * site's own* placeholder domain are allowed through, and nothing else is. * Narrowing it to our own domain matters: a contact form that accepts * `someone@example.invalid` from a visitor would silently collect addresses * that can never be replied to. */ add_filter( 'is_email', function ( $is_email, $email ) { if ( $is_email || ! class_exists( 'SP_Settings' ) ) { return $is_email; } $domain = '@' . strtolower( SP_Settings::stub_email_domain() ); if ( substr( strtolower( (string) $email ), -strlen( $domain ) ) !== $domain ) { return $is_email; } // Same local-part rules core applies, minus the domain check it fails. $local = substr( (string) $email, 0, strlen( (string) $email ) - strlen( $domain ) ); return (bool) preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.\-]+$/', $local ); }, 10, 2 ); /** * 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 ] ) ); } );