# code-snippets/4.0.0-beta.1/js/components/EditMenu/EditorSidebar/controls/LockControl.tsx

Code Snippets, version 4.0.0-beta.1. 53 lines.

- Page: https://pluginprobe.com/plugins/code-snippets/4.0.0-beta.1/code/js/components/EditMenu/EditorSidebar/controls/LockControl.tsx
- Raw: https://pluginprobe.com/plugins/code-snippets/4.0.0-beta.1/raw/js/components/EditMenu/EditorSidebar/controls/LockControl.tsx
- Modified: 2026-06-19T15:56:12+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/code-snippets/4.0.0-beta.1/code/js/components/EditMenu/EditorSidebar/controls/LockControl.tsx#L10-L20`.

```tsx
import React from 'react'
import { __ } from '@wordpress/i18n'
import { useSnippetsAPI } from '../../../../hooks/useSnippetsAPI'
import { Tooltip } from '../../../common/Tooltip'
import { useSnippetForm } from '../../SnippetForm/WithSnippetFormContext'

export const LockControl: React.FC = () => {
	const { snippet, setSnippet, isWorking, setIsWorking, setCurrentNotice } = useSnippetForm()
	const { update } = useSnippetsAPI()

	const handleToggle = () => {
		setSnippet(previous => ({ ...previous, locked: !previous.locked }))
		setIsWorking(true)

		update({ id: snippet.id, network: snippet.network, locked: !snippet.locked })
			.then(result => {
				setSnippet(result)

				setCurrentNotice(['updated', result.locked
					? __('Snippet <strong>locked</strong>.', 'code-snippets')
					: __('Snippet <strong>unlocked</strong>.', 'code-snippets')])
			})
			.catch(() => setCurrentNotice(['error', __('Unable to lock snippet.', 'code-snippets')]))
			.finally(() => setIsWorking(false))
	}

	return (
		<div className="inline-form-field lock-control-container">
			<label htmlFor="snippet-lock" id="snippet-lock-label">
				{__('Lock snippet', 'code-snippets')}
			</label>

			<Tooltip block end>
				{__('Mark this snippet as read-only to prevent accidental changes or deletion.', 'code-snippets')}
			</Tooltip>

			<span className="lock-status-text">
				{snippet.locked ? __('Locked', 'code-snippets') : __('Unlocked', 'code-snippets')}
			</span>

			<input
				id="snippet-lock"
				type="checkbox"
				checked={snippet.locked}
				disabled={isWorking}
				className="switch"
				onChange={handleToggle}
				aria-labelledby="snippet-lock-label"
			/>
		</div>
	)
}

```
