Forked from lucasstark/acf-field-group-documentor.php
Last active
February 9, 2016 16:08
-
-
Save isotrope/e04b09bd09e48e67f10f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// based on https://gist.github.com/lucasstark/dbba39215b862b446f0e | |
//this is very rough, but it works. | |
//add this to your functions file and navigate to your site http://yoururl.com/?dump-acf=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']; | |
} | |
} | |
} | |
} | |
} | |
} | |
if ( ! empty( $object_types ) ) { | |
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 ) . ' [<span style="font-family: Monaco, Consolas, monospace;">' . $field['name'] . '</span>]'; | |
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 ) . ' [<span style="font-family: Monaco, Consolas, monospace;">' . $sub_field['name'] . '</span>]' ; | |
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 ) . ' [<span style="font-family: Monaco, Consolas, monospace;">' . $sub_field['name'] . '</span>]'; | |
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