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:
1287functioncheck_admin_referer($action=-1,$query_arg='_wpnonce'){1288if(-1===$action){1289_doing_it_wrong(__FUNCTION__,__('You should specify an action to be verified by using the first parameter.'),'3.2.0');1290}12911292$adminurl=strtolower(admin_url());1293$referer=strtolower(wp_get_referer());1294$result=isset($_REQUEST[$query_arg])?wp_verify_nonce($_REQUEST[$query_arg],$action):false;12951296/**1297 * Fires once the admin request has been validated or not.1298 *1299 * @since 1.5.11300 *1301 * @param string $action The nonce action.1302 * @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between1303 * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.1304 */1305do_action('check_admin_referer',$action,$result);13061307if(!$result&&!(-1===$action&&str_starts_with($referer,$adminurl))){1308wp_nonce_ays($action);1309die();1310}13111312return$result;1313}
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.8.8 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.