Make WordPress Core

Changeset 59471


Ignore:
Timestamp:
11/28/2024 10:50:21 PM (3 days ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r59461 r59471  
    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
     
    610610    // $start + 1 week - 1 second.
    611611    $end = $start + WEEK_IN_SECONDS - 1;
     612
    612613    return compact( 'start', 'end' );
    613614}
  • trunk/src/wp-includes/general-template.php

    r59419 r59471  
    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>';
     
    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>';
Note: See TracChangeset for help on using the changeset viewer.