Skip to content

fix: resolve all PHPCS violations for WordPress coding standards#866

Merged
GaryJones merged 1 commit intodevelopfrom
fix/phpcs-violations
Dec 25, 2025
Merged

fix: resolve all PHPCS violations for WordPress coding standards#866
GaryJones merged 1 commit intodevelopfrom
fix/phpcs-violations

Conversation

@GaryJones
Copy link
Copy Markdown
Contributor

Problem

The codebase contained numerous violations of WordPress-VIP-Go and WordPress-Extra coding standards that were being silently ignored in CI. The php-lint workflow had continue-on-error: true enabled for PHPCS checks, meaning coding standards failures wouldn't prevent merges or alert developers to issues. This allowed technical debt to accumulate and made it harder to maintain consistent code quality across the project.

Running composer cs revealed 37 files with violations spanning core modules, common utilities, and test files. These violations included missing text domains for internationalisation, improper escaping practices, use of deprecated WordPress functions, inconsistent documentation, and formatting issues that reduced code readability.

Solution

This change addresses all PHPCS errors and warnings to bring the codebase into full compliance with WordPress-VIP-Go and WordPress-Extra standards, and removes the continue-on-error flag from the CI workflow to enforce strict standards checking going forward.

The fixes fall into several categories:

Security and nonce handling: Added phpcs:ignore annotations for legitimate exceptions where nonce verification isn't required (such as public ICS calendar feeds that use secret key validation instead) and where input sanitization is properly handled through dedicated sanitize_filter() methods rather than generic WordPress functions.

WordPress coding standards: Replaced all instances of strip_tags() with wp_strip_all_tags() to align with WordPress best practices for HTML stripping. This provides better XSS protection and consistency with the WordPress ecosystem.

Internationalisation: Added missing 'edit-flow' text domains to all i18n function calls, ensuring proper translation support throughout the plugin.

Documentation: Added comprehensive doc comments for class member variables that were previously undocumented, improving code maintainability and IDE support.

Code formatting: Fixed inline comment formatting to end with periods per WordPress standards, and applied consistent spacing and indentation throughout.

Form handling: Used phpcs:disable/phpcs:enable blocks around form sections where proper escaping is already in place but would otherwise trigger false positives.

With these changes, the CI workflow now enforces coding standards strictly, preventing future violations from being introduced whilst maintaining all existing functionality.

Address all errors and warnings from `composer cs` to enable strict
enforcement in CI. The php-lint workflow now fails on coding standards
violations instead of using continue-on-error.

Changes include:
- Add phpcs:ignore comments for legitimate exceptions (nonce verification
  on public ICS feeds with secret key validation, input sanitization
  handled by dedicated sanitize_filter() methods, legacy method names)
- Replace strip_tags() with wp_strip_all_tags() per WordPress standards
- Add missing 'edit-flow' text domains for i18n functions
- Add doc comments for class member variables
- Fix inline comment formatting (periods at end)
- Use phpcs:disable/enable blocks for form sections with proper escaping

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@GaryJones GaryJones requested a review from a team as a code owner December 25, 2025 00:21
@GaryJones GaryJones self-assigned this Dec 25, 2025
@GaryJones GaryJones added the type: maintenance Routine maintenance and code quality improvements label Dec 25, 2025
@GaryJones GaryJones added this to the Next (minor) milestone Dec 25, 2025
@GaryJones GaryJones merged commit 6c72487 into develop Dec 25, 2025
14 checks passed
@GaryJones GaryJones deleted the fix/phpcs-violations branch December 25, 2025 00:26
@GaryJones GaryJones mentioned this pull request Jan 4, 2026
GaryJones added a commit that referenced this pull request Jan 7, 2026
The nonce verification in save_post_subscriptions() was using the wrong
action string ('editpost'), which caused WordPress to reject legitimate
save requests from users with Editor role when using Classic Editor.
Classic Editor's edit form nonces use 'update-post_{$post_id}' as the
action, so the verification must match this to prevent "Cheatin' uh?"
errors on post save.

This regression was introduced in the PHPCS fixes (PR #866) and broke
existing functionality for Editor role users, as reported on the
WordPress.org support forums.

The fix ensures compatibility with Classic Editor whilst maintaining
the security benefits of nonce verification. Integration tests verify
the nonce check now correctly accepts Classic Editor nonces and rejects
those created with the wrong action.

Fixes: https://wordpress.org/support/topic/upgrading-to-0-10-0-breaks-funtionality-for-editor-role/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
GaryJones added a commit that referenced this pull request Jan 7, 2026
The nonce verification in save_post_subscriptions() was using the wrong
action string ('editpost'), which caused WordPress to reject legitimate
save requests from users with Editor role when using Classic Editor.
Classic Editor's edit form nonces use 'update-post_{$post_id}' as the
action, so the verification must match this to prevent "Cheatin' uh?"
errors on post save.

This regression was introduced in the PHPCS fixes (PR #866) and broke
existing functionality for Editor role users, as reported on the
WordPress.org support forums.

The fix ensures compatibility with Classic Editor whilst maintaining
the security benefits of nonce verification. Integration tests verify
the nonce check now correctly accepts Classic Editor nonces and rejects
those created with the wrong action.

Fixes: https://wordpress.org/support/topic/upgrading-to-0-10-0-breaks-funtionality-for-editor-role/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: maintenance Routine maintenance and code quality improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant