Namespace: heartbeat

wp. heartbeat

Contains the Heartbeat API.
Source:

Methods


connectNow()

Connects as soon as possible regardless of 'hasFocus' state. Will not open two concurrent connections. If a connection is in progress, will connect again immediately after the current connection completes.
Since:
  • 3.8.0
Source:
Returns:
Type
void

dequeue(handle)

Removes data with a particular handle from the queue.
Parameters:
Name Type Description
handle string The handle for the data.
Since:
  • 3.7.0
Source:
Returns:
Type
void

disableSuspend()

Disables suspending. Should be used only when Heartbeat is performing critical tasks like autosave, post-locking, etc. Using this on many screens may overload the user's hosting account if several browser windows/tabs are left open for a long time.
Since:
  • 3.8.0
Source:
Returns:
Type
void

enqueue(handle, data, noOverwrite)

Enqueues data to send with the next XHR. As the data is send asynchronously, this function doesn't return the XHR response. To see the response, use the custom jQuery event 'heartbeat-tick' on the document, example: $(document).on( 'heartbeat-tick.myname', function( event, data, textStatus, jqXHR ) { // code }); If the same 'handle' is used more than once, the data is not overwritten when the third argument is 'true'. Use `wp.heartbeat.isQueued('handle')` to see if any data is already queued for that handle.
Parameters:
Name Type Description
handle string Unique handle for the data, used in PHP to receive the data.
data * The data to send.
noOverwrite boolean Whether to overwrite existing data in the queue.
Since:
  • 3.6.0
Source:
Returns:
True if the data was queued.
Type
boolean

getQueuedItem(handle)

Gets data that was enqueued with a particular handle.
Parameters:
Name Type Description
handle string The handle for the data.
Since:
  • 3.7.0
Source:
Returns:
The data or undefined.
Type
*

hasConnectionError()

Checks whether there is a connection error.
Since:
  • 3.6.0
Source:
Returns:
True if a connection error was found.
Type
boolean

hasFocus()

Checks whether the window (or any local iframe in it) has focus, or the user is active.
Since:
  • 3.6.0
Source:
Returns:
True if the window or the user is active.
Type
boolean

interval(speed, ticks)

Gets/Sets the interval. When setting to 'fast' or 5, the interval is 5 seconds for the next 30 ticks (for 2 minutes and 30 seconds) by default. In this case the number of 'ticks' can be passed as second argument. If the window doesn't have focus, the interval slows down to 2 minutes.
Parameters:
Name Type Description
speed string | number Interval: 'fast' or 5, 15, 30, 60, 120. Fast equals 5.
ticks string Tells how many ticks before the interval reverts back. Used with speed = 'fast' or 5.
Since:
  • 3.6.0
Source:
Returns:
Current interval in seconds.
Type
number