Skip to content

Commit f0e4279

Browse files
committed
Fixed #87 added option to configure a nonce on the frontend JS script attribute.
1 parent c5b8be5 commit f0e4279

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ Filters the Rollbar JavaScript configuration.
193193

194194
* `array $config` - The Rollbar JavaScript configuration array.
195195

196+
#### `apply_filters('rollbar_js_nonce', string|null $nonce)`
197+
198+
Filter that can be used to set the nonce attribute value of the frontend JS script.
199+
200+
**Since: 3.1.0**
201+
202+
**Parameters**
203+
204+
* `string|null $nonce` - The nonce value to be used in the script tag. If `null` the attribute is excluded. Default
205+
is `null`.
206+
196207
#### `apply_filters('rollbar_plugin_settings', array $settings)`
197208

198209
Filters the Rollbar plugin settings.

src/Plugin.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,16 @@ public function initJsLogging(): void
349349
return;
350350
}
351351

352-
$rollbarJs = RollbarJsHelper::buildJs($this->buildJsConfig());
352+
/**
353+
* Filter that can be used to set the nonce attribute value of the frontend JS script.
354+
*
355+
* @param string|null $nonce The nonce value to be used in the script tag. If `null` the attribute is excluded.
356+
* Default is `null`.
357+
* @since 3.1.0
358+
*/
359+
$nonce = apply_filters('rollbar_js_nonce', null);
360+
361+
$rollbarJs = RollbarJsHelper::buildJs($this->buildJsConfig(), nonce: $nonce);
353362

354363
echo $rollbarJs;
355364
}

0 commit comments

Comments
 (0)