PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.0.0
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.0.0
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
desktop-mode / includes / desktop-files / types / class-openstation-user-file.php

class-openstation-user-file.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.0.0, at includes/desktop-files/types/class-openstation-user-file.php

103 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — `user` file type.
4 *
5 * @package OpenStation
6 */
7
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * The `user` desktop file type.
12 */
13 class OpenStation_User_File extends OpenStation_File {
14
15 public static function type(): string {
16 return 'user';
17 }
18
19 public function exists(): bool {
20 return $this->user() instanceof WP_User;
21 }
22
23 public function title(): string {
24 $user = $this->user();
25 if ( ! $user ) {
26 return __( '(missing user)', 'desktop-mode' );
27 }
28 return (string) $user->display_name;
29 }
30
31 public function icon(): string {
32 return 'dashicons-admin-users';
33 }
34
35 public function preview_url(): string {
36 $user = $this->user();
37 if ( ! $user ) {
38 return '';
39 }
40 $avatar = get_avatar_url( $user->ID, array( 'size' => 96 ) );
41 return is_string( $avatar ) ? $avatar : '';
42 }
43
44 public function can_read( int $user_id ): bool {
45 // Reading the existence of another user is gated on
46 // `list_users` to avoid leaking the user roster via shared
47 // folders. Tighter than `read` (every logged-in user has
48 // `read`) but looser than `edit_users`.
49 return user_can( $user_id, 'list_users' );
50 }
51
52 public function serialize(): array {
53 $shape = parent::serialize();
54 $user = $this->user();
55 $shape['roles'] = $user ? array_values( (array) $user->roles ) : array();
56 // Author archive URL — surfaced so cross-frame drag handlers
57 // can build a `<a href>` to the author's posts on drop into
58 // Gutenberg without a REST roundtrip.
59 $shape['link'] = $user ? (string) get_author_posts_url( (int) $user->ID ) : '';
60
61 // OpenStation agent surface. `isAgent` marks the tile; the
62 // drag-trigger entity kinds ship inline so the tile drop
63 // handler can gate synchronously without an agents REST
64 // roundtrip: null = no drag trigger configured (tile rejects
65 // drops), [] = drag trigger with no filter (accepts every
66 // entity kind). Guarded — the agents module is behind the
67 // `agents` extended option.
68 if (
69 $user
70 && function_exists( 'openstation_agent_is_agent' )
71 && openstation_agent_is_agent( $user->ID )
72 ) {
73 $shape['isAgent'] = true;
74 // The "when to use" line — the chat window's subtitle when
75 // the tile opener starts a conversation.
76 $shape['agentDescription'] = openstation_agent_get_description( (int) $user->ID );
77 $drag_kinds = null;
78 foreach ( openstation_agent_get_triggers( (int) $user->ID ) as $trigger ) {
79 if ( 'drag' !== ( isset( $trigger['kind'] ) ? $trigger['kind'] : '' ) ) {
80 continue;
81 }
82 $kinds = isset( $trigger['config']['entityKinds'] ) && is_array( $trigger['config']['entityKinds'] )
83 ? $trigger['config']['entityKinds']
84 : array();
85 $drag_kinds = array_values( array_map( 'strval', $kinds ) );
86 break;
87 }
88 $shape['agentDragKinds'] = $drag_kinds;
89 }
90
91 return $shape;
92 }
93
94 private function user(): ?WP_User {
95 $id = (int) $this->ref;
96 if ( $id <= 0 ) {
97 return null;
98 }
99 $user = get_userdata( $id );
100 return $user instanceof WP_User ? $user : null;
101 }
102 }
103