-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (37 loc) · 1.34 KB
/
index.js
File metadata and controls
42 lines (37 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* WordPress dependencies
*/
import { CheckboxControl, PanelRow } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { registerPlugin } from '@wordpress/plugins';
const EXCLUDED = 'excluded';
const LessonArchiveExcludedMeta = () => {
const postMetaData = useSelect( ( select ) => select( 'core/editor' ).getEditedPostAttribute( 'meta' ) || {} );
const { editPost } = useDispatch( 'core/editor' );
const [ lessonExcluded, setLessonFeatured ] = useState( postMetaData?._lesson_archive_excluded === EXCLUDED );
return (
<PluginDocumentSettingPanel title={ __( 'Hidden Lesson (deprecated)', 'wporg-learn' ) }>
<PanelRow>
<CheckboxControl
label={ __( 'Exclude this lesson from the archive', 'wporg-learn' ) }
checked={ lessonExcluded }
onChange={ ( newLessonExcluded ) => {
setLessonFeatured( newLessonExcluded );
editPost( {
meta: {
...postMetaData,
_lesson_archive_excluded: newLessonExcluded ? EXCLUDED : '',
},
} );
} }
/>
</PanelRow>
</PluginDocumentSettingPanel>
);
};
registerPlugin( 'wporg-learn-lesson-archive-excluded-meta', {
render: LessonArchiveExcludedMeta,
} );