| 1 |
<?php |
| 2 |
/** |
| 3 |
* CMB2 HTML Field Type |
| 4 |
*/ |
| 5 |
|
| 6 |
if( ! function_exists( 'cmb2_render_html' ) ) : |
| 7 |
|
| 8 |
/** |
| 9 |
* Render the HTML content |
| 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_html( $field, $value, $object_id, $object_type, $field_type ) { |
| 20 |
|
| 21 |
// Parse args |
| 22 |
$attrs = $field_type->parse_args( 'html', array( |
| 23 |
'id' => $field_type->_id(), |
| 24 |
) ); |
| 25 |
|
| 26 |
if( isset( $field->args['content_cb'] ) && ! empty( $field->args['content_cb'] ) ) { |
| 27 |
ob_start(); |
| 28 |
call_user_func_array( $field->args['content_cb'], array( $field, $object_id, $object_type ) ); |
| 29 |
$field->args['content'] = ob_get_clean(); |
| 30 |
} |
| 31 |
|
| 32 |
echo sprintf( '<div %s>%s</div>', |
| 33 |
$field_type->concat_attrs( $attrs ), |
| 34 |
( isset( $field->args['content'] ) && ! empty( $field->args['content'] ) ? $field->args['content'] : '' ) |
| 35 |
); |
| 36 |
} |
| 37 |
add_action( 'cmb2_render_html', 'cmb2_render_html', 10, 5 ); |
| 38 |
|
| 39 |
endif; |