field, array( 'max' => 0, 'min' => 0, 'fields' => array(), 'button_title' => esc_html__( 'Add New', 'wpgp' ), 'accordion_title_prefix' => '', 'accordion_title_number' => false, 'accordion_title_auto' => true, ) ); $title_prefix = ( ! empty( $args['accordion_title_prefix'] ) ) ? $args['accordion_title_prefix'] : ''; $title_number = ( ! empty( $args['accordion_title_number'] ) ) ? true : false; $title_auto = ( ! empty( $args['accordion_title_auto'] ) ) ? true : false; if( ! empty( $this->parent ) && preg_match( '/'. preg_quote( '['. $this->field['id'] .']' ) .'/', $this->parent ) ) { echo '
'. esc_html__( 'Error: Nested field id can not be same with another nested field id.', 'wpgp' ) .'
'; } else { echo $this->field_before(); echo '
'; echo '
'; echo ''; echo ''; echo ''; echo '
'; echo '

'; echo ''; echo ( $title_number ) ? '' : ''; echo ( $title_prefix ) ? ''. $title_prefix .'' : ''; echo ( $title_auto ) ? '' : ''; echo ''; echo '

'; echo '
'; foreach ( $this->field['fields'] as $field ) { $field_parent = $this->parent .'['. $this->field['id'] .']'; $field_default = ( isset( $field['default'] ) ) ? $field['default'] : ''; WPGP::field( $field, $field_default, '_nonce', 'field/group', $field_parent ); } echo '
'; echo '
'; echo '
'; if( ! empty( $this->value ) ) { $num = 0; foreach ( $this->value as $value ) { $first_id = ( isset( $this->field['fields'][0]['id'] ) ) ? $this->field['fields'][0]['id'] : ''; $first_value = ( isset( $value[$first_id] ) ) ? $value[$first_id] : ''; echo '
'; echo '
'; echo ''; echo ''; echo ''; echo '
'; echo '

'; echo ''; echo ( $title_number ) ? ''. ( $num+1 ) .'.' : ''; echo ( $title_prefix ) ? ''. $title_prefix .'' : ''; echo ( $title_auto ) ? '' . $first_value . '' : ''; // echo ( $title_auto ) ? '' . array_values( $first_value )[0] .'' : ''; echo ''; echo '

'; echo '
'; foreach ( $this->field['fields'] as $field ) { $field_parent = $this->parent .'['. $this->field['id'] .']'; $field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']['. $num .']' : $this->field['id'] .'['. $num .']'; $field_value = ( isset( $field['id'] ) && isset( $value[$field['id']] ) ) ? $value[$field['id']] : ''; WPGP::field( $field, $field_value, $field_unique, 'field/group', $field_parent ); } echo '
'; echo '
'; $num++; } } echo '
'; echo '
'. esc_html__( 'You can not add more than', 'wpgp' ) .' '. $args['max'] .'
'; echo '
'. esc_html__( 'You can not remove less than', 'wpgp' ) .' '. $args['min'] .'
'; echo ''. $args['button_title'] .''; echo $this->field_after(); } } public function enqueue() { if( ! wp_script_is( 'jquery-ui-accordion' ) ) { wp_enqueue_script( 'jquery-ui-accordion' ); } if( ! wp_script_is( 'jquery-ui-sortable' ) ) { wp_enqueue_script( 'jquery-ui-sortable' ); } } } }