diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 527289901e..3b0875f876 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -2292,7 +2292,39 @@ function get_calendar( $args = array() ) { */ $args = apply_filters( 'get_calendar_args', wp_parse_args( $args, $defaults ) ); - $key = md5( $m . $monthnum . $year ); + if ( ! post_type_exists( $args['post_type'] ) ) { + $args['post_type'] = 'post'; + } + + $w = 0; + if ( isset( $_GET['w'] ) ) { + $w = (int) $_GET['w']; + } + + /* + * Normalize the cache key. + * + * The following ensures the same cache key is used for the same parameter + * and parameter equivalents. This prevents `post_type > post, initial > true` + * from generating a different key from the same values in the reverse order. + * + * `display` is excluded from the cache key as the cache contains the same + * HTML regardless of this functions need to echo or return the output. + * + * The global values contain data generated by the URL querystring variables. + */ + $cache_args = $args; + unset( $cache_args['display'] ); + + $cache_args['globals'] = array( + 'm' => $m, + 'monthnum' => $monthnum, + 'year' => $year, + 'week' => $w, + ); + + wp_recursive_ksort( $cache_args ); + $key = md5( serialize( $cache_args ) ); $cache = wp_cache_get( 'get_calendar', 'calendar' ); if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) { @@ -2312,9 +2344,6 @@ function get_calendar( $args = array() ) { } $post_type = $args['post_type']; - if ( ! post_type_exists( $post_type ) ) { - $post_type = 'post'; - } // Quick check. If we have no posts at all, abort! if ( ! $posts ) { @@ -2327,9 +2356,6 @@ function get_calendar( $args = array() ) { } } - if ( isset( $_GET['w'] ) ) { - $w = (int) $_GET['w']; - } // week_begins = 0 stands for Sunday. $week_begins = (int) get_option( 'start_of_week' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index fb94dec7f8..7eb71f3a75 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8-beta1-59938'; +$wp_version = '6.8-beta1-59939'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.