VIP-Coding-Standards
VIP-Coding-Standards copied to clipboard
WPQueryParams.PostNotIn_exclude: False positive outside get_posts context
Bug Description
We started flagging for exclude since it's an alias of post__not_in in #589. Unfortunately, when used outside of a get_posts() or WP_Query context, it's a false positive.
Minimal Code Snippet
$users = get_users(
array(
'blog_id' => false,
'include' => $include_blog_users,
'exclude' => $exclude_blog_users,
)
);
Error Code
WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude
Environment
| Question | Answer |
|---|---|
| PHP version | 7.4 |
| PHP_CodeSniffer version | 3.6 |
| VIPCS version | 2.3 |
Tested Against master branch?
- [x] I have verified the issue still exists in the
masterbranch of VIPCS. - [x] I have verified the issue still exists in the
developbranch of VIPCS.
From https://github.com/Automattic/VIP-Coding-Standards/issues/369#issuecomment-705898613:
Also note that
excludeis quite a generic array key name, so I suspect adding this key as one to be detected by this sniff will yield lots of false positives forexcludebeing used in other contexts thanget_posts().At the same time, hard linking the key detection to
get_posts()is also not a realistic option as these kind of parameters are often set up outside of the function call / in class properties / class constants etc.
I'm wondering if this might be worth changing the messaging to include a manual inspection disclaimer...