admin管理员组

文章数量:1122832

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.

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.

Share Improve this question asked Jul 9, 2019 at 14:27 MattimatorMattimator 1113 bronze badges 2
  • How are you enqueueing your JavaScript? Can you add that code as well? – Welcher Commented Jul 9, 2019 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 Commented Jul 10, 2019 at 15:21
Add a comment  | 

1 Answer 1

Reset to default 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' )

本文标签: block editorWhen to use removeEditorPanel()