Send WPForms Notifications to the Page Author
Sends WPForms notifications to the author of the post or page where the form was filled in, for agent, listing or team profile pages.
Opens WPIDE on
Code
$wpide_wpf_author_forms = array(); // Form IDs, e.g. array( 1 ).
add_filter( 'wpforms_entry_email_atts', function ( $email, $fields, $entry, $form_data ) use ( $wpide_wpf_author_forms ) {
if ( ! in_array( (int) $form_data['id'], array_map( 'intval', $wpide_wpf_author_forms ), true ) ) {
return $email;
}
$page_id = isset( $_POST['page_id'] ) ? absint( $_POST['page_id'] ) : url_to_postid( (string) wp_get_referer() );
$post = $page_id ? get_post( $page_id ) : null;
$author = $post ? get_userdata( (int) $post->post_author ) : false;
if ( $author && is_email( $author->user_email ) ) {
$email['address'] = array( $author->user_email );
}
return $email;
}, 10, 4 );
Notes
Limit it to forms in the list at the top; the original recipients are used when the page cannot be found.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.