acf_field_true_false::render_field()publicACF 3.6

Create the HTML interface for your field

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

Хуков нет.

Возвращает

null. Ничего.

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

$acf_field_true_false = new acf_field_true_false();
$acf_field_true_false->render_field( $field );
$field (обязательный)
-

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

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

Код acf_field_true_false::render_field() ACF 5.10.2

<?php
function render_field( $field ) {

	// vars
	$input = array(
		'type'         => 'checkbox',
		'id'           => $field['id'],
		'name'         => $field['name'],
		'value'        => '1',
		'class'        => $field['class'],
		'autocomplete' => 'off',
	);

	$hidden = array(
		'name'  => $field['name'],
		'value' => 0,
	);

	$active = $field['value'] ? true : false;
	$switch = '';

	// checked
	if ( $active ) {
		$input['checked'] = 'checked';
	}

	// ui
	if ( $field['ui'] ) {

		// vars
		if ( $field['ui_on_text'] === '' ) {
			$field['ui_on_text'] = __( 'Yes', 'acf' );
		}
		if ( $field['ui_off_text'] === '' ) {
			$field['ui_off_text'] = __( 'No', 'acf' );
		}

		// update input
		$input['class'] .= ' acf-switch-input';
		// $input['style'] = 'display:none;';

		$switch .= '<div class="acf-switch' . ( $active ? ' -on' : '' ) . '">';
		$switch .= '<span class="acf-switch-on">' . $field['ui_on_text'] . '</span>';
		$switch .= '<span class="acf-switch-off">' . $field['ui_off_text'] . '</span>';
		$switch .= '<div class="acf-switch-slider"></div>';
		$switch .= '</div>';

	}

	?>
<div class="acf-true-false">
	<?php acf_hidden_input( $hidden ); ?>
	<label>
<input <?php echo acf_esc_attr( $input ); ?>/>
	<?php
	if ( $switch ) {
		echo acf_esc_html( $switch );}
	?>
	<?php
	if ( $field['message'] ) :
		?>
		<span class="message"><?php echo acf_esc_html( $field['message'] ); ?></span><?php endif; ?>
	</label>
</div>
	<?php

}