Skip to content

✨ feat(menus): take WordPress 7.2 icon names, none and absolute URLs as the menu icon - #146

Merged
gfazioli merged 2 commits into
masterfrom
feat/menu-icon-names
Nov 26, 2026
Merged

gfazioli merged 2 commits into
masterfrom
feat/menu-icon-names

Conversation

@gfazioli

Copy link
Copy Markdown
Collaborator

Why

WordPress 7.2 (December 8, 2026) draws the admin menu and the admin bar with inline SVGs, and add_menu_page() now takes the name of a registered icon such as core-admin/pin (dev note).

AdminMenuProvider turned every icon of config/menus.php that was not dashicons* or data: into a file of the plugin's public/images folder. So an icon name, and also none and an absolute URL (both already valid for WordPress), became a broken <img>.

What

  • AdminMenuProvider::menuIcon() passes through what WordPress reads by itself:

    • an icon name, where wp_is_valid_icon_name() exists (7.2+)
    • none
    • an absolute or protocol-relative URL
    • Dashicons classes and base64 SVGs, as before
  • Anything else is still a file of the plugin's images.

  • An absolute URL keeps the <img> padding rule that plugin images get.

  • Before 7.2 an icon name stays a file name, as in 3.3.1. A menu that must run on both versions gates it in config/menus.php:

    'icon' => function_exists('wp_is_valid_icon_name') ? 'core-admin/pin' : 'dashicons-admin-post',

    The docs page core-concepts/menus.mdx gets this with the release.

  • The menu icon of custom post types was already passed to register_post_type() unchanged, so icon names work there with no change.

Verification

  • Unit: AdminMenuProviderTest has 10 new cases: each form, plus the icon name with and without 7.2's wp_is_valid_icon_name() (the latter in a separate process). Against the 3.3.1 AdminMenuProvider, 5 of them fail: none, the three URL forms and the icon name. composer test: 396 tests, all green.
  • Live: new menu-icon-live-smoke.sh, in the workspace's .claude/scripts. It copies WPKirk-Developing with the checkout's src/ into a local Playground, without touching the shared bench. It gives it five top-level menus, one per icon form, and reads each div.wp-menu-image from the logged-in admin page.
    • v3.3.1 on WordPress 7.2-RC3: 3 ✗
      • core-admin/pin → <img src=".../public/images/core-admin/pin">
      • none → <img src=".../images/none">
      • the URL → <img src=".../images/https://example.test/menu.png">
    • this branch on WordPress 7.2-RC3: 5 ✓. core-admin/pin is an inline SVG, none draws no image, the URL is loaded as it is, the file name is the plugin's image and the Dashicons class is not an <img>.
    • this branch on WordPress 7.1.5: 5 ✓. The icon name stays a file of the plugin, as documented.

…as the menu icon

WordPress 7.2 draws the admin menu with inline SVGs and lets add_menu_page() take the name of a
registered icon (`core-admin/pin`). AdminMenuProvider turned every icon that was not `dashicons*`
or `data:` into a file of the plugin's public/images folder, so an icon name, `none` and an
absolute URL all became a broken <img>.

menuIcon() now passes through what WordPress reads by itself: an icon name where
wp_is_valid_icon_name() exists (7.2+), `none`, an absolute or protocol-relative URL, besides the
Dashicons classes and base64 SVGs. Before 7.2 an icon name stays a file name, as in 3.3.1; a menu
that must run on both gates it in config/menus.php with function_exists('wp_is_valid_icon_name').
@gfazioli

Copy link
Copy Markdown
Collaborator Author

Review. Codex reached its usage limit for the day on round 1, before it read any code. A fresh-context reviewer subagent stood in for it. It found nothing serious and raised four low-severity points:

  • div (core's older none) still became an image of the plugin. It now passes through, with a test case.
  • On 7.2, a lowercase folder/name with no extension is read as an icon name. The docblock now says so.
  • The docblock's "base64 SVG (data:)" was wider than the check. It now says "a data: URI".
  • '0' and array values: not changed. '0' was falsy before, which is no use as an icon, and an array was a TypeError before and is a warning now.

Its own checks of the test order and the separate process passed. It ran phpunit in reverse order: 396 tests OK.

Re-verified on 5c80f97:

  • composer test: 398 tests, OK. The 3 deprecations are the existing setAccessible() calls in two other tests, which local PHP 8.6 reports.
  • menu-icon-live-smoke.sh on WordPress 7.2-RC3: 5 ✓.

@gfazioli
gfazioli merged commit 5c80f97 into master Nov 26, 2026
4 checks passed
@gfazioli
gfazioli deleted the feat/menu-icon-names branch November 26, 2026 07:40
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.

1 participant