Skip to content

Commit

Permalink
Fix: Calendar block: Always show current month for non post types on …
Browse files Browse the repository at this point in the history
…the editor (#13873)
  • Loading branch information
jorgefilipecosta authored and youknowriad committed Mar 20, 2019
1 parent eb65b1f commit 1ad879f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
11 changes: 10 additions & 1 deletion packages/block-library/src/calendar/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
22 changes: 13 additions & 9 deletions packages/block-library/src/calendar/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down

0 comments on commit 1ad879f

Please sign in to comment.