Add menu_image_icon check to detect raster image menu icons - #1438
Open
faisalahammad wants to merge 2 commits into
Open
Add menu_image_icon check to detect raster image menu icons#1438faisalahammad wants to merge 2 commits into
faisalahammad wants to merge 2 commits into
Conversation
…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.
faisalahammad
requested review from
chriscct7,
davidperezgar,
ernilambar and
frantorres
as code owners
August 8, 2026 18:36
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. 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
Contributor
Author
CI Fix Summary - 1 failure resolved
Tests ok · Verification ok · PHP 8.5 ok |
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.
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
AI Usage Disclosure
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.