Replies: 1 comment 1 reply
-
You can use In your case : <?php
global $papi_nonce;
$papi_nonce = papi_create_nonce();
function papi_create_nonce($length = 32) {
global $papi_nonce;
// ...
return $papi_nonce;
}
function papi_my_csp() {
global $papi_nonce;
echo '<meta ...' . $papi_nonce . '....>';
} You could also use the built-in nonce API, eg replace your custom nonce function with a call to |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm writing my first plugin, which adds a Content Security Policy in the meta equiv attribute.
It includes a dynamic nonce which I want to use in functions-html.php.
How can I access the variable
$papi_dynamic_nonce
of my plugin in functions_html.php?Trying
<script type="text/javascript" nonce='<?php echo $papi_dynamic_nonce ?>'>
or<?php global $papi_dynamic_nonce; echo $papi_dynamic_nonce; ?>
does not produce the desired result. The variable don't exist in this scope.
Thanks for helping a novice!
Papillon
Beta Was this translation helpful? Give feedback.
All reactions