diff --git a/includes/calendar.php b/includes/calendar.php index dbc1f76..7467d9e 100644 --- a/includes/calendar.php +++ b/includes/calendar.php @@ -139,13 +139,13 @@ function cptda_get_calendar( $post_type, $initial = true, $echo = true ) { $thismonth = zeroise( absint( $calendar['month'] ), 2 ); $last_day = $calendar['last_day']; - /* translators: Calendar caption: 1: month name, 2: 4-digit year */ + /* translators: Calendar caption: 1: Month name, 2: 4-digit year. */ $calendar_caption = _x( '%1$s %2$s', 'calendar caption' ); - $output = ' + $output = '
'; @@ -165,32 +165,6 @@ function cptda_get_calendar( $post_type, $initial = true, $echo = true ) { $output .= ' - - - '; - - if ( $prev_year && $prev_month ) { - $output .= "\n\t\t" . ''; - } else { - $output .= "\n\t\t" . ''; - } - - $output .= "\n\t\t" . ''; - - if ( $next_year && $next_month ) { - $output .= "\n\t\t" . ''; - } else { - $output .= "\n\t\t" . ''; - } - - $output .= ' - - - '; @@ -220,7 +194,7 @@ function cptda_get_calendar( $post_type, $initial = true, $echo = true ) { } $newrow = false; - $daysinmonth = (int) date( 't', $calendar['unixmonth'] ); + $daysinmonth = (int) gmdate( 't', $calendar['unixmonth'] ); for ( $day = 1; $day <= $daysinmonth; ++$day ) { if ( isset( $newrow ) && $newrow ) { @@ -260,7 +234,33 @@ function cptda_get_calendar( $post_type, $initial = true, $echo = true ) { if ( $pad != 0 && $pad != 7 ) { $output .= "\n\t\t" . ''; } - $output .= "\n\t\n\t\n\t
' . sprintf( $calendar_caption, $wp_locale->get_month( $thismonth ), - date( 'Y', $calendar['unixmonth'] ) + gmdate( 'Y', $calendar['unixmonth'] ) ) . '
« ' . - $wp_locale->get_month_abbrev( $wp_locale->get_month( $prev_month ) ) . - '  ' . - $wp_locale->get_month_abbrev( $wp_locale->get_month( $next_month ) ) . - ' » 
 
"; + + $output .= "\n\t\n\t"; + $output .= "\n\t"; + + $output .= ''; + $cache[ $key ] = $output; wp_cache_set( 'cptda_get_calendar', $cache, 'calendar' ); diff --git a/tests/test-block-calendar.php b/tests/test-block-calendar.php index 6cd708a..2cc0a64 100644 --- a/tests/test-block-calendar.php +++ b/tests/test-block-calendar.php @@ -65,6 +65,14 @@ function test_calendar_block_in_post_content() { function test_calendar_block_is_equal_to_wp_calendar_block() { global $monthnum, $year; + $version = $GLOBALS['wp_version']; + + // WordPress changed HTML in version 5.4 + if ( version_compare( $version , '5.4', '<' ) ) { + $this->markTestSkipped('Skipped calendar output test. Incorrect calendar HTML for WP < 5.4'); + } + + $previous_monthnum = $monthnum; $previous_year = $year;