username from login in contact form
We use WordPress for an internal intranet with login for each user.
Is it possible to show and post the username in the contact form.
If possible, this field should be readonly
This is our free support forum. Replies can take several days.
Need fast email support? Get SiteOrigin Premium
Replies
1Hi,
Thanks for getting in touch. We don’t directly have a field that allows for this at this time. We can assist you with doing this over premium support by coming up with a snippet that allows for this. If that’s something you would be interested in, check SiteOrigin Premium.
Alternatively, you can include the submitter’s username as a mail header – which can be viewed by viewing the email source. That can be done by adding the following PHP to your website:
function add_username_to_email_headers( $headers, $form_data, $instance ) { if ( is_user_logged_in() ) { $current_user = wp_get_current_user(); // Get the current user object $username = $current_user->user_login; // Get the username from the user object // Add the username to the email headers $headers .= 'X-Username: ' . $username . "\r\n"; } return $headers; } add_filter( 'siteorigin_widgets_contact_form_email_headers', 'add_username_to_email_headers', 10, 3 );If you need a method of adding PHP, you can use the Code Snippets plugin.
Kind regards,
Alex
Replies on this thread are closed.
Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.