function update_field_group($field_group) { // vars $path = acf_get_setting('save_json'); $file = $field_group['key'] . '.json'; // remove trailing slash $path = untrailingslashit($path); // bail early if dir does not exist if (!is_writable($path)) { //error_log( 'ACF failed to save field group to .json file. Path does not exist: ' . $path ); return; } // load fields $fields = acf_get_fields($field_group); // prepare fields $fields = acf_prepare_fields_for_export($fields); // add to field group $field_group['fields'] = $fields; // extract field group ID $id = acf_extract_var($field_group, 'ID'); // write file $f = fopen("{$path}/{$file}", 'w'); fwrite($f, acf_json_encode($field_group)); fclose($f); }
/** * Get ACF data * * @param $value * @param $data * * @return string */ function vc_gitem_template_attribute_acf($value, $data) { $label = ''; /** * @var null|Wp_Post $post ; * @var string $data ; */ extract(array_merge(array('post' => null, 'data' => ''), $data)); if (strstr($data, 'field_from_group_')) { $group_id = preg_replace('/(^field_from_group_|_labeled$)/', '', $data); $fields = function_exists('acf_get_fields') ? acf_get_fields($group_id) : apply_filters('acf/field_group/get_fields', array(), $group_id); $field = is_array($fields) && isset($fields[0]) ? $fields[0] : false; if (is_array($field) && isset($field['key'])) { $data = $field['key'] . (strstr($data, '_labeled') ? '_labeled' : ''); } } $label = ''; if (preg_match('/_labeled$/', $data)) { $data = preg_replace('/_labeled$/', '', $data); $field = get_field_object($data); $label = is_array($field) && isset($field['label']) ? '<span class="vc_gitem-acf-label">' . $field['label'] . ':</span> ' : ''; } $value = ''; if ($data) { $value = do_shortcode('[acf field="' . $data . '" post_id="' . $post->ID . '"]'); } return $label . apply_filters('vc_gitem_template_attribute_acf_value', $value); }
/** * Get the visible ACF fields. * @return array */ public function get_visible_acf_fields($widget_id = null) { global $wp_registered_widgets; $visible_fields = array(); // build field group filters required for current screen $filter = $this->get_acf_field_group_filters(); if (count($filter) === 0) { return $visible_fields; } // widgets need some special handling since they // require multiple acf_get_field_group_visibility() // calls in order to return all the visible fields if (acf_is_screen('widgets') || acf_is_screen('customize')) { if ($widget_id) { $filter['widget'] = _get_widget_id_base($widget_id); } else { // process each widget form individually for any visible fields foreach ($wp_registered_widgets as $widget) { $visible_fields += $this->get_visible_acf_fields($widget['id']); } return $visible_fields; } } $supported_field_types = array('email', 'text', 'textarea', 'repeater', 'flexible_content', 'qtranslate_file', 'qtranslate_image', 'qtranslate_text', 'qtranslate_textarea', 'qtranslate_wysiwyg'); foreach (acf_get_field_groups($filter) as $field_group) { $fields = acf_get_fields($field_group); foreach ($fields as $field) { if (in_array($field['type'], $supported_field_types)) { $visible_fields[] = array('id' => 'acf-' . $field['key']); } } } return $visible_fields; }
/** * Get ACF data * * @param $value * @param $data * * @return string */ function vc_gitem_template_attribute_acf($value, $data) { $label = ''; /** * @var null|Wp_Post $post ; * @var string $data ; */ extract(array_merge(array('post' => null, 'data' => ''), $data)); if (strstr($data, 'field_from_group_')) { $group_id = preg_replace('/(^field_from_group_|_labeled$)/', '', $data); $fields = function_exists('acf_get_fields') ? acf_get_fields($group_id) : apply_filters('acf/field_group/get_fields', array(), $group_id); $field = is_array($fields) && isset($fields[0]) ? $fields[0] : false; if (is_array($field) && isset($field['key'])) { $data = $field['key'] . (strstr($data, '_labeled') ? str_replace($data, '', '_labeled') : ''); } } if (preg_match('/_labeled$/', $data)) { $data = preg_replace('/_labeled$/', '', $data); $field = apply_filters('acf/load_field', array(), $data); $label = is_array($field) ? '<span class="vc_gite-acf-label">' . $field['label'] . ':</span> ' : ''; } if (get_field($data)) { $value = apply_filters('vc_gitem_template_attribute_acf_value', get_field($data, $post->ID)); } return strlen($value) > 0 ? $label . $value : ''; }
function load_field($field) { // bail early if no field layouts if (empty($field['layouts'])) { return $field; } // vars $sub_fields = acf_get_fields($field); // loop through layouts, sub fields and swap out the field key with the real field foreach (array_keys($field['layouts']) as $i) { // extract layout $layout = acf_extract_var($field['layouts'], $i); // validate layout $layout = $this->get_valid_layout($layout); // append sub fields if (!empty($sub_fields)) { foreach (array_keys($sub_fields) as $k) { // check if 'parent_layout' is empty if (empty($sub_fields[$k]['parent_layout'])) { // parent_layout did not save for this field, default it to first layout $sub_fields[$k]['parent_layout'] = $layout['key']; } // append sub field to layout, if ($sub_fields[$k]['parent_layout'] == $layout['key']) { $layout['sub_fields'][] = acf_extract_var($sub_fields, $k); } } } // append back to layouts $field['layouts'][$i] = $layout; } // return return $field; }
/** * @return array multidimensional list of custom fields definitions */ public function getCustomFieldDefinitions() { $fieldGroups = acf_get_field_groups(); $customFields = array(); foreach ($fieldGroups as $fieldGroup) { $fields = acf_get_fields($fieldGroup); $customFields[] = array('id' => $fieldGroup['key'], 'label' => $fieldGroup['title'], 'type' => 'group', 'field_definitions' => $this->getFieldDefinitions($fields)); } return $customFields; }
function load_field($field) { // vars $sub_fields = acf_get_fields($field); // append if ($sub_fields) { $field['sub_fields'] = $sub_fields; } // return return $field; }
function update_field_group($field_group) { // validate if (!acf_get_setting('json')) { return; } // get fields $field_group['fields'] = acf_get_fields($field_group); // save file acf_write_json_field_group($field_group); }
function widget($args, $instance) { $instance = (object) $instance; foreach (acf_get_field_groups(array('widget' => $this->identifier)) as $field_group) { foreach (acf_get_fields($field_group) as $field) { $name = $field['name']; $instance->{$name} = get_field($name, "widget_{$this->id}"); } } if (!empty($this->has_title)) { $instance->title = apply_filters('widget_title', empty($instance->title) ? '' : $instance->title, $instance, $this->id_base); } $this->render_widget($instance, $args); }
function load_field($field) { // min/max $field['min'] = (int) $field['min']; $field['max'] = (int) $field['max']; // vars $sub_fields = acf_get_fields($field); // append if ($sub_fields) { $field['sub_fields'] = $sub_fields; } // return return $field; }
/** * Import (overwrite) field groups into DB * @param string $params['name'] * @param string $params['group'] * @param string $params['old_value'] The previous settings data * @param string $params['new_value'] The new settings data */ function acf_pull($params) { $field_group = $params['new_value']; if ($existing_group = acf_get_field_group($field_group['key'])) { $field_group['ID'] = $existing_group['ID']; $existing_fields = acf_get_fields($existing_group); // Remove fields foreach ($existing_fields as $field) { wp_delete_post($field['ID'], true); } } // extract fields $fields = acf_extract_var($field_group, 'fields'); // format fields $fields = acf_prepare_fields_for_import($fields); // 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 $index => $field) { // add parent if (empty($field['parent'])) { $field['parent'] = $field_group['ID']; } else { if (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']; } }
public function display_settings() { $groups = acf_get_field_groups(false); $options = array(); foreach ($groups as $group_id => $group) { $fields = acf_get_fields($group); foreach ($fields as $field) { if (in_array($field['type'], array('tab'))) { continue; } if ('image_crop' == $field['type']) { $options[$field['key']] = $field['label']; } } } if ($options) { $this->display_field_select('cropper_field', 'Field', $options, ''); } }
static function get_json() { if (!function_exists('acf_get_field_group')) { echo 'You need ACF activated to use this screen'; exit; } $keys = isset($_GET['generate-template-id']) ? array($_GET['generate-template-id']) : array(); //print_r($keys); //exit; //$keys = $_GET['acf_export_keys']; //$keys = array('group_55e23ad63ecc3'); //$keys = array('group_55d38b033048e'); //$keys = array('group_55d26a506a990'); // validate if (empty($keys)) { return false; } // vars $json = array(); // construct JSON foreach ($keys as $key) { // load field group $field_group = acf_get_field_group($key); // validate field group if (empty($field_group)) { continue; } // load fields $field_group['fields'] = acf_get_fields($field_group); // prepare fields $field_group['fields'] = acf_prepare_fields_for_export($field_group['fields']); // extract field group ID $id = acf_extract_var($field_group, 'ID'); // add to json array $json[] = $field_group; } // return return $json; }
public function load_field($field) { global $wp_widget_factory; $widget = isset($field['value']) && isset($field['value']['the_widget']) ? $field['value']['the_widget'] : $field['widget']; // This is a chance for plugins to replace missing widgets $the_widget = !empty($wp_widget_factory->widgets[$widget]) ? $wp_widget_factory->widgets[$widget] : false; if (empty($the_widget)) { return $field; } // get any ACF field groups attached to the widget. $field_groups = acf_get_field_groups(array('widget' => $the_widget->id_base)); $field['sub_fields'] = array(); if (!empty($field_groups)) { foreach ($field_groups as $group) { $these_subfields = acf_get_fields($group); foreach ($these_subfields as $the_subfield) { $field['sub_fields'][] = $the_subfield; } } } return $field; }
function load_field($field) { $field['sub_fields'] = acf_get_fields($field); // return return $field; }
private function acf_get_field_groups() { $field_groups = acf_get_field_groups(); // ************************************************************************ // call wp_cache_delete on the field_groups cache added by ACF // fields groups added after a call to the function acf_get_field_groups // will not appear unless that cache is cleared // hoping that ACF will be corrected to handle this at some point // will remove this when it is wp_cache_delete('get_field_groups', 'acf'); // ************************************************************************ $count = count($field_groups); for ($i = 0; $i < $count; $i++) { // skip field group of it is a field group in this plugin if ($field_groups[$i]['key'] != 'group_acf_opt_grp_dup' && $field_groups[$i]['key'] != 'acf_options-page-details') { $fields = acf_get_fields($field_groups[$i]['key']); $field_groups[$i]['fields'] = $fields; $this->field_groups[$field_groups[$i]['key']] = $field_groups[$i]; } } }
function ajax_query() { // validate if (!acf_verify_ajax()) { die; } // disable field to allow clone fields to appear selectable acf_disable_filter('clone'); // options $options = acf_parse_args($_POST, array('post_id' => 0, 'paged' => 0, 's' => '', 'title' => '', 'fields' => array())); // vars $results = array(); $s = false; $i = -1; $limit = 20; $range_start = $limit * ($options['paged'] - 1); // 0, 20, 40 $range_end = $range_start + ($limit - 1); // 19, 39, 59 // search if ($options['s'] !== '') { // strip slashes (search may be integer) $s = wp_unslash(strval($options['s'])); } // load groups $field_groups = acf_get_field_groups(); $field_group = false; // bail early if no field groups if (empty($field_groups)) { die; } // move current field group to start foreach (array_keys($field_groups) as $j) { // check ID if ($field_groups[$j]['ID'] !== $options['post_id']) { continue; } // extract field group and move to start $field_group = acf_extract_var($field_groups, $j); // field group found, stop looking break; } // if field group was not found, this is a new field group (not yet saved) if (!$field_group) { $field_group = array('ID' => $options['post_id'], 'title' => $options['title'], 'key' => ''); } // move current field group to start of list array_unshift($field_groups, $field_group); // loop foreach ($field_groups as $field_group) { // vars $fields = false; $data = array('text' => $field_group['title'], 'children' => array()); // get fields if ($field_group['ID'] == $options['post_id']) { $fields = $options['fields']; } else { $fields = acf_get_fields($field_group); $fields = acf_prepare_fields_for_import($fields); } // bail early if no fields if (!$fields) { continue; } // populate children $children = array(); $children[] = $field_group['key']; foreach ($fields as $field) { $children[] = $field['key']; } // loop foreach ($children as $child) { // bail ealry if no key (fake field group or corrupt field) if (!$child) { continue; } // vars $text = false; // bail early if is search, and $text does not contain $s if ($s !== false) { // get early $text = $this->get_clone_setting_choice($child); // search if (stripos($text, $s) === false) { continue; } } // $i $i++; // bail early if $i is out of bounds if ($i < $range_start || $i > $range_end) { continue; } // load text if ($text === false) { $text = $this->get_clone_setting_choice($child); } // append $data['children'][] = array('id' => $child, 'text' => $text); } // bail early if no children // - this group contained fields, but none shown on this page if (empty($data['children'])) { continue; } // append $results[] = $data; // end loop if $i is out of bounds // - no need to look further if ($i > $range_end) { break; } } // return acf_send_ajax_results(array('results' => $results, 'limit' => $limit)); }
function acf_form($args = array()) { // vars $url = acf_get_current_url(); // defaults $args = wp_parse_args($args, array('id' => 'acf-form', 'post_id' => false, 'new_post' => false, 'field_groups' => false, 'fields' => false, 'post_title' => false, 'post_content' => false, 'form' => true, 'form_attributes' => array(), 'return' => add_query_arg('updated', 'true', $url), 'html_before_fields' => '', 'html_after_fields' => '', 'submit_value' => __("Update", 'acf'), 'updated_message' => __("Post updated", 'acf'), 'label_placement' => 'top', 'instruction_placement' => 'label', 'field_el' => 'div', 'uploader' => 'wp')); $args['form_attributes'] = wp_parse_args($args['form_attributes'], array('id' => 'post', 'class' => '', 'action' => '', 'method' => 'post')); // filter post_id $args['post_id'] = acf_get_valid_post_id($args['post_id']); // load values from this post $post_id = $args['post_id']; // new post? if ($post_id == 'new_post') { // dont load values $post_id = false; // new post defaults $args['new_post'] = acf_parse_args($args['new_post'], array('post_type' => 'post', 'post_status' => 'draft')); } // attributes $args['form_attributes']['class'] .= ' acf-form'; // vars $field_groups = array(); $fields = array(); // post_title if ($args['post_title']) { $fields[] = acf_get_valid_field(array('name' => '_post_title', 'label' => 'Title', 'type' => 'text', 'value' => $post_id ? get_post_field('post_title', $post_id) : '', 'required' => true)); } // post_content if ($args['post_content']) { $fields[] = acf_get_valid_field(array('name' => '_post_content', 'label' => 'Content', 'type' => 'wysiwyg', 'value' => $post_id ? get_post_field('post_content', $post_id) : '')); } // specific fields if ($args['fields']) { foreach ($args['fields'] as $selector) { // append field ($strict = false to allow for better compatibility with field names) $fields[] = acf_maybe_get_field($selector, $post_id, false); } } elseif ($args['field_groups']) { foreach ($args['field_groups'] as $selector) { $field_groups[] = acf_get_field_group($selector); } } elseif ($args['post_id'] == 'new_post') { $field_groups = acf_get_field_groups(array('post_type' => $args['new_post']['post_type'])); } else { $field_groups = acf_get_field_groups(array('post_id' => $args['post_id'])); } //load fields based on field groups if (!empty($field_groups)) { foreach ($field_groups as $field_group) { $field_group_fields = acf_get_fields($field_group); if (!empty($field_group_fields)) { foreach (array_keys($field_group_fields) as $i) { $fields[] = acf_extract_var($field_group_fields, $i); } } } } // updated message if (!empty($_GET['updated']) && $args['updated_message']) { echo '<div id="message" class="updated"><p>' . $args['updated_message'] . '</p></div>'; } // uploader (always set incase of multiple forms on the page) acf_update_setting('uploader', $args['uploader']); // display form if ($args['form']) { ?> <form <?php acf_esc_attr_e($args['form_attributes']); ?> > <?php } // render post data acf_form_data(array('post_id' => $args['post_id'], 'nonce' => 'acf_form')); ?> <div class="acf-hidden"> <?php acf_hidden_input(array('name' => '_acf_form', 'value' => base64_encode(json_encode($args)))); ?> </div> <div class="acf-fields acf-form-fields -<?php echo $args['label_placement']; ?> "> <?php // html before fields echo $args['html_before_fields']; // render acf_render_fields($post_id, $fields, $args['field_el'], $args['instruction_placement']); // html after fields echo $args['html_after_fields']; ?> </div><!-- acf-form-fields --> <?php if ($args['form']) { ?> <!-- Submit --> <div class="acf-form-submit"> <input type="submit" class="button button-primary button-large" value="<?php echo $args['submit_value']; ?> " /> <span class="acf-spinner"></span> </div> <!-- / Submit --> </form> <?php } }
function edit_attachment($form_fields, $post) { // vars $el = 'tr'; $post_id = $post->ID; $args = array('attachment' => 'All'); // $el if ($this->validate_page()) { //$el = 'div'; } // get field groups $field_groups = acf_get_field_groups($args); // render if (!empty($field_groups)) { // get acf_form_data ob_start(); acf_form_data(array('post_id' => $post_id, 'nonce' => 'attachment')); if ($this->validate_page()) { echo '<style type="text/css"> .compat-attachment-fields, .compat-attachment-fields > tbody, .compat-attachment-fields > tbody > tr, .compat-attachment-fields > tbody > tr > th, .compat-attachment-fields > tbody > tr > td { display: block; } tr.acf-field { display: block; margin: 0 0 13px; } tr.acf-field td.acf-label { display: block; margin: 0; } tr.acf-field td.acf-input { display: block; margin: 0; } </style>'; } // $el //if( $el == 'tr' ) { echo '</td></tr>'; //} foreach ($field_groups as $field_group) { $fields = acf_get_fields($field_group); acf_render_fields($post_id, $fields, $el, 'field'); } // $el //if( $el == 'tr' ) { echo '<tr class="compat-field-acf-blank"><td>'; //} $html = ob_get_contents(); ob_end_clean(); $form_fields['acf-form-data'] = array('label' => '', 'input' => 'html', 'html' => $html); } // return return $form_fields; }
/** * Get the fields for the given taxonomies * * @return array|null * @author Nicolas Juen */ private function get_fields() { if (!is_null($this->fields)) { return $this->fields; } // Empty the fields on the taxonomies if (empty($this->taxonomies)) { $this->fields = null; } foreach ($this->taxonomies as $taxonomy_name => $taxonomy) { $groups = acf_get_field_groups(array('taxonomy' => $taxonomy_name)); if (empty($groups)) { continue; } $fields = array(); foreach ($groups as $group) { $fields += acf_get_fields($group); } foreach ($fields as $field) { $this->fields[$taxonomy_name][$field['name']] = $field['key']; } } return $this->fields; }
function edit_term($term, $taxonomy) { // vars $post_id = "{$taxonomy}_{$term->term_id}"; $args = array('taxonomy' => $taxonomy); // update vars $this->form = '#edittag'; // get field groups $field_groups = acf_get_field_groups($args); // render if (!empty($field_groups)) { acf_form_data(array('post_id' => $post_id, 'nonce' => 'taxonomy')); foreach ($field_groups as $field_group) { $fields = acf_get_fields($field_group); ?> <?php if ($field_group['style'] == 'default') { ?> <h3><?php echo $field_group['title']; ?> </h3> <?php } ?> <table class="form-table"> <tbody> <?php acf_render_fields($post_id, $fields, 'tr', 'field'); ?> </tbody> </table> <?php } } }
public function post_field_groups($post_id) { $found = false; $cache = wp_cache_get('post_field_groups-' . $post_id, 'acfpost2post', false, $found); if ($found) { return $cache; } $args = array('post_id' => $post_id); $field_groups = acf_get_field_groups($args); //echo '<pre>'; print_r($field_groups); die; $count = count($field_groups); for ($i = 0; $i < $count; $i++) { $field_groups[$i]['fields'] = acf_get_fields($field_groups[$i]['key']); } //echo '<pre>'; print_r($field_groups); die; wp_cache_set('post_field_groups-' . $post_id, $field_groups, 'acfpost2post'); return $field_groups; }
function get_field_groups() { // options $options = acf_parse_args($_POST, array('nonce' => '', 'post_id' => 0, 'ajax' => 1)); // vars $r = array(); $nonce = acf_extract_var($options, 'nonce'); // verify nonce if (!wp_verify_nonce($nonce, 'acf_nonce')) { die; } // get field groups $field_groups = acf_get_field_groups($options); // loop through field groups and build $r if (!empty($field_groups)) { foreach ($field_groups as $field_group) { // vars $class = 'acf-postbox ' . $field_group['style']; // load fields $fields = acf_get_fields($field_group); // get field HTML ob_start(); // render if ($field_group['label_placement'] == 'left') { ?> <table class="acf-table"> <tbody> <?php acf_render_fields($options['post_id'], $fields, 'tr', $field_group['instruction_placement']); ?> </tbody> </table> <?php } else { acf_render_fields($options['post_id'], $fields, 'div', $field_group['instruction_placement']); } $html = ob_get_clean(); // get style $style = acf_get_field_group_style($field_group); // append to $r $r[] = array('key' => $field_group['key'], 'title' => $field_group['title'], 'html' => $html, 'style' => $style, 'class' => $class); } } // return wp_send_json_success($r); }
function get_json() { // validate if (empty($_POST['acf_export_keys'])) { return false; } // vars $json = array(); // construct JSON foreach ($_POST['acf_export_keys'] as $key) { // load field group $field_group = acf_get_field_group($key); // validate field group if (empty($field_group)) { continue; } // load fields $field_group['fields'] = acf_get_fields($field_group); // prepare fields $field_group['fields'] = acf_prepare_fields_for_export($field_group['fields']); // extract field group ID $id = acf_extract_var($field_group, 'ID'); // add to json array $json[] = $field_group; } // return return $json; }
<?php $groups = function_exists('acf_get_field_groups') ? acf_get_field_groups() : apply_filters('acf/get_field_groups', array()); $groups_param_values = $fields_params = array(); foreach ($groups as $group) { $id = isset($group['id']) ? 'id' : (isset($group['ID']) ? 'ID' : 'id'); $groups_param_values[$group['title']] = $group[$id]; $fields = function_exists('acf_get_fields') ? acf_get_fields($group[$id]) : apply_filters('acf/field_group/get_fields', array(), $group[$id]); $fields_param_value = array(); foreach ($fields as $field) { $fields_param_value[$field['label']] = (string) $field['key']; } $fields_params[] = array('type' => 'dropdown', 'heading' => __('Field name', 'js_composer'), 'param_name' => 'field_from_' . $group[$id], 'value' => $fields_param_value, 'description' => __('Select field from group.', 'js_composer'), 'dependency' => array('element' => 'field_group', 'value' => array((string) $group[$id]))); } return array('vc_gitem_acf' => array('name' => __('Advanced Custom Field', 'js_composer'), 'base' => 'vc_gitem_acf', 'icon' => 'vc_icon-acf', 'category' => __('Content', 'js_composer'), 'description' => __('Advanced Custom Field', 'js_composer'), 'php_class_name' => 'Vc_Gitem_Acf_Shortcode', 'params' => array_merge(array(array('type' => 'dropdown', 'heading' => __('Field group', 'js_composer'), 'param_name' => 'field_group', 'value' => $groups_param_values, 'description' => __('Select field group.', 'js_composer'))), $fields_params, array(array('type' => 'checkbox', 'heading' => __('Show label', 'js_composer'), 'param_name' => 'show_label', 'value' => array(__('Yes, please', 'js_composer') => 'yes'), 'description' => __('Enter label to display before key value.', 'js_composer')), array('type' => 'dropdown', 'heading' => __('Align', 'js_composer'), 'param_name' => 'align', 'value' => array(__('left', 'js_composer') => 'left', __('right', 'js_composer') => 'right', __('center', 'js_composer') => 'center', __('justify', 'js_composer') => 'justify'), 'description' => __('Select alignment.', 'js_composer')), array('type' => 'textfield', 'heading' => __('Extra class name', 'js_composer'), 'param_name' => 'el_class', 'description' => __('If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.', 'js_composer'))))));
function acf_untrash_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_untrash_field($field['ID']); } } // delete wp_untrash_post($field_group['ID']); // action for 3rd party customization do_action('acf/untrash_field_group', $field_group); // return return true; }
function add_comment() { // vars $post_id = "comment_0"; // get field groups $field_groups = acf_get_field_groups(array('comment' => 'new')); if (!empty($field_groups)) { // render post data acf_form_data(array('post_id' => $post_id, 'nonce' => 'comment')); foreach ($field_groups as $field_group) { $fields = acf_get_fields($field_group); ?> <table class="form-table"> <tbody> <?php acf_render_fields($post_id, $fields, 'tr', 'field'); ?> </tbody> </table> <?php } } }
function render($user_id, $user_form, $el = 'tr') { // vars $post_id = "user_{$user_id}"; $show_title = true; // show title if ($user_form === 'register') { $show_title = false; } // args $args = array('user_id' => 'new', 'user_form' => $user_form); if ($user_id) { $args['user_id'] = $user_id; } // get field groups $field_groups = acf_get_field_groups($args); // bail early if no field groups if (empty($field_groups)) { return; } // form data acf_form_data(array('post_id' => $post_id, 'nonce' => 'user')); // loop foreach ($field_groups as $field_group) { // vars $fields = acf_get_fields($field_group); // title if ($show_title && $field_group['style'] === 'default') { echo '<h2>' . $field_group['title'] . '</h2>'; } // table start if ($el == 'tr') { echo '<table class="form-table"><tbody>'; } // render fields acf_render_fields($post_id, $fields, $el, $field_group['instruction_placement']); // table end if ($el == 'tr') { echo '</tbody></table>'; } } }
function edit_widget($widget, $return, $instance) { // vars $post_id = 0; if ($widget->number !== '__i__') { $post_id = "widget_{$widget->id}"; } // get field groups $field_groups = acf_get_field_groups(array('widget' => $widget->id_base)); // render if (!empty($field_groups)) { // render post data acf_form_data(array('post_id' => $post_id, 'nonce' => 'widget')); foreach ($field_groups as $field_group) { $fields = acf_get_fields($field_group); acf_render_fields($post_id, $fields, 'div', 'field'); } if ($widget->updated) { ?> <script type="text/javascript"> (function($) { acf.do_action('append', $('[id^="widget"][id$="<?php echo $widget->id; ?> "]') ); })(jQuery); </script> <?php } } }
function render_meta_box($post, $args) { // extract args extract($args); // all variables from the add_meta_box function extract($args); // all variables from the args argument // vars $o = array('id' => $id, 'key' => $field_group['key'], 'style' => $field_group['style'], 'edit_url' => '', 'edit_title' => __('Edit field group', 'acf'), 'visibility' => true); // vars $post_id = acf_get_valid_post_id('options'); // load fields $fields = acf_get_fields($field_group); // render if ($field_group['label_placement'] == 'left') { ?> <table class="acf-table"> <tbody> <?php acf_render_fields($post_id, $fields, 'tr', $field_group['instruction_placement']); ?> </tbody> </table> <?php } else { acf_render_fields($post_id, $fields, 'div', $field_group['instruction_placement']); } // edit_url if ($field_group['ID'] && acf_current_user_can_admin()) { $o['edit_url'] = admin_url('post.php?post=' . $field_group['ID'] . '&action=edit'); } ?> <script type="text/javascript"> if( typeof acf !== 'undefined' ) { acf.postbox.render(<?php echo json_encode($o); ?> ); } </script> <?php }