passing variables from php to js within static block created using npx
-
I have a static block created using
npx @wordpress/create-block
, with one plugin php file, and among other files: edit.js, save.js and view.js.
It is a form that does ajax call to admin-ajax.php with specific action, and i would like to secure it a little bit, so i thought that generating and verifying nonce would be a good start.
If i understand it correctly, this nonce should be generated server side, then somehow passed to client, and then sended back to server within ajax call where it should be verified.
However I can’t find any reliable way to send variable to edit|save.js or view.js from php file (I can generate it usingwp_create_nonce
).What I found are references to
wp_localize_script
, orwp_add_inline_script
, but those need handle to a script, which can be obtained when registering script throughwp_register_script
function, but my block is generated using npx, so it doesn’t use that function – they are included throughblock.json
file and there doesn’t seem to be any kind of handle defined.
Is there some kind of handle generated when included by block.json, or there isn’t one?
How can I pass variables from php to these files when they are included withblock.json
?Thanks in advance
- The topic ‘passing variables from php to js within static block created using npx’ is closed to new replies.