wp_refresh_post_nonces

函式
wp_refresh_post_nonces ( $response, $data, $screen_id )
引數
  • (array) $response The Heartbeat response.
    Required:
  • (array) $data The $_POST data sent.
    Required:
  • (string) $screen_id The screen ID.
    Required:
返回值
  • (array) The Heartbeat response.
定義位置
相關方法
wp_refresh_post_lockwp_refresh_heartbeat_nonceswp_refresh_metabox_loader_nonceswp_trash_post_commentswp_restore_post_revision
引入
3.6.0
棄用
-

wp_refresh_post_nonces: 這個函式用來重新整理文章編輯器使用的nonces,以防止未經授權訪問文章資料。

在新建/編輯文章介面檢查nonce的過期情況,如果需要,可以重新整理。

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 );

		$post_id = absint( $received['post_id'] );

		if ( ! $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;
}

常見問題

FAQs
檢視更多 >