heartbeat simply doesn’t work
-
following the exact steps in the heartbeat official documentation doesn’t simply work.
and that’s super frusturating.
here is what I did in case someone is trying to reproduce the problem and see it yourself:
simply created 3 files in wp-content/plugins
test.php<?php // Plugin Name: test add_action("admin_menu","f_admin_menu"); function f_admin_menu(){ add_menu_page("title_123","test_menu_123","manage_options","admin_menu_123",'f_menu_page'); } function f_menu_page(){ wp_register_script("jQuery","https://code.jquery.com/jquery-3.5.1.min.js"); wp_register_script('all_script',plugin_dir_url(__FILE__) . 'all_script.js'); wp_enqueue_script('jQuery'); wp_enqueue_script('all_script'); include_once('admin_menu_123.php'); } function myplugin_receive_heartbeat( $response, $data ) { $response['myplugin_customfield_hashed'] = sha1( $data['myplugin_customfield'] ); return $response; } add_filter( 'heartbeat_received', 'myplugin_receive_heartbeat', 10, 2 ); ?>
all_script.js
$(document).ready(function(){ $(document).on( 'heartbeat-send', function ( event, data ) { console.log('pulse sent') data.myplugin_customfield = 'some_data'; }); $(document).on( 'heartbeat-tick', function ( event, data ) { alert( 'The hash is ' + data.myplugin_customfield_hashed ); }); })
admin_menu_123.php
<?php ?> <input type="button" value="click">
my wordpress details:
latest version 5.5.1 hosted in my local wamp in a win10 64bits if that matters (even though am sure it doesn’t but someone will ask saying it\s the problem)
what I expect:
what is already obvious, a log in my console saying that i at least simply sent an AJAX heartbeat to serverside.
what happens: NOTHING.
again: this code is copied from the OFFICIAL documentation pageThe page I need help with: [log in to see the link]
- The topic ‘heartbeat simply doesn’t work’ is closed to new replies.