Skip to content

Instantly share code, notes, and snippets.

@kopepasah
Last active April 30, 2019 09:26
Show Gist options
  • Save kopepasah/357a386756e98ba77b968626579890ae to your computer and use it in GitHub Desktop.
Save kopepasah/357a386756e98ba77b968626579890ae to your computer and use it in GitHub Desktop.
Ensure some panels are "Always On".
// 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