string, 'title' => string) */ public static function get_forms($integration_key) { switch ($integration_key) { case 'cf7': return self::get_cf7_forms(); case 'wpforms': return self::get_wpforms_forms(); case 'gravity_form': return self::get_gravity_forms(); case 'ninja_form': return self::get_ninja_forms(); case 'forminator_form': return self::get_forminator_forms(); case 'fluent_form': return self::get_fluent_forms(); case 'formidable_form': return self::get_formidable_forms(); case 'everest_form': return self::get_everest_forms(); case 'metform': return self::get_metform_forms(); default: return array(); } } private static function map_posts($posts) { $out = array(); foreach ($posts as $p) { $id = isset($p->ID) ? (string) $p->ID : null; $title = isset($p->post_title) ? $p->post_title : ''; if ($id === null || $id === '') continue; if ($title === '') $title = 'Form #' . $id; $out[] = array('id' => (string) $id, 'title' => $title); } return $out; } private static function query_forms_cpt($post_types) { if (!function_exists('get_posts')) return array(); $posts = get_posts(array( 'post_type' => $post_types, 'post_status' => array('publish', 'private', 'draft'), 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC', 'suppress_filters' => true, )); if (!is_array($posts)) return array(); return self::map_posts($posts); } private static function get_cf7_forms() { // Preferred: official CF7 API if (class_exists('WPCF7_ContactForm')) { try { if (method_exists('WPCF7_ContactForm', 'find')) { $found = WPCF7_ContactForm::find(array('posts_per_page' => -1)); if (is_array($found)) { $out = array(); foreach ($found as $form) { try { $id = method_exists($form, 'id') ? $form->id() : (isset($form->id) ? $form->id : null); $title = method_exists($form, 'title') ? $form->title() : ''; } catch (Exception $e) { continue; } if (empty($id)) continue; if ($title === '' || $title === null) $title = 'Form #' . $id; $out[] = array('id' => (string) $id, 'title' => $title); } return $out; } } } catch (Exception $e) { // fall through to CPT query } } return self::query_forms_cpt('wpcf7_contact_form'); } private static function get_wpforms_forms() { if (function_exists('wpforms') && method_exists(wpforms(), 'form')) { try { $forms = wpforms()->form->get('', array('fields' => false)); if (is_array($forms)) { $out = array(); foreach ($forms as $form) { $id = isset($form->ID) ? $form->ID : (isset($form['ID']) ? $form['ID'] : null); $title = isset($form->post_title) ? $form->post_title : (isset($form['post_title']) ? $form['post_title'] : ''); if (empty($id)) continue; if ($title === '' || $title === null) $title = 'Form #' . $id; $out[] = array('id' => (string) $id, 'title' => $title); } if (!empty($out)) return $out; } } catch (Exception $e) { // fall through } } return self::query_forms_cpt(array('wpforms')); } private static function get_gravity_forms() { if (class_exists('GFAPI') && method_exists('GFAPI', 'get_forms')) { try { $forms = GFAPI::get_forms(true, false); if (is_array($forms)) { $out = array(); foreach ($forms as $form) { $id = isset($form['id']) ? $form['id'] : null; $title = isset($form['title']) ? $form['title'] : ''; if (empty($id) && $id !== '0' && $id !== 0) continue; if ($title === '' || $title === null) $title = 'Form #' . $id; $out[] = array('id' => (string) $id, 'title' => $title); } return $out; } } catch (Exception $e) { return array(); } } return array(); } private static function get_ninja_forms() { if (function_exists('Ninja_Forms')) { try { $nf = Ninja_Forms(); if (is_object($nf) && method_exists($nf, 'form')) { $repo = $nf->form(); if (is_object($repo) && method_exists($repo, 'get_forms')) { $forms = $repo->get_forms(); if (is_array($forms)) { $out = array(); foreach ($forms as $form) { if (is_object($form)) { $id = method_exists($form, 'get_id') ? $form->get_id() : (isset($form->id) ? $form->id : null); $title = method_exists($form, 'get_setting') ? $form->get_setting('title') : (isset($form->title) ? $form->title : ''); } else { $id = isset($form['id']) ? $form['id'] : null; $title = isset($form['title']) ? $form['title'] : ''; } if (empty($id) && $id !== '0' && $id !== 0) continue; if ($title === '' || $title === null) $title = 'Form #' . $id; $out[] = array('id' => (string) $id, 'title' => $title); } return $out; } } } } catch (Exception $e) { return array(); } } // Fallback: custom table lookup (read-only) try { global $wpdb; if (isset($wpdb)) { $table = $wpdb->prefix . 'nf3_forms'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery $exists = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table)); if ($exists === $table) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery $rows = $wpdb->get_results("SELECT id, title FROM {$table} ORDER BY title ASC", ARRAY_A); if (is_array($rows)) { $out = array(); foreach ($rows as $row) { $title = isset($row['title']) && $row['title'] !== '' ? $row['title'] : 'Form #' . $row['id']; $out[] = array('id' => (string) $row['id'], 'title' => $title); } return $out; } } } } catch (Exception $e) { return array(); } return array(); } private static function get_forminator_forms() { if (class_exists('Forminator_API') && method_exists('Forminator_API', 'get_forms')) { try { // get_forms($form_type = null, $page = 1, $per_page = 10, $status = 'publish') $forms = Forminator_API::get_forms(null, 1, 100, 'publish'); if (is_array($forms)) { $out = array(); foreach ($forms as $form) { if (is_object($form)) { $id = isset($form->id) ? $form->id : null; $title = isset($form->name) ? $form->name : (isset($form->title) ? $form->title : ''); } else { $id = isset($form['id']) ? $form['id'] : null; $title = isset($form['name']) ? $form['name'] : (isset($form['title']) ? $form['title'] : ''); } if (empty($id) && $id !== '0' && $id !== 0) continue; if ($title === '' || $title === null) $title = 'Form #' . $id; $out[] = array('id' => (string) $id, 'title' => $title); } if (!empty($out)) return $out; } } catch (Exception $e) { // fall through to CPT query } } return self::query_forms_cpt(array('forminator_forms', 'forminator_form')); } private static function get_fluent_forms() { try { global $wpdb; if (isset($wpdb)) { $table = $wpdb->prefix . 'fluentform_forms'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery $exists = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table)); if ($exists === $table) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery $rows = $wpdb->get_results("SELECT id, title FROM {$table} ORDER BY title ASC", ARRAY_A); if (is_array($rows)) { $out = array(); foreach ($rows as $row) { $title = isset($row['title']) && $row['title'] !== '' ? $row['title'] : 'Form #' . $row['id']; $out[] = array('id' => (string) $row['id'], 'title' => $title); } return $out; } } } } catch (Exception $e) { return array(); } return array(); } private static function get_formidable_forms() { if (class_exists('FrmForm')) { try { if (method_exists('FrmForm', 'getAll')) { $forms = FrmForm::getAll(array(), 'name'); if (is_array($forms)) { $out = array(); foreach ($forms as $form) { $id = isset($form->id) ? $form->id : null; $title = isset($form->name) ? $form->name : ''; if (empty($id) && $id !== '0' && $id !== 0) continue; if ($title === '' || $title === null) $title = 'Form #' . $id; $out[] = array('id' => (string) $id, 'title' => $title); } if (!empty($out)) return $out; } } } catch (Exception $e) { // fall through to DB lookup } } // Fallback: Formidable stores forms in its own table (no CPT). try { global $wpdb; if (isset($wpdb)) { $table = $wpdb->prefix . 'frm_forms'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery $exists = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table)); if ($exists === $table) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery $rows = $wpdb->get_results("SELECT id, name FROM {$table} WHERE status <> 'trash' ORDER BY name ASC", ARRAY_A); if (is_array($rows)) { $out = array(); foreach ($rows as $row) { $title = isset($row['name']) && $row['name'] !== '' ? $row['name'] : 'Form #' . $row['id']; $out[] = array('id' => (string) $row['id'], 'title' => $title); } return $out; } } } } catch (Exception $e) { return array(); } return array(); } private static function get_everest_forms() { return self::query_forms_cpt(array('everest_form', 'everest-forms', 'evf_form')); } private static function get_metform_forms() { return self::query_forms_cpt(array('metform-form', 'metform_form')); } }