-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Meta boxes saving when they’re not present (#67254)
* Initialize meta boxes whether or not they’re visible * Add hook for initialization of meta boxes * Minimize hook for meta boxes initialization * Name the export Co-authored-by: stokesman <[email protected]> Co-authored-by: afercia <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: enricobattocchi <[email protected]>
- Loading branch information
1 parent
f6d161d
commit f6f3bdd
Showing
3 changed files
with
43 additions
and
39 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 ] ); | ||
}; |