aboutsummaryrefslogtreecommitdiff
path: root/srcs/wordpress/wp-includes/blocks/calendar.php
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-07 13:06:14 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-07 13:06:14 +0100
commit7086111ad4dd997e12a3220e1ee60c9b9bcf0bb8 (patch)
treef7453d7dd5cbaaab246e23810b02d3edf1e451be /srcs/wordpress/wp-includes/blocks/calendar.php
parentc59bdcf77c50cbe89b4a93782cdd6d9e7532080e (diff)
downloadft_server-7086111ad4dd997e12a3220e1ee60c9b9bcf0bb8.tar.gz
ft_server-7086111ad4dd997e12a3220e1ee60c9b9bcf0bb8.tar.bz2
ft_server-7086111ad4dd997e12a3220e1ee60c9b9bcf0bb8.zip
Added wordpress
Diffstat (limited to 'srcs/wordpress/wp-includes/blocks/calendar.php')
-rw-r--r--srcs/wordpress/wp-includes/blocks/calendar.php78
1 files changed, 78 insertions, 0 deletions
diff --git a/srcs/wordpress/wp-includes/blocks/calendar.php b/srcs/wordpress/wp-includes/blocks/calendar.php
new file mode 100644
index 0000000..3d2e806
--- /dev/null
+++ b/srcs/wordpress/wp-includes/blocks/calendar.php
@@ -0,0 +1,78 @@
+<?php
+/**
+ * Server-side rendering of the `core/calendar` block.
+ *
+ * @package WordPress
+ */
+
+/**
+ * Renders the `core/calendar` block on server.
+ *
+ * @param array $attributes The block attributes.
+ *
+ * @return string Returns the block content.
+ */
+function render_block_core_calendar( $attributes ) {
+ global $monthnum, $year;
+
+ $previous_monthnum = $monthnum;
+ $previous_year = $year;
+
+ if ( isset( $attributes['month'] ) && isset( $attributes['year'] ) ) {
+ $permalink_structure = get_option( 'permalink_structure' );
+ if (
+ strpos( $permalink_structure, '%monthnum%' ) !== false &&
+ strpos( $permalink_structure, '%year%' ) !== false
+ ) {
+ // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
+ $monthnum = $attributes['month'];
+ // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
+ $year = $attributes['year'];
+ }
+ }
+
+ $custom_class_name = empty( $attributes['className'] ) ? '' : ' ' . $attributes['className'];
+ $align_class_name = empty( $attributes['align'] ) ? '' : ' ' . "align{$attributes['align']}";
+
+ $output = sprintf(
+ '<div class="%1$s">%2$s</div>',
+ esc_attr( 'wp-block-calendar' . $custom_class_name . $align_class_name ),
+ get_calendar( true, false )
+ );
+
+ // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
+ $monthnum = $previous_monthnum;
+ // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
+ $year = $previous_year;
+
+ return $output;
+}
+
+/**
+ * Registers the `core/calendar` block on server.
+ */
+function register_block_core_calendar() {
+ register_block_type(
+ 'core/calendar',
+ array(
+ 'attributes' => array(
+ 'align' => array(
+ 'type' => 'string',
+ 'enum' => array( 'left', 'center', 'right', 'wide', 'full' ),
+ ),
+ 'className' => array(
+ 'type' => 'string',
+ ),
+ 'month' => array(
+ 'type' => 'integer',
+ ),
+ 'year' => array(
+ 'type' => 'integer',
+ ),
+ ),
+ 'render_callback' => 'render_block_core_calendar',
+ )
+ );
+}
+
+add_action( 'init', 'register_block_core_calendar' );