Fix WordPress Nonce Verification PHPCS Warnings#1025
Open
faisalahammad wants to merge 1 commit intowp-media:developfrom
Open
Fix WordPress Nonce Verification PHPCS Warnings#1025faisalahammad wants to merge 1 commit intowp-media:developfrom
faisalahammad wants to merge 1 commit intowp-media:developfrom
Conversation
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.
Summary
Fixes missing and improperly formatted
phpcs:ignorecomments causing PHPCS warnings about WordPress HTTP Variable Nonce Verification.Fixes #971
Problem
PHP CodeSniffer raised multiple warnings for
WordPress.Security.NonceVerification.MissingandWordPress.Security.NonceVerification.Recommendedacross various$_POSTand$_GETdata processing blocks. A recent ruleset update stopped suppressing these warnings globally, exposing poorly-formatted ignore tags and unignored conditionals.Solution
Replaced outdated
// WPCS: CSRF ok.comments with standard// phpcs:ignoretag syntax, placed them correctly before the code block they evaluate, and added explicit ignore tags immediately aboveisset()orempty()usages. Removed redundantusenamespace declarations that caused Unit Tests to fail with Reflection classes.Changes
inc/classes/class-imagify-settings.phpBefore:
After:
Why this works:
Standardized PHPCS annotations must strictly precede the evaluated lines to ensure the CodeSniffer properly parses and suppresses the warning instead of flagging valid application logic.
classes/Bulk/Bulk.phpBefore:
After:
Why this works:
PHP CodeSniffer requires subsequent variable initializations referencing
$_POSTelements to also have an ignore directive natively above the assignment to squash subsequent validation errors.Testing
Automated Tests
$ vendor/bin/phpcs --standard=phpcs.xml --sniffs=WordPress.Security.NonceVerification . 0 Errors 0 Warnings $ composer run test-unit Tests: 24, Assertions: 59 OK (24 tests, 59 assertions)