wp_nonce_field( int|string $action = -1, string $name = ‘_wpnonce’, bool $referer = true, bool $echo = true )

Retrieve or display nonce hidden field for forms.检索或显示表格的临时隐藏字段。是wp表格的自带验证,可以有效防止注册、提交等动作。

The nonce field is used to validate that the contents of the form came from the location on the current site and not somewhere else. The nonce does not offer absolute protection, but should protect against most cases. It is very important to use nonce field in forms.

The $action and $name are optional, but if you want to have better security, it is strongly suggested to set those two parameters. It is easier to just call the function without any parameters, because validation of the nonce doesn’t require any parameters, but since crackers know what the default is it won’t be difficult for them to find a way around your nonce and cause damage.

The input name will be whatever $name value you gave. The input value will be the nonce creation value.






(int|string) (Optional) Action name.

Default value: -1$name

(string) (Optional) Nonce name.

Default value: ‘_wpnonce’$referer

(bool) (Optional) Whether to set the referer field for validation.

Default value: true$echo

(bool) (Optional) Whether to display or return hidden form field.

Default value: true

Anytime you submit form data and you add it todatabase it’s a good idea to use wp’s nonce field generate a unique ID it’s for the functions so that you know the not being posted you are not geting data posted from a malicious script.(恶意脚本)


Share :
Tag :