Created
February 5, 2026 23:19
-
-
Save roykho/ab4b1eb878ca3ef40d6d771f2c1cce01 to your computer and use it in GitHub Desktop.
Alley React Snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * WordPress dependencies | |
| */ | |
| import { PanelBody, ToggleControl } from '@wordpress/components'; | |
| import { useSelect, useDispatch } from '@wordpress/data'; | |
| import { __ } from '@wordpress/i18n'; | |
| /** | |
| * Renders the Advanced Features sidebar panel and toggle for the alley feature flag. | |
| * Reads and updates post meta via core/editor; does not persist to server (editor save does). | |
| * | |
| * @return {JSX.Element} Inspector panel with toggle control. | |
| */ | |
| export default function FeatureTogglePanel() { | |
| // Use WP data store to get the post attributes. | |
| const { meta } = useSelect( ( select ) => { | |
| const editor = select( 'core/editor' ); | |
| return { | |
| meta: editor.getEditedPostAttribute( 'meta' ) || {}, | |
| }; | |
| }, [] ); | |
| const { editPost } = useDispatch( 'core/editor' ); | |
| const enabled = Boolean( meta.alley_feature_enabled ); | |
| const updateMeta = ( nextValue ) => { | |
| // New object so core/editor detects a change and keeps meta in sync. | |
| editPost( { | |
| meta: Object.assign( {}, meta, { alley_feature_enabled: nextValue } ), | |
| } ); | |
| }; | |
| return ( | |
| <PanelBody title="Advanced Features" initialOpen> | |
| <ToggleControl | |
| label={__( 'Enable smart feature', 'alley' ) } | |
| checked={ enabled } | |
| onChange={ updateMeta } | |
| help={ __( 'Applies additional processing during rendering.', 'alley' ) } | |
| /> | |
| </PanelBody> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment