|null */ private $types = null; /** * All field types. Built lazily so add-ons can hook the filter late. * * @return array */ public function all() { if ( null === $this->types ) { $types = array( new Text(), new Textarea(), new Email(), new Phone(), new Number(), new Url(), new Date(), new Name(), new Address(), new Select(), new Radio(), new Checkboxes(), new Consent(), new Hidden(), new Section(), new Html(), ); /** * Filters the registered field types. Add a FieldType instance to * register a new type. * * @param FieldType[] $types Field types. */ $types = apply_filters( 'fillaro/field_types', $types ); $this->types = array(); foreach ( $types as $type ) { if ( $type instanceof FieldType ) { $this->types[ $type->type() ] = $type; } } } return $this->types; } /** * Get a type by name. * * @param string $type Machine name. * @return FieldType|null */ public function get( $type ) { $all = $this->all(); return isset( $all[ $type ] ) ? $all[ $type ] : null; } }