UCF / WP-Shortcode-Interface

Creates a shortcode interface that provides a form for inserting and updating shortcodes.
0 stars 0 forks source link

Normalize field options/fix undefined index notices #14

Closed cjg89 closed 7 years ago

cjg89 commented 7 years ago

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.

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.

cjg89 commented 7 years ago

Resolved in #16. Closing issue