Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@technote-space
Last active January 9, 2019 15:39
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 technote-space/a9d1ab7154b6e5d372e0aa8b0cd77faa to your computer and use it in GitHub Desktop.
Save technote-space/a9d1ab7154b6e5d372e0aa8b0cd77faa to your computer and use it in GitHub Desktop.
Gutenberg複数追加例
(function (richText, element, editor) {
richText.registerFormatType('my-plugin/my-plugin1', {
title: 'my-plugin',
tagName: 'span',
className: 'class1',
edit: function ({isActive, value, onChange}) {
return element.createElement(editor.RichTextToolbarButton, {
icon: 'admin-customizer',
title: 'title1',
onClick: function () {
onChange(richText.toggleFormat(value, {
type: 'my-plugin/my-plugin1'
}));
},
isActive: isActive,
});
},
});
richText.registerFormatType('my-plugin/my-plugin2', {
title: 'my-plugin',
tagName: 'span',
className: 'class2',
edit: function ({isActive, value, onChange}) {
return element.createElement(editor.RichTextToolbarButton, {
icon: 'admin-customizer',
title: 'title2',
onClick: function () {
onChange(richText.toggleFormat(value, {
type: 'my-plugin/my-plugin2'
}));
},
isActive: isActive,
});
},
});
}(
window.wp.richText,
window.wp.element,
window.wp.editor
));
add_action( 'enqueue_block_editor_assets', function () {
wp_enqueue_style( 'my_plugin', plugins_url( 'assets/css/editor.css', __FILE__ ) );
wp_enqueue_script( 'my_plugin', plugins_url( 'assets/js/editor.js', __FILE__ ), [
'wp-element',
'wp-rich-text',
'wp-editor',
] );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment