Skip to content

Commit

Permalink
Language suggestion: Prevent loading script when not needed (#628)
Browse files Browse the repository at this point in the history
* Update the hook and prevent mass-loading of locale script

* Add missing context value
  • Loading branch information
ryelle authored Jun 17, 2024
1 parent 2543908 commit 92d700f
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions mu-plugins/blocks/language-suggest/language-suggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,20 @@ function language_suggest_block_init() {
'wporg/language-suggest',
array(
'name' => 'prominent',
'label' => _x( 'Prominent', 'wporg' ),
'label' => _x( 'Prominent', 'block style name', 'wporg' ),
)
);
}
add_action( 'init', __NAMESPACE__ . '\language_suggest_block_init' );

function language_suggest_enqueue_scripts() {
wp_enqueue_script(
'language-suggest-front',
plugins_url( 'src/front.js', __FILE__ ),
array(),
null,
true
);

wp_add_inline_script(
'language-suggest-front',
'var languageSuggestData = ' . wp_json_encode( array( 'locale' => get_locale() ) ) . ';',
'before'
);
/**
* Inject the locale data for use in viewScript.
*/
function add_locale_data() {
wp_add_inline_script(
'wporg-language-suggest-view-script',
'var languageSuggestData = ' . wp_json_encode( array( 'locale' => get_locale() ) ) . ';',
'before'
);
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\language_suggest_enqueue_scripts' );
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\add_locale_data' );

0 comments on commit 92d700f

Please sign in to comment.