Skip to content

Instantly share code, notes, and snippets.

@lucasstark
Created February 9, 2016 15:08
Show Gist options
  • Save lucasstark/dbba39215b862b446f0e to your computer and use it in GitHub Desktop.
Save lucasstark/dbba39215b862b446f0e to your computer and use it in GitHub Desktop.
<?php
//this is very rough, but it works.
//add this to your functions file and navigate to your site http://yoururl.com/?acf-dump=1 then look in your footer area.
add_action( 'wp_footer', 'after_the_fact_documentation' );
function after_the_fact_documentation() {
if ( isset( $_GET['dump-acf'] ) ) {
$groups = acf_get_field_groups();
$object_types = array();
foreach ( $groups as $group ) {
if ( isset( $group['location'] ) ) {
foreach ( $group['location'] as $and ) {
foreach ( $and as $rule ) {
if ( $rule['operator'] == '==' ) {
if ( !isset( $object_types[$rule['param']] ) ) {
$object_types[$rule['param']] = array();
}
if ( !isset( $object_types[$rule['param']][$rule['value']] ) ) {
$object_types[$rule['param']][$rule['value']] = array();
}
$object_types[$rule['param']][$rule['value']][] = $group['key'];
}
}
}
}
}
}
echo '<ul>';
foreach ( $object_types as $object_type => $objects ) {
echo '<li>';
echo $object_type;
echo '<ul>';
foreach ( $objects as $object => $groups ) {
echo '<li>';
echo $object;
echo '<ul>';
foreach ( $groups as $group_key ) {
$acf_field_group = acf_get_field_group( $group_key );
$field_group_fields = acf_get_fields( $acf_field_group );
echo '<li>';
echo 'Group: ' . $acf_field_group['title'];
echo '<ul>';
if ( !empty( $field_group_fields ) ) {
echo '<li>';
echo 'Fields';
echo '<ul>';
foreach ( array_keys( $field_group_fields ) as $i ) {
$field = acf_extract_var( $field_group_fields, $i );
echo '<li>';
echo $field['label'] . ' : ' . acf_dump_get_field_type_label($field);
acf_dump_print_sub_fields( $field );
echo '</li>';
}
echo '</ul>';
echo '</li>';
}
echo '</ul>';
echo '</li>';
}
echo '</ul>';
echo '</li>';
}
echo '</ul>';
echo '</li>';
}
echo '</ul>';
die();
}
function acf_dump_print_sub_fields( $field ) {
if ( $field['type'] == 'repeater' ) {
echo '<ul>';
foreach ( $field['sub_fields'] as $sub_field ) {
echo '<li>';
echo $sub_field['label'] . ' : ' . acf_dump_get_field_type_label($sub_field);
acf_dump_print_sub_fields( $sub_field );
echo '</li>';
}
echo '</ul>';
} elseif ( $field['type'] == 'flexible_content' ) {
$layouts = array();
foreach ( $field['layouts'] as $k => $layout ) {
$layouts[$layout['name']] = acf_extract_var( $field['layouts'], $k );
}
echo '<ul>';
foreach ( $layouts as $layout ) {
echo '<li>';
echo $layout['name'];
echo '<ul>';
foreach ( $layout['sub_fields'] as $sub_field ) {
echo '<li>';
echo $sub_field['label'] . ' : ' . acf_dump_get_field_type_label($sub_field);
acf_dump_print_sub_fields( $sub_field );
echo '</li>';
}
echo '</ul>';
echo '</li>';
}
echo '</ul>';
}
}
function acf_dump_get_field_type_label( $field ) {
if ( acf_field_type_exists( $field['type'] ) ) {
return acf_get_field_type_label( $field['type'] );
} else {
return $field['type'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment