0

I'd like to remove the Discussion Panel in the post editor sidebar with removeEditorPanel().

I'm trying to do the following:

const { removeEditorPanel } = wp.data.dispatch( 'core/edit-post' )
removeEditorPanel( 'discussion-panel' )

However, I get an error that removeEditorPanel is undefined because, I assume, core/edit-post hasn't loaded yet. Is there an event or hook that I can use to know that the post editor is loaded?

As a workaround, I'm using an interval to check that window.wp exists and a querySelector() to check for .edit-post-sidebar, but that just feels janky.

  • How are you enqueueing your JavaScript? Can you add that code as well? – Welcher Jul 9 at 18:09
  • @Welcher I'm using create-guten-block, which enqueues with wp_enqueue_script( 'orthoscan_blocks-js', plugins_url( '/dist/blocks.build.js', dirname( __FILE__ ) ),array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ), true ); – Mattimator Jul 10 at 15:21
0

I think this is due to how you've destructured it out. I believe dispatch works as a realtime "action". So you need call dispatch() when you want to remove the panel.

Try this:

const { dispatch } = wp.data;
dispatch( 'core/edit-post' ).removeEditorPanel( 'discussion-panel' )
  • Thanks for the suggestion, but that still throws the same error. wp.data.dispatch('core/edit-post') and removeEditorPanel are both undefined. I think the problem is I'm calling dispatch too early, but I'm not sure how to know when to call it (outside of registerBlockType, because I want to remove the panel irrespective of the blocks I register). – Mattimator Jul 22 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.