Created
May 25, 2023 14:55
-
-
Save 465media/17664b045de75deafcb2b99695d22df9 to your computer and use it in GitHub Desktop.
Set default "From Email" for Gravity Forms notifications using WordPress domain.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Set default "From Email" for Gravity Forms notifications using WordPress domain. | |
*/ | |
function override_gravityforms_from_email( $email, $notification ) { | |
// Get the WordPress site URL and extract the domain. | |
$site_url = get_site_url(); | |
$parsed_url = parse_url( $site_url ); | |
$domain = isset( $parsed_url['host'] ) ? $parsed_url['host'] : ''; | |
if ( isset( $email['from'] ) && $email['from'] === '{admin_email}' ) { | |
$email['from'] = 'no-reply@' . $domain; | |
} | |
return $email; | |
} | |
add_filter( 'gform_notification', 'override_gravityforms_from_email', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@clubdeuce we should be adding something like this to all our builds.