Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. <?PHP  
  2. //embed heartbeat api
  3.     function heartbeat_test_enqueue($hook_suffix) {
  4.             if ( is_page(1105)) {
  5.                 // Make sure the JS part of the Heartbeat API is loaded.
  6.                 wp_enqueue_script('heartbeat');
  7.        
  8.                 // Output the test JS in footer.
  9.                 add_action( 'print_footer_scripts', 'heartbeat_test_js', 20 );
  10.                
  11.                 //Add filter to receive hook, and specify we need 2 parameters.
  12.                 add_filter( 'heartbeat_received', 'dw_receive_heartbeat', 10, 2 );
  13.             }
  14.    
  15.     }
  16.     add_action( 'wp_enqueue_scripts', 'heartbeat_test_enqueue' );
  17.    
  18.    
  19.     //clientside
  20.     function heartbeat_test_js() {
  21.             ?>
  22.             <script>
  23.    
  24.             jQuery(document).ready( function($) {
  25.                     // Hook into the heartbeat-send
  26.                     jQuery( document ).on( 'heartbeat-send', function( e, data ) {
  27.                         //
  28.                     });
  29.    
  30.                     // Listen for the custom event "heartbeat-tick" on $(document). This fire's once every minute that the page is open.
  31.                     jQuery(document).on( 'heartbeat-tick', function(e, data) {
  32.                         console.log("tick");
  33.                     });
  34.             });
  35.    
  36.             </script>
  37.             <?php
  38.     }
  39.    
  40.    
  41.     //change heartbeat interval time
  42.     function m_heartbeat_settings( $settings ) {
  43.        $settings['interval'] = 15; //only values between 15 and 60 seconds allowed
  44.        return $settings;
  45.     }
  46.     add_filter( 'heartbeat_settings', 'm_heartbeat_settings' );
  47.    
  48.     //heartbeat api end
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement