Build a custom Gutenberg sidebar plugin document panel
An "SEO Priority" document panel scenario covering register_post_meta auth callbacks, useEntityProp wiring, and the classic panel-not-showing REST exposure mistake.
Works with Claude / GPT850 uses★ 4.2
The prompt
code-gutenberg-sidebar-document-panel
I need a custom panel in the post editor sidebar labeled "SEO Priority" with a select
field (Low / Medium / High) that saves to post meta, visible alongside the built-in
Featured Image and Categories panels.
ENVIRONMENT: [WordPress 6.7, block editor only (no classic editor fallback needed),
registered from a plugin, needs to work for both `post` and `page` post types]
Build this like a developer who's shipped editor sidebar panels before, in order:
1. Show the PHP side first, since it's the part most people get wrong: register the
meta field with `register_post_meta()` on `init`, with `show_in_rest => true` (a
panel that isn't exposed via REST simply won't show any data or save anything, with
no error in the console, just silent failure), a defined `type`, `single => true`,
and an explicit `auth_callback` checking `current_user_can( 'edit_post', $post_id )`
rather than leaving the default (which restricts to users who can `edit_posts` in
general, not necessarily this specific post).
2. Show the JS side: `registerPlugin()` wrapping a `PluginDocumentSettingPanel`
component, with a `SelectControl` bound via `useEntityProp( 'postType', postType,
'meta' )` so it reads and writes through the same data layer the rest of the editor
uses, rather than a separate `useState` that would fall out of sync with actual
save state.
3. Set `icon` and `name` properties on the panel appropriately, and explain the
`PluginDocumentSettingPanel`'s optional `className` prop for consistent styling with
core panels rather than an ad hoc custom style.
4. Flag the edge case that causes "my panel doesn't show up at all": if the plugin's
editor script isn't enqueued with the correct dependencies
(`wp-plugins`, `wp-edit-post`, `wp-editor`, `wp-components`, `wp-data`) via
`wp_enqueue_script()` on `enqueue_block_editor_assets`, the panel registration
either silently no-ops or throws a console error about an undefined component,
depending on which dependency is missing.
5. Confirm the panel works identically for both `post` and `page`: since
`useEntityProp`'s `postType` argument needs to come from `wp.data.select('core/editor').getCurrentPostType()`
rather than being hardcoded to `'post'`, or the panel will silently fail to save
meta when used on a page.
Replace the panel label, field type, and post types with your actual needs.
The silent-failure pattern shows up twice in this build: once if show_in_rest is missing, once if the post type is hardcoded wrong. Both look identical from the editor UI (the panel renders, the field just never actually saves), so check the meta registration and the dynamic post type argument first whenever a sidebar panel “isn’t working.”