PodsField_Password

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

Defined (1)

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

/classes/fields/password.php  
  1. class PodsField_Password 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 = 'password'; 
  16.  
  17. /** 
  18. * Field Type Label 
  19. * @var string 
  20. * @since 2.0 
  21. */ 
  22. public static $label = 'Password'; 
  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. * @return array 
  43. */ 
  44. public function options () { 
  45. $options = array( 
  46. self::$type . '_max_length' => array( 
  47. 'label' => __( 'Maximum Length', 'pods' ),  
  48. 'default' => 255,  
  49. 'type' => 'number',  
  50. 'help' => __( 'Set to -1 for no limit', 'pods' ) 
  51. )/**,  
  52. self::$type . '_size' => array( 
  53. 'label' => __( 'Field Size', 'pods' ),  
  54. 'default' => 'medium',  
  55. 'type' => 'pick',  
  56. 'data' => array( 
  57. 'small' => __( 'Small', 'pods' ),  
  58. 'medium' => __( 'Medium', 'pods' ),  
  59. 'large' => __( 'Large', 'pods' ) 
  60. )*/ 
  61. ); 
  62.  
  63. return $options; 
  64.  
  65. /** 
  66. * Define the current field's schema for DB table storage 
  67. * @param array $options 
  68. * @return array 
  69. * @since 2.0 
  70. */ 
  71. public function schema ( $options = null ) { 
  72. $length = (int) pods_var( self::$type . '_max_length', $options, 255 ); 
  73.  
  74. $schema = 'VARCHAR(' . $length . ')'; 
  75.  
  76. if ( 255 < $length || $length < 1 ) 
  77. $schema = 'LONGTEXT'; 
  78.  
  79. return $schema; 
  80.  
  81. /** 
  82. * Customize output of the form field 
  83. * @param string $name 
  84. * @param mixed $value 
  85. * @param array $options 
  86. * @param array $pod 
  87. * @param int $id 
  88. * @since 2.0 
  89. */ 
  90. public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) { 
  91. $options = (array) $options; 
  92. $form_field_type = PodsForm::$field_type; 
  93.  
  94. if ( is_array( $value ) ) 
  95. $value = implode( ' ', $value ); 
  96.  
  97. if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) { 
  98. if ( pods_var( 'read_only', $options, false ) ) 
  99. $options[ 'readonly' ] = true; 
  100. else 
  101. return; 
  102. elseif ( !pods_has_permissions( $options ) && pods_var( 'read_only', $options, false ) ) 
  103. $options[ 'readonly' ] = true; 
  104.  
  105. pods_view( PODS_DIR . 'ui/fields/password.php', compact( array_keys( get_defined_vars() ) ) ); 
  106.  
  107. /** 
  108. * Validate a value before it's saved 
  109. * @param mixed $value 
  110. * @param string $name 
  111. * @param array $options 
  112. * @param array $fields 
  113. * @param array $pod 
  114. * @param int $id 
  115. * @param null $params 
  116. * @return array|bool 
  117. * @since 2.0 
  118. */ 
  119. public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) { 
  120. $errors = array(); 
  121.  
  122. $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params ); 
  123.  
  124. if ( is_array( $check ) ) 
  125. $errors = $check; 
  126. else { 
  127. if ( 0 < strlen( $value ) && strlen( $check ) < 1 ) { 
  128. if ( 1 == pods_var( 'required', $options ) ) 
  129. $errors[] = __( 'This field is required.', 'pods' ); 
  130.  
  131. if ( !empty( $errors ) ) 
  132. return $errors; 
  133.  
  134. return true; 
  135.  
  136. /** 
  137. * Change the value or perform actions after validation but before saving to the DB 
  138. * @param mixed $value 
  139. * @param int $id 
  140. * @param string $name 
  141. * @param array $options 
  142. * @param array $fields 
  143. * @param array $pod 
  144. * @param object $params 
  145. * @return mixed|string 
  146. * @since 2.0 
  147. */ 
  148. public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { 
  149. $length = (int) pods_var( self::$type . '_max_length', $options, 255 ); 
  150.  
  151. if ( 0 < $length && $length < pods_mb_strlen( $value ) ) { 
  152. $value = pods_mb_substr( $value, 0, $length ); 
  153.  
  154. return $value;