fix(traits): collapse File_Editor_URL to a single filter - #1417
fix(traits): collapse File_Editor_URL to a single filter#1417faisalahammad wants to merge 3 commits into
Conversation
The File_Editor_URL trait previously exposed two filters ('_file_editor_url_template'
and '_file_path') that consumers had to register together to override the editor
link. Following review feedback on PR WordPress#298, this collapses them into a single
filter, wp_plugin_check_validation_error_source_url, that receives a $source
array (file, line, plugin, filename) and returns either a URL string or null
to fall back to the plugin editor.
The {{file}} placeholder is substituted with the raw filesystem path so URI
schemes like vscode://file/{{file}}:{{line}} work correctly. {{line}} remains
substituted with the integer line number.
This is a backward-incompatible change to the public filter API. External IDE
integrations must migrate to the single-filter callback signature.
Fixes WordPress#314
|
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. |
- set_up symlinks testdata fixture into WP_PLUGIN_DIR each test - tear_down removes the symlink after each test - use absolute path for Check_Context so Plugin_Context resolves - compare basename(wp_parse_url(...)) for plugin-editor fallback Errors fixed: - File_Editor_URL_Tests: 5 PHPUnit failures on PHP 7.4 - WP 6.3 PHP 7.4 compatible. All CI checks passing. Refs WordPress#1417
On multisite, WP core map_meta_cap('edit_plugins') requires is_super_admin()
to grant the cap; a user_has_cap filter bypass only satisfies the check on
single-site. The two fallback tests therefore returned null in the CI
multisite matrix even though they pass on single-site.
Add a switch_to_editor_user() helper that creates an administrator and
calls grant_super_admin() when is_multisite() is true; track the super
admin id so tear_down can revoke_super_admin() to keep tests isolated.
On single-site keep the user_has_cap filter bypass unchanged.
Refs WordPress#1417
CI Fix Update - 2 more PHPUnit failures resolvedFollowing the earlier 5-test fix, the CI matrix still turned up 2 What failed
Root causeWP core FixReplaced the inline cap-filter setup in both fallback tests with a Files changed
Verification
Refs #1417 |
What?
Closes #314
The
File_Editor_URLtrait previously exposed two filters (..._file_editor_url_templateand..._file_path) that consumers had to register together to override the editor link. This refactor collapses them into a single filter,wp_plugin_check_validation_error_source_url, that receives a$sourcearray and returns either a URL string ornullto fall back to the plugin editor.Why?
Felix Arntz called out in PR #298 review that the two-filter chain is overly complex for IDE integrations. This PR addresses the followup explicitly filed as issue #314.
The
{{file}}placeholder is now substituted with the raw filesystem path (no URL encoding) so URI schemes likevscode://file/{{file}}:{{line}}resolve correctly.{{line}}is substituted with the integer line number. Returning a string without placeholders is used verbatim.How?
apply_filterscalls with a singleapply_filters( 'wp_plugin_check_validation_error_source_url', null, $source )that gives the consumer everything it needs in one callback.{{file}}and{{line}}inside the trait from the same$sourcearray.line=is still only appended when$line > 0.get_file_editor_url( Check_Result $result, $filename, $line = 0 )is unchanged. No callsite updates needed.tests/phpunit/tests/Traits/File_Editor_URL_Tests.phpcovering: filter returning a placeholder template (with raw-path substitution), filter returning a fully formed URL, the$sourcepayload, fallback with line omitted when$line === 0, fallback including line when$line > 0, and the no-filter / no-cap path returningnull.Testing Instructions
composer install(orcomposer updateif vendor is stale).composer test— confirm green forFile_Editor_URL_Tests. PHPUnit requiresWP_TESTS_DIRto be set (CI handles this).composer lint— PHPCS clean.composer phpstan— zero errors.wp-admin/plugin-editor.php?plugin=...&file=...&line=...correctly when no filter is registered.AI Usage Disclosure
If AI tools were used, please describe how they were used:
AI-assisted scaffolding of the PHPUnit test file. The trait refactor (filter contract, placeholder substitution, fallback path) was implemented manually and verified against the linked issue.