/
class-writemore-comment-walker.php
177 lines (158 loc) · 5.83 KB
/
class-writemore-comment-walker.php
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
class Writemore_Comment_Walker extends Walker_Comment {
/**
* Starts the element output.
*
* This was forked from WordPress 5.3.2.
*
* @since 1.1.0
* @since WordPress 2.7.0
*
* @see Walker::start_el()
* @see wp_list_comments()
* @global int $comment_depth
* @global WP_Comment $comment Global comment object.
*
* @param string $output Used to append additional content. Passed by reference.
* @param WP_Comment $comment Comment data object.
* @param int $depth Optional. Depth of the current comment in reference to parents. Default 0.
* @param array $args Optional. An array of arguments. Default empty array.
* @param int $id Optional. ID of the current comment. Default 0 (unused).
*/
public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
$depth++;
$GLOBALS['comment_depth'] = $depth;
$GLOBALS['comment'] = $comment;
if ( ! empty( $args['callback'] ) ) {
ob_start();
call_user_func( $args['callback'], $comment, $args, $depth );
$output .= ob_get_clean();
return;
}
if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {
ob_start();
$this->ping( $comment, $depth, $args );
$output .= ob_get_clean();
} elseif ( 'html5' === $args['format'] ) {
ob_start();
$this->html5_comment( $comment, $depth, $args );
$output .= ob_get_clean();
} else {
ob_start();
$this->comment( $comment, $depth, $args );
$output .= ob_get_clean();
}
}
/**
* Ends the element output, if needed.
*
* This was forked from WordPress 5.3.2.
*
* @since 1.1.0
* @since WordPress 2.7.0
*
* @see Walker::end_el()
* @see wp_list_comments()
*
* @param string $output Used to append additional content. Passed by reference.
* @param WP_Comment $comment The current comment object. Default current comment.
* @param int $depth Optional. Depth of the current comment. Default 0.
* @param array $args Optional. An array of arguments. Default empty array.
*/
public function end_el( &$output, $comment, $depth = 0, $args = array() ) {
if ( ! empty( $args['end-callback'] ) ) {
ob_start();
call_user_func( $args['end-callback'], $comment, $args, $depth );
$output .= ob_get_clean();
return;
}
$output .= "</div><!-- #comment-## -->\n";
}
/**
* Outputs a comment in the HTML5 format.
*
* This was forked from WordPress 5.3.2.
*
* @since 1.1.0
* @since WordPress 3.6.0
*
* @see wp_list_comments()
*
* @param WP_Comment $comment Comment to display.
* @param int $depth Depth of the current comment.
* @param array $args An array of arguments.
*/
protected function html5_comment( $comment, $depth, $args ) {
$commenter = wp_get_current_commenter();
if ( $commenter['comment_author_email'] ) {
$moderation_note = __( 'Your comment is awaiting moderation.' );
} else {
$moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.' );
}
$url = get_comment_meta( $comment->comment_ID, 'webmention_source_url', true );
if ( '' === $url ) {
$url = get_comment_link( $comment, $args );
}
$author_url = get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_author_url', true );
if ( '' === $author_url ) {
$author_url = $url;
}
// An avatar URL is stored with a Webmention, even if an email is not provided. Look
// there before trying to build an avatar based on a comment's email.
$avatar = get_comment_meta( $comment->comment_ID, 'avatar', true );
// If there is no stored avatar URL, use WordPress to make default assumptions.
if ( '' === $avatar ) {
$avatar = get_avatar_url( $comment );
}
// And if there is still nothing, use the theme's mystery person.
if ( '' === $avatar ) {
$avatar = get_template_directory_uri() . '/images/mystery-person.png';
}
?>
<div id="comment-<?php comment_ID(); ?>" <?php comment_class( '', $comment ); ?>>
<article id="div-comment-<?php comment_ID(); ?>" >
<footer class="comment-meta">
<!-- This span is my lazy way of enabling a vertically aligned flex display on the article element. -->
<div class="comment-author vcard">
<img src="<?php echo esc_url( $avatar ); ?>" width=40 alt="" loading="lazy" />
<span>
<a class="u-author h-card" href="<?php echo esc_url( $author_url ); ?>"><?php echo esc_html( $comment->comment_author ); ?></a>
replied on
<a class="u-url" href="<?php echo esc_url( $url ); ?>">
<time datetime="<?php comment_time( 'c' ); ?>" class="dt-published"><?php echo get_comment_date( 'F j, Y', $comment ); ?> at <?php echo get_comment_time(); ?></time>
</a>
<?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
</span>
</div>
<?php if ( '0' == $comment->comment_approved ) : ?>
<em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em>
<?php endif; ?>
</footer><!-- .comment-meta -->
<div class="e-content">
<?php
// This is hilarious, but I'm feeling lazy. Replace all single line breaks in a
// comment with a double linke break so that wpautop() uses paragraph tags instead
// of <br> tags.
$comment_text = str_replace( "\n", "\n\n", get_comment_text( $comment, $args ) );
echo wpautop( $comment_text, false );
?>
</div><!-- .comment-content -->
<?php
comment_reply_link(
array_merge(
$args,
array(
'add_below' => 'div-comment',
'depth' => $depth,
'max_depth' => $args['max_depth'],
'before' => '<div class="reply">',
'after' => '</div>',
'reply_text' => 'Reply to ' . esc_html( $comment->comment_author ),
)
)
);
?>
</article>
<?php
}
}