Repository navigation
Include a page's design system as a companion library item on save/import - #519
Conversation
A page can reference companion posts it needs to render (e.g. a design system via _fl_ds_ref). Previously only the page uploaded to a cloud library, so it arrived at the destination with a dangling reference and no styling. Assistant stays generic and the companion knowledge lives in the plugin that owns the relationship, via two filters mirroring the #517 fl_assistant_post_types_known pattern: - save_to_library() uploads companions first (fl_assistant_library_companion_posts), $seen-deduped, and records their cloud ids on the page item as _fl_asst_companion_items. get_save_data() gains a $with_screenshot flag so companions that never render (a design system) skip a wasted headless capture. - import_from_library() is refactored around a reusable, post-type-agnostic import_item(); import_companions_from_library() reads the recorded ids from the fetched item (not the just-written post meta, which a raw-INSERT leaves stale in cache), pulls each, skips any a plugin reports already present via fl_assistant_library_companion_exists, creates the rest, and strips the linkage meta. Save-only for now; sync_to_library is untouched. Co-Authored-By: Claude Opus 4.8 <[email protected]>
wp_insert_post() unslashes its argument internally, but import_item() passed the fetched post data through unslashed. A design system item stores its CSS as JSON in post_content (with \n escapes), so the missing slash stripped every backslash and turned each \n into a literal 'n' — corrupting the stylesheet the design system builds from it (broken selectors like nn.bb-badge, mangled token/reset blocks) and leaving imported pages unstyled. wp_slash() the array passed to wp_insert_post() so the content survives the internal unslash intact. Not visible on regular pages because their builder data lives in meta (imported via a slash-safe path); it surfaced once #518 started importing design-system posts whose content is post_content JSON. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…raw escaped INSERT import_post_meta_from_library() wrote each meta value with addslashes() + a raw string-interpolated INSERT. On hosts running MySQL in NO_BACKSLASH_ESCAPES mode that query silently fails for large serialized values (e.g. a 49KB _fl_builder_data full of escaped quotes) — the return value was ignored, so the data was never stored and the imported page rendered blank while smaller meta imported fine. Use $wpdb->insert(), which escapes per the connection and is safe on any sql_mode, and clean_post_cache() after the direct writes so same-request reads (asset regeneration) and object-cache hosts see the imported meta. Co-Authored-By: Claude Opus 4.8 <[email protected]>
replace_imported_attachment_urls_in_meta() re-saved each meta value with update_post_meta(), which unslashes internally. For _fl_builder_data — an array of module objects — that strips the escaped quotes (\") inside every module's ds_block_data JSON, making it invalid. The ds-block module can't parse it, so pages built from ds-blocks imported blank whenever the media step ran (i.e. pages with a featured image or other attachments). Slashing the input didn't help because the corruption is on a deeply nested object property. Re-serialize the rewritten value with maybe_serialize() and write it with $wpdb->update() so the bytes are stored verbatim, then clean_post_cache(). Verified end to end: ds_block_data stays valid JSON and the page renders. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Resolve the get_save_data() conflict with the #530 screenshot fix: keep main's client-screenshot-only shape and gate it on $with_screenshot, so a companion item is not uploaded with the primary post's screenshot. Co-Authored-By: Claude Fable 5.2 <[email protected]>
A page's companions (its design system) now travel inside the page's own library item, as one JSON string under the `_fl_asst_companions` meta key, instead of as separate library items linked by cloud id. The link survives a library being duplicated or moved, saving several pages no longer uploads repeated copies, and there is no second item to delete by accident. Import creates each embedded companion unless `fl_assistant_library_companion_exists` reports it present. A companion that cannot be created is logged and returned in an additive `companion_errors` response key. Preview imports the page only. The embedded data is never stored on the local post. `get_save_data()` returns to its signature on main. Adds unit tests for the save, import and meta paths, including regressions for the three base import fixes. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
… companion types (#518) Post creation from a library item (insert, meta, terms, builder cache, embedded companions) moves from LibraryItemPostController into a new Services/LibraryPostImporter, so the controller stops growing past its size on main. The controller's public import methods stay as delegates with unchanged signatures. A companion is now imported only when its post type is library-portable, the list behind the existing `fl_assistant_post_types_library` filter (default `fl-design-system`), read through the new PostsRepository::get_library_post_types(). Embedded companion data can come from a library another user authored, so it must not choose its own post type. A refused companion is reported as `companion_type_not_allowed`. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Merge CheckState: tested at TLDRWhen someone saves a page to a cloud library, the page's design system now travels inside that same library item. Importing the page on another site brings the design system with it, and a design system that is already there is reused, not duplicated. Three bugs that could leave any imported page blank or with broken CSS are fixed along the way. Reviewmerge-check deep review, verdict Fix-then-ship: no blockers at head; six non-blocking concerns in the fold. Review detailVerdict: Fix-then-ship. The blocker from the previous round (controller grown past the file size ceiling) is fixed and verified at head: the controller is 665 lines against 707 on main, and the moved method bodies are identical to what was removed. The companion post type restriction asked for in that round is in and verified. Concerns (non-blocking)
Nits
deep review · 6 files / +787/-147 lines reviewed. Sanity checkHigh depth. The approach holds: the cloud never indexes, validates or truncates the embedded value. The stored value ships as a bare list with no version wrapper, by the author's decision. Sanity check detailLane: irreversible: a new persisted key,
Test plan
Agent playbookPreconditions: local site at the workspace's
Run history
bb-merge-check · head:5ba45531c · state:tested · risk:irreversible |
Closes #518.
How it works
Assistant stays generic. The design-system knowledge lives in the Beaver Builder Platform behind two filters, mirroring the
fl_assistant_post_types_knownpattern from #517. The platform side is already merged (see Related).Save and sync (
get_save_data): Assistant asks plugins for companion posts throughfl_assistant_library_companion_posts. Each companion's post, meta and terms are embedded in the page item's meta under_fl_asst_companionsas one JSON string. Because the companion is part of the page item's data, it moves with the item, there is no second library item to keep in step or delete by accident, and saving several pages that share a design system does not fill the library with copies.sync_to_libraryuses the same data, so a sync refreshes the embedded copy.Import (
import_from_library): after the page is created through the sharedimport_item(), each embedded companion is created the same way unless a plugin reports it present throughfl_assistant_library_companion_exists. A companion is only imported when its post type is library-portable, meaning it is on the list behind the existingfl_assistant_post_types_libraryfilter (defaultfl-design-system); the embedded data can come from a library someone else authored, so it cannot choose its own post type. A companion that is refused or cannot be created is logged and listed in an additivecompanion_errorskey on the response; the page import still succeeds.Never stored locally:
import_post_meta_from_library()skips_fl_asst_companions, so the embedded data is not written to the imported page on import, sync or preview, andget_save_data()never re-uploads a stale copy.Preview: previewing a library page imports the page only, as before. A page whose design system is not already on the site previews unstyled; a real import brings the design system.
Where the code lives: post creation moved out of the controller into
Services/LibraryPostImporter;import_post_meta_from_library(),import_post_terms_from_library()andregenerate_builder_cache()stay on the controller as delegates with unchanged signatures. The controller is smaller than on main.Three fixes to the base import flow
Found while validating against real Beaver Builder pages. They also affect
sync_from_library.wp_insert_post()unslashes its input, so JSON stored inpost_contenthad every\nturned into a literaln. Fixed withwp_slash().wp_insert_post()is also now called with theWP_Errorflag, so a failed insert returns the documented{ error: true }instead of continuing with post id 0.$wpdb->insert(). Meta was written withaddslashes()and a hand-builtINSERT, which silently fails for large values on MySQL hosts runningNO_BACKSLASH_ESCAPES, leaving the page blank.update_post_meta()unslashes, which stripped the escaped quotes inside each module'sds_block_dataJSON in_fl_builder_data. The value is now written withmaybe_serialize()and$wpdb->update().Behavior changes to know about
update_post_metadataorupdated_post_meta, because it writes through$wpdb. The post cache is cleaned afterwards.Testing
backend/tests/Unit/Controllers/LibraryItemPostCompanionsTest.phpcovers: a declared companion is embedded once; no key without companions; a stale local value is not uploaded; an embedded companion is created with its content and meta byte for byte; a companion reported present is skipped; a companion that cannot be created comes back as an error while the others import; a companion whose post type is not library-portable is refused; malformed data is ignored; imported meta keeps backslashes and quotes; the media URL rewrite keeps the escapes inside nestedds_block_data.Manual Testing
Related
Platform side of the two filters, already merged: https://github.com/beaverbuilder/beaver-builder-platform/pull/738
🤖 Generated with Claude Code