acf_field_textarea

The Advanced Custom Fields acf field textarea class.

Defined (1)

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

/core/fields/textarea.php  
  1. class acf_field_textarea extends acf_field 
  2.  
  3. /** 
  4. * __construct 
  5. * Set name / label needed for actions / filters 
  6. * @since 3.6 
  7. * @date 23/01/13 
  8. */ 
  9.  
  10. function __construct() 
  11. // vars 
  12. $this->name = 'textarea'; 
  13. $this->label = __("Text Area", 'acf'); 
  14. $this->defaults = array( 
  15. 'default_value' => '',  
  16. 'formatting' => 'br',  
  17. 'maxlength' => '',  
  18. 'placeholder' => '',  
  19. 'rows' => '' 
  20. ); 
  21.  
  22.  
  23. // do not delete! 
  24. parent::__construct(); 
  25.  
  26.  
  27. /** 
  28. * create_field() 
  29. * Create the HTML interface for your field 
  30. * @param $field - an array holding all the field's data 
  31. * @type action 
  32. * @since 3.6 
  33. * @date 23/01/13 
  34. */ 
  35.  
  36. function create_field( $field ) 
  37. // vars 
  38. $o = array( 'id', 'class', 'name', 'placeholder', 'rows' ); 
  39. $e = ''; 
  40.  
  41.  
  42. // maxlength 
  43. if( $field['maxlength'] !== "" ) 
  44. $o[] = 'maxlength'; 
  45.  
  46.  
  47. // rows 
  48. if( empty($field['rows']) ) 
  49. $field['rows'] = 8; 
  50.  
  51. $e .= '<textarea'; 
  52.  
  53. foreach( $o as $k ) 
  54. $e .= ' ' . $k . '="' . esc_attr( $field[ $k ] ) . '"';  
  55.  
  56. $e .= '>'; 
  57. $e .= esc_textarea($field['value']); 
  58. $e .= '</textarea>'; 
  59.  
  60. // return 
  61. echo $e; 
  62.  
  63.  
  64. /** 
  65. * create_options() 
  66. * Create extra options for your field. This is rendered when editing a field. 
  67. * The value of $field['name'] can be used (like bellow) to save extra data to the $field 
  68. * @param $field - an array holding all the field's data 
  69. * @type action 
  70. * @since 3.6 
  71. * @date 23/01/13 
  72. */ 
  73.  
  74. function create_options( $field ) 
  75. // vars 
  76. $key = $field['name']; 
  77.  
  78. ?> 
  79. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  80. <td class="label"> 
  81. <label><?php _e("Default Value", 'acf'); ?></label> 
  82. <p><?php _e("Appears when creating a new post", 'acf') ?></p> 
  83. </td> 
  84. <td> 
  85. <?php  
  86. do_action('acf/create_field', array( 
  87. 'type' => 'textarea',  
  88. 'name' => 'fields['.$key.'][default_value]',  
  89. 'value' => $field['default_value'],  
  90. )); 
  91. ?> 
  92. </td> 
  93. </tr> 
  94. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  95. <td class="label"> 
  96. <label><?php _e("Placeholder Text", 'acf'); ?></label> 
  97. <p><?php _e("Appears within the input", 'acf') ?></p> 
  98. </td> 
  99. <td> 
  100. <?php  
  101. do_action('acf/create_field', array( 
  102. 'type' => 'text',  
  103. 'name' => 'fields[' .$key.'][placeholder]',  
  104. 'value' => $field['placeholder'],  
  105. )); 
  106. ?> 
  107. </td> 
  108. </tr> 
  109. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  110. <td class="label"> 
  111. <label><?php _e("Character Limit", 'acf'); ?></label> 
  112. <p><?php _e("Leave blank for no limit", 'acf') ?></p> 
  113. </td> 
  114. <td> 
  115. <?php  
  116. do_action('acf/create_field', array( 
  117. 'type' => 'number',  
  118. 'name' => 'fields[' .$key.'][maxlength]',  
  119. 'value' => $field['maxlength'],  
  120. )); 
  121. ?> 
  122. </td> 
  123. </tr> 
  124. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  125. <td class="label"> 
  126. <label><?php _e("Rows", 'acf'); ?></label> 
  127. <p><?php _e("Sets the textarea height", 'acf') ?></p> 
  128. </td> 
  129. <td> 
  130. <?php  
  131. do_action('acf/create_field', array( 
  132. 'type' => 'number',  
  133. 'name' => 'fields[' .$key.'][rows]',  
  134. 'value' => $field['rows'],  
  135. 'placeholder' => 8 
  136. )); 
  137. ?> 
  138. </td> 
  139. </tr> 
  140. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  141. <td class="label"> 
  142. <label><?php _e("Formatting", 'acf'); ?></label> 
  143. <p><?php _e("Affects value on front end", 'acf') ?></p> 
  144. </td> 
  145. <td> 
  146. <?php  
  147. do_action('acf/create_field', array( 
  148. 'type' => 'select',  
  149. 'name' => 'fields['.$key.'][formatting]',  
  150. 'value' => $field['formatting'],  
  151. 'choices' => array( 
  152. 'none' => __("No formatting", 'acf'),  
  153. 'br' => __("Convert new lines into <br /> tags", 'acf'),  
  154. 'html' => __("Convert HTML into tags", 'acf') 
  155. )); 
  156. ?> 
  157. </td> 
  158. </tr> 
  159. <?php 
  160.  
  161.  
  162.  
  163. /** 
  164. * format_value_for_api() 
  165. * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field 
  166. * @type filter 
  167. * @since 3.6 
  168. * @date 23/01/13 
  169. * @param $value - the value which was loaded from the database 
  170. * @param $post_id - the $post_id from which the value was loaded 
  171. * @param $field - the field array holding all the field options 
  172. * @return $value - the modified value 
  173. */ 
  174.  
  175. function format_value_for_api( $value, $post_id, $field ) 
  176. // validate type 
  177. if( !is_string($value) ) 
  178. return $value; 
  179.  
  180.  
  181. if( $field['formatting'] == 'none' ) 
  182. $value = htmlspecialchars($value, ENT_QUOTES); 
  183. elseif( $field['formatting'] == 'html' ) 
  184. //$value = html_entity_decode($value); 
  185. //$value = nl2br($value); 
  186. elseif( $field['formatting'] == 'br' ) 
  187. $value = htmlspecialchars($value, ENT_QUOTES); 
  188. $value = nl2br($value); 
  189.  
  190.  
  191. return $value; 
  192.