Created
October 25, 2013 20:36
-
-
Save spivurno/7161427 to your computer and use it in GitHub Desktop.
Gravity Wiz // Gravity Forms Field Info Tab
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 | |
/** | |
* Gravity Forms Field Info Tab | |
* http://gravitywiz.com | |
* | |
* Adds a summary of your fields as a tab on the form settings screen; includes field ID, label and field type. | |
* | |
*/ | |
class GWFieldInfo { | |
public function __construct() { | |
add_filter( 'gform_form_settings_menu', array( $this, 'my_custom_form_settings_menu_item' ) ); | |
add_action( 'gform_form_settings_page_gw_field_info', array( $this, 'my_custom_form_settings_page' ) ); | |
} | |
public function my_custom_form_settings_menu_item( $menu_items ) { | |
$menu_items[] = array( | |
'name' => 'gw_field_info', | |
'label' => __( 'Field Info' ) | |
); | |
return $menu_items; | |
} | |
public function my_custom_form_settings_page() { | |
$tabs = $this->my_custom_form_settings_menu_item( array() ); | |
$current_tab = $tabs[0]; | |
GFFormSettings::page_header( $current_tab['label'] ); | |
$form = GFFormsModel::get_form_meta( rgget( 'id' ) ); | |
$inputs = array(); | |
foreach( $form['fields'] as $field ) { | |
$type = $field['type']; | |
$input_type = GFFormsModel::get_input_type( $field ); | |
$label = GFCommon::get_label( $field ); | |
if( ! $label ) | |
$label = '<span class="no-label">' . __( 'No label' ) . '</span>'; | |
$label .= ' <span class="input-type">' . GFCommon::get_field_type_title( $input_type ) . '</span>'; | |
if( $type != $input_type ) | |
$label .= ' <span class="type">' . GFCommon::get_field_type_title( $type ) . '</span>'; | |
array_push( $inputs, (object) array( | |
'id' => $field['id'], | |
'parent' => 0, | |
'label' => $label | |
) ); | |
if( ! is_array( $field['inputs'] ) ) | |
continue; | |
foreach( $field['inputs'] as $input ) { | |
array_push( $inputs, (object) array( | |
'id' => $input['id'], | |
'parent' => $field['id'], | |
'label' => GFCommon::get_label( $field, $input['id'], true ) | |
) ); | |
} | |
} | |
$walker = new Walker_GWFieldInfo(); | |
?> | |
<style type="text/css"> | |
#gwfi-fields { border-top: 1px solid #eee; } | |
#gwfi-fields li { margin: 0; border-bottom: 1px solid #eee; line-height: 2; padding: 3px 10px; } | |
#gwfi-fields li:nth-child(odd) { background-color: #f7f7f7; } | |
#gwfi-fields li:nth-child(even) li { background-color: #fff; } | |
#gwfi-fields ul { margin: 3px -10px -4px; border-top: 1px solid #eee; } | |
#gwfi-fields ul li { xpadding-left: 50px; } | |
#gwfi-fields span.gwfi-id { width: 40px; display: inline-block; color: #555; font-weight: bold; } | |
#gwfi-fields ul span.gwfi-id { font-weight: normal; } | |
#gwfi-fields ul span.gwfi-label:before { content: "\2014"; padding-right: 8px; color: #999; } | |
#gwfi-fields span.type, | |
#gwfi-fields span.input-type { color: #888; display: inline-block; float: right; font-size: 11px; | |
padding: 2px 0 0; text-transform: uppercase; } | |
#gwfi-fields span.type:after { content: "/"; padding: 0 5px; } | |
#gwfi-fields span.no-label { color: #aaa; font-style: italic; } | |
</style> | |
<ul id="gwfi-fields"> | |
<?php echo $walker->walk( $inputs, 2 ); ?> | |
</ul> | |
<?php | |
GFFormSettings::page_footer(); | |
} | |
} | |
class Walker_GWFieldInfo extends Walker { | |
var $tree_type = false; | |
var $db_fields = array( 'parent' => 'parent', 'id' => 'id' ); | |
function start_lvl( &$output, $depth = 0, $args = array() ) { | |
$output .= '<ul>'; | |
} | |
function end_lvl( &$output, $depth = 0, $args = array() ) { | |
$output .= '</ul>'; | |
} | |
function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { | |
$output .= '<li id="gwfi-row-' . $object->id . '"><span class="gwfi-id">' . $object->id . '</span><span class="gwfi-label">' . $object->label . '</span>'; | |
} | |
function end_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { | |
$output .= '</li>'; | |
} | |
} | |
new GWFieldInfo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment