Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: post-date.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/post-date` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/post-date` block on the server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 5.8.0
[10] Fix | Delete
* @since 6.9.0 Added `datetime` attribute and Block Bindings support.
[11] Fix | Delete
*
[12] Fix | Delete
* @param array $attributes Block attributes.
[13] Fix | Delete
* @param string $content Block default content.
[14] Fix | Delete
* @param WP_Block $block Block instance.
[15] Fix | Delete
* @return string Returns the filtered post date for the current post wrapped inside "time" tags.
[16] Fix | Delete
*/
[17] Fix | Delete
function render_block_core_post_date( $attributes, $content, $block ) {
[18] Fix | Delete
$classes = array();
[19] Fix | Delete
[20] Fix | Delete
if (
[21] Fix | Delete
! isset( $attributes['datetime'] ) && ! (
[22] Fix | Delete
isset( $attributes['metadata']['bindings']['datetime']['source'] ) &&
[23] Fix | Delete
isset( $attributes['metadata']['bindings']['datetime']['args'] )
[24] Fix | Delete
)
[25] Fix | Delete
) {
[26] Fix | Delete
/*
[27] Fix | Delete
* This is the legacy version of the block that didn't have the `datetime` attribute.
[28] Fix | Delete
* This branch needs to be kept for backward compatibility.
[29] Fix | Delete
*/
[30] Fix | Delete
$source = get_block_bindings_source( 'core/post-data' );
[31] Fix | Delete
if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
[32] Fix | Delete
$source_args = array(
[33] Fix | Delete
'field' => 'modified',
[34] Fix | Delete
);
[35] Fix | Delete
} else {
[36] Fix | Delete
$source_args = array(
[37] Fix | Delete
'field' => 'date',
[38] Fix | Delete
);
[39] Fix | Delete
}
[40] Fix | Delete
$attributes['datetime'] = $source->get_value( $source_args, $block, 'datetime' );
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
if ( isset( $source_args['field'] ) && 'modified' === $source_args['field'] ) {
[44] Fix | Delete
$classes[] = 'wp-block-post-date__modified-date';
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
if ( empty( $attributes['datetime'] ) ) {
[48] Fix | Delete
// If the `datetime` attribute is set but empty, it could be because Block Bindings
[49] Fix | Delete
// set it that way. This can happen e.g. if the block is bound to the
[50] Fix | Delete
// post's last modified date, and the latter lies before the publish date.
[51] Fix | Delete
// (See https://github.com/WordPress/gutenberg/pull/46839 where this logic was originally
[52] Fix | Delete
// implemented.)
[53] Fix | Delete
// In this case, we have to respect and return the empty value.
[54] Fix | Delete
return '';
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
$unformatted_date = $attributes['datetime'];
[58] Fix | Delete
$post_timestamp = strtotime( $unformatted_date );
[59] Fix | Delete
[60] Fix | Delete
if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) {
[61] Fix | Delete
if ( $post_timestamp > time() ) {
[62] Fix | Delete
// translators: %s: human-readable time difference.
[63] Fix | Delete
$formatted_date = sprintf( __( '%s from now' ), human_time_diff( $post_timestamp ) );
[64] Fix | Delete
} else {
[65] Fix | Delete
// translators: %s: human-readable time difference.
[66] Fix | Delete
$formatted_date = sprintf( __( '%s ago' ), human_time_diff( $post_timestamp ) );
[67] Fix | Delete
}
[68] Fix | Delete
} else {
[69] Fix | Delete
$format = empty( $attributes['format'] ) ? get_option( 'date_format' ) : $attributes['format'];
[70] Fix | Delete
$formatted_date = wp_date( $format, $post_timestamp );
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
if ( isset( $attributes['textAlign'] ) ) {
[74] Fix | Delete
$classes[] = 'has-text-align-' . $attributes['textAlign'];
[75] Fix | Delete
}
[76] Fix | Delete
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
[77] Fix | Delete
$classes[] = 'has-link-color';
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
[81] Fix | Delete
[82] Fix | Delete
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] && isset( $block->context['postId'] ) ) {
[83] Fix | Delete
$formatted_date = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $block->context['postId'] ), $formatted_date );
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
return sprintf(
[87] Fix | Delete
'<div %1$s><time datetime="%2$s">%3$s</time></div>',
[88] Fix | Delete
$wrapper_attributes,
[89] Fix | Delete
$unformatted_date,
[90] Fix | Delete
$formatted_date
[91] Fix | Delete
);
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Registers the `core/post-date` block on the server.
[96] Fix | Delete
*
[97] Fix | Delete
* @since 5.8.0
[98] Fix | Delete
*/
[99] Fix | Delete
function register_block_core_post_date() {
[100] Fix | Delete
register_block_type_from_metadata(
[101] Fix | Delete
__DIR__ . '/post-date',
[102] Fix | Delete
array(
[103] Fix | Delete
'render_callback' => 'render_block_core_post_date',
[104] Fix | Delete
)
[105] Fix | Delete
);
[106] Fix | Delete
}
[107] Fix | Delete
add_action( 'init', 'register_block_core_post_date' );
[108] Fix | Delete
[109] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function