PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 0.9.1
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v0.9.1
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-desktop-mode-user-file.php

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

73 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Desktop Mode — `user` file type.
4 *
5 * @package WPDesktopMode
6 * @since 0.9.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * @since 0.9.0
13 */
14 class Desktop_Mode_User_File extends Desktop_Mode_File {
15
16 public static function type(): string {
17 return 'user';
18 }
19
20 public function exists(): bool {
21 return $this->user() instanceof WP_User;
22 }
23
24 public function title(): string {
25 $user = $this->user();
26 if ( ! $user ) {
27 return __( '(missing user)', 'desktop-mode' );
28 }
29 return (string) $user->display_name;
30 }
31
32 public function icon(): string {
33 return 'dashicons-admin-users';
34 }
35
36 public function preview_url(): string {
37 $user = $this->user();
38 if ( ! $user ) {
39 return '';
40 }
41 $avatar = get_avatar_url( $user->ID, array( 'size' => 96 ) );
42 return is_string( $avatar ) ? $avatar : '';
43 }
44
45 public function can_read( int $user_id ): bool {
46 // Reading the existence of another user is gated on
47 // `list_users` to avoid leaking the user roster via shared
48 // folders. Tighter than `read` (every logged-in user has
49 // `read`) but looser than `edit_users`.
50 return user_can( $user_id, 'list_users' );
51 }
52
53 public function serialize(): array {
54 $shape = parent::serialize();
55 $user = $this->user();
56 $shape['roles'] = $user ? array_values( (array) $user->roles ) : array();
57 // Author archive URL — surfaced so cross-frame drag handlers
58 // can build a `<a href>` to the author's posts on drop into
59 // Gutenberg without a REST roundtrip.
60 $shape['link'] = $user ? (string) get_author_posts_url( (int) $user->ID ) : '';
61 return $shape;
62 }
63
64 private function user(): ?WP_User {
65 $id = (int) $this->ref;
66 if ( $id <= 0 ) {
67 return null;
68 }
69 $user = get_userdata( $id );
70 return $user instanceof WP_User ? $user : null;
71 }
72 }
73