Skip to content

Instantly share code, notes, and snippets.

@dougkeeling
Created November 20, 2023 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dougkeeling/1b5e05c843d8b0b23c5c167b8d7954e6 to your computer and use it in GitHub Desktop.
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
// 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'] = 'info@domain.com';
$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