Created
June 24, 2019 23:56
-
-
Save tareiking/f66171c29e4a3fef2e372fd2c21505a4 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 | |
add_action( 'cmb2_after_init', function() { | |
$metaboxes = \CMB2_Boxes::get_all(); | |
foreach ( $metaboxes as $cmb_id => $cmb ) { | |
?><?php echo PHP_EOL; | |
echo PHP_EOL; ?>***<?php echo PHP_EOL; | |
echo PHP_EOL; ?>## <?php echo esc_html( $cmb->meta_box['title'] ); ?><?php echo PHP_EOL; ?><table> | |
<tr> | |
<th> | |
Name | |
</th> | |
<th> | |
Pages | |
</th> | |
<th> | |
Id | |
</th> | |
<th> | |
Show On | |
</th> | |
</tr><?php | |
printf( '<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>', | |
esc_html( $cmb->meta_box['title'] ), | |
sc_array_to_li( $cmb->meta_box['object_types'] ), | |
esc_html( $cmb->meta_box['id'] ), | |
sc_array_to_li( $cmb->meta_box['show_on'] ) | |
); | |
?></table><?php echo PHP_EOL; ?><?php echo PHP_EOL; ?> | |
#### Fields<?php echo PHP_EOL; ?><?php echo sc_field_table( $cmb->meta_box['fields'] ); ?> | |
<?php | |
} | |
?> | |
<?php | |
exit; | |
}, PHP_INT_MAX ); | |
function sc_array_to_li( $data ) { | |
$data = (array) $data; | |
$str = '<ul>'; | |
foreach($data as $li){ | |
if ( is_array( $li ) ) { | |
$li = $li[0]; | |
} | |
$str .= '<li>' . esc_html($li) . '</li>'; | |
} | |
$str .= '</ul>'; | |
return $str; | |
} | |
function sc_field_table( $fields ){ | |
ob_start(); | |
$groups = []; | |
?><table> | |
<tr> | |
<th> | |
Name | |
</th> | |
<th> | |
Type | |
</th> | |
<th> | |
Repeatable | |
</th> | |
<th> | |
Sortable | |
</th> | |
</tr> | |
<?php | |
foreach ( $fields as $field ) { | |
printf( '<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>', | |
esc_html( $field['id'] ), | |
esc_html( $field['type'] ), | |
( isset( $field['repeatable'] ) ) ? '✅' : '', | |
( isset( $field['sortable'] ) ) ? '✅' : '' | |
); | |
if($field['type'] === 'group'){ | |
$groups[] = $field; | |
} | |
$unique_field_types[] = $field['type']; | |
} | |
?> | |
</table> | |
<?php | |
$content = ob_get_clean(); | |
foreach ($groups as $group){ | |
$content .= PHP_EOL . PHP_EOL . '### Group ' . $field['id'] . PHP_EOL . PHP_EOL . sc_field_table( $group['fields'] ); | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment