Suppress filters in get_posts false positive
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 68/100
Direção de pesquisa
Reproduce the warning using the minimal get_posts() snippet against the VIP Coding Standards main branch, then trace how the phpcs:ignore comment is handled alongside suppress_filters. Done means the false-positive warning is no longer reported while the intended meta_key warning remains available.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Bug Description
This get_posts call generates a warning that you must use suppress_filters set to false for performance reasons, despite that already being the case:
$post_ids = get_posts( [
'post_type' => [ 'post' ],
'post_status' => 'publish',
'fields' => 'ids',
'meta_key' => 'foobar', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'suppress_filters' => false,
] );
My suspicion is that phpcs ignore comment is breaking the parsing of the array somehow.
( Note this is legacy code, we're aware of the meta_key issue )
Minimal Code Snippet
$post_ids = get_posts( [
'post_type' => [ 'post' ],
'post_status' => 'publish',
'fields' => 'ids',
'meta_key' => 'foobar', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'suppress_filters' => false,
] );
Error Code
⚠️ Warning( severity 3 ): get_posts() is uncached unless the "suppress_filters" parameter is set to false. If the suppress_filter parameter is set to false this can be safely ignored. More Info: https://docs.wpvip.com/technical-references/caching/uncached-functions/ (
WordPressVIPMinimum.Functions.RestrictedFunctions.get_posts_get_posts).
Environment
This occurred 1st October in the VIP Coding standards bot on a github pull request
Tested Against main branch?
- I have verified the issue still exists in the
mainbranch of VIPCS. - I have verified the issue still exists in the
developbranch of VIPCS.
- Linguagem predominante
- PHP
- Estrelas
- 261
- Forks
- 44
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de Automattic/VIP-Coding-Standards
-
AlwaysReturnInFilter: isInsideIfConditonal() guards the conditions array after reading itTalvez já em andamento @tomjn assumiu há 4 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
Bug: PreGetPosts warns when the early is_main_query() return is not the first statement in its ifTalvez já em andamento @tomjn assumiu há 4 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 76/100
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 48/100
-
Breaking Change Type: Maintenance
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
Automattic/VIP-Coding-Standards#849 · 1 comentário ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 45/100
Todas as issues de Automattic/VIP-Coding-Standards
Issues semelhantes
-
L: github:actions L: php:composer
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
dependabot/dependabot-core#16493 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
api-platform/core#8649 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 84/100
open-telemetry/opentelemetry-php#2071 ·
Mantenedores costumam responder em até 1 dia
-
Always show measure tooltipsAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 1 dia
-
bug No Code Attached Yet
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
joomla/joomla-cms#48587 ·
Mantenedores costumam responder em até 1 dia