<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
    /**
     * Helper function to get a list of all supported forms.
     * @return array
     */
    function sifency_addons_get_all_forms() {
        $forms = ['' => __('Select a Form', 'sifency-addons')];
        // Contact Form 7
        if (class_exists('WPCF7_ContactForm')) {
            $cf7_forms = get_posts([
                'post_type'   => 'wpcf7_contact_form',
                'numberposts' => -1,
            ]);
            if ($cf7_forms) {
                foreach ($cf7_forms as $form) {
                    $forms['cf7-' . $form->ID] = '(CF7) ' . $form->post_title;
                }
            }
        }
        // WPForms
        if (function_exists('wpforms')) {
            $wpforms = wpforms()->form->get();
            if ($wpforms) {
                foreach ($wpforms as $form) {
                    $forms['wpf-' . $form->ID] = '(WPForms) ' . $form->post_title;
                }
            }
        }
        // MetForm
        if (post_type_exists('metform-form')) {
            $metforms = get_posts([
                'post_type'   => 'metform-form',
                'numberposts' => -1,
            ]);
            if ($metforms) {
                foreach ($metforms as $form) {
                    $forms['mf-' . $form->ID] = '(MetForm) ' . $form->post_title;
                }
            }
        }
        // Ninja Forms
        if (class_exists('Ninja_Forms')) {
            $ninja_forms = Ninja_Forms()->form()->get_forms();
            if ($ninja_forms) {
                foreach ($ninja_forms as $form) {
                    $forms['nf-' . $form->get_id()] = '(Ninja Forms) ' . $form->get_setting('title');
                }
            }
        }
        // Gravity Forms
        if (class_exists('GFAPI')) {
            $gf_forms = \GFAPI::get_forms();
            if ($gf_forms) {
                foreach ($gf_forms as $form) {
                    $forms['gf-' . $form['id']] = '(Gravity Forms) ' . $form['title'];
                }
            }
        }

        return $forms;
    }
