-
Notifications
You must be signed in to change notification settings - Fork 1
/
block-editor.js
35 lines (30 loc) · 1010 Bytes
/
block-editor.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
const { registerPlugin } = wp.plugins;
const { PluginPostStatusInfo } = wp.editPost;
const { createElement } = wp.element;
const { PanelBody } = wp.components;
const mt8PostShare = () => {
const { getEditedPostAttribute, isCurrentPostPublished } = wp.data.select('core/editor');
if (!isCurrentPostPublished()) {
return null;
}
const postUrl = getEditedPostAttribute('link');
const facebookUrl = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(postUrl)}`;
const twitterUrl = `https://twitter.com/intent/tweet?url=${encodeURIComponent(postUrl)}`;
return (
<PanelBody title="MT8 Post Share" initialOpen={true}>
<p>
<a href={facebookUrl} target="_blank" rel="noopener noreferrer">
Share on Facebook
</a>
</p>
<p>
<a href={twitterUrl} target="_blank" rel="noopener noreferrer">
Share on Twitter
</a>
</p>
</PanelBody>
);
};
registerPlugin('mt8-post-share', {
render: mt8PostShare,
});