Skip to content

Give FrontBlocks a menu of its own with a submenu for each settings tab - #357

Merged
davidperezgar merged 4 commits into
trunkfrom
feature/top-level-menu
Nov 19, 2026
Merged

davidperezgar merged 4 commits into
trunkfrom
feature/top-level-menu

Conversation

@Castellon-ACM

@Castellon-ACM Castellon-ACM commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

FrontBlocks leaves the Appearance menu and gets a menu of its own, right below it, with a submenu entry for each settings tab. Each entry is a page of its own, so a tab can be linked, bookmarked and opened from the admin sidebar. The screen, its tabs and its save bar stay the same.

(See menu-screenshot.png, attach it to the pull request.)

How it works

  • The menu. Settings::register_menu() adds the top-level menu with the existing icon-menu.svg at position 60.5, below Appearance, and a submenu entry for each tab. The page callback is on the first entry, so the page is not rendered twice.
  • One page per tab. The first tab uses the page slug of the menu (admin.php?page=frontblocks-settings) and every other adds its id (frontblocks-settings-image-management). All of them render the same screen, which opens on the tab of the page that was requested. A #hash still wins over it, so links with a hash keep working.
  • The sidebar and the address bar follow the screen. Clicking a tab updates the address bar to the page of that tab and highlights its entry in the sidebar, so a reload or a copied link opens the same tab. A link with a hash that is followed while the screen is open now switches tab too (hashchange).
  • One list of tabs. get_tabs() is shared by the menu and the screen, so a tab added with frontblocks_settings_tabs gets a menu entry automatically. A tab can stay out of the menu with 'menu' => false. The toggle counts shown next to a tab are passed in by the screen, because the fields they come from do not exist yet when the menu is registered.
  • The old URL keeps working. themes.php?page=frontblocks-settings redirects to the new menu on admin_menu, before WordPress checks the page. It keeps the query arguments and the #tab (the browser carries the fragment across the redirect), forwards only sanitized string arguments, stays on the site (wp_safe_redirect) and only redirects users who can open the settings. Everyone else gets the usual "not allowed".

One set of helpers instead of hard-coded locations

Settings::get_settings_url( $tab ), get_page_slug(), get_tab_from_page() and is_settings_screen() replace the themes.php?page=... URLs and the appearance_page_frontblocks-settings screen ID, in:

  • the settings assets, including the Image Management module (they now load on the screen of every tab);
  • the review, redundant plugins and Cookie Notice migration notices;
  • the activation redirect and the admin bar "Maintenance: ON" link (now opens the Maintenance tab);
  • Google Sign-In (returns to its tab) and the redundant plugins notice.

is_settings_screen() matches by slug, because the screen ID is different on each tab, and it still recognizes the Appearance one for plugins that have not changed yet.

Release order and FrontBlocks PRO

PRO compares the screen ID in two places (the styles of Advanced Cookie Management and the Leads notice). The companion pull request, feature/accept-top-level-menu in frontblocks-pro, makes them work with both locations and does not depend on this one, so it should be released first. If this goes out first, the only thing that stops working with an older PRO is the admin stylesheet of Advanced Cookie Management; the Leads tab keeps working.

Testing

  • 29 new unit tests (tests/Unit/SettingsMenuTest.php): the top-level menu and its position, the submenu entries and their order, tabs added, hidden and invalid, the helpers and screen detection, the tab that opens, the script that keeps the sidebar in step, the redirect of the old URL (arguments, sanitizing, same-site, capability, other pages) and every link that used to point at Appearance. The two tests that used the old screen ID were updated.
  • Mutation checks: reverting the page callback, any condition of the redirect, the screen detection, the 'menu' => false rule, the slug of the first tab, the position, or any of the links makes tests fail.
  • Full suite: 496 tests pass. composer lint and composer phpstan are clean. Together with the Backup tab pull request (Add settings export and import in a new Backup tab #350) the merged result passes 561 tests.
  • Manual test in Chromium on a clean WordPress with FrontBlocks and PRO: the menu sits right below Appearance and nothing is left under it; the 11 entries (including PRO's Leads) each open their tab, highlighted; clicking a tab updates the address and the sidebar, and a reload keeps it; the old URL with #google-signin and gsi-updated lands on the new page with the Social Login tab and its notice; saving the Optional tab returns to it with the change saved; the activation redirect and the admin bar link land on the new pages; an editor sees no menu and gets a 403 on the new and the old URLs; a logged-out visitor goes to the login. No JavaScript errors.

Notes for reviewers

  • The Backup tab pull request (Add settings export and import in a new Backup tab #350) builds its redirect URL with themes.php?page=...#backup. It works through the redirect, but whichever of the two is merged second should switch it to Settings::get_settings_url( 'backup' ). The two only conflict in the changelog of readme.txt.
  • The Playwright E2E tests on feature/e2e-playwright use themes.php?page=frontblocks-settings. They keep working because they follow the redirect, but their expectations about the URL should be updated.
  • The classes are marked @since 1.6.0. Adjust it if this ships in another version.
  • While testing I saw an unrelated JavaScript error that also exists on trunk: Settings.php calls closest('.tw:flex'), which is not a valid selector and needs the colon escaped. It is outside this change.
Open WordPress Playground Preview

Move the settings out of Appearance into a top-level menu below it. Each tab
is an entry of the submenu and a page of its own, so a tab has a URL that can
be linked, bookmarked and opened from the admin sidebar.

- The first tab uses the page slug of the menu and every other adds its id,
  for example frontblocks-settings-image-management. The tab of the page
  that was opened is shown first, a #hash still overrides it, and a link with
  a hash followed while the screen is open now switches tab.
- Clicking a tab in the screen updates the address bar to the page of that
  tab and highlights its entry in the sidebar, so reloading or copying the
  link opens the same tab.
- Tabs come from one place, get_tabs(), which the menu and the screen share,
  so a tab added with frontblocks_settings_tabs also gets a menu entry. A tab
  can stay out of the menu with 'menu' => false.
- The old themes.php?page=frontblocks-settings URL redirects to the new menu
  and keeps its query arguments and its #tab. It only redirects users who can
  open the settings, and forwards only sanitized string arguments.
- Settings::get_settings_url(), get_page_slug(), get_tab_from_page() and
  is_settings_screen() replace the hard-coded URLs and the
  appearance_page_frontblocks-settings screen ID, in the settings assets,
  the notices, the activation redirect, the admin bar maintenance link,
  Google Sign-In and the redundant plugins notice.
Cover the top-level menu and its submenu entries, tabs added or hidden by companion plugins, the URL helpers and screen detection, the tab that opens, the script that keeps the sidebar and the address bar in step, the redirect of the old URL and every link that used to point at Appearance. Update the tests that used the old screen ID.
Say FrontBlocks menu instead of Appearance in the docs, explain how a companion plugin gets its tab in the submenu and links to it, and add the changelog entry.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-12T12:08:01.900445Z
We couldn’t complete this review. Comment @codex review to try again.
48a81c2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Resolve the changelog conflict and move the code that came with Staging Mode to the new menu: the admin bar node and the redundant plugins link open the Maintenance tab, and the staging notice also shows on every FrontBlocks settings screen.
@davidperezgar
davidperezgar merged commit e67556a into trunk Nov 19, 2026
8 checks passed
@davidperezgar
davidperezgar deleted the feature/top-level-menu branch November 19, 2026 08:26
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.

2 participants