public function __construct( $args ) {
...
$this->fields = $this->normalize_fields( $args['fields'] );
...
}
...
public function normalize_fields( $fields ) {
$normalized = array();
foreach ( $fields as $field ) {
$normalized[] = array_merge( array( 'name' => '', 'desc' => '', ... ), $field );
}
return $normalized;
}
Doing this would help suppress undefined index notices caused on lines such as this one, where $field['required'] may not have been set in the original fields array passed to the constructor.
Ideally, instead of
$this->fields
being assigned the raw fields array passed to it, the assigned fields array should be normalized and assigned a set of default supported key/value pairs, e.g.Doing this would help suppress undefined index notices caused on lines such as this one, where
$field['required']
may not have been set in the original fields array passed to the constructor.