-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WP 6.7] Fix meta boxes saving when they’re not present (#67503)
* Fix meta boxes saving when they’re not present * Fix hiding/showing meta boxes Co-authored-by: stokesman <presstoke@git.wordpress.org>
- Loading branch information
Showing
3 changed files
with
38 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
32 changes: 32 additions & 0 deletions
32
packages/edit-post/src/components/meta-boxes/use-meta-box-initialization.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editPostStore } from '../../store'; | ||
|
||
/** | ||
* Initializes WordPress `postboxes` script and the logic for saving meta boxes. | ||
* | ||
* @param { boolean } enabled | ||
*/ | ||
export const useMetaBoxInitialization = ( enabled ) => { | ||
const isEnabledAndEditorReady = useSelect( | ||
( select ) => | ||
enabled && select( editorStore ).__unstableIsEditorReady(), | ||
[ enabled ] | ||
); | ||
const { initializeMetaBoxes } = useDispatch( editPostStore ); | ||
// The effect has to rerun when the editor is ready because initializeMetaBoxes | ||
// will noop until then. | ||
useEffect( () => { | ||
if ( isEnabledAndEditorReady ) { | ||
initializeMetaBoxes(); | ||
} | ||
}, [ isEnabledAndEditorReady, initializeMetaBoxes ] ); | ||
}; |