Ensures intent by verifying that a user was referred from another admin page with the correct security nonce.
Description
This function ensures the user intends to perform a given action, which helps protect against clickjacking style attacks. It verifies intent, not authorization, therefore it does not verify the user's capabilities. This should be performed with current_user_can() or similar. If the nonce value is invalid, the function will exit with an "Are You Sure?" style message.
Parameters
$actionint|stringoptional
The nonce action.Default: -1
$query_argstringoptional
Key to check for nonce in $_REQUEST. Default '_wpnonce'.Default: '_wpnonce'
Return
int|false
1 if the nonce is valid and generated between 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago. False if the nonce is invalid.
Hooks fired · 1
One hook fires while check_admin_referer() runs, in this order:
1272functioncheck_admin_referer($action=-1,$query_arg='_wpnonce'){1273if(-1===$action){1274_doing_it_wrong(__FUNCTION__,__('You should specify an action to be verified by using the first parameter.'),'3.2.0');1275}12761277$adminurl=strtolower(admin_url());1278$referer=strtolower(wp_get_referer());1279$result=isset($_REQUEST[$query_arg])?wp_verify_nonce($_REQUEST[$query_arg],$action):false;12801281/**1282 * Fires once the admin request has been validated or not.1283 *1284 * @since 1.5.11285 *1286 * @param string $action The nonce action.1287 * @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between1288 * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.1289 */1290do_action('check_admin_referer',$action,$result);12911292if(!$result&&!(-1===$action&&str_starts_with($referer,$adminurl))){1293wp_nonce_ays($action);1294die();1295}12961297return$result;1298}
History
Introduced in 1.2.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
2.5.0
The $query_arg parameter was added.from the docblock
1.2.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/pluggable.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.