Skip to content

Instantly share code, notes, and snippets.

@rheinardkorf
Created June 3, 2020 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rheinardkorf/9d0c1b3dcececc5d69590ea8728b2b53 to your computer and use it in GitHub Desktop.
Save rheinardkorf/9d0c1b3dcececc5d69590ea8728b2b53 to your computer and use it in GitHub Desktop.
Gutenberg manipulate Editor Mode state. (Experimental)
(function (wp) {
var registerPlugin = wp.plugins.registerPlugin;
var PluginMoreMenuItem = wp.editPost.PluginMoreMenuItem;
// var image = wp.icons.image;
var el = wp.element.createElement;
var withDispatch = wp.data.withDispatch;
var MoreItem = function (props) {
return el(PluginMoreMenuItem,
{
name: 'my-plugin-sidebar',
icon: 'admin-post',
title: 'My plugin sidebar',
onClick: props.setEditorValue('markdown')
},
'Markdown Editor'
);
}
var MoreItemWithDispatch = withDispatch(
function (dispatch) {
return {
setEditorValue: function (value) {
dispatch('core/edit-post').switchEditorMode(value);
}
}
}
)(MoreItem)
registerPlugin('my-plugin-sidebar', {
render: function () {
return el(MoreItemWithDispatch);
},
});
// var PluginSidebar = wp.editPost.PluginSidebar;
// var el = wp.element.createElement;
// registerPlugin('my-plugin-sidebar', {
// render: function () {
// return el(PluginSidebar,
// {
// name: 'my-plugin-sidebar',
// icon: 'admin-post',
// title: 'My plugin sidebar',
// },
// 'Meta field'
// );
// },
// });
})(window.wp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment