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; }