描述

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.

用法

Obsolete Usage

`<?php check_admin_referer(); ?>`

Prefered Usage

`<?php check_admin_referer( \$action, \$query_arg ); ?>`

参数

\$action

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

\$query_arg

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

示例

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:

注意

• 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() 函数的代码位于 `wp-includes/pluggable.php`.
{"extraction_info": {"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.808588981628418, "perplexity": 3169.258400839366}, "config": {"markdown_headings": false, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-22/segments/1558232256314.52/warc/CC-MAIN-20190521102417-20190521124417-00072.warc.gz"}