acf_form_widget::edit_widget()publicACF 5.0.0

edit_widget

This function will render the fields for a widget form

@type    function

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

Хуков нет.

Возвращает

$post_id. (int)

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

$acf_form_widget = new acf_form_widget();
$acf_form_widget->edit_widget( $widget, $return, $instance );
$widget (обязательный)
-
$return (обязательный)
-
$instance (обязательный)
-

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

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

Код acf_form_widget::edit_widget() ACF 5.10.2

<?php
function edit_widget( $widget, $return, $instance ) {

	// vars
	$post_id = 0;
	$prefix  = 'widget-' . $widget->id_base . '[' . $widget->number . '][acf]';

	// get id
	if ( $widget->number !== '__i__' ) {

		$post_id = "widget_{$widget->id}";

	}

	// get field groups
	$field_groups = acf_get_field_groups(
		array(
			'widget' => $widget->id_base,
		)
	);

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

		// render post data
		acf_form_data(
			array(
				'screen'        => 'widget',
				'post_id'       => $post_id,
				'widget_id'     => 'widget-' . $widget->id_base,
				'widget_number' => $widget->number,
				'widget_prefix' => $prefix,
			)
		);

		// wrap
		echo '<div class="acf-widget-fields acf-fields -clear">';

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

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

				// bail if not fields
			if ( empty( $fields ) ) {
				continue;
			}

				// change prefix
				acf_prefix_fields( $fields, $prefix );

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

		}

		// wrap
		echo '</div>';

		// jQuery selector looks odd, but is necessary due to WP adding an incremental number into the ID
		// - not possible to find number via PHP parameters
		if ( $widget->updated ) : ?>
	<script type="text/javascript">
	(function($) {
		
		acf.doAction('append', $('[id^="widget"][id$="<?php echo $widget->id; ?>"]') );
		
	})(jQuery);	
	</script>
			<?php
	endif;

	}

}