Releases: WordPress/WordPress-Coding-Standards
Release list
3.4.1 - 2026-07-27
This is a security release and all users are advised to update their WordPressCS install as soon as possible.
Changed
- The minimum required
PHPCSUtilsversion to 1.2.3 (was 1.2.2). #2770 - The minimum required
PHPCSExtraversion to 1.5.1 (was 1.5.0). #2770 - Various housekeeping, including documentation improvements.
Fixed
- SECURITY FIX: Running the
WordPress.WP.EnqueuedResourceParameterssniff over untrusted PHP code, for example, in a CI pipeline that lints pull requests, or on a developer machine reviewing third-party code, could lead to arbitrary command execution on the scanning host. #2771
This affects users of theWordPressandWordPress-Extrarulesets. TheWordPress-Coreruleset and theWordPress-Docsruleset are not affected.
For more details, see the security advisory
Thanks to @FORIMOC for responsibly disclosing the vulnerability.
3.4.0
We're happy to welcome @rodrigoprimo as co-maintainer of WordPressCS as of this release.
Added
WordPress.Arrays.ArrayDeclarationSpacing: newallow_single_item_single_line_explicit_key_arraysproperty to replace the, now deprecated,allow_single_item_single_line_associative_arraysproperty. #2696- End-user documentation to the following existing sniffs:
WordPress.Arrays.ArrayDeclarationSpacing(props @RafaelFunchal, @mattgaldino and @rodrigoprimo, #2489, #2593, #2682),WordPress.CodeAnalysis.AssignmentInTernaryCondition(props @Nic-Sevic and @rodrigoprimo, #2488, #2678),WordPress.DB.RestrictedClasses(props @paulgibbs and @rodrigoprimo, #2455, #2689),WordPress.DB.DirectDatabaseQuery(props @jaymcp and @rodrigoprimo, #2458, #2697),WordPress.DB.RestrictedFunctions(props @paulgibbs and @rodrigoprimo, #2453, #2676),WordPress.DB.SlowDBQuery(props @petitphp and @rodrigoprimo, #2464, #2699),WordPress.PHP.DevelopmentFunctions(props @gogdzl and @rodrigoprimo, #2490, #2690),WordPress.PHP.NoSilencedErrors(props @gogdzl and @rodrigoprimo, #2495, #2694),WordPress.PHP.PregQuoteDelimiter(props @tikifez and @rodrigoprimo, #2487, #2677),WordPress.PHP.RestrictedPHPFunctions(props @gogdzl and @rodrigoprimo, #2491, #2693),WordPress.Security.PluginMenuSlug(props @jasonkenison, #2592),WordPress.WP.AlternativeFunctions(props @pamprn09, @bhubbard and @rodrigoprimo, #2496, #2588, #2687),WordPress.WP.DiscouragedConstants(props @RafaelFunchal, @paulopmt1 and @rodrigoprimo, #2493, #2589, #2680),WordPress.WP.GlobalVariablesOverride(props @paulopmt1 and @rodrigoprimo, #2586, #2679).
This documentation can be exposed via thePHP_CodeSniffer--generator=...command-line argument.
Changed
- The minimum required
PHP_CodeSnifferversion to 3.13.5 (was 3.13.4). #2761 - The minimum required
PHPCSUtilsversion to 1.2.2 (was 1.1.0). #2761 - The default value for
minimum_wp_version, as used by a number of sniffs detecting usage of deprecated WP features, has been updated to6.7. #2757 WordPress.NamingConventions.PrefixAllGlobalshas been updated to recognize pluggable functions introduced in WP up to WP 7.0.0. #2747WordPress.WP.ClassNameCasehas been updated to recognize classes introduced in WP up to WP 7.0.0. #2747WordPress.WP.DeprecatedFunctionsnow detects functions deprecated in WordPress up to WP 7.0.0. #2747- The
ConstantsHelper::is_use_of_global_constant()method will no longer flag a constant alias created via an importusestatement as it were the use of a global constant. #2579 - The
ConstantsHelper::is_in_function_call()method will now act fully case-agnostic for the function names being checked. #2706
Previously, the$valid_functionsparameter would need to be passed with the function names as keys in lowercase. WordPress.PHP.NoSilencedErrors: error silencing is no longer accepted for theparse_url()function. #2701- Improved the wording of the error message for
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound. #2688 - Improved the wording of the error message for
WordPress.PHP.RestrictedPHPFunctions. #2702 - Various housekeeping, including documentation and test improvements. Includes a contribution by @dd32.
Deprecated
WordPress.Arrays.ArrayDeclarationSpacing: theallow_single_item_single_line_associative_arraysproperty has been deprecated in favor of the newallow_single_item_single_line_explicit_key_arraysproperty. #2696
This is a name change only. The functionality of these properties is the same.
Fixed
WordPress.DB.PreparedSQLandWordPress.DB.PreparedSQLPlaceholders: false positive for static method calls to a non-global class namedwpdb. #2753WordPress.Security.EscapeOutput: false positive forget_search_query()when the$escapedparameter was passed as fully qualified or non-lowercasetrue. #2618WordPress.Security.EscapeOutput: false negative for_deprecated_file()calls when thebasename( __FILE__ )pattern used non-standard casing for eitherbasename()and/or__FILE__. #2729WordPress.WP.AlternativeFunctions: false negative when class functions/constants/properties use the same name as select global WP constants/functions. #2617WordPress.WP.AlternativeFunctions: false positive for fully qualified references to the global PHP stream constants \STDIN, \STDOUT, and \STDERR. #2617WordPress.WP.CronInterval: false positive when the callback function reference used a different case than the function declaration, even though they are in the same file. #2730
3.3.0
Added
- Support for attributes on anonymous classes (PHP 8.0) and
readonlyanonymous classes (PHP 8.3) to theWordPress.Security.EscapeOutputsniff. Props @rodrigoprimo. #2559 - Support for handling "exit as a function call" (PHP 8.4) to the
WordPress.Security.EscapeOutputsniff. #2563 - WordPress-Extra: the following sniffs have been added to the ruleset:
Universal.Attributes.BracketSpacingandUniversal.Attributes.DisallowAttributeParentheses. #2646
Changed
- The minimum supported PHP version is now PHP 7.2 (was PHP 5.4). #2614
- The minimum required
PHP_CodeSnifferversion to 3.13.4 (was 3.13.0). #2630 - The minimum required
PHPCSExtraversion to 1.5.0 (was 1.4.0). #2646 - The default value for
minimum_wp_version, as used by a number of sniffs detecting usage of deprecated WP features, has been updated to6.6. #2656 WordPress.DB.DirectDatabaseQuerywill now recognize more caching functions, like thewp_cache_*_multiple()functions as added in WordPress 6.0 and thewp_cache_*_salted()functions as added in WordPress 6.9. #2654WordPress.NamingConventions.PrefixAllGlobalshas been updated to recognize pluggable functions introduced in WP up to WP 6.9.0. #2652WordPress.WP.ClassNameCasehas been updated to recognize classes introduced in WP up to WP 6.9.0. #2652WordPress.WP.DeprecatedFunctionsnow detects functions deprecated in WordPress up to WP 6.9.0. #2652WordPress.WP.DeprecatedParametersnow detects parameters deprecated in WordPress up to WP 6.9.0. #2652WordPress.Security.ValidatedSanitizedInput: improved the clarity of the error message for theInputNotValidatederror code. Props @rodrigoprimo. #2642- README: updated
testVersionrecommendations for PHPCompatibility. Props @johnjago. #2471 - Example ruleset: updated the
minimum_wp_versionandtestVersionrecommendations. #2608 - All sniffs are now also being tested against PHP 8.5 for consistent sniff results. #2649
- Various housekeeping, including documentation and test improvements. Includes contributions by @rodrigoprimo.
Deprecated
- The
WordPress.PHP.POSIXFunctionssniff (as it is no longer relevant). #2616
Removed
wp_kses_allowed_html()from the list of escaping functions. #2566
This affects theWordPress.Security.EscapeOutputsniff.
Fixed
WordPress.DB.DirectDatabaseQuery: false positive when function call to caching functions did not use the canonical function name. Props @rodrigoprimo. #2613WordPress.DB.DirectDatabaseQuery: potential false negative when a class property or constant would mirror the name of one of the caching functions. Props @rodrigoprimo. #2615WordPress.DB.PreparedSQL: false positive for correctly escaped SQL snippets when the function call did not use the canonical function name. Props @rodrigoprimo. #2570WordPress.DB.PreparedSQLPlaceholders: improved handling of fully qualified calls to global functions. Props @rodrigoprimo. #2569WordPress.Security.EscapeOutput: expanded protection against false positives for*::class. Props @rodrigoprimo. #2605WordPress.Security.NonceVerification: false positive when nonce checking function call did not use the canonical function name. Props @rodrigoprimo. #2572WordPress.WP.EnqueuedResourceParameters: the sniff could cause a PHP 8.5 deprecation notice if the code under scan contained one of the deprecated type casts. #2573WordPress.WP.EnqueuedResourceParameters: improved recognition of non-lowercase and fully qualifiedtrue/false/nullwhen passed as the$verparameter value. Props @rodrigoprimo. #2630
3.2.0
Added
- New
WordPress.WP.GetMetaSinglesniff to theWordPress-Extraruleset. Props @rodrigoprimo! #2465
This sniff warns whenget_*_meta()andget_metadata*()functions are used with the$meta_key/$keyparam, but without the$singleparameter as this could lead to unexpected behavior due to the different return types. WordPress-Extra: the following additional sniffs have been added to the ruleset:Generic.Strings.UnnecessaryHeredocandGeneric.WhiteSpace.HereNowdocIdentifierSpacing. #2534- The
rest_sanitize_boolean()functions to the list of known "sanitizing" functions. Props @westonruter. #2530 - End-user documentation to the following existing sniffs:
WordPress.DB.PreparedSQL(props @jaymcp, #2454),WordPress.NamingConventions.ValidFunctionName(props @richardkorthuis and @rodrigoprimo, #2452, #2531),WordPress.NamingConventions.ValidVariableName(props @richardkorthuis, #2457),WordPress.PHP.DontExtract(props @aiolachiara #2456).
This documentation can be exposed via thePHP_CodeSniffer--generator=...command-line argument.
Changed
- The minimum required
PHP_CodeSnifferversion to 3.13.0 (was 3.9.0). #2532 - The minimum required
PHPCSUtilsversion to 1.1.0 (was 1.0.10). #2532 - The minimum required
PHPCSExtraversion to 1.4.0 (was 1.2.1). #2532 - Sniffs based on the
AbstractFunctionParameterSniffwill now call a dedicatedprocess_first_class_callable()method for PHP 8.1+ first class callables. Props @rodrigoprimo, @jrfnl. #2518, #2544
By default, the method won't do anything, but individual sniffs extending theAbstractFunctionParameterSniffclass can choose to implement the method to handle first class callables.
Previously, first class callables were treated as a function call without parameters and would trigger theprocess_no_parameters()method. - The minimum required prefix length for the
WordPress.NamingConventions.PrefixAllGlobalssniff has been changed from 3 to 4 characters. Props @davidperezgar. #2479 - The default value for
minimum_wp_version, as used by a number of sniffs detecting usage of deprecated WP features, has been updated to6.5. #2553 WordPress.NamingConventions.ValidVariableNamenow allows for PHP 8.4 properties in interfaces. #2532WordPress.NamingConventions.PrefixAllGlobalshas been updated to recognize pluggable functions introduced in WP up to WP 6.8.1. #2537WordPress.WP.Capabilitieshas been updated to recognize new capabilities introduced in WP up to WP 6.8.1. #2537WordPress.WP.ClassNameCasehas been updated to recognize classes introduced in WP up to WP 6.8.1. #2537WordPress.WP.DeprecatedFunctionsnow detects functions deprecated in WordPress up to WP 6.8.1. #2537WordPress.WP.DeprecatedParametersnow detects parameters deprecated in WordPress up to WP 6.8.1. #2537WordPress.WP.DeprecatedParameterValuesnow detects parameter values deprecated in WordPress up to WP 6.8.1. #2537- Minor performance improvements.
- Developer happiness: prevent creating a
composer.lockfile. Thanks @fredden! #2443 - Various housekeeping, including documentation and test improvements. Includes contributions by @rodrigoprimo and @szepeviktor.
- All sniffs are now also being tested against PHP 8.4 for consistent sniff results. #2511
Removed
- The
Generic.Functions.CallTimePassByReferencehas been removed from theWordPress-Extraruleset. Props @rodrigoprimo. #2536
This sniff was dated anyway and deprecated in PHP_CodeSniffer. If you need to check if your code is PHP cross-version compatible, use the PHPCompatibility standard instead.
Fixed
- Sniffs based on the
AbstractClassRestrictionsSniffcould previously run into a PHPCSInternal.Exception, leading to fixes not being made. #2500 - Sniffs based on the
AbstractFunctionParameterSniffwill now bow out more often when it is sure the code under scan is not calling the target function and during live coding, preventing false positives. Props @rodrigoprimo. #2518
3.1.0
Added
- WordPress-Core ruleset: now includes the
Universal.PHP.LowercasePHPTagsniff. - WordPress-Extra ruleset: now includes the
Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedenceand theUniversal.CodeAnalysis.NoDoubleNegativesniffs. - The
sanitize_locale_name()function to the list of known "escaping" functions. Props @Chouby - The
sanitize_locale_name()function to the list of known "sanitize & unslash" functions. Props @Chouby
Changed
- The minimum required
PHP_CodeSnifferversion to 3.9.0 (was 3.7.2). - The minimum required
PHPCSUtilsversion to 1.0.10 (was 1.0.8). - The minimum required
PHPCSExtraversion to 1.2.1 (was 1.1.0).
Please ensure you runcomposer update wp-coding-standards/wpcs --with-dependenciesto benefit from these updates. - Core ruleset: the spacing after the
usekeyword for closureusestatements will now consistently be checked. Props @westonruter for reporting. - The default value for
minimum_wp_version, as used by a number of sniffs detecting usage of deprecated WP features, has been updated to6.2. WordPress.NamingConventions.PrefixAllGlobalshas been updated to recognize pluggable functions introduced in WP 6.4 and 6.5.WordPress.NamingConventions.ValidPostTypeSlughas been updated to recognize reserved post types introduced in WP 6.4 and 6.5.WordPress.WP.ClassNameCasehas been updated to recognize classes introduced in WP 6.4 and 6.5.WordPress.WP.DeprecatedClassesnow detects classes deprecated in WordPress up to WP 6.5.WordPress.WP.DeprecatedFunctionsnow detects functions deprecated in WordPress up to WP 6.5.- The
IsUnitTestTraitwill now recognize classes which extend the new WP CoreWP_Font_Face_UnitTestCaseclass as test classes. - The test suite can now run on PHPUnit 4.x - 9.x (was 4.x - 7.x), which should make contributing more straight forward.
- Various housekeeping, includes a contribution from @rodrigoprimo.
Fixed
WordPress.WP.PostsPerPagecould potentially result in anInternal.Exceptionwhen encountering a query string which doesn't include the value forposts_per_pagein the query string. Props @anomiex for reporting.
3.0.1
Added
- In WordPressCS 3.0.0, the functionality of the
WordPress.Security.EscapeOutputsniff was updated to report unescaped message parameters passed to exceptions created inthrowstatements. This specific violation now has a separate error code:ExceptionNotEscaped. This will allow users to ignore or exclude that specific error code. Props @anomiex.
The error code(s) for other escaping issues flagged by the sniff remain unchanged.
Changed
- Updated the CI workflow to test the example ruleset for issues.
- Funding files and updates in the Readme about funding the project.
Fixed
- Fixed a sniff name in the
phpcs.xml.dist.samplefile (case-sensitive sniff name). Props @dawidurbanski.
3.0.0
Important information about this release:
At long last... WordPressCS 3.0.0 is here.
This is an important release which makes significant changes to improve the accuracy, performance, stability and maintainability of all sniffs, as well as making WordPressCS much better at handling modern PHP.
WordPressCS 3.0.0 contains breaking changes, both for people using ignore annotations, people maintaining custom rulesets, as well as for sniff developers who maintain a custom PHPCS standard based on WordPressCS.
If you are an end-user or maintain a custom WordPressCS based ruleset, please start by reading the Upgrade Guide to WordPressCS 3.0.0 for ruleset maintainers which lists the most important changes and contains a step by step guide for upgrading.
If you are a maintainer of an external standard based on WordPressCS and any of your custom sniffs are based on or extend WordPressCS sniffs, please read the Upgrade Guide to WordPressCS 3.0.0 for Developers.
In all cases, please read the complete changelog carefully before you upgrade.
Added
- Dependencies on the following packages: PHPCSUtils, PHPCSExtra and the [Composer PHPCS plugin].
- A best effort has been made to add support for the new PHP syntaxes/features to all WordPressCS native sniffs and utility functions (or to verify/improve existing support).
While support in external sniffs used by WordPressCS has not be exhaustively verified, a lot of work has been done to try and add support for new PHP syntaxes to those as well.
WordPressCS native sniffs and utilities have received fixes for the following syntaxes:- PHP 7.2
- Keyed lists.
- PHP 7.3
- Flexible heredoc/nowdoc (providing the PHPCS scan is run on PHP 7.3 or higher).
- Trailing commas in function calls.
- PHP 7.4
- Arrow functions.
- Array unpacking in array expressions.
- Numeric literals with underscores.
- Typed properties.
- Null coalesce equals operator.
- PHP 8.0
- Nullsafe object operators.
- Match expressions.
- Named arguments in function calls.
- Attributes.
- Union types // including supporting the
falseandnulltypes. - Constructor property promotion.
$object::class- Throw as an expression.
- PHP 8.1
- Enumerations.
- Explicit octal notation.
- Final class constants
- First class callables.
- Intersection types.
- PHP 8.2
- Constants in traits.
- PHP 7.2
- New
WordPress.CodeAnalysis.AssignmentInTernaryConditionsniff to theWordPress-Coreruleset which partially replaces the removedWordPress.CodeAnalysis.AssignmentInConditionsniff. - New
WordPress.WhiteSpace.ObjectOperatorSpacingsniff which replaces the use of theSquiz.WhiteSpace.ObjectOperatorSpacingsniff in theWordPress-Coreruleset. - New
WordPress.WP.ClassNameCasesniff to theWordPress-Coreruleset, to check that any class name references to WP native classes and classes from external dependencies use the case of the class as per the class declaration. - New
WordPress.WP.Capabilitiessniff to theWordPress-Extraruleset. This sniff checks that valid capabilities are used, not roles or user levels. Props, amongst others, to [@grappler] and [@khacoder].
Custom capabilities can be added to the sniff via acustom_capabilitiesruleset property.
The sniff also supports theminimum_wp_versionproperty to allow the sniff to accurately determine how the use of deprecated capabilities should be flagged. - The
WordPress.WP.CapitalPDangitsniff contains a new check to verify the correct spelling ofWordPressin namespace names. - The
WordPress.WP.I18nsniff contains a newEmptyTextDomainerror code for an empty text string being passed as the text domain, which overrules the default value of the parameter and renders a text untranslatable. - The
WordPress.DB.PreparedSQLPlaceholderssniff has been expanded with additional checks for the correct use of the%iplaceholder, which was introduced in WP 6.2. Props [@craigfrancis].
The sniff now also supports theminimum_wp_versionruleset property to determine whether the%iplaceholder can be used. WordPress-Core: the following additional sniffs (or select error codes from these sniffs) have been added to the ruleset:Generic.CodeAnalysis.AssignmentInCondition,Generic.CodeAnalysis.EmptyPHPStatement(replaces the WordPressCS native sniff),Generic.VersionControl.GitMergeConflict,Generic.WhiteSpace.IncrementDecrementSpacing,Generic.WhiteSpace.LanguageConstructSpacing,Generic.WhiteSpace.SpreadOperatorSpacingAfter,PSR2.Classes.ClassDeclaration,PSR2.Methods.FunctionClosingBrace,PSR12.Classes.ClassInstantiation,PSR12.Files.FileHeader(select error codes only),PSR12.Functions.NullableTypeDeclaration,PSR12.Functions.ReturnTypeDeclaration,PSR12.Traits.UseDeclaration,Squiz.Functions.MultiLineFunctionDeclaration(replaces part of theWordPress.WhiteSpace.ControlStructureSpacingsniff),Modernize.FunctionCalls.Dirname,NormalizedArrays.Arrays.ArrayBraceSpacing(replaces part of theWordPress.Arrays.ArrayDeclarationSpacingsniff),NormalizedArrays.Arrays.CommaAfterLast(replaces the WordPressCS native sniff),Universal.Classes.ModifierKeywordOrder,Universal.Classes.RequireAnonClassParentheses,Universal.Constants.LowercaseClassResolutionKeyword,Universal.Constants.ModifierKeywordOrder,Universal.Constants.UppercaseMagicConstants,Universal.Namespaces.DisallowCurlyBraceSyntax,Universal.Namespaces.DisallowDeclarationWithoutName,Universal.Namespaces.OneDeclarationPerFile,Universal.NamingConventions.NoReservedKeywordParameterNames,Universal.Operators.DisallowShortTernary(replaces the WordPressCS native sniff),Universal.Operators.DisallowStandalonePostIncrementDecrement,Universal.Operators.StrictComparisons(replaces the WordPressCS native sniff),Universal.Operators.TypeSeparatorSpacing,Universal.UseStatements.DisallowMixedGroupUse,Universal.UseStatements.KeywordSpacing,Universal.UseStatements.LowercaseFunctionConst,Universal.UseStatements.NoLeadingBackslash,Universal.UseStatements.NoUselessAliases,Universal.WhiteSpace.CommaSpacing,Universal.WhiteSpace.DisallowInlineTabs(replaces the WordPressCS native sniff),Universal.WhiteSpace.PrecisionAlignment(replaces the WordPressCS native sniff),Universal.WhiteSpace.AnonClassKeywordSpacing.WordPress-Extra: the following additional sniffs have been added to the ruleset:Generic.CodeAnalysis.UnusedFunctionParameter,Universal.Arrays.DuplicateArrayKey,Universal.CodeAnalysis.ConstructorDestructorReturn,Universal.CodeAnalysis.ForeachUniqueAssignment,Universal.CodeAnalysis.NoEchoSprintf,Universal.CodeAnalysis.StaticInFinalClass,Universal.ControlStructures.DisallowLonelyIf,Universal.Files.SeparateFunctionsFromOO.WordPress.Utils.I18nTextDomainFixer: theload_script_textdomain()function to the functions the sniff looks for.WordPress.WP.AlternativeFunctions: the following PHP native functions have been added to the sniff and will now be flagged when used:unlink()(in a newunlinkgroup) ,rename()(in a newrenamegroup),chgrp(),chmod(),chown(),is_writable()is_writeable(),mkdir(),rmdir(),touch(),fputs()(in the existingfile_system_operationsgroup, which was previously namedfile_system_read). Props [@sandeshjangam] and [@JDGrimes].- The
PHPUnit_Adapter_TestCaseclass to the list of "known test (case) classes". - The
antispambot()function to the list of known "formatting" functions. - The
esc_xml()andwp_kses_one_attr()functions to the list of known "escaping" functions. - The
wp_timezone_choice()andwp_readonly()functions to the list of known "auto escaping" functions. - The
sanitize_url()andwp_kses_one_attr()functions to the list of known "sanitizing" functions. - Metrics for blank lines at the start/end of a control structure body to the
WordPress.WhiteSpace.ControlStructureSpacingsniff. These can be displayed using--report=infowhen theblank_line_checkproperty has been set totrue. - End-user documentation to the following new and pre-existing sniffs:
WordPress.DateTime.RestrictedFunctions,WordPress.NamingConventions.PrefixAllGlobals(props [@Ipstenu]),WordPress.PHP.StrictInArray(props [@marconmartins]),WordPress.PHP.YodaConditions(props [@Ipstenu]),WordPress.WhiteSpace.ControlStructureSpacing(props [@ckanitz]),WordPress.WhiteSpace.ObjectOperatorSpacing,WordPress.WhiteSpace.OperatorSpacing(props [@ckanitz]),WordPress.WP.CapitalPDangit(props [@NielsdeBlaauw]),WordPress.WP.Capabilities,WordPress.WP.ClassNameCase,WordPress.WP.EnqueueResourceParameters(props [@NielsdeBlaauw]).
This documentation can be exposed via thePHP_CodeSniffer--generator=...command-line argument.
Note: all sniffs which have been added from PHPCSExtra (Universal, Modernize, NormalizedArrays sniffs) are also fully documented.
Added (internal/dev-only)
- New Helper classes:
ArrayWalkingFunctionsHelperConstantsHelper*ContextHelper*DeprecationHelper*FormattingFunctionsHelperListHelper*RulesetPropertyHelper*SnakeCaseHelper*UnslashingFunctionsHelperValidationHelperVariableHelper*
...
2.3.0
Added
- The
WordPress.WP.I18nsniff contains a new check for translatable text strings which are wrapped in HTML tags, like<h1>Translate me</h1>. Those tags should be moved out of the translatable string.
Note: Translatable strings wrapped in<a href..>tags where the URL is intended to be localized will not trigger this check.
Changed
- The default value for
minimum_supported_wp_version, as used by a number of sniffs detecting usage of deprecated WP features, has been updated to5.1. - The
WordPress.WP.DeprecatedFunctionssniff will now detect functions deprecated in WP 5.4. - Improved grammar of an error message in the
WordPress.WP.DiscouragedFunctionssniff. - CI: The codebase is now - preliminary - being tested against the PHPCS 4.x development branch.
Fixed
- All function call detection sniffs: fixed a bug where constants with the same name as one of the targeted functions could inadvertently be recognized as if they were a called function.
WordPress.DB.PreparedSQL: fixed a bug where the sniff would trigger on the namespace separator character\\.WordPress.Security.EscapeOutput: fixed a bug with the variable replacement in one of the error messages.
2.2.1
Added
- Metrics to the
WordPress.Arrays.CommaAfterArrayItemsniff. These can be displayed using--report=info. - The
sanitize_hex_color()and thesanitize_hex_color_no_hash()functions to theescapingFunctionslist used by theWordPress.Security.EscapeOutputsniff.
Changed
- The recommended version of the suggested DealerDirect PHPCS Composer plugin is now
^0.6.
Fixed
WordPress.PHP.NoSilencedErrors: depending on the custom properties set, the metrics would be different.WordPress.WhiteSpace.ControlStructureSpacing: fixed undefined index notice for closures withuse.WordPress.WP.GlobalVariablesOverride: fixed undefined offset notice when thetreat_files_as_scopedproperty would be set totrue.WordPress.WP.I18n: fixed a Trying to access array offset on value of type null error when the sniff was run on PHP 7.4 and would encounter a translation function expecting singular and plural texts for which one of these arguments was missing.
2.2.0
Note: The repository has moved. The new URL is https://github.com/WordPress/WordPress-Coding-Standards.
The move does not affect the package name for Packagist. This remains the same: wp-coding-standards/wpcs.
Added
- New
WordPress.DateTime.CurrentTimeTimestampsniff to theWordPress-Coreruleset, which checks against the use of the WP nativecurrent_time()function to retrieve a timestamp as this won't be a real timestamp. Includes an auto-fixer. - New
WordPress.DateTime.RestrictedFunctionssniff to theWordPress-Coreruleset, which checks for the use of certain date/time related functions. Initially this sniff forbids the use of the PHP nativedate_default_timezone_set()anddate()functions. - New
WordPress.PHP.DisallowShortTernarysniff to theWordPress-Coreruleset, which, as the name implies, disallows the use of short ternaries. - New
WordPress.CodeAnalysis.EscapedNotTranslatedsniff to theWordPress-Extraruleset which will warn when a text string is escaped for output, but not being translated, while the arguments passed to the function call give the impression that translation is intended. - New
WordPress.NamingConventions.ValidPostTypeSlugsniff to theWordPress-Extraruleset which will examine calls toregister_post_type()and throw errors when an invalid post type slug is used. Generic.Arrays.DisallowShortArraySyntaxto theWordPress-Coreruleset.WordPress.NamingConventions.PrefixAllGlobals: thePHPprefix has been added to the prefix blacklist as it is reserved by PHP itself.- The
wp_sanitize_redirect()function to thesanitizingFunctionslist used by theWordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInputandWordPress.Security.EscapeOutputsniffs. - The
sanitize_key()and thehighlight_string()functions to theescapingFunctionslist used by theWordPress.Security.EscapeOutputsniff. - The
RECOVERY_MODE_COOKIEconstant to the list of WP Core constants which may be defined by plugins and themes and therefore don't need to be prefixed (WordPress.NamingConventions.PrefixAllGlobals). $content_width,$plugin,$mu_pluginand$network_pluginto the list of WP globals which is used by both theWordPress.Variables.GlobalVariablesand theWordPress.NamingConventions.PrefixAllGlobalssniffs.Sniff::is_short_list()utility method to determine whether a short array open/close token actually represents a PHP 7.1+ short list.Sniff::find_list_open_close()utility method to find the opener and closer forlist()constructs, including short lists.Sniff::get_list_variables()utility method which will retrieve an array with the token pointers to the variables which are being assigned to in alist()construct. Includes support for short lists.Sniff::is_function_deprecated()static utility method to determine whether a declared function has been marked as deprecated in the function DocBlock.- End-user documentation to the following existing sniffs:
WordPress.Arrays.ArrayIndentation,WordPress.Arrays.ArrayKeySpacingRestrictions,WordPress.Arrays.MultipleStatementAlignment,WordPress.Classes.ClassInstantiation,WordPress.NamingConventions.ValidHookName,WordPress.PHP.IniSet,WordPress.Security.SafeRedirect,WordPress.WhiteSpace.CastStructureSpacing,WordPress.WhiteSpace.DisallowInlineTabs,WordPress.WhiteSpace.PrecisionAlignment,WordPress.WP.CronInterval,WordPress.WP.DeprecatedClasses,WordPress.WP.DeprecatedFunctions,WordPress.WP.DeprecatedParameters,WordPress.WP.DeprecatedParameterValues,WordPress.WP.EnqueuedResources,WordPress.WP.PostsPerPage.
This documentation can be exposed via thePHP_CodeSniffer--generator=...command-line argument.
Changed
- The default value for
minimum_supported_wp_version, as used by a number of sniffs detecting usage of deprecated WP features, has been updated to5.0. - The
WordPress.Arrays.ArrayKeySpacingRestrictionssniff has two new error codes:TooMuchSpaceBeforeKeyandTooMuchSpaceAfterKey. Both auto-fixable.
The sniff will now check that there is exactly one space on the inside of the square brackets around the array key for non-string, non-numeric array keys. Previously, it only checked that there was whitespace, not how much whitespace. WordPress.Arrays.ArrayKeySpacingRestrictions: the fixers have been made more efficient and less fixer-conflict prone.WordPress.NamingConventions.PrefixAllGlobals: plugin/theme prefixes should be at least three characters long. A newShortPrefixPassederror has been added for when the prefix passed does not comply with this rule.WordPress.WhiteSpace.CastStructureSpacingnow allows for no whitespace before a cast when the cast is preceded by the spread...operator. This pre-empts a fixer conflict for when the spacing around the spread operator will start to get checked.- The
WordPress.WP.DeprecatedClassessniff will now detect classes deprecated in WP 4.9 and WP 5.3. - The
WordPress.WP.DeprecatedFunctionssniff will now detect functions deprecated in WP 5.3. WordPress.NamingConventions.ValidHookNamenow has "cleaner" error messages and higher precision for the line on which an error is thrown.WordPress.Security.EscapeOutput: if an error refers to array access via a variable, the array index key will now be included in the error message.- The processing of the
WordPressruleset byPHP_CodeSnifferwill now be faster. - Various minor code tweaks and clean up.
- Various minor documentation fixes.
- Documentation: updated the repo URL in all relevant places.
Deprecated
- The
WordPress.WP.TimezoneChangesniff. Use theWordPress.DateTime.RestrictedFunctionsinstead.
The deprecated sniff will be removed in WPCS 3.0.0.
Fixed
- All sniffs in the
WordPress.Arrayscategory will no longer treat short lists as if they were a short array. - The
WordPress.NamingConventions.ValidFunctionNameand theWordPress.NamingConventions.PrefixAllGlobalssniff will now ignore functions marked as@deprecated. - Both the
WordPress.NamingConventions.PrefixAllGlobalssniff as well as theWordPress.WP.GlobalVariablesOverridesniff have been updated to recognize variables being declared via (long/short)list()constructs and handle them correctly. - Both the
WordPress.NamingConventions.PrefixAllGlobalssniff as well as theWordPress.WP.GlobalVariablesOverridesniff will now take a limited list of WP global variables which are intended to be overwritten by plugins/themes into account.
Initially this list contains the$content_widthand the$wp_cockneyreplacevariables. WordPress.NamingConventions.ValidHookName: will no longer examine a string array access index key as if it were a part of the hook name.WordPress.Security.EscapeOutput: will no longer trigger on the typicalbasename( __FILE__ )pattern if found as the first parameter passed to a call to_deprecated_file().WordPress.WP.CapitalPDangit: now allows for the.testTLD in URLs.- WPCS is now fully compatible with PHP 7.4.
Note:PHP_CodeSnifferitself is only compatible with PHP 7.4 from PHPCS 3.5.0 onwards.