Suppress filters in get_posts false positive
維護者通常 1 天內回覆
評估
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- PHP
- 星號
- 261
- 分支
- 44
- 平均合併
- 3 天 9 小時
- 30 天內合併 PR
- 10
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
Automattic/VIP-Coding-Standards 的其他 Issue
-
難度 3/5 1-2 天 新手友好度 48/100
Automattic/VIP-Coding-Standards#876 ·
維護者通常 1 天內回覆
-
Breaking Change Type: Maintenance
難度 4/5 3-5 天 新手友好度 35/100
Automattic/VIP-Coding-Standards#849 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 45/100
Automattic/VIP-Coding-Standards#832 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 48/100
Automattic/VIP-Coding-Standards#823 ·
維護者通常 1 天內回覆
-
Status: Awaiting feedback
難度 2/5 1-3 小時 新手友好度 45/100
Automattic/VIP-Coding-Standards#754 · 3 則留言 ·
維護者通常 1 天內回覆
查看 Automattic/VIP-Coding-Standards 的全部 Issue