This example demonstrates how to extend the WordPress block editor by adding a custom sidebar panel using the PluginSidebar component. The sidebar includes a text input field that saves data to post meta, showcasing the integration between the block editor's UI components and WordPress data management.
Key concepts covered:
- Plugin Sidebar implementation
- Post meta data integration
- WordPress components usage
- SlotFill system utilization
- Custom UI panel creation
| Example | Description | Tags | Download .zip | Live Demo |
|---|---|---|---|---|
| Plugin Sidebar | Shows how to add a custom sidebar to the editor using SlotFill and integrate it with post meta data. | slotfill meta no-block |
📦 |
-
Plugin Registration
- Register plugin with
registerPlugin - Configure sidebar settings
- Set up meta field integration
- Define UI components
- Register plugin with
-
Meta Field Setup
- Register meta field with
register_post_meta - Configure REST API access
- Set up data persistence
- Handle permissions
- Register meta field with
-
Plugin Registration
import { registerPlugin } from '@wordpress/plugins'; import { PluginSidebar } from '@wordpress/edit-post'; registerPlugin( 'sidebar-plugin', { render: () => ( <PluginSidebar name="sidebar-plugin" title="My Plugin Sidebar" icon="admin-post" > // Sidebar content </PluginSidebar> ), } );
-
Meta Integration
import { useEntityProp } from '@wordpress/core-data'; import { TextControl } from '@wordpress/components'; const [ metaValue, setMetaValue ] = useEntityProp( 'postType', 'post', 'sidebar_plugin_meta_block_field' );
-
Main Components Used
@wordpress/edit-post: ProvidesPluginSidebar@wordpress/components: UI components@wordpress/core-data: Data management@wordpress/plugins: Plugin registration
-
Meta Field Configuration
register_post_meta('post', 'sidebar_plugin_meta_block_field', [ 'show_in_rest' => true, 'single' => true, 'type' => 'string' ]);
- Follow WordPress component guidelines
- Implement proper data persistence
- Handle loading and error states
- Consider user permissions
- Maintain consistent UI/UX
Note Check the Start Guide for local development with the examples
