在New / Edit Post屏幕上检查nonce到期,并在需要时刷新
原型
wp_refresh_post_nonces( array $response, array $data, string $screen_id )
参数
$response
(array)
(Required)
心跳响应。
$data
(array)
(Required)
发送了$ _POST数据。
$screen_id
(string)
(Required)
屏幕ID。
返回值
(array)
心跳响应。
源文件
路径:wp-admin/includes/misc.php
<?php
...
function wp_refresh_post_nonces( $response, $data, $screen_id ) {
if ( array_key_exists( 'wp-refresh-post-nonces', $data ) ) {
$received = $data['wp-refresh-post-nonces'];
$response['wp-refresh-post-nonces'] = array( 'check' => 1 );
if ( ! $post_id = absint( $received['post_id'] ) ) {
return $response;
}
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $response;
}
$response['wp-refresh-post-nonces'] = array(
'replace' => array(
'getpermalinknonce' => wp_create_nonce('getpermalink'),
'samplepermalinknonce' => wp_create_nonce('samplepermalink'),
'closedpostboxesnonce' => wp_create_nonce('closedpostboxes'),
'_ajax_linking_nonce' => wp_create_nonce( 'internal-linking' ),
'_wpnonce' => wp_create_nonce( 'update-post_' . $post_id ),
),
);
}
return $response;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_refresh_post_nonces/