创建与特定操作,用户,用户会话和时间窗口关联的加密令牌。
原型
wp_create_nonce( string|int $action = -1 )
参数
$action
(string|int)
(Optional)
标量值,用于向nonce添加上下文。
返回值
(string)
令牌。
源文件
路径:wp-includes/pluggable.php
<?php
...
function wp_create_nonce($action = -1) {
$user = wp_get_current_user();
$uid = (int) $user->ID;
if ( ! $uid ) {
/** This filter is documented in wp-includes/pluggable.php */
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
}
$token = wp_get_session_token();
$i = wp_nonce_tick();
return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_create_nonce/