PluginProbe
Gutenberg / 10.5.3
Gutenberg v10.5.3
24.0.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 All 403 releases
gutenberg / build / block-library / blocks / calendar.php

calendar.php in Gutenberg 10.5.3, at build/block-library/blocks/calendar.php

62 lines 1.6 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/calendar` block.
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Renders the `core/calendar` block on server.
10 *
11 * @param array $attributes The block attributes.
12 *
13 * @return string Returns the block content.
14 */
15 function gutenberg_render_block_core_calendar( $attributes ) {
16 global $monthnum, $year;
17
18 $previous_monthnum = $monthnum;
19 $previous_year = $year;
20
21 if ( isset( $attributes['month'] ) && isset( $attributes['year'] ) ) {
22 $permalink_structure = get_option( 'permalink_structure' );
23 if (
24 strpos( $permalink_structure, '%monthnum%' ) !== false &&
25 strpos( $permalink_structure, '%year%' ) !== false
26 ) {
27 // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
28 $monthnum = $attributes['month'];
29 // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
30 $year = $attributes['year'];
31 }
32 }
33
34 $wrapper_attributes = get_block_wrapper_attributes();
35 $output = sprintf(
36 '<div %1$s>%2$s</div>',
37 $wrapper_attributes,
38 get_calendar( true, false )
39 );
40
41 // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
42 $monthnum = $previous_monthnum;
43 // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
44 $year = $previous_year;
45
46 return $output;
47 }
48
49 /**
50 * Registers the `core/calendar` block on server.
51 */
52 function gutenberg_register_block_core_calendar() {
53 register_block_type_from_metadata(
54 __DIR__ . '/calendar',
55 array(
56 'render_callback' => 'gutenberg_render_block_core_calendar',
57 )
58 );
59 }
60
61 add_action( 'init', 'gutenberg_register_block_core_calendar', 20 );
62