Wire up Edit button for template-backed pages (blog index, archives) — closes #22#25
Open
itzmekhokan wants to merge 3 commits into
Open
Conversation
Template-backed views (blog index, archives) have no post.php/term.php
destination — on block themes they edit a site-editor template instead.
Adds pure, testable helpers (templateCandidates, pickTemplate,
buildSiteEditorUrl) and the REST orchestrator resolveTemplateEditUrlAsync,
which gates on the active theme's is_block_theme flag and matches the
current view against /wp/v2/templates following the template hierarchy.
Returns { url, isBlockTheme } so the popup can label the disabled state
honestly (classic theme vs. block theme with no matching template vs.
undeterminable). Smoke tests cover candidate ordering, template matching
with fallback, URL construction, and the full block/classic/unauth paths.
Template-backed views (blog index, archives) were disabled with "(Coming Soon)" placeholders. The popup now resolves them to a site-editor deep link on block themes: - content.js handles RESOLVE_TEMPLATE_EDIT_URL, calling the new resolveTemplateEditUrlAsync with the popup-supplied REST nonce (the /themes and /templates endpoints are private). - actions.js adds requestTemplateEditUrl, reusing the existing nonce resolution path (same as site-info / current-user). - useEditUrlResolution gains a template branch and surfaces isBlockTheme. - Labels are now honest about the disabled state: classic theme, block theme with no matching template, or undeterminable — never a "Coming Soon" false promise. Enabled rows read "Edit Blog Template" / "Edit Archive Template". Category/tag and author archives are unchanged — they keep editing their own term/user record via term.php / user-edit.php.
Mirrors content.js, lib/rest.js, and the rebuilt dist/popup.js into the Safari Xcode project Resources via scripts/sync-safari.sh.
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
Closes #22. The popup's Edit button was disabled with
"… (Coming Soon)"placeholders for template-backed views — the blog index (pageType === 'home') and archives (pageType === 'archive'). On block themes these now resolve to a site-editor deep link; on classic themes they stay disabled with an honest label.These were the only genuinely-disabled cases. Category/tag archives (
pageType === 'term') and author archives already worked and are intentionally left unchanged — they edit their own term/user record viaterm.php/user-edit.php, which is the more useful destination than a shared template.What changed
Detection → resolution (
lib/rest.js) — new pure, testable helpers plus a REST orchestrator:isTemplateBackedPage(ctx)/templateCandidates(ctx)— the WP template hierarchy per view (home → [home, index],archive → [archive-{type}?, archive, index]).pickTemplate(ctx, templates)— most-specific registered template wins, using each template'sid({stylesheet}//{slug}) directly as the site-editorpostId.buildSiteEditorUrl(origin, template)— builds/wp-admin/site-editor.php?postType=wp_template&postId={id}&canvas=edit.resolveTemplateEditUrlAsync(...)— gates on the active theme'sis_block_themeflag (cheap), then lists/wp/v2/templatesonly for block themes. Returns{ url, isBlockTheme }.Wiring
content.jshandlesRESOLVE_TEMPLATE_EDIT_URLwith the popup-supplied REST nonce (the/themesand/templatesendpoints are private).src/popup/lib/actions.jsaddsrequestTemplateEditUrl, reusing the existing nonce-resolution path (same as site-info / current-user).useEditUrlResolution(DetectedView) gains a template branch and surfacesisBlockTheme.Honest labels (
src/popup/lib/labels.js) — no more "Coming Soon":Edit Blog Template/Edit Archive Template.Editing Not Available (Classic Theme),Template Not Found(block theme, no match), orEditing Not Available(undeterminable — non-admin / REST off).Safari mirror synced via
scripts/sync-safari.sh.Behavior matrix
post.php)Testing
cd test && npm test— full smoke suite passes, including 4 new scenarios: candidate ordering, template matching with hierarchy fallback, URL construction/encoding, and the full block / classic / unauth / non-template short-circuit paths ofresolveTemplateEditUrlAsync.npm run buildcompiles cleanly.Use of AI