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. Only possible when $action is -1, as the function otherwise exits rather than returning false.
Hooks fired · 1
One hook fires while check_admin_referer() runs, in this order:
1374functioncheck_admin_referer($action=-1,$query_arg='_wpnonce'){1375if(-1===$action){1376_doing_it_wrong(__FUNCTION__,__('You should specify an action to be verified by using the first parameter.'),'3.2.0');1377}13781379$adminurl=strtolower(admin_url());1380$referer=strtolower(wp_get_referer());1381$result=isset($_REQUEST[$query_arg])?wp_verify_nonce($_REQUEST[$query_arg],$action):false;13821383/**1384 * Fires once the admin request has been validated or not.1385 *1386 * @since 1.5.11387 *1388 * @param string $action The nonce action.1389 * @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between1390 * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.1391 */1392do_action('check_admin_referer',$action,$result);13931394if(!$result&&!(-1===$action&&str_starts_with($referer,$adminurl))){1395wp_nonce_ays($action);1396die();1397}13981399return$result;1400}
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 7.1.0 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.