alleyinteractive / alleyinteractive/wp-curate

Adjustments to query block context can generate query for arbitrary posts

未關閉
#457 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
PHP
星號
11
分支
3
PR 合併指標
30 天內沒有已合併 PR

描述

### Description of the bug

When a `wp-curate/query` block contains both hardcoded `wp-curate/post` blocks and a `core/post-template` block, it's possible for the query block's `include` attribute to be reset to an empty array, causing the `post-template` block to query for and display a list of arbitrary posts.

### Steps To Reproduce

Simplified example:

```html





```

In this example pattern, the block markup inside of the query block is static, representing the layout of the section of the page. The query block itself is dynamically generated, first by determining the posts that will appear, then by generating the corresponding `numberOfPosts` and `posts` attributes. Therefore, as in this example, it's possible for there to be more `post` blocks than there are available posts in the pattern.

When this query block renders, all of the inner blocks will render, including the `post-template` block, which will generate a query even though it's known that there will be no posts available to display by virtue of there being more `post` blocks than there are `numberOfPosts`. The resulting query will be equivalent to, in this case, a query with `{"numberOfPosts":2,"postTypes":["post"],"posts":[null, null]}`

### Additional Information

The problem occurs here: https://github.com/alleyinteractive/wp-curate/blob/87bc80eafaf4d16b92c15573c01ed8c54bd01bb4/src/features/class-block-index.php#L174

In scenarios where `$new_include` is empty but it isn't possible for there to be more posts to display, the `wp_curate_stop_queries` query variable should be used rather than setting `include` to `[]`.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。