acf_field_button_group::render_field()publicACF 5.6.3

Creates the field's input HTML

{} Это метод класса: acf_field_button_group{}

Хуков нет.

Возвращает

null. Ничего.

Использование

$acf_field_button_group = new acf_field_button_group();
$acf_field_button_group->render_field( $field );
$field(массив) (обязательный)
The field settings array

Список изменений

С версии 5.6.3 Введена.

Код acf_field_button_group::render_field() ACF 5.10.2

function render_field( $field ) {

	// vars
	$html     = '';
	$selected = null;
	$buttons  = array();
	$value    = esc_attr( $field['value'] );

	// bail ealrly if no choices
	if ( empty( $field['choices'] ) ) {
		return;
	}

	// buttons
	foreach ( $field['choices'] as $_value => $_label ) {

		// checked
		$checked = ( $value === esc_attr( $_value ) );
		if ( $checked ) {
			$selected = true;
		}

		// append
		$buttons[] = array(
			'name'    => $field['name'],
			'value'   => $_value,
			'label'   => $_label,
			'checked' => $checked,
		);

	}

	// maybe select initial value
	if ( ! $field['allow_null'] && $selected === null ) {
		$buttons[0]['checked'] = true;
	}

	// div
	$div = array( 'class' => 'acf-button-group' );

	if ( $field['layout'] == 'vertical' ) {
		$div['class'] .= ' -vertical'; }
	if ( $field['class'] ) {
		$div['class'] .= ' ' . $field['class']; }
	if ( $field['allow_null'] ) {
		$div['data-allow_null'] = 1; }

	// hdden input
	$html .= acf_get_hidden_input( array( 'name' => $field['name'] ) );

	// open
	$html .= '<div ' . acf_esc_attr( $div ) . '>';

	// loop
	foreach ( $buttons as $button ) {

		// checked
		if ( $button['checked'] ) {
			$button['checked'] = 'checked';
		} else {
			unset( $button['checked'] );
		}

		// append
		$html .= acf_get_radio_input( $button );

	}

	// close
	$html .= '</div>';

	// return
	echo $html;

}