我正在寻找一种方法来隐藏一些页面设置面板在Gutenberg编辑器侧边栏基于用户角色。由于这些面板标题没有特定的类,所以我无法使用CSS来针对它们,所以我想知道是否有一种方法至少可以控制哪些面板在首选项中处于活动状态:

有没有人知道我是否可以根据用户角色有条件地预先设置这些切换点?
非常感谢。
发布于 2022-03-28 07:20:07
我在WordPress 5.9上做了一些工作(没有在早期版本上进行测试)。
包含插件/主题的JS
add_action( 'enqueue_block_editor_assets', [ __CLASS__, 'so67286587EnqueueGutenbergEditorAssets' ] );
function so67286587EnqueueGutenbergEditorAssets() {
wp_enqueue_script( 'so67286587-gutenberg', plugins_url( '/js/gutenberg.jsx.js', __FILE__ ), [ 'wp-edit-post' ] );
}这是JS的特效。我只是检查是否一些功能是检查/未检查,并切换他们。
// force enabling those settings
['reducedUI', 'keepCaretInsideBlock', 'showBlockBreadcrumbs', 'focusMode', 'themeStyles'].forEach(mustBeEnabled => {
if (!wp.data.select('core/edit-post').isFeatureActive(mustBeEnabled)) {
wp.data.dispatch('core/edit-post').toggleFeature(mustBeEnabled);
}
});
// force disabling those settings
['fullscreenMode', 'fixedToolbar', 'welcomeGuide', 'showIconLabels', 'mostUsedBlocks'].forEach(mustBeDisabled => {
if (wp.data.select('core/edit-post').isFeatureActive(mustBeDisabled)) {
wp.data.dispatch('core/edit-post').toggleFeature(mustBeDisabled);
}
});这个JSX文件是用@wordpress/脚本编译的。
https://stackoverflow.com/questions/67286587
复制相似问题