New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a sniff for suppress_filters in get_posts #1416
Comments
So a sniff for this should flag any equivalent of However, if a plugin very deliberately sets So that just leaves sniffing for This can be done when the This would mean that if its "undetermined", the sniff should not flag the code. function plugin_get_posts( $args ) {
return get_posts( $args ); // OK.
}
class plugin_class {
private $args = array(); // Set via constructor or other method.
public function get_posts() {
return get_posts( $this->args ); // OK.
}
} And what about code like this: function plugin_get_posts() {
$args = [
'post_type' => 'page',
'suppress_filters' => false
];
$args = apply_filter( 'plugin_filter_hook', $args );
return get_posts( $args ); // ???
} Or along those same lines: function plugin_get_posts() {
$args = [
'post_type' => 'page',
];
$args = apply_filter( 'plugin_filter_hook', $args );
return get_posts( $args ); // ???
}
In other words, this is only valid in a limited number of all cases as by far not all sites are running with caching (plugins or otherwise). When there is no caching plugin active, calling All in all, for this to be added to WPCS, I would like to see some more discussion about this. |
P.S.: @tomjn Thanks for opening the issue 😉 |
The problem with sniffing this, as I see it, is that arguments can be passed to the
We could detect only if we have some array in the file where the Just flagging every |
Good points from @dingo-d I'm also just now wondering if the recent changes to As I haven't done a deep dive into the WP 6.1 changes, I'm pinging @spacedmonkey and @felixarntz for an opinion. |
WP_Query is now cached by default. So this sniff is much less important now. |
@spacedmonkey Does this mean that the |
Not sure what you mean by relevant. There is no longer a need to pass |
@spacedmonkey is |
Set to true by default. |
Given the above, I get the impression a sniff for this is no longer relevant. Is that correct ? If so, I suggest we close the issue. If a sniff would still be relevant, it needs to be hashed out in detail what the conditions should be for the sniff to flag something and I would like to see that input in this issue. |
I concur with closing this
…On Fri, 9 Dec 2022 at 15:05, Juliette ***@***.***> wrote:
Given the above, I get the impression a sniff for this is no longer
relevant. Is that correct ? If so, I suggest we close the issue.
If a sniff would still be relevant, it needs to be hashed out in detail
what the conditions should be for the sniff to flag something and I would
like to see that input in this issue.
—
Reply to this email directly, view it on GitHub
<#1416 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAOLZYTYRJGZOXPLXENGQLWMNDELANCNFSM4FI2FBVA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Consider these 2 queries snippets:
2 is faster, despite 1 using 2 internally. The reason for this is a difference in default arguments, specifically
suppress_filters
. InWP_Query
it isfalse
by default, but inget_posts
it is true.In this example, the performance difference is resolved:
With
suppress_filters
set to true, any caching mechanisms are unable to do their job. Setting it to false fixes this. It's particularly noticeable on sites with any kind of object cache or effective caching plugins.We flag this at VIP, and as a result a PR for a new VIP sniff was submitted in #1041 (comment) but this is not VIP specific, and falls into the cached vs uncached core APIs bucket
The text was updated successfully, but these errors were encountered: