Phpcs reduce ignores - #955
Draft
peterwilsoncc wants to merge 6 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces inline PHPCS suppressions by restructuring input handling and nonce validation so that WordPress security sniffs can be satisfied without phpcs:ignore/phpcs:disable, while preserving existing behavior in the Two-Factor plugin’s settings and revalidation flows.
Changes:
- Replaces
$_GET['page']usage (with nonce-verification ignore) by usingget_current_screen()to detect the Two-Factor settings screen. - Introduces
two_factor_is_valid_user_action()and updates core logic/tests to use it, while deprecatingTwo_Factor_Core::is_valid_user_action(). - Sanitizes posted provider arrays earlier (settings page + user profile options) and adds PHPCS config for custom nonce verification helper.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
two-factor.php |
Uses get_current_screen() for settings-page detection and adds two_factor_is_valid_user_action() helper. |
class-two-factor-core.php |
Deprecates is_valid_user_action() in favor of the new helper; adjusts request parsing and revalidation nonce checks. |
settings/class-two-factor-settings.php |
Sanitizes enabled provider inputs inline to remove PHPCS suppressions. |
tests/class-two-factor-core.php |
Updates coverage and assertions to target two_factor_is_valid_user_action(). |
phpcs.xml.dist |
Configures PHPCS nonce verification sniff to recognize the new helper as a custom nonce verification function. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
533
to
+536
| * Check if a user action is valid. | ||
| * | ||
| * @since 0.5.2 | ||
| * @deprecated x.x.x Use two_factor_is_valid_user_action() instead. |
Comment on lines
+1737
to
+1739
| $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) ) : admin_url(); | ||
| // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- false report due to strtoupper. | ||
| $is_post_request = isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD']; |
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?
Reducing
phpcs:ignoreandphpcs:disableinstances.Fixes #
Why?
It's not unknown that these come back cause problems later as code is removed.
How?
Modifies code to remove the need where possible.
Commonly:
Use of AI Tools
N/A
Testing Instructions
TBA once this comes out of draft.
Screenshots or screencast
Changelog Entry