fix(importer): resolve nav_menu widget term_id from slug hint#458
Merged
selul merged 1 commit intodevelopmentfrom Apr 23, 2026
Merged
fix(importer): resolve nav_menu widget term_id from slug hint#458selul merged 1 commit intodevelopmentfrom
selul merged 1 commit intodevelopmentfrom
Conversation
Widget instances exported from another site reference menus by numeric term_id (e.g. `nav_menu` => 3), which never match on the target after a fresh import. `Slug_Mapping::rewrite_value()` only rewrites URL strings, so the integer passes through and `wp_nav_menu(['menu' => 3])` silently renders nothing. Add a pre-import resolver that consumes a `_ti_nav_menu_slug` hint (carried by companion exporters), looks the slug up on the target site via `wp_get_nav_menu_object()`, rewrites `nav_menu` to the fresh term_id, and strips the hint so it never persists into `widget_nav_menu`. Unresolved slugs are non-fatal. Expose the resolution step as a `ti_tpc_widget_pre_import` filter so future ID-by-reference widgets (taxonomies, products) can plug in without further core changes. Covered by `tests/widgets-import-test.php` with three cases: successful resolution, unresolved-slug fallback, and filter-hook invocation. Made-with: Cursor
Collaborator
Collaborator
|
🎉 This PR is included in version 1.2.27 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.
Summary
Nav-menu widgets imported through TPC lose their menu after a cross-site import: the source payload carries
nav_menu=><source_term_id>andSlug_Mapping::rewrite_value()only rewrites URL strings, so the integer passes through andwp_nav_menu(['menu' => N])silently matches nothing. The target sidebar ends up with an empty.widget_nav_menudiv.This PR adds a general pre-import resolution layer for ID-by-reference widget settings:
Widgets_Importer::resolve_known_references()consumes a_ti_nav_menu_slughint, looks up the menu on the target site viawp_get_nav_menu_object(), rewritesnav_menuto the freshly-imported term_id, and strips the hint so it never leaks intowidget_nav_menu.ti_tpc_widget_pre_importfilter exposes the same pipeline to third-party exporters for future ID-by-reference widgets (products, custom taxonomies, etc.).Slug_Mapping::rewrite_value()and before the "identical settings already exist" dedup, so reruns stay idempotent.Companion exporter change (stamping
_ti_nav_menu_slug) lives in the consumer (Demo Data Exporter). This PR does not introduce any dependency on the exporter - absent the hint, behaviour is unchanged.Test plan
tests/widgets-import-test.phpcovers:_ti_nav_menu_slugresolves to the target term_id and is stripped.ti_tpc_widget_pre_importfires with(widget, id_base, instance_id, sidebar_id)and its mutation is persisted.php -lclean on all touched files.vendor/bin/phpunit._ti_nav_menu_slugand confirm Footer Two renders the imported menu andwidget_nav_menustores the target term_id with no leftover_ti_nav_menu_slugkey.Made with Cursor