wp-shortcake / shortcake

Shortcake makes using WordPress shortcodes a piece of cake.
GNU General Public License v2.0
664 stars 142 forks source link

Avoid outputting underscore templates before the opening <doctype> tag #807

Closed goldenapples closed 5 years ago

goldenapples commented 5 years ago

As noted in #806, the pattern used for many of the Shortcake attribute fields which output custom field templates is to output those templates on the shortcode_ui_loaded_editor hook. In WP 5.0 with the block editor active, this hook fires before the page output is begun, which causes these script templates to be spit out before the opening tag, causing all kinds of ruckus with the browser layout.

Specifically, any output before the declaration forces browsers into quirks mode, which renders the flex layout required for the Gutenberg editor incorrectly. In practive this was causing meta boxes to float awkwardly over editor content.

This fixes the problem by, instead of outputting the templates on the shortcode_ui_loaded_editor hook, instead attaching a hook to a later action to output these templates in the admin footer.