-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheartbeat-control.php
More file actions
102 lines (94 loc) · 3.17 KB
/
Copy pathheartbeat-control.php
File metadata and controls
102 lines (94 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* Heartbeat API Control
*
* Control WordPress Heartbeat API frequency or disable it entirely
* in three independent contexts: Admin, Frontend, and Post Editor.
*
* @package RefiTune
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$refitune_heartbeat_settings = get_option( 'refitune_settings', array() );
// ============================================================================
// 1. ADMIN HEARTBEAT (Dashboard and other admin pages, NOT post editor)
// ============================================================================
$admin_value = isset( $refitune_heartbeat_settings['heartbeat_admin'] ) ? $refitune_heartbeat_settings['heartbeat_admin'] : '';
if ( 'disable' === $admin_value ) {
add_action(
'admin_enqueue_scripts',
static function ( $hook ) {
global $pagenow;
// Csak akkor deregisztráljuk ha NEM post editor.
if ( ! in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) {
wp_deregister_script( 'heartbeat' );
}
}
);
} elseif ( '' !== $admin_value && is_numeric( $admin_value ) ) {
add_filter(
'heartbeat_settings',
static function ( $settings ) use ( $admin_value ) {
global $pagenow;
// Csak admin oldalakra alkalmazzuk, post editorra nem.
if ( is_admin() && ! in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) {
$settings['interval'] = (int) $admin_value;
}
return $settings;
}
);
}
// ============================================================================
// 2. FRONTEND HEARTBEAT
// ============================================================================
$frontend_value = isset( $refitune_heartbeat_settings['heartbeat_frontend'] ) ? $refitune_heartbeat_settings['heartbeat_frontend'] : '';
if ( 'disable' === $frontend_value ) {
add_action(
'init',
static function (): void {
if ( ! is_admin() ) {
wp_deregister_script( 'heartbeat' );
}
},
1
);
} elseif ( '' !== $frontend_value && is_numeric( $frontend_value ) ) {
add_filter(
'heartbeat_settings',
static function ( $settings ) use ( $frontend_value ) {
if ( ! is_admin() ) {
$settings['interval'] = (int) $frontend_value;
}
return $settings;
}
);
}
// ============================================================================
// 3. POST EDITOR HEARTBEAT (Gutenberg + Classic Editor)
// ============================================================================
$editor_value = isset( $refitune_heartbeat_settings['heartbeat_editor'] ) ? $refitune_heartbeat_settings['heartbeat_editor'] : '';
if ( 'disable' === $editor_value ) {
add_action(
'admin_enqueue_scripts',
static function ( $hook ) {
global $pagenow;
// Csak post editor oldalakon deregisztráljuk.
if ( in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) {
wp_deregister_script( 'heartbeat' );
}
}
);
} elseif ( '' !== $editor_value && is_numeric( $editor_value ) ) {
add_filter(
'heartbeat_settings',
static function ( $settings ) use ( $editor_value ) {
global $pagenow;
// Csak post editor oldalakon alkalmazzuk.
if ( is_admin() && in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) {
$settings['interval'] = (int) $editor_value;
}
return $settings;
}
);
}