By default, MailPoet doesn’t do this. Here is a workaround if you are very keen on doing this.
The Approach
MailPoet renders its signup forms via a shortcode or block. You can hook into WordPress to inject the logged-in user’s email into the form field using a bit of JavaScript (or PHP + JS together).
Solution: Add Custom JavaScript via functions.php
Add this to your theme’s functions.php (or a site-specific plugin):
php:
add_action( 'wp_footer', function () { if ( ! is_user_logged_in() ) { return; } $current_user = wp_get_current_user(); $email = esc_js( $current_user->user_email ); ?> <script> document.addEventListener('DOMContentLoaded', function () { // MailPoet form email fields use this selector var emailFields = document.querySelectorAll('.mailpoet_text[name="data[email]"]'); emailFields.forEach(function (field) { if (!field.value) { field.value = <?php echo json_encode( $current_user->user_email ); ?>; } }); }); </script> <?php} );
Why this works
- The email is fetched server-side in PHP (safe and reliable โ no client-side auth needed).
- The JS runs after the DOM loads and finds MailPoet’s email input (which uses the class
mailpoet_textandname="data[email]"). - The
if (!field.value)check means it only pre-fills if the field is empty, so it won’t override anything.
If you’re using the MailPoet Gutenberg Block (newer forms)
Newer MailPoet forms rendered as blocks may use slightly different markup. If the snippet above doesn’t work, check the rendered HTML of your form in browser DevTools and find the name attribute of the email input, then update the selector accordingly. Common alternatives:
php:
add_action( 'wp_footer', function () { if ( ! is_user_logged_in() ) { return; } $current_user = wp_get_current_user(); $email = esc_js( $current_user->user_email ); ?> <script> document.addEventListener('DOMContentLoaded', function () { // MailPoet form email fields use this selector var emailFields = document.querySelectorAll('input[type="email"]'); emailFields.forEach(function (field) { if (!field.value) { field.value = echo json_encode( $current_user->user_email ); ; } }); }); </script> } );
A note on security
Since the email comes from wp_get_current_user() on the server, there’s no risk of spoofing โ it’s always the actual logged-in user’s email. The user can still edit the field before submitting if they wish.