-
Notifications
You must be signed in to change notification settings - Fork 205
/
Copy pathindex.js
49 lines (42 loc) · 1.17 KB
/
index.js
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
/**
* WordPress dependencies
*/
import { registerPlugin } from '@wordpress/plugins';
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
import { __ } from '@wordpress/i18n';
import { select, subscribe } from "@wordpress/data";
/**
* Components
*/
import CoAuthors from './components/co-authors';
/**
* Component for rendering the plugin sidebar.
*/
const PluginDocumentSettingPanelAuthors = () => (
<PluginDocumentSettingPanel
name="coauthors-panel"
title={ __( 'Authors', 'co-authors-plus' ) }
className="coauthors"
>
<CoAuthors />
</PluginDocumentSettingPanel>
);
registerPlugin( 'plugin-coauthors-document-setting', {
render: PluginDocumentSettingPanelAuthors,
icon: 'users',
} );
// Save authors when the post is saved.
// https://github.com/WordPress/gutenberg/issues/17632
const { isSavingPost, getCurrentPost } = select("core/editor");
const { getAuthors, saveAuthors } = select("cap/authors");
let checked = true; // Start in a checked state.
subscribe(() => {
if (isSavingPost()) {
checked = false;
} else if (!checked) {
const { id } = getCurrentPost();
const authors = getAuthors(id);
saveAuthors(id, authors);
checked = true;
}
});