Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- //embed heartbeat api
- function heartbeat_test_enqueue($hook_suffix) {
- if ( is_page(1105)) {
- // Make sure the JS part of the Heartbeat API is loaded.
- wp_enqueue_script('heartbeat');
- // Output the test JS in footer.
- add_action( 'print_footer_scripts', 'heartbeat_test_js', 20 );
- //Add filter to receive hook, and specify we need 2 parameters.
- add_filter( 'heartbeat_received', 'dw_receive_heartbeat', 10, 2 );
- }
- }
- add_action( 'wp_enqueue_scripts', 'heartbeat_test_enqueue' );
- //clientside
- function heartbeat_test_js() {
- ?>
- <script>
- jQuery(document).ready( function($) {
- // Hook into the heartbeat-send
- jQuery( document ).on( 'heartbeat-send', function( e, data ) {
- //
- });
- // Listen for the custom event "heartbeat-tick" on $(document). This fire's once every minute that the page is open.
- jQuery(document).on( 'heartbeat-tick', function(e, data) {
- console.log("tick");
- });
- });
- </script>
- <?php
- }
- //change heartbeat interval time
- function m_heartbeat_settings( $settings ) {
- $settings['interval'] = 15; //only values between 15 and 60 seconds allowed
- return $settings;
- }
- add_filter( 'heartbeat_settings', 'm_heartbeat_settings' );
- //heartbeat api end
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement