Skip to content

Commit

Permalink
General: Escape nonce used for block theme activation.
Browse files Browse the repository at this point in the history
Add `wp_json_encode()` as an escaping function when setting the `WP_BLOCK_THEME_ACTIVATE_NONCE` global on the block theme preview screen.

This account for custom nonce implementations making use of special characters that require escaping in JavaScript strings.

Props antonvlasenko, ramonopoly.
Fixes #58712.



git-svn-id: https://develop.svn.wordpress.org/trunk@56218 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
peterwilsoncc committed Jul 12, 2023
1 parent ee7434f commit 4417367
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/wp-includes/theme-previews.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function wp_block_theme_activate_nonce() {
$nonce_handle = 'switch-theme_' . wp_get_theme_preview_path();
?>
<script type="text/javascript">
window.WP_BLOCK_THEME_ACTIVATE_NONCE = '<?php echo wp_create_nonce( $nonce_handle ); ?>';
window.WP_BLOCK_THEME_ACTIVATE_NONCE = <?php echo wp_json_encode( wp_create_nonce( $nonce_handle ) ); ?>;
</script>
<?php
}
Expand Down

0 comments on commit 4417367

Please sign in to comment.