acf_field_true_false::render_field
Create the HTML interface for your field
Метод класса: acf_field_true_false{}
Хуков нет.
Возвращает
null. Ничего (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 field true false::render field ACF 6.4.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_attrs( $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
}