acf_form_attachment::edit_attachment()publicACF 5.0.0

edit_attachment

description

Метод класса: acf_form_attachment{}

Хуков нет.

Возвращает

$post_id. (int)

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

$acf_form_attachment = new acf_form_attachment();
$acf_form_attachment->edit_attachment( $form_fields, $post );
$form_fields (обязательный)
-
$post (обязательный)
-

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

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

Код acf_form_attachment::edit_attachment() ACF 6.0.4

function edit_attachment( $form_fields, $post ) {

	// vars
	$is_page = acf_is_screen( 'attachment' );
	$post_id = $post->ID;
	$el      = 'tr';

	// get field groups
	$field_groups = acf_get_field_groups(
		array(
			'attachment_id' => $post_id,
			'attachment'    => $post_id, // Leave for backwards compatibility
		)
	);

	// render
	if ( ! empty( $field_groups ) ) {

		// get acf_form_data
		ob_start();

		acf_form_data(
			array(
				'screen'  => 'attachment',
				'post_id' => $post_id,
			)
		);

		// open
		echo '</td></tr>';

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

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

				// override instruction placement for modal
			if ( ! $is_page ) {

				$field_group['instruction_placement'] = 'field';
			}

				// render
				acf_render_fields( $fields, $post_id, $el, $field_group['instruction_placement'] );

		}

		// close
		echo '<tr class="compat-field-acf-blank"><td>';

		$html = ob_get_contents();

		ob_end_clean();

		$form_fields['acf-form-data'] = array(
			'label' => '',
			'input' => 'html',
			'html'  => $html,
		);

	}

	// return
	return $form_fields;

}