PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 0.8.9
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v0.8.9
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-comment-file.php

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

68 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Desktop Mode — `comment` 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_Comment_File extends Desktop_Mode_File {
15
16 public static function type(): string {
17 return 'comment';
18 }
19
20 public function exists(): bool {
21 return $this->comment() instanceof WP_Comment;
22 }
23
24 public function title(): string {
25 $c = $this->comment();
26 if ( ! $c ) {
27 return __( '(missing comment)', 'desktop-mode' );
28 }
29 $author = '' !== $c->comment_author ? $c->comment_author : __( 'Anonymous', 'desktop-mode' );
30 $excerpt = wp_trim_words( wp_strip_all_tags( $c->comment_content ), 8, '' );
31 return sprintf( '%s — %s', $author, $excerpt );
32 }
33
34 public function icon(): string {
35 return 'dashicons-admin-comments';
36 }
37
38 public function can_read( int $user_id ): bool {
39 $c = $this->comment();
40 if ( ! $c ) {
41 return false;
42 }
43 // Approved comments are public; non-approved gated on
44 // moderation cap.
45 if ( '1' === (string) $c->comment_approved ) {
46 return true;
47 }
48 return user_can( $user_id, 'moderate_comments' );
49 }
50
51 public function serialize(): array {
52 $shape = parent::serialize();
53 $c = $this->comment();
54 $shape['postId'] = $c ? (int) $c->comment_post_ID : 0;
55 $shape['approved'] = $c ? '1' === (string) $c->comment_approved : false;
56 return $shape;
57 }
58
59 private function comment(): ?WP_Comment {
60 $id = (int) $this->ref;
61 if ( $id <= 0 ) {
62 return null;
63 }
64 $c = get_comment( $id );
65 return $c instanceof WP_Comment ? $c : null;
66 }
67 }
68