diff -r 48c4eec2b7e6 -r 8c2e4d02f4ef wp/wp-includes/general-template.php --- a/wp/wp-includes/general-template.php Fri Sep 05 18:40:08 2025 +0200 +++ b/wp/wp-includes/general-template.php Fri Sep 05 18:52:52 2025 +0200 @@ -19,9 +19,9 @@ * @since 5.5.0 A return value was added. * @since 5.5.0 The `$args` parameter was added. * - * @param string $name The name of the specialized header. - * @param array $args Optional. Additional arguments passed to the header template. - * Default empty array. + * @param string|null $name The name of the specialized header. Default null. + * @param array $args Optional. Additional arguments passed to the header template. + * Default empty array. * @return void|false Void on success, false if the template does not exist. */ function get_header( $name = null, $args = array() ) { @@ -63,9 +63,9 @@ * @since 5.5.0 A return value was added. * @since 5.5.0 The `$args` parameter was added. * - * @param string $name The name of the specialized footer. - * @param array $args Optional. Additional arguments passed to the footer template. - * Default empty array. + * @param string|null $name The name of the specialized footer. Default null. + * @param array $args Optional. Additional arguments passed to the footer template. + * Default empty array. * @return void|false Void on success, false if the template does not exist. */ function get_footer( $name = null, $args = array() ) { @@ -107,9 +107,9 @@ * @since 5.5.0 A return value was added. * @since 5.5.0 The `$args` parameter was added. * - * @param string $name The name of the specialized sidebar. - * @param array $args Optional. Additional arguments passed to the sidebar template. - * Default empty array. + * @param string|null $name The name of the specialized sidebar. Default null. + * @param array $args Optional. Additional arguments passed to the sidebar template. + * Default empty array. * @return void|false Void on success, false if the template does not exist. */ function get_sidebar( $name = null, $args = array() ) { @@ -159,7 +159,7 @@ * @since 5.5.0 The `$args` parameter was added. * * @param string $slug The slug name for the generic template. - * @param string|null $name Optional. The name of the specialized template. + * @param string|null $name Optional. The name of the specialized template. Default null. * @param array $args Optional. Additional arguments passed to the template. * Default empty array. * @return void|false Void on success, false if the template does not exist. @@ -175,8 +175,8 @@ * @since 5.5.0 The `$args` parameter was added. * * @param string $slug The slug name for the generic template. - * @param string|null $name The name of the specialized template or null if - * there is none. + * @param string|null $name The name of the specialized template + * or null if there is none. * @param array $args Additional arguments passed to the template. */ do_action( "get_template_part_{$slug}", $slug, $name, $args ); @@ -196,8 +196,8 @@ * @since 5.5.0 The `$args` parameter was added. * * @param string $slug The slug name for the generic template. - * @param string $name The name of the specialized template or an empty - * string if there is none. + * @param string $name The name of the specialized template + * or an empty string if there is none. * @param string[] $templates Array of template files to search for, in order. * @param array $args Additional arguments passed to the template. */ @@ -1118,7 +1118,7 @@ $image ); } else { - $aria_current = is_front_page() && ! is_paged() ? ' aria-current="page"' : ''; + $aria_current = ! is_paged() && ( is_front_page() || is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) ? ' aria-current="page"' : ''; $html = sprintf( '%3$s', @@ -1299,7 +1299,6 @@ /** * Displays title tag with content. * - * @ignore * @since 4.1.0 * @since 4.4.0 Improved title output replaced `wp_title()`. * @access private @@ -1917,7 +1916,7 @@ * @param string $format Optional. Can be 'link', 'option', 'html', or custom. Default 'html'. * @param string $before Optional. Content to prepend to the description. Default empty. * @param string $after Optional. Content to append to the description. Default empty. - * @param bool $selected Optional. Set to true if the current page is the selected archive page. + * @param bool $selected Optional. Set to true if the current page is the selected archive page. Default false. * @return string HTML link content for archive. */ function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) { @@ -2155,7 +2154,7 @@ if ( $results ) { $after = $parsed_args['after']; foreach ( (array) $results as $result ) { - if ( $result->week != $arc_w_last ) { + if ( $result->week !== $arc_w_last ) { $arc_year = $result->yr; $arc_w_last = $result->week; $arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) ); @@ -2234,6 +2233,8 @@ * no posts for the month, then it will not be displayed. * * @since 1.0.0 + * @since 6.8.0 Added the `$args` parameter, with backward compatibility + * for the replaced `$initial` and `$display` parameters. * * @global wpdb $wpdb WordPress database abstraction object. * @global int $m @@ -2242,21 +2243,96 @@ * @global WP_Locale $wp_locale WordPress date and time locale object. * @global array $posts * - * @param bool $initial Optional. Whether to use initial calendar names. Default true. - * @param bool $display Optional. Whether to display the calendar output. Default true. + * @param array $args { + * Optional. Arguments for the `get_calendar` function. + * + * @type bool $initial Whether to use initial calendar names. Default true. + * @type bool $display Whether to display the calendar output. Default true. + * @type string $post_type Optional. Post type. Default 'post'. + * } * @return void|string Void if `$display` argument is true, calendar HTML if `$display` is false. */ -function get_calendar( $initial = true, $display = true ) { +function get_calendar( $args = array() ) { global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; - $key = md5( $m . $monthnum . $year ); + $defaults = array( + 'initial' => true, + 'display' => true, + 'post_type' => 'post', + ); + + $original_args = func_get_args(); + $args = array(); + + if ( ! empty( $original_args ) ) { + if ( ! is_array( $original_args[0] ) ) { + if ( isset( $original_args[0] ) && is_bool( $original_args[0] ) ) { + $defaults['initial'] = $original_args[0]; + } + if ( isset( $original_args[1] ) && is_bool( $original_args[1] ) ) { + $defaults['display'] = $original_args[1]; + } + } else { + $args = $original_args[0]; + } + } + + /** + * Filter the `get_calendar` function arguments before they are used. + * + * @since 6.8.0 + * + * @param array $args { + * Optional. Arguments for the `get_calendar` function. + * + * @type bool $initial Whether to use initial calendar names. Default true. + * @type bool $display Whether to display the calendar output. Default true. + * @type string $post_type Optional. Post type. Default 'post'. + * } + * @return array The arguments for the `get_calendar` function. + */ + $args = apply_filters( 'get_calendar_args', wp_parse_args( $args, $defaults ) ); + + 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 function's need to echo or return the output. + * + * The global values contain data generated by the URL query string 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 ] ) ) { /** This filter is documented in wp-includes/general-template.php */ - $output = apply_filters( 'get_calendar', $cache[ $key ] ); - - if ( $display ) { + $output = apply_filters( 'get_calendar', $cache[ $key ], $args ); + + if ( $args['display'] ) { echo $output; return; } @@ -2268,9 +2344,21 @@ $cache = array(); } + $post_type = $args['post_type']; + // Quick check. If we have no posts at all, abort! if ( ! $posts ) { - $gotsome = $wpdb->get_var( "SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1" ); + $gotsome = $wpdb->get_var( + $wpdb->prepare( + "SELECT 1 as test + FROM $wpdb->posts + WHERE post_type = %s + AND post_status = 'publish' + LIMIT 1", + $post_type + ) + ); + if ( ! $gotsome ) { $cache[ $key ] = ''; wp_cache_set( 'get_calendar', $cache, 'calendar' ); @@ -2278,32 +2366,35 @@ } } - if ( isset( $_GET['w'] ) ) { - $w = (int) $_GET['w']; - } // week_begins = 0 stands for Sunday. $week_begins = (int) get_option( 'start_of_week' ); // Let's figure out when we are. if ( ! empty( $monthnum ) && ! empty( $year ) ) { - $thismonth = zeroise( (int) $monthnum, 2 ); + $thismonth = (int) $monthnum; $thisyear = (int) $year; } elseif ( ! empty( $w ) ) { // We need to get the month from MySQL. $thisyear = (int) substr( $m, 0, 4 ); // It seems MySQL's weeks disagree with PHP's. $d = ( ( $w - 1 ) * 7 ) + 6; - $thismonth = $wpdb->get_var( "SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')" ); + $thismonth = (int) $wpdb->get_var( + $wpdb->prepare( + "SELECT DATE_FORMAT((DATE_ADD('%d0101', INTERVAL %d DAY) ), '%%m')", + $thisyear, + $d + ) + ); } elseif ( ! empty( $m ) ) { $thisyear = (int) substr( $m, 0, 4 ); if ( strlen( $m ) < 6 ) { - $thismonth = '01'; + $thismonth = 1; } else { - $thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 ); + $thismonth = (int) substr( $m, 4, 2 ); } } else { - $thisyear = current_time( 'Y' ); - $thismonth = current_time( 'm' ); + $thisyear = (int) current_time( 'Y' ); + $thismonth = (int) current_time( 'm' ); } $unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear ); @@ -2311,20 +2402,32 @@ // Get the next and previous month and year with at least one post. $previous = $wpdb->get_row( - "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year - FROM $wpdb->posts - WHERE post_date < '$thisyear-$thismonth-01' - AND post_type = 'post' AND post_status = 'publish' - ORDER BY post_date DESC - LIMIT 1" + $wpdb->prepare( + "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year + FROM $wpdb->posts + WHERE post_date < '%d-%d-01' + AND post_type = %s AND post_status = 'publish' + ORDER BY post_date DESC + LIMIT 1", + $thisyear, + zeroise( $thismonth, 2 ), + $post_type + ) ); - $next = $wpdb->get_row( - "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year - FROM $wpdb->posts - WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' - AND post_type = 'post' AND post_status = 'publish' - ORDER BY post_date ASC - LIMIT 1" + + $next = $wpdb->get_row( + $wpdb->prepare( + "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year + FROM $wpdb->posts + WHERE post_date > '%d-%d-%d 23:59:59' + AND post_type = %s AND post_status = 'publish' + ORDER BY post_date ASC + LIMIT 1", + $thisyear, + zeroise( $thismonth, 2 ), + $last_day, + $post_type + ) ); /* translators: Calendar caption: 1: Month name, 2: 4-digit year. */ @@ -2345,9 +2448,9 @@ } foreach ( $myweek as $wd ) { - $day_name = $initial ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd ); + $day_name = $args['initial'] ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd ); $wd = esc_attr( $wd ); - $calendar_output .= "\n\t\t$day_name"; + $calendar_output .= "\n\t\t$day_name"; } $calendar_output .= ' @@ -2360,10 +2463,18 @@ // Get days with posts. $dayswithposts = $wpdb->get_results( - "SELECT DISTINCT DAYOFMONTH(post_date) - FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' - AND post_type = 'post' AND post_status = 'publish' - AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", + $wpdb->prepare( + "SELECT DISTINCT DAYOFMONTH(post_date) + FROM $wpdb->posts WHERE post_date >= '%d-%d-01 00:00:00' + AND post_type = %s AND post_status = 'publish' + AND post_date <= '%d-%d-%d 23:59:59'", + $thisyear, + zeroise( $thismonth, 2 ), + $post_type, + $thisyear, + zeroise( $thismonth, 2 ), + $last_day + ), ARRAY_N ); @@ -2374,8 +2485,8 @@ } // See how much we should pad in the beginning. - $pad = calendar_week_mod( gmdate( 'w', $unixmonth ) - $week_begins ); - if ( 0 != $pad ) { + $pad = calendar_week_mod( (int) gmdate( 'w', $unixmonth ) - $week_begins ); + if ( $pad > 0 ) { $calendar_output .= "\n\t\t" . ' '; } @@ -2386,11 +2497,13 @@ if ( isset( $newrow ) && $newrow ) { $calendar_output .= "\n\t\n\t\n\t\t"; } + $newrow = false; - if ( current_time( 'j' ) == $day && - current_time( 'm' ) == $thismonth && - current_time( 'Y' ) == $thisyear ) { + if ( (int) current_time( 'j' ) === $day + && (int) current_time( 'm' ) === $thismonth + && (int) current_time( 'Y' ) === $thisyear + ) { $calendar_output .= ''; } else { $calendar_output .= ''; @@ -2413,13 +2526,13 @@ $calendar_output .= ''; - if ( 6 == calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) { + if ( 6 === (int) calendar_week_mod( (int) gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) { $newrow = true; } } - $pad = 7 - calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ); - if ( 0 != $pad && 7 != $pad ) { + $pad = 7 - calendar_week_mod( (int) gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ); + if ( 0 < $pad && $pad < 7 ) { $calendar_output .= "\n\t\t" . ' '; } @@ -2430,9 +2543,11 @@ $calendar_output .= '