-
-
Notifications
You must be signed in to change notification settings - Fork 461
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 check for post_per_page to -1 in PostsPerPage sniff #1638
Comments
This used to be in a VIP sniff which we have just removed at the request of the VIP team. If a developer made a conscious choice to use |
I've just updated the OP with my thoughts from my discussion with @rebeccahum that didn't get added initially. WordPress.com VIP has requirements regarding no limit queries. The VIPCS uses the WPCS PostsPerPageSniff as a means to flag queries with What we don't have is, is a way to capture A developer may have made a conscious choice to choose If you feel that Myself or @rebeccahum would happily do the PR for this. Sure, we could write our own sniff for VIPCS, but that limits it to those folks using VIPCS, rather than all those who are using WPCS by itself or one of the standards built on top of WPCS, and who have an eye on performance considerations. |
As clearly nobody else seemed to think it was a bad idea to remove that sniff, I consider this a VIP issue, not a WPCS issue. Implementation-wise, introducing a new property for something which used to be a separate errorcode feels even more inconsistent, than removing something and then adding it back. |
For my convenience, here is the PostsPerPageSniff at WPCS 0.14.1, before it was amended and deprecated in 1.0.0. To answer your questions:
This issue isn't a complaint though, but a request to improve WPCS to make it more flexible without any drawbacks to other users. Other than the history which brought us to this point, and your dislike of Automattic / VIPCS, do you have any reason for not supporting this enhancement?
If there's a more suitable way to make this optional, from the code we currently have in |
@GaryJones WTF ? What sort of nonsensical personal attack is that ? I have nothing against VIPCS or Automattic, I do object to commercial companies making forceful demands of open source volunteers without putting any resources towards those projects. All the same, for this issue I'm trying to establish if this is something which should be solved in WPCS, same as I would do with any issue raised. So far, I have only seen arguments backed by a VIP requirement. If there is demand for this by a larger part of the WP community, other than VIP, or a strong technical argument, it's worth considering, but I have not seen that so far. I suggest leaving this issue open for a while to see if more people - outside of VIPCS - are interested in this. |
For me it's a tricky issue: On one hand I never allow my colleagues to use On the other hand, who are we to limit what a plugin/theme author wants to do? Maybe they need this to filter some data out, in which case they really do need all posts returned, and this will prevent any issues if the entity they are querying out grows larger than an arbitrary large number they set in I'm fine in leaving it out of WPCS, if you need it in your own coding standard, either pull it from VIP CS, or create your own sniff (what I'll probably do) 🙂 |
I'm sorry you felt that was a personal attack. I've misunderstood your feelings, and for that, I sincerely apologise. |
I understand it's contentious, and I'm not advocating that it be enabled by default.
Right - that would be another good improvement. 100 was presumably decided from the historical VIP decision, but there's no reason that is a perfect suggestion for every site. My request here is to make the sniff more flexible - and I can't see any technical argument why this idea would be rejected. We've got public properties for things like whitespace in array alignment, yet the ideas for improvement for PostsPerPage are arguably more important in terms of making a difference to site performance. |
That number is already configurable and has been since WPCS 0.14.0... |
Hi Juliette! |
hi, i mentioned this some time before #1531 i never got the time to get back to this tho.. |
My 2 cents: A check for -1 is useful, as the problems that come from a bad usage of this often are
This doesn't feel right. I agree with @jrfnl here. |
Instead of adding a boolean flag, @jrfnl suggested it could be an array of values that are checked for. I had a really quick play with the sniff, and by adding: public $limits = array(
array( '>', 100 ),
); ...and: foreach ( $this->limits as $limit ) {
eval( '$result = ' . "$val $limit[0] (int) $limit[1];" );
if ( $result ) {
return 'Detected disallowed pagination limit, `%s` is set to `%s`';
}
} ...in the That would allow other packages to override with a custom class and property like: public $limits = array(
array( '>', 100 ),
array( '===', -1 ),
); ...or add the properties into the XML config file. I've not seen any other requests for having multiple limits or values though, besides this one for |
Is your feature request related to a problem?
Since -1 means no limit, it would be nice to add a check for
-1
being passed in as well inWordPress.WP.PostsPerPage.posts_per_page_posts_per_page
Rationale
The PostsPerPage sniff already gives a warning for high pagination - that is, over 100 by the public property default.
While for small sites, a value of
-1
may only return a few results, it is still more efficient to limit the number to 10, or 50, or 100, than it is to set it to-1
. A value of-1
is lazy and doesn't scale.Describe the solution you'd like
We can have a public property of
$allow_unlimited_posts
to enable/disable the check for those who want to set an unlimited posts_per_page. Whether this property has an initial value oftrue
orfalse
is open to discussion, but adding it and using it as part of the check allows it to be skipped if necessary.The text was updated successfully, but these errors were encountered: