-
Notifications
You must be signed in to change notification settings - Fork 42
Add a few optimizations #3264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add a few optimizations #3264
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| /** | ||
| * 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, '<!-- wp:formidable/simple-form ' ) ) { | ||
| // New post contains the form shortcode, so clear the embed posts transient. | ||
| delete_transient( self::EMBED_POSTS_TRANSIENT ); | ||
| return; | ||
| } | ||
|
|
||
| $cached_posts = get_transient( self::EMBED_POSTS_TRANSIENT ); | ||
|
|
||
| if ( ! is_array( $cached_posts ) ) { | ||
| return; | ||
| } | ||
|
|
||
| // If the new post data of a cached post doesn't contain the Formidable forms, clear the transient. | ||
| foreach ( $cached_posts as $posts ) { | ||
| foreach ( $posts as $post_data ) { | ||
| if ( intval( $post_data->ID ) === intval( $post_id ) ) { | ||
| // This post contains the form shortcode before updating, so clear the embed posts transient. | ||
| delete_transient( self::EMBED_POSTS_TRANSIENT ); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking coordination note. #3242 (opened 2026-08-14, before this PR) independently bumps
$db_versionfrom 106 to 107 too, and registers its ownmigrate_to_107()step inFrmMigrate::migrate_data()'s version-gated dispatch (its own test assertsmigrate_to_107"must not re-run once already at db_version 107"). This PR's own index additions inadd_composite_indexes_for_entries()are version-agnostic (idempotent, called fromcreate_tables()on any upgrade, not gated to exactly 107), so they're safe regardless of ordering — but if #3242 merges after this one without renumbering, any site that already upgraded to db_version 107 via this PR will have$old_db_version >= $migrationevaluate true for #3242'smigrate_to_107step, and that step's data migration (frm_last_style_update) will silently never run for those sites. Worth flagging to whoever merges second: bump to 108 rather than reusing 107.