acf_form_nav_menu::admin_footer()publicACF 5.0.0

admin_footer

This function will add some custom HTML to the footer of the edit page

@type    function

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

Хуков нет.

Возвращает

null. Ничего.

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

$acf_form_nav_menu = new acf_form_nav_menu();
$acf_form_nav_menu->admin_footer();

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

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

Код acf_form_nav_menu::admin_footer() ACF 5.10.2

<?php
function admin_footer() {

	// vars
	$nav_menu_id = acf_get_data( 'nav_menu_id' );
	$post_id     = 'term_' . $nav_menu_id;

	// get field groups
	$field_groups = acf_get_field_groups(
		array(
			'nav_menu' => $nav_menu_id,
		)
	);

	?>
<div id="tmpl-acf-menu-settings" style="display: none;">
	<?php

	// data (always needed to save nav menu items)
	acf_form_data(
		array(
			'screen'  => 'nav_menu',
			'post_id' => $post_id,
			'ajax'    => 1,
		)
	);

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

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

			$fields = acf_get_fields( $field_group );

			echo '<div class="acf-menu-settings -' . $field_group['style'] . '">';

			echo '<h2>' . $field_group['title'] . '</h2>';

			echo '<div class="acf-fields -left -clear">';

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

			echo '</div>';

			echo '</div>';

		}
	}

	?>
</div>
<script type="text/javascript">
(function($) {
	
	// append html
	$('#post-body-content').append( $('#tmpl-acf-menu-settings').html() );
	
	
	// avoid WP over-writing $_POST data
	// - https://core.trac.wordpress.org/ticket/41502#ticket
	$(document).on('submit', '#update-nav-menu', function() {

// vars
var $form = $(this);
var $input = $('input[name="nav-menu-data"]');


// decode json
var json = $form.serializeArray();
var json2 = [];


// loop
$.each( json, function( i, pair ) {
	
	// avoid nesting (unlike WP)
	if( pair.name === 'nav-menu-data' ) return;
	
	
	// bail early if is 'acf[' input
	if( pair.name.indexOf('acf[') > -1 ) return;
				
	
	// append
	json2.push( pair );
	
});


// update
$input.val( JSON.stringify(json2) );

	});


})(jQuery);	
</script>
	<?php

}