PHP 8.1.33
Preview: latest-comments.php Size: 4.92 KB
/home/jambtst2015/public_html/cccng.org/wp-includes/blocks/latest-comments.php

<?php
/**
 * Server-side rendering of the `core/latest-comments` block.
 *
 * @package WordPress
 */

/**
 * Get the post title.
 *
 * The post title is fetched and if it is blank then a default string is
 * returned.
 *
 * Copied from `wp-admin/includes/template.php`, but we can't include that
 * file because:
 *
 * 1. It causes bugs with test fixture generation and strange Docker 255 error
 *    codes.
 * 2. It's in the admin; ideally we *shouldn't* be including files from the
 *    admin for a block's output. It's a very small/simple function as well,
 *    so duplicating it isn't too terrible.
 *
 * @since 3.3.0
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string The post title if set; "(no title)" if no title is set.
 */
function wp_latest_comments_draft_or_post_title( $post = 0 ) {
	$title = get_the_title( $post );
	if ( empty( $title ) ) {
		$title = __( '(no title)' );
	}
	return $title;
}

/**
 * Renders the `core/latest-comments` block on server.
 *
 * @since 5.1.0
 *
 * @param array $attributes The block attributes.
 *
 * @return string Returns the post content with latest comments added.
 */
function render_block_core_latest_comments( $attributes = array() ) {
	$comments = get_comments(
		/** This filter is documented in wp-includes/widgets/class-wp-widget-recent-comments.php */
		apply_filters(
			'widget_comments_args',
			array(
				'number'      => $attributes['commentsToShow'],
				'status'      => 'approve',
				'post_status' => 'publish',
			),
			array()
		)
	);

	$list_items_markup = '';
	if ( ! empty( $comments ) ) {
		// Prime the cache for associated posts. This is copied from \WP_Widget_Recent_Comments::widget().
		$post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
		_prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );

		foreach ( $comments as $comment ) {
			$list_items_markup .= '<li class="wp-block-latest-comments__comment">';
			if ( $attributes['displayAvatar'] ) {
				$avatar = get_avatar(
					$comment,
					48,
					'',
					'',
					array(
						'class' => 'wp-block-latest-comments__comment-avatar',
					)
				);
				if ( $avatar ) {
					$list_items_markup .= $avatar;
				}
			}

			$list_items_markup .= '<article>';
			$list_items_markup .= '<footer class="wp-block-latest-comments__comment-meta">';
			$author_url         = get_comment_author_url( $comment );
			if ( empty( $author_url ) && ! empty( $comment->user_id ) ) {
				$author_url = get_author_posts_url( $comment->user_id );
			}

			$author_markup = '';
			if ( $author_url ) {
				$author_markup .= '<a class="wp-block-latest-comments__comment-author" href="' . esc_url( $author_url ) . '">' . get_comment_author( $comment ) . '</a>';
			} else {
				$author_markup .= '<span class="wp-block-latest-comments__comment-author">' . get_comment_author( $comment ) . '</span>';
			}

			// `_draft_or_post_title` calls `esc_html()` so we don't need to wrap that call in
			// `esc_html`.
			$post_title = '<a class="wp-block-latest-comments__comment-link" href="' . esc_url( get_comment_link( $comment ) ) . '">' . wp_latest_comments_draft_or_post_title( $comment->comment_post_ID ) . '</a>';

			$list_items_markup .= sprintf(
				/* translators: 1: author name (inside <a> or <span> tag, based on if they have a URL), 2: post title related to this comment */
				__( '%1$s on %2$s' ),
				$author_markup,
				$post_title
			);

			if ( $attributes['displayDate'] ) {
				$list_items_markup .= sprintf(
					'<time datetime="%1$s" class="wp-block-latest-comments__comment-date">%2$s</time>',
					esc_attr( get_comment_date( 'c', $comment ) ),
					date_i18n( get_option( 'date_format' ), get_comment_date( 'U', $comment ) )
				);
			}
			$list_items_markup .= '</footer>';
			if ( $attributes['displayExcerpt'] ) {
				$list_items_markup .= '<div class="wp-block-latest-comments__comment-excerpt">' . wpautop( get_comment_excerpt( $comment ) ) . '</div>';
			}
			$list_items_markup .= '</article></li>';
		}
	}

	$classnames = array();
	if ( $attributes['displayAvatar'] ) {
		$classnames[] = 'has-avatars';
	}
	if ( $attributes['displayDate'] ) {
		$classnames[] = 'has-dates';
	}
	if ( $attributes['displayExcerpt'] ) {
		$classnames[] = 'has-excerpts';
	}
	if ( empty( $comments ) ) {
		$classnames[] = 'no-comments';
	}
	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) );

	return ! empty( $comments ) ? sprintf(
		'<ol %1$s>%2$s</ol>',
		$wrapper_attributes,
		$list_items_markup
	) : sprintf(
		'<div %1$s>%2$s</div>',
		$wrapper_attributes,
		__( 'No comments to show.' )
	);
}

