Repository navigation
fix(export): register template parts with area and title in theme.json on export and save. - #883
Open
KarunyaChavan wants to merge 2 commits into
Open
KarunyaChavan wants to merge 2 commits into
KarunyaChavan wants to merge 2 commits into
Conversation
When exporting or saving templates to theme files, parts/*.html files were written to disk, but corresponding entries in theme.json under templateParts were never registered. This caused custom template parts or plugin-provided parts (e.g., WooCommerce mini-cart) to lose their area classification and human-friendly titles, falling back to 'uncategorized' and raw slug names. - Add CBT_Theme_Templates::add_template_parts_to_theme_json_data() to merge exported template parts with their name, title, and area, deduplicating by slug and preserving existing entries. - Add CBT_Theme_Templates::update_theme_json_template_parts() to write templateParts directly to local theme.json during add_templates_to_local() and invalidate theme JSON resolver caches. - Update CBT_Theme_JSON_Resolver::export_theme_data() to merge exported template parts into theme.json during ZIP exports and theme cloning.
…eme.json. - test_add_template_parts_to_theme_json_data_adds_new_parts: Verifies new template parts are added with name, title, and area. - test_add_template_parts_to_theme_json_data_does_not_duplicate_existing: Ensures existing templateParts entries in theme.json are preserved without duplicates. - test_add_template_parts_to_theme_json_data_defaults_area_and_title: Verifies safe fallbacks to slug and 'uncategorized' when title or area are missing. - test_update_theme_json_template_parts_updates_file: Verifies file-level theme.json update and persistence on disk. - test_export_theme_data_includes_template_parts: Verifies integration with CBT_Theme_JSON_Resolver::export_theme_data().
KarunyaChavan
marked this pull request as ready for review
October 9, 2026 09:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where saving or exporting template parts wrote the template markup files to
parts/*.htmlbut failed to register correspondingtemplatePartsdefinitions intheme.json. As a result, custom template parts created in the Site Editor lost their assigned areas (such as Header, Footer, or Sidebar) and human-friendly titles upon export or when database customizations were cleared, falling back to "Uncategorized" and raw slug titles.Fixes #870
Why ?
header,footer,sidebar) and custom title in the database. Without registering them intheme.json, WordPress Core defaults toWP_TEMPLATE_PART_AREA_UNCATEGORIZED.parts/were written;theme.jsonwas never updated to reflect the newly created parts.What Changed ?
includes/create-theme/theme-templates.php:add_template_parts_to_theme_json_data(): Merges template parts into thetheme.jsondata array undertemplateParts. It populatesname,title, andarea, safely falls back to slug name and'uncategorized'if properties are empty, and deduplicates by slug so existing definitions are preserved.update_theme_json_template_parts(): Updatestheme.jsonon disk in the target theme directory, writes the formatted JSON, and clearsCBT_Theme_JSON_Resolverandwp_get_theme()caches.add_templates_to_local(): Callsupdate_theme_json_template_parts()whenever template parts are saved locally, ensuringtheme.jsonis updated even if the user saves templates without saving global styles.includes/create-theme/resolver_additions.php:CBT_Theme_JSON_Resolver::export_theme_data(): Merges exported template parts intotheme.jsondata during ZIP export, clone, and child theme creation based on the active export scope (all,current, oruser).tests/test-theme-templates.php:name,title, andarea.theme.jsonon disk.CBT_Theme_JSON_Resolver::export_theme_data().Steps for Testing
Test 1: Local Save Changes
Header Variation V2, Area:Header, Slug:header-variation-v2).theme.jsonfile on disk.templatePartsarray exists containing an entry forheader-variation-v2with"area": "header"and"title": "Header Variation V2".Test 2: ZIP Export
theme.json.theme.jsonincludes the new part intemplatePartswith its title and area intact.Use of AI