From cebf337a2a12890f086469e035e1990ed3cd8ff0 Mon Sep 17 00:00:00 2001 From: Jorge Date: Thu, 14 Feb 2019 11:34:30 +0000 Subject: [PATCH] Fix: Calendar block: Always show current month for non post types on the editor --- packages/block-library/src/calendar/edit.js | 11 +++++++++- packages/block-library/src/calendar/index.php | 22 +++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/packages/block-library/src/calendar/edit.js b/packages/block-library/src/calendar/edit.js index 67d89d99bd457..f884490ec38c8 100644 --- a/packages/block-library/src/calendar/edit.js +++ b/packages/block-library/src/calendar/edit.js @@ -61,7 +61,16 @@ class CalendarEdit extends Component { } export default withSelect( ( select ) => { + const { + getEditedPostAttribute, + } = select( 'core/editor' ); + const postType = getEditedPostAttribute( 'type' ); + // Dates are used to overwrite year and month used on the calendar. + // This overwrite should only happen for 'post' post types. + // For other post types the calendar always displays the current month. return { - date: select( 'core/editor' ).getEditedPostAttribute( 'date' ), + date: postType === 'post' ? + getEditedPostAttribute( 'date' ) : + undefined, }; } )( CalendarEdit ); diff --git a/packages/block-library/src/calendar/index.php b/packages/block-library/src/calendar/index.php index 9177997692f40..8e26626f5f861 100644 --- a/packages/block-library/src/calendar/index.php +++ b/packages/block-library/src/calendar/index.php @@ -13,18 +13,22 @@ * @return string Returns the block content. */ function render_block_core_calendar( $attributes ) { - global $monthnum, $year, $post; + global $monthnum, $year; + $previous_monthnum = $monthnum; $previous_year = $year; - if ( isset( $attributes['month'] ) ) { - // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited - $monthnum = $attributes['month']; - } - - if ( isset( $attributes['year'] ) ) { - // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited - $year = $attributes['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'];