-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (52 loc) · 1.59 KB
/
index.js
File metadata and controls
56 lines (52 loc) · 1.59 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* WordPress dependencies
*/
import { PanelRow, TextControl } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
import { __ } from '@wordpress/i18n';
import { registerPlugin } from '@wordpress/plugins';
const CourseCompletionMeta = () => {
const postMetaData = useSelect( ( select ) => select( 'core/editor' ).getEditedPostAttribute( 'meta' ) || {} );
const { editPost } = useDispatch( 'core/editor' );
const message = postMetaData?._course_completion_success_message || '';
const link = postMetaData?._course_completion_survey_link || '';
return (
<PluginDocumentSettingPanel title={ __( 'Course Completion Settings', 'wporg-learn' ) }>
<PanelRow>
<p>{ __( 'If the fields are left blank, the default values will be applied.', 'wporg-learn' ) }</p>
</PanelRow>
<PanelRow>
<TextControl
label={ __( 'Success Message', 'wporg-learn' ) }
value={ message }
onChange={ ( newMessage ) => {
editPost( {
meta: {
...postMetaData,
_course_completion_success_message: newMessage,
},
} );
} }
/>
</PanelRow>
<PanelRow>
<TextControl
label={ __( 'Survey Link', 'wporg-learn' ) }
value={ link }
onChange={ ( newLink ) => {
editPost( {
meta: {
...postMetaData,
_course_completion_survey_link: newLink,
},
} );
} }
/>
</PanelRow>
</PluginDocumentSettingPanel>
);
};
registerPlugin( 'wporg-learn-course-completion-meta', {
render: CourseCompletionMeta,
} );