$id, 'user_form' => $user_form, )); foreach($_field_groups as $_field_group){ if(in_array($_field_group['key'], $keys)) continue; $keys[] = $_field_group['key']; $field_groups[] = $_field_group; } } // attachment }elseif($type === 'attachment'){ $field_groups = acf_get_field_groups(array( 'attachment_id' => $id, 'attachment' => $id, )); // taxonomy }elseif($type === 'term'){ $term = get_term($id); if($term && !is_wp_error($term)){ $taxonomy = $term->taxonomy; $field_groups = acf_get_field_groups(array( 'taxonomy' => $taxonomy, 'term_id' => $id, )); } // post type }elseif($type === 'post'){ $post_type = get_post_type($post_id); $field_groups = acf_get_field_groups(array( 'post_id' => $post_id, 'post_type' => $post_type, )); // options page }elseif($type === 'option'){ // vars $keys = array(); $options_pages = array(); // get all options pages using the post id foreach(acf_get_options_pages() as $page){ if($page['post_id'] !== $id) continue; $options_pages[] = $page; } foreach($options_pages as $page){ $_field_groups = acf_get_field_groups(array( 'options_page' => $page['menu_slug'], )); foreach($_field_groups as $_field_group){ if(in_array($_field_group['key'], $keys)) continue; $keys[] = $_field_group['key']; $field_groups[] = $_field_group; } } // nav menu }elseif($type === 'menu'){ $field_groups = acf_get_field_groups(array( 'screen' => 'nav_menu', 'post_id' => $id, )); // user list }elseif($type === 'user_list'){ $field_groups = acf_get_field_groups(array( 'user_list' => 1, )); // attachment list }elseif($type === 'attachment_list'){ $field_groups = acf_get_field_groups(array( 'attachment_list' => 1, )); // post type list }elseif($type === 'post_type_list'){ $field_groups = acf_get_field_groups(array( 'post_type_list' => $post_type, )); // taxonomy list }elseif($type === 'taxonomy_list'){ $field_groups = acf_get_field_groups(array( 'taxonomy_list' => $taxonomy, )); // settings page }elseif($type === 'settings_page'){ $field_groups = acf_get_field_groups(array( 'wp_settings' => $post_id )); } return $field_groups; } /** * acfe_get_locations_array * * Legacy way to retrieve Field Groups Locations data in ACF 5.8 * * @param $locations * * @return array */ function acfe_get_locations_array($locations){ $return = array(); $types = acf_get_location_rule_types(); if(!$locations || !$types){ return $return; } $icon_default = 'admin-generic'; $icons = array( 'edit' => array( 'post_type', 'post_template', 'post_status', 'post_format', 'post', ), 'media-default' => array( 'page_template', 'page_type', 'page_parent', 'page', ), 'admin-users' => array( 'current_user', 'user_form', ), 'welcome-widgets-menus' => array( 'widget', 'nav_menu', 'nav_menu_item', ), 'category' => array( 'taxonomy', 'post_category', 'post_taxonomy', ), 'admin-comments' => array( 'comment', ), 'paperclip' => array( 'attachment', ), 'admin-settings' => array( 'options_page', ), 'businessman' => array( 'current_user_role', 'user_role', ), 'admin-appearance' => array( 'acfe_template' ) ); $rules = array(); foreach($types as $key => $type){ foreach($type as $slug => $name){ $icon = $icon_default; foreach($icons as $_icon => $icon_slugs){ if(!in_array($slug, $icon_slugs)){ continue; } $icon = $_icon; break; } $rules[ $slug ] = array( 'name' => $slug, 'label' => $name, 'icon' => $icon ); } } foreach($locations as $group){ if(!acf_maybe_get($rules, $group['param']) || !acf_maybe_get($group, 'value')){ continue; } // init $rule = $rules[ $group['param'] ]; // vars $icon = $rule['icon']; $name = $rule['name']; $label = $rule['label']; $operator = $group['operator'] === '==' ? '=' : $group['operator']; $value = $group['value']; // Exception for Post/Page/page Parent ID if(in_array($group['param'], array('post', 'page', 'page_parent'))){ $value = get_the_title((int) $value); }else{ // Validate value $values = acf_get_location_rule_values($group); if(!empty($values) && is_array($values)){ foreach($values as $value_slug => $value_name){ if($value != $value_slug){ continue; } $value = $value_name; if(is_array($value_name) && isset($value_name[$value_slug])){ $value = $value_name[$value_slug]; } break; } } } // html $title = $label . ' ' . $operator . ' ' . $value; $atts = array( 'class' => 'acf-js-tooltip dashicons dashicons-' . $icon, 'title' => $title ); if($operator === '!='){ $atts['style'] = 'color: #ccc;'; } $html = ''; $return[] = array( 'html' => $html, 'icon' => $icon, 'title' => $title, 'name' => $name, 'label' => $label, 'operator' => $operator, 'value' => $value, ); } return $return; } /** * acfe_render_field_group_locations_html * * Legacy way to display Field Groups Locations in ACF 5.8 * * @param $field_group */ function acfe_render_field_group_locations_html($field_group){ foreach($field_group['location'] as $groups){ $html = acfe_get_locations_array($groups); if($html){ $array = array(); foreach($html as $location){ $array[] = $location['html']; } echo implode(' ', $array); } } } /** * acfe_add_field_groups_metabox * * @param array $args */ function acfe_add_field_groups_metabox($args = array()){ $args = wp_parse_args($args, array( 'id' => 'acfe-field-groups', 'title' => __('Field Groups', 'acfe'), 'screen' => '', 'context' => 'normal', 'priority' => 'default', 'field_groups' => array(), )); add_meta_box($args['id'], $args['title'], function($object, $data) use($args){ $field_groups = $data['args']; acfe_render_field_groups_details($field_groups); ?> ' . __('edit'). ')' : ''; ?>

' . $field['name'] . '' : ''; $field_key = $field['key'] ? '' . $field['key'] . '' : ''; ?>