WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

acf_field_radio::render_field() public ACF 3.6

Create the HTML interface for your field

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

Хуков нет.

Возвращает

n/a.

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

$acf_field_radio = new acf_field_radio();
$acf_field_radio->render_field( $field );
(array)($field) (обязательный)
the $field being rendered
(array)($field) (обязательный)
the $field being edited

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

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

Код acf_field_radio::render_field() ACF 5.9.1

<?php
function render_field( $field ) {

	// vars
	$i = 0;
	$e = '';
	$ul = array( 
		'class'				=> 'acf-radio-list',
		'data-allow_null'	=> $field['allow_null'],
		'data-other_choice'	=> $field['other_choice']
	);
	
	
	// append to class
	$ul['class'] .= ' ' . ($field['layout'] == 'horizontal' ? 'acf-hl' : 'acf-bl');
	$ul['class'] .= ' ' . $field['class'];
	
	
	// select value
	$checked = '';
	$value = strval($field['value']);
	
	
	// selected choice
	if( isset($field['choices'][ $value ]) ) {
		
		$checked = $value;
		
	// custom choice
	} elseif( $field['other_choice'] && $value !== '' ) {
		
		$checked = 'other';
		
	// allow null	
	} elseif( $field['allow_null'] ) {
		
		// do nothing
		
	// select first input by default	
	} else {
		
		$checked = key($field['choices']);
		
	}
	
	
	// ensure $checked is a string (could be an int)
	$checked = strval($checked); 
	
			
	// other choice
	if( $field['other_choice'] ) {
		
		// vars
		$input = array(
			'type'		=> 'text',
			'name'		=> $field['name'],
			'value'		=> '',
			'disabled'	=> 'disabled',
			'class'		=> 'acf-disabled'
		);
		
		
		// select other choice if value is not a valid choice
		if( $checked === 'other' ) {
			
			unset($input['disabled']);
			$input['value'] = $field['value'];
			
		}
		
		
		// allow custom 'other' choice to be defined
		if( !isset($field['choices']['other']) ) {
			
			$field['choices']['other'] = '';
			
		}
		
		
		// append other choice
		$field['choices']['other'] .= '</label> <input type="text" ' . acf_esc_attr($input) . ' /><label>';
	
	}
	
	
	// bail early if no choices
	if( empty($field['choices']) ) return;
	
	
	// hiden input
	$e .= acf_get_hidden_input( array('name' => $field['name']) );
	
	
	// open
	$e .= '<ul ' . acf_esc_attr($ul) . '>';
	
	
	// foreach choices
	foreach( $field['choices'] as $value => $label ) {
		
		// ensure value is a string
		$value = strval($value);
		$class = '';
		
		
		// increase counter
		$i++;
		
		
		// vars
		$atts = array(
			'type'	=> 'radio',
			'id'	=> $field['id'], 
			'name'	=> $field['name'],
			'value'	=> $value
		);
		
		
		// checked
		if( $value === $checked ) {
			
			$atts['checked'] = 'checked';
			$class = ' class="selected"';
			
		}
		
		
		// deisabled
		if( isset($field['disabled']) && acf_in_array($value, $field['disabled']) ) {
		
			$atts['disabled'] = 'disabled';
			
		}
		
		
		// id (use crounter for each input)
		if( $i > 1 ) {
		
			$atts['id'] .= '-' . $value;
			
		}
		
		
		// append
		$e .= '<li><label' . $class . '><input ' . acf_esc_attr( $atts ) . '/>' . $label . '</label></li>';
		
	}
	
	
	// close
	$e .= '</ul>';
	
	
	// return
	echo $e;
	
}