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-comment-file.php

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

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