acf_admin_field_group::save_post
Saves field group data.
Метод класса: acf_admin_field_group{}
Хуков нет.
Возвращает
Int. $post_id
Использование
$acf_admin_field_group = new acf_admin_field_group(); $acf_admin_field_group->save_post( $post_id, $post );
- $post_id(int) (обязательный)
- The post ID.
- $post(WP_Post) (обязательный)
- The post object.
Список изменений
| С версии 1.0.0 | Введена. |
Код acf_admin_field_group::save_post() acf admin field group::save post ACF 6.4.2
public function save_post( $post_id, $post ) {
if ( ! $this->verify_save_post( $post_id, $post ) ) {
return $post_id;
}
// disable filters to ensure ACF loads raw data from DB.
acf_disable_filters();
// save fields.
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Validated by WordPress.
if ( ! empty( $_POST['acf_fields'] ) ) {
// loop.
foreach ( $_POST['acf_fields'] as $field ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized when saved.
if ( ! isset( $field['key'] ) ) {
continue;
}
// vars.
$specific = false;
$save = acf_extract_var( $field, 'save' );
// only saved field if has changed.
if ( $save == 'meta' ) {
$specific = array(
'menu_order',
'post_parent',
);
}
// set parent.
if ( ! $field['parent'] ) {
$field['parent'] = $post_id;
}
// save field.
acf_update_field( $field, $specific );
}
}
// delete fields.
if ( acf_maybe_get_POST( '_acf_delete_fields', false ) ) { // phpcs:ignore -- Sanitized below, unslash not needed
// clean.
$ids = explode( '|', $_POST['_acf_delete_fields'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- Sanitized below, unslash not required.
$ids = array_map( 'intval', $ids );
// loop.
foreach ( $ids as $id ) {
// bai early if no id.
if ( ! $id ) {
continue;
}
// delete.
acf_delete_field( $id );
}
}
$_POST['acf_field_group']['ID'] = $post_id;
// phpcs:disable WordPress.Security.ValidatedSanitizedInput
$_POST['acf_field_group']['title'] = isset( $_POST['post_title'] ) ? $_POST['post_title'] : ''; // Post title is stored unsafe like WordPress, escaped on output.
// save field group.
acf_update_field_group( $_POST['acf_field_group'] );
// phpcs:enable WordPress.Security.ValidatedSanitizedInput
// phpcs:enable WordPress.Security.NonceVerification.Missing
return $post_id;
}