【问题标题】:How to remove panels from Gutenberg in cleared way?如何以清晰的方式从古腾堡移除面板?
【发布时间】:2020-05-04 15:01:40
【问题描述】:

我正在寻找一些代码来帮助我从 Gutenberg 删除面板,但特别是针对选定角色而不是每个角色的设置等。我尝试了所有方法,但问题是 Gutenberg 使用面板而不是像经典编辑器这样的元框之前。

有人知道如何在gutenberg 中为x 个用户级别关闭元框吗?

我尝试了 https://codex.wordpress.org/Function_Reference/remove_meta_box ,但正如我所说的那样,因为古腾堡,这行不通。

谢谢。

【问题讨论】:

  • 谁能帮帮我?

标签: wordpress wordpress-gutenberg gutenberg-blocks


【解决方案1】:

如您所知,Gutenberg 忽略了 remove_meta_box。您可以通过执行以下操作来移除面板:

PHP 中注册一个脚本。同时注册一个空块,并在其中添加一个 JS 文件。

function hughie_register_files() {
    // script file
    wp_register_script(
        'hughie-admin-panels',
        plugins_url('/scripts/admin-panels.js', __FILE__),
        [ 'wp-blocks', 'wp-edit-post' ]
    );
    // register block editor script
    register_block_type( 'hughie/admin-panels', array(
        'editor_script' => 'hughie-admin-panels'
    ) );
}

JS 文件中添加以下任何一行:

wp.data.dispatch('core/edit-post').removeEditorPanel( 'taxonomy-panel-category' ) ; // category
wp.data.dispatch('core/edit-post').removeEditorPanel( 'taxonomy-panel-TAXONOMY-NAME' ) ; // custom taxonomy
wp.data.dispatch('core/edit-post').removeEditorPanel( 'taxonomy-panel-post_tag' ); // tags
wp.data.dispatch('core/edit-post').removeEditorPanel( 'featured-image' ); // featured image
wp.data.dispatch('core/edit-post').removeEditorPanel( 'post-link' ); // permalink
wp.data.dispatch('core/edit-post').removeEditorPanel( 'page-attributes' ); // page attributes
wp.data.dispatch('core/edit-post').removeEditorPanel( 'post-excerpt' ); // Excerpt
wp.data.dispatch('core/edit-post').removeEditorPanel( 'discussion-panel' ); // Discussion

你的问题是你只想包含文件是用户有一定的能力。

所有 WP 钩子都可以在以下位置找到:https://codex.wordpress.org/Plugin_API/Action_Reference

init 被调用时,用户应该被定义并且可以检查

【讨论】:

  • Init 是一个 wordpress 动作钩子。只需将函数放在那个钩子上
猜你喜欢
  • 2019-02-16
  • 1970-01-01
  • 2019-01-21
  • 2022-06-21
  • 2021-08-24
  • 2019-09-20
  • 2019-06-26
  • 1970-01-01
  • 2023-02-13
相关资源
最近更新 更多