7.4.33 | Linux x86_64
Server128.199.10.0
Userwww-data (uid:33)
PHP7.4.33 (apache2handler)
Terminal
Upload
Files: /var/www/html/wp-includes/blocks
View: latest-posts.php
<?php /** * Server-side rendering of the `core/latest-posts` block. * * @package WordPress */ /** * The excerpt length set by the Latest Posts core block * set at render time and used by the block itself. * * @var int */ global $block_core_latest_posts_excerpt_length; $block_core_latest_posts_excerpt_length = 0; /** * Callback for the excerpt_length filter used by * the Latest Posts block at render time. * * @since 5.4.0 * * @global int $block_core_latest_posts_excerpt_length Excerpt length set by the Latest Posts core block. * * @return int Returns the global $block_core_latest_posts_excerpt_length variable * to allow the excerpt_length filter respect the Latest Block setting. */ function block_core_latest_posts_get_excerpt_length() { global $block_core_latest_posts_excerpt_length; return $block_core_latest_posts_excerpt_length; } /** * Renders the `core/latest-posts` block on server. * * @since 5.0.0 * * @global WP_Post $post Global post object. * @global int $block_core_latest_posts_excerpt_length Excerpt length set by the Latest Posts core block. * * @param array $attributes The block attributes. * * @return string Returns the post content with latest posts added. */ function render_block_core_latest_posts( $attributes ) { global $post, $block_core_latest_posts_excerpt_length; $args = array( 'posts_per_page' => $attributes['postsToShow'], 'post_status' => 'publish', 'order' => $attributes['order'], 'orderby' => $attributes['orderBy'], 'ignore_sticky_posts' => true, 'no_found_rows' => true, ); $block_core_latest_posts_excerpt_length = $attributes['excerptLength']; add_filter( 'excerpt_length', 'block_core_latest_posts_get_excerpt_length', 20 ); if ( ! empty( $attributes['categories'] ) ) { $args['category__in'] = array_column( $attributes['categories'], 'id' ); } if ( isset( $attributes['selectedAuthor'] ) ) { $args['author'] = $attributes['selectedAuthor']; } $query = new WP_Query(); $recent_posts = $query->query( $args ); if ( isset( $attributes['displayFeaturedImage'] ) && $attributes['displayFeaturedImage'] ) { update_post_thumbnail_cache( $query ); } $list_items_markup = ''; foreach ( $recent_posts as $post ) { $post_link = esc_url( get_permalink( $post ) ); $title = get_the_title( $post ); if ( ! $title ) { $title = __( '(no title)' ); } $list_items_markup .= '<li>'; if ( $attributes['displayFeaturedImage'] && has_post_thumbnail( $post ) ) { $image_style = ''; if ( isset( $attributes['featuredImageSizeWidth'] ) ) { $image_style .= sprintf( 'max-width:%spx;', $attributes['featuredImageSizeWidth'] ); } if ( isset( $attributes['featuredImageSizeHeight'] ) ) { $image_style .= sprintf( 'max-height:%spx;', $attributes['featuredImageSizeHeight'] ); } $image_classes = 'wp-block-latest-posts__featured-image'; if ( isset( $attributes['featuredImageAlign'] ) ) { $image_classes .= ' align' . $attributes['featuredImageAlign']; } $featured_image = get_the_post_thumbnail( $post, $attributes['featuredImageSizeSlug'], array( 'style' => esc_attr( $image_style ), ) ); if ( $attributes['addLinkToFeaturedImage'] ) { $featured_image = sprintf( '<a href="%1$s" aria-label="%2$s">%3$s</a>', esc_url( $post_link ), esc_attr( $title ), $featured_image ); } $list_items_markup .= sprintf( '<div class="%1$s">%2$s</div>', esc_attr( $image_classes ), $featured_image ); } $list_items_markup .= sprintf( '<a class="wp-block-latest-posts__post-title" href="%1$s">%2$s</a>', esc_url( $post_link ), $title ); if ( isset( $attributes['displayAuthor'] ) && $attributes['displayAuthor'] ) { $author_display_name = get_the_author_meta( 'display_name', $post->post_author ); /* translators: byline. %s: author. */ $byline = sprintf( __( 'by %s' ), $author_display_name ); if ( ! empty( $author_display_name ) ) { $list_items_markup .= sprintf( '<div class="wp-block-latest-posts__post-author">%1$s</div>', $byline ); } } if ( isset( $attributes['displayPostDate'] ) && $attributes['displayPostDate'] ) { $list_items_markup .= sprintf( '<time datetime="%1$s" class="wp-block-latest-posts__post-date">%2$s</time>', esc_attr( get_the_date( 'c', $post ) ), get_the_date( '', $post ) ); } if ( isset( $attributes['displayPostContent'] ) && $attributes['displayPostContent'] && isset( $attributes['displayPostContentRadio'] ) && 'excerpt' === $attributes['displayPostContentRadio'] ) { $trimmed_excerpt = get_the_excerpt( $post ); /* * Adds a "Read more" link with screen reader text. * [&hellip;] is the default excerpt ending from wp_trim_excerpt() in Core. */ if ( str_ends_with( $trimmed_excerpt, ' [&hellip;]' ) ) { /** This filter is documented in wp-includes/formatting.php */ $excerpt_length = (int) apply_filters( 'excerpt_length', $block_core_latest_posts_excerpt_length ); if ( $excerpt_length <= $block_core_latest_posts_excerpt_length ) { $trimmed_excerpt = substr( $trimmed_excerpt, 0, -11 ); $trimmed_excerpt .= sprintf( /* translators: 1: A URL to a post, 2: Hidden accessibility text: Post title */ __( '… <a class="wp-block-latest-posts__read-more" href="%1$s" rel="noopener noreferrer">Read more<span class="screen-reader-text">: %2$s</span></a>' ), esc_url( $post_link ), esc_html( $title ) ); } } if ( post_password_required( $post ) ) { $trimmed_excerpt = __( 'This content is password protected.' ); } $list_items_markup .= sprintf( '<div class="wp-block-latest-posts__post-excerpt">%1$s</div>', $trimmed_excerpt ); } if ( isset( $attributes['displayPostContent'] ) && $attributes['displayPostContent'] && isset( $attributes['displayPostContentRadio'] ) && 'full_post' === $attributes['displayPostContentRadio'] ) { $post_content = html_entity_decode( $post->post_content, ENT_QUOTES, get_option( 'blog_charset' ) ); if ( post_password_required( $post ) ) { $post_content = __( 'This content is password protected.' ); } $list_items_markup .= sprintf( '<div class="wp-block-latest-posts__post-full-content">%1$s</div>', wp_kses_post( $post_content ) ); } $list_items_markup .= "</li>\n"; } remove_filter( 'excerpt_length', 'block_core_latest_posts_get_excerpt_length', 20 ); $classes = array( 'wp-block-latest-posts__list' ); if ( isset( $attributes['postLayout'] ) && 'grid' === $attributes['postLayout'] ) { $classes[] = 'is-grid'; } if ( isset( $attributes['columns'] ) && 'grid' === $attributes['postLayout'] ) { $classes[] = 'columns-' . $attributes['columns']; } if ( isset( $attributes['displayPostDate'] ) && $attributes['displayPostDate'] ) { $classes[] = 'has-dates'; } if ( isset( $attributes['displayAuthor'] ) && $attributes['displayAuthor'] ) { $classes[] = 'has-author'; } if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) { $classes[] = 'has-link-color'; } $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); return sprintf( '<ul %1$s>%2$s</ul>', $wrapper_attributes, $list_items_markup ); } /** * Registers the `core/latest-posts` block on server. * * @since 5.0.0 */ function register_block_core_latest_posts() { register_block_type_from_metadata( __DIR__ . '/latest-posts', array( 'render_callback' => 'render_block_core_latest_posts', ) ); } add_action( 'init', 'register_block_core_latest_posts' ); /** * Handles outdated versions of the `core/latest-posts` block by converting * attribute `categories` from a numeric string to an array with key `id`. * * This is done to accommodate the changes introduced in #20781 that sought to * add support for multiple categories to the block. However, given that this * block is dynamic, the usual provisions for block migration are insufficient, * as they only act when a block is loaded in the editor. * * TODO: Remove when and if the bottom client-side deprecation for this block * is removed. * * @since 5.5.0 * * @param array $block A single parsed block object. * * @return array The migrated block object. */ function block_core_latest_posts_migrate_categories( $block ) { if ( 'core/latest-posts' === $block['blockName'] && ! empty( $block['attrs']['categories'] ) && is_string( $block['attrs']['categories'] ) ) { $block['attrs']['categories'] = array( array( 'id' => absint( $block['attrs']['categories'] ) ), ); } return $block; } add_filter( 'render_block_data', 'block_core_latest_posts_migrate_categories' );
NameSizeActions
accordion/--
accordion-heading/--
accordion-item/--
accordion-item.php3KView Edit Del
accordion-panel/--
accordion.php1.1KView Edit Del
archives/--
archives.php4.3KView Edit Del
audio/--
avatar/--
avatar.php5.5KView Edit Del
block/--
block.php4.1KView Edit Del
blocks-json.php194.5KView Edit Del
breadcrumbs/--
breadcrumbs.php18.6KView Edit Del
button/--
button.php1.7KView Edit Del
buttons/--
calendar/--
calendar.php5.9KView Edit Del
categories/--
categories.php4.8KView Edit Del
code/--
column/--
columns/--
comment-author-name/--
comment-author-name.php2.1KView Edit Del
comment-content/--
comment-content.php2.4KView Edit Del
comment-date/--
comment-date.php1.8KView Edit Del
comment-edit-link/--
comment-edit-link.php1.7KView Edit Del
comment-reply-link/--
comment-reply-link.php2KView Edit Del
comment-template/--
comment-template.php4.4KView Edit Del
comments/--
comments-pagination/--
comments-pagination-next/--
comments-pagination-next.php1.9KView Edit Del
comments-pagination-numbers/--
comments-pagination-numbers.php1.6KView Edit Del
comments-pagination-previous/--
comments-pagination-previous.php1.7KView Edit Del
comments-pagination.php1.2KView Edit Del
comments-title/--
comments-title.php2.7KView Edit Del
comments.php6.6KView Edit Del
cover/--
cover.php7.2KView Edit Del
details/--
details.php1.5KView Edit Del
embed/--
file/--
file.php1.8KView Edit Del
footnotes/--
footnotes.php3.7KView Edit Del
freeform/--
gallery/--
gallery.php8.9KView Edit Del
group/--
heading/--
heading.php1.3KView Edit Del
home-link/--
home-link.php5.3KView Edit Del
html/--
icon/--
icon.php4KView Edit Del
image/--
image.php17.2KView Edit Del
index.php5KView Edit Del
latest-comments/--
latest-comments.php5.4KView Edit Del
latest-posts/--
latest-posts.php8.6KView Edit Del
legacy-widget/--
legacy-widget.php3.9KView Edit Del
list/--
list-item/--
list.php1.2KView Edit Del
loginout/--
loginout.php1.6KView Edit Del
math/--
media-text/--
media-text.php4.2KView Edit Del
missing/--
more/--
navigation/--
navigation-link/--
navigation-link.php15.8KView Edit Del
navigation-overlay-close/--
navigation-overlay-close.php1.7KView Edit Del
navigation-submenu/--
navigation-submenu.php11.5KView Edit Del
navigation.php63.3KView Edit Del
nextpage/--
page-list/--
page-list-item/--
page-list-item.php361BView Edit Del
page-list.php14.7KView Edit Del
paragraph/--
paragraph.php1.1KView Edit Del
pattern/--
pattern.php1.7KView Edit Del
post-author/--
post-author-biography/--
post-author-biography.php1.5KView Edit Del
post-author-name/--
post-author-name.php1.9KView Edit Del
post-author.php2.7KView Edit Del
post-comments-count/--
post-comments-count.php1.2KView Edit Del
post-comments-form/--
post-comments-form.php2.7KView Edit Del
post-comments-link/--
post-comments-link.php2.2KView Edit Del
post-content/--
post-content.php2.3KView Edit Del
post-date/--
post-date.php3.6KView Edit Del
post-excerpt/--
post-excerpt.php4.2KView Edit Del
post-featured-image/--
post-featured-image.php9KView Edit Del
post-navigation-link/--
post-navigation-link.php4.7KView Edit Del
post-template/--
post-template.php5.6KView Edit Del
post-terms/--
post-terms.php3.6KView Edit Del
post-time-to-read/--
post-time-to-read.php6.3KView Edit Del
post-title/--
post-title.php2.1KView Edit Del
preformatted/--
pullquote/--
query/--
query-no-results/--
query-no-results.php1.8KView Edit Del
query-pagination/--
query-pagination-next/--
query-pagination-next.php3.6KView Edit Del
query-pagination-numbers/--
query-pagination-numbers.php4.6KView Edit Del
query-pagination-previous/--
query-pagination-previous.php3.4KView Edit Del
query-pagination.php1.1KView Edit Del
query-title/--
query-title.php2.7KView Edit Del
query-total/--
query-total.php2.4KView Edit Del
query.php5.6KView Edit Del
quote/--
read-more/--
read-more.php1.8KView Edit Del
require-dynamic-blocks.php4.9KView Edit Del
require-static-blocks.php520BView Edit Del
rss/--
rss.php4.5KView Edit Del
search/--
search.php23.3KView Edit Del
separator/--
shortcode/--
shortcode.php735BView Edit Del
site-logo/--
site-logo.php6.2KView Edit Del
site-tagline/--
site-tagline.php1.2KView Edit Del
site-title/--
site-title.php1.8KView Edit Del
social-link/--
social-link.php66KView Edit Del
social-links/--
spacer/--
table/--
tag-cloud/--
tag-cloud.php1.6KView Edit Del
template-part/--
template-part.php10.2KView Edit Del
term-count/--
term-count.php1.8KView Edit Del
term-description/--
term-description.php1.7KView Edit Del
term-name/--
term-name.php2KView Edit Del
term-template/--
term-template.php4.4KView Edit Del
terms-query/--
text-columns/--
verse/--
video/--
video.php2.7KView Edit Del
widget-group/--
widget-group.php2.4KView Edit Del