I'm trying to pass a nonce at the links created from my plugin using add_menu_page and add_submenu_page. Of course this is invalid:

 'my_dashboard&nonce-field=' . wp_create_nonce('my_action'),

as per the Codex, the slug should only include lowercase alphanumeric, dashes, and underscores characters.

So my question is, how could we pass nonce in the URL of the menu links a plugin creates?

  • Can you elaborate on what you're trying to achieve? Not clear on why you need a nonce here. There's probably a better way to do whatever it is you're doing. – Jacob Peattie May 24 '18 at 14:59
  • Yes of course. I'm trying to verify nonce (either with check_admin_referer() or with wp_verify_nonce(), at the body of the show_dashboard function, but to do that, I must pass a nonce field at the initial URL. – L.Milo May 24 '18 at 15:03
  • I use a $_GET variable inside the show_dashboard function, so if I don't have nonce verification, it would produce an error of the WordPress Code Standards. – L.Milo May 24 '18 at 15:05
  • When are you using $_GET? After submitting a form? In that case you're supposed to use a nonce field in the form so that it gets added to the URL when you submit. – Jacob Peattie May 24 '18 at 15:13
  • I'm not submitting a form unfortunately. I'm just checking for $_GET parameters inside the function to be called to output the content for this page, because this specific page is used for many stages at the plugin, so I have to check the $_GET parameters to check at what stage I'm currently at. – L.Milo May 24 '18 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.