render_block_core_calendar

函数


render_block_core_calendar ( $attributes )
参数
  • (array)
    $attributes
    The block attributes.
    Required:
返回值
  • (string) Returns the block content.
定义位置
  • wp-includes/blocks/calendar.php
    , line 15
引入
弃用

Renders the `core/calendar` block on server.

function render_block_core_calendar( $attributes ) {
	global $monthnum, $year;

	// Calendar shouldn't be rendered
	// when there are no published posts on the site.
	if ( ! block_core_calendar_has_published_posts() ) {
		if ( is_user_logged_in() ) {
			return '
' . __( 'The calendar block is hidden because there are no published posts.' ) . '
'; } return ''; } $previous_monthnum = $monthnum; $previous_year = $year; if ( isset( $attributes['month'] ) && isset( $attributes['year'] ) ) { $permalink_structure = get_option( 'permalink_structure' ); if ( str_contains( $permalink_structure, '%monthnum%' ) && str_contains( $permalink_structure, '%year%' ) ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited $monthnum = $attributes['month']; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited $year = $attributes['year']; } } $wrapper_attributes = get_block_wrapper_attributes(); $output = sprintf( '
%2$s
', $wrapper_attributes, get_calendar( true, false ) ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited $monthnum = $previous_monthnum; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited $year = $previous_year; return $output; }