'Gravity Forms', 'wpforms' => 'WPForms', 'cf7' => 'Contact Form 7', 'fluent' => 'Fluent Forms', 'ninja' => 'Ninja Forms', 'elementor' => 'Elementor Pro Forms', ); const ENFORCED_PROVIDERS = array('gravity'); private static $forms = null; public static function is_enforced($surface) { $parsed = self::parse_surface($surface); if ($parsed === null) { return false; } return in_array($parsed['provider'], self::ENFORCED_PROVIDERS, true); } public static function enforcement_available() { return count(self::ENFORCED_PROVIDERS) > 0; } public static function surface($provider, $form_id) { $provider = strtolower((string) $provider); if (!isset(self::PROVIDERS[$provider])) { return ''; } if ('elementor' === $provider) { $id = strtolower(preg_replace('/[^A-Za-z0-9]/', '', (string) $form_id)); if ($id === '' || strlen($id) > 32) { return ''; } } else { $id = (int) $form_id; if ($id <= 0) { return ''; } $id = (string) $id; } return $provider . '_' . $id; } public static function provider_label($provider) { $provider = strtolower((string) $provider); return isset(self::PROVIDERS[$provider]) ? self::PROVIDERS[$provider] : $provider; } public static function is_canonical_surface($key) { $parsed = self::parse_surface($key); if ($parsed === null) { return false; } return self::surface($parsed['provider'], $parsed['form_id']) === (string) $key; } public static function parse_surface($key) { $key = (string) $key; $pos = strpos($key, '_'); if ($pos === false) { return null; } $provider = substr($key, 0, $pos); $id = substr($key, $pos + 1); if (!isset(self::PROVIDERS[$provider]) || $id === '') { return null; } return array('provider' => $provider, 'form_id' => $id); } public static function forms() { if (self::$forms !== null) { return self::$forms; } $out = array(); foreach (array('gravity', 'wpforms', 'cf7', 'fluent', 'ninja', 'elementor') as $provider) { $method = 'enumerate_' . $provider; try { foreach ((array) self::$method() as $row) { $surface = self::surface($provider, isset($row['form_id']) ? $row['form_id'] : ''); if ($surface === '') { continue; } $out[$surface] = array( 'provider' => $provider, 'form_id' => (string) $row['form_id'], 'title' => (string) (isset($row['title']) && $row['title'] !== '' ? $row['title'] : '#' . $row['form_id']), ); } } catch (Throwable $e) { if (function_exists('aieo_debug_log')) { aieo_debug_log('AIEO_Form_Registry: ' . $provider . ' enumeration failed: ' . $e->getMessage()); } } } self::$forms = $out; return $out; } private static function enumerate_gravity() { if (!class_exists('GFAPI')) { return array(); } global $wpdb; if (isset($wpdb) && is_object($wpdb)) { $table = (class_exists('GFFormsModel') && method_exists('GFFormsModel', 'get_form_table_name')) ? (string) GFFormsModel::get_form_table_name() : $wpdb->prefix . 'gf_form'; if ((string) $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table)) === $table) { $rows = $wpdb->get_results("SELECT id AS form_id, title FROM `{$table}` WHERE is_active = 1 AND is_trash = 0 ORDER BY id ASC LIMIT 500", ARRAY_A); if (is_array($rows)) { $out = array(); foreach ($rows as $r) { $out[] = array('form_id' => $r['form_id'], 'title' => $r['title']); } return $out; } } } $out = array(); if (class_exists('AIEO_Goal_Tracker') && method_exists('AIEO_Goal_Tracker', 'available_forms')) { foreach ((array) AIEO_Goal_Tracker::available_forms() as $row) { if (!is_array($row) || (isset($row['provider']) && $row['provider'] !== 'gravity')) { continue; } $out[] = array('form_id' => isset($row['form_id']) ? $row['form_id'] : 0, 'title' => isset($row['title']) ? $row['title'] : ''); } if ($out) { return $out; } } if (!class_exists('GFAPI')) { return array(); } foreach ((array) GFAPI::get_forms(true) as $f) { if (isset($f['id'])) { $out[] = array('form_id' => $f['id'], 'title' => isset($f['title']) ? $f['title'] : ''); } } return $out; } private static function enumerate_wpforms() { if (!post_type_exists('wpforms')) { return array(); } return self::enumerate_post_type('wpforms'); } private static function enumerate_cf7() { if (!post_type_exists('wpcf7_contact_form')) { return array(); } return self::enumerate_post_type('wpcf7_contact_form'); } private static function enumerate_fluent() { return self::enumerate_table('fluentform_forms', 'id', 'title'); } private static function enumerate_ninja() { return self::enumerate_table('nf3_forms', 'id', 'title'); } private static function enumerate_elementor() { return array(); } private static function enumerate_post_type($post_type) { $posts = get_posts(array( 'post_type' => $post_type, 'post_status' => array('publish', 'draft'), 'numberposts' => 200, 'orderby' => 'title', 'order' => 'ASC', 'suppress_filters' => true, 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, )); $out = array(); foreach ((array) $posts as $p) { $out[] = array('form_id' => $p->ID, 'title' => $p->post_title); } return $out; } private static function enumerate_table($suffix, $id_col, $title_col) { global $wpdb; if (!isset($wpdb) || !is_object($wpdb)) { return array(); } $table = $wpdb->prefix . $suffix; if ((string) $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table)) !== $table) { return array(); } $rows = $wpdb->get_results("SELECT `{$id_col}` AS form_id, `{$title_col}` AS title FROM `{$table}` ORDER BY `{$id_col}` ASC LIMIT 200", ARRAY_A); $out = array(); foreach ((array) $rows as $r) { $out[] = array('form_id' => $r['form_id'], 'title' => $r['title']); } return $out; } public static function creates_users() { $out = array(); if (class_exists('GFAPI')) { global $wpdb; $table = $wpdb->prefix . 'gf_addon_feed'; if ((string) $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table)) === $table) { $rows = $wpdb->get_results( $wpdb->prepare("SELECT form_id, meta FROM `{$table}` WHERE addon_slug = %s AND is_active = 1", 'gravityformsuserregistration'), ARRAY_A ); foreach ((array) $rows as $r) { $meta = json_decode((string) $r['meta'], true); if (!is_array($meta)) { continue; } if (isset($meta['feedType']) && 'create' === $meta['feedType']) { $surface = self::surface('gravity', $r['form_id']); if ($surface !== '') { $out[$surface] = true; } } } } } return $out; } public static function unassessed_providers() { $unknown = array(); foreach (self::forms() as $row) { if ('gravity' === $row['provider']) { continue; } $unknown[$row['provider']] = true; } return array_keys($unknown); } public static function elementor_present_but_unlisted() { return did_action('elementor_pro/init') > 0 || defined('ELEMENTOR_PRO_VERSION'); } }