Created
December 11, 2013 15:04
-
-
Save jameslaws/7911909 to your computer and use it in GitHub Desktop.
Group Fields in Ninja Forms This code allows you to group fields by adding the nf-open-field-group to the first field in a group and nf-close-field-group to the last field in a group. Fields must already be in proper order.
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 | |
function nfjal_open_field_group( $field_id, $data ) { | |
if ( !$class = $data['class'] ) { | |
$class = ''; | |
} | |
if ( strstr( $class, 'nf-open-field-group' ) ) { | |
$class = nfjal_get_group_wrap_class( $class ); | |
echo '<div class="' . $class . '">'; | |
} | |
} | |
add_action( 'ninja_forms_display_before_opening_field_wrap', 'nfjal_open_field_group', 10, 2 ); | |
function nfjal_close_field_group( $field_id, $data ) { | |
if ( !$class = $data['class'] ) { | |
$class = ''; | |
} | |
if ( strstr( $class, 'nf-close-field-group' ) ) { | |
echo '</div>'; | |
} | |
} | |
add_action( 'ninja_forms_display_after_closing_field_wrap', 'nfjal_close_field_group', 10, 2 ); | |
function nfjal_get_group_wrap_class( $class ) { | |
$class = str_replace( '-group', '', $class ); | |
$class = str_replace( '-open', '', $class ); | |
$x = 0; | |
$custom_class = ''; | |
if ( isset( $class ) AND !empty( $class ) ) { | |
$class_array = explode(" ", $class ); | |
foreach($class_array as $class){ | |
$custom_class .= $class; | |
if($x != (count($class_array) - 1)){ | |
$custom_class .= " "; | |
} | |
$x++; | |
} | |
} | |
if($custom_class != ''){ | |
$custom_class = str_replace( ' ', '-group ', $custom_class ); | |
$field_wrap_class .= ' ' . $custom_class . '-group'; | |
} | |
return $field_wrap_class; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment