Created
April 24, 2024 22:47
-
-
Save youknowriad/e668c56f20e514dfe84bf01e793e7860 to your computer and use it in GitHub Desktop.
Gutenberg Log Deprecations
This file contains hidden or 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
const { createElement: el, useState, useEffect } = React; | |
const PanelBody = wp.components.PanelBody; | |
const PluginSidebar = wp.editor.PluginSidebar; | |
const addAction = wp.hooks.addAction; | |
const registerPlugin = wp.plugins.registerPlugin; | |
function MyPluginSidebar() { | |
const [ deprecations, setDeprecations ] = useState( [] ); | |
useEffect( () => { | |
addAction( | |
'deprecated', | |
'myplugin/track-deprecations', | |
( feature, options, message ) => { | |
console.log( 'new deprecation' ); | |
setDeprecations( ( current ) => [ | |
...current, | |
{ feature, options, message }, | |
] ); | |
} | |
); | |
}, [] ); | |
console.log( 'rerender', deprecations ); | |
return el( | |
PluginSidebar, | |
{ | |
name: 'my-sidebar', | |
title: 'My deprecations', | |
icon: 'smiley', | |
}, | |
el( | |
PanelBody, | |
{}, | |
deprecations.map( ( deprecation, index ) => { | |
return el( | |
'p', | |
{ key: index }, | |
el( 'strong', {}, deprecation.feature + ' : ' ), | |
deprecation.message | |
); | |
} ) | |
) | |
); | |
} | |
registerPlugin( 'myplugin', { | |
render: MyPluginSidebar, | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can paste this Gist into the console of the WordPress Block Editor (post or site editor) to try it.