Automattic / Automattic/VIP-Coding-Standards
Add check for queries made without post_status or post_type
- Langage dominant
- PHP
- Étoiles
- 261
- Forks
- 44
- Merge moyen
- 19 min
- PR mergées (30 j)
- 1
Description
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
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par lire l’issue WordPress-Coding-Standards liée et les directives de revue de code de VIP, puis examinez les sniffs PHP_CodeSniffer existants du dépôt. Suivez la manière dont les appels à get_posts() et WP_Query sont analysés. Le travail est terminé lorsque le nouveau contrôle signale les requêtes qui omettent post_status ou post_type, avec un comportement conforme à la justification énoncée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- php
- Domaine
- tooling
- Type d'issue
- Fonctionnalité
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100