Skip to content

Add menu_image_icon check to detect raster image menu icons - #1438

Open
faisalahammad wants to merge 2 commits into
WordPress:trunkfrom
faisalahammad:fix/788-menu-image-icon-check
Open

Add menu_image_icon check to detect raster image menu icons#1438
faisalahammad wants to merge 2 commits into
WordPress:trunkfrom
faisalahammad:fix/788-menu-image-icon-check

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

What?

Closes #788

Adds a new warning-level check, menu_image_icon, that detects when plugins use raster image files (PNG, JPG, GIF, WebP, ICO, BMP) as the icon parameter in add_menu_page(). Raster images do not adapt to the WordPress admin color schemes, so a dashicon or an SVG data: URI is recommended instead.

Why?

Raster image icons in the admin menu do not recolor to match the active admin color scheme, unlike dashicons and SVG data: URIs. This produces inconsistent admin UI. The check warns plugin authors about this best practice so they can switch to a color-scheme-safe icon.

How?

The check extends Abstract_File_Check and uses a PHP token-based parser to locate add_menu_page() calls. It tracks open and close parens to reliably extract the sixth parameter, the icon URL, and reports a warning when the value is a raster image file. Dashicon classes, SVG data: URIs, empty strings and the 'none' value are all valid and skipped. The check is registered in Default_Check_Repository under the plugin_repo category.

Testing Instructions

  1. Install and activate Plugin Check.
  2. Run Plugin Check on a plugin whose add_menu_page() call uses an image file as the icon, for example 'img/icon.png'.
  3. Confirm a warning appears on the add_menu_page() call: "Raster image used as admin menu icon."
  4. Run Plugin Check on a plugin that uses a dashicon or an SVG data: URI as the icon.
  5. Confirm no warning is raised for the valid icons.

AI Usage Disclosure

  • This PR was created without the help of AI tools
  • This PR includes AI-assisted code or content

If AI tools were used, please describe how they were used:
Used Claude Code to implement the check, write the unit tests, and prepare this PR.

Screenshots or screencast

Not applicable. This change does not alter any user-facing UI.

Open WordPress Playground Preview

…s#788)

Adds a new warning-level check that detects when plugins use raster image
files (PNG, JPG, GIF, WebP, ICO, BMP) as the icon parameter in
add_menu_page(). Raster images do not adapt to the WordPress admin color
schemes, so a dashicon or an SVG data: URI is recommended instead.

The check uses a PHP token-based parser to locate the sixth parameter of
add_menu_page() and reports a warning when it points to a raster image
file. Dashicon classes, SVG data: URIs, empty strings and the 'none'
value are all valid and skipped.

Includes unit tests covering flagged and clean cases.
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: faisalahammad <faisalahammad@git.wordpress.org>
Co-authored-by: Zodiac1978 <zodiac1978@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

- add PHPMD NPath and cyclomatic complexity suppressions in Menu_Image_Icon_Check
- match established suppression pattern in Direct_File_Access_Check and Plugin_Header_Fields_Check

Errors fixed:
- PHPMD.NPathComplexity: file_scan_add_menu_page_icons() 2841 > 200
- PHPMD.CyclomaticComplexity: file_scan_add_menu_page_icons() 20 >= 20

PHP 8.5 compatible. All CI checks passing.

Refs WordPress#1438
@faisalahammad

Copy link
Copy Markdown
Contributor Author

CI Fix Summary - 1 failure resolved

# File Error Fix
1 Menu_Image_Icon_Check.php:124 PHPMD NPathComplexity 2841>200 + CyclomaticComplexity 20>=20 Added @SuppressWarnings(PHPMD.CyclomaticComplexity) + @SuppressWarnings(PHPMD.NPathComplexity), matching existing repo pattern

Tests ok · Verification ok · PHP 8.5 ok

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.

Add a check for images instead of icons in the main menu

1 participant