@@ -18,13 +18,17 @@ import {
1818 isContentOnlyMode ,
1919 settings ,
2020} from 'stackable'
21+ import { currentUserHasCapability } from '~stackable/util'
2122
2223/** WordPress dependencies
2324 */
2425import { registerPlugin } from '@wordpress/plugins'
2526import { __ } from '@wordpress/i18n'
2627import { applyFilters , addAction } from '@wordpress/hooks'
27- import { dispatch , select } from '@wordpress/data'
28+ import { useEffect , useState } from '@wordpress/element'
29+ import {
30+ dispatch , select , useSelect ,
31+ } from '@wordpress/data'
2832import { PanelBody } from '@wordpress/components'
2933
3034// Action used to toggle the global settings panel.
@@ -40,13 +44,26 @@ addAction( 'stackable.global-settings.toggle-sidebar', 'toggle', () => {
4044} )
4145
4246const GlobalSettings = ( ) => {
47+ const [ userCanManageOptions , setUserCanManageOptions ] = useState ( false )
48+ const id = useSelect ( select => select ( 'core' ) . getCurrentUser ( ) . id )
49+
50+ useEffect ( ( ) => {
51+ const checkCapabilities = async ( ) => {
52+ const capabilities = await currentUserHasCapability ( 'manage_options' )
53+ setUserCanManageOptions ( capabilities )
54+ }
55+
56+ checkCapabilities ( )
57+ } , [ id ] )
4358 // For older WP versions (<6.6), wp.editor.PluginSidebar is undefined,
4459 // use wp.editSite.PluginSidebar and wp.editPost.PluginSidebar as fallback
4560 const PluginSidebar = window . wp . editor . PluginSidebar || window . wp . editSite ?. PluginSidebar || window . wp . editPost ?. PluginSidebar
4661
62+ const globalSettingsInspector = applyFilters ( 'stackable.global-settings.inspector' , null )
63+
4764 return (
4865 < >
49- { PluginSidebar &&
66+ { PluginSidebar && userCanManageOptions &&
5067 < PluginSidebar
5168 name = "sidebar"
5269 title = { __ ( 'Stackable Settings' , i18n ) }
@@ -60,7 +77,7 @@ const GlobalSettings = () => {
6077 <a href="https://docs.wpstackable.com/article/465-how-to-style-the-different-block-hover-states?utm_source=wp-settings-global-settings&utm_campaign=learnmore&utm_medium=wp-dashboard" target="_docs">{ __( 'Learn more', i18n ) }</a> */ }
6178 </ p >
6279 </ PanelBody >
63- { applyFilters ( 'stackable.global-settings.inspector' , null ) }
80+ { globalSettingsInspector }
6481 </ PluginSidebar >
6582 }
6683 </ >
0 commit comments