forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollaboration.php
More file actions
72 lines (66 loc) · 1.64 KB
/
collaboration.php
File metadata and controls
72 lines (66 loc) · 1.64 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
<?php
/**
* Bootstraps collaborative editing.
*
* @package WordPress
* @since 7.0.0
*/
/**
* Checks whether real-time collaboration is enabled.
*
* The feature requires both the site option and the database schema
* introduced in db_version 61699.
*
* @since 7.0.0
*
* @return bool True if collaboration is enabled, false otherwise.
*/
function wp_is_collaboration_enabled() {
return get_option( 'wp_enable_real_time_collaboration' )
&& get_option( 'db_version' ) >= 61699;
}
/**
* Injects the real-time collaboration setting into a global variable.
*
* @since 7.0.0
*
* @access private
*/
function wp_collaboration_inject_setting() {
if ( wp_is_collaboration_enabled() ) {
wp_add_inline_script(
'wp-core-data',
'window._wpCollaborationEnabled = true;',
'after'
);
}
}
/**
* Deletes stale collaboration data from the collaboration table.
*
* Removes collaboration rows older than 7 days and awareness rows older than
* 60 seconds. Rows left behind by abandoned collaborative editing sessions
* are cleaned up to prevent unbounded table growth.
*
* @since 7.0.0
*/
function wp_delete_old_collaboration_data() {
if ( ! wp_is_collaboration_enabled() ) {
return;
}
global $wpdb;
// Clean up collaboration rows older than 7 days.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->collaboration} WHERE created_at < %s",
gmdate( 'Y-m-d H:i:s', time() - WEEK_IN_SECONDS )
)
);
// Clean up awareness rows older than 60 seconds (2× the 30-second awareness timeout as a buffer).
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->awareness} WHERE created_at < %s",
gmdate( 'Y-m-d H:i:s', time() - 60 )
)
);
}