Created
October 10, 2024 04:32
-
-
Save apermo/bc736d41f6ac9cd0a0605c609b41d992 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'heartbeat_settings', 'filter_heartbeat', 10, 1 ); | |
/** | |
* Filter the heartbeat interval based on the current request. | |
* | |
* Called on the 'heartbeat_settings' filter. | |
* | |
* @param array $settings The Heartbeat settings. By Default an empty array. | |
* | |
* Credits: Ideas used from https://wordpress.org/plugins/heartbeat-control/ | |
*/ | |
function filter_heartbeat( array $settings ): array { | |
$request_uri = filter_var( $_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL ); | |
if ( str_contains( $request_uri, '/wp-admin/post.php' ) ) { | |
// In the editor. | |
$interval = 60; | |
} elseif ( is_admin() ) { | |
// In the admin panel. | |
$interval = 180; | |
} else { | |
// In the frontend. | |
$interval = 3600; | |
} | |
$settings['interval'] = $interval; | |
return $settings; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment