acf_admin_field_group::ajax_move_field() │ public │ ACF 5.0.0
Move field AJAX function
Метод класса: acf_admin_field_group{}
Хуков нет.
Возвращает
null
. Ничего.
Использование
$acf_admin_field_group = new acf_admin_field_group();
$acf_admin_field_group->ajax_move_field();
Список изменений
Код acf_admin_field_group::ajax_move_field() acf admin field group::ajax move field
ACF 6.0.4
public function ajax_move_field() {
// disable filters to ensure ACF loads raw data from DB.
acf_disable_filters();
$args = acf_parse_args(
//phpcs:ignore WordPress.Security.NonceVerification.Missing
$_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(
/* translators: Confirmation message once a field has been moved to a different field group. */
acf_punctify( __( 'The %1$s field can now be found in the %2$s field group', 'acf' ) ),
esc_html( $field['label'] ),
$link //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
) . '</p>' .
'<a href="#" class="button button-primary acf-close-popup">' . __( 'Close Modal', '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 early if is current.
if ( $field_group['ID'] == $args['post_id'] ) {
continue;
}
$choices[ $field_group['ID'] ] = $field_group['title'];
}
}
// render options.
$field = acf_get_valid_field(
array(
'type' => 'select',
'name' => 'acf_field_group',
'choices' => $choices,
'aria-label' => __( 'Please select the destination for this field', 'acf' ),
)
);
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="acf-btn">' . __( 'Move Field', 'acf' ) . '</button>';
echo '</form>';
// die.
die();
}