acf_admin_field_group::ajax_move_field()publicACF 5.0.0

ajax_move_field

description

@type    function

{} Это метод класса: 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.10.2

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();
	}

	// verify user capability
	if ( ! acf_current_user_can_admin() ) {
		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 );

		// Output HTML.
		$link = '<a href="' . admin_url( 'post.php?post=' . $field_group['ID'] . '&action=edit' ) . '" target="_blank">' . esc_html( $field_group['title'] ) . '</a>';

		echo '' .
			'<p><strong>' . __( 'Move Complete.', 'acf' ) . '</strong></p>' .
			'<p>' . sprintf(
				acf_punctify( __( 'The %1$s field can now be found in the %2$s field group', 'acf' ) ),
				esc_html( $field['label'] ),
				$link
			) . '</p>' .
			'<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();

}