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

acf_admin_field_group::ajax_move_field() public ACF 5.0.0

description

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

Хуков нет.

Возвращает

$post_id. (int)

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

$acf_admin_field_group = new acf_admin_field_group();
$acf_admin_field_group->ajax_move_field();

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

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

Код acf_admin_field_group::ajax_move_field() ACF 5.9.1

<?php
function ajax_move_field() {
	
	// disable filters to ensure ACF loads raw data from DB
	acf_disable_filters();
	
	
	$args = acf_parse_args($_POST, array(
		'nonce'				=> '',
		'post_id'			=> 0,
		'field_id'			=> 0,
		'field_group_id'	=> 0
	));
	
	
	// verify nonce
	if( !wp_verify_nonce($args['nonce'], 'acf_nonce') ) die();
	
	
	// confirm?
	if( $args['field_id'] && $args['field_group_id'] ) {
		
		// vars 
		$field = acf_get_field($args['field_id']);
		$field_group = acf_get_field_group($args['field_group_id']);
		
		
		// update parent
		$field['parent'] = $field_group['ID'];
		
		
		// remove conditional logic
		$field['conditional_logic'] = 0;
		
		
		// update field
		acf_update_field($field);
		
		
		// message
		$a = '<a href="' . admin_url("post.php?post={$field_group['ID']}&action=edit") . '" target="_blank">' . $field_group['title'] . '</a>';
		echo '<p><strong>' . __('Move Complete.', 'acf') . '</strong></p>';
		echo '<p>' . sprintf( __('The %s field can now be found in the %s field group', 'acf'), $field['label'], $a ). '</p>';
		echo '<a href="#" class="button button-primary acf-close-popup">' . __("Close Window",'acf') . '</a>';
		die();
		
	}
	
	
	// get all field groups
	$field_groups = acf_get_field_groups();
	$choices = array();
	
	
	// check
	if( !empty($field_groups) ) {
		
		// loop
		foreach( $field_groups as $field_group ) {
			
			// bail early if no ID
			if( !$field_group['ID'] ) continue;
			
			
			// bail ealry if is current
			if( $field_group['ID'] == $args['post_id'] ) continue;
			
			
			// append
			$choices[ $field_group['ID'] ] = $field_group['title'];
			
		}
		
	}
	
	
	// render options
	$field = acf_get_valid_field(array(
		'type'		=> 'select',
		'name'		=> 'acf_field_group',
		'choices'	=> $choices
	));
	
	
	echo '<p>' . __('Please select the destination for this field', 'acf') . '</p>';
	
	echo '<form id="acf-move-field-form">';
	
		// render
		acf_render_field_wrap( $field );
		
		echo '<button type="submit" class="button button-primary">' . __("Move Field",'acf') . '</button>';
		
	echo '</form>';
	
	
	// die
	die();
	
}