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

Use wp_add_inline_script for createBlockTheme object #428

Merged
merged 2 commits into from
Aug 14, 2023

Conversation

vcanales
Copy link
Member

This change ensures we follow accepted good practices, as wp_localize_script should only be used when localizing strings.

It's more verbose, but it doesn't lend itself to confusion.

Relevant comment: https://developer.wordpress.org/reference/functions/wp_localize_script/#comment-3213

@vcanales vcanales added the enhancement New feature or request label Jul 27, 2023
@vcanales vcanales force-pushed the refactor-inline-script-call branch from 5909229 to 3e599ac Compare July 31, 2023 14:25
Copy link
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

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

This is working well for me. I can see the createBlockTheme global variable is created in the same format, and looks more readable in the page source:

image

The "Add Google fonts to your theme" page still works as expected ✅

I did notice that the fonts json file is now included after the build script (ID create-block-theme-app-js), whereas currently the file is included before:

image

I don't think it affects the way the app works, but it looks like we can switch the order by adding 'before' to the wp_add_inline_script call:

wp_add_inline_script(
	'create-block-theme-app',
	sprintf(
		$script_content,
		esc_url( plugins_url( 'assets/google-fonts/fallback-fonts-list.json', __DIR__ ) ),
		esc_url( admin_url() ),
		esc_url( get_template_directory_uri() )
	),
	'before'
);

I don't think it matters either way, just wanted to point out the order change!

Vicente Canales and others added 2 commits August 14, 2023 11:43
This change ensures we follow accepted good practices, as
`wp_localize_script` should only be used when localizing strings.

It's more verbose, but it doesn't lend itself to confusion.

Relevant comment: https://developer.wordpress.org/reference/functions/wp_localize_script/#comment-3213
@vcanales
Copy link
Member Author

I don't think it matters either way, just wanted to point out the order change!

Good catch; I agree that it doesn't seem to affect things, but in order to keep things as close as they were before, I've added your suggestion.

@vcanales vcanales merged commit 41bd24a into trunk Aug 14, 2023
@mikachan mikachan deleted the refactor-inline-script-call branch August 14, 2023 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants