-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add course completion meta field (#2877)
* Add course completion meta fields * Use the meta on the completed page
- Loading branch information
Showing
4 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
62 changes: 62 additions & 0 deletions
62
wp-content/plugins/wporg-learn/js/course-completion-meta/index.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* 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={ __( 'Completed screen', 'wporg-learn' ) }> | ||
<PanelRow> | ||
<p> | ||
{ __( | ||
'These fields customize what is displayed on the Course Completed screen. If left blank, the default values will be applied.', | ||
'wporg-learn' | ||
) } | ||
</p> | ||
</PanelRow> | ||
<PanelRow> | ||
<TextControl | ||
label={ __( 'Success Message', 'wporg-learn' ) } | ||
value={ message } | ||
placeholder={ __( 'Congratulations on completing this course!', 'wporg-learn' ) } | ||
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, | ||
} ); |
This file contains 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
This file contains 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