Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function wp_presence_admin_bar_node( $wp_admin_bar ) {
return;
}

$entries = wp_get_presence( 'admin/online' );
$entries = wp_get_presence( wp_presence_admin_room() );
$current_uid = get_current_user_id();

// Only show the admin bar node when other users are online.
Expand Down
12 changes: 11 additions & 1 deletion includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
/**
* Presence API functions.
*
* Public API (6 functions):
* Public API (7 functions):
* wp_get_presence()
* wp_set_presence()
* wp_remove_presence()
* wp_remove_user_presence()
* wp_can_access_presence_room()
* wp_presence_post_room()
* wp_presence_admin_room()
*
* @package Presence_API
*/
Expand Down Expand Up @@ -197,6 +198,15 @@ function wp_presence_post_room( $post ) {
return 'postType/' . $post->post_type . ':' . $post->ID;
}

/**
* Returns the presence room identifier for the admin "who's online" list.
*
* @return string The room identifier.
*/
function wp_presence_admin_room() {
return 'admin/online';
}

/*
*
* The following functions are used by the plugin's widgets, CLI, REST
Expand Down
6 changes: 3 additions & 3 deletions includes/heartbeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function wp_presence_enqueue_heartbeat_ping() {
// Every page where the ping is enqueued occupies the admin/online room.
$entries = array(
array(
'room' => 'admin/online',
'room' => wp_presence_admin_room(),
'client_id' => 'user-' . $user_id,
),
);
Expand Down Expand Up @@ -100,7 +100,7 @@ function wp_presence_enqueue_heartbeat_ping() {
$admin_state['post_id'] = $front_context['post_id'];
}
}
wp_set_presence( 'admin/online', 'user-' . $user_id, $admin_state, $user_id );
wp_set_presence( wp_presence_admin_room(), 'user-' . $user_id, $admin_state, $user_id );

if ( $editor_post_id ) {
$editor_room = wp_presence_post_room( $editor_post_id );
Expand Down Expand Up @@ -307,7 +307,7 @@ function wp_presence_admin_heartbeat_received( $response, $data, $screen_id ) {
}
}

wp_set_presence( 'admin/online', 'user-' . $user_id, $state, $user_id );
wp_set_presence( wp_presence_admin_room(), 'user-' . $user_id, $state, $user_id );

return $response;
}
Expand Down
2 changes: 1 addition & 1 deletion includes/lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function wp_presence_on_login( $user_login, $user ) {
}

wp_set_presence(
'admin/online',
wp_presence_admin_room(),
'user-' . $user->ID,
array(
'screen' => 'login',
Expand Down
4 changes: 2 additions & 2 deletions includes/user-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function wp_presence_users_views( $views ) {
return $views;
}

$entries = wp_get_presence( 'admin/online' );
$entries = wp_get_presence( wp_presence_admin_room() );
$online_ids = array_map( 'intval', array_unique( wp_list_pluck( $entries, 'user_id' ) ) );
$current_user_id = get_current_user_id();

Expand Down Expand Up @@ -71,7 +71,7 @@ function wp_presence_filter_online_users( $query ) {
return;
}

$entries = wp_get_presence( 'admin/online' );
$entries = wp_get_presence( wp_presence_admin_room() );
$online_ids = array_map( 'intval', array_unique( wp_list_pluck( $entries, 'user_id' ) ) );
$current_user_id = get_current_user_id();

Expand Down
11 changes: 2 additions & 9 deletions includes/widgets/class-wp-presence-widget-whos-online.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
*/
class WP_Presence_Widget_Whos_Online {

/**
* The presence room used by this widget.
*
* @var string
*/
const ROOM = 'admin/online';

/**
* Maximum number of users shown as full rows before collapsing.
*
Expand Down Expand Up @@ -572,7 +565,7 @@ private static function render_user_row( $entry, $user ) {
* Renders the dashboard widget.
*/
public static function render() {
$entries = wp_get_presence( self::ROOM );
$entries = wp_get_presence( wp_presence_admin_room() );
$current_uid = get_current_user_id();
$entries = array_values(
array_filter(
Expand Down Expand Up @@ -701,7 +694,7 @@ public static function heartbeat_received( $response, $data, $screen_id ) { // p
return $response;
}

$entries = wp_get_presence( self::ROOM );
$entries = wp_get_presence( wp_presence_admin_room() );
$online = array();

cache_users( wp_list_pluck( $entries, 'user_id' ) );
Expand Down
Loading