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

Iframed editor: rename PHP function for assets #32010

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ function gutenberg_extend_block_editor_settings_with_fse_theme_flag( $settings )
/**
* Sets the editor styles to be consumed by JS.
*/
function gutenberg_extend_block_editor_styles_html() {
function gutenberg_add_iframed_editor_assets_html() {
Copy link
Member Author

Choose a reason for hiding this comment

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

@gziolo How would this be named in WP core?
@mcsf Is this a good name? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the mention of iframe too implementation-specific? Ultimately, the function returns nothing and has the side effect of echo "<script>window.__editorAssets = $editor_assets</script>";, so I'd favour something as close to the original as gutenberg_extend_block_editor_assets — or alternatively along the lines of gutenberg_prepare_block_editor_frontend_assets?

Also, don't forget to update the doc comment for the function!

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not for the frontend, it's for the editor. It's also very specific for the use in the iframe and ideally we need to refactor this to not output HTML but hopefully the sources formatted as JSON.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not for the frontend, it's for the editor

Right, that's the reason for my poor attempt with _block_editor_frontend_ . But since some of the assets will be editor-only, it's no good.

It's also very specific for the use in the iframe and ideally we need to refactor this to not output HTML but hopefully the sources formatted as JSON.

Hm, that's fair. I'm ok with your initial suggestion, then. :)

Copy link
Member

@gziolo gziolo May 20, 2021

Choose a reason for hiding this comment

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

It's a hard one to name properly, mayby gutenberg_share_block_editor_assets_with_iframe. It's a callback for the filter so in WP core we can replace gutenberg_ with wp_. At least this is the most popular handling. The challenge here is also to ensure it doesn't get printed twice, so in Gutenberg, we should either bail out early when the function is defined in core or maybe better to remove the filter that WP core registers.

Copy link
Member Author

Choose a reason for hiding this comment

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

What should we do now that this has landed in core? Should we remove the core filter when adding this in Gutenberg?

Copy link
Member

Choose a reason for hiding this comment

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

If we want to override the filter that exists in WP core we should remove the original one, before adding a newer version. If the version present in WP core is good enough we would need something to bridge WP 5.7 anyway. We can use an action name that is in WP 5.8 as a way to perform feature detection.

Copy link
Member Author

Choose a reason for hiding this comment

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

What we currently do in Gutenberg, does it not output the scripts twice? So we'll have to do it.

$script_handles = array();
$style_handles = array(
'wp-block-editor',
Expand Down Expand Up @@ -763,9 +763,9 @@ function gutenberg_extend_block_editor_styles_html() {

echo "<script>window.__editorAssets = $editor_assets</script>";
}
add_action( 'admin_footer-toplevel_page_gutenberg-edit-site', 'gutenberg_extend_block_editor_styles_html' );
add_action( 'admin_footer-post.php', 'gutenberg_extend_block_editor_styles_html' );
add_action( 'admin_footer-post-new.php', 'gutenberg_extend_block_editor_styles_html' );
add_action( 'admin_footer-toplevel_page_gutenberg-edit-site', 'gutenberg_add_iframed_editor_assets_html' );
add_action( 'admin_footer-post.php', 'gutenberg_add_iframed_editor_assets_html' );
add_action( 'admin_footer-post-new.php', 'gutenberg_add_iframed_editor_assets_html' );

/**
* Adds a polyfill for object-fit in environments which do not support it.
Expand Down