Releases: WordPress/WordPress-Coding-Standards
2.0.0
Important information about this release:
WordPressCS 2.0.0 contains breaking changes, both for people using custom rulesets as well as for sniff developers who maintain a custom PHPCS standard based on WordPressCS.
Support for PHP_CodeSniffer 2.x has been dropped, the new minimum PHP_CodeSniffer version is 3.3.1.
Also, all previously deprecated sniffs, properties and methods have been removed.
Please read the complete changelog carefully before you upgrade.
If you are a maintainer of an external standard based on WordPressCS and any of your custom sniffs are based on or extend WPCS sniffs, please read the Developers Upgrade Guide to WordPressCS 2.0.0.
Changes since 2.0.0-RC1
Fixed
WordPress-Extra: Reverted back to including theSquiz.WhiteSpace.LanguageConstructSpacingsniff instead of the newGeneric.WhiteSpace.LanguageConstructSpacingsniff as the new sniff is not (yet) available when the PEAR install of PHPCS is used.
Changes since 1.2.1
For a full list of changes from the 1.2.1 version, please review the following changelog:
2.0.0-RC1
Important information about this release:
This is the first release candidate for WordPressCS 2.0.0.
WordPressCS 2.0.0 contains breaking changes, both for people using custom rulesets as well as for sniff developers who maintain a custom PHPCS standard based on WordPressCS.
Support for PHP_CodeSniffer 2.x has been dropped, the new minimum PHP_CodeSniffer version is 3.3.1.
Also, all previously deprecated sniffs, properties and methods have been removed.
Please read the complete changelog carefully before you upgrade.
If you are a maintainer of an external standard based on WordPressCS and any of your custom sniffs are based on or extend WPCS sniffs, please read the Developers Upgrade Guide to WordPressCS 2.0.0.
Added
Generic.PHP.DiscourageGoto,Generic.PHP.LowerCaseType,Generic.WhiteSpace.ArbitraryParenthesesSpacingandPSR12.Keywords.ShortFormTypeKeywordsto theWordPress-Coreruleset.- Checking the spacing around the
instanceofoperator to theWordPress.WhiteSpace.OperatorSpacingsniff.
Changed
- The minimum required
PHP_CodeSnifferversion to 3.3.1 (was 2.9.0). - The namespace used by WordPressCS has been changed from
WordPresstoWordPressCS\WordPress.
This was not possible whilePHP_CodeSniffer2.x was still supported, but WordPressCS, as a good Open Source citizen, does not want to occupy theWordPressnamespace and is releasing its use of it now this is viable. - The
WordPress.DB.PreparedSQLsniff used the same error code for two different errors.
TheNotPreparederror code remains, however an additionalInterpolatedNotPreparederror code has been added for the second error.
If you are referencing the old error code in a ruleset XML file or in inline annotations, you may need to update it. - The
WordPress.NamingConventions.PrefixAllGlobalssniff used the same error code for some errors as well as warnings.
TheNonPrefixedConstantFounderror code remains for the related error, but the warning will now use the newVariableConstantNameFounderror code.
TheNonPrefixedHooknameFounderror code remains for the related error, but the warning will now use the newDynamicHooknameFounderror code.
If you are referencing the old error codes in a ruleset XML file or in inline annotations, you may need to update these to use the new codes instead. WordPress.NamingConventions.ValidVariableName: the error messages and error codes used by this sniff have been changed for improved usability and consistency.- The error messages will now show a suggestion for a valid alternative name for the variable.
- The
NotSnakeCaseMemberVarerror code has been renamed toUsedPropertyNotSnakeCase. - The
NotSnakeCaseerror code has been renamed toVariableNotSnakeCase. - The
MemberNotSnakeCaseerror code has been renamed toPropertyNotSnakeCase. - The
StringNotSnakeCaseerror code has been renamed toInterpolatedVariableNotSnakeCase.
If you are referencing the old error codes in a ruleset XML file or in inline annotations, you may need to update these to use the new codes instead.
- The
WordPress.Security.NonceVerificationsniff used the same error code for both an error as well as a warning.
The old error codeNoNonceVerificationis no longer used.
Theerrornow uses theMissingerror code, while thewarningnow uses theRecommendederror code.
If you are referencing the old error code in a ruleset XML file or in inline annotations, please update these to use the new codes instead. - The
WordPress.WP.DiscouragedConstantssniff used to have two error codesUsageFoundandDeclarationFound.
These error codes will now be prefixed by the name of the constant found to allow for more fine-grained excluding/ignoring of warnings generated by this sniff.
If you are referencing the old error codes in a ruleset XML file or in inline annotations, you may need to update these to use the new codes instead. - The
WordPress.WP.GlobalVariablesOverride.OverrideProhibitederror code has been replaced by theWordPress.WP.GlobalVariablesOverride.Prohibitederror code.
If you are referencing the old error code in a ruleset XML file or in inline annotations, you may need to update it. WordPress-Extra: Replaced the inclusion of theGeneric.Files.OneClassPerFile,Generic.Files.OneInterfacePerFileand theGeneric.Files.OneTraitPerFilesniffs with the newGeneric.Files.OneObjectStructurePerFilesniff.WordPress-Extra: Replaced the inclusion of theSquiz.WhiteSpace.LanguageConstructSpacingsniff with the newGeneric.WhiteSpace.LanguageConstructSpacingsniff.WordPress-Extra: Replaced the inclusion of theSquiz.Scope.MemberVarScopesniff with the more comprehensivePSR2.Classes.PropertyDeclarationsniff.WordPress.NamingConventions.ValidFunctionName: Added a unit test confirming support for interfaces extending multiple interfaces.WordPress.NamingConventions.ValidVariableName: Added unit tests confirming support for multi-variable/property declarations.- The
get_name_suggestion()method has been moved from theWordPress.NamingConventions.ValidFunctionNamesniff to the baseSniffclass, renamed toget_snake_case_name_suggestion()and made static. - The rulesets are now validated against the
PHP_CodeSnifferXSD schema. - Updated the custom ruleset example to use the recommended ruleset syntax for
PHP_CodeSniffer3.3.1+, including using the new array property format which is now supported. - Dev: The command to run the unit tests has changed. Please see the updated instructions in the CONTRIBUTING.md file.
Thebin/pre-commitexample git hook has been updated to match. Additionally arun-testsscript has been added to thecomposer.jsonfile for your convenience.
To facilitate this, PHPUnit has been added torequire-dev, even though it is strictly speaking a dependency of PHPCS, not of WPCS. - Dev: The DealerDirect PHPCS Composer plugin has been added to
require-dev. - Various code tweaks and clean up.
- User facing documentation, including the wiki, as well as inline documentation has been updated for all the changes contained in WordPressCS 2.0 and other recommended best practices for
PHP_CodeSniffer3.3.1+.
Deprecated
- The use of the WordPressCS native whitelist comments, which were introduced in WPCS 0.4.0, have been deprecated and support will be removed in WPCS 3.0.0.
The WordPressCS native whitelist comments will continue to work for now, but a deprecation warning will be thrown when they are encountered.
You are encouraged to upgrade our whitelist comment to use the PHPCS native selective ignore annotations as introduced inPHP_CodeSniffer3.2.0, as soon as possible.
Removed
- Support for PHP 5.3. PHP 5.4 is the minimum requirement for
PHP_CodeSniffer3.x.
Includes removing any and all workarounds which were in place to still support PHP 5.3. - Support for
PHP_CodeSniffer< 3.3.1.
Includes removing any and all workarounds which were in place for supporting olderPHP_CodeSnifferversions. - The
WordPress-VIPstandard which was deprecated since WordPressCS 1.0.0.
For checking a theme/plugin for hosting on the WordPress.com VIP platform, please use the Automattic VIP coding standards instead. - Support for array properties set in a custom ruleset without the
type="array"attribute.
Support for this was deprecated in WPCS 1.0.0.
If in doubt about how properties should be set in your custom ruleset, please refer to the Customizable sniff properties wiki page which contains XML code examples for setting each and every WPCS native sniff property.
As the minimumPHP_CodeSnifferversion is now 3.3.1, you can now also use the new format for setting array properties, so this would be a great moment to review and update your custom ruleset.
Note: the ability to set select properties from the command-line as comma-delimited strings is not affected by this change. - The following sniffs have been removed outright without deprecation.
If you are referencing these sniffs in a ruleset XML file or in inline annotations, please update these to reference the replacement sniffs instead.WordPress.Functions.FunctionCallSignatureNoParams- superseded by a bug fix in the upstreamPEAR.Functions.FunctionCallSignaturesniff.WordPress.PHP.DiscourageGoto- replaced by the same sniff which is now available upstream:Generic.PHP.DiscourageGoto.WordPress.WhiteSpace.SemicolonSpacing- superseded by a bug fix in the upstreamSquiz.WhiteSpace.SemicolonSpacingsniff.WordPress.WhiteSpace.ArbitraryParenthesesSpacing- replaced by the same sniff which is now available upstream:Generic.WhiteSpace.ArbitraryParenthesesSpacing.
- The following "base" sniffs which were previously already deprecated and turned into abstract base classes, have been removed:
WordPress.Arrays.ArrayAssignmentRestrictions- use the `Abstract...
1.2.1
Note: This will be the last release supporting PHP_CodeSniffer 2.x.
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 to4.7. - The
WordPress.NamingConventions.PrefixAllGlobalssniff will now report the error for hook names and constant names declared withdefine()on the line containing the parameter for the hook/constant name. Previously, it would report the error on the line containing the function call. - Various minor housekeeping fixes to inline documentation, rulesets, code.
Removed
comment_author_email_link(),comment_author_email(),comment_author_IP(),comment_author_link(),comment_author_rss(),comment_author_url_link(),comment_author_url(),comment_author(),comment_date(),comment_excerpt(),comment_form_title(),comment_form(),comment_id_fields(),comment_ID(),comment_reply_link(),comment_text_rss(),comment_text(),comment_time(),comment_type(),comments_link(),comments_number(),comments_popup_link(),comments_popup_script(),comments_rss_link(),delete_get_calendar_cache(),edit_bookmark_link(),edit_comment_link(),edit_post_link(),edit_tag_link(),get_footer(),get_header(),get_sidebar(),get_the_title(),next_comments_link(),next_image_link(),next_post_link(),next_posts_link(),permalink_anchor(),posts_nav_link(),previous_comments_link(),previous_image_link(),previous_post_link(),previous_posts_link(),sticky_class(),the_attachment_link(),the_author_link(),the_author_meta(),the_author_posts_link(),the_author_posts(),the_category_rss(),the_category(),the_content_rss(),the_content(),the_date_xml(),the_excerpt_rss(),the_excerpt(),the_feed_link(),the_ID(),the_meta(),the_modified_author(),the_modified_date(),the_modified_time(),the_permalink(),the_post_thumbnail(),the_search_query(),the_shortlink(),the_tags(),the_taxonomies(),the_terms(),the_time(),the_title_rss(),the_title(),wp_enqueue_script(),wp_meta(),wp_shortlink_header()andwp_shortlink_wp_head()from the list of auto-escaped functionsSniff::$autoEscapedFunctions. This affects theWordPress.Security.EscapeOutputsniff.
Fixed
- The
WordPress.WhiteSpace.PrecisionAlignmentsniff would loose the value of a custom setignoreAlignmentTokensproperty when scanning more than one file.
1.2.0
Added
- New
WordPress.PHP.TypeCastssniff to theWordPress-Coreruleset.
This new sniff checks that PHP type casts are:- lowercase;
- short form, i.e.
(bool)not(boolean); - normalized, i.e.
(float)not(real).
Additionally, the new sniff discourages the use of the(unset)and(binary)type casts.
- New
WordPress.Utils.I18nTextDomainFixersniff which can compehensively replace/addtext-domains in a plugin or theme.
Important notes:- This sniff is disabled by default and intended as a utility tool.
- The sniff will fix the text domains in all I18n function calls as well as in a plugin/theme
Text Domain:header. - Passing the following properties will activate the sniff:
old_text_domain: an array with one or more (old) text domains which need to be replaced;new_text_domain: the correct (new) text domain as a string.
- The
WordPress.NamingConventions.PrefixAllGlobalssniff will now also verify that namespace names use a valid prefix.- The sniff allows for underscores and (other) non-word characters in a passed prefix to be converted to namespace separators when used in a namespace name.
In other words, if a prefix ofmy_pluginis passed as a value to theprefixesproperty, a namespace name of bothMy\Pluginas well asMy_Plugin\\, will be accepted automatically. - Passing a prefix property value containing namespace separators will now also be allowed and will no longer trigger a warning.
- The sniff allows for underscores and (other) non-word characters in a passed prefix to be converted to namespace separators when used in a namespace name.
WordPressto the prefix blacklist for theWordPress.NamingConventions.PrefixAllGlobalssniff.
While the prefix cannot beWordPress, a prefix can still start with or containWordPress.- Additional unit tests covering a change in the tokenizer which will be included in the upcoming
PHP_CodeSniffer3.4.0 release. - A variety of issue templates for use on GitHub.
Changed
- The
Sniff::valid_direct_scope()method will now return the$stackPtrto the valid scope if a valid direct scope has been detected. Previously, it would returntrue. - Minor hardening and efficiency improvements to the
WordPress.NamingConventions.PrefixAllGlobalssniff. - The inline documentation of the
WordPress-Coreruleset has been updated to be in line again with the handbook. - The inline links to documentation about the VIP requirements have been updated.
- Updated the custom ruleset example to recommend using
PHPCompatibilityWPrather thanPHPCompatibility. - All sniffs are now also being tested against PHP 7.3 for consistent sniff results.
Note: PHP 7.3 is only supported in combination with PHPCS 3.3.1 or higher asPHP_CodeSnifferitself has an incompatibility in earlier versions. - Minor grammar fixes in text strings and documentation.
- Minor consistency improvement for the unit test case files.
- Minor tweaks to the
composer.jsonfile. - Updated the PHPCompatibility
devdependency.
Removed
- The
WordPress.WhiteSpace.CastStructureSpacing.NoSpaceAfterCloseParenthesiserror code as an error for the same issue was already being thrown by an included upstream sniff.
Fixed
- The
WordPress.CodeAnalysis.EmptyStatementwould throw a false positive for an empty condition in afor()statement. - The
Sniff::is_class_property()method could, in certain circumstances, incorrectly recognize parameters in a method declaration as class properties. It would also, incorrectly, fail to recognize class properties when the object they are declared in, was nested in parentheses.
This affected, amongst others, theGlobalVariablesOverridesniff. - The
Sniff::get_declared_namespace_name()method could get confused over whitespace and comments within a namespace name, which could lead to incorrect results (mostly underreporting).
This affected, amongst others, theGlobalVariablesOverridesniff.
The return value of the method will now no longer contain any whitespace or comments encountered. - The
Sniff::has_whitelist_comment()method would sometimes incorrectly regard// phpcs:setcomments as whitelist comments.
1.1.0
Added
- New
WordPress.PHP.NoSilencedErrorssniff. This sniff replaces theGeneric.PHP.NoSilencedErrorssniff which was previously used and included in theWordPress-Coreruleset.
The WordPress specific version of the sniff differs from the PHPCS version in that it:- Allows the error control operator
@if it preceeds a function call to a limited list of PHP functions for which no amount of error checking can prevent a PHP warning from being thrown. - Allows for a used-defined list of (additional) function names to be passed to the sniff via the
custom_whitelistproperty in a custom ruleset, for which - if the error control operator is detected in front of a function call to one of the functions in this whitelist - no warnings will be thrown. - Displays a brief snippet of code in the
warningmessage text to show the context in which the error control operator is being used. The length of the snippet (in tokens) can be customized via thecontext_lengthproperty. - Contains a public
use_default_whitelistproperty which can be set from a custom ruleset which regulates whether or not the standard whitelist of PHP functions should be used by the sniff.
The user-defined whitelist will always be respected.
By default, this property is set totruefor theWordPress-Coreruleset and tofalsefor theWordPress-Extraruleset (which is stricter regarding these kind of best practices).
- Allows the error control operator
- Metrics to the
WordPress.NamingConventions.PrefixAllGlobalssniff to aid people in determining the most commonly used prefix in a legacy project.
For an example of how to use this feature, please see the detailed explanation in the pull request.
Changed
- The
PEAR.Functions.FunctionCallSignaturesniff, which is part of theWordPress-Coreruleset, used to allow multiple function call parameters per line in multi-line function calls. This will no longer be allowed.
As of this release, if a function call is multi-line, each parameter should start on a new line and anerrorwill be thrown if the code being analysed does not comply with that rule.
The sniff behaviour for single-line function calls is not affected by this change. - Moved the
WordPress.CodeAnalysis.EmptyStatementsniff from theWordPress-Extrato theWordPress-Coreruleset. - Moved the
Squiz.PHP.CommentedOutCodesniff from theWordPress-Docsto theWordPress-Extraruleset and lowered the threshold for determining whether or not a comment is commented out code from 45% to 40%. - The
WordPress.NamingConventions.PrefixAllGlobalssniff now has improved support for recognizing whether or not (non-prefixed) globals are declared in the context of unit tests. - The
is_foreach_as()method has been moved from theGlobalVariablesOverrideSniffclass to the WordPressSniffbase class. - The
Sniff::is_token_in_test_method()utility method now has improved support for recognizing test methods in anonymous classes. - Minor efficiency improvement to the
Sniff::is_safe_casted()method. - CI: Minor tweaks to the Travis script.
- CI: Improved Composer scripts for use by WPCS developers.
- Dev: Removed IDE specific files from
.gitignore. - Readme: Improved the documentation about the project history and the badge display.
Fixed
- The
WordPress.Security.ValidatedSanitizedInputsniff will now recognize array keys in superglobals independently of the string quote-style used for the array key. - The
WordPress.WhiteSpace.PrecisionAlignmentsniff will no longer throw false positives for DocBlocks for JavaScript functions within inline HTML. WordPress.WP.DeprecatedClasses: The error codes for this sniff were unstable as they were based on the code being analysed instead of on fixed values.- Various bugfixes for the
WordPress.WP.GlobalVariablesOverridesniff:- Previously, the sniff only checked variables in the global namespace when a
globalstatement would be encountered. As of now, all variable assignments in the global namespace will be checked. - Nested functions/closures/classes which don't import the global variable will now be skipped over when encountered within another function, preventing false positives.
- Parameters in function declarations will no longer throw false positives.
- The error message for assignments to a subkey of the
$GLOBALSsuperglobal has been improved. - Various efficiency improvements.
- Previously, the sniff only checked variables in the global namespace when a
- The
Sniff::is_in_isset_or_empty()method presumed the WordPress coding style regarding code layout, which could lead to incorrect results (mostly underreporting).
This affected, amongst others, theWordPress.Security.ValidatedSanitizedInputsniff. - Broken links in the inline developer documentation.
1.0.0
Important information about this release:
If you use the WordPress Coding Standards with a custom ruleset, please be aware that a number of sniffs have been moved between categories and that the old sniff names have been deprecated.
If you selectively include any of these sniffs in your custom ruleset or set custom property values for these sniffs, your custom ruleset will need to be updated.
The WordPress-VIP ruleset has also been deprecated. If you used that ruleset to check your theme/plugin for hosting on the WordPress.com VIP platform, please use the Automattic VIP coding standards instead.
If you used that ruleset for any other reason, you should probably use the WordPress-Extra or WordPress ruleset instead.
These and some related changes have been annotated in detail in the Deprecated section of this changelog.
Please read the complete changelog carefully before you upgrade.
If you are a maintainer of an external standard based on WPCS and any of your custom sniffs are based on or extend WPCS sniffs, the same applies.
Added
WordPress.PHP.PregQuoteDelimitersniff to theWordPress-Extraruleset to warn about calls topreg_quote()which don't pass the$delimiterparameter.WordPress.Security.SafeRedirectsniff to theWordPress-Extraruleset to warn about potential open redirect vulnerabilities.WordPress.WP.DeprecatedParameterValuessniff to theWordPress-Extraruleset to detect deprecated parameter values being passed to select functions.WordPress.WP.EnqueuedResourceParameterssniff to theWordPress-Extraruleset to detect:- Calls to the script/style register/enqueue functions which don't pass a
$versionfor the script/style, which can cause issues with browser caching; and/or - Calls to the register/enqueue script functions which don't pass the
$in_footerparameter, which causes scripts - by default - to be loaded in the HTML header in a layout rendering blocking manner.
- Calls to the script/style register/enqueue functions which don't pass a
- Detection of calls to
strip_tags()and various PHP native..rand()functions to theWordPress.WP.AlternativeFunctionssniff. readonly()to the list of auto-escaped functionsSniff::$autoEscapedFunctions. This affects theWordPress.Security.EscapeOutputsniff.- The
WordPress.Security.PluginMenuSlug,WordPress.WP.CronInterval,WordPress.WP.PostsPerPageandWordPress.WP.TimezoneChangesniffs are now included in theWordPress-Extraruleset. Previously, they were already included in theWordPressandWordPress-VIPrulesets. - New utility method
Sniff::is_use_of_global_constant(). - A rationale to the package suggestion made via
composer.json. - CI: Validation of the
composer.jsonfile on each build. - A wiki page with instructions on how to set up WPCS to run with Eclipse on XAMPP.
- Readme: A link to an external resource with more examples for setting up PHPCS for CI.
- Readme: A badge-based quick overview of the project.
Changed
- The
WordPressruleset no longer includes theWordPress-VIPruleset, nor does it include any of the (deprecated)VIPsniffs anymore. - The following sniffs have been moved to a new category:
CronIntervalfrom theVIPcategory to theWPcategory.DirectDatabaseQueryfrom theVIPcategory to theDBcategory.DontExtractfrom theFunctionscategory to thePHPcategory.EscapeOutputfrom theXSScategory to theSecuritycategory.GlobalVariablesfrom theVariablescategory to theWPcategory.NonceVerificationfrom theCSRFcategory to theSecuritycategory.PluginMenuSlugfrom theVIPcategory to theSecuritycategory.PreparedSQLfrom theWPcategory to theDBcategory.SlowDBQueryfrom theVIPcategory to theDBcategory.TimezoneChangefrom theVIPcategory to theWPcategory.ValidatedSanitizedInputfrom theVIPcategory to theSecuritycategory.
- The
WordPress.VIP.PostsPerPagesniff has been split into two distinct sniffs:WordPress.WP.PostsPerPagewhich will check for the use of a high pagination limit and will throw awarningwhen this is encountered. For theVIPruleset, the error level remainserror.WordPress.VIP.PostsPerPagewich will check for disabling of pagination.
- The default value for
minimum_supported_wp_version, as used by a number of sniffs detecting usage of deprecated WP features, has been updated to4.6. - The
WordPress.WP.AlternativeFunctionssniff will now only throw a warning if/when the recommended alternative function is available in the minimum supported WP version of a project.
In addition to this, certain alternatives are only valid alternatives in certain circumstances, like when the WP version only supports the first parameter of the PHP function it is trying to replace.
This will now be taken into account for:wp_strip_all_tags()is only a valid alternative for the PHP nativestrip_tags()when the second parameter$allowed_tagshas not been passed.wp_parse_url()only added support for the second parameter$componentof the PHP nativeparse_url()function in WP 4.7.0.
- The
WordPress.WP.DeprecatedFunctionssniff will now detect functions deprecated in WP 4.9. - The
WordPress.WP.GlobalVariablesOverridesniff will now display the name of the variable being overridden in the error message. - The
WordPress.WP.I18nsniff now extends theAbstractFunctionRestrictionSniff. - Assignments in conditions in ternaries as detected by the
WordPress.CodeAnalysis.AssignmentInConditionsniff will now be reported under a separate error codeFoundInTernaryCondition. - The default error level for the notices from the
WordPress.DB.DirectDatabaseQuerysniff has been lowered fromerrortowarning. For theVIPruleset, the error level remainserror. - The default error level for the notices from the
WordPress.Security.PluginMenuSlugsniff has been lowered fromerrortowarning. For theVIPruleset, the error level remainserror. - The default error level for the notices from the
WordPress.WP.CronIntervalsniff has been lowered fromerrortowarning. For theVIPruleset, the error level remainserror. - The
Sniff::get_function_call_parameters()utility method now has improved handling of closures when passed as function call parameters. - Rulesets: a number of error codes were previously silenced by explicitly
exclude-ing them. Now, they will be silenced by setting theseverityto0which makes it more easily discoverable for maintainers of custom rulesets how to enable these error codes again. - Various performance optimizations which should most notably make a difference when running WPCS on PHP 7.
- References to the WordPress.com VIP platform have been clarified.
- Unit Tests: custom properties set in unit test files are reset after use.
- Various improvements to the ruleset used by the WPCS project itself and minor code clean up related to this.
- CI: Each change will now also be tested against the lowest supported PHPCS 3 version.
- CI: Each change will now also be checked for PHP cross-version compatibility.
- CI: The rulesets will now also be tested on each change to ensure no unexpected messages are thrown.
- CI: Minor changes to the script to make the build testing faster.
- Updated the custom ruleset example for the changes contained in this release and to reflect current best practices regarding the PHPCompatibility standard.
- The instructions on how to set up WPCS for various IDEs have been moved from the
READMEto the wiki. - Updated output examples in
README.mdandCONTRIBUTING.mdand other minor changes to these files. - Updated references to the PHPCompatibility standard to reflect its new location and recommend using PHPCompatibilityWP.
Deprecated
- The
WordPress-VIPruleset has been deprecated.
For checking a theme/plugin for hosting on the WordPress.com VIP platform, please use the Automattic VIP coding standards instead.
If you used theWordPress-VIPruleset for any other reason, you should probably use theWordPress-ExtraorWordPressruleset instead. - The following sniffs have been deprecated and will be removed in WPCS 2.0.0:
WordPress.CSRF.NonceVerification- useWordPress.Security.NonceVerificationinstead.WordPress.Functions.DontExtract- useWordPress.PHP.DontExtractinstead.WordPress.Variables.GlobalVariables- useWordPress.WP.GlobalVariablesOverrideinstead.WordPress.VIP.CronInterval- useWordPress.WP.CronIntervalinstead.WordPress.VIP.DirectDatabaseQuery- useWordPress.DB.DirectDatabaseQueryinstead.WordPress.VIP.PluginMenuSlug- useWordPress.Security.PluginMenuSluginstead.WordPress.VIP.SlowDBQuery- useWordPress.DB.SlowDBQueryinstead.WordPress.VIP.TimezoneChange- useWordPress.WP.TimezoneChangeinstead.WordPress.VIP.ValidatedSanitizedInput- useWordPress.Security.ValidatedSanitizedInputinstead.WordPress.WP.PreparedSQL- useWordPress.DB.PreparedSQLinstead.WordPress.XSS.EscapeOutput- useWordPress.Security.EscapeOutputinstead.- `WordPress.VIP.AdminBarRemova...
0.14.1
0.14.0
Added
WordPress.Arrays.MultipleStatementAlignmentsniff to theWordPress-Coreruleset which will align the array assignment operator for multi-item, multi-line associative arrays.
This new sniff offers four custom properties to customize its behaviour:ignoreNewlines,exact,maxColumnandalignMultilineItems.WordPress.DB.PreparedSQLPlaceholderssniff to theWordPress-Coreruleset which will analyse the placeholders passed to$wpdb->prepare()for their validity, check whether queries usingIN ()andLIKEstatements are created correctly and will check whether a correct number of replacements are passed.
This sniff should help detect queries which are impacted by the security fixes to$wpdb->prepare()which shipped with WP 4.8.2 and 4.8.3.
The sniff also adds a new "PreparedSQLPlaceholders replacement count" whitelist comment for pertinent replacement count vs placeholder mismatches. Please consider carefully whether something could be a bug when you are tempted to use the whitelist comment and if so, report it.WordPress.PHP.DiscourageGotosniff to theWordPress-Coreruleset.WordPress.PHP.RestrictedFunctionssniff to theWordPress-Coreruleset which initially forbids the use ofcreate_function().
This was previous only discouraged under certain circumstances.WordPress.WhiteSpace.ArbitraryParenthesesSpacingsniff to theWordPress-Coreruleset which checks the spacing on the inside of arbitrary parentheses.WordPress.WhiteSpace.PrecisionAlignmentsniff to theWordPress-Coreruleset which will throw a warning when precision alignment is detected in PHP, JS and CSS files.WordPress.WhiteSpace.SemicolonSpacingsniff to theWordPress-Coreruleset which will throw a (fixable) error when whitespace is found before a semi-colon, except for when the semi-colon denotes an emptyfor()condition.WordPress.CodeAnalysis.AssignmentInConditionsniff to theWordPress-Extraruleset.WordPress.WP.DiscouragedConstantssniff to theWordPress-ExtraandWordPress-VIPrulesets to detect usage of deprecated WordPress constants, such asSTYLESHEETPATHandHEADER_IMAGE.- Ability to pass the
minimum_supported_versionto use for theDeprecatedFunctions,DeprecatedClassesandDeprecatedParameterssniff in one go. You can pass aminimum_supported_wp_versionruntime variable for this from the command line or pass it using aconfigdirective in a custom ruleset. Generic.Formatting.MultipleStatementAlignment- customized to have amaxPaddingof40-,Generic.Functions.FunctionCallArgumentSpacingandSquiz.WhiteSpace.ObjectOperatorSpacingto theWordPress-Coreruleset.Squiz.Scope.MethodScope,Squiz.Scope.MemberVarScope,Squiz.WhiteSpace.ScopeKeywordSpacing,PSR2.Methods.MethodDeclaration,Generic.Files.OneClassPerFile,Generic.Files.OneInterfacePerFile,Generic.Files.OneTraitPerFile,PEAR.Files.IncludingFile,Squiz.WhiteSpace.LanguageConstructSpacing,PSR2.Namespaces.NamespaceDeclarationto theWordPress-Extraruleset.- The
is_class_constant(),is_class_propertyandvalid_direct_scope()utility methods to theWordPress\Sniffclass.
Changed
- When passing an array property via a custom ruleset to PHP_CodeSniffer, spaces around the key/value are taken as intentional and parsed as part of the array key/value. In practice, this leads to confusion and WPCS does not expect any values which could be preceded/followed by a space, so for the WordPress Coding Standard native array properties, like
customAutoEscapedFunction,text_domain,prefixes, WPCS will now trim whitespace from the keys/values received before use. - The WPCS native whitelist comments used to only work when they were put on the end of the line of the code they applied to. As of now, they will also be recognized when they are be put at the end of the statement they apply to.
- The
WordPress.Arrays.ArrayDeclarationSpacingsniff used to enforce all associative arrays to be multi-line. The handbook has been updated to only require this for multi-item associative arrays and the sniff has been updated accordingly.
The original behaviour can still be enforced by setting the newallow_single_item_single_line_associative_arraysproperty tofalsein a custom ruleset. - The
WordPress.NamingConventions.PrefixAllGlobalssniff will now allow for a limited list of WP core hooks which are intended to be called by plugins and themes. - The
WordPress.PHP.DiscouragedFunctionssniff used to includecreate_function. This check has been moved to the newWordPress.PHP.RestrictedFunctionssniff. - The
WordPress.PHP.StrictInArraysniff now has a separate error codeFoundNonStrictFalsefor when the$strictparameter has been set tofalse. This allows for excluding the warnings for that particular situation, which will normally be intentional, via a custom ruleset. - The
WordPress.VIP.CronIntervalsniff now allows for customizing the minimum allowed cron interval by setting a property in a custom ruleset. - The
WordPress.VIP.RestrictedFunctionssniff used to prohibit the use of certain WP native functions, recommending the use ofwpcom_vip_get_term_link(),wpcom_vip_get_term_by()andwpcom_vip_get_category_by_slug()instead, as the WP native functions were not being cached. As the results of the relevant WP native functions are cached as of WP 4.8, the advice has now been reversed i.e. use the WP native functions instead ofwpcom...functions. - The
WordPress.VIP.PostsPerPagesniff now allows for customizing thepost_per_pagelimit for which the sniff will trigger by setting a property in a custom ruleset. - The
WordPress.WP.I18nsniff will now allow and actively encourage omitting the text-domain in I18n function calls if the text-domain passed via thetext_domainproperty isdefault, i.e. the domain used by Core.
Whendefaultis one of several text-domains passed via thetext_domainproperty, the error thrown when the domain is missing has been downgraded to awarning. - The
WordPress.XSS.EscapeOutputsniff now has a separate error codeOutputNotEscapedShortEchoand the error message texts have been updated. - Moved
Squiz.PHP.Evalfrom theWordPress-ExtraandWordPress-VIPto theWordPress-Coreruleset. - Removed two sniffs from the
WordPress-VIPruleset which were already included via theWordPress-Coreruleset. - The unit test suite is now compatible with PHPCS 3.1.0+ and PHPUnit 6.x.
- Some tidying up of the unit test case files.
- All sniffs are now also being tested against PHP 7.2 for consistent sniff results.
- An attempt is made to detect potential fixer conflicts early via a special build test.
- Various minor documentation fixes.
- Improved the Atom setup instructions in the Readme.
- Updated the unit testing information in Contributing.
- Updated the custom ruleset example for the changes contained in this release and to make it more explicit what is recommended versus example code.
- The minimum recommended version for the suggested
DealerDirect/phpcodesniffer-composer-installerComposer plugin has gone up to0.4.3. This patch version fixes support for PHP 5.3.
Fixed
- The
WordPress.Arrays.ArrayIndentationsniff did not correctly handle array items with multi-line strings as a value. - The
WordPress.Arrays.ArrayIndentationsniff did not correctly handle array items directly after an array item with a trailing comment. - The
WordPress.Classes.ClassInstantiationsniff will now correctly handle detection when usingnew $array['key']ornew $array[0]. - The
WordPress.NamingConventions.PrefixAllGlobalssniff did not allow for arbitrary word separators in hook names. - The
WordPress.NamingConventions.PrefixAllGlobalssniff did not correctly recognize namespaced constants as prefixed. - The
WordPress.PHP.StrictInArraysniff would erronously trigger if thetruefor$strictwas passed in uppercase. - The
WordPress.PHP.YodaConditionssniff could get confused over complex ternaries containing assignments. This has been remedied. - The
WordPress.WP.PreparedSQLsniff would erronously throw errors about comments found within a DB function call. - The
WordPress.WP.PreparedSQLsniff would erronously throw erro...
0.13.1
0.13.0
Added
- Support for PHP CodeSniffer 3.0.2+. The minimum required PHPCS version (2.9.0) stays the same.
- Support for the PHPCS 3
--ignore-annotationscommand line option. If you pass this option, both PHPCS native@ignore ...annotations as well as the WPCS specific whitelist flags will be ignored.
Changed
- The minimum required PHP version is now 5.3 when used in combination with PHPCS 2.x and PHP 5.4 when used in combination with PHPCS 3.x.
- The way the unit tests can be run is now slightly different for PHPCS 2.x versus 3.x. For more details, please refer to the updated information in the Contributing Guidelines.
- Release archives will no longer contain the unit tests and other typical development files. You can still get these by using Composer with
--prefer-sourceor by checking out a git clone of the repository. - Various textual improvements to the Readme.
- Various textual improvements to the Contributing Guidelines.
- Minor internal changes.
Removed
- The
WordPress.Arrays.ArrayDeclarationsniff has been deprecated. The last remaining checks this sniff contained have been moved to theWordPress.Arrays.ArrayDeclarationSpacingsniff. - Work-arounds which were in place to support PHP 5.2.
Fixed
- A minor bug where the auto-fixer could accidentally remove a comment near an array opener.