Created
December 18, 2013 20:58
-
-
Save BFTrick/8029740 to your computer and use it in GitHub Desktop.
Automatically change the from address in the admin email notifications for Ninja Form forms.
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
<?php | |
/** | |
* Plugin Name: Ninja Forms - Change From Address | |
* Plugin URI: https://gist.github.com/BFTrick/8029740 | |
* Description: Automatically change the from address in the admin email notifications from Ninja Forms | |
* Author: Patrick Rauland | |
* Author URI: http://patrickrauland.com/ | |
* Version: 1.0 | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
* | |
*/ | |
/** | |
* Automatically change the from address in the admin notification email | |
* | |
* @return void | |
* @since 1.0 | |
*/ | |
function patricks_nf_change_from_address(){ | |
global $ninja_forms_processing; | |
// set up some defaults | |
$user_name = ""; | |
$user_email = ""; | |
// get fields | |
$all_fields = $ninja_forms_processing->get_all_fields(); | |
if ( ! empty ( $all_fields ) ) { | |
foreach ( $all_fields as $key => $value ) { | |
// get the field | |
$field = ninja_forms_get_field_by_id( $key ); | |
// get name & email | |
if ( $field['data']['first_name'] ) { | |
$user_name = $value . " " . $user_name; | |
} | |
if ( $field['data']['last_name'] ) { | |
$user_name = $user_name . " " . $value; | |
} | |
if ( $field['data']['email'] ) { | |
$user_email = $value; | |
} | |
} | |
// trim the name in case we added too many spaces | |
$user_name = trim( $user_name ); | |
} | |
// if we have an email or a name then set them | |
if ( ! empty ( $user_email ) ) { | |
$ninja_forms_processing->update_form_setting( 'email_from', $user_email ); | |
} | |
if ( ! empty ( $user_name ) ) { | |
$ninja_forms_processing->update_form_setting( 'email_from_name', $user_name ); | |
} | |
} | |
add_action( 'ninja_forms_email_admin', 'patricks_nf_change_from_address' ); | |
// That's all folks! |
Hi
Thanks for this helpful plugin but it is changing the from email for the user as well not just the administrator email .. how can I keep the " From Email Address " set in the form settings in the email sent to the user ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
This seems like something that could be really useful to me but I cant get my page to call it? Am I missing some command somewhere that is needed to call custom plugins?
Wordpress Beginner :)
Thanks