| 1 |
<?php |
| 2 |
/** |
| 3 |
* PHP file to use when rendering the block type on the server to show on the front end. |
| 4 |
* |
| 5 |
* The following variables are exposed to the file: |
| 6 |
* $attributes (array): The block attributes. |
| 7 |
* $content (string): The block default content. |
| 8 |
* $block (WP_Block): The block instance. |
| 9 |
* |
| 10 |
* @see https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#render |
| 11 |
* @package block-developer-examples |
| 12 |
*/ |
| 13 |
|
| 14 |
// Exit if accessed directly. |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
// Get the current year. |
| 20 |
$charitable_current_year = gmdate( 'Y' ); |
| 21 |
|
| 22 |
// Determine which content to display. |
| 23 |
if ( isset( $attributes['fallbackCurrentYear'] ) && $attributes['fallbackCurrentYear'] === $charitable_current_year ) { |
| 24 |
|
| 25 |
// The current year is the same as the fallback, so use the block content saved in the database (by the save.js function). |
| 26 |
$charitable_block_content = $content; |
| 27 |
} else { |
| 28 |
|
| 29 |
// The current year is different from the fallback, so render the updated block content. |
| 30 |
if ( ! empty( $attributes['startingYear'] ) && ! empty( $attributes['showStartingYear'] ) ) { |
| 31 |
$charitable_display_date = $attributes['startingYear'] . '–' . $charitable_current_year; |
| 32 |
} else { |
| 33 |
$charitable_display_date = $charitable_current_year; |
| 34 |
} |
| 35 |
|
| 36 |
$charitable_block_content = '<p ' . get_block_wrapper_attributes() . '>© ' . esc_html( $charitable_display_date ) . '</p>'; |
| 37 |
} |
| 38 |
|
| 39 |
echo wp_kses_post( $charitable_block_content ); |
| 40 |
|