acf_update_field_group()
acf_update_field_group
Updates a field group in the database.
Хуки из функции
Возвращает
Массив
.
Использование
acf_update_field_group( $field_group );
- $field_group(массив) (обязательный)
- The field group array.
Список изменений
С версии 5.7.10 | Введена. |
Код acf_update_field_group() acf update field group ACF 6.0.4
function acf_update_field_group( $field_group ) { // Validate field group. $field_group = acf_get_valid_field_group( $field_group ); // May have been posted. Remove slashes. $field_group = wp_unslash( $field_group ); // Parse types (converts string '0' to int 0). $field_group = acf_parse_types( $field_group ); // Clean up location keys. if ( $field_group['location'] ) { // Remove empty values and convert to associated array. $field_group['location'] = array_filter( $field_group['location'] ); $field_group['location'] = array_values( $field_group['location'] ); $field_group['location'] = array_map( 'array_filter', $field_group['location'] ); $field_group['location'] = array_map( 'array_values', $field_group['location'] ); } // Make a backup of field group data and remove some args. $_field_group = $field_group; acf_extract_vars( $_field_group, array( 'ID', 'key', 'title', 'menu_order', 'fields', 'active', '_valid' ) ); // Create array of data to save. $save = array( 'ID' => $field_group['ID'], 'post_status' => $field_group['active'] ? 'publish' : 'acf-disabled', 'post_type' => 'acf-field-group', 'post_title' => $field_group['title'], 'post_name' => $field_group['key'], 'post_excerpt' => sanitize_title( $field_group['title'] ), 'post_content' => maybe_serialize( $_field_group ), 'menu_order' => $field_group['menu_order'], 'comment_status' => 'closed', 'ping_status' => 'closed', ); // Unhook wp_targeted_link_rel() filter from WP 5.1 corrupting serialized data. remove_filter( 'content_save_pre', 'wp_targeted_link_rel' ); // Slash data. // WP expects all data to be slashed and will unslash it (fixes '\' character issues). $save = wp_slash( $save ); // Update or Insert. if ( $field_group['ID'] ) { wp_update_post( $save ); } else { $field_group['ID'] = wp_insert_post( $save ); } // Flush field group cache. acf_flush_field_group_cache( $field_group ); /** * Fires immediately after a field group has been updated. * * @date 12/02/2014 * @since 5.0.0 * * @param array $field_group The field group array. */ do_action( 'acf/update_field_group', $field_group ); // Return field group. return $field_group; }