本文整理汇总了PHP中acf_get_field_groups函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_get_field_groups函数的具体用法?PHP acf_get_field_groups怎么用?PHP acf_get_field_groups使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acf_get_field_groups函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_visible_acf_fields
/**
* 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;
}
示例2: content
/**
* @param $atts
* @param null $content
*
* @return mixed|void
*/
protected function content($atts, $content = null)
{
$field_key = $label = '';
/**
* @var string $el_class
* @var string $show_label
* @var string $align
* @var string $field_group
*/
extract(shortcode_atts(array('el_class' => '', 'field_group' => '', 'show_label' => '', 'align' => ''), $atts));
if (0 === strlen($field_group)) {
$groups = function_exists('acf_get_field_groups') ? acf_get_field_groups() : apply_filters('acf/get_field_groups', array());
if (is_array($groups) && isset($groups[0])) {
$key = isset($groups[0]['id']) ? 'id' : (isset($groups[0]['ID']) ? 'ID' : 'id');
$field_group = $groups[0][$key];
}
}
if (!empty($field_group)) {
$field_key = !empty($atts['field_from_' . $field_group]) ? $atts['field_from_' . $field_group] : 'field_from_group_' . $field_group;
}
if ('yes' === $show_label && $field_key) {
$field_key .= '_labeled';
}
$css_class = 'vc_gitem-acf' . (strlen($el_class) ? ' ' . $el_class : '') . (strlen($align) ? ' vc_gitem-align-' . $align : '') . (strlen($field_key) ? ' ' . $field_key : '');
return '<div ' . $field_key . ' class="' . esc_attr($css_class) . '">' . '{{ acf' . (!empty($field_key) ? ':' . $field_key : '') . ' }}' . '</div>';
}
示例3: edit_widget
function edit_widget($widget, $return, $instance)
{
// vars
$post_id = 0;
// get id
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
}
}
}
示例4: getCustomFieldDefinitions
/**
* @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;
}
示例5: get_acf_field_groups
private function get_acf_field_groups()
{
$acf_field_groups = acf_get_field_groups();
wp_cache_delete('field_groups', 'acf');
if (count($acf_field_groups)) {
foreach ($acf_field_groups as $group) {
$this->acf_field_groups[$group['key']] = $group['key'];
}
// end foreach field group
}
// end if field groups
}
示例6: get_acf_field_groups
private function get_acf_field_groups()
{
$groups = array();
$acf_groups = acf_get_field_groups();
if (!count($acf_groups)) {
return;
}
foreach ($acf_groups as $group) {
$groups[$group['key']] = $group['key'];
}
return $groups;
}
示例7: widget
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);
}
示例8: get_acf_field_groups
private function get_acf_field_groups()
{
$groups = array();
$acf_groups = acf_get_field_groups();
if (!count($acf_groups)) {
return;
}
foreach ($acf_groups as $group) {
$groups[$group['key']] = $group['key'];
}
// need to delete the ACF field group cache
wp_cache_delete('get_field_groups', 'acf');
return $groups;
}
示例9: display_settings
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, '');
}
}
示例10: load_field
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;
}
示例11: content
/**
* @param $atts
* @param null $content
*
* @return mixed|void
*/
protected function content($atts, $content = null)
{
$atts = $atts + vc_map_get_attributes($this->getShortcode(), $atts);
$field_group = $atts['field_group'];
$field_key = '';
if (0 === strlen($atts['field_group'])) {
$groups = function_exists('acf_get_field_groups') ? acf_get_field_groups() : apply_filters('acf/get_field_groups', array());
if (is_array($groups) && isset($groups[0])) {
$key = isset($groups[0]['id']) ? 'id' : (isset($groups[0]['ID']) ? 'ID' : 'id');
$field_group = $groups[0][$key];
}
}
if ($field_group) {
$field_key = !empty($atts['field_from_' . $field_group]) ? $atts['field_from_' . $field_group] : 'field_from_group_' . $field_group;
}
$css_class = array();
$css_class[] = 'vc_acf';
if ($atts['el_class']) {
$css_class[] = $atts['el_class'];
}
if ($atts['align']) {
$css_class[] = 'vc_txt_align_' . $atts['align'];
}
$value = '';
if ($field_key) {
$css_class[] = $field_key;
$value = do_shortcode('[acf field="' . $field_key . '" post_id="' . get_the_ID() . '"]');
if ($atts['show_label']) {
$field = get_field_object($field_key);
$label = is_array($field) && isset($field['label']) ? '<span class="vc_acf-label">' . $field['label'] . ':</span> ' : '';
$value = $label . $value;
}
}
$css_string = implode(' ', $css_class);
$output = '<div class="' . esc_attr($css_string) . '">' . $value . '</div>';
return $output;
}
示例12: get_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;
}
示例13: get_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);
}
示例14: get_acf_field_groups
function get_acf_field_groups()
{
$found = false;
$cache = wp_cache_get('acf_reusable/acf_field_groups', 'acf_resuable', false, $found);
if ($found) {
$this->field_groups = $cache;
return;
} else {
// look in acf-json
$json_path = plugin_dir_path(__FILE__) . 'acf-json';
if (!is_dir($json_path)) {
@mkdir($json_path);
}
if (is_multisite()) {
$json_path .= '/' . get_current_blog_id();
if (!is_dir($json_path)) {
@mkdir($json_path);
}
}
$object_path = $json_path . '/acf_field_groups.json';
if (is_dir($json_path) && file_exists($object_path)) {
$json = @file_get_contents($object_path);
if ($json !== false) {
$object = json_decode($json, true);
if ($object !== NULL) {
$this->field_groups = $object;
}
}
return;
}
// end if is_dir etc
}
// end if else
$field_groups = acf_get_field_groups();
$count = count($field_groups);
for ($i = 0; $i < $count; $i++) {
$fields = acf_get_fields($field_groups[$i]['key']);
$field_groups[$i]['fields'] = $fields;
$this->field_groups[$field_groups[$i]['key']] = $field_groups[$i];
}
wp_cache_set('acf_reusable/acf_field_groups', $this->field_groups, 'acf_resuable');
// store json file to avoid using acf_get_field_groups unless necessary
$json_path = plugin_dir_path(__FILE__) . 'acf-json';
if (!is_dir($json_path)) {
@mkdir($json_path);
}
if (is_multisite()) {
$json_path .= '/' . get_current_blog_id();
if (!is_dir($json_path)) {
@mkdir($json_path);
}
}
if (($handle = @fopen($json_path . '/acf_field_groups.json', 'w')) !== false) {
$json = json_encode($this->field_groups);
fwrite($handle, $json, strlen($json));
fclose($handle);
}
$this->clear_acf_cache();
}
示例15: check_sync
function check_sync()
{
// message
if ($ids = acf_maybe_get($_GET, 'acfsynccomplete')) {
// explode
$ids = explode(',', $ids);
$total = count($ids);
if ($total == 1) {
acf_add_admin_notice(sprintf(__('Field group synchronised. %s', 'acf'), '<a href="' . get_edit_post_link($ids[0]) . '">' . get_the_title($ids[0]) . '</a>'));
} else {
acf_add_admin_notice(sprintf(_n('%s field group synchronised.', '%s field groups synchronised.', $total, 'acf'), $total));
}
}
// vars
$groups = acf_get_field_groups();
// bail early if no field groups
if (empty($groups)) {
return;
}
// find JSON field groups which have not yet been imported
foreach ($groups as $group) {
// vars
$local = acf_maybe_get($group, 'local', false);
$modified = acf_maybe_get($group, 'modified', 0);
$private = acf_maybe_get($group, 'private', false);
// ignore DB / PHP / private field groups
if ($local !== 'json' || $private) {
// do nothing
} elseif (!$group['ID']) {
$this->sync[$group['key']] = $group;
} elseif ($modified && $modified > get_post_modified_time('U', true, $group['ID'], true)) {
$this->sync[$group['key']] = $group;
}
}
// bail if no sync needed
if (empty($this->sync)) {
return;
}
// import field group
if ($key = acf_maybe_get($_GET, 'acfsync')) {
// disable JSON
// - this prevents a new JSON file being created and causing a 'change' to theme files - solves git anoyance
acf_update_setting('json', false);
// validate
check_admin_referer('bulk-posts');
// append fields
if (acf_have_local_fields($key)) {
$this->sync[$key]['fields'] = acf_get_local_fields($key);
}
// import
$field_group = acf_import_field_group($this->sync[$key]);
// redirect
wp_redirect(admin_url($this->url . '&acfsynccomplete=' . $field_group['ID']));
exit;
} elseif (acf_maybe_get($_GET, 'action2') === 'acfsync') {
// validate
check_admin_referer('bulk-posts');
// get ids
$keys = acf_maybe_get($_GET, 'post');
if (!empty($keys)) {
// disable JSON
// - this prevents a new JSON file being created and causing a 'change' to theme files - solves git anoyance
acf_update_setting('json', false);
// vars
$new_ids = array();
foreach ($keys as $key) {
// append fields
if (acf_have_local_fields($key)) {
$this->sync[$key]['fields'] = acf_get_local_fields($key);
}
// import
$field_group = acf_import_field_group($this->sync[$key]);
// append
$new_ids[] = $field_group['ID'];
}
// redirect
wp_redirect(admin_url($this->url . '&acfsynccomplete=' . implode(',', $new_ids)));
exit;
}
}
// filters
add_filter('views_edit-acf-field-group', array($this, 'list_table_views'));
}