Repository navigation
Conversation
|
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. |
SummaryThe PR builds a plugin-wide set of global function declarations and skips flagging calls to any function in that set. That fixes the issue: polyfills in a separate ✅ What's good
|
|
Thanks for your contribution. Could you fix the tests before we can review? |
|
I reviewed this PR with Codex. The overall direction makes sense, but I found two issues:
Additionally, the required PHP CI job currently fails PHPMD because the new method exceeds the configured complexity thresholds. These should be addressed before approval. |
|
@ernilambar Thanks for the thorough review. Changed in e24845d
Not changed
|
|
@davidperezgar Agreed that skipping the call could hide a real failure. Changed in e24845d
Alternatives not taken
|
There was a problem hiding this comment.
🟡 Changes recommended
Declaration parsing and scope tracking can incorrectly downgrade compatibility errors or miss valid polyfills.
3 open findings
What changed in this PR
Updates WordPress function compatibility checks to recognize plugin-provided polyfills across files, addressing #1496.
Changes:
- Collects global function declarations across plugin PHP files.
- Reports matching compatibility issues as warnings naming the declaring file.
- Adds fixtures and tests for polyfills and non-global declarations.
| File | Description |
|---|---|
| tests/phpunit/tests/Checker/Checks/WP_Functions_Compatibility_Check_Tests.php | Tests warning and error behavior. |
| tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-polyfill-file/uses-polyfilled-function.php | Calls cross-file polyfills. |
| tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-polyfill-file/load.php | Loads polyfill fixtures. |
| tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-polyfill-file/includes/compat.php | Declares guarded polyfills. |
| tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-polyfill-file/includes/braced-namespaces.php | Covers braced namespace declarations. |
| tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-non-global-declarations/uses-new-function.php | Calls functions without global polyfills. |
| tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-non-global-declarations/namespaced.php | Provides a namespaced declaration. |
| tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-non-global-declarations/load.php | Loads non-global declaration fixtures. |
| tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-non-global-declarations/imports.php | Covers function imports. |
| tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-non-global-declarations/enum.php | Covers enum methods. |
| tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-non-global-declarations/class-notices.php | Covers class methods. |
| tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-non-global-declarations/anonymous-class.php | Covers anonymous-class methods. |
| includes/Traits/Function_Declaration_Utils.php | Adds global declaration scanning. |
| includes/Checker/Checks/Plugin_Repo/WP_Functions_Compatibility_Check.php | Integrates declaration-aware warnings. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| $next_index = $this->get_next_significant_token_index( $tokens, $index ); | ||
| return null === $next_index ? null : $tokens[ $next_index ]; |

What?
Closes #1496
wp_functions_compatibilityreports a call to a newer WordPress function that the plugin declares itself, such as a polyfill in a separate compat file, as a warning naming that file instead of an error.Why?
A polyfill is only recognised when it's in the same file as the call, so the common
includes/compat.phppattern fails the check.How?
When a call would be flagged, the check collects the global functions the plugin declares across its files and reports calls to them as
wp_function_declared_by_pluginwarnings. Methods, enum and namespaced functions, anduse functionimports with the same name are still errors.Testing Instructions
QA steps
tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-polyfill-fileintowp-content/plugins/.wp_function_not_compatible_with_requires_wperrorsuses-polyfilled-function.phplines 8 and 9:wp_function_declared_by_pluginwarning namingincludes/compat.phpincludes/braced-namespaces.phpincludes/commented-declaration.phpincludes/class-compat-loader.phpDeveloper checks
wp plugin check tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-polyfill-file --checks=wp_functions_compatibilitywp plugin check tests/phpunit/testdata/plugins/test-plugin-wp-functions-compatibility-with-non-global-declarations --checks=wp_functions_compatibilityAI Usage Disclosure
Claude Code was used to reproduce the bug and draft the fix, tests and this description; I reviewed and tested the changes.