Skip to content

Commit cf9185f

Browse files
committed
Added ability to change or disable WordPress heartbeat
1 parent 60b33de commit cf9185f

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### master
44

55
- Fixed: Firing sequence of `common_toolkit_loaded` hook
6+
- Added: Ability to modify or disable WordPress heartbeat
67
- Added: `ctk_environment` filter
78
- Added: Ability to disable WordPress search
89
- Added: Ability to define custom environment constant

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ All variables are optional.
3232
| `environment` | Environment of current instance (ex: 'production', 'development', 'staging') | string | "production" |
3333
| `environment_constant` | Constant used to determine environment, environmental variable name for `getenv()`. | string | "WP_ENV" |
3434
| `environment_production` | The label used to match if production environment. | string | "production" |
35+
| `admin_bar_color` | Change admin bar color in current environment | string | _null_ |
3536
| `disable_emojis` | Remove support for emojis | bool | false |
3637
| `disable_search` | Disable WordPress site search | bool | false |
37-
| `admin_bar_color` | Change admin bar color in current environment | string | _null_ |
38-
| `script_attributes` | Enable support for [additional attributes](#add-attributes-to-enqueued-scripts) to script tags via wp_enqueue_script() | bool | flase |
39-
| `shortcodes` | Enable custom [shortcodes](#shortcodes) created by this class | bool | false |
4038
| `disable_xmlrpc` | Disable XML-RPC | bool | false |
39+
| `feed_links` | Include RSS feed links in page head | bool | true |
40+
| `heartbeat` | Modify or disable the WordPress heartbeat. Set to integer to change, `false` to disable | bool/int | null |
4141
| `meta_generator` | Enable or change meta generator tags in page head and RSS feeds | bool/string | true |
42+
| `script_attributes` | Enable support for [additional attributes](#add-attributes-to-enqueued-scripts) to script tags via wp_enqueue_script() | bool | flase |
43+
| `shortcodes` | Enable custom [shortcodes](#shortcodes) created by this class | bool | false |
4244
| `windows_live_writer` | Enable [Windows Live Writer](https://is.gd/Q6KjEQ) support | bool | true |
43-
| `feed_links` | Include RSS feed links in page head | bool | true |
4445

4546
### Example
4647

common-toolkit.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static function init() {
4444
'disable_search' => false,
4545
'disable_xmlrpc' => false,
4646
'feed_links' => true,
47+
'heartbeat' => null,
4748
'meta_generator' => true,
4849
'script_attributes' => false,
4950
'shortcodes' => false,
@@ -69,6 +70,13 @@ public static function init() {
6970
'is_production' => defined( self::get_config( 'common_toolkit/environment_constant' ) ) ? self::get_config( 'common_toolkit/environment_production' ) == getenv( self::get_config( 'common_toolkit/environment_constant' ) ) : true
7071
];
7172

73+
// Modify or disable WordPress heartbeat
74+
if( self::get_config( 'common_toolkit/heartbeat' ) === false ) { // Disable heartbeat
75+
add_action( 'init', function() { wp_deregister_script( 'heartbeat' ); }, 1 );
76+
} else if( intval( self::get_config( 'common_toolkit/heartbeat' ) ) ) { // Modify heartbeat
77+
add_action( 'heartbeat_settings', array( self::$instance, 'modify_heartbeat' ) );
78+
}
79+
7280
// Disable emoji support
7381
if( self::get_config( 'common_toolkit/disable_emojis' ) ) add_action( 'init', array( self::$instance, 'disable_emojis' ) );
7482

@@ -366,6 +374,22 @@ public static function set_default_atts( $pairs, $atts ) {
366374

367375
}
368376

377+
/*
378+
* Modify the WordPress heartbeat
379+
*
380+
* @since 0.8.0
381+
* @see https://codex.wordpress.org/Function_Reference/wp_heartbeat_settings
382+
*/
383+
public function modify_heartbeat( $settings ) {
384+
385+
$heartbeat = intval( self::get_config( 'common_toolkit/heartbeat' ) );
386+
if( !$heartbeat ) return $settings;
387+
388+
$settings['interval'] = $heartbeat;
389+
return $settings;
390+
391+
}
392+
369393
/*
370394
* Remove or modify meta generator tag.
371395
*

sample-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"disable_search": false,
99
"disable_xmlrpc": false,
1010
"feed_links": true,
11+
"heartbeat": null,
1112
"meta_generator": "Atari 2600",
1213
"script_attributes": true,
1314
"shortcodes": false,

0 commit comments

Comments
 (0)