Skip to content

Instantly share code, notes, and snippets.

@jamesgol
Last active September 14, 2017 13:30
Show Gist options
  • Save jamesgol/abbf8ee1428236deccd080fadadc9fca to your computer and use it in GitHub Desktop.
Save jamesgol/abbf8ee1428236deccd080fadadc9fca to your computer and use it in GitHub Desktop.
Adding virtual Field Grouping to Pods
<?php
/*
* Add virtual Field Grouping to Pods
* This requires the PR from https://github.com/pods-framework/pods/pull/3548 which will hopefully be
* available in Pods 2.6.6
* James Golovich <james@gnuinter.net>
*/
add_filter( 'pods_admin_setup_edit_field_options', 'jmg_pods_admin_setup_edit_field_options', 10, 2 );
function jmg_pods_admin_setup_edit_field_options( $options, $pod ) {
$options[ 'advanced' ][ 'Visual' ][ 'backend_group' ] = array(
'name' => 'backend_group',
'label' => __( 'Field Group on backend editor', 'pods' ),
'help' => __( 'help', 'pods' ),
'type' => 'text',
'default' => 'More Fields'
);
return $options;
}
add_filter( 'pods_meta_groups_get', 'jmg_pods_meta_groups_get', 10, 3 );
function jmg_pods_meta_groups_get( $groups, $type, $name ) {
$new_groups = array();
foreach ( $groups as $group ) {
foreach ( $group[ 'fields' ] as $field ) {
if ( isset( $field[ 'options' ][ 'backend_group' ] ) ) {
$group_name = $field[ 'options' ][ 'backend_group' ];
} else {
$group_name = 'More Fields';
}
$new_groups[ $group_name ][ 'fields' ][ $field[ 'name' ] ] = $field;
// We don't really need to set the following every time, but it's easier than doing another loop afterwards
$new_groups[ $group_name ][ 'pod' ] = $group[ 'pod' ];
$new_groups[ $group_name ][ 'context' ] = $group[ 'context' ];
$new_groups[ $group_name ][ 'priority' ] = $group[ 'priority' ];
$new_groups[ $group_name ][ 'label' ] = $group_name;
}
}
return $new_groups;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment