Last active
April 30, 2019 09:26
-
-
Save kopepasah/357a386756e98ba77b968626579890ae to your computer and use it in GitHub Desktop.
Ensure some panels are "Always On".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Subscribe to changes in the wp.data redux store. | |
wp.data.subscribe( () => { | |
// An array of "Always On" panel (metabox) ids to disallow disabling. | |
const alwaysOn = []; | |
// Current panels preferences | |
const panels = wp.data.select( 'core/edit-post' ).getPreference( 'panels' ); | |
// Loop over the panels object. | |
for ( const id in panels ) { | |
// Only target panels in the always alwaysOn array. | |
if ( panels.hasOwnProperty( id ) && alwaysOn.includes( id ) ) { | |
const panel = panels[ id ]; | |
// Only perform the actions with panels with enabled property. | |
if ( panel.hasOwnProperty( 'enabled' ) ) { | |
// If panel is disabled, enable it. | |
if ( ! panel.enabled ) { | |
wp.data.dispatch( 'core/edit-post' ).toggleEditorPanelEnabled( id ) | |
} | |
} | |
} | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment