[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-includes/blocks/ -> calendar.php (source)

   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 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      $custom_class_name = empty( $attributes['className'] ) ? '' : ' ' . $attributes['className'];
  35      $align_class_name  = empty( $attributes['align'] ) ? '' : ' ' . "align{$attributes['align']}";
  36  
  37      $output = sprintf(
  38          '<div class="%1$s">%2$s</div>',
  39          esc_attr( 'wp-block-calendar' . $custom_class_name . $align_class_name ),
  40          get_calendar( true, false )
  41      );
  42  
  43      // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
  44      $monthnum = $previous_monthnum;
  45      // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
  46      $year = $previous_year;
  47  
  48      return $output;
  49  }
  50  
  51  /**
  52   * Registers the `core/calendar` block on server.
  53   */
  54  function register_block_core_calendar() {
  55      register_block_type(
  56          'core/calendar',
  57          array(
  58              'attributes'      => array(
  59                  'align'     => array(
  60                      'type' => 'string',
  61                      'enum' => array( 'left', 'center', 'right', 'wide', 'full' ),
  62                  ),
  63                  'className' => array(
  64                      'type' => 'string',
  65                  ),
  66                  'month'     => array(
  67                      'type' => 'integer',
  68                  ),
  69                  'year'      => array(
  70                      'type' => 'integer',
  71                  ),
  72              ),
  73              'render_callback' => 'render_block_core_calendar',
  74          )
  75      );
  76  }
  77  
  78  add_action( 'init', 'register_block_core_calendar' );


Generated: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7