*/ private static $fields = array(); /** * Whether the registry is already filled. * * @var bool */ private static $loaded = false; /** * Fills the registry. Done once per request, and lazily. * * @return void */ private static function load() { if ( self::$loaded ) { return; } self::$loaded = true; require_once RANQ_FORMS_DIR . 'includes/fields/abstract-ranq-forms-field.php'; require_once RANQ_FORMS_DIR . 'includes/fields/abstract-ranq-forms-field-choices.php'; require_once RANQ_FORMS_DIR . 'includes/fields/abstract-ranq-forms-field-input.php'; // The order here is the order in the builder. What is used most often first. $classes = array( 'Ranq_Forms_Field_Text' => 'class-ranq-forms-field-text.php', 'Ranq_Forms_Field_Textarea' => 'class-ranq-forms-field-textarea.php', 'Ranq_Forms_Field_Email' => 'class-ranq-forms-field-email.php', 'Ranq_Forms_Field_Number' => 'class-ranq-forms-field-number.php', 'Ranq_Forms_Field_Select' => 'class-ranq-forms-field-select.php', 'Ranq_Forms_Field_Checkbox' => 'class-ranq-forms-field-checkbox.php', 'Ranq_Forms_Field_Radio' => 'class-ranq-forms-field-radio.php', 'Ranq_Forms_Field_Imagechoice' => 'class-ranq-forms-field-imagechoice.php', 'Ranq_Forms_Field_Ranking' => 'class-ranq-forms-field-ranking.php', 'Ranq_Forms_Field_Name' => 'class-ranq-forms-field-name.php', 'Ranq_Forms_Field_Phone' => 'class-ranq-forms-field-phone.php', 'Ranq_Forms_Field_Address' => 'class-ranq-forms-field-address.php', 'Ranq_Forms_Field_Url' => 'class-ranq-forms-field-url.php', 'Ranq_Forms_Field_Date' => 'class-ranq-forms-field-date.php', 'Ranq_Forms_Field_Time' => 'class-ranq-forms-field-time.php', 'Ranq_Forms_Field_Password' => 'class-ranq-forms-field-password.php', 'Ranq_Forms_Field_Rating' => 'class-ranq-forms-field-rating.php', 'Ranq_Forms_Field_Signature' => 'class-ranq-forms-field-signature.php', 'Ranq_Forms_Field_File' => 'class-ranq-forms-field-file.php', 'Ranq_Forms_Field_Pagebreak' => 'class-ranq-forms-field-pagebreak.php', 'Ranq_Forms_Field_Content' => 'class-ranq-forms-field-content.php', 'Ranq_Forms_Field_Divider' => 'class-ranq-forms-field-content.php', 'Ranq_Forms_Field_Hidden' => 'class-ranq-forms-field-content.php', ); foreach ( $classes as $class => $file ) { require_once RANQ_FORMS_DIR . 'includes/fields/' . $file; /** * The field. * * @var Ranq_Forms_Field $field */ $field = new $class(); self::$fields[ $field->get_type() ] = $field; } /** * Adding fields from modules and from outside. * * The hook has been there since day one. A module that adds a field does * not touch the core. * * @param array $fields Fields by type. */ self::$fields = apply_filters( 'ranq_forms_fields', self::$fields ); } /** * Every field. * * @return array */ public static function all() { self::load(); return self::$fields; } /** * A single field by type, or null when that type does not exist. * * @param string $type The field type. * * @return Ranq_Forms_Field|null */ public static function get( $type ) { self::load(); $type = sanitize_key( $type ); return isset( self::$fields[ $type ] ) ? self::$fields[ $type ] : null; } /** * The fields of one form, the way they were saved. * * @param int $form_id The form id. * * @return array */ public static function get_form_fields( $form_id ) { $saved = get_post_meta( absint( $form_id ), '_ranq_forms_fields', true ); if ( ! is_array( $saved ) ) { return array(); } return $saved; } }