templates for self-hosting game jams (or any other kind of jam tbh)
1<?php
2
3namespace App\View\Composers;
4
5use Roots\Acorn\View\Composer;
6
7class Comments extends Composer
8{
9 /**
10 * List of views served by this composer.
11 *
12 * @var array
13 */
14 protected static $views = [
15 'partials.comments',
16 ];
17
18 /**
19 * The comment title.
20 */
21 public function title(): string
22 {
23 return sprintf(
24 /* translators: %1$s is replaced with the number of comments and %2$s with the post title */
25 _nx('%1$s response to “%2$s”', '%1$s responses to “%2$s”', get_comments_number(), 'comments title', 'sage'),
26 get_comments_number() === 1 ? _x('One', 'comments title', 'sage') : number_format_i18n(get_comments_number()),
27 get_the_title()
28 );
29 }
30
31 /**
32 * Retrieve the comments.
33 */
34 public function responses(): ?string
35 {
36 if (! have_comments()) {
37 return null;
38 }
39
40 return wp_list_comments([
41 'style' => 'ol',
42 'short_ping' => true,
43 'echo' => false,
44 ]);
45 }
46
47 /**
48 * The previous comments link.
49 */
50 public function previous(): ?string
51 {
52 if (! get_previous_comments_link()) {
53 return null;
54 }
55
56 return get_previous_comments_link(
57 __('← Older comments', 'sage')
58 );
59 }
60
61 /**
62 * The next comments link.
63 */
64 public function next(): ?string
65 {
66 if (! get_next_comments_link()) {
67 return null;
68 }
69
70 return get_next_comments_link(
71 __('Newer comments →', 'sage')
72 );
73 }
74
75 /**
76 * Determine if the comments are paginated.
77 */
78 public function paginated(): bool
79 {
80 return get_comment_pages_count() > 1 && get_option('page_comments');
81 }
82
83 /**
84 * Determine if the comments are closed.
85 */
86 public function closed(): bool
87 {
88 return ! comments_open() && get_comments_number() != '0' && post_type_supports(get_post_type(), 'comments');
89 }
90}