Skip to content

Commit 6b06ea0

Browse files
authored
Fix missing field IDs when creating a form (#15)
1 parent 6ee6525 commit 6b06ea0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

includes/class-gf-cli-form.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,20 @@ function create( $args, $assoc_args ) {
241241
if ( isset( $args[1] ) ) {
242242
$form['description'] = $args[1];
243243
}
244+
245+
if ( ! isset( $form['fields'] ) ) {
246+
$form['fields'] = array();
247+
}
248+
249+
$field_ids = wp_list_pluck( $form['fields'], 'id' );
250+
$field_ids = array_map( 'absint', $field_ids );
251+
$next_field_id = max( $field_ids ) + 1;
252+
foreach( $form['fields'] as &$field ) {
253+
if ( ! isset( $field['id'] ) ) {
254+
$field['id'] = $next_field_id++;
255+
}
256+
}
257+
244258
} else {
245259
// Set the title based on the passed argument
246260
$title = $args[0];

0 commit comments

Comments
 (0)