Skip to content

Commit

Permalink
Use wp_add_inline_script for WPCOM sidebar notice (#40465)
Browse files Browse the repository at this point in the history
* Use wp_add_inline_script

* Fix syntax

* changelog

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/12191014160

Upstream-Ref: Automattic/jetpack@d0318ed
  • Loading branch information
okmttdhr authored and matticbot committed Dec 6, 2024
1 parent bbf9cb1 commit a5de230
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 95 deletions.
58 changes: 29 additions & 29 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/automattic/jetpack-mu-wpcom/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

This is an alpha version! The changes listed here are not final.

### Changed
- Use wp_add_inline_script

### Fixed
- Load WPCOM sidebar notice async

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '58e5ab90569a6b59ac8e');
<?php return array('dependencies' => array(), 'version' => '8f30753970be611fb884');

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const wpcomFetchSidebarNotice = async () => {
`${ wpcomSidebarNoticeConfig.ajaxUrl }?action=wpcom_fetch_sidebar_notice&nonce=${ wpcomSidebarNoticeConfig.nonce }`
);

if ( ! response.status === 200 ) {
if ( response.status !== 200 ) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ function wpcom_enqueue_sidebar_notice_assets() {
$asset_file['version'] ?? filemtime( Jetpack_Mu_Wpcom::BASE_DIR . 'build/wpcom-sidebar-notice/wpcom-sidebar-notice.css' )
);

wp_localize_script(
'wpcom-sidebar-notice',
'wpcomSidebarNoticeConfig',
array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'wpcom_fetch_sidebar_notice' ),
)
$data = array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'wpcom_fetch_sidebar_notice' ),
);
$inline_script = 'const wpcomSidebarNoticeConfig = ' . wp_json_encode( $data ) . ';';
wp_add_inline_script( 'wpcom-sidebar-notice', $inline_script, 'before' );
}
add_action( 'admin_enqueue_scripts', 'wpcom_enqueue_sidebar_notice_assets' );

Expand Down
Loading

0 comments on commit a5de230

Please sign in to comment.