Tests either if the current request carries a valid nonce, or if the current request was referred from an administration screen; depending on whether the $action argument is given (which is prefered), or not, respectively. On failure, the function dies after calling the wp_nonce_ays() function.

Used to avoid security exploits.

The now improper name of the function is kept for backward compatibility and has origin in previous WordPress versions where the function only checked the referer. For details, see the Notes section below.

check_admin_referer() 描述


Obsolete Usage

<?php check_admin_referer(); ?>

Prefered Usage

<?php check_admin_referer$action$query_arg ); ?>

check_admin_referer() 用法



(string) (可选) Action name. Should give the context to what is taking place. (Since 2.0.1).

默认值: -1


(string) (可选) Where to look for nonce in the $_REQUEST PHP variable. (Since 2.5).

默认值: '_wpnonce'

check_admin_referer() 参数


Obsolete usage here (script dies if the admin referer is not validated).

Here is an example of how you might use this in a plugin's option page. You add a nonce to a form using the wp_nonce_field() function:

Then in the page where the form submits to, you can verify whether or not the form was submitted and update values if it was successfully submitted:

check_admin_referer() 示例


  • Using the function without the $action argument is obsolete and, as of Version 3.2, if WP_DEBUG is set to true will die with an appropriate message ("You should specify a nonce 动作 to be verified by using the first parameter." is the default).
  • As of 2.0.1, the referer is checked only if the $action argument is not specified (or set to the default -1) as a backward compatibility fallback for not using a nonce. A nonce is prefered to unreliable referers and with $action specified the function behaves the same way as wp_verify_nonce() except that it dies after calling wp_nonce_ays() if the nonce is not valid or was not sent.

check_admin_referer() 注意


添加于 版本: 1.2.0

check_admin_referer() 历史


check_admin_referer() 函数的代码位于 wp-includes/pluggable.php.

check_admin_referer() 源文件