-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.php
58 lines (51 loc) · 1.56 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Server-side rendering of the `core/post-time-to-read` block.
*
* @package WordPress
*/
/**
* Renders the `core/post-time-to-read` block on the server.
*
* @param array $attributes Block attributes.
* @param string $content Block default content.
* @param WP_Block $block Block instance.
* @return string Returns the rendered post author name block.
*/
function render_block_core_post_time_to_read( $attributes, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
}
// TODO: Create an equivalent word count PHP funciton.
$minutes_to_read = 0;
$minutes_to_read_string = 0 !== $minutes_to_read
? sprintf(
/* translators: %d is the number of minutes the post will take to read. */
_n(
'You can read this post in %d minute.',
'You can read this post in %d minutes.',
$minutes_to_read
),
$minutes_to_read
)
: __( 'You can read this post in less than a minute.' );
$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
return sprintf(
'<p %1$s>%2$s</p>',
$wrapper_attributes,
$minutes_to_read_string
);
}
/**
* Registers the `core/post-time-to-read` block on the server.
*/
function register_block_core_post_time_to_read() {
register_block_type_from_metadata(
__DIR__ . '/post-time-to-read',
array(
'render_callback' => 'render_block_core_post_time_to_read',
)
);
}
add_action( 'init', 'register_block_core_post_time_to_read' );