wp/wp-includes/blocks/post-date.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
    18 function render_block_core_post_date( $attributes, $content, $block ) {
    18 function render_block_core_post_date( $attributes, $content, $block ) {
    19 	if ( ! isset( $block->context['postId'] ) ) {
    19 	if ( ! isset( $block->context['postId'] ) ) {
    20 		return '';
    20 		return '';
    21 	}
    21 	}
    22 
    22 
    23 	$post_ID          = $block->context['postId'];
    23 	$post_ID = $block->context['postId'];
    24 	$formatted_date   = get_the_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
    24 
       
    25 	if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) {
       
    26 		$post_timestamp = get_post_timestamp( $post_ID );
       
    27 		if ( $post_timestamp > time() ) {
       
    28 			// translators: %s: human-readable time difference.
       
    29 			$formatted_date = sprintf( __( '%s from now' ), human_time_diff( $post_timestamp ) );
       
    30 		} else {
       
    31 			// translators: %s: human-readable time difference.
       
    32 			$formatted_date = sprintf( __( '%s ago' ), human_time_diff( $post_timestamp ) );
       
    33 		}
       
    34 	} else {
       
    35 		$formatted_date = get_the_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
       
    36 	}
    25 	$unformatted_date = esc_attr( get_the_date( 'c', $post_ID ) );
    37 	$unformatted_date = esc_attr( get_the_date( 'c', $post_ID ) );
    26 	$classes          = array();
    38 	$classes          = array();
    27 
    39 
    28 	if ( isset( $attributes['textAlign'] ) ) {
    40 	if ( isset( $attributes['textAlign'] ) ) {
    29 		$classes[] = 'has-text-align-' . $attributes['textAlign'];
    41 		$classes[] = 'has-text-align-' . $attributes['textAlign'];
    36 	 * If the "Display last modified date" setting is enabled,
    48 	 * If the "Display last modified date" setting is enabled,
    37 	 * only display the modified date if it is later than the publishing date.
    49 	 * only display the modified date if it is later than the publishing date.
    38 	 */
    50 	 */
    39 	if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
    51 	if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
    40 		if ( get_the_modified_date( 'Ymdhi', $post_ID ) > get_the_date( 'Ymdhi', $post_ID ) ) {
    52 		if ( get_the_modified_date( 'Ymdhi', $post_ID ) > get_the_date( 'Ymdhi', $post_ID ) ) {
    41 			$formatted_date   = get_the_modified_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
    53 			if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) {
       
    54 				// translators: %s: human-readable time difference.
       
    55 				$formatted_date = sprintf( __( '%s ago' ), human_time_diff( get_post_timestamp( $post_ID, 'modified' ) ) );
       
    56 			} else {
       
    57 				$formatted_date = get_the_modified_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
       
    58 			}
    42 			$unformatted_date = esc_attr( get_the_modified_date( 'c', $post_ID ) );
    59 			$unformatted_date = esc_attr( get_the_modified_date( 'c', $post_ID ) );
    43 			$classes[]        = 'wp-block-post-date__modified-date';
    60 			$classes[]        = 'wp-block-post-date__modified-date';
    44 		} else {
    61 		} else {
    45 			return '';
    62 			return '';
    46 		}
    63 		}