/**
 * Registers the `core/latest-comments` block.
 *
 * @since 5.3.0
 */
function register_block_core_latest_comments() {
	register_block_type_from_metadata(
		__DIR__ . '/latest-comments',
		array(
			'render_callback' => 'render_block_core_latest_comments',
		)
	);
}

add_action( 'init', 'register_block_core_latest_comments' );

Directory Contents

Dirs: 95 × Files: 74

Name Size Perms Modified Actions
archives DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
audio DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
avatar DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
block DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
button DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
buttons DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
calendar DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
classic DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
code DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
column DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
columns DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
comments DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
cover DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
details DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
embed DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
file DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
footnotes DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
freeform DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
gallery DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
group DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
heading DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
home-link DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
html DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
image DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
list DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
list-item DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
loginout DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
missing DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
more DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
nextpage DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
page-list DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
paragraph DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
pattern DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2025-10-08 17:06:32
Edit Download
post-date DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2025-10-08 17:06:32
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
pullquote DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
query DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2025-10-08 17:06:31
Edit Download
quote DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
read-more DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
rss DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
search DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
separator DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
shortcode DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
site-logo DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
spacer DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
table DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
tag-cloud DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
verse DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
video DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
2.92 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
5.61 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
3.24 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
189.40 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
1.76 KB lrw-r--r-- 2024-06-11 19:37:32
Edit Download
5.93 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
3.92 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
2.08 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
2.40 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
1.82 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
1.67 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
2.03 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
4.39 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
1.88 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
1.59 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
1.75 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
1.17 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
2.71 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
6.61 KB lrw-r--r-- 2024-06-01 04:29:00
Edit Download
3.10 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
1.75 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
3.68 KB lrw-r--r-- 2024-02-28 01:18:24
Edit Download
6.29 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
1.27 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
5.31 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
11.74 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
4.99 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
734 B lrw-r--r-- 2023-01-12 06:44:12
Edit Download
4.92 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
8.34 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
3.90 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
1.24 KB lrw-r--r-- 2024-05-24 05:26:08
Edit Download
1.38 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
4.28 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
13.59 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
9.71 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
48.46 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
361 B lrw-r--r-- 2024-05-24 05:09:28
Edit Download
13.29 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
1.75 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
1.49 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
1.91 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
2.67 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
2.74 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
2.11 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
3.05 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
3.37 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
9.14 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
4.72 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
5.61 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
3.55 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
2.09 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
1.80 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
3.70 KB lrw-r--r-- 2024-06-11 19:37:32
Edit Download
4.66 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
3.50 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
1.15 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
2.05 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
2.48 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
5.56 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
1.79 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
4.07 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
501 B lrw-r--r-- 2024-06-11 19:37:32
Edit Download
3.98 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
22.48 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
735 B lrw-r--r-- 2024-05-24 05:09:28
Edit Download
6.19 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
1.17 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
1.81 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
63.65 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
1.55 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
9.92 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
1.30 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download
2.38 KB lrw-r--r-- 2024-05-24 05:09:28
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).