Email.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /**
  3. * Class NF_Fields_Email
  4. */
  5. class NF_Fields_Email extends NF_Abstracts_UserInfo
  6. {
  7. protected $_name = 'email';
  8. protected $_nicename = 'Email';
  9. protected $_type = 'email';
  10. protected $_section = 'userinfo';
  11. protected $_icon = 'envelope-o';
  12. protected $_templates = 'email';
  13. protected $_test_value = 'foo@bar.dev';
  14. protected $_settings_all_fields = array( 'custom_name_attribute', 'personally_identifiable' );
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. $this->_nicename = __( 'Email', 'ninja-forms' );
  19. $this->_settings[ 'custom_name_attribute' ][ 'value' ] = 'email';
  20. $this->_settings[ 'personally_identifiable' ][ 'value' ] = '1';
  21. }
  22. public function filter_default_value( $default_value, $field_class, $settings )
  23. {
  24. if( ! isset( $settings[ 'default_type' ] ) ||
  25. 'user-meta' != $settings[ 'default_type' ] ||
  26. $this->_name != $field_class->get_name()) return $default_value;
  27. $current_user = wp_get_current_user();
  28. if( $current_user ){
  29. $default_value = $current_user->user_email;
  30. }
  31. return $default_value;
  32. }
  33. }