| @@ -1,0 +1,38 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * CMB2 Display Field Type | |
| 4 | + */ | |
| 5 | + | |
| 6 | +if( ! function_exists( 'cmb2_render_display' ) ) : | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * Render a text-only field type | |
| 10 | + * | |
| 11 | + * @param array $field The field data array | |
| 12 | + * @param mixed $value The stored value for this field | |
| 13 | + * @param integer|string $object_id The object ID | |
| 14 | + * @param string $object_type The object type | |
| 15 | + * @param CMB2_Types $field_type The field type object | |
| 16 | + * | |
| 17 | + * @return string HTML markup for our field | |
| 18 | + */ | |
| 19 | + function cmb2_render_display( $field, $value, $object_id, $object_type, $field_type ) { | |
| 20 | + | |
| 21 | + $value = isset( $field->args['value'] ) ? $field->args['value'] : $value; | |
| 22 | + | |
| 23 | + // Parse args | |
| 24 | + $attrs = $field_type->parse_args( 'display', array( | |
| 25 | + 'class' => $field->args['classes'], | |
| 26 | + 'name' => $field_type->_name(), | |
| 27 | + 'id' => $field_type->_id(), | |
| 28 | + ) ); | |
| 29 | + | |
| 30 | + echo sprintf( '<span%s>%s</span>%s', | |
| 31 | + $field_type->concat_attrs( $attrs ), | |
| 32 | + $value, | |
| 33 | + $field_type->_desc( true ) | |
| 34 | + ); | |
| 35 | + } | |
| 36 | + add_action( 'cmb2_render_display', 'cmb2_render_display', 10, 5 ); | |
| 37 | + | |
| 38 | +endif; | |