acf_get_checkbox_input()ACF 5.0.0

acf_get_checkbox_input

Returns the HTML of a checkbox input.

No Hooks.

Returns

String.

Usage

acf_get_checkbox_input( $attrs );
$attrs(array)
The array of attrs.
Default: array()

Changelog

Since 5.0.0 Introduced.

acf_get_checkbox_input() code ACF 6.0.4

function acf_get_checkbox_input( $attrs = array() ) {

	// Allow radio or checkbox type.
	$attrs = wp_parse_args(
		$attrs,
		array(
			'type' => 'checkbox',
		)
	);

	// Get label.
	$label = '';
	if ( isset( $attrs['label'] ) ) {
		$label = $attrs['label'];
		unset( $attrs['label'] );
	}

	// Render.
	$checked = isset( $attrs['checked'] );
	return '<label' . ( $checked ? ' class="selected"' : '' ) . '><input ' . acf_esc_attr( $attrs ) . '/> ' . acf_esc_html( $label ) . '</label>';
}