settings)) { return []; } // Only ordinary contact forms. Registration, login and quiz leads have // different side effects and must not be advertised as protected. if (!in_array($form->settings['form-type'] ?? 'default', ['default'], true)) { return []; } if (filter_var($form->settings['use_save_and_continue'] ?? false, FILTER_VALIDATE_BOOLEAN) || !empty($form->settings['abandonment'])) { return []; } try { $fields = []; foreach ($form->get_fields() as $field) { $schema = $field->to_array(); $type = $schema['type'] ?? ''; if (in_array($type, ['stripe', 'stripe-ocs', 'paypal', 'postdata', 'password', 'group'], true)) { return []; } $key = $schema['element_id'] ?? ''; if (is_string($key) && preg_match('/^[a-zA-Z0-9_-]{1,100}$/', $key) && in_array($type, ['text', 'textarea', 'email'], true)) { $fields[$key] = is_string($schema['field_label'] ?? null) ? $schema['field_label'] : $key; } } return $fields; } catch (\Throwable $error) { return []; } } public static function available(int $limit): array { if ($limit < 1 || !class_exists('Forminator_Form_Model')) { return []; } $available = []; foreach (get_posts(['post_type' => 'forminator_forms', 'post_status' => 'publish', 'numberposts' => $limit, 'orderby' => 'ID', 'order' => 'ASC']) as $post) { $fields = self::fields(self::model((int) $post->ID)); if ($fields) { $available['forminator_' . (int) $post->ID] = ['title' => 'Forminator:' . $post->post_title, 'fields' => $fields]; } } return $available; } }