Retrieves URL with nonce added to URL query.
Parameters
$actionurl
stringrequired- URL to add nonce action.
$action
int|stringoptional- Nonce action name.
Default:
-1
$name
stringoptional- Nonce name. Default
'_wpnonce'
.Default:
'_wpnonce'
Source
*
* @param string $actionurl URL to add nonce action.
* @param int|string $action Optional. Nonce action name. Default -1.
* @param string $name Optional. Nonce name. Default '_wpnonce'.
Changelog
Version | Description |
---|---|
2.0.4 | Introduced. |
Note that
wp_nonce_url
escapes&
to&
and may cause links or redirects to become incorrect.Example
Plugin authors can safely add links that perform tasks using a combination of wp_nonce_url() and admin_url() .
For instance, start by creating the link users can click to do something interesting:
Then, to detect when the user clicks the link, check the nonce validity using wp_verify_nonce() in the function you defined when you called add_menu_page() or one of its Administration Menus wrappers. If the nonce isn’t valid, the link wasn’t clicked, so display the link. Otherwise, do “something interesting.”
Note that the recommended “context” parameter of the nonce is used to disambiguate which button was pressed. If you make more than one button users can press, make sure each button has a different nonce name and/or context.