From d8a7c26921ad75819ca3013949371df002a6fd25 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Wed, 19 Aug 2026 16:15:32 -0300 Subject: [PATCH 1/4] Add a few optimizations --- classes/controllers/FrmHooksController.php | 2 +- classes/factories/FrmFieldFactory.php | 12 ++++- classes/helpers/FrmAppHelper.php | 2 +- classes/helpers/FrmFormsHelper.php | 49 +++++++++++++++++++ classes/helpers/FrmFormsListHelper.php | 41 +++------------- classes/models/FrmMigrate.php | 24 +++++++++ .../FrmPayPalLiteHooksController.php | 8 ++- .../FrmSquareLiteHooksController.php | 8 ++- .../FrmStrpLiteHooksController.php | 25 +++++++++- .../FrmTransLiteHooksController.php | 9 ++-- 10 files changed, 136 insertions(+), 44 deletions(-) diff --git a/classes/controllers/FrmHooksController.php b/classes/controllers/FrmHooksController.php index 932cae769c..ee50affb10 100644 --- a/classes/controllers/FrmHooksController.php +++ b/classes/controllers/FrmHooksController.php @@ -86,7 +86,7 @@ public static function load_hooks() { add_action( 'wp_scheduled_delete', 'FrmForm::scheduled_delete' ); // Clear embed posts transient when posts are updated. - add_action( 'wp_insert_post', 'FrmFormsListHelper::maybe_clear_embed_posts_transient', 10, 2 ); + add_action( 'wp_insert_post', 'FrmFormsHelper::maybe_clear_embed_posts_transient', 10, 2 ); // Form Shortcodes. add_shortcode( 'formidable', 'FrmFormsController::get_form_shortcode' ); diff --git a/classes/factories/FrmFieldFactory.php b/classes/factories/FrmFieldFactory.php index 8469442693..335a0a9532 100644 --- a/classes/factories/FrmFieldFactory.php +++ b/classes/factories/FrmFieldFactory.php @@ -85,6 +85,15 @@ public static function get_field_type( $field_type, $field = 0 ) { * @return string */ private static function get_field_type_class( $field_type ) { + // Rendering one form calls this three times per field, so build the map once per request. + // The frm_get_field_type_class filter still runs on every call, since add-ons can register + // it after the first lookup has already happened. + static $type_classes = null; + + if ( null !== $type_classes ) { + return apply_filters( 'frm_get_field_type_class', $type_classes[ $field_type ] ?? '', $field_type ); + } + $type_classes = array( 'text' => 'FrmFieldText', 'textarea' => 'FrmFieldTextarea', @@ -105,7 +114,8 @@ private static function get_field_type_class( $field_type ) { 'address' => 'FrmFieldAddress', // Submit button field. FrmSubmitHelper::FIELD_TYPE => 'FrmFieldSubmit', - FrmFieldGdprHelper::FIELD_TYPE => FrmFieldGdprHelper::get_gdpr_field_class( $field_type ), + // get_gdpr_field_class only returns a class for the GDPR type, which is this entry's key. + FrmFieldGdprHelper::FIELD_TYPE => FrmFieldGdprHelper::get_gdpr_field_class( FrmFieldGdprHelper::FIELD_TYPE ), 'product' => 'FrmFieldProduct', 'quantity' => 'FrmFieldQuantity', 'total' => 'FrmFieldTotal', diff --git a/classes/helpers/FrmAppHelper.php b/classes/helpers/FrmAppHelper.php index 7d1532ea75..22f54185c0 100644 --- a/classes/helpers/FrmAppHelper.php +++ b/classes/helpers/FrmAppHelper.php @@ -10,7 +10,7 @@ class FrmAppHelper { * * @var int */ - public static $db_version = 106; + public static $db_version = 107; /** * Used by the API add-on. diff --git a/classes/helpers/FrmFormsHelper.php b/classes/helpers/FrmFormsHelper.php index a4749e02a4..f958e31421 100644 --- a/classes/helpers/FrmFormsHelper.php +++ b/classes/helpers/FrmFormsHelper.php @@ -5,6 +5,19 @@ class FrmFormsHelper { + /** + * The transient name that stores data for which posts a form is embedded in. + * + * It lives here rather than in FrmFormsListHelper so the invalidation callback below can run + * without autoloading that admin list table on a front end post insert. + * + * @since 6.32 + * @since 6.35 Moved here from FrmFormsListHelper. + * + * @var string + */ + const EMBED_POSTS_TRANSIENT = 'frm_posts_contain_form'; + /** * Store and re-use field type data for the insert_opt_html function (to avoid multiple calls to FrmField::all_field_selection). * @@ -2205,4 +2218,40 @@ public static function get_form_name( $form, $length = 0 ) { return FrmAppHelper::truncate( $form_name, $length ); } + + /** + * Maybe clear the embed posts transient. + * + * @since 6.32 + * @since 6.35 Moved here from FrmFormsListHelper. + * + * @param int $post_id Post ID. + * @param WP_Post $post Post object. + * + * @return void + */ + public static function maybe_clear_embed_posts_transient( $post_id, $post ) { + if ( str_contains( $post->post_content, '[formidable ' ) || str_contains( $post->post_content, '