From f0e4279a10249d8641217898dca1cd2635a9d792 Mon Sep 17 00:00:00 2001 From: Daniel Morell Date: Fri, 7 Nov 2025 11:44:06 -0600 Subject: [PATCH] Fixed #87 added option to configure a nonce on the frontend JS script attribute. --- README.md | 11 +++++++++++ src/Plugin.php | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f30b3c1..7c360f9 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,17 @@ Filters the Rollbar JavaScript configuration. * `array $config` - The Rollbar JavaScript configuration array. +#### `apply_filters('rollbar_js_nonce', string|null $nonce)` + +Filter that can be used to set the nonce attribute value of the frontend JS script. + +**Since: 3.1.0** + +**Parameters** + +* `string|null $nonce` - The nonce value to be used in the script tag. If `null` the attribute is excluded. Default + is `null`. + #### `apply_filters('rollbar_plugin_settings', array $settings)` Filters the Rollbar plugin settings. diff --git a/src/Plugin.php b/src/Plugin.php index b576744..a7c01c1 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -349,7 +349,16 @@ public function initJsLogging(): void return; } - $rollbarJs = RollbarJsHelper::buildJs($this->buildJsConfig()); + /** + * Filter that can be used to set the nonce attribute value of the frontend JS script. + * + * @param string|null $nonce The nonce value to be used in the script tag. If `null` the attribute is excluded. + * Default is `null`. + * @since 3.1.0 + */ + $nonce = apply_filters('rollbar_js_nonce', null); + + $rollbarJs = RollbarJsHelper::buildJs($this->buildJsConfig(), nonce: $nonce); echo $rollbarJs; }