Send Gravity Forms Notifications to the Page Author
Sends the admin notification of a Gravity Forms form to the author of the post or page the form was submitted from, ideal for agent, listing or staff profile pages.
Opens WPIDE on
Code
$wpide_gf_author_notifications = array( 'Admin Notification' ); // Notification names to reroute.
add_filter( 'gform_notification', function ( $notification, $form, $entry ) use ( $wpide_gf_author_notifications ) {
if ( ! in_array( rgar( $notification, 'name' ), $wpide_gf_author_notifications, true ) ) {
return $notification;
}
$post_id = url_to_postid( (string) rgar( $entry, 'source_url' ) );
$post = $post_id ? get_post( $post_id ) : null;
$author = $post ? get_userdata( (int) $post->post_author ) : false;
if ( $author && is_email( $author->user_email ) ) {
$notification['toType'] = 'email';
$notification['to'] = $author->user_email;
}
return $notification;
}, 10, 3 );
Notes
Only notifications named in the list at the top are changed; the original recipient is used when the author has no email.
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.