Skip to content

Commit 9575ed0

Browse files
committed
Update docs and claude file to describe the new changes.
1 parent 72f8ab6 commit 9575ed0

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

CLAUDE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ Each trait in the Traits directory handles a specific query modification:
9494
- Conditionally renders different control sets based on `query.inherit` attribute
9595
- When `inherit: false` - Shows all advanced controls in the "Advanced Query Settings" panel
9696
- When `inherit: true` - Shows limited controls (only PostOrderControls and inherited query slot)
97+
- Builds `propsWithControls` passed to every component; extends the original block props with:
98+
- `allowedControls` — array of permitted control keys
99+
- `context.currentPostId` — numeric ID of the currently edited post/page (`0` in template context)
100+
- `context.currentPostType` — post type string, e.g. `'post'`, `'page'`, `'wp_template'`
97101

98102
**UI Components** (`src/components/`):
99103
Each component corresponds to a query feature:

extending-aql.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@ For example, a control that makes changes to the content types being displayed m
1414

1515
Both SlotFills are passed all `props` from the main block and are available on the `window.aql` object for use.
1616

17+
##### Available props
18+
19+
In addition to the standard block props (`attributes`, `setAttributes`, `clientId`, etc.), every component receives an enriched `context` object with the following values:
20+
21+
| Property | Type | Description |
22+
|---|---|---|
23+
| `context.currentPostId` | `number` | The ID of the post or page currently open in the editor. Returns `0` when editing a template. |
24+
| `context.currentPostType` | `string` | The post type of the currently edited entity, e.g. `'post'`, `'page'`, or `'wp_template'`. |
25+
26+
Any other context values that `core/query` already receives from its parent are also preserved.
27+
28+
```js
29+
const MyControl = ( { attributes, setAttributes, context } ) => {
30+
const { currentPostId, currentPostType } = context;
31+
// currentPostId: e.g. 42
32+
// currentPostType: e.g. 'post'
33+
};
34+
```
35+
1736
The example below adds a new control to only show content from the from currently logged in user regardless of the status of `Inherit query from template`.
1837

1938
```js
@@ -22,8 +41,9 @@ import { registerPlugin } from '@wordpress/plugins';
2241
import { ToggleControl } from '@wordpress/components';
2342
import { __ } from '@wordpress/i18n';
2443

25-
const LoggedInUserControl = ( { attributes, setAttributes } ) => {
44+
const LoggedInUserControl = ( { attributes, setAttributes, context } ) => {
2645
const { query: { authorContent = false } = {} } = attributes;
46+
const { currentPostId, currentPostType } = context;
2747
return (
2848
<>
2949
<ToggleControl
@@ -137,8 +157,9 @@ import { registerPlugin } from '@wordpress/plugins';
137157
import { ToggleControl } from '@wordpress/components';
138158
import { __ } from '@wordpress/i18n';
139159
140-
const LoggedInUserControl = ( { attributes, setAttributes } ) => {
160+
const LoggedInUserControl = ( { attributes, setAttributes, context } ) => {
141161
const { query: { authorContent = false } = {} } = attributes;
162+
const { currentPostId, currentPostType } = context;
142163
return (
143164
<>
144165
<ToggleControl

0 commit comments

Comments
 (0)