Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored meta box data collection. Fixed a bug where meta boxes may not be shown. #5619

Merged

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Mar 14, 2018

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:
image

After, moved meta boxes are also rendered in the correct place, and we have a sidebar meta box are:
image

@jorgefilipecosta jorgefilipecosta added [Type] Bug An existing feature does not function as intended [Feature] Meta Boxes A draggable box shown on the post editing screen labels Mar 14, 2018
@jorgefilipecosta jorgefilipecosta self-assigned this Mar 14, 2018
@jorgefilipecosta jorgefilipecosta force-pushed the fix/metaboxes-may-not-be-shown-if-they-were-moved branch from 9f27773 to 1e081b4 Compare March 14, 2018 22:19
@jorgefilipecosta jorgefilipecosta requested a review from a team March 16, 2018 19:32
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice simplification

… may not be shown if they were moved to other location by the user.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Meta Boxes A draggable box shown on the post editing screen [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants