Form::prepare()
Description #
Prepare input field.
Source #
File: lib/class-form.php
public function prepare() {
if ( empty( $this->args['fields'] ) ) {
return $this;
}
$fields = ap_sort_array_by_order( $this->args['fields'] );
if ( ! ap_opt( 'allow_private_posts' ) && isset( $fields['is_private'] ) ) {
unset( $fields['is_private'] );
}
foreach ( $fields as $field_name => $field_args ) {
if ( empty( $field_args['type'] ) ) {
$field_args['type'] = 'input';
}
$type_class = ucfirst( trim( $field_args['type'] ) );
$field_class = 'AnsPress\\Form\\Field\\' . $type_class;
if ( class_exists( $field_class ) ) {
/**
* Allows filtering field argument before its being passed to Field class.
*
* @param array $field_args Field arguments.
* @param object $form Form class, passed by reference.
* @since 4.1.0
*/
$field_args = apply_filters_ref_array( 'ap_before_prepare_field', array( $field_args, $this ) );
$this->fields[ $field_name ] = new $field_class( $this->form_name, $field_name, $field_args, $this );
}
}
$this->prepared = true;
$this->sanitize_validate();
return $this;
}
Expand full source code Collapse full source code View on GitHub: lib/class-form.php:125
Add your comment