wp/wp-includes/class-walker-comment.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
   159 	 * @since 2.7.0
   159 	 * @since 2.7.0
   160 	 *
   160 	 *
   161 	 * @see Walker::start_el()
   161 	 * @see Walker::start_el()
   162 	 * @see wp_list_comments()
   162 	 * @see wp_list_comments()
   163 	 * @global int        $comment_depth
   163 	 * @global int        $comment_depth
   164 	 * @global WP_Comment $comment
   164 	 * @global WP_Comment $comment       Global comment object.
   165 	 *
   165 	 *
   166 	 * @param string     $output  Used to append additional content. Passed by reference.
   166 	 * @param string     $output  Used to append additional content. Passed by reference.
   167 	 * @param WP_Comment $comment Comment data object.
   167 	 * @param WP_Comment $comment Comment data object.
   168 	 * @param int        $depth   Optional. Depth of the current comment in reference to parents. Default 0.
   168 	 * @param int        $depth   Optional. Depth of the current comment in reference to parents. Default 0.
   169 	 * @param array      $args    Optional. An array of arguments. Default empty array.
   169 	 * @param array      $args    Optional. An array of arguments. Default empty array.
   179 			call_user_func( $args['callback'], $comment, $args, $depth );
   179 			call_user_func( $args['callback'], $comment, $args, $depth );
   180 			$output .= ob_get_clean();
   180 			$output .= ob_get_clean();
   181 			return;
   181 			return;
   182 		}
   182 		}
   183 
   183 
   184 		if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {
   184 		if ( 'comment' === $comment->comment_type ) {
       
   185 			add_filter( 'comment_text', array( $this, 'filter_comment_text' ), 40, 2 );
       
   186 		}
       
   187 
       
   188 		if ( ( 'pingback' === $comment->comment_type || 'trackback' === $comment->comment_type ) && $args['short_ping'] ) {
   185 			ob_start();
   189 			ob_start();
   186 			$this->ping( $comment, $depth, $args );
   190 			$this->ping( $comment, $depth, $args );
   187 			$output .= ob_get_clean();
   191 			$output .= ob_get_clean();
   188 		} elseif ( 'html5' === $args['format'] ) {
   192 		} elseif ( 'html5' === $args['format'] ) {
   189 			ob_start();
   193 			ob_start();
   192 		} else {
   196 		} else {
   193 			ob_start();
   197 			ob_start();
   194 			$this->comment( $comment, $depth, $args );
   198 			$this->comment( $comment, $depth, $args );
   195 			$output .= ob_get_clean();
   199 			$output .= ob_get_clean();
   196 		}
   200 		}
       
   201 
       
   202 		if ( 'comment' === $comment->comment_type ) {
       
   203 			remove_filter( 'comment_text', array( $this, 'filter_comment_text' ), 40, 2 );
       
   204 		}
   197 	}
   205 	}
   198 
   206 
   199 	/**
   207 	/**
   200 	 * Ends the element output, if needed.
   208 	 * Ends the element output, if needed.
   201 	 *
   209 	 *
   214 			ob_start();
   222 			ob_start();
   215 			call_user_func( $args['end-callback'], $comment, $args, $depth );
   223 			call_user_func( $args['end-callback'], $comment, $args, $depth );
   216 			$output .= ob_get_clean();
   224 			$output .= ob_get_clean();
   217 			return;
   225 			return;
   218 		}
   226 		}
   219 		if ( 'div' == $args['style'] ) {
   227 		if ( 'div' === $args['style'] ) {
   220 			$output .= "</div><!-- #comment-## -->\n";
   228 			$output .= "</div><!-- #comment-## -->\n";
   221 		} else {
   229 		} else {
   222 			$output .= "</li><!-- #comment-## -->\n";
   230 			$output .= "</li><!-- #comment-## -->\n";
   223 		}
   231 		}
   224 	}
   232 	}
   233 	 * @param WP_Comment $comment The comment object.
   241 	 * @param WP_Comment $comment The comment object.
   234 	 * @param int        $depth   Depth of the current comment.
   242 	 * @param int        $depth   Depth of the current comment.
   235 	 * @param array      $args    An array of arguments.
   243 	 * @param array      $args    An array of arguments.
   236 	 */
   244 	 */
   237 	protected function ping( $comment, $depth, $args ) {
   245 	protected function ping( $comment, $depth, $args ) {
   238 		$tag = ( 'div' == $args['style'] ) ? 'div' : 'li';
   246 		$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
   239 		?>
   247 		?>
   240 		<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( '', $comment ); ?>>
   248 		<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( '', $comment ); ?>>
   241 			<div class="comment-body">
   249 			<div class="comment-body">
   242 				<?php _e( 'Pingback:' ); ?> <?php comment_author_link( $comment ); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
   250 				<?php _e( 'Pingback:' ); ?> <?php comment_author_link( $comment ); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
   243 			</div>
   251 			</div>
   244 		<?php
   252 		<?php
   245 	}
   253 	}
   246 
   254 
   247 	/**
   255 	/**
       
   256 	 * Filters the comment text.
       
   257 	 *
       
   258 	 * Removes links from the pending comment's text if the commenter did not consent
       
   259 	 * to the comment cookies.
       
   260 	 *
       
   261 	 * @since 5.4.2
       
   262 	 *
       
   263 	 * @param string          $comment_text Text of the current comment.
       
   264 	 * @param WP_Comment|null $comment      The comment object. Null if not found.
       
   265 	 * @return string Filtered text of the current comment.
       
   266 	 */
       
   267 	public function filter_comment_text( $comment_text, $comment ) {
       
   268 		$commenter          = wp_get_current_commenter();
       
   269 		$show_pending_links = ! empty( $commenter['comment_author'] );
       
   270 
       
   271 		if ( $comment && '0' == $comment->comment_approved && ! $show_pending_links ) {
       
   272 			$comment_text = wp_kses( $comment_text, array() );
       
   273 		}
       
   274 
       
   275 		return $comment_text;
       
   276 	}
       
   277 
       
   278 	/**
   248 	 * Outputs a single comment.
   279 	 * Outputs a single comment.
   249 	 *
   280 	 *
   250 	 * @since 3.6.0
   281 	 * @since 3.6.0
   251 	 *
   282 	 *
   252 	 * @see wp_list_comments()
   283 	 * @see wp_list_comments()
   254 	 * @param WP_Comment $comment Comment to display.
   285 	 * @param WP_Comment $comment Comment to display.
   255 	 * @param int        $depth   Depth of the current comment.
   286 	 * @param int        $depth   Depth of the current comment.
   256 	 * @param array      $args    An array of arguments.
   287 	 * @param array      $args    An array of arguments.
   257 	 */
   288 	 */
   258 	protected function comment( $comment, $depth, $args ) {
   289 	protected function comment( $comment, $depth, $args ) {
   259 		if ( 'div' == $args['style'] ) {
   290 		if ( 'div' === $args['style'] ) {
   260 			$tag       = 'div';
   291 			$tag       = 'div';
   261 			$add_below = 'comment';
   292 			$add_below = 'comment';
   262 		} else {
   293 		} else {
   263 			$tag       = 'li';
   294 			$tag       = 'li';
   264 			$add_below = 'div-comment';
   295 			$add_below = 'div-comment';
   265 		}
   296 		}
   266 
   297 
   267 		$commenter = wp_get_current_commenter();
   298 		$commenter          = wp_get_current_commenter();
       
   299 		$show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author'];
       
   300 
   268 		if ( $commenter['comment_author_email'] ) {
   301 		if ( $commenter['comment_author_email'] ) {
   269 			$moderation_note = __( 'Your comment is awaiting moderation.' );
   302 			$moderation_note = __( 'Your comment is awaiting moderation.' );
   270 		} else {
   303 		} else {
   271 			$moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.' );
   304 			$moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.' );
   272 		}
   305 		}
   273 
       
   274 		?>
   306 		?>
   275 		<<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?> id="comment-<?php comment_ID(); ?>">
   307 		<<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?> id="comment-<?php comment_ID(); ?>">
   276 		<?php if ( 'div' != $args['style'] ) : ?>
   308 		<?php if ( 'div' !== $args['style'] ) : ?>
   277 		<div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
   309 		<div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
   278 		<?php endif; ?>
   310 		<?php endif; ?>
   279 		<div class="comment-author vcard">
   311 		<div class="comment-author vcard">
   280 			<?php
   312 			<?php
   281 			if ( 0 != $args['avatar_size'] ) {
   313 			if ( 0 != $args['avatar_size'] ) {
   282 				echo get_avatar( $comment, $args['avatar_size'] );}
   314 				echo get_avatar( $comment, $args['avatar_size'] );
       
   315 			}
   283 			?>
   316 			?>
   284 			<?php
   317 			<?php
   285 				/* translators: %s: comment author link */
   318 			$comment_author = get_comment_author_link( $comment );
   286 				printf(
   319 
   287 					__( '%s <span class="says">says:</span>' ),
   320 			if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
   288 					sprintf( '<cite class="fn">%s</cite>', get_comment_author_link( $comment ) )
   321 				$comment_author = get_comment_author( $comment );
   289 				);
   322 			}
       
   323 
       
   324 			printf(
       
   325 				/* translators: %s: Comment author link. */
       
   326 				__( '%s <span class="says">says:</span>' ),
       
   327 				sprintf( '<cite class="fn">%s</cite>', $comment_author )
       
   328 			);
   290 			?>
   329 			?>
   291 		</div>
   330 		</div>
   292 		<?php if ( '0' == $comment->comment_approved ) : ?>
   331 		<?php if ( '0' == $comment->comment_approved ) : ?>
   293 		<em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em>
   332 		<em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em>
   294 		<br />
   333 		<br />
   295 		<?php endif; ?>
   334 		<?php endif; ?>
   296 
   335 
   297 		<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
   336 		<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
   298 			<?php
   337 			<?php
   299 				/* translators: 1: comment date, 2: comment time */
   338 				/* translators: 1: Comment date, 2: Comment time. */
   300 				printf( __( '%1$s at %2$s' ), get_comment_date( '', $comment ), get_comment_time() );
   339 				printf( __( '%1$s at %2$s' ), get_comment_date( '', $comment ), get_comment_time() );
   301 			?>
   340 			?>
   302 				</a>
   341 				</a>
   303 				<?php
   342 				<?php
   304 				edit_comment_link( __( '(Edit)' ), '&nbsp;&nbsp;', '' );
   343 				edit_comment_link( __( '(Edit)' ), '&nbsp;&nbsp;', '' );
   332 				)
   371 				)
   333 			)
   372 			)
   334 		);
   373 		);
   335 		?>
   374 		?>
   336 
   375 
   337 		<?php if ( 'div' != $args['style'] ) : ?>
   376 		<?php if ( 'div' !== $args['style'] ) : ?>
   338 		</div>
   377 		</div>
   339 		<?php endif; ?>
   378 		<?php endif; ?>
   340 		<?php
   379 		<?php
   341 	}
   380 	}
   342 
   381 
   352 	 * @param array      $args    An array of arguments.
   391 	 * @param array      $args    An array of arguments.
   353 	 */
   392 	 */
   354 	protected function html5_comment( $comment, $depth, $args ) {
   393 	protected function html5_comment( $comment, $depth, $args ) {
   355 		$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
   394 		$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
   356 
   395 
   357 		$commenter = wp_get_current_commenter();
   396 		$commenter          = wp_get_current_commenter();
       
   397 		$show_pending_links = ! empty( $commenter['comment_author'] );
       
   398 
   358 		if ( $commenter['comment_author_email'] ) {
   399 		if ( $commenter['comment_author_email'] ) {
   359 			$moderation_note = __( 'Your comment is awaiting moderation.' );
   400 			$moderation_note = __( 'Your comment is awaiting moderation.' );
   360 		} else {
   401 		} else {
   361 			$moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.' );
   402 			$moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.' );
   362 		}
   403 		}
   363 
       
   364 		?>
   404 		?>
   365 		<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>>
   405 		<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>>
   366 			<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
   406 			<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
   367 				<footer class="comment-meta">
   407 				<footer class="comment-meta">
   368 					<div class="comment-author vcard">
   408 					<div class="comment-author vcard">
   369 						<?php
   409 						<?php
   370 						if ( 0 != $args['avatar_size'] ) {
   410 						if ( 0 != $args['avatar_size'] ) {
   371 							echo get_avatar( $comment, $args['avatar_size'] );}
   411 							echo get_avatar( $comment, $args['avatar_size'] );
       
   412 						}
   372 						?>
   413 						?>
   373 						<?php
   414 						<?php
   374 							/* translators: %s: comment author link */
   415 						$comment_author = get_comment_author_link( $comment );
   375 							printf(
   416 
   376 								__( '%s <span class="says">says:</span>' ),
   417 						if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
   377 								sprintf( '<b class="fn">%s</b>', get_comment_author_link( $comment ) )
   418 							$comment_author = get_comment_author( $comment );
   378 							);
   419 						}
       
   420 
       
   421 						printf(
       
   422 							/* translators: %s: Comment author link. */
       
   423 							__( '%s <span class="says">says:</span>' ),
       
   424 							sprintf( '<b class="fn">%s</b>', $comment_author )
       
   425 						);
   379 						?>
   426 						?>
   380 					</div><!-- .comment-author -->
   427 					</div><!-- .comment-author -->
   381 
   428 
   382 					<div class="comment-metadata">
   429 					<div class="comment-metadata">
   383 						<a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
   430 						<a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
   384 							<time datetime="<?php comment_time( 'c' ); ?>">
   431 							<time datetime="<?php comment_time( 'c' ); ?>">
   385 								<?php
   432 								<?php
   386 									/* translators: 1: comment date, 2: comment time */
   433 									/* translators: 1: Comment date, 2: Comment time. */
   387 									printf( __( '%1$s at %2$s' ), get_comment_date( '', $comment ), get_comment_time() );
   434 									printf( __( '%1$s at %2$s' ), get_comment_date( '', $comment ), get_comment_time() );
   388 								?>
   435 								?>
   389 							</time>
   436 							</time>
   390 						</a>
   437 						</a>
   391 						<?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
   438 						<?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
   399 				<div class="comment-content">
   446 				<div class="comment-content">
   400 					<?php comment_text(); ?>
   447 					<?php comment_text(); ?>
   401 				</div><!-- .comment-content -->
   448 				</div><!-- .comment-content -->
   402 
   449 
   403 				<?php
   450 				<?php
   404 				comment_reply_link(
   451 				if ( '1' == $comment->comment_approved || $show_pending_links ) {
   405 					array_merge(
   452 					comment_reply_link(
   406 						$args,
   453 						array_merge(
   407 						array(
   454 							$args,
   408 							'add_below' => 'div-comment',
   455 							array(
   409 							'depth'     => $depth,
   456 								'add_below' => 'div-comment',
   410 							'max_depth' => $args['max_depth'],
   457 								'depth'     => $depth,
   411 							'before'    => '<div class="reply">',
   458 								'max_depth' => $args['max_depth'],
   412 							'after'     => '</div>',
   459 								'before'    => '<div class="reply">',
       
   460 								'after'     => '</div>',
       
   461 							)
   413 						)
   462 						)
   414 					)
   463 					);
   415 				);
   464 				}
   416 				?>
   465 				?>
   417 			</article><!-- .comment-body -->
   466 			</article><!-- .comment-body -->
   418 		<?php
   467 		<?php
   419 	}
   468 	}
   420 }
   469 }