PodsField_Email

The Pods - Custom Content Types and Fields PodsField Email class.

Defined (1)

The class is defined in the following location(s).

/classes/fields/email.php  
  1. class PodsField_Email extends PodsField { 
  2.  
  3. /** 
  4. * Field Type Group 
  5. * @var string 
  6. * @since 2.0 
  7. */ 
  8. public static $group = 'Text'; 
  9.  
  10. /** 
  11. * Field Type Identifier 
  12. * @var string 
  13. * @since 2.0 
  14. */ 
  15. public static $type = 'email'; 
  16.  
  17. /** 
  18. * Field Type Label 
  19. * @var string 
  20. * @since 2.0 
  21. */ 
  22. public static $label = 'E-mail'; 
  23.  
  24. /** 
  25. * Field Type Preparation 
  26. * @var string 
  27. * @since 2.0 
  28. */ 
  29. public static $prepare = '%s'; 
  30.  
  31. /** 
  32. * Do things like register/enqueue scripts and stylesheets 
  33. * @since 2.0 
  34. */ 
  35. public function __construct () { 
  36.  
  37.  
  38. /** 
  39. * Add options and set defaults to 
  40. * @return array 
  41. * @since 2.0 
  42. */ 
  43. public function options () { 
  44. $options = array( 
  45. self::$type . '_repeatable' => array( 
  46. 'label' => __( 'Repeatable Field', 'pods' ),  
  47. 'default' => 0,  
  48. 'type' => 'boolean',  
  49. 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),  
  50. 'boolean_yes_label' => '',  
  51. 'dependency' => true,  
  52. 'developer_mode' => true 
  53. ),  
  54. self::$type . '_max_length' => array( 
  55. 'label' => __( 'Maximum Length', 'pods' ),  
  56. 'default' => 255,  
  57. 'type' => 'number',  
  58. 'help' => __( 'Set to -1 for no limit', 'pods' ) 
  59. ),  
  60. self::$type . '_html5' => array( 
  61. 'label' => __( 'Enable HTML5 Input Field?', 'pods' ),  
  62. 'default' => apply_filters( 'pods_form_ui_field_html5', 0, self::$type ),  
  63. 'type' => 'boolean' 
  64. )/**,  
  65. self::$type . '_size' => array( 
  66. 'label' => __( 'Field Size', 'pods' ),  
  67. 'default' => 'medium',  
  68. 'type' => 'pick',  
  69. 'data' => array( 
  70. 'small' => __( 'Small', 'pods' ),  
  71. 'medium' => __( 'Medium', 'pods' ),  
  72. 'large' => __( 'Large', 'pods' ) 
  73. )*/ 
  74. ); 
  75. return $options; 
  76.  
  77. /** 
  78. * Define the current field's schema for DB table storage 
  79. * @param array $options 
  80. * @return array 
  81. * @since 2.0 
  82. */ 
  83. public function schema ( $options = null ) { 
  84. $length = (int) pods_var( self::$type . '_max_length', $options, 255 ); 
  85.  
  86. $schema = 'VARCHAR(' . $length . ')'; 
  87.  
  88. if ( 255 < $length || $length < 1 ) 
  89. $schema = 'LONGTEXT'; 
  90.  
  91. return $schema; 
  92.  
  93. /** 
  94. * Customize output of the form field 
  95. * @param string $name 
  96. * @param mixed $value 
  97. * @param array $options 
  98. * @param array $pod 
  99. * @param int $id 
  100. * @since 2.0 
  101. */ 
  102. public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) { 
  103. $options = (array) $options; 
  104. $form_field_type = PodsForm::$field_type; 
  105.  
  106. if ( is_array( $value ) ) 
  107. $value = implode( ' ', $value ); 
  108.  
  109. $field_type = 'email'; 
  110.  
  111. if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) { 
  112. if ( pods_var( 'read_only', $options, false ) ) { 
  113. $options[ 'readonly' ] = true; 
  114.  
  115. $field_type = 'text'; 
  116. else 
  117. return; 
  118. elseif ( !pods_has_permissions( $options ) && pods_var( 'read_only', $options, false ) ) { 
  119. $options[ 'readonly' ] = true; 
  120.  
  121. $field_type = 'text'; 
  122.  
  123. pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) ); 
  124.  
  125. /** 
  126. * Build regex necessary for JS validation 
  127. * @param mixed $value 
  128. * @param string $name 
  129. * @param array $options 
  130. * @param string $pod 
  131. * @param int $id 
  132. * @return bool 
  133. * @since 2.0 
  134. */ 
  135. public function regex ( $value = null, $name = null, $options = null, $pod = null, $id = null ) { 
  136. return false; 
  137.  
  138. /** 
  139. * Validate a value before it's saved 
  140. * @param mixed $value 
  141. * @param string $name 
  142. * @param array $options 
  143. * @param array $fields 
  144. * @param array $pod 
  145. * @param int $id 
  146. * @param null $params 
  147. * @return array|bool 
  148. * @since 2.0 
  149. */ 
  150. public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) { 
  151. $errors = array(); 
  152.  
  153. $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params ); 
  154.  
  155. if ( is_array( $check ) ) 
  156. $errors = $check; 
  157. else { 
  158. if ( 0 < strlen( $value ) && strlen( $check ) < 1 ) { 
  159. $label = pods_var( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) ); 
  160.  
  161. if ( 1 == pods_var( 'required', $options ) ) 
  162. $errors[] = sprintf( __( '%s is required', 'pods' ), $label ); 
  163. else 
  164. $errors[] = sprintf( __( 'Invalid e-mail provided for %s', 'pods' ), $label ); 
  165.  
  166. if ( !empty( $errors ) ) 
  167. return $errors; 
  168.  
  169. return true; 
  170.  
  171. /** 
  172. * Change the value or perform actions after validation but before saving to the DB 
  173. * @param mixed $value 
  174. * @param int $id 
  175. * @param string $name 
  176. * @param array $options 
  177. * @param array $fields 
  178. * @param array $pod 
  179. * @param object $params 
  180. * @return mixed|string 
  181. * @since 2.0 
  182. */ 
  183. public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { 
  184. $options = (array) $options; 
  185.  
  186. if ( !is_email( $value ) ) 
  187. $value = ''; 
  188.  
  189. $length = (int) pods_var( self::$type . '_max_length', $options, 255 ); 
  190.  
  191. if ( 0 < $length && $length < pods_mb_strlen( $value ) ) { 
  192. $value = pods_mb_substr( $value, 0, $length ); 
  193.  
  194. return $value; 
  195.  
  196. /** 
  197. * Customize the Pods UI manage table column output 
  198. * @param int $id 
  199. * @param mixed $value 
  200. * @param string $name 
  201. * @param array $options 
  202. * @param array $fields 
  203. * @param array $pod 
  204. * @return mixed|string 
  205. * @since 2.0 
  206. */ 
  207. public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) { 
  208. return '<a href="mailto:' . esc_attr( $value ) . '">' . $value . '</a>';