PluginProbe
Gutenberg / 12.1.0
Gutenberg v12.1.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / block-library / blocks / post-date.php

post-date.php in Gutenberg 12.1.0, at build/block-library/blocks/post-date.php

49 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Server-side rendering of the `core/post-date` block.
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Renders the `core/post-date` block on the server.
10 *
11 * @param array $attributes Block attributes.
12 * @param string $content Block default content.
13 * @param WP_Block $block Block instance.
14 * @return string Returns the filtered post date for the current post wrapped inside "time" tags.
15 */
16 function gutenberg_render_block_core_post_date( $attributes, $content, $block ) {
17 if ( ! isset( $block->context['postId'] ) ) {
18 return '';
19 }
20
21 $post_ID = $block->context['postId'];
22 $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
23 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
24 $formatted_date = get_the_date( isset( $attributes['format'] ) ? $attributes['format'] : '', $post_ID );
25 if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
26 $formatted_date = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $post_ID ), $formatted_date );
27 }
28
29 return sprintf(
30 '<div %1$s><time datetime="%2$s">%3$s</time></div>',
31 $wrapper_attributes,
32 get_the_date( 'c', $post_ID ),
33 $formatted_date
34 );
35 }
36
37 /**
38 * Registers the `core/post-date` block on the server.
39 */
40 function gutenberg_register_block_core_post_date() {
41 register_block_type_from_metadata(
42 __DIR__ . '/post-date',
43 array(
44 'render_callback' => 'gutenberg_render_block_core_post_date',
45 )
46 );
47 }
48 add_action( 'init', 'gutenberg_register_block_core_post_date', 20 );
49