Skip to content

Commit 0181606

Browse files
westonruterclaude
andcommitted
Date/Time: Handle a missing post weekday in the_weekday() and the_weekday_date().
`get_post_time()` returns false when the post date cannot be parsed. Both functions passed that straight to `WP_Locale::get_weekday()`, where it was coerced to the array key 0, so the post was silently labeled Sunday. Now nothing is output in that case, and the filterable string result is cast and clamped to 0-6 to match the `int<0, 6>` type of `WP_Locale::get_weekday()`. This removes the corresponding entry from the `argument.type` PHPStan baseline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e4f3252 commit 0181606

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

‎src/wp-includes/general-template.php‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3436,7 +3436,13 @@ function the_weekday() {
34363436
return;
34373437
}
34383438

3439-
$the_weekday = $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
3439+
$weekday_number = get_post_time( 'w', false, $post );
3440+
3441+
if ( false === $weekday_number ) {
3442+
return;
3443+
}
3444+
3445+
$the_weekday = $wp_locale->get_weekday( clamp( (int) $weekday_number, 0, 6 ) );
34403446

34413447
/**
34423448
* Filters the localized weekday of the post, for display.
@@ -3473,10 +3479,11 @@ function the_weekday_date( $before = '', $after = '' ) {
34733479
}
34743480

34753481
$the_weekday_date = '';
3482+
$weekday_number = get_post_time( 'w', false, $post );
34763483

3477-
if ( $currentday !== $previousweekday ) {
3484+
if ( false !== $weekday_number && $currentday !== $previousweekday ) {
34783485
$the_weekday_date .= $before;
3479-
$the_weekday_date .= $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
3486+
$the_weekday_date .= $wp_locale->get_weekday( clamp( (int) $weekday_number, 0, 6 ) );
34803487
$the_weekday_date .= $after;
34813488
$previousweekday = $currentday;
34823489
}

‎tests/phpstan/baselines/argument.type.neon‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -953,11 +953,6 @@ parameters:
953953
identifier: argument.type
954954
count: 2
955955
path: ../../../src/wp-includes/general-template.php
956-
-
957-
message: '#^Parameter \#1 \$weekday_number of method WP_Locale\:\:get_weekday\(\) expects int\<0, 6\>, string\|false given\.$#'
958-
identifier: argument.type
959-
count: 2
960-
path: ../../../src/wp-includes/general-template.php
961956
-
962957
message: '#^Parameter \#2 \$replace of function str_replace expects array\<string\>\|string, int\<1, max\> given\.$#'
963958
identifier: argument.type

0 commit comments

Comments
 (0)