-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathindex.js
More file actions
91 lines (81 loc) · 2.93 KB
/
index.js
File metadata and controls
91 lines (81 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Internal dependencies
*/
import './editor-loader'
import './color-schemes'
import './buttons-and-icons'
import './spacing-and-borders'
import './block-defaults'
import './icon-library'
import './preset-controls'
/**
* External dependencies
*/
import { SVGStackableIcon } from '~stackable/icons'
import {
i18n,
isContentOnlyMode,
settings,
} from 'stackable'
import { currentUserHasCapability } from '~stackable/util'
/** WordPress dependencies
*/
import { registerPlugin } from '@wordpress/plugins'
import { __ } from '@wordpress/i18n'
import { applyFilters, addAction } from '@wordpress/hooks'
import { useEffect, useState } from '@wordpress/element'
import {
dispatch, select, useSelect,
} from '@wordpress/data'
import { PanelBody } from '@wordpress/components'
// Action used to toggle the global settings panel.
addAction( 'stackable.global-settings.toggle-sidebar', 'toggle', () => {
const stackableSidebar = 'stackable-global-settings/sidebar'
const currentlyOpenedSidebar = select( 'core/edit-post' ).getActiveGeneralSidebarName()
if ( currentlyOpenedSidebar === stackableSidebar ) {
dispatch( 'core/edit-post' ).closeGeneralSidebar( stackableSidebar )
} else {
dispatch( 'core/edit-post' ).openGeneralSidebar( stackableSidebar )
}
} )
const GlobalSettings = () => {
const [ userCanManageOptions, setUserCanManageOptions ] = useState( false )
const id = useSelect( select => select( 'core' ).getCurrentUser()?.id )
useEffect( () => {
const checkCapabilities = async () => {
const capabilities = await currentUserHasCapability( 'manage_options' )
setUserCanManageOptions( capabilities )
}
checkCapabilities()
}, [ id ] )
// For older WP versions (<6.6), wp.editor.PluginSidebar is undefined,
// use wp.editSite.PluginSidebar and wp.editPost.PluginSidebar as fallback
const PluginSidebar = window.wp.editor.PluginSidebar || window.wp.editSite?.PluginSidebar || window.wp.editPost?.PluginSidebar
const globalSettingsInspector = applyFilters( 'stackable.global-settings.inspector', null )
return (
<>
{ PluginSidebar && userCanManageOptions &&
<PluginSidebar
name="sidebar"
title={ __( 'Stackable Settings', i18n ) }
className="ugb-global-settings__inspector"
icon={ <SVGStackableIcon /> }
>
<PanelBody>
<p>
{ __( 'Set global styles and settings for your Stackable blocks to create a consistent design across your site. All the settings below will apply globally.', i18n ) }
{ /*
<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> */ }
</p>
</PanelBody>
{ globalSettingsInspector }
</PluginSidebar>
}
</>
)
}
if ( ! isContentOnlyMode && settings.stackable_enable_global_settings ) {
registerPlugin( 'stackable-global-settings', {
render: GlobalSettings,
} )
}