wp_ajax_nopriv_heartbeat() - WordPress 函数参考中文文档

返回介绍

wp_ajax_nopriv_heartbeat()

发布于 2017-09-11 字数2712 浏览 906 评论 0

wp_ajax_nopriv_heartbeat()

Ajax handler for the Heartbeat API in the no-privilege context.


描述

Runs when the user is not logged in.


源代码

File: wp-admin/includes/ajax-actions.php

function wp_ajax_nopriv_heartbeat() {
	$response = array();

	// screen_id is the same as $current_screen->id and the JS global 'pagenow'.
	if ( ! empty($_POST['screen_id']) )
		$screen_id = sanitize_key($_POST['screen_id']);
	else
		$screen_id = 'front';

	if ( ! empty($_POST['data']) ) {
		$data = wp_unslash( (array) $_POST['data'] );

		/**
		 * Filters Heartbeat Ajax response in no-privilege environments.
		 *
		 * @since 3.6.0
		 *
		 * @param array|object $response  The no-priv Heartbeat response object or array.
		 * @param array        $data      An array of data passed via $_POST.
		 * @param string       $screen_id The screen id.
		 */
		$response = apply_filters( 'heartbeat_nopriv_received', $response, $data, $screen_id );
	}

	/**
	 * Filters Heartbeat Ajax response when no data is passed.
	 *
	 * @since 3.6.0
	 *
	 * @param array|object $response  The Heartbeat response object or array.
	 * @param string       $screen_id The screen id.
	 */
	$response = apply_filters( 'heartbeat_nopriv_send', $response, $screen_id );

	/**
	 * Fires when Heartbeat ticks in no-privilege environments.
	 *
	 * Allows the transport to be easily replaced with long-polling.
	 *
	 * @since 3.6.0
	 *
	 * @param array|object $response  The no-priv Heartbeat response.
	 * @param string       $screen_id The screen id.
	 */
	do_action( 'heartbeat_nopriv_tick', $response, $screen_id );

	// Send the current time according to the server.
	$response['server_time'] = time();

	wp_send_json($response);
}

更新日志

Version 描述
3.6.0 Introduced.

相关函数

Uses

  • wp-admin/includes/ajax-actions.php:
    heartbeat_nopriv_received
  • wp-admin/includes/ajax-actions.php:
    heartbeat_nopriv_send
  • wp-admin/includes/ajax-actions.php:
    heartbeat_nopriv_tick
  • wp-includes/formatting.php:
    wp_unslash()
  • wp-includes/formatting.php:
    sanitize_key()
  • wp-includes/functions.php:
    wp_send_json()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/plugin.php:
    do_action()
  • Show 3 more uses
    Hide more uses


User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!