ACF_Form_User::render()publicACF 5.0.0

render

This function will render ACF fields for a given $post_id parameter

@type    function

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

Хуков нет.

Возвращает

null. Ничего.

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

$ACF_Form_User = new ACF_Form_User();
$ACF_Form_User->render( $args );
$args **
-
По умолчанию: array()

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

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

Код ACF_Form_User::render() ACF 5.10.2

function render( $args = array() ) {

	// Allow $_POST data to persist across form submission attempts.
	if ( isset( $_POST['acf'] ) ) {
		add_filter( 'acf/pre_load_value', array( $this, 'filter_pre_load_value' ), 10, 3 );
	}

	// defaults
	$args = wp_parse_args(
		$args,
		array(
			'user_id' => 0,
			'view'    => 'edit',
			'el'      => 'tr',
		)
	);

	// vars
	$post_id = 'user_' . $args['user_id'];

	// get field groups
	$field_groups = acf_get_field_groups(
		array(
			'user_id'   => $args['user_id'] ? $args['user_id'] : 'new',
			'user_form' => $args['view'],
		)
	);

	// bail early if no field groups
	if ( empty( $field_groups ) ) {
		return;
	}

	// form data
	acf_form_data(
		array(
			'screen'     => 'user',
			'post_id'    => $post_id,
			'validation' => ( $args['view'] == 'register' ) ? 0 : 1,
		)
	);

	// elements
	$before = '<table class="form-table"><tbody>';
	$after  = '</tbody></table>';

	if ( $args['el'] == 'div' ) {
		$before = '<div class="acf-user-' . $args['view'] . '-fields acf-fields -clear">';
		$after  = '</div>';
	}

	// loop
	foreach ( $field_groups as $field_group ) {

		// vars
		$fields = acf_get_fields( $field_group );

		// title
		if ( $field_group['style'] === 'default' ) {
			echo '<h2>' . $field_group['title'] . '</h2>';
		}

		// render
		echo $before;
		acf_render_fields( $fields, $post_id, $args['el'], $field_group['instruction_placement'] );
		echo $after;
	}

	// actions
	add_action( 'acf/input/admin_footer', array( $this, 'admin_footer' ), 10, 1 );
}