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
*
[11] Fix | Delete
* @param array $attributes Block attributes.
[12] Fix | Delete
* @param string $content Block default content.
[13] Fix | Delete
* @param WP_Block $block Block instance.
[14] Fix | Delete
* @return string Returns the filtered post date for the current post wrapped inside "time" tags.
[15] Fix | Delete
*/
[16] Fix | Delete
function render_block_core_post_date( $attributes, $content, $block ) {
[17] Fix | Delete
if ( ! isset( $block->context['postId'] ) ) {
[18] Fix | Delete
return '';
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
$post_ID = $block->context['postId'];
[22] Fix | Delete
[23] Fix | Delete
if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) {
[24] Fix | Delete
$post_timestamp = get_post_timestamp( $post_ID );
[25] Fix | Delete
if ( $post_timestamp > time() ) {
[26] Fix | Delete
// translators: %s: human-readable time difference.
[27] Fix | Delete
$formatted_date = sprintf( __( '%s from now' ), human_time_diff( $post_timestamp ) );
[28] Fix | Delete
} else {
[29] Fix | Delete
// translators: %s: human-readable time difference.
[30] Fix | Delete
$formatted_date = sprintf( __( '%s ago' ), human_time_diff( $post_timestamp ) );
[31] Fix | Delete
}
[32] Fix | Delete
} else {
[33] Fix | Delete
$formatted_date = get_the_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
[34] Fix | Delete
}
[35] Fix | Delete
$unformatted_date = esc_attr( get_the_date( 'c', $post_ID ) );
[36] Fix | Delete
$classes = array();
[37] Fix | Delete
[38] Fix | Delete
if ( isset( $attributes['textAlign'] ) ) {
[39] Fix | Delete
$classes[] = 'has-text-align-' . $attributes['textAlign'];
[40] Fix | Delete
}
[41] Fix | Delete
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
[42] Fix | Delete
$classes[] = 'has-link-color';
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
/*
[46] Fix | Delete
* If the "Display last modified date" setting is enabled,
[47] Fix | Delete
* only display the modified date if it is later than the publishing date.
[48] Fix | Delete
*/
[49] Fix | Delete
if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
[50] Fix | Delete
if ( get_the_modified_date( 'Ymdhi', $post_ID ) > get_the_date( 'Ymdhi', $post_ID ) ) {
[51] Fix | Delete
if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) {
[52] Fix | Delete
// translators: %s: human-readable time difference.
[53] Fix | Delete
$formatted_date = sprintf( __( '%s ago' ), human_time_diff( get_post_timestamp( $post_ID, 'modified' ) ) );
[54] Fix | Delete
} else {
[55] Fix | Delete
$formatted_date = get_the_modified_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
[56] Fix | Delete
}
[57] Fix | Delete
$unformatted_date = esc_attr( get_the_modified_date( 'c', $post_ID ) );
[58] Fix | Delete
$classes[] = 'wp-block-post-date__modified-date';
[59] Fix | Delete
} else {
[60] Fix | Delete
return '';
[61] Fix | Delete
}
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
[65] Fix | Delete
[66] Fix | Delete
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
[67] Fix | Delete
$formatted_date = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $post_ID ), $formatted_date );
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
return sprintf(
[71] Fix | Delete
'<div %1$s><time datetime="%2$s">%3$s</time></div>',
[72] Fix | Delete
$wrapper_attributes,
[73] Fix | Delete
$unformatted_date,
[74] Fix | Delete
$formatted_date
[75] Fix | Delete
);
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Registers the `core/post-date` block on the server.
[80] Fix | Delete
*
[81] Fix | Delete
* @since 5.8.0
[82] Fix | Delete
*/
[83] Fix | Delete
function register_block_core_post_date() {
[84] Fix | Delete
register_block_type_from_metadata(
[85] Fix | Delete
__DIR__ . '/post-date',
[86] Fix | Delete
array(
[87] Fix | Delete
'render_callback' => 'render_block_core_post_date',
[88] Fix | Delete
)
[89] Fix | Delete
);
[90] Fix | Delete
}
[91] Fix | Delete
add_action( 'init', 'register_block_core_post_date' );
[92] Fix | Delete
[93] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function