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:
1368functioncheck_admin_referer($action=-1,$query_arg='_wpnonce'){1369if(-1===$action){1370_doing_it_wrong(__FUNCTION__,__('You should specify an action to be verified by using the first parameter.'),'3.2.0');1371}13721373$adminurl=strtolower(admin_url());1374$referer=strtolower(wp_get_referer());1375$result=isset($_REQUEST[$query_arg])?wp_verify_nonce($_REQUEST[$query_arg],$action):false;13761377/**1378 * Fires once the admin request has been validated or not.1379 *1380 * @since 1.5.11381 *1382 * @param string $action The nonce action.1383 * @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between1384 * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.1385 */1386do_action('check_admin_referer',$action,$result);13871388if(!$result&&!(-1===$action&&str_starts_with($referer,$adminurl))){1389wp_nonce_ays($action);1390die();1391}13921393return$result;1394}
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.9.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.