false]) : $value; } } if (!function_exists('forge_kses_credit_badge')) { /** * Allowed-HTML list for echoing trusted, self-built credit-cost badge and * AI-button inner markup at output time (covers the inline SVG icon that * wp_kses_post would strip). Every dynamic value in that markup is * already esc_attr'd / integer-cast by its builder; this is the late- * escape gate. */ function forge_kses_credit_badge() { $attr = array( 'class' => true, 'style' => true, 'title' => true, 'id' => true, 'role' => true, 'aria-hidden' => true, 'aria-label' => true, 'data-cost' => true, 'data-action' => true, 'data-slug' => true, // BUG-FORM-AI-02: the attribute the shared script reads to refresh the number from the live price list. 'data-forge-cost-action' => true, // The sum badge (Forge_Wporg_Disabled_Credits::render_badge_sum_html) lists its actions here. 'data-forge-cost-action-sum' => true, ); return array( 'span' => $attr, 'strong' => $attr, 'small' => $attr, 'b' => $attr, 'em' => $attr, 'svg' => array('class'=>true,'style'=>true,'width'=>true,'height'=>true,'viewbox'=>true,'fill'=>true,'stroke'=>true,'xmlns'=>true,'aria-hidden'=>true,'role'=>true,'focusable'=>true), // The diamond of the badge icon: . 'polygon' => array('points'=>true,'fill'=>true,'stroke'=>true,'stroke-width'=>true,'opacity'=>true), 'path' => array('d'=>true,'fill'=>true,'fill-rule'=>true,'clip-rule'=>true,'stroke'=>true,'stroke-width'=>true,'stroke-linecap'=>true,'stroke-linejoin'=>true,'opacity'=>true), 'g' => array('fill'=>true,'stroke'=>true,'transform'=>true), 'circle' => array('cx'=>true,'cy'=>true,'r'=>true,'fill'=>true,'stroke'=>true), 'rect' => array('x'=>true,'y'=>true,'width'=>true,'height'=>true,'rx'=>true,'fill'=>true), ); } } require_once FORMFORGE_DIR . 'includes/kses-form-fields.php'; // Pro Bridge — the Free side of the Free/Pro extension contract. // Loaded before any other class so License + everything downstream can // consult it. See SPLIT_PLAN.md §5.3. require_once FORMFORGE_DIR . 'includes/class-pro-bridge.php'; FORMFORGE_Pro_Bridge::instance(); // The shared licence resolver is not loaded here: the licence layer is the Pro // add-on's alone, and the add-on carries its own copy of that file. // Forge Queue — shared job queue (first plugin to load wins) if (!class_exists('Forge_Queue')) { require_once __DIR__ . '/includes/class-forge-queue.php'; } // Shared transactional email renderer (first Forge plugin to load wins). if (!class_exists('Forge_Email_Template')) { require_once __DIR__ . '/includes/class-forge-email.php'; } // Shared SSRF-safe wp_remote_* wrapper (first Forge plugin to load wins). if (!class_exists('Forge_Net')) { require_once __DIR__ . '/includes/class-forge-net.php'; } // Shared opt-in telemetry (first Forge plugin to load wins). Off by default — // nothing is sent without explicit consent. See class-forge-telemetry.php. if (!class_exists('Forge_Telemetry') && file_exists(FORMFORGE_DIR . 'includes/class-forge-telemetry.php')) { require_once FORMFORGE_DIR . 'includes/class-forge-telemetry.php'; } if (class_exists('Forge_Telemetry')) { Forge_Telemetry::watch_plugin_errors(FORMFORGE_DIR); register_activation_hook(__FILE__, ['Forge_Telemetry', 'on_activate']); register_deactivation_hook(__FILE__, ['Forge_Telemetry', 'on_deactivate']); } spl_autoload_register(function ($class) { if (strpos($class, 'FORMFORGE_') !== 0) return; $name = strtolower(str_replace('_', '-', str_replace('FORMFORGE_', '', $class))); foreach (['includes/', 'admin/'] as $dir) { $f = FORMFORGE_DIR . $dir . 'class-' . $name . '.php'; if (file_exists($f)) { require_once $f; return; } } }); function formforge_init() { // WP 4.6+ loads a plugin's translations from WP_LANG_DIR on its own, so the // wp.org build — which ships only the .pot — needs nothing registered here // and registering a path by hand would be dead weight. The Avakode channel // does bundle catalogs in the plugin's own languages/ folder; load one // directly, and only when the community pack does not already cover the // locale, so a reviewed translation always wins over a bundled one. $ff_locale = determine_locale(); if (!is_readable(WP_LANG_DIR . '/plugins/fillinforge-' . $ff_locale . '.mo')) { $ff_bundled_mo = FORMFORGE_DIR . 'languages/fillinforge-' . $ff_locale . '.mo'; if (is_readable($ff_bundled_mo)) { load_textdomain('fillinforge', $ff_bundled_mo); } } // Shared Forge UI (class-forge-*.php) uses the 'forge' textdomain — alias it // to this plugin's own compiled catalog so the shared dashboard/credits/ // connect/feedback/updater strings translate (they're extracted into this // plugin's .po/.mo too). Without this, 'forge' loads nowhere → English-only. // Prefer the community language pack from translate.wordpress.org when one // exists: WordPress installs it into WP_LANG_DIR/plugins/ and it already // overrides our bundled catalog for the 'formforge' textdomain, so reading the // bundled file here would alias 'forge' to an older, unreviewed translation. $forge_locale = $ff_locale; $ff_forge_mo = WP_LANG_DIR . '/plugins/fillinforge-' . $forge_locale . '.mo'; if (!is_readable($ff_forge_mo)) { $ff_forge_mo = FORMFORGE_DIR . 'languages/fillinforge-' . $forge_locale . '.mo'; } if (is_readable($ff_forge_mo)) { load_textdomain('forge', $ff_forge_mo); } // Schema migrations — must run BEFORE any class that touches the FF // tables. dbDelta is idempotent so this is essentially free on the // hot path (one option compare). Catches the auto-update case where // register_activation_hook never fires. FORMFORGE_Schema::maybe_upgrade(); if (is_admin()) { add_action('admin_notices', ['FORMFORGE_Schema', 'render_missing_tables_notice']); } // An add-on too old for this core is kept from booting (FORMFORGE_MIN_PRO). FORMFORGE_Pro_Bridge::keep_outdated_addon_from_booting(); FORMFORGE_Core::instance(); FORMFORGE_Field_Types::instance(); FORMFORGE_Form_Builder::instance(); FORMFORGE_Form_Renderer::instance(); FORMFORGE_Form_Handler::instance(); FORMFORGE_Webhooks::instance(); FORMFORGE_Notifications::instance(); FORMFORGE_Anti_Spam::instance(); // Forge Queue Forge_Queue::instance(); FORMFORGE_Rest_Api::instance(); FORMFORGE_Templates::instance(); if (is_admin()) { require_once FORMFORGE_DIR . 'includes/class-forge-docs-link.php'; require_once FORMFORGE_DIR . 'includes/class-forge-support-link.php'; FORMFORGE_Admin::instance(); // Tasks that wait for WP-Cron (retries of a booking, a Sheets row, a payment check): shown and run by hand. FORMFORGE_Cron_Overdue::boot(); require_once FORMFORGE_DIR . 'includes/class-migration.php'; FORMFORGE_Migration::instance(); } } add_action('plugins_loaded', 'formforge_init', 5); // Shortcode add_shortcode('formforge', function ($atts) { $atts = shortcode_atts(['id' => 0], $atts); return FORMFORGE_Form_Renderer::instance()->render((int) $atts['id']); }); register_activation_hook(__FILE__, function () { require_once FORMFORGE_DIR . 'includes/class-core.php'; FORMFORGE_Core::activate(); // Seed the schema version so maybe_upgrade short-circuits on the // very first request after activation — but only when the tables exist: // otherwise the next load creates them again (wp.org review of // 25 November 2026) and a notice names what is missing. FORMFORGE_Schema::record_version_if_ready(FORMFORGE_DB_VERSION); // Telemetry (Pro-only). On Free-only sites the class isn't loaded. if (class_exists('Forge_Telemetry')) { $prev = (string) get_option('formforge_previous_version', ''); Forge_Telemetry::track('plugin.activated', [ 'first_install' => $prev === '', 'previous_version' => $prev, ]); update_option('formforge_previous_version', FORMFORGE_VERSION, false); if (!get_option('formforge_installed_at')) { update_option('formforge_installed_at', time(), false); } } }); register_deactivation_hook(__FILE__, function () { // B9: clear Fillin Forge-owned single-event retry crons. After deactivation // the queued retries try to load FORMFORGE_Integrations whose class file // no longer auto-loads, throwing a fatal on every cron tick. Both retries // are scheduled with arguments (the attempt and the call's data), and // wp_clear_scheduled_hook called with none takes only the events that // have none: wp_unschedule_hook takes every event of the hook. wp_unschedule_hook('formforge_retry_sheets_append'); wp_unschedule_hook('formforge_retry_calendar_event'); // The one-time sweep of saved draft passwords (FORMFORGE_Schema): a one-shot too. wp_unschedule_hook('formforge_erase_draft_passwords'); // The background encryption of earlier versions' files; it is booked again on the next admin screen while files remain. wp_unschedule_hook('formforge_files_migrate'); // formforge_init constructs Forge_Queue, which schedules these two on // every bootstrap — so a still-active sibling puts them straight back and // clearing here only stops the ticks on a site that just lost its last // Forge plugin. Same contract as Forge_Telemetry::on_deactivate. if (class_exists('Forge_Queue')) { wp_clear_scheduled_hook(Forge_Queue::CRON_HOOK); wp_clear_scheduled_hook(Forge_Queue::CLEANUP_HOOK); } // Older versions shipped a licensing SDK (removed in 72759e1 / 0e8ee87 / // 62427f9) whose daily sync event is still booked on every install that // ever ran it, now with no callback — wp-cron respawns it forever. // Nothing else will ever clear it. wp_clear_scheduled_hook('fs_data_sync_formforge'); if (class_exists('Forge_Telemetry')) { $installed_at = (int) get_option('formforge_installed_at', time()); Forge_Telemetry::track('plugin.deactivated', [ 'uptime_days' => max(0, (int) floor((time() - $installed_at) / DAY_IN_SECONDS)), ]); Forge_Telemetry::flush(); } });