Automattic / Automattic/VIP-Coding-Standards

Add check for queries made without post_status or post_type

未关闭
#186 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Type: Enhancement
主要语言
PHP
星标
261
派生
44
平均合并
19 分钟
30 天内合并 PR
1

描述

See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/459.

----

A sniff can be added to flag `get_posts()` and `WP_Query` instances that are made without supplying post_status or post_type. See rationale:

> ## Not defining post_status Or post_type
>
> By default the post_status of a query is set to publish for anonymous users on the front end. It is not set in any WP_ADMIN context including Ajax queries. Queries on the front end for logged in users will also contain an OR statement for private posts created by the logged in user, even if that user is not part of the site. This will reduce the effectiveness of MySQL indexes, specifically the type_status_date index.
>
> The same is true for post_type, if you know that only a certain post_type will match the rest of the query (for example for a taxonomy, meta or just general query) adding the post_type as well as the post_status will help MySQL better utilize the indexes as it’s disposal.

https://vip.wordpress.com/documentation/code-review-what-we-look-for/#not-defining-post_status-or-post_type

贡献指南

打开贡献指南

调研方向

先阅读链接的 WordPress-Coding-Standards issue 和 VIP 代码审查指南,然后检查 repository 中现有的 PHP_CodeSniffer sniff。跟踪 get_posts() 和 WP_Query 的调用是如何被分析的。完成的标准是新检查能够标记省略 post_status 或 post_type 的查询,并且行为与所述理由一致。

由索引模型根据 Issue 内容生成。

评估

技术栈
php
领域
tooling
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。