Skip to content

Instantly share code, notes, and snippets.

@youknowriad
Created April 24, 2024 22:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save youknowriad/e668c56f20e514dfe84bf01e793e7860 to your computer and use it in GitHub Desktop.
Save youknowriad/e668c56f20e514dfe84bf01e793e7860 to your computer and use it in GitHub Desktop.
Gutenberg Log Deprecations
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,
} );
@youknowriad
Copy link
Author

You can paste this Gist into the console of the WordPress Block Editor (post or site editor) to try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment