from-setting-check.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /*
  3. *
  4. * Function that checks to see if we've properly removed the old "From Email" setting and replaced it with "From Name" and "From Email."
  5. *
  6. * @since 2.3
  7. * @return void
  8. */
  9. function ninja_forms_check_email_from_name() {
  10. $plugin_settings = nf_get_settings();
  11. // Check to see if we've already fixed the setting.
  12. if ( !isset ( $plugin_settings['fix_form_email_from'] ) or $plugin_settings['fix_form_email_from'] != 1 ) {
  13. // Get our forms.
  14. $forms = ninja_forms_get_all_forms();
  15. if ( is_array ( $forms ) ) {
  16. foreach( $forms as $form ) {
  17. // Check to see if we've already added the "from_email_name."
  18. if ( !isset ( $form['data']['email_from_name'] ) and isset ( $form['data']['email_from'] ) ) {
  19. // This field doesn't have an "email_from_name" saved, so we'll run it through the adjustment function.
  20. $email_from = ninja_forms_split_email_from( $form['data']['email_from'] );
  21. $form['data']['email_from'] = $email_from['email_from'];
  22. $form['data']['email_from_name'] = $email_from['email_from_name'];
  23. $args = array(
  24. 'update_array' => array(
  25. 'data' => serialize( $form['data'] ),
  26. ),
  27. 'where' => array(
  28. 'id' => $form['id'],
  29. ),
  30. );
  31. ninja_forms_update_form($args);
  32. }
  33. }
  34. }
  35. $plugin_settings['fix_form_email_from'] = 1;
  36. update_option( 'ninja_forms_settings', $plugin_settings );
  37. }
  38. }
  39. add_action( 'init', 'ninja_forms_check_email_from_name' );
  40. /*
  41. *
  42. * Function that looks at our "Email From" setting and breaks it up into "Name" and "Email."
  43. *
  44. * @since 2.3
  45. * @return $tmp_array array
  46. */
  47. function ninja_forms_split_email_from( $email_from ) {
  48. $pat = '/\<([^\"]*?)\>/'; // text between quotes excluding quotes
  49. $value = $email_from;
  50. $tmp_array = array();
  51. if( preg_match( $pat, $value, $matches ) ) {
  52. $arr = explode("<", $email_from, 2);
  53. $tmp_array['email_from_name'] = $arr[0];
  54. $tmp_array['email_from'] = $matches[1];
  55. } else {
  56. $tmp_array['email_from_name'] = '';
  57. $tmp_array['email_from'] = $email_from;
  58. }
  59. return $tmp_array;
  60. }