PATH:
home
/
thecwrif
/
public_html
/
wp-includes
/
blocks
<?php /** * Server-side rendering of the `core/post-date` block. * * @package WordPress */ /** * Renders the `core/post-date` block on the server. * * @since 5.8.0 * @since 6.9.0 Added `datetime` attribute and Block Bindings support. * * @param array $attributes Block attributes. * @param string $content Block default content. * @param WP_Block $block Block instance. * @return string Returns the filtered post date for the current post wrapped inside "time" tags. */ function render_block_core_post_date( $attributes, $content, $block ) { $classes = array(); if ( ! isset( $attributes['datetime'] ) && ! ( isset( $attributes['metadata']['bindings']['datetime']['source'] ) && isset( $attributes['metadata']['bindings']['datetime']['args'] ) ) ) { /* * This is the legacy version of the block that didn't have the `datetime` attribute. * This branch needs to be kept for backward compatibility. */ $source = get_block_bindings_source( 'core/post-data' ); if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) { $source_args = array( 'field' => 'modified', ); } else { $source_args = array( 'field' => 'date', ); } $attributes['datetime'] = $source->get_value( $source_args, $block, 'datetime' ); } if ( isset( $source_args['field'] ) && 'modified' === $source_args['field'] ) { $classes[] = 'wp-block-post-date__modified-date'; } if ( empty( $attributes['datetime'] ) ) { // If the `datetime` attribute is set but empty, it could be because Block Bindings // set it that way. This can happen e.g. if the block is bound to the // post's last modified date, and the latter lies before the publish date. // (See https://github.com/WordPress/gutenberg/pull/46839 where this logic was originally // implemented.) // In this case, we have to respect and return the empty value. return ''; } $unformatted_date = $attributes['datetime']; $post_timestamp = strtotime( $unformatted_date ); if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) { if ( $post_timestamp > time() ) { // translators: %s: human-readable time difference. $formatted_date = sprintf( __( '%s from now' ), human_time_diff( $post_timestamp ) ); } else { // translators: %s: human-readable time difference. $formatted_date = sprintf( __( '%s ago' ), human_time_diff( $post_timestamp ) ); } } else { $format = empty( $attributes['format'] ) ? get_option( 'date_format' ) : $attributes['format']; $formatted_date = wp_date( $format, $post_timestamp ); } if ( isset( $attributes['textAlign'] ) ) { $classes[] = 'has-text-align-' . $attributes['textAlign']; } if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) { $classes[] = 'has-link-color'; } $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); if ( isset( $attributes['isLink'] ) && $attributes['isLink'] && isset( $block->context['postId'] ) ) { $formatted_date = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $block->context['postId'] ), $formatted_date ); } return sprintf( '<div %1$s><time datetime="%2$s">%3$s</time></div>', $wrapper_attributes, $unformatted_date, $formatted_date ); } /** * Registers the `core/post-date` block on the server. * * @since 5.8.0 */ function register_block_core_post_date() { register_block_type_from_metadata( __DIR__ . '/post-date', array( 'render_callback' => 'render_block_core_post_date', ) ); } add_action( 'init', 'register_block_core_post_date' );
[+]
..
[+]
terms-query
[+]
comment-edit-link
[+]
list
[-] query-total.php
[edit]
[-] media-text.php
[edit]
[+]
site-tagline
[+]
audio
[-] blocks-json.php
[edit]
[+]
navigation-submenu
[+]
post-date
[+]
comments-pagination-next
[-] comments-pagination-next.php
[edit]
[+]
post-author-biography
[-] navigation-submenu.php
[edit]
[+]
navigation
[+]
home-link
[+]
query-pagination-numbers
[-] tag-cloud.php
[edit]
[-] shortcode.php
[edit]
[-] list.php
[edit]
[-] term-description.php
[edit]
[-] page-list-item.php
[edit]
[+]
social-links
[-] post-comments-count.php
[edit]
[+]
post-comments-link
[+]
file
[-] pattern.php
[edit]
[+]
latest-posts
[+]
post-navigation-link
[-] post-author-biography.php
[edit]
[-] footnotes.php
[edit]
[+]
post-template
[-] post-title.php
[edit]
[+]
preformatted
[-] query-pagination-next.php
[edit]
[+]
paragraph
[+]
page-list
[+]
post-comments-count
[+]
term-count
[-] post-terms.php
[edit]
[+]
navigation-link
[-] accordion.php
[edit]
[-] post-time-to-read.php
[edit]
[+]
query-pagination-next
[-] template-part.php
[edit]
[-] home-link.php
[edit]
[+]
categories
[+]
site-title
[+]
avatar
[+]
comment-content
[+]
shortcode
[-] site-title.php
[edit]
[+]
term-template
[+]
embed
[+]
verse
[+]
template-part
[-] loginout.php
[edit]
[-] rss.php
[edit]
[-] page-list.php
[edit]
[+]
accordion-panel
[+]
latest-comments
[-] heading.php
[edit]
[+]
more
[+]
quote
[+]
comments
[-] search.php
[edit]
[-] comment-date.php
[edit]
[-] error_log
[edit]
[-] latest-comments.php
[edit]
[+]
post-comments-form
[+]
text-columns
[-] require-dynamic-blocks.php
[edit]
[-] block.php
[edit]
[+]
read-more
[+]
nextpage
[+]
columns
[-] term-name.php
[edit]
[-] calendar.php
[edit]
[+]
group
[+]
query-title
[-] post-template.php
[edit]
[+]
separator
[+]
pullquote
[-] post-date.php
[edit]
[-] comment-author-name.php
[edit]
[-] query-no-results.php
[edit]
[-] site-logo.php
[edit]
[+]
post-author
[-] read-more.php
[edit]
[+]
video
[+]
comment-reply-link
[-] image.php
[edit]
[-] comment-edit-link.php
[edit]
[-] navigation.php
[edit]
[-] comments-pagination.php
[edit]
[+]
post-title
[+]
query-no-results
[+]
widget-group
[-] comment-template.php
[edit]
[+]
query-total
[+]
rss
[+]
social-link
[-] post-author-name.php
[edit]
[+]
column
[+]
buttons
[-] term-count.php
[edit]
[-] comments.php
[edit]
[+]
spacer
[+]
code
[-] index.php
[edit]
[+]
site-logo
[+]
image
[+]
table
[+]
query-pagination
[+]
footnotes
[-] button.php
[edit]
[+]
comments-title
[+]
pattern
[+]
cover
[+]
list-item
[+]
block
[+]
media-text
[-] comment-content.php
[edit]
[-] term-template.php
[edit]
[+]
post-author-name
[-] post-comments-link.php
[edit]
[-] file.php
[edit]
[-] social-link.php
[edit]
[+]
details
[+]
tag-cloud
[-] gallery.php
[edit]
[-] widget-group.php
[edit]
[-] comments-title.php
[edit]
[+]
heading
[-] query-pagination-numbers.php
[edit]
[+]
query
[+]
gallery
[-] post-navigation-link.php
[edit]
[-] post-excerpt.php
[edit]
[+]
legacy-widget
[+]
post-featured-image
[+]
button
[+]
html
[-] post-content.php
[edit]
[-] query.php
[edit]
[-] accordion-item.php
[edit]
[-] post-comments-form.php
[edit]
[+]
page-list-item
[-] query-title.php
[edit]
[-] cover.php
[edit]
[-] comment-reply-link.php
[edit]
[+]
archives
[-] archives.php
[edit]
[-] categories.php
[edit]
[+]
accordion-heading
[+]
post-excerpt
[+]
query-pagination-previous
[+]
freeform
[+]
search
[-] comments-pagination-numbers.php
[edit]
[-] latest-posts.php
[edit]
[-] navigation-link.php
[edit]
[+]
loginout
[+]
comments-pagination
[-] site-tagline.php
[edit]
[+]
comments-pagination-previous
[+]
math
[-] post-author.php
[edit]
[-] query-pagination.php
[edit]
[+]
post-content
[-] require-static-blocks.php
[edit]
[+]
accordion
[+]
post-time-to-read
[+]
calendar
[+]
comment-date
[+]
comments-pagination-numbers
[-] comments-pagination-previous.php
[edit]
[+]
term-name
[+]
term-description
[-] avatar.php
[edit]
[+]
comment-template
[+]
accordion-item
[-] legacy-widget.php
[edit]
[+]
post-terms
[-] query-pagination-previous.php
[edit]
[-] post-featured-image.php
[edit]
[-] video.php
[edit]
[+]
missing
[+]
comment-author-name