Stop/Pause WordPress Heartbeat using Javascript

I use the WordPress heartbeat to check a setting on my server from the front-end. If that setting has a specific value I want to stop bothering the server. There for I want to stop/pause the heartbeat. There are no other things depending on the heartbeat. I found wp.heartbeat.stop() over here, but it doesn't work. jQuery(document).ready(function ($) { $(document).on('heartbeat-tick', function (e, data) { [...] if (true == x) { wp.heartbeat.stop(); } [...] } }); I get this error in the …
Category: Web

Why does Wordpress Heartbeat login not refresh the nonces?

Here's an interesting experiment: Go to wordpress plugins listing page, notice the activate, deactivate links all have a nonce part in the request. In a second tab, log out of the site, and go back to plugin listing page. After awhile, the page realizes it's not logged in, and pops up a log in screen. Log in, and click an "activate" or "deactivate" button. Notice it gives the nonce-failure message, "are you sure you want to do this"? Because the …
Category: Web

Content including hooks inside wp-settings.php are being called twice in WordPress

I found that init hook is being called twice and then I try to trace and find out wp-settings.php is also being called twice. I originally want to post a question to find out why. And after some code injection tests. I found out the reason and would like to share here and see if there is anyone have another insight or method or workaround which could avoid the "double calling". And the following is the testing method for finding …
Category: Web

Disabled Heartbeat but i think it's still working. Is there a plugin or script to check it?

I just disabled Heartbeat with the plugin Heartbeat control and also adding this script in function.php of my child-theme add_action( 'init', 'stop_heartbeat', 1 ); function stop_heartbeat() { wp_deregister_script('heartbeat'); } But i think it's still working and some plugin is overriding it. I still have large cpu spike while the site is in mantainance mode. Is there a function or action that i can use to check if this worked ?
Category: Web

Wordpress Heartbeat API cannot parse data

I want to use WP-API heartbeat to open a connection to two displays and have them reflect what the other is saying with each send and tick. It used to work when the heartbeat API came out in 3.6 - but now at the latest version it is outputting an error: SyntaxError: JSON Parse error: Unexpected identifier "SyntaxError" I have tried following other answers on the web to parse the json error or find where it is failing but nothing …
Category: Web

How to create notification on frontend using heartbeat api for multiple custom post types

How can I get correct action hook on publish_posts for multiple custom types ? I have a following problem, I can use this hook for posts or single custom post_type, but I don't know correct hook for multiple custom post types: // Post publication for posts add_filter ( 'publish_post', 'notify_published_post' ); function notify_published_post( $post_id ) { I would like to publish to all even future custom post_types, so I would like to get something like this: // Post publication hook …
Category: Web

How to link Wordpress heartbeat to ajax form

I have a form that $_POSTs an input value, and user's ID that saves the data to the database: // frontend form <form id="form"> <input type="radio" name="location" id="name1" value="1"> <label for="name1">Label 1</label> <input type="radio" name="location" id="name2" value="2"> <label for="name2">Label 2</label> <input type="radio" name="location" id="name3" value="3"> <label for="name3">Label 3</label> <input type="hidden" name="userid" value="{userid}"> </form> // footer script <script> $(function() { $( "#form" ).change(function(a) { a.preventDefault(); var formdata = new FormData($(this)[0]); $.ajax({ method: "POST", data: formdata, contentType: false, processData: false }); }); …
Category: Web

How can change heartbeat hasFocus option to false

After I check heartbeat.js file I found that by default WordPress set heartbeat hasFocuse option to true, I want to change this option to false what can I do? What am I trying to achieve? I have a live notification and messages system working depending on heartbeat.js the problem that if I switch from my site tab to any another tab the heartbeat stop working so I don't receive the messages and notification until I switch to my site again. …
Category: Web

Why is the Ajax heartbeat included in my cached frontend pages? Is it OK to get rid of it?

I recently thought I'd protect a WP site's /wp-admin folder with Apache's basic auth to provide a crude but somewhat effective additional layer of security (as a second line of defense should the WP install accidentally go out of date or an exploit emerge). However when I did this, I immediately noticed that the site's cached front-end pages started showing the authentication dialog, too! This appears to be because the Ajax heartbeat is being included in all the frontend pages: …
Category: Web

Heartbeat API NOT disabling

I’m hoping this is something easy to fix although from my tests (very new to WordPress so please go easy with me if these tests are not very good!) doesn’t appear to be. I have a site hosted on SiteGround which was eating through the CPU seconds like nobody’s business. I’ve now managed to put it down to the Heartbeat API calling the admin-ajax.php file so much. Small question about admin-ajax.php if I may? Am I correct in my thinking …
Category: Web

admin-ajax.php + load-scripts.php hanging for minutes

My issue is that when I do a simple Admin Dashboard change, like updating a post or page, I sometimes wait up to 10 minutes for the request to finish. I have tried restarting the process and my server many times; the only way it works is if I wait all 10 minutes or so for the request to finish. Here is a screen shot of what the error looks like: That error will loop 5-10 times, making it take …
Category: Web

How to disable the "Post Lock/Edit Lock"?

I want to disable this just for one Post Type, as it doesn't really matters if there's another user editing it (the main content editing area is Ajaxified and non-admins can only see that). I looked at the core functions but couldn't find an entry point. From the function wp_set_post_lock I'm guessing that I'd have to intercept the get_post_meta, but is there an official way to do it? And there's a second lock that doesn't seem to be affected by …
Category: Web

Log of Heartbeat Calls

I've read that Heartbeat can slow a WP site down and I'm assuming if our admins/store managers have a lot of admin windows/tabs open, this will exacerbate the issue. If yes, is there a condition to test and log the calls that Heartbeat makes so I can see if the site slowdown could be related to an excess of Heartbeat calls? I had a look in the documentation and elsewhere but only found ways to deregister the script ( wp_deregister_script('heartbeat'); …
Category: Web

Bruteforce attack from 127.0.0.1?

I've got a very strange problem. Actually my server is being attacked by a brute force on wp-login.php. But when I look into the access log file I see that it's from 127.0.0.1... www.*.fr:80 127.0.0.1 - - [29/Apr/2015:18:23:01 +0200] "POST /wp-login.php HTTP/1.0" 200 6254 "-" "-" www.*.fr:80 127.0.0.1 - - [29/Apr/2015:18:23:01 +0200] "POST /wp-login.php HTTP/1.0" 200 6254 "-" "-" www.*.fr:80 127.0.0.1 - - [29/Apr/2015:18:23:01 +0200] "POST /wp-login.php HTTP/1.0" 200 6254 "-" "-" www.*.fr:80 127.0.0.1 - - [29/Apr/2015:18:23:01 +0200] "POST /wp-login.php …
Category: Web

CPU usage: AJAX and Heartbeat API on admin pages

My (shared) web host recently sent me this: "Our server monitoring systems keep indicating high server load persistently maintained by your website (...). Most of the hits are to the /www/www/wp-admin/admin-ajax.php script. We would advise the following: Do not stay logged into the WordPress dashboard through the day. Once you finish your work, you should log out. If you stay logged in and keep the browser window open, WordPress will keep generating hits to admin-ajax.php. ..." When I asked them …
Category: Web

Heartbeat API long polling

I recently noticed that in Heartbeat API js client there was added option for speed of ticks called "long polling" with 0 interval. I pretty much understand what they try to achieve but I'm confused about how to implement plugin using this feature. For now every time my server received request from browser, hook was fired, data queried, response created and sent back to client. But with 0 interval, I should actually wait in my hook for some event being …
Category: Web

Heartbeat API: How to access data already enqueued?

I'm having problems when trying to access data that I've queued using the Heartbeat API. I'm queuing data using wp.heartbeat.enqueue(). For example: var data = { my_key: 'value' }; wp.heartbeat.enqueue( 'my_handle', data, false ); Then later on in my script, I'd like to access the data I've queued. For example: $( document ).on( 'click', '#button', function() { // Here, I want to access the data I've enqueued. }); I've tried doing the following but that doesn't work: $( document ).on( …
Category: Web

How to check if new posts have been published since page load?

My aim is to use the Heartbeat API to check if new posts have been published since the blog's homepage was loaded. If new posts have been published, I will display a link at the top of the screen "16 new posts" which, when clicked, will insert the new posts into the DOM. My problem: How can I check if new posts have been published since the blog's homepage was loaded? My PHP so far: function new_post_check( $response, $data, $screen_id …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.