Slide 1

Slide 1 text

Heartbeat API: your data simply in realtime. ! WordCamp NYC 2014 Mike Schroder (DH-Shredder) @GetSource - http://www.getsource.net

Slide 2

Slide 2 text

Who Am I? • Mike Schroder, a.k.a DH- Shredder, a.k.a. @GetSource • Third Culture Kid, enjoy Coffee & Sailing • WordPress 3.9 Co-Lead and co-author of Heartbeat API • Happy DreamHost Employee

Slide 3

Slide 3 text

WAT is Heartbeat API?

Slide 4

Slide 4 text

Realtime* Bidirectional communication via AJAX.

Slide 5

Slide 5 text

15-30 seconds by default. 120 seconds when inactive.

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

EXPERIMENTAL WARNING!

Slide 12

Slide 12 text

EXPERIMENTAL WARNING!

Slide 13

Slide 13 text

No longer experimental as of WordPress 3.9

Slide 14

Slide 14 text

JS Trigger Flow ! ! -> heartbeat-send -> heartbeat-tick -/> heartbeat-error ! ! (wp-includes/js/heartbeat.js)

Slide 15

Slide 15 text

PHP Filter/Action Flow ! ! -> heartbeat_received -> heartbeat_send -> heartbeat_tick (action) ! ! (wp-admin/includes/ajax-actions.php)

Slide 16

Slide 16 text

if ( ! empty( $_POST['data'] ) ) { $data = (array) $_POST['data']; $response = apply_filters( 'heartbeat_received', $response, $data, $screen_id ); } $response = apply_filters( 'heartbeat_send', $response, $screen_id ); ! do_action( 'heartbeat_tick', $response, $screen_id ); // Send the current time according to the server $response['server_time'] = time(); wp_send_json($response); Direct from core.

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

wp-json/honk_horn custom REST endpoint demo

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

This is just a start.

Slide 21

Slide 21 text

Resources! • getsource.net/2014/01/heartbeat-api-wordcamp-phoenix/ • gist.github.com/getsource/6254495 • core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/js/heartbeat.js • pippinsplugins.com/using-the-wordpress-heartbeat-api/ Mike Schroder (DH-Shredder) @GetSource - http://www.getsource.net