Menus, template parts and synced patterns

Since 1.20.0, create-post and update-post can write a block theme’s menus (wp_navigation), template parts (wp_template_part) and synced patterns (wp_block). Before that both abilities were hard-coded to drafts, which left no way to edit a block theme’s menus or header from MCP: these types do nothing until they are published.

Per-type rules

What each ability may do is set per post type by LH_MCP_General_Abilities_Post_Type_Rules, filterable through lh_mcp_general_abilities_post_type_rules. A type with no rule cannot be written at all. Types added through the older lh_mcp_general_abilities_return_writable_post_types filter still work and get the default rule. Other plugins add their own types through the filter, so the built-in types are not the only ones.

Typecreate-postupdate-postExtra
post, page, othersdraft, pendingdraft, pendingDefault rule
wp_navigationdraft, publishdraft, publishFallback guard; navigation blocks only
wp_blockdraft, publishdraft
wp_template_partdraft, publishdraftOverride guard; slug required
bp-email (added by LH Buddypress Extender)nonepublishinstall_plugins; classic HTML; token guard
lh_email_compose (added by LH Email)nonenoneTrash only

The design types need edit_theme_options, and publishing anything needs the type’s publish_posts. Menu content may only hold navigation-link, navigation-submenu, page-list and home-link blocks. A published menu can be revised in place; a published template part or synced pattern cannot, because the change would be live everywhere it is used. Live template parts go through lh-mcp-site-design’s propose, preview and apply flow instead.

Described from the rules

Since 1.23.0 the descriptions of create-post, update-post, trash-post and untrash-post list the types and statuses from the rules on the site (describe()), instead of a hard-coded list that hid every type a plugin added. They keep the principle visible: a type with no rule cannot be written, and ordinary content stays draft or pending. A description is built on the site the connector serves, so a call with site_id can meet other rules; list-post-types reports each type’s write_rule (create, update and trash statuses, extra capability, content format, allowed blocks, audit) for the site it is asked about, and is the authoritative answer. Since 1.23.1 its can_write is true only when the rule allows create.

Classic HTML

A rule can set content_format to classic for a type that keeps classic HTML rather than blocks, such as BuddyPress emails, which are sent as stored. Its body is then taken only as content_html and saved exactly as sent; content_md and content_blocks are refused. Converting such content would turn it into block markup it was never written in, and the converter’s URL handling can strip the braces from a token such as href="{{{lh.register.url}}}", breaking the link silently.

Guards

A guard runs only when a write would leave the post published, and a refusal writes nothing. Since 1.23.0 it receives, alongside the action, type, status, post and slug, the fields the write sets (title, content and excerpt, each only when supplied), so it can check what is changing.

update-post refuses a date change on anything published or being published, since on a menu the date decides which menu is the fallback.

Audit trail

Every write to a type whose rule sets audit (the design types, and BuddyPress emails) is recorded in LH Audit Trail as site_design.post_saved (staff only, kept 730 days), with the action, statuses before and after, the fields changed and replaced_revision_id: a revision holding the content as it was before the write, saved first if one did not already exist. The ability returns the entry as audit_entry_id.