comments.php
3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* View: Focus Mode Comments.
*
* @since 4.6.0
* @version 4.6.0
*
* @var int $approved_comments_number Number of approved comments.
* @var Course_Step $model Course step model.
* @var WP_User $user User.
* @var Template $this Template instance.
*
* @package LearnDash\Core
*
* cSpell:ignore replytocom
*/
/** NOTICE: This code is currently under development and may not be stable.
* Its functionality, behavior, and interfaces may change at any time without notice.
* Please refrain from using it in production or other critical systems.
* By using this code, you assume all risks and liabilities associated with its use.
* Thank you for your understanding and cooperation.
**/
use LearnDash\Core\Models\Interfaces\Course_Step;
use LearnDash\Core\Template\Template;
if ( post_password_required() ) {
return;
}
// TODO: Split into smaller files.
// This filter is documented in themes/ld30/templates/focus/index.php.
if ( ! apply_filters( 'learndash_focus_mode_show_existing_comments', false ) && ! comments_open() ) {
return;
}
?>
<div class="ld-focus-comments">
<?php if ( $approved_comments_number > 0 && ! isset( $_GET['replytocom'] ) ) : ?>
<div class="ld-focus-comments__heading">
<div class="ld-focus-comments__header">
<?php
printf(
esc_html(
// translators: single approved comment, multiple approved comments.
_nx( '%s Comment', '%s Comments', $approved_comments_number, 'comments', 'learndash' )
),
esc_html( number_format_i18n( $approved_comments_number ) )
);
?>
</div>
<div class="ld-focus-comments__heading-actions">
<div
class="ld-expand-button ld-button-alternate ld-expanded"
id="ld-expand-button-comments"
data-ld-expands="ld-comments"
data-ld-expand-text="<?php esc_html_e( 'Expand Comments', 'learndash' ); ?>"
data-ld-collapse-text="<?php esc_html_e( 'Collapse Comments', 'learndash' ); ?>"
>
<span class="ld-text">
<?php esc_html_e( 'Collapse Comments', 'learndash' ); ?>
</span>
<?php $this->template( 'components/icons/arrow-down' ); ?>
</div>
</div>
</div>
<?php endif; ?>
<div class="ld-focus-comments__comments ld-expanded" id="ld-comments" data-ld-expand-id="ld-comments">
<div class="ld-focus-comments__comments-items" id="ld-comments-wrapper">
<?php
// If comments are open, or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {
// Add filter to direct comments to our template.
add_filter(
'comments_template',
function( $theme_template = '' ) {
$theme_template_alt = SFWD_LMS::get_template(
'focus/comments_list.php',
null,
null,
true
);
if ( ! empty( $theme_template_alt ) ) {
$theme_template = $theme_template_alt;
}
return $theme_template;
},
999,
1
);
comments_template();
if ( ! isset( $_GET['replytocom'] ) ) {
the_comments_navigation();
}
}
?>
</div>
</div>
<?php if ( 0 === $approved_comments_number ) : ?>
<div class="ld-expand-button ld-button-alternate" id="ld-comments-post-button">
<?php $this->template( 'components/icons/arrow-down' ); ?>
<span class="ld-text">
<?php esc_html_e( 'Post a comment', 'learndash' ); ?>
</span>
</div>
<?php endif; ?>
<div
class="ld-focus-comments__form-container<?php echo esc_attr( 0 === $approved_comments_number ? ' ld-collapsed' : '' ); ?>"
id="ld-comments-form"
>
<?php
comment_form(
// This filter is documented in themes/ld30/templates/focus/comments.php.
apply_filters(
'learndash_focus_mode_comment_form_args',
array(
'title_reply' => esc_html__( 'Leave a Comment', 'learndash' ),
)
)
);
?>
</div>
</div>