function delete_field($field) { if (!empty($field['layouts'])) { // loop through layouts foreach ($field['layouts'] as $layout) { // loop through sub fields if (!empty($layout['sub_fields'])) { foreach ($layout['sub_fields'] as $sub_field) { acf_delete_field($sub_field['ID']); } // foreach } // if } // foreach } // if }
function save_post($post_id) { // do not save if this is an auto save routine if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // only save once! WordPress save's a revision as well. if (wp_is_post_revision($post_id)) { return $post_id; } // verify nonce if (!acf_verify_nonce('field_group')) { return $post_id; } // disable local to avoid conflicts between DB and local acf_disable_local(); // save fields unset($_POST['acf_fields']['acfcloneindex']); if (!empty($_POST['acf_fields'])) { foreach ($_POST['acf_fields'] as $field) { // 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 field parent if (empty($field['parent'])) { $field['parent'] = $post_id; } // save field acf_update_field($field, $specific); } } // delete fields if ($_POST['_acf_delete_fields']) { $ids = explode('|', $_POST['_acf_delete_fields']); $ids = array_map('intval', $ids); foreach ($ids as $id) { if ($id != 0) { acf_delete_field($id); } } } // add args $_POST['acf_field_group']['ID'] = $post_id; $_POST['acf_field_group']['title'] = $_POST['post_title']; // save field group acf_update_field_group($_POST['acf_field_group']); // return return $post_id; }
function delete_field($field) { // loop through sub fields if (!empty($field['sub_fields'])) { foreach ($field['sub_fields'] as $sub_field) { acf_delete_field($sub_field['ID']); } } }
function acf_import_field_group($field_group) { // vars $ref = array(); $order = array(); // extract fields $fields = acf_extract_var($field_group, 'fields'); // format fields $fields = acf_prepare_fields_for_import($fields); // remove old fields if ($field_group['ID']) { $db_fields = acf_get_fields_by_id($field_group['ID']); $db_fields = acf_prepare_fields_for_import($db_fields); // get field keys $keys = array(); foreach ($fields as $field) { $keys[] = $field['key']; } // loop over db fields foreach ($db_fields as $field) { // add to ref $ref[$field['key']] = $field['ID']; if (!in_array($field['key'], $keys)) { acf_delete_field($field['ID']); } } } // save field group $field_group = acf_update_field_group($field_group); // add to ref $ref[$field_group['key']] = $field_group['ID']; // add to order $order[$field_group['ID']] = 0; // add fields foreach ($fields as $field) { // add ID if (!$field['ID'] && isset($ref[$field['key']])) { $field['ID'] = $ref[$field['key']]; } // add parent if (empty($field['parent'])) { $field['parent'] = $field_group['ID']; } elseif (isset($ref[$field['parent']])) { $field['parent'] = $ref[$field['parent']]; } // add field menu_order if (!isset($order[$field['parent']])) { $order[$field['parent']] = 0; } $field['menu_order'] = $order[$field['parent']]; $order[$field['parent']]++; // save field $field = acf_update_field($field); // add to ref $ref[$field['key']] = $field['ID']; } // return new field group return $field_group; }
function acf_delete_field_group($selector = 0) { // disable JSON to avoid conflicts between DB and JSON acf_disable_local(); // load the origional field gorup $field_group = acf_get_field_group($selector); // bail early if field group did not load correctly if (empty($field_group)) { return false; } // get fields $fields = acf_get_fields($field_group); if (!empty($fields)) { foreach ($fields as $field) { acf_delete_field($field['ID']); } } // delete wp_delete_post($field_group['ID']); // action for 3rd party customization do_action('acf/delete_field_group', $field_group); // return return true; }
function save_post($post_id, $post) { // do not save if this is an auto save routine if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // bail early if not acf-field-group if ($post->post_type !== 'acf-field-group') { return $post_id; } // only save once! WordPress save's a revision as well. if (wp_is_post_revision($post_id)) { return $post_id; } // verify nonce if (!acf_verify_nonce('field_group')) { return $post_id; } // disable filters to ensure ACF loads raw data from DB acf_disable_filters(); // save fields if (!empty($_POST['acf_fields'])) { foreach ($_POST['acf_fields'] as $field) { // 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 field parent if (empty($field['parent'])) { $field['parent'] = $post_id; } // save field acf_update_field($field, $specific); } } // delete fields if ($_POST['_acf_delete_fields']) { // clean $ids = explode('|', $_POST['_acf_delete_fields']); $ids = array_map('intval', $ids); // loop foreach ($ids as $id) { // bai early if no id if (!$id) { continue; } // delete acf_delete_field($id); } } // add args $_POST['acf_field_group']['ID'] = $post_id; $_POST['acf_field_group']['title'] = $_POST['post_title']; // save field group acf_update_field_group($_POST['acf_field_group']); // return return $post_id; }
function delete_field($field) { // bail early if no sub fields if (empty($field['sub_fields'])) { return; } // loop through sub fields foreach ($field['sub_fields'] as $sub_field) { acf_delete_field($sub_field['ID']); } }