Gets awareness state for a given room.
Parameters
$roomstringrequired- Room identifier.
Source
public function get_awareness_state( string $room ): array {
global $wpdb;
$post_id = $this->get_storage_post_id( $room );
if ( null === $post_id ) {
return array();
}
// Use direct database operation to avoid updating the post meta cache.
// ORDER BY meta_id DESC ensures the latest row wins if duplicates exist
// from a past race condition in set_awareness_state().
$meta_value = $wpdb->get_var(
$wpdb->prepare(
"SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s ORDER BY meta_id DESC LIMIT 1",
$post_id,
self::AWARENESS_META_KEY
)
);
if ( null === $meta_value ) {
return array();
}
$awareness = json_decode( $meta_value, true );
if ( ! is_array( $awareness ) ) {
return array();
}
return array_values( $awareness );
}
Changelog
| Version | Description |
|---|---|
| 7.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.