Skip to content

Instantly share code, notes, and snippets.

@JPry
Last active April 13, 2023 16:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save JPry/b1f6c55a5d5337557f97 to your computer and use it in GitHub Desktop.
Save JPry/b1f6c55a5d5337557f97 to your computer and use it in GitHub Desktop.
Note that you must change "plugins.php" to match whatever page you want to allow.
<?php
/**
* Plugin Name: Allow Heartbeat on more pages
* Plugin URI: https://gist.github.com/JPry/b1f6c55a5d5337557f97
* Description: Allow the Heartbeat API on more pages in the Dashboard
* Version: 1.0
* Author: Jeremy Pry
* Author URI: http://jeremypry.com/
* License: GPL2
*/
// Prevent direct access to this file
if ( ! defined( 'ABSPATH' ) ) {
die( "You can't do anything by accessing this file directly." );
}
add_filter( 'wpe_heartbeat_allowed_pages', 'jpry_add_allowed_page' );
/**
* Add a page to the list of pages where the Heartbeat API is allowed.
*
* Replace plugins.php with the actual page name. The page name correlates to the global $pagenow variable.
* See http://codex.wordpress.org/Global_Variables#Admin_Globals for more information about this
* global variable.
*
* @param array $heartbeat_allowed_pages The array of pages where the Heartbeat API is allowed.
* @return array The updated array of pages where the Heartbeat API is allowed.
*/
function jpry_add_allowed_page( $heartbeat_allowed_pages ) {
$heartbeat_allowed_pages[] = 'plugins.php';
return $heartbeat_allowed_pages;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment