Skip to content

Wire up Edit button for template-backed pages (blog index, archives) — closes #22#25

Open
itzmekhokan wants to merge 3 commits into
WordPress:mainfrom
itzmekhokan:issue/22-edit-template-backed-pages
Open

Wire up Edit button for template-backed pages (blog index, archives) — closes #22#25
itzmekhokan wants to merge 3 commits into
WordPress:mainfrom
itzmekhokan:issue/22-edit-template-backed-pages

Conversation

@itzmekhokan
Copy link
Copy Markdown
Contributor

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 via term.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's id ({stylesheet}//{slug}) directly as the site-editor postId.
  • buildSiteEditorUrl(origin, template) — builds /wp-admin/site-editor.php?postType=wp_template&postId={id}&canvas=edit.
  • resolveTemplateEditUrlAsync(...) — gates on the active theme's is_block_theme flag (cheap), then lists /wp/v2/templates only for block themes. Returns { url, isBlockTheme }.

Wiring

  • content.js handles RESOLVE_TEMPLATE_EDIT_URL with the popup-supplied REST nonce (the /themes and /templates endpoints are private).
  • src/popup/lib/actions.js adds requestTemplateEditUrl, reusing the existing nonce-resolution path (same as site-info / current-user).
  • useEditUrlResolution (DetectedView) gains a template branch and surfaces isBlockTheme.

Honest labels (src/popup/lib/labels.js) — no more "Coming Soon":

  • Enabled → Edit Blog Template / Edit Archive Template.
  • Disabled → Editing Not Available (Classic Theme), Template Not Found (block theme, no match), or Editing Not Available (undeterminable — non-admin / REST off).

Safari mirror synced via scripts/sync-safari.sh.

Behavior matrix

Theme Page Result
Block blog index / archive Edit enabled → site-editor template deep link
Block template not resolvable Disabled — "Template Not Found"
Classic any non-singular Disabled — "Editing Not Available (Classic Theme)"
Static front page / posts page homepage Unchanged (singular page → 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 of resolveTemplateEditUrlAsync.
  • npm run build compiles cleanly.

Use of AI

  • Yes ( Claude Code )

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wire up Edit button for template-backed pages (blog index, archives)

1 participant