Refactored meta box data collection. Fixed a bug where meta boxes may not be shown. #5619
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We were checking the locations where we have meta boxes in gutenberg_collect_meta_box_data. But our logic did not take into account that the locations of the meta boxes may be changed by the user.
So if the user moved meta boxes that by default appeared in the normal location to the sidebar and had no default sidebar meta box, sidebar meta boxes would not be visible.
To solve that we would need to copy the mechanism that reads user preferences for meta boxes to check their location from do_meta_boxes. Copying this logic makes gutenberg_collect_meta_box_data more complex and increases the maintainability efforts. It would also be very inefficient as that code would be executed multiple times.
So the computing of the array of locations where we have meta boxes was moved to the_gutenberg_metaboxes function where we invoke do_meta_boxes function. This way we can take advantage of the fact that do_meta_boxes returns the number of meta boxes that were outputted.
How Has This Been Tested?
Verify that there are no regression in the meta boxes, they continue to show, we can still use them and save information.
Check that no meta box that appeared by default in the sidebar exists. E.g: extended settings are is not rendered. Activate one more plugin that render meta boxes in the "normal" location e.g: Open Graph Metabox, Simple CSS, Yoast SEO.
Verify that the meta boxes appear in Gutenberg.
In the classic editor move the meta boxes to the sidebar (darg&drop them).
Go to Gutenberg and verify the meta boxes appear in the sidebar as in the classic editor. In master, the meta boxes the user moved to the sidebar are not rendered.
Screenshots (jpeg or gifs if applicable):
Before only meta boxes that were not moved are rendered. Sidebar meta box area does not appear:
After, moved meta boxes are also rendered in the correct place, and we have a sidebar meta box are: