=== Heartbeat Manager – Optimize CPU Performance, Fix admin-ajax & Speed Up WordPress ===
Contributors: sonofgod80
Donate link: https://www.paypal.com/donate?hosted_button_id=5MGAYLG6QTUZG
Tags: heartbeat, performance, fix-admin-ajax, reduce-cpu, speed-up
Requires at least: 5.4
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.3
License: GPLv2 or later

Stop high CPU spikes and fix admin-ajax.php slowdowns. Granularly control WordPress Heartbeat frequency to boost backend speed and save hosting costs.

== Description ==

Is your WordPress admin dashboard lagging? Are you getting **High CPU usage warnings** from your hosting provider due to constant `admin-ajax.php` requests? 

By default, the native WordPress Heartbeat API constantly pulses in the background (every 15 to 60 seconds) to handle autosaves and notifications. On high-traffic sites, multi-author blogs, or busy **WooCommerce stores**, this silent stream of background requests can completely saturate your server resources, slowing down your site for both visitors and administrators.

**Heartbeat Manager** is the ultimate lightweight performance solution designed to put an end to server resource waste. It gives you total control over background polling frequencies, allowing you to **save hosting costs**, boost backend speed, and eliminate server crashes.

Unlike aggressive optimization methods that completely disable the heartbeat and break essential features, this plugin allows you to granularly optimize your site's heartbeat frequency zone by zone.

### Key Benefits & Features:

* **Stop Admin Dashboard Lag (Backend Control):** Easily slow down the background poll interval when you are idling in general admin screens (Bacheca, Media Library, Plugins list) to save immense server memory.
* **Isolate Post & Page Editors:** Keep a faster interval (30s or 60s) exclusively while editing posts, pages, or WooCommerce products. This ensures your **Autosaves** and **Post Locking** features work safely without overloading your CPU.
* **Boost Frontend Loading Times:** Completely disable or dilate frontend heartbeat loops. Turning off the heartbeat on public pages eliminates unnecessary AJAX queries for your visitors, making mobile and desktop navigation significantly smoother.
* **Page Builder Friendly:** Fully compatible and optimized for sites built with Elementor, Divi, Gutenberg, and premium WooCommerce setups.
* **Integrated Step-by-Step Vademecum:** Includes a built-in testing guide directly in your admin sidebar so you can visually verify your CPU savings via the browser Developer Tools.
* **Ultra-Lightweight & Clean Code:** Built following the highest WordPress.org security standards with 100% unique prefixing to avoid any plugin conflicts. Fully translation-ready.

== Installation ==

1. Upload the `levelnetwork-heartbeat-manager` folder to the `/wp-content/plugins/` directory, or install it directly via the WordPress Plugins dashboard.
2. Activate the plugin through the 'Plugins' menu in WordPress.
3. Navigate to **Settings > Heartbeat Manager** to instantly optimize your frequencies.

== Frequently Asked Questions ==

= Will disabling the Heartbeat API break my site? =
No, it will not break your site's core layout or design. However, completely disabling it on the frontend might affect real-time updates from specific third-party layout widgets that rely on it (e.g., live notification badges or certain real-time dynamic bidding plugins). If you notice any frontend sync issues, simply change the setting from "Disabled" to 60 or 120 seconds.

= What is the recommended setting for a WooCommerce store? =
For maximum performance under high traffic, we highly recommend setting the Backend interval to 60 or 120 seconds, the Editor frequency to 30 or 60 seconds, and setting the Frontend to "Disabled". This setup drastically reduces the number of background AJAX requests hitting your server while keeping your cart functions stable.

= Why do I get an "Uncaught ReferenceError" or "undefined" error when testing the frontend in the browser console? =
This is completely normal and actually a fantastic sign! WordPress does not load the Heartbeat script on the public frontend by default. If you see this error, it means neither your theme nor any active plugins are running background loops on your public pages. Your frontend is already naturally optimized and completely free of background AJAX hits.

= Will a higher Post/Page Editor interval cause lag or sync issues in my Page Builder? =
No, it won't cause any lag. However, if you increase the interval to the maximum (e.g., 300 seconds), your automatic layout backups (autosaves) will only happen every 5 minutes. If you are actively designing with heavy page builders like Elementor or Divi, we recommend keeping the Editor frequency at 30 or 60 seconds. This gives you the perfect balance between server CPU relief and content safety.

== Screenshots ==

1. The intuitive administrative settings control card panel featuring granular frequency configurations and the integrated step-by-step optimization Vademecum testing guide.

== Changelog ==

= 1.0.3 =
* Fix: Updated the Plugin Vademecum Section 1 to correctly reflect the new Post/Page Editor separation and prevent layout testing confusion.
* Docs: Added a new FAQ regarding high editor intervals, page builders (Elementor, Divi, Gutenberg), and their impact on WordPress autosaves.

= 1.0.2 =
* Tweak: Raised the minimum allowed interval for the Backend Frequency to 30 seconds (previously 15) to prevent accidental server CPU spikes from overly aggressive polling.
* Docs: Updated the Plugin Vademecum & Testing Guide to clarify that frontend testing is only applicable when the theme or another plugin actively enqueues the Heartbeat API.

= 1.0.1 =
* Enhancement: Fully internationalized (i18n ready) with default language set to English.
* Enhancement: Added a comprehensive step-by-step "Plugin Vademecum & Testing Guide" section in the admin sidebar.
* Fix: Completely refactored prefixing to unique `lnhm_` across all constants, options, classes, and variables to ensure 100% compliance with WordPress.org guidelines.
* Fix: Greatly improved logic for handling frontend heartbeat intervals (disabling via inline script, changing frequency via standardized localization).
* Fix: Added missing escaping (`esc_attr`, `esc_html`) and proper sanitization (`intval`) for better security.
* Feature: Added "Settings" and "Donate" links directly beneath the plugin name in the plugins list.
* Dev: Cleaned up CSS and separated layout structures to avoid class name conflicts with WordPress core.

= 1.0.0 =
* Initial release.
* Granular heartbeat control and dedicated UI.

== Upgrade Notice ==

= 1.0.3 =
This version improves the built-in documentation and Vademecum to perfectly align with the new Post/Page Editor isolation feature introduced in recent builds. Recommended for clear testing instructions.

= 1.0.2 =
This update raises the minimum Backend interval to 30 seconds to safeguard your server from CPU spikes and adds essential troubleshooting details for frontend testing.

= 1.0.1 =
This version includes critical security fixes, unique 4+ character prefixing to prevent plugin conflicts, an integrated sidebar testing guide, unique text-domain, and full translation readiness. Highly recommended upgrade.