class-redux-textarea.php (2010B)
1 <?php 2 /** 3 * Textarea Field 4 * 5 * @package Redux Framework/Fields 6 * @author Dovy Paukstys & Kevin Provance (kprovance) 7 * @version 4.0.0 8 */ 9 10 defined( 'ABSPATH' ) || exit; 11 12 if ( ! class_exists( 'Redux_Textarea', false ) ) { 13 14 /** 15 * Class Redux_Textarea 16 */ 17 class Redux_Textarea extends Redux_Field { 18 19 /** 20 * Field Render Function. 21 * Takes the vars and outputs the HTML for the field in the settings 22 * 23 * @since ReduxFramework 1.0.0 24 * */ 25 public function render() { 26 27 $this->field['attributes'] = wp_parse_args( 28 $this->field['attributes'] ?? array(), 29 array( 30 'placeholder' => $this->field['placeholder'] ?? '', 31 'rows' => $this->field['rows'] ?? 6, 32 'autocomplete' => ( isset( $this->field['autocomplete'] ) && false === $this->field['autocomplete'] ) ? 'off' : '', 33 'readonly' => isset( $this->field['readonly'] ) && $this->field['readonly'] ? 'readonly' : '', 34 'name' => esc_attr( $this->field['name'] . $this->field['name_suffix'] ), 35 'id' => esc_attr( $this->field['id'] ), 36 'class' => isset( $this->field['class'] ) && ! empty( $this->field['class'] ) ? array( trim( $this->field['class'] ) ) : array(), 37 ) 38 ); 39 40 $this->field['attributes']['class'][] = 'large-text'; 41 42 $this->field['attributes']['class'] = implode( ' ', $this->field['attributes']['class'] ); 43 44 $attributes_string = $this->render_attributes( $this->field['attributes'] ); 45 echo '<textarea ' . $attributes_string . '>' . esc_textarea( $this->value ) . '</textarea>'; // phpcs:ignore WordPress.Security.EscapeOutput 46 } 47 48 /** 49 * Santize value. 50 * 51 * @param array $field Field array. 52 * @param string $value Values array. 53 * 54 * @return string 55 */ 56 public function sanitize( array $field, string $value ): string { 57 if ( empty( $value ) ) { 58 $value = ''; 59 } else { 60 $value = esc_textarea( $value ); 61 } 62 63 return $value; 64 } 65 } 66 } 67 68 class_alias( 'Redux_Textarea', 'ReduxFramework_Textarea' );