Skip to content

Commit ce4627f

Browse files
Coding Standards: Cast gmdate( 'w' ) to int before using as integer.
This addresses several instances of `gmdate( 'w' )` being used directly as an integer, when it's actually a numeric string. The issue is remediated by casting the value to `int` before use. Affected functions: * `get_calendar()` * `get_weekstartend()` Follow-up to [508], [1632]. Props justlevine. See #52217. git-svn-id: https://develop.svn.wordpress.org/trunk@59471 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8834f57 commit ce4627f

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/wp-includes/functions.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,10 @@ function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
594594
$day = mktime( 0, 0, 0, $md, $mm, $my );
595595

596596
// The day of the week from the timestamp.
597-
$weekday = gmdate( 'w', $day );
597+
$weekday = (int) gmdate( 'w', $day );
598598

599599
if ( ! is_numeric( $start_of_week ) ) {
600-
$start_of_week = get_option( 'start_of_week' );
600+
$start_of_week = (int) get_option( 'start_of_week' );
601601
}
602602

603603
if ( $weekday < $start_of_week ) {
@@ -609,6 +609,7 @@ function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
609609

610610
// $start + 1 week - 1 second.
611611
$end = $start + WEEK_IN_SECONDS - 1;
612+
612613
return compact( 'start', 'end' );
613614
}
614615

src/wp-includes/general-template.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ function get_calendar( $initial = true, $display = true ) {
23732373
}
23742374

23752375
// See how much we should pad in the beginning.
2376-
$pad = calendar_week_mod( gmdate( 'w', $unixmonth ) - $week_begins );
2376+
$pad = calendar_week_mod( (int) gmdate( 'w', $unixmonth ) - $week_begins );
23772377
if ( 0 != $pad ) {
23782378
$calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr( $pad ) . '" class="pad">&nbsp;</td>';
23792379
}
@@ -2412,12 +2412,12 @@ function get_calendar( $initial = true, $display = true ) {
24122412

24132413
$calendar_output .= '</td>';
24142414

2415-
if ( 6 == calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) {
2415+
if ( 6 == calendar_week_mod( (int) gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) {
24162416
$newrow = true;
24172417
}
24182418
}
24192419

2420-
$pad = 7 - calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins );
2420+
$pad = 7 - calendar_week_mod( (int) gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins );
24212421
if ( 0 != $pad && 7 != $pad ) {
24222422
$calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr( $pad ) . '">&nbsp;</td>';
24232423
}

0 commit comments

Comments
 (0)