Created
November 20, 2023 17:13
-
-
Save dougkeeling/1b5e05c843d8b0b23c5c167b8d7954e6 to your computer and use it in GitHub Desktop.
[Set default "To", "From", "From Name" for Gravity Forms notifications] #wordpress #php #gravityforms #ACF
This file contains 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 the default notification email address for new forms | |
// ------------------------------------------------------------------------------ | |
add_action( 'gform_after_save_form', 'rkt_set_default_notification_to', 10, 2 ); | |
function rkt_set_default_notification_to( $form, $is_new ) { | |
// Using an ACF options field to allow the user to set this. | |
$admin_email = get_field( 'default_admin_email', 'option' ); | |
if ( $is_new ) { | |
foreach ( $form['notifications'] as &$notification ) { | |
if($admin_email) { | |
$notification['to'] = $admin_email; | |
} | |
$notification['from'] = '[email protected]'; | |
$notification['fromName'] = 'Site Name'; | |
} | |
$form['is_active'] = '1'; | |
GFAPI::update_form( $form ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment